// JavaScript Document
/*
******************************************************************
Created by Julien A. Checkley March 2010
All rights reserved. Please do not remove this disclaimer.
********************************************************************
*/



var msg="";



/*********************************Multi-function-String***************************************/
function checkString(strText, n){
	   if(strText.value ==""){
	     msg += "Please fill out "+ capitaliseFirstLetter(strText.id) + " Field! \n";
		 strText.className = "inputBoxError";	 
		 
	   }else if(strText.value.length < n){
	              msg += ""+ capitaliseFirstLetter(strText.id) + " must be at least " + n + " characters! \n";
		          strText.className = "inputBoxError";
				  
	   }else if (IsNumeric(strText.value)) { 	   
	               msg+="Your "+ capitaliseFirstLetter(strText.id) +" cannot only be numbers! \n";
	               strText.className = "inputBoxError";	   
	   }else{
		         strText.className = "inputBoxCurrect";	
	   }
	
}


/*********************************Multi-function-Numbers***************************************/
function multi(mText, n){
	   if(mText.value ==""){
	     msg += "Please fill out "+ capitaliseFirstLetter(mText.id) + " Field! \n";
		 mText.className = "inputBoxError";	 
		 
	   }else if(mText.value.length < n){
	              msg += ""+ capitaliseFirstLetter(mText.id) + " must be at least " + n + " characters! \n";
		          mText.className = "inputBoxError";
				  
	   }else if (!IsNumeric(mText.value)) { 	   
	               msg+="Please enter only numbers in "+ capitaliseFirstLetter(mText.id) +" Field! \n";
	               mText.className = "inputBoxError";	   
	   }else{
		         mText.className = "inputBoxCurrect";	
	   }
	
}

/*********************************Multi-function-Phone***************************************/
function multiPhone(mpText, n){
	   if(mpText.value ==""){
	     msg += "Please fill out "+ capitaliseFirstLetter(mpText.id) + " Field! \n";
		 mpText.className = "inputBoxError";	 
		 
	   }else if(mpText.value.length < n){
	              msg +=""+ capitaliseFirstLetter(mpText.id) + " must be at least " + n + " characters! \n";
		          mpText.className = "inputBoxError";
				  
	   }else if (!IsNumeric(mpText.value)) { 	   
	               msg+=""+ capitaliseFirstLetter(mpText.id) +" number must be as e.g. 123-456-7890! \n";
	               mpText.className = "inputBoxError";	   
	   }else{
		         mpText.className = "inputBoxCurrect";	
	   }
	
}


/*********************************Multi-function-Phone-ALTERNATE***************************************/
function checkPhoneNR(nrText, n){
	   if(nrText.value !=""){	 
	      if(nrText.value.length < n){
	              msg +=""+ capitaliseFirstLetter(nrText.id) + " must be at least " + n + " characters! \n";
		          nrText.className = "inputBoxError";
				  
	      }else if (!IsNumeric(nrText.value)) { 	   
	               msg+=""+ capitaliseFirstLetter(nrText.id) +" number must be as e.g. 123-456-7890! \n";
	               nrText.className = "inputBoxError";	   
	      }else{
		         nrText.className = "inputBoxCurrect";	
	   }
	
	
    }
}

/*********************************Multi-function-Zip***************************************/
function multiZip(mZText, n){
	   if(mZText.value ==""){
	              msg += "Please fill out "+ capitaliseFirstLetter(mZText.id) + " Field! \n";
		          mZText.className = "inputBoxError";	 
		 
	   }else if(mZText.value.length < n){
	              msg += ""+ capitaliseFirstLetter(mZText.id) + " must be at least " + n + " characters! \n";
		          mZText.className = "inputBoxError";
				  
	   }else if (!IsZip(mZText.value)) { 	   
	               msg+="Please enter only numbers in "+ capitaliseFirstLetter(mZText.id) +" Field! \n";
	               mZText.className = "inputBoxError";	   
	   }else{
		           mZText.className = "inputBoxCurrect";	
	   }
	
}
/********************Check for Empty Form Fields**************************************/
function IsEmpty(eText){
	
   if(eText.value ==""){
	     msg += "Please fill out "+ capitaliseFirstLetter(eText.id) + " Field! \n";
		 eText.className = "inputBoxError";	   
	}else{
		 eText.className = "inputBoxCurrect";	
	}
		
}

/*************************************************************************************/


/********************Check value lengthForm Fields**************************************/
function validateLength(lText, num){

  if(lText.value !=""){
        if(lText.value.length < num){
	              msg += ""+ capitaliseFirstLetter(lText.id) + " must be at least " + num + " characters! \n";
		          lText.className = "inputBoxError";	   
	    }else{
		          lText.className = "inputBoxCurrect";	
	    }
  }
		
}

/************************************************************************************/

/***********************************Validate form fields******************************/
function verifyNumber(vNumber){
   
   if(vNumber.value !=""){
	       if (!IsNumeric(vNumber.value)) 
           { 	   
	               msg+="Please enter only numbers in "+ capitaliseFirstLetter(vNumber.id) +" Field! \n";
	               vNumber.className = "inputBoxError";	   
	       }else{
		         vNumber.className = "inputBoxCurrect";	
	      }
   }
}


function verifyZip(zNumber){
   if(zNumber.value !=""){
	 if (!IsZip(zNumber.value)) 
      { 
           msg+="Please enter only numbers in "+ capitaliseFirstLetter(zNumber.id) +" Field! \n";
	       zNumber.className = "inputBoxError";	   
	  }else{
		   zNumber.className = "inputBoxCurrect";	
	 }
   }
}

function verifyEmail(mail){
   
   if(mail.value !=""){
	     if (!isValidEmail(mail.value)) 
            { 
	            msg+="Please enter a valid email in "+ capitaliseFirstLetter(mail.id) +" Field! \n";
	            mail.className = "inputBoxError";	   
	        }else{
		        mail.className = "inputBoxCurrect";	
	     }
	
   }
}

function verifyDec(decimal){
   if(decimal.value !=""){
	    if (!IsNumericdec(decimal.value)) 
        { 
               msg+="Please enter only numbers in "+ capitaliseFirstLetter(decimal.id) +" Field! \n";
	           decimal.className = "inputBoxError";	   
	    }else{
		       decimal.className = "inputBoxCurrect";	
    	}
    }
}

function validateStr(vaStr, n){
   
   if(vaStr.value !=""){
	   
	   if(vaStr.value.length < n){
	              msg +=""+ capitaliseFirstLetter(vSatr.id) + " must be at least " + n + " characters! \n";
		          vatr.className = "inputBoxError";
				  
	   }else if (IsNumeric(vaStr.value)) 
           { 	   
	               msg+=""+ capitaliseFirstLetter(vaStr.id) +" cannot be numbers! \n";
	               vaStr.className = "inputBoxError";	   
	       }else{
		         vaStr.className = "inputBoxCurrect";	
	      }
   }
}


function verifyStr(vStr){
   
   if(vStr.value !=""){
	       if (IsNumeric(vStr.value)) 
           { 	   
	               msg+=""+ capitaliseFirstLetter(vStr.id) +" cannot be numbers only! \n";
	               vStr.className = "inputBoxError";	   
	       }else{
		         vStr.className = "inputBoxCurrect";	
	      }
   }
}

function verifyPhone(vPhone){
   
   if(vPhone.value !=""){
	       if (!IsPhone(vPhone.value)) 
           { 	   
	               msg+=""+ capitaliseFirstLetter(vPhone.id) +" number must be as e.g 123-456-7890! \n";
	               vPhone.className = "inputBoxError";	   
	       }else{
		         vPhone.className = "inputBoxCurrect";	
	      }
   }
}



/*************************************************************************************************/

/******************************************Character checking*************************************/
function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
   
function IsNumericdec(dText)
 {
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (j = 0; j < dText.length && IsNumber == true; j++) 
      { 
      Char = dText.charAt(j); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}
  
  
function IsZip(zText)
 {
   var ValidChars = "0123456789-.";
   var IsNumber=true;
   var Char;

 
   for (k = 0; k < zText.length && IsNumber == true; k++) 
      { 
      Char = zText.charAt(k); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}
 
function IsPhone(phoneText)
 {
   var ValidChars = "0123456789-";
   var IsNumber=true;
   var Char;

 
   for (m = 0; m < phoneText.length && IsNumber == true; m++) 
      { 
      Char = phoneText.charAt(m); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}


 function isValidEmail(str) {
	  var filter = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
	   if(!filter.test(str)){
	       return false;
	   }else{
	      return true;
	   }
   }
/********************************************************************************************************/


function verifyAlpha(alpha){
   
     if(alpha.value != ""){
	       if (!isAlphabetic(alpha.value)) 
           { 	   
	               msg+=""+ capitaliseFirstLetter(alpha.id) +" letters or numbers! \n";
	              alpha.className = "inputBoxError";	   
	       }else{
		         alpha.className = "inputBoxCurrect";	
	      }
	 }

}

function isAlphanumeric(elem){
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		return false;
	}
}




function capitaliseFirstLetter(string)
{
    return string.charAt(0).toUpperCase() + string.slice(1);
}




// check to see if input is alphabetic
function isAlphabetic(val)
{
       if (val.match(/^[a-zA-Z]+$/))
       {
           return true;
       }
       else
      {
          return false;
      } 
}


// check to see if input is alphanumeric
function isAlphaNumeric(val)
{
     if (val.match(/^[a-zA-Z0-9]+$/))
      {
          return true;
      }
      else
      {
        return false;
    } 
}
