var http = getHTTPObject(); // We create the HTTP Object
var isWorking = false;
var responsediv="           ";
var holdprevious = "...";

function pc1_onchange()
{
  document.getElementById("pc2").style.visibility = "visible";
  document.getElementById("pchelp").innerHTML = "Enter a different players name in the second box.";
}
function pc2_onchange()
{
  document.getElementById("pclb").style.visibility = "visible";
  document.getElementById("pchelp").innerHTML = "Click the Go! button when ready.";
}

function handleCompare()
{
var holdmystring;
    document.getElementById("pchelp").innerHTML = " ";
    holdmystring = 'compare.asp?pc1=' + document.getElementById("pc1").value + '&pc2=' + document.getElementById("pc2").value;
    GetContent('compare',holdmystring); 
}


function pccselect_onchange()
{
var holdmystring;
    holdmystring = document.getElementById("pccselect").value;
    GetContent('content',holdmystring); 
}

function handleSearch()
{
var holdmystring;
    holdmystring = 'findplayer.asp?playername=' + document.getElementById("searchtext").value;
    GetContent('content',holdmystring); 
}


function GetContent(divtag,fullurl) {

  if ((fullurl == 'precompare.asp') && (holdprevious.indexOf('Comparison Results') > -1)) {
    document.getElementById('content').innerHTML = holdprevious;
  }
  else if (!isWorking && http) {
    var b = document.getElementById(divtag);
    responsediv = divtag;
    if ((fullurl.indexOf('getgamedetail') == -1) && (b.innerHTML.indexOf('Search Results For') == -1)) {
        holdprevious = b.innerHTML;
    }
    b.innerHTML = "<br><br><table align=center><tr><th>Loading&nbsp;<img src=img/progbar7.gif border=0>&nbsp;Content</th></tr></table>"; 

    http.open("GET", fullurl, true);
    http.onreadystatechange = handleResponse;
    isWorking = true;
    http.send(null);
  }
}

function handleResponse() {
var b = document.getElementById(responsediv); 
  if (http.readyState == 4) { 
    if (http.status == 200) { 
      results = http.responseText;

      b.innerHTML = results;

      isWorking = false;

      if (results.indexOf('precompare') > -1) {
         document.getElementById("pc1").focus();
         document.getElementById("pc2").style.visibility = "hidden";
         document.getElementById("pclb").style.visibility = "hidden";
      }

    }
    else {
		alert("The server has not responded. Check that you have a good internet connection then try again:" + http.status);
      	isWorking = false;
		b.innerHTML = "server fetch failure. if the problem persist, please contact support@rogueffl.com";
    }
  }
}

function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
	  xmlhttp.overrideMimeType("text/xml"); 
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

function ShowPrevious() {
      var b = document.getElementById("content"); 
      b.innerHTML = holdprevious;
      isWorking = false;
}


var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")

function countdown(yr,m,d,hr,min){
theyear=yr;themonth=m;theday=d;thehour=hr;theminute=min
    var today=new Date()
    var todayy=today.getYear()
    if (todayy < 1000) {todayy+=1900}
    var todaym=today.getMonth()
    var todayd=today.getDate()
    var todayh=today.getHours()
    var todaymin=today.getMinutes()
    var todaysec=today.getSeconds()
    var todaystring1=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
    var todaystring=Date.parse(todaystring1)+(tz*1000*60*60)
    var futurestring1=(montharray[m-1]+" "+d+", "+yr+" "+hr+":"+min);
    var futurestring=Date.parse(futurestring1)-(today.getTimezoneOffset()*(1000*60));
    var dd=futurestring-todaystring
    var dday=Math.floor(dd/(60*60*1000*24)*1)
    var dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
    var dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
    var dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)
    if(dday<=0&&dhour<=0&&dmin<=0&&dsec<=0){
        document.getElementById('count2').innerHTML=current;
        document.getElementById('count2').style.display="block";
        document.getElementById('count2').style.width="150px";
        document.getElementById('dday').style.display="none";
        document.getElementById('dhour').style.display="none";
        document.getElementById('dmin').style.display="none";
        document.getElementById('dsec').style.display="none";
        document.getElementById('days').style.display="none";
        document.getElementById('hours').style.display="none";
        document.getElementById('minutes').style.display="none";
        document.getElementById('seconds').style.display="none";
        document.getElementById('spacer1').style.display="none";
        document.getElementById('spacer2').style.display="none";
        return;
    }
    else {
        document.getElementById('count2').style.display="none";
        document.getElementById('dday').innerHTML=dday;
        document.getElementById('dhour').innerHTML=dhour;
        document.getElementById('dmin').innerHTML=dmin;
        document.getElementById('dsec').innerHTML=dsec;
        setTimeout("countdown(theyear,themonth,theday,thehour,theminute)",1000);
    }
}

