﻿var xmlHttp;
var divID;
var oldStyle; //the style of the last row that was hovered
var oldClick=""; //the last row that was clicked
var oldClickStyle=""; // the style of the last row that was clicked
//the changecolor function changes the color of any row on mouseclick or mouseover.
//mouseclick cause the change to last until another mouseclick. mouseout cause the row to revert 
//to its previous colour
function changeColor(myElement,mouseEvent,playerCode)
{
switch (mouseEvent.type)
    {
    case "click":
        // if the row is not already clicked
        if (myElement!=oldClick)
            //reset the last row that was clicked to its original style
            {oldClick.className = oldClickStyle;}
            oldClick = myElement; // specify this row as the last row clicked
            oldClickStyle = oldStyle;  // specify the old style as the last style clicked
            myElement.className = "gridRowSelected"; // set the new style to "clicked"
            var myPlayer;
            ajaxUpdate(myPlayer,"../myPlayerProfile.aspx?playercode="+playerCode,"detailsHolder");    
    break
    case "mouseout":
            // if the row losing focus has not been clicked
            if (myElement!=oldClick)
             // reset its style to its original style
             {myElement.className = oldStyle;}
    break
    case "mouseover":
        // if this row has not been clicked
        if (myElement.className!="gridRowSelected"&&myElement.className!="gridRowHover")
        {
        oldStyle = myElement.className;  // set the current style as the last selected style
        myElement.className = "gridRowHover" // set the current style to "hover"
        }
    break
    }
}

    function ajaxTeamUpdate(url,divName)
        {
        var anim=document.getElementById("updateAnim");
        if (anim)
        {anim.style.visibility="visible";}
        rowOrButton="button"
        var myTeam;
        var ranNum = Math.floor(Math.random()*99999999)
        ajaxUpdate(myTeam,url+'&uid='+ranNum,divName); 
        document.getElementById('theTabs').tabber.tabShow(1);
        }

    function ajaxUpdate(myObj,url,divName)
    {
    myObj=GetXmlHttpObject()
    if (myObj==null)
        {
        alert ("Browser does not support HTTP Request")
        return
        } 
    myObj.onreadystatechange=function(){stateChanged(divName,myObj)}
    myObj.open("GET",url,true)
    myObj.send(null);
    }

    function stateChanged(divID,myHTMLObj) 
    { 
    if (myHTMLObj.readyState==4 || myHTMLObj.readyState=="complete")
        { 
        var anim=document.getElementById("updateAnim");
        if (anim)
        {anim.style.visibility="hidden";}
        var myText = myHTMLObj.responseText;
        var myStart = myText.indexOf('<div id="myNewDiv">');
        var myEnd = myText.indexOf ('</form>');
        if (myStart!=-1)
        {document.getElementById(divID).innerHTML = myText.substring(myStart,myEnd);}
        } 
    } 

    function GetXmlHttpObject()
    { 
    var objXMLHttp=null
    if (window.XMLHttpRequest)
        {
        objXMLHttp=new XMLHttpRequest()
        }
    else if (window.ActiveXObject)
        {
        objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
        }
    return objXMLHttp
    }