function LTrim( value )
{
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

// Removes ending whitespaces
function RTrim( value )
{
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

// Removes leading and ending whitespaces
function trim( value ) 
{
	return LTrim(RTrim(value));
}

function Handle(e)
{
	if ( e.keyCode == 27 )
	{
		closeMe();
	}
}

function closeMe()
{
	self.close();
}
//Check whether specified value is numeric or not?
function ValidateNo(NumStr, String)
{
	for(var Idx=0; Idx<NumStr.length; Idx++)
	{
		var Char = NumStr.charAt(Idx);
		var Match = false;

		for(var Idx1=0; Idx1<String.length; Idx1++)
		{
			if(Char == String.charAt (Idx1))
				Match = true;
		}

		if (!Match) 
			return false;
	}
	return true;
}

function validate()
{
	//validate name
	if (trim(document.myform.name.value) == "")
	{
		alert("Please Enter Your Name");
		document.myform.name.focus();
		return false;
	}
	
	//validate company name
	if (trim(document.myform.company.value) == "")
	{
		alert("Please Enter Your Company Name");
		document.myform.company.focus();
		return false;
	}
	
	if (document.myform.country.selectedIndex == 0)
	{
		alert("Please Select Country");
		document.myform.country.focus();
		return false;
	}

	//validate email
	var mail = document.myform.email.value;

	if(trim(document.myform.email.value)=="")
	{
		alert("Please enter a value for the Email Id.");
		document.myform.email.focus();
		return false;
	}

	if ((mail.length == mail.lastIndexOf('.')+1) || (mail.indexOf('@') != mail.lastIndexOf('@')))
	{
		alert("Please enter a proper Email Id");
		document.myform.email.focus();
		return false;
	}

	if(mail.indexOf('@')==-1 || mail.indexOf('.')==-1 ||  mail.indexOf('@',0)==0 || mail.indexOf('.',0)<1 || mail.indexOf('@.')!= -1 || mail.indexOf('.@')!=-1 || mail.indexOf('..')!=-1)
	{
		alert("Please enter a proper Email Id");
		document.myform.email.focus();
		return false;
	}

	if(!ValidateNo(document.myform.email.value,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@._-"))
	{
		alert("Please enter a proper Email Id");
		document.myform.email.focus();
		return false;
	}

	
	//validating phone number
	//country code
	if (trim(document.myform.cphone.value) == "")
	{
		alert("Please enter country code");
		document.myform.cphone.focus();
		return false;
	}
	
	if(!ValidateNo(document.myform.cphone.value,"1234567890+- "))
	{
		alert("Please Enter Only Number");
		document.myform.cphone.focus();
		return false;
	}
	//area code
	if (trim(document.myform.aphone.value) == "")
	{
		alert("Please enter area code");
		document.myform.aphone.focus();
		return false;
	}
	
	if(!ValidateNo(document.myform.aphone.value,"1234567890+- "))
	{
		alert("Please Enter Only Number");
		document.myform.aphone.focus();
		return false;
	}
	//phone code
	if (trim(document.myform.pphone.value) == "")
	{
		alert("Please enter phone number");
		document.myform.pphone.focus();
		return false;
	}
	
	if(!ValidateNo(document.myform.pphone.value,"1234567890+- "))
	{
		alert("Please Enter Only Number");
		document.myform.pphone.focus();
		return false;
	}

	
//fax code



	var name , company , address , country , phone , fax , email , comments;

	name = document.myform.name.value ;
	company = document.myform.company.value ;
	designation=document.myform.designation.value ;
	email = document.myform.email.value ;
	phone = document.myform.cphone.value+'-'+document.myform.aphone.value+'-'+document.myform.pphone.value;
	fax = document.myform.cfax.value+'-'+document.myform.afax.value+'-'+document.myform.pfax.value;
	country = document.myform.country.value ;
	comments = document.myform.comments.value;

	var str;
	str = "name="+name+"&company="+company+"&country="+country+"&phone="+phone+"&email="+email+"&comments="+comments+"&fax="+fax+"&designation="+designation;

	var xmlHttp = null 	
	if (typeof window.ActiveXObject != 'undefined' ) 
	{ 
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	else 
	{ 
		xmlHttp = new XMLHttpRequest(); 
	}

	var url="sendmail.asp?"+str+"&sid="+Math.random()

	xmlHttp.open("GET", url, false);
    xmlHttp.send(null);
	
	if (xmlHttp.readyState == 4 || xmlHttp.readyState=="complete") 
	{	
		document.getElementById("popup").innerHTML=xmlHttp.responseText
	}
}