// JavaScript Document
function validateform()
{
	
	with(document.frmfreeconsulting){
	
		if (!required (firstname,"Please enter First Name"))
			return false
				
		if (!blank (firstname,"Please enter First Name"))
			return false
			
		if (!required (lastname,"Please enter your Last Name"))
			return false
				
		if (!blank (lastname,"Please enter your Last Name"))
			return false
		
		if (!required (Company_Name,"Please enter your Company Name"))
			return false
				
		if (!blank (Company_Name,"Please enter your Company Name"))
			return false
		
		if (!required (Phone,"Please enter your phone"))
			return false
				
		if (!blank (Phone,"Please enter your phone"))
			return false	
		
		if (!required (email,"Please enter your Email ID"))
			return false
				
		if (!blank (email,"Please enter your Email ID"))
			return false

		if (!ValidateEMail (email))
			return false	
			
		if (!required (scope,"Please enter your Project Scope/Specifications"))
			return false
				
		if (!blank (scope,"Please enter your Project Scope/Specifications"))
			return false
		if (!required (currency,"Please enter, What currency would you like the quotation in?"))
			return false
		if (!blank (currency,"Please enter, What currency would you like the quotation in?"))
			return false
		if (!required (randomtext,"Please enter, Security Code"))
			return false
		/*if (!required (sec_code,"Please enter security code"))
			return false*/
	}
	return true
}

function len(field,ll,nm){
	if(field.value.length>ll){
		alert(nm)
		field.focus()
		return false
	}
	return true
 }


function required(field,nm)
{
 
if(field.value == ""){
		alert(nm)
		field.focus()
		return false
	}
	return true

}


function blank(field,nm)
{
if(field.value!=""){

	var crlf="\r\n"
	text=false
	
	var arr=new Array()
	arr=field.value.split(crlf)
	for(j=0;j<arr.length&&!text;j++){
		a=arr[j]
		if ((a!=crlf)){
			for(i=0;i<a.length&&!text;i++){
				str=a.substring(i,i+1)
				if((str!=" ")&&(str!=""))
					text=true
			}
		}
	}

	if (!text){
		alert(nm)
		field.focus()
		return false;
	}
	return true
}
return true
}

function lenword(field,nm){
	if (field.value!=""){
		var arr=new Array()
		arr=field.value.split(" ")
		for(i=0;i<arr.length;i++){
			if(arr[i].length>70){
				//alert("Sorry, the word '"+arr[i]+"' is too long.  Please enter another word. [max 70 char]")
				alert("Sorry, the word is too long.  Please enter another word. [one word max 70 char]")
				field.focus()
				return false;
			}
		}
	}

	return true
 }
 
 function ValidateEMail(objName)
{
	var sobjValue;
	var iobjLength;
	
	sobjValue=objName.value;
	
	iobjLength=sobjValue.length;
	
	iFposition=sobjValue.indexOf("@");
	iSposition=sobjValue.indexOf(".");
	iTmp=sobjValue.lastIndexOf(".");	
	
	if (iobjLength!=0)
	{
		if ((iFposition == -1)||(iSposition == -1))
		{
			alert("Please enter the Email address in correct format (yourname@company.com)")
			objName.focus();
			return false;
		}
		else if(sobjValue.charAt(0) == "@" || sobjValue.charAt(0)==".")
		{
			alert("Please enter the Email address in correct format (yourname@company.com)")
			objName.focus();
			return false;				
		}
		else if(sobjValue.charAt(iobjLength) == "@" || sobjValue.charAt(iobjLength)==".")
		{
			alert("Please enter the Email address in correct format (yourname@company.com)");
			objName.focus();
			return false;				
		}	
		else if((sobjValue.indexOf("@",(iFposition+1)))!=-1)
		{	
			alert("Please enter the Email address in correct format (yourname@company.com)")
			objName.focus();
			return false;
		}
		else if ((iobjLength-(iTmp+1)<2)||(iobjLength-(iTmp+1)>3))
		{
			alert("Please enter the Email address in correct format (yourname@company.com)")
			objName.focus();
			return false;
		}
		else if(sobjValue.indexOf(" ") != -1)
		{	
			alert("Please remove the space between the words")
			objName.focus();
			return false;
		}
		
		else
		{
			return true;
		}		
	}		
}  
