// Global Variables
var map = ""; // Initialize to string for printing function

// Check for empty searches
function validateSearch()
{
    if ( document.search_form.sp_q.value.match( /^\s*$/ ) != null )
    {
        alert( "Please enter a search phrase" );
        return false;
    }
    document.getElementById('site-search').submit();	
    return true;
}

// Standard print routine
function doPrint()
{
    // Print routine for map pages
    if ( typeof(map) == "object" ) {
        map.showStaticMap();
        window.print();
        //HidePrinterFriendly
        map.hideStaticMap();
    } else {
        window.print();
    }
}

// Add trim function to strings
String.prototype.trim = function () {
	return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function clearForm() {
	theForm = document.contact;
	for( var i=0; i<theForm.elements.length; i++ ) {
		if (theForm.elements[i].type == "text" || theForm.elements[i].type == "textarea") {
			theForm.elements[i].value = "";
		}
	}
}

function submitForm() {
	var flag = true;
	var alertMsg = "";

	if ( document.contact.name.value == "" || document.contact.name.value == null) {
		flag = false;
		alertMsg = "Name is a required field.\n";
	}
	if ( document.contact.email.value == "" || document.contact.email.value == null) {
		flag = false;
		alertMsg += "Email is a required field.\n";
	}
	if ( document.contact.category && document.contact.category.value == "-1" ) {
		flag = false;
		alertMsg += "You must select a comment category.";
	}
	tmp = document.contact.comment.value;
	if ( tmp.indexOf("<") >= 0 || tmp.indexOf(">") >= 0 ) {
		flag = false;
		alertMsg += "Invalid characters in form. Please do not use '<' or '>' characters.";
	}
	// Submit if there are no errors
	if ( flag ) {
		document.contact.submit();
	} else {
		alert(alertMsg);
	}
}

function submitNDAPrimeForm() {
	document.ndaform.submit();
}

function submitNDASubForm() {
	document.ndaform.submit();
}

// Correcly handle external links in HTML 4.01
// Created by Robert Falconer 2/21/2008
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;


