
var ajaxRequestObj;

function createRequestObject()
{
    var xmlHttp;
    try
    {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }
    catch (e)
    {
        // Internet Explorer
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            try
            {
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e)
            {
                alert("Your browser does not support AJAX!");
                return false;
            }
        }
    }
    
    return xmlHttp;
}

var counter=0;
var countdownTimerId = 0;
function startCountDown( startVal )
{
   if ( countdownTimerId != 0)
    {
        clearInterval(  countdownTimerId );
        countdownTimerId = 0;
    }
    
    counter = startVal; 
    countdownTimerId = setInterval("countDown()", 1000);
    
}
function countDown()
{
    counter--;
    if (counter <= 0)
    {
        counter = 0;
    }
	document.getElementById("countdown").innerHTML = counter;
}

function getHTMLText(url)
{
   /* ajaxRequestObj = createRequestObject();
    ajaxRequestObj.onreadystatechange=putHTMLTextResponse;
    ajaxRequestObj.open("GET",url,true);
    ajaxRequestObj.send(null);*/
	return true;
}

function putHTMLTextResponse()
{
    if (ajaxRequestObj.readyState==4)
    { 
        document.getElementById('helpTextArea').innerHTML = ajaxRequestObj.responseText;
    }
}

function getSLOTImg(url)
{
	ajaxRequestObj = createRequestObject();
    ajaxRequestObj.onreadystatechange=putSLOTImgResponse;
    ajaxRequestObj.open("GET",url,true);
    ajaxRequestObj.send(null);
}
function putSLOTImgResponse()
{
	if (ajaxRequestObj.readyState==4)
    { 
		responseText = ajaxRequestObj.responseText;
		
		arr = responseText.split('_');
		
		id = document.getElementById("selectedSlot").value;
		objToImage = document.getElementById("img_slot_"+id);	
		
		objFromImage = document.getElementById("img_"+arr[0]);
		objToImage.src = objFromImage.src;
		
		alert("Item Equipped");
    }
}
function getFriendList(url)
{
   
	ajaxRequestObj = createRequestObject();
    ajaxRequestObj.onreadystatechange=putFriendListResponse;
    ajaxRequestObj.open("GET",url,true);
    ajaxRequestObj.send(null);
}
function putFriendListResponse()
{
  
	if(ajaxRequestObj.readyState==4)
    { 
        self.setTimeout('setResponse()', 1000); 
    }
}
function setResponse()
{
		opponentLoad = document.getElementById("opponent_load");
       	 opponentNotFound = document.getElementById("opponent_notfound");
		opponentSearch = document.getElementById("opponent_search");
		opponentAvailable = document.getElementById("opponent_availability");

		opponentLoad.style.display = "none";
			
		if(ajaxRequestObj.responseText == 'PE' || ajaxRequestObj.responseText == 'PA')
		{
			if(ajaxRequestObj.responseText == 'PE') 
			{
				opponentAvailable.innerHTML = 'Player does not exists.'; 	
			}
			else if(ajaxRequestObj.responseText == 'PA') 
			{
				opponentAvailable.innerHTML = 'Player has been found but is currently unavailable may be offline or playing a game.'; 	
			}
			opponentNotFound.style.display = "block";
			opponentSearch.style.display = "none";
		}
		else
		{
			opponentSearch.style.display = "block";
			opponentNotFound.style.display = "none";
			opponentSearch.innerHTML = ajaxRequestObj.responseText; 
		}
}

