function ValidateApplicationForm()
{
	/* Object declarations */
	var objFName = document.getElementById("txtName");
	var objAdr = document.getElementById("txtAddress1");
	var objCity = document.getElementById("txtCity");
	var objState = document.getElementById("txtState");
	var objPostalCode = document.getElementById("txtPostalcode");
	var objEmail = document.getElementById("txtEmail");
	var objPhone = document.getElementById("txtHomePhone");
	var objSkills = document.getElementById("txtSkills");
	var objProfessionalRef = document.getElementById("txtProfessionalRef");
	var objPersonalRef = document.getElementById("txtPersonalRef");
	
	/* Validating the First name Field */
	if( !validateNull( objFName ) )
	{
		alert("Enter FirstName");
		objFName.focus();
		return false;
	}
	else if(!IsCharOnly(objFName.value))
	{
		alert('Enter only Characters for First name');
		objFName.focus();
		return false;
	}
	/* Validating the Address1 Field */
	else if( !validateNull( objAdr ))
	{
		alert("Enter Address");
		objAdr.focus();
		return false;
	}
	/* Validating the City name Field */
	else if( !validateNull( objCity ) )
	{
		alert("Enter City Name");
		objCity.focus();
		return false;
	}
	else if(!IsCharOnly(objCity.value))
	{
		alert('Enter only Characters for City name');
		objCity.focus();
		return false;
	}
	/* Validating the State name Field */
	else if( !validateNull( objState ) )
	{
		alert("Enter State Name");
		objState.focus();
		return false;
	}	
	else if(!IsCharOnly(objState.value))
	{
		alert('Enter only Characters for State name');
		objState.focus();
		return false;
	}
	/* Validating the Postal Code Field */
	else if( !validateNull( objPostalCode ) )
	{
		alert("Enter Postal Code");
		objPostalCode.focus();
		return false;
	}
	else if(!IsNumeric(objPostalCode.value))
	{
		alert('Enter only numerics for PostalCode');
		objPostalCode.focus();
		return false;
	}
	/* Cheching length of Postal Code Field */
	else if( objPostalCode.value.length < 5)
	{
		alert("Enter a valid Postal Code");
		objPostalCode.focus();
		return false;
	}
	/* Validating the Phone Number Field */
	else if(!ValidatePhone(objPhone))
	{
		return false;
	}
	/* Validating the EmailID Field */
	else if( !ValidateEmail(objEmail))
	{
		return false;
	}
	/* Validating the skills entered by the user*/
	else if( !validateNull( objSkills ) )
	{
		alert("Enter Skills information");
		objSkills.focus();
		return false;
	}
	/* Checking the skills info entered by the user*/
	else if(!checkSequence(objSkills.value))
	{
		alert("Enter Valid skills information");
		objSkills.focus();
		return false;
	}
	
	/* Validating the Professional Reference entered by the user*/
	else if( !validateNull( objProfessionalRef ) )
	{
		alert("Enter Professional Reference");
		objProfessionalRef.focus();
		return false;
	}
	/* Checking the Length of Professional Reference entered by the user*/
	else if(!checkSequence(objProfessionalRef.value))
	{
		alert("Enter Valid Professional Reference");
		objProfessionalRef.focus();
		return false;
	}
	
	/* Validating the Personal Reference entered by the user*/
	else if( !validateNull( objPersonalRef ) )
	{
		alert("Enter Personal Reference");
		objPersonalRef.focus();
		return false;
	}
	/* Checking the Length of Personal Reference entered by the user*/
	else if(!checkSequence(objPersonalRef.value))
	{
		alert("Enter Valid Personal Reference");
		objPersonalRef.focus();
		return false;
	}
	
	else
	{
	 return true;
	}
}
//////////////////////////////////////////////////////////////////////////////////////////

function ValidateContactForm()
{
	/* Object declarations */
	var objFName = document.getElementById("txtFName");
	var objAdr = document.getElementById("txtAddress1");
	var objTitle = document.getElementById("txtTitle");
	var objCity = document.getElementById("txtCity");
	var objState = document.getElementById("txtState");
	var objPostalCode = document.getElementById("txtZip");
	var objComments = document.getElementById("txtComments");
	var objEmail = document.getElementById("txtEmail");
	var objPhone = document.getElementById("txtPhoneNumber");
	var objServices = document.getElementById("ddlServices");
	
	/* Validating the First name Field */
	if( !validateNull( objFName ) )
	{
		alert("Enter First Name");
		objFName.focus();
		return false;
	}
	else if(!IsCharOnly(objFName.value))
	{
		alert('First Name should be characters only');
		objFName.focus();
		return false;
	}
	/* Validating the Job Title Field */
	else if( !validateNull( objTitle ) )
	{
		alert("Enter Job Title");
		objTitle.focus();
		return false;
	}
	else if(!IsAlphaCharOnly())
	{
		alert("Job Title should be alphanumeric");
		objTitle.focus();
		return false;
	}
	/* Validating the Address1 Field */
	else if( !validateNull( objAdr ))
	{
		alert("Enter Address");
		objAdr.focus();
		return false;
	}
	/* Validating the City name Field */
	else if( !validateNull( objCity ) )
	{
		alert("Enter City Name");
		objCity.focus();
		return false;
	}
	else if(!IsCharOnly(objCity.value))
	{
		alert('City name should contain characters only');
		objCity.focus();
		return false;
	}
	/* Validating the State name Field */
	else if( !validateNull( objState ) )
	{
		alert("Enter State Name");
		objState.focus();
		return false;
	}	
	else if(!IsCharOnly(objState.value))
	{
		alert('state name should contain characters');
		objState.focus();
		return false;
	}
	/* Validating the Postal Code Field */
	else if( !validateNull( objPostalCode ) )
	{
		alert("Enter Postal Code");
		objPostalCode.focus();
		return false;
	}
	/* Cheching length of Postal Code Field */
	else if( objPostalCode.value.length < 5)
	{
		alert("Enter a valid Postal Code");
		objPostalCode.focus();
		return false;
	}
	else if(!IsNumeric(objPostalCode.value))
	{
		alert('PostalCode should contain numerics');
		objPostalCode.focus();
		return false;
	}
	/* Validating the Phone Number Field */
	else if(!ValidatePhone(objPhone))
	{
		return false;
	}
	/* Validating the EmailID Field */
	else if( !ValidateEmail(objEmail))
	{
		return false;
	}
	
	else if(objServices.value == -1)
	{
		alert("Select a service");
		objServices.focus();
		return false;
	}
	
	/* Validating the Comments entered by the user*/
	else if( !validateNull( objComments ) )
	{
		alert("Enter Comments");
		objComments.focus();
		return false;
	}
	/* Checking the Length of Comments entered by the user*/
	else if(!checkSequence(objComments.value))
	{
		alert("Enter Valid Comments");
		objComments.focus();
		return false;
	}
	else
	{
	 return true;
	}
}

///////////////////////////////////////////////////////////////////////////////////////////

function ValidateRequestAQuoteForm()
{
	/* Object declarations */
	var objFName = document.getElementById("txtFirstName");
	var objAdr = document.getElementById("txtAddress1");
	var objCmp = document.getElementById("txtCompany");
	var objCity = document.getElementById("txtCity");
	var objState = document.getElementById("txtState");
	var objPostalCode = document.getElementById("txtPostalCode");
	var objQuote = document.getElementById("txtQuoteFor");	
	var objEmail = document.getElementById("txtEmail");
	var objPhone = document.getElementById("txtTelePhoneNumber");
	
	
	/* Validating the First name Field */
	if( !validateNull( objFName ) )
	{
		alert("Enter First Name");
		objFName.focus();
		return false;
	}
	else if(!IsCharOnly(objFName.value))
	{
		alert('First Name should be characters only');
		objFName.focus();
		return false;
	}
	/* Validating the Company name Field */
	else if( !validateNull( objCmp ) )
	{
		alert("Enter Company Name");
		objCmp.focus();
		return false;
	}
	else if(!IsAlphaCharOnly(objCmp.value))
	{
		alert('Company Name should contain AlphaNumeric only');
		objCmp.focus();
		return false;
	}
	/* Validating the Address1 Field */
	else if( !validateNull( objAdr ))
	{
		alert("Enter Address1");
		objAdr.focus();
		return false;
	}
	/* Validating the City name Field */
	else if( !validateNull( objCity ) )
	{
		alert("Enter City Name");
		objCity.focus();
		return false;
	}
	else if(!IsCharOnly(objCity.value))
	{
		alert('City name should contain characters only');
		objCity.focus();
		return false;
	}
	/* Validating the State name Field */
	else if( !validateNull( objState ) )
	{
		alert("Enter State Name");
		objState.focus();
		return false;
	}
	else if(!IsCharOnly(objState.value))
	{
		alert('State name should contain characters');
		objState.focus();
		return false;
	}	
	/* Validating the Postal Code Field */
	else if( !validateNull( objPostalCode ) )
	{
		alert("Enter Postal Code");
		objPostalCode.focus();
		return false;
	}
	/* Cheching length of Postal Code Field */
	else if( objPostalCode.value.length < 5)
	{
		alert("Enter a valid Postal Code");
		objPostalCode.focus();
		return false;
	}
	else if(!IsNumeric(objPostalCode.value))
	{
		alert('PostalCode should contain numerics');
		objPostalCode.focus();
		return false;
	}
	/* Validating the Phone Number Field */
	if(!ValidatePhone(objPhone))
	{
		return false;
	}
	/* Validating the EmailID Field */
	else if( !ValidateEmail(objEmail))
	{
		return false;
	}
	/* Validating the Quote information entered by the user*/
	else if( !validateNull( objQuote ) )
	{
		alert("Enter Quote Details");
		objQuote.focus();
		return false;
	}
	/* Checking length of Quote Info entered by the User*/
	else if(!checkSequence(objQuote.value))
	{
		alert("Enter Valid Quote details");
		objQuote.focus();
		return false;
	}
	else
	{
	 return true;
	}
}

///////////////////////////////////////////////////////////////////////////


function ValidateTellAFriendForm()
{	
	/* Creating objects for the controls to validate */
	var objName = document.getElementById("txtName");
	var objEmailID = document.getElementById("txtEmail");
	var objurName = document.getElementById("txtUserName");
	var objurEmailID = document.getElementById("txturEmail");
	
	// Checking the length of Friends Name
	if( objName.value.length == 0 )
	{
		// if friends name length is 0,
		// alerting the user with a message.
		alert('Enter your friend name');
		// focusing the same control to enter the value
		objName.focus();
		// returning the false value
		return false;
	}
	else if(!IsCharOnly(objName.value))
	{
		alert('Friend name should contain only Characters ');
		objName.focus();
		return false;
	}
	// Validating the Email ID
	else if(!ValidateEmail(objEmailID))
	{
		// if email ID is not in  correct format or 
		// null returning the false
		return false;
	}
	// checking the length of the user name
	else if( objurName.value.length == 0 )
	{
		// if the length is 0 then 
		// alerting the user with a message
		alert('Enter your Name');
		// focusing the control to the Your Name Field
		objurName.focus();
		// returns the false value
		return false;
	}
	else if(!IsCharOnly(objurName.value))
	{
		alert('Your name should contain only characters');
		objurName.focus();
		return false;
	}
	// validating the your email id
	else if(!ValidateEmail(objurEmailID))
	{
		// if email ID is not in  correct format or 
		// null returning the false
		return false;
	}
	//  otherwise
	else
	{
		// returning the true value
		return true;
	}
}	


//################################################################################################################################

										//..........GENERIC Methods..............///

//################################################################################################################################
/* Function to validate the objet value is null or not and returns the boolean value */
function validateNull(obj)
{
	// checking the length of the object value is 0 or not. 
	if(obj.value.length == 0)
	{
		// if  length is 0 then returning the value as false.
		return false;
	}
	else
	{
		// otherwise returning the true value.
		return true;
	}
}

//################################################################################################################################
function DateValidate(strDate)
{
	var re1 = /\d{2}[/]\d{2}[/]\d\{4}/;
	var re2 = /\d{2}[-]\d{2}[-]\d\{4}/;
	var re3 = /\d{2}[.]\d{2}[.]\d\{4}/;
	if(re1.test(strDate))
	{
		return checkDate(strDate);
	}
	else if(re2.test(strDate))
	{
		return checkDate(strDate);
	}
	else if(re3.test(strDate))
	{
		return checkDate(strDate);
	}
	else
	{
		//alert('Enter a valid date (Ex: dd/mm/yyyy (or) dd-mm-yyyy (or) dd.mm.yyyy)');
		return false;
	}
}
function checkDate(strDate)
{
	var  ss = new Array();
	var s = strDate;
	var date = parseInt( s.substring(0,2) );
	var month = parseInt( s.substring(3,5) );
	var year = parseInt( s.substring(6,10) );
	var isleap = false;
	if(!IsEmpty(date) && !IsEmpty(month) && !IsEmpty(year))
	{
		if((year%4) == 0)
		{
			isleap = true;
		}
		
		var monthDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
		switch(month)
		{
			case 1:
					if(date > monthDays[month-1] || date < 1)
					{
						return false;
					}
					else
					{
						return true;
					}
					
			case 2:
					if(isleap)
					{
						if(date > 29 || date < 1)
						{
							return false;
						}
						else
						{
							return true;
						}
					}
					else
					{
						if(date > monthDays[month-1] || date < 1)
						{
							return false;
						}
						else
						{
							return true;
						}
					}
					
			case 3:
					if(date > monthDays[month-1] || date < 1)
					{
						return false;
					}
					else
					{
						return true;
					}
					
			case 4:
					if(date > monthDays[month-1] || date < 1)
					{
						return false;
					}
					else
					{
						return true;
					}
					
			case 5:
					if(date > monthDays[month-1] || date < 1)
					{
						return false;
					}
					else
					{
						return true;
					}
					
			case 6:
					if(date > monthDays[month-1] || date < 1)
					{
						return false;
					}
					else
					{
						return true;
					}
					
			case 7:
					if(date > monthDays[month-1] || date < 1)
					{
						return false;
					}
					else
					{
						return true;
					}
					
			case 8:
					if(date > monthDays[month-1] || date < 1)
					{
						return false;
					}
					else
					{
						return true;
					}
					
			case 9:
					if(date > monthDays[month-1] || date < 1)
					{
						return false;
					}
					else
					{
						return true;
					}
					
			case 10:
					if(date > monthDays[month-1] || date < 1)
					{
						return false;
					}
					else
					{
						return true;
					}
					
			case 11:
					if(date > monthDays[month-1] || date < 1)
					{
						return false;
					}
					else
					{
						return true;
					}
					
			case 12:
					if(date > monthDays[month-1] || date < 1)
					{
						return false;
					}
					else
					{
						return true;
					}
					
			default:
				return false;
				
		};
	}
    else
    {
		return false;
    }

}
//################################################################################################################################

function checkSequence(strValue)
{
	var str = strValue.charAt(0)
	//alert(str);
	var re1 = /[^\W{1,}]/;
	var re2 = /[^\w{2,}]/;
	if(!re1.test(strValue))
	{
		//alert('Enter a valid Message');
		return false;
	}
	else if(!re2.test(strValue))
	{
		//alert('Enter a valid Message');
		return false;
	}
	else
	{
		return true;
	}
	
}
//################################################################################################################################
/* Function to validate the Emailid whether the entered email ID is in Correct format or not */
function ValidateEmail(objEmailID)
{
	if( objEmailID.value.length > 0 )
	{
			// preparing the regular expression to validate the Email ID
			var re = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
			// storing the Object value in a string variable
			var str = objEmailID.value;
			// testing the value with the regularexpression
			if(!re.test(str))
			{
				alert('Enter a valid email id');
				objEmailID.focus();
				return false;
			}
		
	}
	// checking the length of the emai id
	else if( objEmailID.value.length == 0 )
	{
		// alerting the user by message.
		alert('Enter Email ID');
		// focusing to the same control to enter the value 
		objEmailID.focus();
		// returns the false
		return false;
	}
	return true;
}



//################################################################################################################################
///function to validate the string is empty.
function IsEmpty(strInput)
{

	// strInput is the string that we are going to check is it empty or not. 
	//if strInput has the length 0 means that the string is empty so returns TRUE
	if(strInput.length==0)
		return true;
	
	//otherwise returns false.
	else
		return false;
}

//################################################################################################################################
///function to check whether the given input string is numeric or not.ok
function IsNumeric(strInput)
{
	//strInput is input string
	//iLength is the length of the string
	var iLength=strInput.length;
	
	//iLoop is for looping purpose
	//flag and flag1 are two integer variables one for numeric count another for non numeric count. 	
	var iLoop,flag=0,flag1;
	
	//iNumeric is for numeric values
	var iNumeric;
	
	// input string each character is checking for all numeric values 0 to 9
	for(iNumeric=0;iNumeric<=9;iNumeric++)
	{
		for(iLoop=0;iLoop<strInput.length;iLoop++)
		{
			// if not matched with 0 to 9 then returns that not a numeric with an indication as false 
			if(strInput.charAt(iLoop)==iNumeric)
				flag+=1;
			else
				flag1=0;
		}
	}
	if(flag!=strInput.length)
	 return false;
	 //alert("it is a numeric");
	else
	 // alert("it's is not a numeric");
	return true;	
}

//################################################################################################################################

 ///function is to check whether the given input string has characters only or not.ok
function IsAlphaCharOnly(strInput)
{
	//charSpecial is a charcter array hving all the special characters excluding '_' 
	var charSpecial="\'\"!@#$%^&*()+|\}{;:/?.><`~";
	
	//iLoop1 and iLoop2 are looping variables
	var iLoop1=0,iLoop2=0;
	
	//iFlag is integer variable  
	var iFlag=1,iFlag1=0;
	
	//first checks that whether the string is numeric or not
	if(!IsNumeric(strInput))
	{
		//if not a numeric checks for each charcter of given input string with each charcter of charSpecial array
		for(iLoop1=0;iLoop1<strInput.length;iLoop1++)
		{
			for(iLoop2=0;iLoop2<charSpecial.length;iLoop2++)
			{
				//if inputstring has any special characters then returns that false 
				if(strInput.charAt(iLoop1)==charSpecial.charAt(iLoop2))
					{
						iFlag1=iFlag+1;
						break;
					}
				else
					iFlag=0;
			}
		}
	}
	else
	{
		//alert("return(false)");
		return false;
	}
	
	//for successfully only it comes out so here returns true.");
	if(iFlag==0 && iFlag1==0)
	{
		//alert("return(true)");
		return true;
	}
	else
	{
		//alert("return(false)");
		return false;
	}
}

//################################################################################################################################
///function is to check whether the given input string has characters only or not.ok
function IsCharOnly(strInput)
{
	//charSpecial is a charcter array hving all the special characters excluding '_' 
	var charSpecial="1234567890\'\"!@#$%^&*()+|\}{;:/?.><`~";
	
	//iLoop1 and iLoop2 are looping variables
	var iLoop1=0,iLoop2=0;
	
	//iFlag is integer variable  
	var iFlag=1,iFlag1=0;
	
	//first checks that whether the string is numeric or not
	if(!IsNumeric(strInput))
	{
		//if not a numeric checks for each charcter of given input string with each charcter of charSpecial array
		for(iLoop1=0;iLoop1<strInput.length;iLoop1++)
		{
			for(iLoop2=0;iLoop2<charSpecial.length;iLoop2++)
			{
				//if inputstring has any special characters then returns that false 
				if(strInput.charAt(iLoop1)==charSpecial.charAt(iLoop2))
					{
						iFlag1=iFlag+1;
						break;
					}
				else
					iFlag=0;
			}
		}
	}
	else
	{
		//alert("return(false)");
		return false;
	}
	
	//for successfully only it comes out so here returns true.");
	if(iFlag==0 && iFlag1==0)
	{
		//alert("return(true)");
		return true;
	}
	else
	{
		//alert("return(false)");
		return false;
	}
}

//################################################################################################################################
/* Function to Vaidating the Phone number using the phone number object */
function ValidatePhone(objPhone)
{
	/* checking the length of the phone number */
	if( objPhone.value.length > 0 )
	{
			/* regular expression to validate the phone number */
			var re = /((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}/;
			/* storing the phone number in a string varibale */
			var str = objPhone.value;
			/* testing the phone number with the regularexpression */
			if(!re.test(str))
			{
				alert('Enter a valid Phone Number, ex:000-000-0000');
				objPhone.focus();
				return false;
			}
		
	}
	
	else if( objPhone.value.length == 0 )
	{
		/* if length is 0 then alerting with the messag */
		alert('Enter Phone number');
		/* focusing to the same control to enter the value */
		objPhone.focus();
		
		return false;
	}
	return true;
}
//################################################################################################################################


