// JavaScript Document
//Checking if Email Address is valid
function validEmail(email) {
    var emailRE = new RegExp(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/);
    return emailRE.test(email);
  }
   //  check for valid numeric strings	  
function IsNumeric(strString)
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }
   
   function validatePackages(){

	//var type = document.getElementById('type').value;
	var total_items = 0;
	var red_val="";
	//radio buttons
	for(var i=0; i < 6; i++){
		if(document.frmSubscribe.s[i].checked)
			total_items = total_items + 1;
	}
	//alert(total_items);
	// get the checked value from the radio button list
	for (var i=0; i < document.frmSubscribe.f22832.length; i++){
   		if (document.frmSubscribe.f22832[i].checked){
	      	rad_val = document.frmSubscribe.f22832[i].value;
			//alert("The radio button you chose has the value: " + rad_val);
      	}
   	}
	//alert(rad_val);
	// now we have to fire messages based on the package type
	if(rad_val == 'Starter'){
		if(total_items > 2 || total_items == 0){
			alert('2 Products');
			return false;
		}
	}
	if(rad_val == 'Value'){
		if(total_items > 4 || total_items == 0){
			alert('4 Products');
			return false;
		}
	}
	if(rad_val == 'Supreme'){
		if(total_items == 0 || total_items == 0){
			alert('Please select your Products');
			return false;
		}
		
	}
}
//Validation Starts Here
function validForm(Form) {
	
//Validating Name Field
if (Form.first.value =="")
{
alert("Please enter your first name.")
Form.first.focus()
Form.first.select()
return false
}
if (Form.last.value =="")
{
alert("Please enter your last name.")
Form.last.focus()
Form.last.select()
return false
}
// end validating name

//Email Validation

if (Form.email.value =="")
	{
	alert("Please enter your e-mail address")
	Form.email.focus()
	return false
	}
if (validEmail(Form.email.value) == false)
     // return focusElement(formElement.email,
	 {
    alert("Invalid e-mail address.");
	Form.email.focus()
	return false
	}
//end validating email

//Validating Phone including to check if the field is numerical.
 if (Form.phone.value.length == 0) 
      {
      alert("Please enter your phone number. No space or symbols allowed. eg:9471234567");
	  Form.phone.focus()
	  Form.phone.select()
	  return false
      } 
   if (IsNumeric(Form.phone.value) == false) 
      {
      alert("Only numbers are alowed! No space or symbols allowed. eg:9471234567");
	    Form.phone.focus()
	  Form.phone.select()
	  return false
      }
//end validating phone



//validating services option
   //if ((Form.p1[0].checked) == false )
   // {
       // alert ("Please select one service only" );
		//Form.p1.focus()
       // return false;
   // }
///
// Radio Button Validation
if ( ( Form.f22832[0].checked == false ) && ( Form.f22832[1].checked == false ) && ( Form.f22832[2].checked == false ) && ( Form.f22832[3].checked == false ))

	{
        alert ("Please select a package" );
		//Form.p1.focus()
        return false;
    }
//...................


//Validating Method
hearChoice = Form.abtus.selectedIndex
if (Form.abtus.options[hearChoice].value == "")
{
alert("Please select how you heard about us.")
Form.abtus.focus()
return false
}
//end validating Method

return validatePackages();
return true
}
