//VP JavaScript Validations Document



	vld_Address = /^[a-zA-Z0-9.,#:\'\-\s ]*$/;

	vld_Address_Message = "It can contain Alphabets, Numbers, Spaces, Dot(.), Comma(,), Hash(#), Colon(:), Single Quotes('), Hyphen(-) only.";



//ville

	vld_ville=/^[a-zA-Z0-9\s]*$/;

	vld_ville_Message= "It can contain Alphabets and Numbers only .";



//alphanumeric code

	vld_AlphaNumericCode= /^[a-zA-Z0-9]*$/;

	vld_AlphaNumericCode_Message= "It can contain Alphabets and Numbers only .";

//telephone code

	vld_tel= /^[0-9]*$/;

	vld_tel_Message= "It can contain  Numbers only .";
//telephone number US format

	vld_srh_TelephoneUS = /^[0-9\-%]*$/;

	vld_srh_TelephoneUS_Message= "It can contain Numbers, Hyphen(-), Percent(%) only."



//telephone number french format

	vld_srh_TelephoneFRENCH = /^[1-9]{5}\s? [0-9]{3}\s?[0-9]{3}|[1-9]{5}\-?[0-9]{3}\-?[0-9]{3}$/;

	vld_srh_TelephoneFRENCH_Message	="Telephone field will contain xxxxx xxx xxx digit only!";



//company name:

	vld_CompanyName	= /^[a-zA-Z][a-zA-Z0-9 ]*$/;

	vld_CompanyName_Message	= "It can contain an Alphabet as the Starting Letter and then Alphabets, Numbers and Spaces only";

	

//city name

	vld_City= /^[a-zA-Z.,\- ]*$/;

	vld_City_Message= "It can contain Alphabets, Spaces Dot(.), Comma(,), Hyphen(-) only.";

	

//date format

	vld_Date= /^((([0-9]{1,2}(\/)[0-9]{1,2}(\/)[0-9]{1,4}){1}))?$/;

	vld_Date_Message= "Enter Date in mm/dd/yyyy format.";

	

//description

	vld_Description= /^([a-zA-Z0-9.,#\'\-\s ]){0,500}$/;

	vld_Description_Message= "It can contain Alphabets, Numbers, Spaces, Dot(.), Comma(,), Hash(#), Single Quotes('), Hyphen(-) only.";



//email

	vld_Email= /^(([a-zA-Z0-9\-])+((\.|_)([a-zA-Z0-9\-])+)*@((\[(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-5][0-5]))\]))|((([a-zA-Z0-9])+(([\-])+([a-zA-Z0-9])+)*\.)+([a-zA-Z])+(([\-])+([a-zA-Z0-9])+)*)))?$/;

	vld_Email_Message= "Email format should be -\n\t user.123@abc.com\n\tor user_123@abc.com\n\tor user@abc.co.in";

	

// name

	vld_Name = /^[a-zA-Z.]*$/;

	vld_Name_Message= "It can contain  Alphabets and Dot(.) only.";

	

//empcode

	vld_EMPCode=/^[a-zA-Z0-9\s]*$/;

	vld_EMPCode_Message= "It can contain Alphabets and Numbers only .";

	

// salary 

	vld_salary=/^[0-9]*$/;

	vld_salary_Message= "It can contain  Numbers only .";

	

//website url

	vld_url=/^[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}$/;

	vld_url_Message= "Please enter a valid url .";



//last name

	vld_LastName = /^[a-zA-Z\.]*$/;

	vld_LastName_Message = "It can contain  Alphabets and Dot(.) only.";





//zip postal code

	vld_ZipPostalCodefr=/^[1-9]{5}$/;

	vld_ZipPostalCodefr_Message	= "Code postal can contain 5 digits only !";

	

	  

 //simplest email validation

 vld_emailSimple_Message = /^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/;

 vld_emailSimple_Message = "Can use joe@aol.com or ssmith@aspalliance.com or a@b.cc format  only"; 

 

  

 //simple email validation

 vld_emailSimple = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;

 vld_emailSimple_Message = "Can use asmith@mactec.com | foo12@foo.edu | bob.smith@foo.tv format only";

 

 





function ValidateForm(pobjForm)

{

	var IsValidField = true;

	 lobjElements = pobjForm.elements;

	//alert(lobjElements.length);

	for(lintLopCnt = 0; lintLopCnt < lobjElements.length; lintLopCnt ++ )

		{

			if(lobjElements[lintLopCnt].getAttribute("required") == "yes")

				{

				//alert(lobjElements[lintLopCnt].getAttribute("fieldName"));

			      if (lobjElements[lintLopCnt].type=="text")

					{

						if(lobjElements[lintLopCnt].value == "")

							{

								lstrErrSpan = "err" + lobjElements[lintLopCnt].getAttribute("fieldName");

								var blankField="please fill "+lobjElements[lintLopCnt].name+" field!";

								//alert(blankField);

								//alert(lobjElements[lintLopCnt]);

								document.getElementById(lstrErrSpan).innerHTML = "Required Field";

								IsValidField = false;

								

								return false;

							}

					else if(lobjElements[lintLopCnt].value != "")

							{

								lstrErrSpan = "err" + lobjElements[lintLopCnt].getAttribute("fieldName");

								//alert(lstrErrSpan);

								if (validate(lobjElements[lintLopCnt]))

									 {	

										document.getElementById(lstrErrSpan).innerHTML = "";

				       				 }

								else

									 {

										document.getElementById(lstrErrSpan).innerHTML = "Incorrect";

										//alert("Please fill "+lobjElements[lintLopCnt].name+" field correctly !");

										IsValidField = false;

										return false;

						    		 }

							 }

			         }

				// About textarea validation

            	  if (lobjElements[lintLopCnt].type=="textarea")

					{

						 

					}

					

				//VP validate combo box

				  if (lobjElements[lintLopCnt].type=="select-one")

					{

					  if(lobjElements[lintLopCnt].getAttribute("required") == "yes")

						{

							if(lobjElements[lintLopCnt].selectedIndex == 0)

							   {

									lstrErrSpan = "err" + lobjElements[lintLopCnt].getAttribute("fieldName");

									document.getElementById(lstrErrSpan).innerHTML = "Required";

									IsValidField = false;

							   }

						  else

							   {

							lstrErrSpan = "err" + lobjElements[lintLopCnt].getAttribute("fieldName");

							document.getElementById(lstrErrSpan).innerHTML = "";

						       }

						}

				    }

    	  		}

	  	}

	if(IsValidField == true)

	  {

		return true;

	  }

	else

	  {

		//alert("Please Enter Required fields.");

		return false;

	  }

}





// validate function for checking whether field is valid if not display  message..



function validate(pObj)

{

	IsValidField = true;

	if(pObj.getAttribute("validation") != null)

	  {

		lstrValid = pObj.getAttribute("validation");

		//alert(lstrValid);

		if ( (eval(lstrValid).test(pObj.value)== false ) )

		   {

			formatError=lstrValid+"_Message";

			//for displaying message of invalid format	

			alert(eval(formatError));

		  	//alert(vld_srh_TelephoneFRENCH_Message);

			IsValidField = false;

		   }

      }

	if (IsValidField == true)

      {

		return true;

	  }

	else

	  {

		return false;

	  }

}





function validate_newsform(obj)

{ 

	if (obj.email.value == "")

	{

		obj.email.style.background = 'yellow';

		alert ("Please enter a valid email");

		return false;

	}

}
