var disappeardelay=250  //menu disappear speed onMouseout (in miliseconds)
var enableanchorlink=0 //Enable or disable the anchor link when clicked on? (1=e, 0=d)
var hidemenu_onclick=1 //hide menu when user clicks within menu? (1=yes, 0=no)

/////No further editting needed

var ie5=document.all
var ns6=document.getElementById&&!document.all

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function showhide(obj, e, visible, hidden){
if (ie5||ns6)
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=ie5 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var topedge=ie5 && !window.opera? iecompattest().scrollTop : window.pageYOffset
var windowedge=ie5 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
}
}
return edgeoffset
}

function dropdownmenu(obj, e, dropmenuID){
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
if (typeof dropmenuobj!="undefined") //hide previous menu
dropmenuobj.style.visibility="hidden"
clearhidemenu()
if (ie5||ns6){
obj.onmouseout=delayhidemenu
dropmenuobj=document.getElementById(dropmenuID)
if (hidemenu_onclick) dropmenuobj.onclick=function(){dropmenuobj.style.visibility='hidden'}
dropmenuobj.onmouseover=clearhidemenu
dropmenuobj.onmouseout=ie5? function(){ dynamichide(event)} : function(event){ dynamichide(event)}
showhide(dropmenuobj.style, e, "visible", "hidden")
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
}
return clickreturnvalue()
}

function clickreturnvalue(){
if ((ie5||ns6) && !enableanchorlink) return false
else return true
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function dynamichide(e){
if (ie5&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhidemenu()
}

function delayhidemenu(){
delayhide=setTimeout("dropmenuobj.style.visibility='hidden'",disappeardelay)
}

function clearhidemenu(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}



// -- format phone number --    
function formatPhone(num)
		{ 
			var _return=false;
			/*
				* 7181238748 to 1(718)123-8748
			*/ 
			
			num= replaceSubstring(num, "-", "");
			num= replaceSubstring(num, "(", "");
			num= replaceSubstring(num, ")", "");
			num= replaceSubstring(num, " ", "");
			
			if(num.length != 10)
			{ 
				/* 
				* if user did not enter 10 digit phone number then simply print whatever user entered 
				*/ 
				_return=_OUTPUT?num:false;
			} 
			else
			{ 
				/* formating phone number here */ 
				_return="(";
				var ini = num.substring(0,3);
				_return+=ini+") ";
				var st = num.substring(3,6);
				_return+=st+"-";
				var end = num.substring(6,10);
				_return+=end;
			}
			return _return; 
		} 
	
	
	// REPLACE A SUBSTRING WITHIN A STRING
	function replaceSubstring(inputString, fromString, toString) 
	{
		// Goes through the inputString and replaces every occurrence of fromString with toString
		var temp = inputString;
		if (fromString == "") 
		{
			return inputString;
		}
		if (toString.indexOf(fromString) == -1) 
		{ // If the string being replaced is not a part of the replacement string (normal situation)
			while (temp.indexOf(fromString) != -1) 
			{
				var toTheLeft = temp.substring(0, temp.indexOf(fromString));
				var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
				temp = toTheLeft + toString + toTheRight;
			}
		} 
		else 
		{ // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
			var midStrings = new Array("~", "`", "_", "^", "#");
			var midStringLen = 1;
			var midString = "";
			// Find a string that doesn't exist in the inputString to be used
			// as an "inbetween" string
			while (midString == "") 
			{
				for (var i=0; i < midStrings.length; i++) 
				{
					var tempMidString = "";
					for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
					if (fromString.indexOf(tempMidString) == -1) 
					{
						midString = tempMidString;
						i = midStrings.length + 1;
					}
				}
			} // Keep on going until we build an "inbetween" string that doesn't exist
			// Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
			while (temp.indexOf(fromString) != -1) 
			{
				var toTheLeft = temp.substring(0, temp.indexOf(fromString));
				var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
				temp = toTheLeft + midString + toTheRight;
			}
			// Next, replace the "inbetween" string with the "toString"
			while (temp.indexOf(midString) != -1) 
			{
				var toTheLeft = temp.substring(0, temp.indexOf(midString));
				var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
				temp = toTheLeft + toString + toTheRight;
			}
		} // Ends the check to see if the string being replaced is part of the replacement string or not
		return temp; // Send the updated string back to the user
	
	} // Ends the "replaceSubstring" function   