//=====================================================================================================
function addLoadEvent(func) {
	var oldonload=window.onload;
	if (typeof window.onload!="function") {
		window.onload=func;
	} else {
		window.onload=function() {
			oldonload();
			func();
		}//end function
	}//end if (typeof window.onload!="function")
}//end function
//=====================================================================================================
function SetInputHighlights() {
	pxInputs=document.getElementsByTagName("input");
	for (pi=0;pi<pxInputs.length;pi++) {
		if (pxInputs[pi].type=="text") {
			pxInputs[pi].onfocus=function() {
					if (this.defaultValue==this.value) {
						this.select();
					}//end if ()
					ShowEpiLabel(this);
				}//end function
			pxInputs[pi].onkeyup=function() {
					ShowEpiLabel(this);
				}//end function
			pxInputs[pi].onblur=function() {
					HideEpiLabel(this);
				}//end function
			pxInputs[pi].onmouseup=function(){return false};//because safari is special
		}//end if (pxInputs[pi].type=="text")
	}//next pi<pxInputs.length
	for (pi=0;pi<pxInputs.length;pi++) {
		if (pxInputs[pi].type=="password") {
			pxInputs[pi].onfocus=function() {
					if (this.defaultValue==this.value) {
						this.select();
					}//end if ()
					ShowEpiLabel(this);
				}//end function
			pxInputs[pi].onkeyup=function() {
					ShowEpiLabel(this);
				}//end function
			pxInputs[pi].onblur=function() {
					HideEpiLabel(this);
				}//end function
			pxInputs[pi].onmouseup=function(){return false};//because safari is special
		}//end if (pxInputs[pi].type=="text")
	}//next pi<pxInputs.length
	pxTextAreas=document.getElementsByTagName("textarea");
	for (pi=0;pi<pxTextAreas.length;pi++) {
		pxTextAreas[pi].onfocus=function() {
				if (this.defaultValue==this.value) {
					this.select();
				}//end if ()
				ShowEpiLabel(this);
			}//end function
		pxTextAreas[pi].onkeyup=function() {
				ShowEpiLabel(this);
			}//end function
		pxTextAreas[pi].onblur=function() {
				HideEpiLabel(this);
			}//end function
		pxTextAreas[pi].onmouseup=function(){return false};//because safari is special
	}//next pi<pxTextAreas.length
}//end function
//=====================================================================================================
function ShowEpiLabel(theInput) {
	theMaxLength=theInput.getAttribute("maxlength");
	if (theMaxLength) {
		theSpan=theInput.parentNode.getElementsByTagName("span")[0];
		if (!theSpan) {
			theSpan=document.createElement("span");
			theInput.parentNode.appendChild(theSpan);
		}//end if (theSpan)
		if (theInput.value.length>theMaxLength) {theInput.value=theInput.value.substr(0, theMaxLength)};
		theSpan.innerHTML="&nbsp;"+theInput.value.length+"/"+theMaxLength+" Characters";
	}//end if (theMaxLength)
}//end function
//=====================================================================================================
function HideEpiLabel(theInput) {
	theMaxLength=theInput.getAttribute("maxlength");
	if (theMaxLength) {
		theSpan=theInput.parentNode.getElementsByTagName("span")[0];
		if (theSpan) {
			theInput.parentNode.removeChild(theSpan);
		}//end if (theSpan)
	}//end if (theMaxLength)
}//end function
//=====================================================================================================
function SetHighlights() {
	xInputs=document.getElementsByTagName("input");
	for (i=0;i<xInputs.length;i++) {
		if (xInputs[i].type=="text") {
			xInputs[i].onfocus=function() {
					if (this.defaultValue==this.value) {
						this.select();
					}//end if ()
				}//end function
			xInputs[i].onmouseup=function(){return false};//because safari is special
		}//end if (xInputs[i].type=="text")
	}//next i<xInputs.length
	xTextAreas=document.getElementsByTagName("textarea");
	for (i=0;i<xTextAreas.length;i++) {
		xTextAreas[i].onfocus=function() {
				if (this.defaultValue==this.value) {
					this.select();
				}//end if ()
			}//end function
		xTextAreas[i].onmouseup=function(){return false};//because safari is special
	}//next i<xTextAreas.length
}//end function
//=====================================================================================================
function SortCatDropdown() {
	theCatDiv=document.getElementById("subcats");
	if (theCatDiv) {
		theCatAs=theCatDiv.getElementsByTagName("a");
		theCatLabel=document.createElement("label");
		theCatLabel.innerHTML="<strong>Sub Categories:</strong>"
		theCatSelect=document.createElement("select");
		theCatOption=document.createElement("option");
		theCatOption.value=window.location;
		theCatSelect.appendChild(theCatOption);
		for(i=0;i<theCatAs.length; i++) { 
			theCatOption=document.createElement("option");
			theCatOption.innerHTML=theCatAs[i].innerHTML;
			theCatOption.value=theCatAs[i].href;
			theCatSelect.appendChild(theCatOption);
		}//next i<theCatAs.length
		theCatSelect.onchange=function() {
			window.location=theCatSelect.options[theCatSelect.selectedIndex].value;
		}//end function
		theCatLabel.appendChild(theCatSelect);
		theCatDiv.appendChild(theCatLabel);
		theCatDiv.style.display="block";
	}//end if (theCatDiv)
}//end function
//=====================================================================================================
function SortLocDropdown() {
	theLocDiv=document.getElementById("locations");
	if (theLocDiv) {
		theLocAs=theLocDiv.getElementsByTagName("a");
		theLocLabel=document.createElement("label");
		theLocLabel.innerHTML="<strong>Location:</strong>"
		theLocSelect=document.createElement("select");
		theLocOption=document.createElement("option");
		theLocOption.value=window.location;
		theLocSelect.appendChild(theLocOption);
		for(i=0;i<theLocAs.length; i++) { 
			theLocOption=document.createElement("option");
			theLocOption.innerHTML=theLocAs[i].innerHTML;
			theLocOption.value=theLocAs[i].href;
			theLocSelect.appendChild(theLocOption);
		}//next i<theLocAs.length
		theLocSelect.onchange=function() {
			window.location=theLocSelect.options[theLocSelect.selectedIndex].value;
		}//end function
		theLocLabel.appendChild(theLocSelect);
		theLocDiv.appendChild(theLocLabel);
		theLocDiv.style.display="block";
	}//end if (theLocDiv)
}//end function
//=====================================================================================================
addLoadEvent(SetInputHighlights);
addLoadEvent(SortCatDropdown);
addLoadEvent(SortLocDropdown);
//=====================================================================================================

