

function trim(text)

{
// Erase blank in the most left and most right sections of a string
	var i,j;
	for(i=0; text.charAt(i)==' ' && i<text.length; i++){}
	if(i==text.length) return ''
	for(j=text.length-1; text.charAt(j)==' ' && j>-1; j--){}
	return text.substring(i,j+1);
}


function isBlank(obj,message)
{
//Check whether the Object Value is blank
//If blank, show alert message
	if(trim(obj.value) == ''){
		if(trim(message) != ''){
			obj.focus();
			alert(message);
		}
		return true;
	} else {
		return false;
	}
}


function numberOnly(obj,event)
{
	var isIE = (navigator.appName.indexOf('Internet Explorer')>-1);
	var isNS = (navigator.appName.indexOf('Netscape')>-1);
	var _ret = true;
	if(isIE)
	{
		if (event.keyCode<46 || event.keyCode>57)
		{
			_ret = false;
		}
	}

	if(isNS)
	{
		if((event.which<46 || event.which>57) && event.which!=8 && event.which!=0)
		{
			_ret = false;
		}
	}

	return (_ret); 
}


function isEmailAddressValid(EmailAddr){
	//Check whether an email address expression is valid
	var re = new RegExp();
	re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	if (!re.test(EmailAddr)) {return false;}
	else {return true;}
}


function validateForm()
{
	with(document.info){
		if(isBlank(YourName,'Please enter your name.')) return false;
		if(isBlank(YourCompany,'Please enter your company.')) return false;
		if(isBlank(YourPhone,'Please enter your phone number.')) return false;
		if(isBlank(YourEmail,'Please enter your email address.')) return false;
		if(isBlank(YourInquiry,'Please enter your inquiry.')) return false;
		if(YourEmail.value != "")
		{
			if(!isEmailAddressValid(YourEmail.value))
			{
				alert ('Invalid Email format');
				YourEmail.focus();return false;
			}
		}
	}
	return true;
}
