


function emailCheck(emailStr)
{
    var checkTLD = 1;
    var knownDomsPat = /^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
    var emailPat = /^(.+)@(.+)$/;
    var specialChars = "\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
    var validChars = "\[^\\s" + specialChars + "\]";
    var quotedUser = "(\"[^\"]*\")";
    var ipDomainPat = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
    var atom = validChars + '+';
    var word = "(" + atom + "|" + quotedUser + ")";
    var userPat = new RegExp("^" + word + "(\\." + word + ")*$");
    var domainPat = new RegExp("^" + atom + "(\\." + atom +")*$");
    var matchArray = emailStr.match(emailPat);

    if (matchArray == null)
    {
	    alert("Email address " + emailStr + " seems incorrect (check @ and .'s)");
	    return false;
    }

    var user = matchArray[1];
    var domain = matchArray[2];

    // Start by checking that only basic ASCII characters are in the strings (0-127).

    for (i = 0; i  <user.length; i++)
    {
	    if (user.charCodeAt(i) > 127)
	    {
		    alert("Email address " + emailStr + " contains invalid characters.");
		    return false;
	    }
    }

    for (i = 0; i < domain.length; i++)
    {
	    if (domain.charCodeAt(i) > 127)
	    {
		    alert("Email address " + emailStr + " contains invalid characters.");
		    return false;
	    }
    }

    // See if "user" is valid 

    if (user.match(userPat) == null)
    {
	    // user is not valid

	    alert("The username in " + emailStr + " doesn't seem to be valid.");
	    return false;
    }

    var IPArray = domain.match(ipDomainPat);

    if (IPArray != null)
    {
	    // this is an IP address

	    for (var i = 1; i <= 4; i++)
	    {
		    if (IPArray[i] > 255)
		    {
			    alert("Destination IP address is invalid in " + emailStr + ".");
			    return false;
		    }
	    }
    	
	    return true;
    }

    // Domain is symbolic name. Check if it's valid.
    var atomPat = new RegExp("^" + atom + "$");
    var domArr = domain.split(".");
    var len = domArr.length;

    for (i = 0; i < len; i++)
    {
	    if (domArr[i].search(atomPat) == -1)
	    {
		    alert("The domain name does not seem to be valid in " + emailStr + ".");
		    return false;
	    }
    }
    if (checkTLD && domArr[domArr.length-1].length != 2 && domArr[domArr.length-1].search(knownDomsPat) == -1)
    {
	    alert("The address " + emailStr + " must end in a well-known domain or two letter " + "country.");
	    return false;
    }

    // Make sure there's a host name preceding the domain.

    if (len < 2)
    {
	    alert("Email address " + emailStr + " is missing a hostname!");
	    return false;
    }

    // If we've gotten this far, everything's valid!
    return true;
}

function trim(varStr) {
	return varStr.replace(/^\s+|\s+$/g,"");
}

function keyPressed(e, action){
    var keyPressed;
    if(window.event)
        keyPressed = window.event.keyCode; // IE
    else
        keyPressed = e.which; // Firefox

    if (keyPressed == 13) {
        if(action == "Search"){
            search();
        }
        if(action == "ContactUs" || action == "Agency"){
            validate();
        }
        if(action == "SignUp")
        {
            document.forms['mc-embedded-subscribe-form'].submit();
        }
    }
}

function search()
{
    if(trim(document.getElementById("txtSearch").value).length == 0)
    {
        alert("You must enter your search keywords.");
        document.getElementById("txtSearch").focus();
        return false;
    }
    if(trim(document.getElementById("txtSearch").value).length < 3)
    {
        alert("Your search keywords must be at least 3 characters long");
        document.getElementById("txtSearch").focus();
        return false;
    }
    document.getElementById("frmSearch").submit();
}

function submitProfile()
{
    document.getElementById("frmHead").action = Application["ApplicationPath"] + "/submit-your-profile.aspx";
    document.getElementById("frmHead").submit();
}

function submitProfile2()
{
    location.href = Application["ApplicationPath"] + "/submit-your-profile.aspx";
}

 function document_onload(){
    if (document.getElementById("txtLoadMessage").value.length > 0){
        alert(document.getElementById("txtLoadMessage").value);
    }
    dropDownSearchNav();
 }
function dropDownSearchNav()
{
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp("sfhover"), "");
		}
	}
	
	if(document.getElementById("privateNav") != null)
	{
	    var sfEls = document.getElementById("privateNav").getElementsByTagName("LI");
	    for (var i=0; i<sfEls.length; i++) {
		    sfEls[i].onmouseover=function() {
			    this.className+=" sfhover";
		    }
		    sfEls[i].onmouseout=function() {
			    this.className=this.className.replace(new RegExp("sfhover"), "");
		    }
	    }
	}
}

