function Trim(s) 
{
 // Remove leading spaces and carriage returns
 while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  { s = s.substring(1,s.length); }

 // Remove trailing spaces and carriage returns
while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  { s = s.substring(0,s.length-1); }

 return s;
}

function isInteger(val){
	if (isBlank(val)){return false;}
	for(var i=0;i<val.length;i++){
		if(!isDigit(val.charAt(i))){return false;}
		}
	return true;
	}
function isBlank(val){
	if(val==null){return true;}
	for(var i=0;i<val.length;i++) {
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
		}
	return true;
	}
function isDigit(num) {
	if (num.length>1){return false;}
	var string="1234567890";
	if (string.indexOf(num)!=-1){return true;}
	return false;
	}

function GCForm_Validator(theForm)
{
    // Check that an appointment time is chosen
    if (Trim(theForm.elements["amount"].value) == "")
    {  
 	   alert("Please enter a gift card amount.");
 	   theForm.elements["amount"].focus();
 	   return (false);
    }

    // Check that an appointment time is chosen
    if ( isInteger(theForm.elements["amount"].value) == false || Number(theForm.elements["amount"].value) < '50' )
    {  
 	   alert("The gift card amount must be a whole number of at least $50.");
 	   theForm.elements["amount"].focus();
 	   return (false);
    }
    
    theForm.elements["item_name"].value = "$" + theForm.elements["amount"].value + " Spargo Gift Card";
    theForm.elements["item_number"].value = theForm.elements["amount"].value + "_GC";
    //if your validation has gotten this far, that means there is no error
    return true;
  }

function Form1_Validator(theForm)
{
// Check that an appointment time is chosen
if (Trim(theForm.elements["TimeBlock"].value) == "")
    {  
 	   alert("Please select a time block");
 	   theForm.elements["TimeBlock"].focus();
 	   return (false);
    }
// Check that service is chosen
// set var checkbox_choices to zero
var checkbox_choices = 0;
var checkbox_field = theForm.elements["service[]"];
// Loop from zero to the one minus the number of checkbox button selections
for (counter = 0; counter < checkbox_field.length; counter++)
{

    // If a checkbox has been selected it will return true
    // (If not it will return false)
    if (checkbox_field[counter].checked)
    { checkbox_choices = checkbox_choices + 1; }

}
if ( checkbox_choices < 1 )
    {  
 	   alert("Please select a desired service");
 	   return (false);
    }	
//Check that eamil is not null
if (Trim(theForm.elements["email"].value) == "")
    {  
 	   alert("Please enter a valid email address");
 	   theForm.elements["email"].focus();
 	   return (false);
    }
// check if both email fields are the same
if (theForm.email.value != theForm.MyEmail.value)
{
	alert("The two emails are not the same.");
	theForm.MyEmail.focus();
	return (false);
}
if (Trim(theForm.elements["FirstName"].value) == "")
    {  
 	   alert("Please enter a first name");
 	   theForm.elements["FirstName"].focus();
 	   return (false);
    }
    
    //if your validation has gotten this far, that means there is no error
    return true;
  }