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,bot){
switch(which){
case 0:
document.getElementById('rightcontent').innerHTML="<p class='bodyheader' align='center'>Contact Support</p>\n\
<p class='body'>Messages should be accompanied by an error log where possible. \n\
To send an errorlog, press the save error button after the bot stops or when the error occurs.\n\
Upload the file by navigating to the folder where you installed Casibot using the box below and looking for a file called \n\
'errorlog.zip'.</p>" + "<form enctype='multipart/form-data' action='mail.php' method='post' onsubmit='return mailCheck()'>\n\
<table align='center'><tr><td class='form'>Username:</td><td class='form'>\n\
<input type = 'hidden' name = 'username' id = 'username' value='" + username + "'>" + username + "</td></tr>\n\
<input type = 'hidden' name = 'bot' id = 'bot' value='" + bot + "'>\n\
<tr><td class='form'>Your Email:</td><td> <input type = 'text' name = 'email' id = 'email' size='52' maxlength='50'></td></tr>\n\
<tr><td class='form'>Subject:</td><td> <input type = 'text' name = 'subject' id = 'subject' size='52' maxlength='50'></td></tr>\n\
<tr><td class='form'>Message:</td><td> <textarea cols='40' rows='8' name = 'emailbody' id = 'emailbody'></textarea></td></tr>\n\
<tr><td class='form'>Error log:</td><td><input id='uploaded' name='uploaded' type='file' /></td></tr>\n\
<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>\n\
<p class='body'>Please note that this will not alter your Forum password.</p>\n\
<form action='changepass.php' method='post' onsubmit='return passCheck()'>\n\
<table align='center'>\n\
<tr>\n\
<td class='form'>Username:</td>\n\
<td><input type = 'text' name = 'new_username' id = 'new_username' value='" + username + "' maxlength='12' size='15'></td>\n\
</tr>\n\
<input type='hidden' name='username' id='username' value='" + username + "'>\n\
<input type = 'hidden' name = 'bot' id = 'bot' value='" + bot + "'>\n\
<td class='form'>Current Password:</td>\n\
<td> <input type = 'password' name = 'curr_password' id = 'curr_password' maxlength='15' size='25'></td></tr>\n\
<tr>\n\
<td class='form'>New Password:</td>\n\
<td><input type = 'password' name = 'new_password1' id = 'new_password1' maxlength='15' size='25'></td></tr>\n\
<tr><td class='form'>New Password:</td>\n\
<td><input type = 'password' name = 'new_password2' id = 'new_password2' maxlength='15' size='25'></td></tr>\n\
<tr><td class='form' colspan=2 align='center'><input type='submit' name='passchange' id='passchange' vale='submit'></td></tr>\n\
</table></form>\n\
<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>\n\
<form action='changeemail.php' method='post' onsubmit='return emailCheck()'>\n\
<table align='center'><input type='hidden' name='username' id='username' value='" + username + "'>\n\
<input type = 'hidden' name = 'bot' id = 'bot' value='" + bot + "'>\n\
<td class='form'>Password:</td><td> <input type = 'password' name = 'password' id = 'password' maxlength='15' size='25'></td></tr>\n\
<tr><td class='form'>New Email:</td><td> <input type = 'text' name = 'email' id = 'email' maxlength='50' size='50'></td></tr>\n\
<tr><td class='form' colspan=2 align='center'><input type='submit' name='emailchange' id='emailchange' vale='submit'></td></tr>\n\
</table></form>\n\
<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>\n\
<form action='linkbot.php' method='post' onsubmit='return botCheck(\"linkbot.php\")'><table align='center'>\n\
<input type='hidden' name='bottype' id='bottype' value='thb'>\n\
<input type = 'hidden' name = 'bot' id = 'bot' value='" + bot + "'>\n\
<input type='hidden' name='username' id='username' value='" + username + "'>\n\
<tr>\n\
<td class='form'>Holdem Bot Username:</td><td> <input type = 'text' name = 'botid' id = 'botid' maxlength='20' size='20'></td>\n\
</tr>\n\
<tr>\n\
<td class='form'>Holdem Bot Serial:</td><td> <input type = 'text' name = 'botserial' id = 'botserial' maxlength='20' size='20'></td>\n\
</tr>\n\
<tr><td class='form' colspan=2 align='center'><input type='submit' name='addbot' id='addbot' value='Submit'></td></tr>\n\
</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>\n\
<form action='linkbot.php' method='post' onsubmit='return botCheck(\"linkbot.php\")'><table align='center'>\n\
<input type='hidden' name='bottype' id='bottype' value='vp'>\n\
<input type = 'hidden' name = 'bot' id = 'bot' value='" + bot + "'>\n\
<input type='hidden' name='username' id='username' value='" + username + "'>\n\
<tr>\n\
<td class='form'>Video Poker Bot Username:</td><td> <input type = 'text' name = 'botid' id = 'botid' maxlength='20' size='20'></td>\n\
</tr>\n\
<tr>\n\
<td class='form'>Video Poker Bot Serial:</td><td> <input type = 'text' name = 'botserial' id = 'botserial' maxlength='20' size='20'></td>\n\
</tr>\n\
<tr><td class='form' colspan=2 align='center'><input type='submit' name='addbot' id='addbot' value='Submit'></td></tr>\n\
</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>\n\
<form action='linkbot.php' method='post' onsubmit='return botCheck(\"linkbot.php\")'><table align='center'>\n\
<input type='hidden' name='bottype' id='bottype' value='chb'>\n\
<input type = 'hidden' name = 'bot' id = 'bot' value='" + bot + "'>\n\
<input type='hidden' name='username' id='username' value='" + username + "'>\n\
<tr>\n\
<td class='form'>Casino Holdem Bot Username:</td><td> <input type = 'text' name = 'botid' id = 'botid' maxlength='20' size='20'></td>\n\
</tr>\n\
<tr>\n\
<td class='form'>Casino Holdem Bot Serial:</td><td> <input type = 'text' name = 'botserial' id = 'botserial' maxlength='20' size='20'></td>\n\
</tr>\n\
<tr><td class='form' colspan=2 align='center'><input type='submit' name='addbot' id='addbot' value='Submit'></td></tr>\n\
</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 8:
document.getElementById('rightcontent').innerHTML="<p class='bodyheader' align='center'>Link Custom Bot</p>\n\
<form action='linkbot.php' method='post' onsubmit='return botCheck(\"linkbot.php\")'><table align='center'>\n\
<input type='hidden' name='bottype' id='bottype' value='custom'>\n\
<input type = 'hidden' name = 'bot' id = 'bot' value='" + bot + "'>\n\
<input type='hidden' name='username' id='username' value='" + username + "'>\n\
<tr>\n\
<td class='form'>Custom Bot Username:</td><td> <input type = 'text' name = 'botid' id = 'botid' maxlength='20' size='20'></td>\n\
</tr>\n\
<tr>\n\
<td class='form'>Custom Bot Serial:</td><td> <input type = 'text' name = 'botserial' id = 'botserial' maxlength='20' size='20'></td>\n\
</tr>\n\
<tr><td class='form' colspan=2 align='center'><input type='submit' name='addbot' id='addbot' value='Submit'></td></tr>\n\
</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 9:
document.getElementById('rightcontent').innerHTML="<p class='bodyheader' align='center'>Link Blackjack Bot</p>\n\
<form action='linkbot.php' method='post' onsubmit='return botCheck(\"linkbot.php\")'><table align='center'>\n\
<input type='hidden' name='bottype' id='bottype' value='bj'>\n\
<input type = 'hidden' name = 'bot' id = 'bot' value='" + bot + "'>\n\
<input type='hidden' name='username' id='username' value='" + username + "'>\n\
<tr>\n\
<td class='form'>Blackjack Bot Username:</td><td> <input type = 'text' name = 'botid' id = 'botid' maxlength='20' size='20'></td>\n\
</tr>\n\
<tr>\n\
<td class='form'>Blackjack Bot Serial:</td><td> <input type = 'text' name = 'botserial' id = 'botserial' maxlength='20' size='20'></td>\n\
</tr>\n\
<tr><td class='form' colspan=2 align='center'><input type='submit' name='addbot' id='addbot' value='Submit'></td></tr>\n\
</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 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)
    + "&bot=" + escape(document.getElementById('bot').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.");
 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)
    + "&bot=" + escape(document.getElementById('bot').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)
    + "&bot=" + escape(document.getElementById('bot').value)
    + "&bottype=" + escape(document.getElementById('bottype').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 setChangeMailError(text){
document.getElementById('changeemailerror').innerHTML=text;
}
function setBotError(text){
document.getElementById('boterror').innerHTML=text;
}

function mailCheck(){
if(document.getElementById('uploaded').value) return true;

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)
    + "&bot=" + escape(document.getElementById('bot').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;

}
