
function CheckRegBoxes(theboxid) {

    thebox1 = document.getElementById('cbyes1');
    thebox2 = document.getElementById('cbyes2');
    thebox3 = document.getElementById('cbyes3');
    thebox4 = document.getElementById('cbyes4');
    thebox5 = document.getElementById('cbyes5');

    if (thebox1.checked && thebox2.checked && thebox3.checked && thebox4.checked && thebox5.checked) {
       thesub = document.getElementById('regformsubmit');
       thesub.disabled=false;
    } else {
       thesub.disabled=true;
    }
}

function trim(s)
{
	var l=0; 
        var r=s.length -1;
	while(l < s.length && s[l] == ' ') {	
            l++; 
        }
	while(r > l && s[r] == ' ') {	
            r-=1;	
        }
	return s.substring(l, r+1);
}

function IsEmpty(textValue) {
   if (textValue==null) return true;

   var trimmed = textValue.replace(/^\s+|\s+$/g, '') ;

   if (trimmed.length==0 ) {
      return true;
   } else { 
      return false; 
   }
}	

function IsTooShort(textValue, minLen) {
   if (textValue.length < minLen) {
      return true;
   } else { 
      return false; 
   }
}	

function IsTooLong(textValue, maxLen) {
   if (textValue.length > maxLen) {
      return true;
   } else { 
      return false; 
   }
}	


function IsMismatch(textValue1, textValue2) {
   if (textValue1!=textValue2) {
      return true;
   } else { 
      return false; 
   }
}

function IsAnInteger(textValue) {
   if (parseInt(textValue)!=(textValue-0)) {
      return false;
   } else { 
      return true; 
   }
}

function EndsWith(textValue, str) {
   var len=str.length;
   var tflen=textValue.length;
   var theending=textValue.substring(tflen-len);
   if (theending==str) {
      return true;
   } else { 
      return false; 
   }
}

function HasThisChar(textValue, str) {
   if (textValue.indexOf(str)>=0) {
       return true;
   } else {
       return false;
   }
}

function InvalidEmail(textValue) {
    email = textValue;
    AtPos = email.indexOf("@");
    StopPos = email.lastIndexOf(".");
    if (AtPos == -1 || StopPos == -1) {
        return true;
    } else {
        return false;
    }
}

function InvalidLinkpageName(textValue,sbad) {
   if (textValue==null) return true;
   var tv=trim(textValue);

   var lplower=tv.toLowerCase();

   if (lplower.indexOf(sbad)>=0) {
       return true;
   } else {
       return false;
   }
}	


function ValidateRegForm(form)
{
   if(IsEmpty(form.reg_email.value)) 
   { 
      alert('You have not entered an email address') 
      form.reg_email.focus(); 
      return false; 
   } 
   if(InvalidEmail(form.reg_email.value)) 
   { 
      alert('Please enter a valid email address') 
      form.reg_email.focus(); 
      return false; 
   } 
   if(IsEmpty(form.reg_pw.value)) 
   { 
      alert('You have not entered a password') 
      form.reg_pw.focus(); 
      return false; 
   } 
   if(IsEmpty(form.reg_pw2.value)) 
   { 
      alert('You must verify your password') 
      form.reg_pw2.focus(); 
      return false; 
   } 
   if(IsMismatch(form.reg_pw.value, form.reg_pw2.value)) 
   { 
      alert('Passwords do not match') 
      form.reg_pw2.focus(); 
      return false; 
   } 
   if(IsTooShort(form.reg_pw.value,6)) 
   { 
      alert('Your password should be at least 6 characters long') 
      form.reg_pw.focus(); 
      return false; 
   } 
   if(IsEmpty(form.reg_firstname.value)) 
   { 
      alert('You have not entered a firstname') 
      form.reg_firstname.focus(); 
      return false; 
   } 
   if(IsEmpty(form.reg_lastname.value)) 
   { 
      alert('You have not entered a lastname') 
      form.reg_lastname.focus(); 
      return false; 
   } 

   if(IsEmpty(form.reg_country.value)) 
   { 
      alert('You have not entered a country') 
      form.reg_country.focus(); 
      return false; 
   } 

   return true;
 
} 


