

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(FirstName,'Entry required in First Name field!')) return false;
		if(isBlank(LastName,'Entry required in Last Name field!')) return false;
		if(isBlank(Company,'Entry required in Company field!')) return false;
		if(isBlank(Email,'Entry required in Email field!')) return false;
		if(isBlank(Phone,'Entry required in Phone field!')) return false;
		if(isBlank(Reason,'Entry required in I am interested in field!')) return false;
		if(Email.value != "")
		{
			if(!isEmailAddressValid(Email.value))
			{
				alert ('Invalid Email format');
				Email.focus();return false;
			}
		}
	}
	return true;
}