function validate(formElement) {

	var frm = formElement;
	var errors = '';
	var requiredFields = '';
	var invalidFields = '';
	var requredFieldsLabel = 'The following fields are required:';
	var invalidFieldsLabel = 'The following fields are invalid:';

	switch (frm.id) {
		case 'makeCard':
			// check required fields
			if (frm.txtFromName.value.length == 0) requiredFields += '\n - ' + frm.txtFromName.title;
			if (frm.txtFromEmail.value.length == 0) requiredFields += '\n - ' + frm.txtFromEmail.title;
			if (frm.txtToName.value.length == 0) requiredFields += '\n - ' + frm.txtToName.title;
			if (frm.txtToEmail.value.length == 0) requiredFields += '\n - ' + frm.txtToEmail.title;
			
			// check for valid e-mail addresses
			if (!emailCheck(frm.txtFromEmail.value)) invalidFields += '\n - ' + frm.txtFromEmail.title;
			if (!emailCheck(frm.txtToEmail.value)) invalidFields += '\n - ' + frm.txtToEmail.title;

			invalidFields += textCounter(frm.txtMessage,1000,15,60);
			
		break;
	}

	if (requiredFields.length > 0) errors += requredFieldsLabel + requiredFields;
	if (requiredFields.length > 0 && invalidFields.length > 0) errors += '\n\n';
	if (invalidFields.length > 0) errors += invalidFieldsLabel + invalidFields;
	if (errors.length > 0) {
		alert(errors);
		return false;
	}

	return true;

}

/* === FLASH VERSION REQUIREMENTS: === */

    var requiredVersion = 7;   // Version the user needs to view site (max 9, min 2)
    var jsVersion = 1.0;       // Do not change or delete.


/* === POPUPS === */

function popup(cPopUrl, cPopName, iPopWidth, iPopHeight, bScrollBars, resizable) {
	var iPopLeft, iPopTop;
	var oPopWindow = null;
	if (!oPopWindow || oPopWindow.closed){
		//Center popup window inside parent window.
		iPopLeft = (window.screen.width/2) - ((iPopWidth/2) + 10);
		iPopTop = (window.screen.height/2) - ((iPopHeight/2) + 50);
		//Open popup window
		oPopWindow=open(cPopUrl, cPopName,"height="+ iPopHeight +",width="+ iPopWidth +",left=" + iPopLeft + ",top=" + iPopTop + ",screenX=" + iPopLeft + ",screenY=" + iPopTop + ",scrollbars=" + bScrollBars + ",resizable=" + resizable + ", status=yes");
		oPopWindow.location.href = cPopUrl;
		oPopWindow.focus()
    } else {
    	oPopWindow.focus()
	}
	return oPopWindow;
}

/* === AUDIENCE SELECTOR === */

    function gotoURL(obj) {
        var url = obj.options[obj.options.selectedIndex].value;
        if (url != "") location.href = url;
    }


/* === XHTML COMPATABILITY === */

    onLoadFuncs = new Array();
    function addOnLoad(func){
    	onLoadFuncs[onLoadFuncs.length] = func;
    }
    function runOnLoad(){
    	for(i in onLoadFuncs){
    		eval(onLoadFuncs[i]+"()");
    	}
    }
    window.onload = runOnLoad;

    function handleExternalLinks() {
    	var anchors = document.getElementsByTagName("a");
    	var i, href;
    	for(i=0; i < anchors.length; i++){
    		if(!anchors[i].href) continue;
    		href = anchors[i].href;

    		if(href.indexOf("emerald") == -1){ // Href is not a file on my server
    			if(href.indexOf("javascript:") == -1){ // Href is not a javascript call
    				if(!anchors[i].onclick){ // Href does not have an onclick event
    					if(href.indexOf("mailto:") == -1){ // Href is not a mailto:
    						if(href.indexOf("http://") != -1 || href.indexOf("https://") != -1) { // Href is not relative (for Safari)
    							anchors[i].setAttribute("target","_blank");
    						}
    					}
    				}
    			}
    		}

    		// things that must open in a new browser window.
    		if (href.indexOf(".pdf") > 0 && href.indexOf("download.asp?file") <= 0) anchors[i].setAttribute("target","_blank");

    	}
    }

    if(document.getElementsByTagName){
    	//addOnLoad("handleExternalLinks");
    }



function textCounter(theField,maxChars,maxLines,maxPerLine) {
	var strTemp = "";
	var strLineCounter = 0;
	var strCharCounter = 0;
	var strWarning = "";
	
	for (var i = 0; i < theField.value.length; i++) {
		var strChar = theField.value.substring(i, i + 1);

		if (strChar == '\n') {
			strTemp += strChar;
			strCharCounter = 1;
			strLineCounter += 1;
		} else if (strCharCounter == maxPerLine) {
			strTemp += '\n' + strChar;
			strCharCounter = 1;
			strLineCounter += 1;
		} else {
			strTemp += strChar;
			strCharCounter ++;
		}
	}

	if (strLineCounter > maxLines) strWarning += '\n - ' + theField.title + " - Maximum number of lines (" + maxLines + ") exceeded : " + strLineCounter;

	if (theField.value.length > maxChars) strWarning += '\n - ' + theField.title + " - Maximum number of characters (" + maxChars +") exceeded : " + theField.value.length;
	
	return strWarning;
}

//Add trimming functions to the String object.
String.prototype.trim = function(){ return this.replace(/^\s*|\s*$/g,''); }
String.prototype.ltrim = function(){ return this.replace(/^\s*/g,''); }
String.prototype.rtrim = function(){ return this.replace(/\s*$/g,''); }

function isAlpha(p_strValue) {
    //Define Matching expression
    var l_regExp = /^[a-zA-Z\ \'\-\.\,]*$/;
    var l_strValue = p_strValue.trim()
    if (l_strValue.match(l_regExp)) 
        return true; 
    else 
        return false;
}

function isNumeric(p_strNum) {   
    if (p_strNum.match(/^\d+$/)) 
        return true; 
    else 
        return false;
}

function isPassword(p_strPass)
{
    //Alpha numeric password 6-15 characters long.
    var l_regExp = /(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{6,15})$/;
    if (p_strPass.match(l_regExp)) 
        return true; 
    else 
        return false;
}

function isValidPhoneNumber(p_strPhone) {
    //Define Matching expression
    var l_regPhone = /^(1-)*\(*\d{3}(\)|\-) *\d{3}-\d{4}( |$)/;
    
    if (p_strPhone.match(l_regPhone)) 
        return true; 
    else 
        return false;
}

function isValidZipCode(p_strZip) {
    //Define Matching expression
    var l_regExp = /(^\d{5}$)|(^\d{5}-\d{4}$)/
    
    if (p_strZip.match(l_regExp)) 
        return true; 
    else 
        return false;
}

function isValidImage(p_strImage) {
    //Define Matching expression
    var l_regExp = /^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*.*))+\.(jpg|gif|png|jpeg)$/i;   
    if (p_strImage.match(l_regExp)) 
        return true; 
    else 
        return false;
}