function loginCheck(){
var tempstring = document.getElementById('username').value;
  document.getElementById('username').value = tempstring.replace(/^\s+|\s+$/g, '');
tempstring = document.getElementById('password').value;
  document.getElementById('password').value = tempstring.replace(/^\s+|\s+$/g, '');
if(!document.getElementById('username').value){
document.getElementById('username').value = '<Enter your username>';
 return false;
 }
if(!document.getElementById('password').value){
setLoginError("Enter your password!");
 return false;
}
return true;
}

function clearBox(){
if(document.getElementById('username').value == '<Enter your username>') document.getElementById('username').value = "";
}

function isNumeric(strString){
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }

function setContent(which,username){
switch(which){
case 0:
document.getElementById('rightcontent').innerHTML="<p class='bodyheader' align='center'>Contact Support</p>\n" + "<form action='mail.php' method='post' onsubmit='return mailCheck()'><table align='center'><tr><td class='form'>Username:</td><td class='form'><input type = 'hidden' name = 'username' id = 'username' value='" + username + "'>" + username + "</td></tr><td class='form'>Your Email:</td><td> <input type = 'text' name = 'email' id = 'email' size='52' maxlength='50'></td></tr><tr><td class='form'>Subject:</td><td> <input type = 'text' name = 'subject' id = 'subject' size='52' maxlength='50'></td></tr>" + "<tr><td class='form'>Message:</td><td> <textarea cols='40' rows='8' name = 'emailbody' id = 'emailbody'></textarea></td></tr><tr><td colspan=2 align='center' class='form'><input type='submit' id='sendmail' name='mail' value='Send Email'></td></tr></table></form>" + "<span style='text-align:center'><div id='mailerror' class='error'></div></span>";
document.getElementById('bonusoffers').style.display="none";
document.getElementById('versionhistory').style.display="none";
document.getElementById('sessions').style.display="none";
break;
case 1:
document.getElementById('rightcontent').innerHTML="<p class='bodyheader' align='center'>Change Details</p><p class='body'>Please note that this will not alter your Forum password.</p>" + "<form action='changepass.php' method='post' onsubmit='return passCheck()'><table align='center'> <tr><td class='form'>Username:</td><td> <input type = 'text' name = 'new_username' id = 'new_username' value='" + username + "' maxlength='12' size='15'></td></tr><input type='hidden' name='username' id='username' value='" + username + "'><td class='form'>Current Password:</td><td> <input type = 'password' name = 'curr_password' id = 'curr_password' maxlength='15' size='25'></td></tr>" + "<tr><td class='form'>New Password:</td><td> <input type = 'password' name = 'new_password1' id = 'new_password1' maxlength='15' size='25'></td></tr>" + "<tr><td class='form'>New Password:</td><td> <input type = 'password' name = 'new_password2' id = 'new_password2' maxlength='15' size='25'></td></tr><tr><td class='form' colspan=2 align='center'><input type='submit' name='passchange' id='passchange' vale='submit'></td></tr></table></form>" + "<span style='text-align:center'><div id='changepasserror' class='error'></div></span>";
document.getElementById('bonusoffers').style.display="none";
document.getElementById('versionhistory').style.display="none";
document.getElementById('sessions').style.display="none";
break;
case 2:
document.getElementById('rightcontent').innerHTML="<p class='bodyheader' align='center'>Change Email</p>" + "<form action='changeemail.php' method='post' onsubmit='return emailCheck()'><table align='center'><input type='hidden' name='username' id='username' value='" + username + "'><td class='form'>Password:</td><td> <input type = 'password' name = 'password' id = 'password' maxlength='15' size='25'></td></tr>" + "<tr><td class='form'>New Email:</td><td> <input type = 'text' name = 'email' id = 'email' maxlength='50' size='50'></td></tr><tr><td class='form' colspan=2 align='center'><input type='submit' name='emailchange' id='emailchange' vale='submit'></td></tr></table></form>" + "<span style='text-align:center'><div id='changeemailerror' class='error'></div></span>";
document.getElementById('bonusoffers').style.display="none";
document.getElementById('versionhistory').style.display="none";
document.getElementById('sessions').style.display="none";
break;
case 3:
document.getElementById('rightcontent').innerHTML="";
document.getElementById('bonusoffers').style.display="block";
document.getElementById('sessions').style.display="none";
break;
case 4:
document.getElementById('rightcontent').innerHTML="";
document.getElementById('sessions').style.display="block";
document.getElementById('bonusoffers').style.display="none";
case 5:
document.getElementById('rightcontent').innerHTML="<p class='bodyheader' align='center'>Link Holdem Bonus Bot</p>" + "<form action='linkbot.php' method='post' onsubmit='return botCheck(\"linkbot.php\")'><table align='center'><input type='hidden' name='username' id='username' value='" + username + "'><tr><td class='form'>Holdem Bot Username:</td><td> <input type = 'text' name = 'botid' id = 'botid' maxlength='20' size='20'></td></tr><tr><td class='form'>Holdem Bot Serial:</td><td> <input type = 'text' name = 'botserial' id = 'botserial' maxlength='20' size='20'></td></tr>" + "<tr><td class='form' colspan=2 align='center'><input type='submit' name='addbot' id='addbot' value='Submit'></td></tr></table></form><span style='text-align:center'><div id='boterror' class='error'></div></span>";
document.getElementById('bonusoffers').style.display="none";
document.getElementById('versionhistory').style.display="none";
document.getElementById('sessions').style.display="none";
break;
case 6:
document.getElementById('rightcontent').innerHTML="<p class='bodyheader' align='center'>Link Video Poker Bot</p>" + "<form action='linkvpbot.php' method='post' onsubmit='return botCheck(\"linkvpbot.php\")'><table align='center'><input type='hidden' name='username' id='username' value='" + username + "'><tr><td class='form'>VP Bot Username:</td><td> <input type = 'text' name = 'botid' id = 'botid' maxlength='20' size='20'></td></tr><tr><td class='form'>VP Bot Serial:</td><td> <input type = 'text' name = 'botserial' id = 'botserial' maxlength='20' size='20'></td></tr>" +  "<tr><td class='form' colspan=2 align='center'><input type='submit' name='addbot' id='addbot' value='Submit'></td></tr></table></form><span style='text-align:center'><div id='boterror' class='error'></div></span>";
document.getElementById('bonusoffers').style.display="none";
document.getElementById('versionhistory').style.display="none";
document.getElementById('sessions').style.display="none";
break;
case 7:
document.getElementById('rightcontent').innerHTML="<p class='bodyheader' align='center'>Link Casino Holdem  Bot</p>" + "<form action='linkchbbot.php' method='post' onsubmit='return botCheck(\"linkchbbot.php\")'><table align='center'><input type='hidden' name='username' id='username' value='" + username + "'><tr><td class='form'>Casino Holdem Bot Username:</td><td> <input type = 'text' name = 'botid' id = 'botid' maxlength='20' size='20'></td></tr><tr><td class='form'>Casino Holdem Bot Serial:</td><td> <input type = 'text' name = 'botserial' id = 'botserial' maxlength='20' size='20'></td></tr>" +  "<tr><td class='form' colspan=2 align='center'><input type='submit' name='addbot' id='addbot' value='Submit'></td></tr></table></form><span style='text-align:center'><div id='boterror' class='error'></div></span>";
document.getElementById('bonusoffers').style.display="none";
document.getElementById('versionhistory').style.display="none";
document.getElementById('sessions').style.display="none";
break;
}
}

function addSession(){
if(!document.getElementById('session').value) return false;
var xmlHttp;
  try
    {        
	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;        }      }    }
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
				document.getElementById('sessions').innerHTML += xmlHttp.responseText;
				}
      }
xmlHttp.open("POST","getsessionrow.php",true);
xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xmlHttp.send("&username=" + escape(document.getElementById('username').value) + "&session=" + escape(document.getElementById('session').value));

return false;
}


function passCheck(){
var tempstring = document.getElementById('new_username').value;
  document.getElementById('new_username').value = tempstring.replace(/^\s+|\s+$/g, '');
	tempstring = document.getElementById('curr_password').value;
  document.getElementById('curr_password').value = tempstring.replace(/^\s+|\s+$/g, '');
	tempstring = document.getElementById('new_password1').value;
  document.getElementById('new_password1').value = tempstring.replace(/^\s+|\s+$/g, '');
	tempstring = document.getElementById('new_password2').value;
  document.getElementById('new_password2').value = tempstring.replace(/^\s+|\s+$/g, '');
if(!document.getElementById('new_username').value){
 setChangePassError("Enter a new username");
 return false;
 }   
  
if(document.getElementById('new_username').value!=document.getElementById('username').value&&isNumeric(document.getElementById('new_username').value)){
 setChangePassError("Username can't consist of only numbers!");
 return false;
 }  
if(!document.getElementById('curr_password').value){
 setChangePassError("Enter your old password!");
 return false;
}
if(!document.getElementById('new_password1').value){
 setChangePassError("Enter your new password!");
 return false;
}
if(document.getElementById('new_password1').value!=document.getElementById('new_password2').value){
setChangePassError("Passwords Don't Match!");
return false;
}	
setChangePassError("Changing Password...");
document.getElementById('passchange').disabled = true;
var xmlHttp;
  try
    {        
	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;        }      }    }
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
				setChangePassError(xmlHttp.responseText);
				document.getElementById('passchange').disabled = false;
				}
      }
xmlHttp.open("POST","changepass.php",true);
xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xmlHttp.send("curr_password=" + escape(document.getElementById('curr_password').value) + "&username=" + escape(document.getElementById('username').value) + "&new_username=" + escape(document.getElementById('new_username').value) + "&new_password1=" + escape(document.getElementById('new_password1').value));

return false;

}

function emailCheck(){
var tempstring = document.getElementById('username').value;
  document.getElementById('username').value = tempstring.replace(/^\s+|\s+$/g, '');
	tempstring = document.getElementById('password').value;
  document.getElementById('password').value = tempstring.replace(/^\s+|\s+$/g, '');
	tempstring = document.getElementById('email').value;
  document.getElementById('email').value = tempstring.replace(/^\s+|\s+$/g, '');

if(!document.getElementById('username').value){
 setChangeMailError("Username missing, please log in again.");
 return false;
 }
if(!document.getElementById('email').value){
 setChangeMailError("Email missing, please log in again.");
 return false;
 }      
if(!document.getElementById('password').value){
 setChangeMailError("Enter your old password!");
 return false;
}
if(!isEmail(document.getElementById('email').value)){
 setChangeMailError("Email address isn't valid");
 return false;
 }  
setChangeMailError("Changing Email...");
document.getElementById('emailchange').disabled = true;
var xmlHttp;
  try
    {        
	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;        }      }    }
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
				setChangeMailError(xmlHttp.responseText);
				document.getElementById('emailchange').disabled = false;
				}
      }
xmlHttp.open("POST","changeemail.php",true);
xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xmlHttp.send("password=" + escape(document.getElementById('password').value) + "&username=" + escape(document.getElementById('username').value) + "&email=" + escape(document.getElementById('email').value));

return false;

}

function botCheck(boturl){
var tempstring = document.getElementById('username').value;
  document.getElementById('username').value = tempstring.replace(/^\s+|\s+$/g, '');
	
	tempstring = document.getElementById('botid').value;
  document.getElementById('botid').value = tempstring.replace(/^\s+|\s+$/g, '');
  tempstring = document.getElementById('botserial').value;
    document.getElementById('botserial').value = tempstring.replace(/^\s+|\s+$/g, '');

if(!document.getElementById('username').value){
 setBotError("Username missing, please log in again.");
 return false;
 }
if(!document.getElementById('botid').value){
 setBotError("Bot username missing, please log in again.");
 return false;
 }      

if(!document.getElementById('botserial').value){
 setBotError("Bot serial missing!");
 return false;
 }  
setBotError("Linking Bot...");
document.getElementById('addbot').disabled = true;
var xmlHttp;
  try
    {        
	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;        }      }    }
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
				setBotError(xmlHttp.responseText);
				document.getElementById('addbot').disabled = false;
				}
      }
xmlHttp.open("POST",boturl,true);
xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xmlHttp.send("&username=" + escape(document.getElementById('username').value) + "&botid=" + escape(document.getElementById('botid').value) + "&botserial=" + escape(document.getElementById('botserial').value));

return false;

}

function setChangePassError(text){
document.getElementById('changepasserror').innerHTML=text;
}
function setLoginError(text){
document.getElementById('loginerror').innerHTML=text;
}
function setMailError(text){
document.getElementById('mailerror').innerHTML=text;
}
function setBotError(text){
document.getElementById('changeemailerror').innerHTML=text;
}
function setBotError(text){
document.getElementById('boterror').innerHTML=text;
}

function mailCheck(){
var tempstring = document.getElementById('email').value;
  document.getElementById('email').value = tempstring.replace(/^\s+|\s+$/g, '');
tempstring = document.getElementById('subject').value;
  document.getElementById('subject').value = tempstring.replace(/^\s+|\s+$/g, '');  
tempstring = document.getElementById('emailbody').value;
  document.getElementById('emailbody').value = tempstring.replace(/^\s+|\s+$/g, '');
  
if(!document.getElementById('email').value){
 setMailError("Enter your email address");
 return false;
 }   
if(!isEmail(document.getElementById('email').value)){
 setMailError("Your email address is not valid");
 return false;
 } 
if(!document.getElementById('subject').value){
 setMailError("Subject field must not be left blank");
 return false;
 } 
if(!document.getElementById('emailbody').value){
 setMailError("Message must not be left blank");
 return false;
 } 
setMailError("Email being Sent...");
document.getElementById('sendmail').disabled = true;
var xmlHttp;
  try
    {        
	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;        }      }    }
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
				setMailError(xmlHttp.responseText);
				document.getElementById('sendmail').disabled = false;
				}
      }
xmlHttp.open("POST","mail.php",true);
xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xmlHttp.send("email=" + escape(document.getElementById('email').value) + "&username=" + escape(document.getElementById('username').value) + "&emailbody=" + escape(document.getElementById('emailbody').value) + "&subject=" + escape(document.getElementById('subject').value));

return false;

}


function isEmail(argvalue) {

  if (argvalue.indexOf(" ") != -1)
    return false;
  else if (argvalue.indexOf("@") == -1)
    return false;
  else if (argvalue.indexOf("@") == 0)
    return false;
  else if (argvalue.indexOf("@") == (argvalue.length-1))
    return false;

  // arrayString = argvalue.split("@"); (works only in netscape3 and above.)
  var retSize = customSplit(argvalue, "@", "arrayString");

  if (arrayString[1].indexOf(".") == -1)
    return false;
  else if (arrayString[1].indexOf(".") == 0)
    return false;
  else if (arrayString[1].charAt(arrayString[1].length-1) == ".") {
    return false;
  }

  return true;
 
}

function customSplit(strvalue, separator, arrayName) {
  var n = 0;

  if (separator.length != 0) {
    while (strvalue.indexOf(separator) != -1) {
      eval("arr"+n+" = strvalue.substring(0, strvalue.indexOf(separator));");
      strvalue = strvalue.substring(strvalue.indexOf(separator)+separator.length,
          strvalue.length+1);
      n++;
    }
    eval("arr" + n + " = strvalue;");
    arraySize = n+1;
  }
  else {
    for (var x = 0; x < strvalue.length; x++) {
      eval("arr"+n+" = \"" + strvalue.substring(x, x+1) + "\";");
      n++;
    }
    arraySize = n;
  }

  eval(arrayName + " = new makeArray(arraySize);");

  for (var i = 0; i < arraySize; i++)
    eval(arrayName + "[" + i + "] = arr" + i + ";");

  return arraySize;
}

function makeArray(IntarrSize) {

  for (var n = 0; n < IntarrSize; n++)
    this[n] = "";

  return this;

}
