// email validation script 

function validMail(obj)	{				
	var EmailOk  = true
	var Temp     = obj
	var AtSym    = Temp.value.indexOf('@')
	var Period   = Temp.value.lastIndexOf('.')
	var Space    = Temp.value.indexOf(' ')
	var Length   = Temp.value.length - 1   // Array is from 0 to length-1

	if(obj.value !=""){
		if ((AtSym < 1) ||                     // '@' cannot be in first position
		    (Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
		    (Period == Length ) ||             // Must be atleast one valid char after '.'
		    (Space  != -1))                    // No empty spaces permitted
			   {  
		      EmailOk = false
		      alert("Please enter a valid e-mail address!");
			      Temp.value="";
			      Temp.focus();
		      return EmailOk;
   			}
		}
	}
function feedback_Validator(theForm)
{
	//Validate Function 
	function validate(value,checkOk)
	{
	var checkStr = value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++)	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOk.length;  j++)
		if (ch == checkOk.charAt(j))
			break;
			if (j == checkOk.length) {
			 allValid = false;
			 break;
			}
	}
	  if (!allValid) {
		return (false);
	  }
	else { return (true); }
  }

		//Trim script
		function Trim(STRING){
		STRING = LTrim(STRING);
		return RTrim(STRING);
		}

		function RTrim(STRING){
		while(STRING.charAt((STRING.length -1))==" "){
		STRING = STRING.substring(0,STRING.length-1);
		}
		return STRING;
		}

		function LTrim(STRING){
		while(STRING.charAt(0)==" "){
		STRING = STRING.replace(STRING.charAt(0),"");
		}
		return STRING;
		}
	 // emptycheck
	 var flag=true;
	 function emptystring(value)
	 {
	   if (value=="") return (false);
	   else return(true);
	 }
//Name

	theForm.Nameorg.value = LTrim(theForm.Nameorg.value);
	theForm.Nameorg.value = RTrim(theForm.Nameorg.value);
	if (!emptystring(theForm.Nameorg.value))
		 {
			alert("Please enter your Organisation Name");
			theForm.Nameorg.focus();
			flag=false;
			return (false);
		}
		else {

           var checkOk = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
			if (!(validate(theForm.Nameorg.value,checkOk)))
				{
				alert("Please Enter Organisation Name");
				theForm.Nameorg.value= "";
				theForm.Nameorg.focus();
				flag=false;
				return (false);
				}
		}
		//Address
	theForm.add1.value = LTrim(theForm.add1.value);
	theForm.add1.value = RTrim(theForm.add1.value);
	if (!emptystring(theForm.add1.value))
		 {
			alert("Please enter the Address");
			theForm.add1.focus();
			flag=false;
			return (false);
		}
			//City
	theForm.city.value = LTrim(theForm.city.value);
	theForm.city.value = RTrim(theForm.city.value);
	if (!emptystring(theForm.city.value))
		 {
			alert("Please enter the City");
			theForm.city.focus();
			flag=false;
			return (false);
		}
	
	//Phone Number

	theForm.phNo.value = LTrim(theForm.phNo.value);
	theForm.phNo.value = RTrim(theForm.phNo.value);
	if (!emptystring(theForm.phNo.value))
		 {
			alert("Please enter your Phone Number");
			theForm.phNo.focus();
			flag=false;
			return (false);
		}
			else {

           var checkOk = "0123456789";
			if (!(validate(theForm.phNo.value,checkOk)))
				{
				alert("Please Enter the Valid Phone Number");
				theForm.phNo.value= "";
				theForm.phNo.focus();
				flag=false;
				return (false);
				}
		}

		
//Set this return value to true when you want to submit the form
	
	return (flag);
}

//submitform validator

function form_Validator(theForm)
{
	//Validate Function 
	function validate(value,checkOk)
	{
	var checkStr = value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++)	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOk.length;  j++)
		if (ch == checkOk.charAt(j))
			break;
			if (j == checkOk.length) {
			 allValid = false;
			 break;
			}
	}
	  if (!allValid) {
		return (false);
	  }
	else { return (true); }
  }

		//Trim script
		function Trim(STRING){
		STRING = LTrim(STRING);
		return RTrim(STRING);
		}

		function RTrim(STRING){
		while(STRING.charAt((STRING.length -1))==" "){
		STRING = STRING.substring(0,STRING.length-1);
		}
		return STRING;
		}

		function LTrim(STRING){
		while(STRING.charAt(0)==" "){
		STRING = STRING.replace(STRING.charAt(0),"");
		}
		return STRING;
		}
	 // emptycheck
	 var flag=true;
	 function emptystring(value)
	 {
	   if (value=="") return (false);
	   else return(true);
	 }
//firstName

	theForm.fName.value = LTrim(theForm.fName.value);
	theForm.fName.value = RTrim(theForm.fName.value);
	if (!emptystring(theForm.fName.value))
		 {
			alert("Please enter your First Name");
			theForm.fName.focus();
			flag=false;
			return (false);
		}
		else {

           var checkOk = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
			if (!(validate(theForm.fName.value,checkOk)))
				{
				alert("Please Enter the First Name");
				theForm.fName.value= "";
				theForm.fName.focus();
				flag=false;
				return (false);
				}
		}
//firstName

	theForm.lastName.value = LTrim(theForm.lastName.value);
	theForm.lastName.value = RTrim(theForm.lastName.value);
	if (!emptystring(theForm.lastName.value))
		 {
			alert("Please enter your Last Name");
			theForm.lastName.focus();
			flag=false;
			return (false);
		}
		else {

           var checkOk = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
			if (!(validate(theForm.lastName.value,checkOk)))
				{
				alert("Please Enter the Last Name");
				theForm.lastName.value= "";
				theForm.lastName.focus();
				flag=false;
				return (false);
				}
		}

//Email
	theForm.email.value = LTrim(theForm.email.value);
	theForm.email.value = RTrim(theForm.email.value);
	if (!emptystring(theForm.email.value))
		 {
			alert("Please enter the Eamil id");
			theForm.email.focus();
			flag=false;
			return (false);
		}
		
//Phone Number

	theForm.tel.value = LTrim(theForm.tel.value);
	theForm.tel.value = RTrim(theForm.tel.value);
	if (!emptystring(theForm.tel.value))
		 {
			alert("Please enter your Phone Number");
			theForm.tel.focus();
			flag=false;
			return (false);
		}
			else {

           var checkOk = "0123456789";
			if (!(validate(theForm.tel.value,checkOk)))
				{
				alert("Please Enter the Valid Phone Number");
				theForm.tel.value= "";
				theForm.tel.focus();
				flag=false;
				return (false);
				}
		}

			

		
		
		
		{
// Checking if at least one period button is selected. Or not.
if (!document.form.six[0].checked && !document.form.six[1].checked && !document.form.six[2].checked){

alert("Please Select The Estimate");
return false;}


if(!document.form.agree.checked)

{alert("Please Read the guidelines and check the box below");
return false; }


return true;
}

		
//Set this return value to true when you want to submit the form
	
	return (flag);
}
