//Writes current year; Used in the copyright area to keep the date current.
function writeDate() {
   var today = new Date();
   var year = today.getFullYear();
   document.write(year);
}

//Pop up windows
function openpopup(popupurl) {
    var option = "height=300,width=300,scrollbars=no"
    winpops=window.open(popupurl,'winname', option)
	winpops.focus()
}

function zipcodesWindow(popupurl) {
    var option = "height=600,width=260,scrollbars=yes"
    winpops=window.open('zip_codes.htm', 'zipcodesWin', option)
	winpops.focus()
}


//Validate information on 'Request Information' form (Contact Info page)
//This function ensures that the input data must contain at least an @ sign and a dot (.). 
//Also, the @ must not be the first character of the email address, and the last dot must 
//at least be one character after the @ sign.
function validate_email(email) {
   with (email) {
   apos=email.indexOf("@")
   dotpos=email.lastIndexOf(".")
   if (apos<1||dotpos-apos<2) {
      alert("You must enter a valid e-mail address.");
	  document.form1.email.focus();
      return false
    }
    else {
      return true
    }
    }
}


function validate_phone()
{
   if(document.form1.phone.value.search(/\d{3}\-\d{3}\-\d{4}/)==-1) {
      alert("The phone number you entered is either not valid or not in the correct format.\r\nPlease enter a phone number with the format xxx-xxx-xxxx.");
      return false;
   }
   else {
      return true
   }
}


function validateForm() {
	if (trim(document.form1.name.value) == '') {
		alert ("Please enter your name.");
		document.form1.name.focus();
		return false;
		}
    if  (trim(document.form1.phone.value) == '' && trim(document.form1.email.value) == ''){
		alert ("Please enter a valid telephone number and e-mail address.");
		document.form1.email.focus();
		return false;
	}
	if  (trim(document.form1.email.value) == ''){
		alert ("Please enter a valid e-mail address.");
		document.form1.email.focus();
		return false;
	}
	if  (trim(document.form1.phone.value) == ''){
		alert ("Please enter a valid telephone number.");
		document.form1.phone.focus();
		return false;
	}
    if  (trim(document.form1.email.value) != '') {
	    return validate_email(document.form1.email.value);
	}
	if  (trim(document.form1.phone.value) != '') {
	    return validate_phone(document.form1.phone.value);
	}
	else
	    return true;
}


function trim(strText) {
   //this will get rid of leading spaces 
   if (strText != null && strText != 'undefined'){
   while (strText.substring(0,1) == ' ') 
       strText = strText.substring(1, strText.length);

   //this will get rid of trailing spaces 
   while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);
   }
   return strText;
}


function quickLinkMenu(selObj){
var page = selObj.options[selObj.selectedIndex].value

	if (page.substr(0,1) == "+") {  //Is there a '+' at the first character  -- '+' means to open in new window
		page = page.substr(1);	//remove the '+' from the string
		window.open(page);   //targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	} 
	else {
		window.location.href=page;	// Open in parent window
	}
	selObj.selectedIndex=0;		// Reset the list to the first item
}

