var emesage="";

function fnTrim(string)
{
	var cnt;	
	len = string.length;
	str = string;
	begin = -1;
	for(cnt=0;cnt<len;cnt++)
	{
		if (str.charAt(cnt) == " ")
		{	
			begin = cnt;
		}	
		else
		break;
		
	}
	str = str.slice(begin+1,len);
	len = str.length;
	end = len;
	for(cnt=len-1;cnt>=0;cnt--)
	{
		if (str.charAt(cnt) == " ")
		{	
			end = cnt;
		}	
		else
		break;
	}
	str = str.slice(0,end);
	return str;
}
function fnIsNull(txtfld, mes)
{ 

 
	   var string=txtfld.value;
       if (fnTrim(string) == null || fnTrim(string) == "" )
       {
	//   	alert(mes);
	 emesage +="-- "+mes+"\n"

		
     	return true;
       }
		return false;
}

function checkName(fld,mes)
{
	var x = fld.value;
	var filter  = /^([a-zA-Z\s]*)$/;
	if (!filter.test(x)) 
	{
		//   	alert(mes);
	 emesage +="-- "+mes+"\n"
	
	}
	else
	return false;
	return true;
	
}

function checkMail(fld,mes)
{
	var x = fld.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9.]{2,5})+$/;
	if (!filter.test(x)) 
	{
		//   	alert(mes);
	 emesage +="-- "+mes+"\n"

	}
	else
	return false;
	return true;
	
}
function getkey(e){
if (window.event)
return window.event.keyCode;
else if (e)
return e.which;
else
return null;
}
	function goodchars(e, goods){
	//alert(e.value);
var key, keychar;
key = getkey(e);
if (key == null) return true;
keychar = String.fromCharCode(key);
if (goods.indexOf(keychar) != -1)
	return true;
if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
	return true;
return false;
}

function dropDownMenu(menu, mes) 
   {
   var myindex=menu.selectedIndex;
      
   if (myindex==0)
      {
      	//   	alert(mes);
	 emesage +="-- "+mes+"\n"
   
	  return true;
	  }
	else 
		{
		return false;
		}
   }

function sorry(mes)
{
	alert(mes);
	return false;
}

function onlyalpha(event)
{

	return goodchars(event, "abcdefghijklmnopqurstuvwxyz");
		
}

function validateform()
{  

frm=document.contact;

fnIsNull(frm.title,"Please Enter title")

fnIsNull(frm.firstname,"Please Enter First Name")

	
checkName(frm.firstname,"First name is not valid name")
fnIsNull(frm.lastname,"Please Enter Last Name")

checkName(frm.lastname,"Last name is not valid name")

	

		
fnIsNull(frm.company,"Please Enter Company Name")
fnIsNull(frm.email,"Please Enter Email Address")

checkMail(frm.email,"Enter Valid Email Address")
fnIsNull(frm.phone,"Please Enter Valid Phone no.")
fnIsNull(frm.budget,"Please Enter Budget in numbers")

//checkPhone(frm.phone,"Please Enter Valid Phone no.")
dropDownMenu(frm.country,"Please select country")
dropDownMenu(frm.profile,"please select the your business profile")
dropDownMenu(frm.aboutus,"please select how did you hear about us")
dropDownMenu(frm.interest,"please select the trade you are interested in")
//fnIsNull(frm.comments,"Please Enter your valuble question & comments")
fnIsNull(frm.comments,"Please describe your requirements")
 
	 
	 if (emesage!="" || emesage.length>0)
	 {
          showmessage= "Please enter the following details :-\n---------------------------------------------------------\n"+emesage;
        alert(showmessage);
		emesage="";
		return false;


	 }
	 else
		 return true;
		
			
		
}


function checkPhonepart(fld,mes)
{

var x = fld.value;
	var filter  = /^\d{3,4}$/;
	if (!filter.test(x)) 
	{
	alert(mes);
	fld.focus()
	}
	else
	return false;
	return true;

}
function checkPhonepart2(fld,mes)
{

var x = fld.value;
	var filter  = /^\d{10,11}$/;
	if (!filter.test(x)) 
	{
	alert(mes);
	fld.focus()
	}
	else
	return false;
	return true;

}

function getkey(e){
if (window.event)
return window.event.keyCode;
else if (e)
return e.which;
else
return null;
}

function onlyNumbers(e){
	//alert(e.value);
var key, keychar;
var goods="0123456789";
key = getkey(e);
if (key == null) return true;
keychar = String.fromCharCode(key);
if (goods.indexOf(keychar) != -1)
	return true;
if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
	return true;
return false;
}

		
function checkPhone(fld,mes)
{

var x = fld.value;
	var filter  = /^\d{10,11}$/;
	if (!filter.test(x)) 
	{
	//   	alert(mes);
	 emesage +="-- "+mes+"\n"
	
	}
	else
	return false;
	return true;

}

	
	
	

		



	


