/***********************************************************
* site: http://www.homesecurityandsound.com
* author: Sam Barnes
*
* description: functions for the Home Security & 
*			   Sound website
*
***********************************************************/

/* 
Validates the fields on contact-us.html to make sure required 
fields have been populated and the email address is valid
*/
function validateForm() {
	var okSoFar=true
 	with (document.phpformmailer) {
  	var foundAt = email.value.indexOf("@",0)
  	if (foundAt < 1 && okSoFar) {
	    okSoFar = false
	    alert ("Please enter a valid email address.")
	    email.focus()
  	}
	var e1 = email.value
	var e2 = email2.value
  	if (!(e1==e2) && okSoFar) {
	    okSoFar = false
	    alert ("Email addresses you entered do not match.  Please re-enter.")
	    email.focus()
  	}
  	if (thesubject.value=="" && okSoFar) {
	    okSoFar=false
	    alert("Please enter the subject.")
	    thesubject.focus()
  	}
	if (themessage.value=="" && okSoFar) {
	    okSoFar=false
	    alert("Please enter the details for your enquiry.")
	    themessage.focus()
	}
  	if (okSoFar==true)  submit();
	}
}


/* 
Validates the fields on assessment.html to make sure required 
fields have been populated and the email address is valid
*/
function validateAssessmentForm() {
	var okSoFar=true
 	with (document.phpformmailer) {
  	var foundAt = email.value.indexOf("@",0)
  	if (foundAt < 1 && okSoFar) {
	    okSoFar = false
	    alert ("Please enter a valid email address.")
	    email.focus()
  	}
	var e1 = email.value
	var e2 = email2.value
  	if (!(e1==e2) && okSoFar) {
	    okSoFar = false
	    alert ("Email addresses you entered do not match.  Please re-enter.")
	    email.focus()
  	}
  	if (thesubject.value=="" && okSoFar) {
	    okSoFar=false
	    alert("Please enter the subject.")
	    thesubject.focus()
  	}
    if (thephonenumber.value=="" && okSoFar) {
	    okSoFar=false
	    alert("Please enter your telephone number.")
	    thesubject.focus()
  	}
	if (theaddress.value=="" && okSoFar) {
	    okSoFar=false
	    alert("Please enter your home address.")
	    themessage.focus()
	}
  	if (okSoFar==true)  submit();
	}
}


// XHTML 1.0 Strict compliant open new window
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors .length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
			anchor.target = "_blank";
			anchor.title = (anchor.title != "") ? anchor.title+" (Opens in a new window)" : "Opens in a new window";
			anchor.className = (anchor.className != '') ? anchor.className+' external' : 'external';
			}
		}
	}
	window.onload = externalLinks;


// Clickable link allowing users to add the website to their Internet browser favorites
function addToFavorites () {
	if (document.all) {
		window.external.AddFavorite("http://www.homesecurityandsound.com","Home Security and Sound, Hawaii")
	}
}





