// begin hide email address from spambots
var user;
var domain;
var suffix;
var subject;

function invisimail(user, domain, suffix, subject)
{
document.write('<a href="' + 'mailto:' + user + '@' + domain +
'.' + suffix + subject + '" class="your_link_class">' + user + '@' + domain
+ '.' + suffix + '</a>');
}
// end spambot script

// begin open in new window script
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";
 }
}
window.onload = externalLinks;
// end open in new window script

// IE Dropdown Menu Fix for :hover pseudo class
nnHover = function() {
	var nnEls = document.getElementById("nav").getElementsByTagName("li");
	for (var i=0; i<nnEls.length; i++) {
		nnEls[i].onmouseover=function() {
			this.className+=" nnhover";
		}
		nnEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" nnhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", nnHover);

// email validation
function isValidEmail(email, required) {
    if (required==undefined) {   // if not specified, assume it's required
        required=true;
    }
    if (email==null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length==0) {  
        if (required) {
            return false;
        }
        return true;
    }
    if (! allValidChars(email)) {  // check to make sure all characters are valid
        return false;
    }
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        return false;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
        return false;
    } else if (email.indexOf("@") == email.length) {  // @ must not be the last character
        return false;
    } else if (email.indexOf("..") >=0) { // two periods in a row is not valid
	return false;
    } else if (email.indexOf(".") == email.length) {  // . must not be the last character
	return false;
    }
    return true;
}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}

function highLight() {
	if (reqd) {
		for (var i=0; i<reqd.length; i++)
		if (ele=document.getElementById(reqd[i])) {
			ele.style.backgroundColor='salmon';
			ele.onfocus=function () {this.style.backgroundColor='';}
		}
	}
}

function validEmail(val) {
	return val.match(/^.+@[^\.].*\.[a-z]{2,}$/);
}

function luhnCheck(cardNumber) {
	var no_digit = cardNumber.length;
	var oddoeven = no_digit & 1;
	var sum = 0;
	for (var count = 0; count < no_digit; count++) {
		var digit = parseInt(cardNumber.charAt(count));
		if (!((count & 1) ^ oddoeven)) {
			digit *= 2;
			if (digit > 9) digit -= 9;
		};
		sum += digit;
	};
	if (sum == 0) return false;
	if (sum % 10 == 0) return true;
}

function checkStateReq(ele) {
	for (i=0; i<ele.childNodes.length; i++) {
		if (ele.childNodes.item(i).selected) {
			if ((ele.childNodes.item(i).value==1) || (ele.childNodes.item(i).value==34)) {
				document.getElementById('state_req').innerHTML='*';
			} else {
				document.getElementById('state_req').innerHTML='';
			}
		}
	}
	
}
// Retype Email Script

function checkValidEmail() {
email1= document.contact_form.emailadd.value;
if (/^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@(([\w\-]?)+\.)+([a-z]{2,4})$/i.test(email1)) {
// alert ("Valid Address"); // simply comment out this line if not required
}
else {
alert ("Invalid Email Address - Please Re-Enter");
document.contact_form.emailadd.value = "";
document.contact_form.emailadd.focus();
}
}

function checkConfirmEmail() {
email2 = document.contact_form.conemail.value;
if (email2 != email1) {
alert ("Email addresses do not match - please re-enter!");
document.contact_form.emailadd.value = "";
document.contact_form.conemail.value = "";
document.contact_form.emailadd.focus();
}
}
