function openWindow() {
	var features = "'left=20,top=20,width=360,height=450,toolbar=0,resizable=0'";
	var URL = "trailForm.html";
	
	myRef = window.open(''+URL,'mywin', features);

}//openWindow

function disableButtons() {
	document.trailForm.submitButton.disabled = true;
	document.trailForm.resButton.disabled = true;
	document.trailForm.btnCancel.disabled = true;
}//disableButtons

function enableButtons() {

	document.trailForm.submitButton.disabled = false;
	document.trailForm.resButton.disabled = false;
	document.trailForm.btnCancel.disabled = false;

}//enableButtons

function validate(frm) {
	
	var dataIsValid = true;
	
	//alert("Entered validation function");
	
	disableButtons();
	
	//edit each input text field.
	var tName = trim(frm.tName.value);
	var validate = validateNull(tName, "Your name");
	if(!validate) {
		enableButtons();
		return false;
	}//if
	
	var tEmail = trim(frm.tEmail.value);
	validate = validateNull(tEmail, "Email address");
	if(!validate) {
		enableButtons();
		return false;
	}else{
		//check email to make sure it is properly qualified.
		validate = checkEmail(tEmail);
		if(!validate) {
			//the email is not properly formatted.
			alert("Email address must be fully qualified");
			enableButtons();
			return false;
		}else{
			//the email is valid
		}
	}//if -- email validation.
	
	var tPhone = trim(frm.tPhone.value);
	//alert("tPhone is " + tPhone);
	
	validate = validateNull(tPhone, "Phone number");
	if(!validate) {
		enableButtons();
		return false;
	}//if
	
	return validate;

}//validate


function validateNull(theData, fieldLabel) {
	var validate = true;
	if(theData == "") {
		alert(" " + fieldLabel + " is required. Please correct this entry and try again.");
		validate = false;
	}
	return validate;
}//validateNull

function checkEmail(emailad)
{

    var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
    var check=/@[\w\-]+\./;
    var checkend=/\.[a-zA-Z]{2,3}$/;

    if(((emailad.search(exclude) != -1)||(emailad.search(check)) == -1)||(emailad.search(checkend) == -1))
    {
        validate= false;
        //alert("Email address must be property qualified.\nExample: 'someuser@aol.com'");
    }//if
    else validate = true;
    return validate;
   
}//checkEmail


function leftTrim(strV)
{

    var strL;
    strL=strV;
   
    while(strL.length > 0 && strL.charAt(0) == " ")
    {
        strL=strL.substring(1,strL.length);
    }//while
   
    return strL;

}//leftTrim


function rightTrim(strV)
{

    var strL="";
   
    if(strV != null) strL=strV;
   
    while(strL.length > 0 && strL.charAt(strL.length - 1) ==" ")
    {
          strL=strL.substring(0,strL.length-1);
    }//while
   
    return strL;
   
}//rightTrim

function trim(strV)
{

     return (leftTrim(rightTrim(strV)));
    
}//trim
