
var isIE = (navigator.appName.indexOf('Internet Explorer')>-1);
var isNS = (navigator.appName.indexOf('Netscape')>-1);

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 _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;}
}

//REGISTATION FORM VALIDATION CODE-----------------------------------------------------------------

//This is used if you have a reset button on your form.
function clearForm()
{
	with(document.frm)
	{	
		firstname.value = "";
		lastname.value = "";
		title.value = "";
		company.value = "";
		address.value = "";
		address2.value = "";
		city.value = "";
		state.value = "";
		zipcode.value = "";
		telephone.value = "";
		fax.value = "";
		email.value = "";
		comment.value = "";
	}
}


function validateForm()
{
	with(document.frm)
	{
		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 name field')) return false;
	//	if(isBlank(address,'Entry required in Address field!')) return false;
	//	if(isBlank(city,'Entry required in City field!')) return false;
	//	if(isBlank(state,'Entry required in state field')) return false;
	//	if(isBlank(zipcode,'Entry required in zipcode field')) return false;
		if(isBlank(telephone,'Entry required in Telephone field')) return false;
		if(!isEmailAddressValid(email.value))
		{
			alert('Please fill your email in the correct format');
			email.focus();
			return false;
		}
	}
	return true;
}

function submitForm()
{
	if(validateForm())
	{
		document.frm.submit();
	}
}