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 alp_onchange()
{
  document.getElementById("allb").style.visibility = "visible";
  document.getElementById("alhelp").innerHTML = "Click the Go! button when ready.";
}

function handleMgowLogon()
{
var holdmystring;
    document.getElementById("alhelp").innerHTML = " ";
    holdmystring = 'mgowlogon.asp?alp=' + document.getElementById("alp").value;
    GetContent('content',holdmystring); 
}

function mgowselect_onchange(contest)
{
var holdmystring;
var holdmyid;
  holdmyid = 'mgowselect' + contest;
  holdmystring = 'mgow_sub_mgowselect.asp?contest=' + contest + '&mgow=' + encodeURI(document.getElementById(holdmyid).value);
  GetContent('content',holdmystring);
}

function maplist_onchange( groupName )
{
var holdmystring;
  holdmystring = 'mgowAddMapToGroup.asp?group=' + groupName + '&map=' +  document.getElementById("maplist").value;
  holdmystring = encodeURI( holdmystring );
  GetContent('mapGroupWork',holdmystring);
}

function mgowshow_onchange()
{
var holdmystring;
  holdmystring = 'mgowShowGroup.asp?group=' + encodeURI(document.getElementById("mgowshow").value);
  GetContent('mapGroupWork',holdmystring);
}

function nmg_onchange()
{
  document.getElementById("nmglb").style.visibility = "visible";
  document.getElementById("nmghelp").innerHTML = "Click the Create It! button when ready.";
}

function handleNmg()
{
var holdmystring;
    document.getElementById("nmghelp").innerHTML = " ";
    document.getElementById("nmg").value = encodeURI(document.getElementById("nmg").value);
    if(document.getElementById("nmg").value.indexOf("+") > -1){ 
        document.getElementById("nmg").value = document.getElementById("nmg").value.replace("+","%2B")
    }
    holdmystring = 'mgowCreateNmg.asp?nmg=' + document.getElementById("nmg").value;
    GetContent('mapGroupWork',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,origurl) {
var fullurl;

if ( origurl.indexOf('?') > -1) {
  fullurl = origurl;
}
else {
  fullurl = origurl + '?dummy=0';
}
  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 + "&timestamp=" + new Date().getTime(), 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('id=precompare') > -1) {
         document.getElementById("pc1").focus();
         document.getElementById("pc2").style.visibility = "hidden";
         document.getElementById("pclb").style.visibility = "hidden";
      }
      if (results.indexOf('id=premgowadmin') > -1) {
               document.getElementById("alp").focus();
               document.getElementById("allb").style.visibility = "hidden";
      }
      if (results.indexOf('id=nmghelp') > -1) {
               document.getElementById("nmg").focus();
               document.getElementById("nmglb").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@roguepack.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);
    }
}


