// Beginning dropdown menu code
window.onerror = null;
 var bName = navigator.appName;
 var bVer = parseInt(navigator.appVersion);
 var NS6 = (bName == "Netscape" && bVer >= 5);
 var NS4 = (bName == "Netscape" && bVer >= 4 && bVer < 5);
 var IE4 = (bName == "Microsoft Internet Explorer" && bVer >= 4);
 var NS3 = (bName == "Netscape" && bVer < 4);
 var IE3 = (bName == "Microsoft Internet Explorer" && bVer < 4);
 var menuActive = 0, menuOn = 0, onLayer, onLayer, onLayer2, onLayer3, timeOn = null;
 
// Layer switching code
if (NS4 || IE4 || NS6) {
 if (NS4) {
 layerStyleRef="layer.";
 layerRef="document.layers";
 styleSwitch="";
  }else if(NS6){
 styleSwitch=".style";
 }else{
 layerStyleRef="layer.style.";
 layerRef="document.all";
 styleSwitch=".style";
 }
 
}


// SHOW DIV
function showDiv(layerName){
	if (NS4 || IE4 || NS6) {
		if (NS4 || IE4) {
			eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="visible"');
			eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.position="relative"');
			eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.display="block"');
		} 
		if (NS6) {
		 eval('document.getElementById("'+layerName+'")'+styleSwitch+'.visibility="visible"');
		 eval('document.getElementById("'+layerName+'")'+styleSwitch+'.position="relative"');
		 eval('document.getElementById("'+layerName+'")'+styleSwitch+'.display="block"');
		} 
	}
}// HIDE DIV
function hideDiv(layerName){
	if (NS4 || IE4) {
		eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="hidden"');
		//eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.position="absolute"');
		eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.display="none"');
	}
	if (NS6) {
		eval('document.getElementById("'+layerName+'")'+styleSwitch+'.visibility="hidden"');
		eval('document.getElementById("'+layerName+'")'+styleSwitch+'.position="absolute"');
		eval('document.getElementById("'+layerName+'")'+styleSwitch+'.display="none"');
	}
}

function displaycopresenter(copres) {
	if (copres) {
		showDiv("copresspan1");
	} else {
		hideDiv("copresspan1");
	}
}

/**
 * DHTML textbox character counter 
 */

function taLimit() {
	var taObj=event.srcElement;
	if (taObj.value.length==taObj.maxLength*1) return false;
}

function taCount(visCnt) { 
	var taObj=event.srcElement;
	if (taObj.value.length>taObj.maxLength*1) taObj.value=taObj.value.substring(0,taObj.maxLength*1);
	if (visCnt) visCnt.innerText=taObj.maxLength-taObj.value.length;
}

function countdown(f,x,counter,total){
//alert(x.value.length);
	if (x.value.length > total*1) {
		document.getElementById(counter).innerHTML = 0;
		x.value = x.value.substring(0, total);
		return false;
	}
	else { 
		document.getElementById(counter).innerHTML = total - x.value.length;
		// f.counter.value = total - x.value.length;
		return true;
	}
}

// CountWords(this.form.x, true, true)
function CountWords (this_field, display_field, max_words,show_word_count, show_char_count) {
	if (show_word_count == null) {show_word_count = true;}
	if (show_char_count == null) {show_char_count = false;}
	var char_count = this_field.value.length;
	var fullStr = this_field.value + " ";
	var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
	var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
	var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
	var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
	var splitString = cleanedStr.split(" ");
	var word_count = splitString.length -1;
	
	if (fullStr.length <2) {word_count = 0;}
	if (word_count == 1) {wordOrWords = " word";}
	else {wordOrWords = " words";}
	if (char_count == 1) {charOrChars = " character";} 
	else {charOrChars = " characters";}
	if (show_word_count & show_char_count) {alert ("Word Count:\n" + "    " + word_count + wordOrWords + "\n" + "    " + char_count + charOrChars);}
	else {
		if (show_word_count) {alert ("Word Count:  " + word_count + wordOrWords);}
		else {if (show_char_count) {alert ("Character Count:  " + char_count + charOrChars);}
	   }
	}
	
	document.getElementById(display_field).innerHTML = 1*max_words-word_count + " words remaining";
	return word_count;
}
