// 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;
   

	if (strString.length <5 || strString.length >15)
	{
	if(isNaN(strString))
	{
		alert("Your phone number consists of invalid characters. Only 0-9 + - . <space> are accepted");
	}
	else{
	alert("Invalid Phone Number")
	}
	
	
	
	 blnResult = false;
	
	}
	else{


   //  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;
		 alert("Your phone number consists of invalid characters. Only 0-9 + - . <space> are accepted");

         }

      }
	}
   return blnResult;

   }



//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


//Country Selection Validation
if (Form.country.value =="")
	
	{
	
	alert("Please enter your country")
	
	Form.country.focus()
	
	Form.country.select()
	
	return false
	
	}

//end validating Country 

//Country Selection Validation

	/*countryChoice = Form.country.selectedIndex
	
	if (Form.country.options[countryChoice].value == "")
	
	{
	
	alert("Please select your country")
	
	Form.country.focus()
	
	return false
	
	}*/
	


//end validating Country 

//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
	
		}

	/*if (Form.cmail.value =="")
	
		{
	
		alert("Please confirm your e-mail address")
	
		Form.cmail.focus()
	
		return false
	
		}
	
	if (Form.email.value !=Form.cmail.value)
	
		{
	
		alert("The e-mail addresses do not match.")
	
		Form.cmail.focus()
	
		Form.cmail.select()
	
		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.");
	
		  Form.phone.focus()
	
		  Form.phone.select()
	
		  return false
	
		  } 

	   if (IsNumeric(Form.phone.value) == false) 
	
		  {
	
		  
	
			Form.phone.focus()
	
		  Form.phone.select()
	
		  return false
	
		  }

//end validating phone

//validating chat fields

	/*if (Form.msn.value =="")
	
		{
	
		alert("Please enter your MSN chat ID")
	
		Form.msn.focus()
	
		return false
	
		}

	if (validEmail(Form.msn.value) == false)
	
		 // return focusElement(formElement.email,
	
		 {
	
		alert("Invalid MSN ID!");
	
		Form.msn.focus()
	
		return false
	
		}*/

/*if (Form.yahoo.value =="")

	{

	alert("Please enter your Yahoo email address")

	Form.yahoo.focus()

	return false

	}

if (validEmail(Form.yahoo.value) == false)

     // return focusElement(formElement.email,

	 {

    alert("Invalid Yahoo ID");

	Form.yahoo.focus()

	return false

	}*/

//end validating chat fields

//Validating Method
//checkbox selected validations
if(Form.f22863.checked == false && Form.f22864.checked == false && Form.f22865.checked == false && Form.f22866.checked == false && Form.f22867.checked == false && Form.f22868.checked == false && Form.f22869.checked == false && Form.f22870.checked == false && Form.f22871.checked == false && Form.f22872.checked == false && Form.f22653.checked == false && Form.f22875.checked == false && Form.f22876.checked == false && Form.f22877.checked == false)
	{
		alert("Please select your prefered RedVoIP Hosted Solutions.");
		Form.f22863.focus();
		return false;
	}


// check how did you hear about us?
/*hearChoice = Form.abtus.selectedIndex

	if (Form.abtus.options[hearChoice].value == "")
	
	{
	
	alert("Let us know 'How you heard about us'")
	
	Form.abtus.focus()
	
	return false
	
	}
*/
//end validating Method
	

//Validating Captcha Field

	if (Form.recaptcha_response_field.value =="")
	
	{
	
	alert("Please enter the verification number displayed.")
	
	Form.recaptcha_response_field.focus()
	
	Form.recaptcha_response_field.select()
	
	return false
	
	}
		
return true

}

//end validating captcha field


