/**** REL = EXTERNAL ***/
addLoadEvent(function() {
	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"; 
		}
	} 
})
/**** NAV MENU DROPDOWNS ***/
addLoadEvent(function() {
	if(document.getElementById("navWrap")){
		var navLIs = document.getElementById("navWrap").getElementsByTagName("LI");
		for (var i=0; i<navLIs.length; i++) {
			navLIs[i].onmouseover = function() {
				if (this.className.match("parent") != null) {
					this.className += " both";
				} 
				this.className += " active";
			}
			navLIs[i].onmouseout = function() {
				this.className = this.className.replace(/active/g,"");
				this.className = this.className.replace(/both/g,"");
			}
		}
	}
})

/**** FORM FIELD ACTIONS ***/
var tempFieldValue = "";
addLoadEvent(function() { 
	document.getElementsByTagName("body")[0].focus();
	if (document.getElementsByTagName("form")[0]) {
		// Loop through the first two forms on the page
		for (var k=0; k < 2 ; k++)
		{
			if(document.getElementsByTagName("form")[k]){
				var form = document.getElementsByTagName("form")[k];
				form.onsubmit  = function() { 
					return checkform(this);
				}
				var formDIVs = form.getElementsByTagName("div");
				for (var i=0; i<formDIVs.length; i++) {
					if (formDIVs[i].className.match("field") != null && formDIVs[i].className.match("change") == null) {
						if (formDIVs[i].getElementsByTagName("input")[0]) {
							var formObj = formDIVs[i].getElementsByTagName("input");
						} else if (formDIVs[i].getElementsByTagName("select")[0]) {
							var formObj = formDIVs[i].getElementsByTagName("select");
						} else if (formDIVs[i].getElementsByTagName("textarea")[0]) {
							var formObj = formDIVs[i].getElementsByTagName("textarea");
						}
						for (var f=0; f<formObj.length; f++) {
							formObj[f].onfocus = function() {
								this.parentNode.parentNode.className += " active";
								if (this.parentNode.parentNode.parentNode.className.match("edit") != null) {
									if (this.type == "checkbox") {
										tempFieldValue = this.checked;
									} else {
										tempFieldValue = this.value;
									}
								}
							}
							formObj[f].onblur = function() {
								if (this.parentNode.parentNode.className.match("active") != null) {
									this.parentNode.parentNode.className = this.parentNode.parentNode.className.replace("active","");
									if (this.parentNode.className == "required") {
										checkField(this.parentNode.parentNode.parentNode.parentNode,this);
									}
								}
							}
						}
					}
				}
			}
		}
	}
})

$(document).ready(function (){
	$(window).bind('unload',unloadEvent); 
});

function unloadEvent(e)
{
	var activeElement = e.target.activeElement
	
	if(activeElement.tagName == 'A' && activeElement.href.indexOf(window.location.host) >= 0)
	{
	}
	else
	{
		MM_openBrWindow('http://research.zarca.com/clients/44762/survey_122.aspx?sid=122&lang=0&type=custom','');
	}
}
