function chechExtension()

{

	var extString = document.contact.attachFile.value;

	if(extString == "")

	{

		return true;

	}

	else

	{

		var position = extString.lastIndexOf(".");

		var ext = extString.substring(position);

		if (ext == ".txt" || ext == ".doc" || ext == ".pdf" || ext == ".png" || ext == ".bmp" || ext == ".jpg" || ext == ".gif")

		{

			return true;

		}

		else

		{



			return false;

		}

	}

}

function validateForm( )

{

    if (document.contact.txtName.value == "")

	{

		alert("Your Name is missing! Please enter your Name.");



		document.contact.txtName.focus( );



		return false;

	}



	if (document.contact.txtPhone.value == "")

	{

		alert("Please enter Your Phone Number.");



		document.contact.txtPhone.focus( );



		return false;

	}



	if (!validateEmailAddress(document.contact.txtEmail.value))

	{

		alert("Please enter Your valid Email Address!");



		document.contact.txtEmail.focus( );

		document.contact.txtEmail.select( );



		return false;

	}



	if (!chechExtension())

	{

		alert("Selected File Type Is Not Allowed, Please Select In [ .txt, .bmp, .jpg, .doc, .gif, .png, .pdf ]");



		document.contact.attachFile.focus( );

		document.contact.attachFile.select( );



		return false;

	}



	if (document.contact.txtParkingSpaces.value == "")

	{

		alert("Please enter no. of parking spaces.");



		document.contact.txtParkingSpaces.focus( );



		return false;

	}





	return true;

}



function validateEmailAddress(sEmail)

{

	var iLength = sEmail.length;



	if (iLength < 5)

		return false;



	var sValidChars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";



	for (var i = 0; i < iLength; i++)

	{

		var sLetter = sEmail.charAt(i).toLowerCase( );



		if (sValidChars.indexOf(sLetter) != -1)

			continue;



		return false;

	}



	var iPosition = sEmail.indexOf('@');



	if (iPosition == -1 || iPosition == 0)

		return false;



	var sFirstPart = sEmail.substring(0, iPosition);



	sEmail = sEmail.substring((iPosition + 1));



	iPosition = sEmail.indexOf('.');



	if (iPosition == -1 || iPosition == 0)

		return false;



	var sSecondPart = sEmail.substring(0,iPosition);



	var sThirdPart = sEmail.substring((iPosition + 1));



	if(sFirstPart.indexOf('-') != -1)

		return false;



	if(sSecondPart.indexOf('@') != -1 || sSecondPart.indexOf('_') != -1)

		return false;



	if(sThirdPart.indexOf('@') != -1 || sThirdPart.indexOf('_') != -1 || sThirdPart.indexOf('-') != -1 || sThirdPart.length < 2)

		return false;



	return true;

}
