
function checkIt(){
        if(document.getElementById('agree').checked){
           document.getElementById('jse').value="yes";
           return true;
        }
        alert("You must read and agree to the rules to continue");
        return false;
}

function ReloadImg(){
    var cImg= document.getElementById("captcha");
    cImg.src = "reloading.gif";
    setTimeout("resetImage()",1000);
}

function remove(){	alert("Why would such a cool Craig want to be removed from such a cool list?\nWe know you don't really mean it.");
	}

function resetAll(){
    ReloadImg();
    document.getElementById("captcha_codetext").innerHTML="Please enter the 5 characters above:";
    document.getElementById("linktext").innerHTML="Link, if providing one:";
    document.getElementById("emailtext").innerHTML="What is your email address?";
}


function resetImage(){
   var rand=(new Date()).getTime();
   document.getElementById("captcha").src="createcaptcha.php?"+rand;
}

function trim(inputString) {
           // Removes leading and trailing spaces from the passed string. Also removes
           // consecutive spaces and replaces it with one space. If something besides
           // a string is passed in (null, custom object, etc.) then return the input.
           if (typeof inputString != "string") { return inputString; }
           var retValue = inputString;
           var ch = retValue.substring(0, 1);
           while (ch == " ") { // Check for spaces at the beginning of the string
              retValue = retValue.substring(1, retValue.length);
              ch = retValue.substring(0, 1);
           }
           ch = retValue.substring(retValue.length-1, retValue.length);
           while (ch == " ") { // Check for spaces at the end of the string
              retValue = retValue.substring(0, retValue.length-1);
              ch = retValue.substring(retValue.length-1, retValue.length);
           }
           while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
              retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
           }
           return retValue; // Return the trimmed string back to the user
        } // Ends the "trim" function

function getAjaxObj (){
   var xmlhttp = false;
   //for IE
   try {
   //for 5+
     xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
   }
   catch (e) {
     //IE 4
     try {
     //last IE check
       xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
     }
     catch (E) {
     //not using IE
       xmlhttp = false;
     }
   }
  //non-IE
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
       xmlhttp = new XMLHttpRequest();
  }
   return xmlhttp;
}

var ajax = getAjaxObj();

function checkremovehttp(url){
         if(url.indexOf("http://")==0){
            url=url.substr(7);
         }
         return url;
}

function checkElement(what){
        var val=document.getElementById(what).value;
        if(what=='link'){
          val=checkremovehttp(val);
          document.getElementById(what).value=val;
        }
        val=encodeURIComponent(val);
        var rand = Math.random();
        switch(what){
               case 'captcha_code':
                     var the_url = "validate.php?subject=captcha&cinput="+val+"&rand="+rand;;
                     ajax.open("GET",the_url,true);
                     ajax.onreadystatechange = function(){
                          if((ajax.readyState == 4)&&(ajax.status==200)){
                            var response = ajax.responseText;
                            var rep=response.indexOf("###");
                            if(rep!=-1){
                             var code=response.slice(rep+3,response.length);
                             document.getElementById("code").value=code;
                             response=response.slice(0,rep);
                            }
                          document.getElementById("captcha_codetext").innerHTML=response;
                          }
                     }
                     ajax.send(null);
                     break;
               case 'link':
                     document.getElementById("linktext").innerHTML="Checking link, please wait...";
                     var the_url = "validate.php?subject=link&linput="+val+"&rand="+rand;
                     ajax.open("GET",the_url,true);
                     ajax.onreadystatechange = function(){
                          if((ajax.readyState == 4)&&(ajax.status==200)){
                          document.getElementById("linktext").innerHTML=ajax.responseText;
                          }
                     }
                     ajax.send(null);
                     break;
               case 'email':
                     document.getElementById("emailtext").innerHTML="Checking Email, please wait...";
                     var the_url = "validate.php?subject=email&einput="+val+"&rand="+rand;
                     ajax.open("GET",the_url,true);
                     ajax.onreadystatechange = function(){
                          if((ajax.readyState == 4)&&(ajax.status==200)){
                              var response="";
                              var loc=0;
                              response=ajax.responseText;
                              loc=response.indexOf("%%NAME%%");
                              if(loc!=-1){
                                  var email=response.substr(0,loc);
                                  loc+=8;
                                  var name=response.substr(loc,response.length);
                                  document.getElementById("emailtext").innerHTML=email;
                                  document.getElementById("username").value=name;
                              }
                              else
                                  document.getElementById("emailtext").innerHTML=response;
                          }
                     }
                     ajax.send(null);
                     break;
               case 'agree':
                     if(!document.getElementById("agree").checked){
                         alert("You must read and agree to the rules to continue");
                     }
                     break;
        }
}

function checkform(){
        if(document.getElementById("lastagree").value=="yes"){
           if(document.getElementById("agree").checked){
              if(ajax){
                 document.getElementById("jse").value="yes";
                 return true;
              }
           }
           else{
                alert("You must still agree to the rules!");
                return false;
           }
        }
        alert("Please make sure you have JavaScript enabled\n and are running a 5.0+ browser");
        return false;
}


function Checkload(){
         checkElement("email");
         checkElement("link");
         checkform();
}