function trim(value) 
{
	
	//function to trim any leading, following and inner spaces
	var temp = value;
	var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
	if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
	var obj = /  /g;
	while (temp.match(obj)) { temp = temp.replace(obj, " "); }
	return temp;
}

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));
}

//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 (document.getElementById("name1").value == "")
	{
		alert("Please Enter Your Name")
		document.getElementById("name1").focus();
		return false
	}
	
	//validate company name
	if (document.getElementById("company1").value == "")
	{
		alert("Please Enter Your Company Name");
		document.getElementById("company1").focus();
		return false;
	}
	
	//validate email
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById("email1").value))
	{
		
	}
	else
	{	
		alert("Invalid E-mail Address! Please re-enter.")
		document.getElementById("email1").focus()
		return false;
	}
	
	//validating phone number
	//phone code
	if (document.getElementById("phoneno1").value == "")
	{
		alert("Please enter phone number");
		document.getElementById("phoneno1").focus();
		return false;
	}
	
	if(!ValidateNo(document.getElementById("phoneno1").value,"1234567890+- "))
	{
		alert("Please Enter Only Number");
		document.getElementById("phoneno1").focus();
		return false;
	}
	
	//Country Validation
	if (document.getElementById("country1").selectedIndex == "")
	{
		alert("Please Enter Your Country");
		document.getElementById("country1").focus();
		return false;
	}
	
	//City Validation
	if (document.getElementById("city1").value == "")
	{
		alert("Please Enter Your City");
		document.getElementById("city1").focus();
		return false;
	}
	
	// MBA As Validation
	 if (document.getElementById("mba").selectedIndex == "")
	{
		alert("Please Select Your Business Area");
		document.getElementById("mba").focus();
		return false;
	}
	
	//validate comments
	if (document.getElementById("comments1").value == "")
	{
		alert("Please Enter Your Comments");
		document.getElementById("comments1").focus();
		return false;
	}
	

	var name , company , address , country , phone , fax , email , comments;

	name = escape(document.getElementById("name1").value) ;

	company = escape(document.getElementById("company1").value) ;
	email = escape(document.getElementById("email1").value) ;
	phone = escape(document.getElementById("phoneno1").value);
	country = escape(document.getElementById("country1").value) ;
	comments = escape(document.getElementById("comments1").value);
	city = escape(document.getElementById("city1").value);
	mba = escape(document.getElementById("mba").value);
	
	var str;
	str = "name="+name+"&company="+company+"&country="+country+"&phone="+phone+"&email="+email+"&comments="+comments+"&city="+city+"&mba="+mba;

	var xmlHttp = null 	
	if (typeof window.ActiveXObject != 'undefined' ) 
	{ 
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	else 
	{ 
		xmlHttp = new XMLHttpRequest(); 
	}

 var url="/services/promotion/fabric-expo-2008-chinese/contact-us/sendmail.asp?dire=yes&"+str+"&sid="+Math.random()

	xmlHttp.open("GET", url, false);
    xmlHttp.send(null);
	
	if (xmlHttp.readyState == 4 || xmlHttp.readyState=="complete") 
	{	
		document.getElementById("directory").innerHTML=xmlHttp.responseText
	}
}

function Handle(e)
{
	if ( e.keyCode == 27 )
	{
		self.close();
	}
}
function closeMe()
{
	self.close();
}
