function trim (strVar) { 
     if(strVar.length >0)
	 {
	        while(strVar.charAt(0)==" ") 
			strVar=strVar.substring(1,strVar.length); 
			while(strVar.charAt(strVar.length-1)==" ") 
			strVar=strVar.substring(0,strVar.length-1); 			
	 }
	 return strVar; 
}

//Not an Alphabet
function isNotAlphabets(str){
		for (var i = 0; i < str.length; i++)
		{
				re = / /gi				//Replace the space between words with no space
				str = str.replace(re,"");
			
				var ch = str.substring(i, i + 1);
				if((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) 
				{
					return true;
				}
		}
		return false;
}
//Not a number
function isNotNumeric(str){
		for (var i = 0; i < str.length; i++)
		{
				var ch = str.substring(i, i + 1);
				if((ch < '0' || '9' < ch)) 
				{
					if((ch == " ") || (ch == "_")  || (ch == ".") || (ch == "-") || (ch == "+")  || (ch == "(") || (ch == ")")) continue;
					return true;
				}
		}
		return false;
}
function isNotID(str){
		for (var i = 0; i < str.length; i++)
		{
				var ch = str.substring(i, i + 1);
				if((ch < '0' || '9' < ch) && ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch))) 
				{
					if((ch == "_") || (ch == "-")  || (ch == "(") || (ch == ")")) continue;
					return true;
				}
		}
		return false;
}

		//Email Function
		function checkEmail(email)
		{
		 if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))
		 {
			return (true)
		 }
			return (false)
		}
		
	//Products Section - Check any check box selected for Add video to Cart
	function check_video_list(chk)
	{
		len = chk.elements.length;
		count=0;
		
		for(i=0;i<len;i++)
		{
			element_type = chk.elements[i].type;
			
			if(element_type=="checkbox")
			{
				if(chk.elements[i].checked==true)
				{
					count++;
				}
			}
		}
		
		if(count==0)
		{
			alert("Please select atleast one video.");
			return false;
		}
	}

	
	//Check the cart for not more than 3 videos
	function checkCart(chk)
	{
		len = chk.elements.length;
		count=0;
		
		for(i=0;i<len;i++)
		{
			element_type = chk.elements[i].type;
			
			if(element_type=="checkbox")
			{
				if(chk.elements[i].checked==true)
				{
					count++;
				}
			}
		}
		
		if(count==0)
		{
			alert("Please check at least 1-3 videos to process your request.");
			return false;
		}
		else if(count>3)
		{
			alert("Please choose no more than 3 videos so that\nwe can make them available for all Peterson customers.");
			return false;
		}
		
	}
	
//Check the Video Request form
function check_video_req_frm(chk)
{
		  //Name
		  var contact_name = trim(chk.contact_name.value);
		  if(contact_name.length == 0)
		  {
		       alert("Please enter your Name.");
			   chk.contact_name.focus();
			   return false;
		  }
		  if(isNotAlphabets(contact_name))
		  {
		       alert("Please enter only Alphabets in Name field.");
			   chk.contact_name.focus();
			   return false;		  
		  }
	
		  //company
		  var company = trim(chk.company.value);
		  if(company.length == 0)
		  {
		       alert("Please enter your Company Name.");
			   chk.company.focus();
			   return false;
		  }
	
		  
		  //address
		  var address = trim(chk.address.value);
		  if(address.length == 0)
		  {
		       alert("Please enter your address.");
			   chk.address.focus();
			   return false;
		  }
		  //telephone
		  var phone = trim(chk.phone.value);
		  
		  if(phone.length == 0)
		  {
		       alert("Please enter your phone number.");
			   chk.phone.focus();
			   return false;
		  }
		  
		  if(isNotNumeric(phone))
		  {
		       alert("Please enter only Numeric value in phone.");
			   chk.phone.focus();
			   return false;
		  }
		  
		  
		  //Email		  
		  var email = trim(chk.email.value);
		  if(email.length == 0)
		  {
		       alert("Please enter your E-mail Address.");
			   chk.email.focus();
			   return false;
		  }
		 if(!checkEmail(email))
		 {
			alert("Please enter valid email address.");
			chk.email.focus();
			return false;		  
		 }

		  //Comments
		  var comments = trim(chk.comments.value);
		  if(comments.length > 1000)
		  {
		       alert("Comments field can not contain more than 1000 characters");
			   chk.comments.focus();
			   return false;
		  }
		 		 
		 
		  //Radio Button
		  
		  if(chk.customer_type[0].checked==false && chk.customer_type[1].checked==false)
		  {
			  alert("Please select option for Customer Type.\nPeterson Customer or Not a Peterson Customer.");
			  chk.customer_type[0].focus();
			  return false;
		  }
		  		  
}		  		  		  
	

