//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 newWindow() {
    var option = "height=400,width=400 scrollbars=no"
    mapWindow=window.open('how_to_join.htm', 'mapWin', option)
}

function alfredWindow() {
    var option = "height=400,width=410 scrollbars=no"
    mapWindow=window.open('alfreds_story.htm', 'mapWin', option)
}

function ninaWindow() {
    var option = "height=600,width=400 scrollbars=no"
    mapWindow=window.open('ninas_story.htm', 'mapWin', option)
}


//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 telephone number or a valid e-mail address.");
		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;
}

