//1st Person Generic JS Functions
//©2007 1st Person Solutions, All Rights Reserved
//For use only on sites written by 1st Person Solutions

//Determine DOM Tree
var IE = (document.all) ? 1 : 0;
var DOM = 0; 
if (parseInt(navigator.appVersion) >=5) {DOM=1};

//Trap enter key, requires <body onKeyPress="keyPress()">
function keyPress() {
   if (event.keyCode == 13){
      event.returnValue = false;
   }
}

//Turn on and off divs with checkboxes
function showHideDiv(thisDivID){
    var thisDivSec = thisDivID + "div";
    var divSecStyle = document.getElementById(thisDivSec).style;
    if(document.getElementById(thisDivID).checked == true){
        if (divSecStyle != false) {
            divSecStyle.display = "block";
        }
    } else {
        if (divSecStyle != false) {
            divSecStyle.display = "none";
        }
    }
}

//Check the email address
function checkEmail(strng){
	var error="";
	if(strng == ""){
		error = "You didn't enter an email address.\n";
	}
	var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(strng))) { 
		error = "Please enter a valid email address.\n";
	} else {
//test email for illegal characters
		var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
		if(strng.match(illegalChars)){
			error = "The email address contains illegal characters.\n";
		}
	}
	return error;    
}

//Checks a field to see if it is empty
function checkCounts(strng,name,minLen,maxLen) {
var error = "";
  if (strng.length == 0) {
     error = name + " has not been filled in.\n";
  } else {
    if (strng.length < minLen || strng.length > maxLen) {
        error = name + " is not within the specified length.\n";
    }
  }
return error;	  
}
