// *********************************************************
//                ROLLOVERS
// *********************************************************
var secs;
var timerID = null;
var timerRunning = false;
var delay = 1000;
var url = "";


function hideElement(elmID)
{
	for (i = 0; i < document.all.tags(elmID).length; i++)
	{
		obj = document.all.tags(elmID)[i];
		if (! obj || ! obj.offsetParent)
			continue;

		obj.style.visibility = "hidden";
	}
}

function showElement(elmID)
{
	for (i = 0; i < document.all.tags(elmID).length; i++)
	{
		obj = document.all.tags(elmID)[i];
		if (! obj || ! obj.offsetParent)
			continue;
		obj.style.visibility = "";
	}
}

// Rollover for results links
function bgRolloverResults(ID, evnt) {
	var i = 0;

	var obj = document.getElementById(ID + "_" + i);
	while (obj!=null)
	{
		if (evnt.type == "mouseover") {
			obj.className = "resultsOver";
		}
		if (evnt.type == "mouseout") {
			obj.className = "results";
		}
		i = i +1;
		obj = document.getElementById(ID + "_" + i);
	}
	
}

// *********************************************************
//	Prevents Form Submission When RouteSmithObjs.classes.business.User Presses the ENTER Key on a Form
//  so the first button won't be default one
// *********************************************************
function CatchKeyPress(KeyCode, Sender) 
{ 
	//alert("KeyCode=" + KeyCode + " : Sender=" +  Sender);
	if(KeyCode == '13') 
	{ 
		RemoveEnterAndEscEvents(); 
		//check it is a button  
		//if(Sender.onclick != null) 
		if (Sender.type == "submit" || Sender.onclick != null)
		{	var sButtonName = Sender.name;
			if (sButtonName == "" )
			{	sButtonName = Sender.id; }
			if (sButtonName == "" )
			{
				return false;
			}
			var btnToBeClicked = document.getElementById(sButtonName);
			if (btnToBeClicked != null)
			{
				btnToBeClicked.click(); 
			}		 
		} 
	} 
}

function RemoveEnterAndEscEvents() { 
	if (event.keyCode == 13 || event.keyCode == 27) { 
		event.cancelBubble = true; event.returnValue = false; 
	} 
} 

// *********************************************************
//	converts 1 to "Yes"; everything esle to "No"
// *********************************************************
function formatYesNo(strValue)
{	var strResult;
	if (strValue == "1") 
	{ 
		strResult = "Yes"
	}
	else
	{
		strResult = "No"
	}	
	return strResult;	
}
// *********************************************************
//	format number
// *********************************************************
function formatNumber(strValue)
{	var strResult;
	if (isNaN(strValue))
	{ 
		strResult = "";
	}
	else
	{
		strResult = strValue;
	}	
	return strResult;	
}
// *********************************************************
//	converts Phone # from 1112223333 to (111) 222-3333
// *********************************************************
function formatPhone(objPhone)
{	var strResult;

   if (objPhone == null)
   {
        return;
   }
    var strValue = objPhone.value;

	if (strValue.length == 10) 
	{ 
		strResult = '(' + strValue.substring(0, 3) + ') ';
		strResult += strValue.substring(3, 6) + '-';
		strResult += strValue.substring(6, 10);
		 
		objPhone.value = strResult;
	}
	 
}
 
// *********************************************************
//                  FORM TABING
// *********************************************************
// Auto Tab for combined inputs
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
var keyCode = (isNN) ? e.which : e.keyCode; 
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if(input.value.length >= len && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0, len);
input.form[(getIndex(input)+1) % input.form.length].focus();
}
function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length)
if(arr[index] == ele)
found = true;
else
index++;
return found;
}
function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input)index = i;
else i++;
return index;
}
return true;
}
//********************************************************
//Name: replace
//Desc: search/replace 
//Note:
//********************************************************
function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

//********************************************************
//Name: setFocus
//Desc: checks if control exists and sets focus to it
//Note:
//********************************************************
function setFocus(objControl) 
{
	if (typeof(objControl) != "undefined")
	{
		objControl.focus();
		/*
		var ev = objControl.onblur;
		//for validation onblur - ???
		if (typeof(ev) == "function" ) 
		{            
			objControl.onblur = "";
			objControl.onchange = ev;
		}
		*/
	}

}

//********************************************************
//Name: nowDate
//Desc: return today's date
//Note:
//********************************************************
function nowDate() 
{
	var dt = new Date();
	var dtToday = null;
	
	dtToday = dt.getMonth() + 1; 
	dtToday = dtToday + '/' + dt.getDate() + '/' + dt.getYear();
	
	return dtToday;
}

//********************************************************
//Name: nowTime
//Desc: return the current time
//Note:
//********************************************************
function nowTime() 
{
	var dt = new Date();
	var dtToday = null;
	var hour = null;
	var ampm = null;
	
	if (dt.getHours() <= 12)
	{
		hour = dt.getHours();
		ampm = "AM";
	}
	else
	{
		hour = dt.getHours() % 12;
		ampm = "PM";
	}	
	
	dtToday = hour + ':' + dt.getMinutes() + ' ' + ampm;		
	return dtToday;
}


//********************************************************
//Name: textCounter
//Desc: used to restrict size on textarea's
//Note:
//********************************************************
function textCounter( field, maxlimit) 
{
	if ( !field.readOnly) //to prevent msgs in readonly mode on keyup
	{
		if ( field.value.length > maxlimit ) 
		{
			field.value = field.value.substring( 0, maxlimit );
			//alert("Your note has exceeded the maximum length of " + maxlimit + " characters. Please save this text in a Word Document and upload it using the Documents page.");

			field.focus();
			return false;
		} 
	}
}



//********************************************************
//Name: clearFormSection
//Desc: used on Clear buttons - clears only a section - if "" passed clears entired form
//Note: 
//********************************************************
function clearFormSection(strParentName)
{	
	var objParent;
	if (strParentName =="")
	{
		objParent = document.body; //default
	}
	else
	{
		objParent = document.getElementById(strParentName);
	}
	
	if (objParent != null)
	{	//input
		var objNodeList = objParent.getElementsByTagName("input");		
		for (var i=0;i<objNodeList.length;i++)
		{	
			if (objNodeList[i].type == "text" )//&& objNodeList[i].style.display != "none"
			{
				objNodeList[i].value="";
			}	
		}
		//select
		objNodeList = objParent.getElementsByTagName("select");		
		for (var i=0;i<objNodeList.length;i++)
		{		
			if (objNodeList[i].size==0) 
			{
				objNodeList[i].selectedIndex= 0;
			}
			else
			{	
				objNodeList[i].selectedIndex= -1;			
			}
			
		}
		
		//re-run validation
		Page_ClientValidate();
	}
	
}
 //********************************************************
//Name: getVisibilityStyle
//Desc: 
//Note: 
//********************************************************
   function getVisibilityStyle( blVisible)
   {	var sVisibility ;
		if (blVisible)
		{
			sVisibility = "visible";
		}
		else
		{
			sVisibility = "hidden";
		}	
		return sVisibility;
   }
   
//********************************************************
//Name: getDisplayStyle
//Desc: 
//Note: 
//********************************************************
   function getDisplayStyle( blVisible)
   {	var sDisplay ;
		if (blVisible)
		{
			sDisplay = "block";
		}
		else
		{
			sDisplay = "none";
		}	
		return sDisplay;
   }
 //********************************************************
//Name: getDisplayStyle
//Desc: 
//Note: strName - object name
//********************************************************
   function setDisplayStyle(strName,  blVisible)
   {	
		var obj = document.getElementById(strName);
		if ( obj != null)
		{
			var sStyle = getDisplayStyle(blVisible);
			obj.style.display=sStyle;			
		}	
   }
   
 //********************************************************
//Name: checkMultiSubmit()
//Desc: 
//Note: disable update button on submit
//		needs to be use on form onsubmit : onsubmit="javascript:checkMultiSubmit()"
//********************************************************
	var blSubmit = 0;
   	function checkMultiSubmit()
	{	
		//case page has no validation
		var isV;
		try
		{
			isV = (Page_IsValid == true);			
		}
		catch(e)
		{	
			isV = true;//page has no validaiton
		}
		if (isV)
		{	
			var doSubmit = (blSubmit != 1);
			blSubmit= 1;
			window.event.returnValue = doSubmit;
			
		}		
	}

 //********************************************************
//Name: arrayToString()
//Desc: 
//Note: converts array to a strToken delim string
//********************************************************
function arrayToString(arr, strToken)
{
	var strValue = "";
	
	if (arr != null)
	{
		for (i=0;i<arr.length; i++)
		{
		 
			strValue += arr[i];
			if (i< arr.length -1)
			{
				strValue = strValue + strToken;
			}
		 
		}
	}

	return strValue;	
}



function fnTrapKD(btn, event){

 if (document.all){

  if (event.keyCode == 13){

   event.returnValue=false;

   event.cancel = true;

   btn.click();
  }

 }

 else if (document.getElementById){

  if (event.which == 13){

   event.returnValue=false;

   event.cancel = true;

   btn.click();

  }

 }
 else if(document.layers){

  if(event.which == 13){

   event.returnValue=false;

   event.cancel = true;

   btn.click();

  }

 }

}


 //********************************************************
//Name: toggleCalendar 
//Desc: 
//Note: converts array to a strToken delim string
//********************************************************
function toggleCalendar(strVal, strDiv)
{


  //  alert("strVal:" + strVal + " strDiv:" + strDiv);

	if (strDiv == "")
	{
		return;
	}
	
//	 alert("strVal:" + strVal + " strDiv:" + strDiv + " not null");
 
	var obj = getObj(strDiv);
	if (obj == null)
	{
	 
		return;
	}
	
	strDateDiv = strDiv;
	if (strVal=='on')
	{
		obj.style.visible="visible";
		obj.style.display="block";
	}
	else
	{
		obj.style.visible="hidden";
		obj.style.display="none";
	}
 
}
		

 //********************************************************
//Name: toggleDiv
//Desc: 
//Note: toggles visibility
//********************************************************
function toggleDiv(strDiv, strTxtBox)
{
	var obj = document.getElementById(strDiv);
	
	 
	var objTxt = document.getElementById(strTxtBox);
	
	if (obj.style.visible=="hidden")
	{
		obj.style.visible="visible";
		obj.style.display="block";
		if (objTxt != null)
		{
			objTxt.value = "1";
			 
		}
	}
	else
	{
		obj.style.visible="hidden";
		obj.style.display="none";
		if (objTxt != null)
		{
			objTxt.value = "0";
			 
		}
	}
}

 //********************************************************
//Name: reloadPage 
//Desc: 
//Note: used by calendar tool
//********************************************************
function reloadPage(strVal, strDiv, strStoreDateID, strIsPostBackID, strIsPostBack)
{

   // alert("to reloadPage strVal:" + strVal + " strDiv:" + strDiv + " strStoreDateID:" + strStoreDateID);
	toggleCalendar('off', strDiv);
	var obj;
	
	//no longer finds anything in asp.net 2.0. Am using session now.
	obj = this.document.getElementById(strStoreDateID);
	if (obj != null)
	{
		 obj.value = strVal;
		 
	}

	 
	if (strIsPostBackID != null && strIsPostBackID != "")
	{
		objPostback = this.document.getElementById(strIsPostBackID);						
		if (objPostback != null)
		{
			objPostback.value = "1";
		}
	}
	
 
	if (strIsPostBack != null && strIsPostBack == "1")
	{
		 
		// alert("strIsPostBack:" + strIsPostBack);
		this.document.body.style.cursor='wait';
		//this.document.Form1.submit(); //("home.aspx?Date='" + strVal + "'");
		this.document.forms[0].submit(); //aspnetForm.submit();
		
	}
}

		
 //********************************************************
//Name: getObj 
//Desc: 
//Note:  
//********************************************************
function getObj(name)
{

 

 var obj;
 if (document.getElementById)
 {
	   obj = document.getElementById(name);
 }
 else if (document.all)
 {
	   obj = document.all[name];
 }
 else if (document.layers)
 {
	   if (document.layers[name])
	   {
	   		obj = document.layers[name];
	   }
	   else
	   {
			obj = document.layers.testP.layers[name];
	   }
 }
return obj;
}

//********************************************************
//Name: swapImg
//Desc: 
//Note:  
//********************************************************
function swapImg(obj, strImgPath)
{
	obj.src = strImgPath;
}


function InitializeTimer(timerSeconds, _url)
{
    //alert("init timer:" + timerSeconds);
    secs = timerSeconds
    StopTheClock()
    StartTheTimer()
    url = _url;
}

function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function StartTheTimer()
{
    if (secs==0)
    {
		window.navigate(url);	
        //StopTheClock()  
    }
    else
    {
        //self.status = secs
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
    }
}

 
 
/* 
function standardizeEvent(event) 
{ 
	if (!event.stopPropagation) 
	{ 
		alert("1");
		event.stopPropagation = new Function('this.cancelBubble = true');
		
		alert("1.0");
	} 
	
	alert("ok2");
	if (!event.preventDefault) 
	{ 
		alert("2");
		event.preventDefault = new Function('this.returnValue = true');
	} 
	
	alert("ok");
	if (typeof event.layerX == 'undefined' && typeof event.offsetX == 'number') 
	{ 
		alert("3");
		event.layerX = event.offsetX;
		event.layerY = event.offsetY; 
	} 
	if (!event.target && event.srcElement) 
	{ 
	alert("4");
		event.target = event.srcElement; 
		if (event.type == 'onmouseout') 
		{ 
		alert("5");
			event.relatedTarget = event.toElement 
		} 
		else if (event.type == 'onmouseover') 
		{ 
		alert("6");
			event.relatedTarget = event.fromElement; 
		} 
	} 
}
*/
 
 
<!--
// Rollover - This swaps the normal state image with the over state image
// You must put the name value into the image tage
function change(name,file) {
	if (document.images)
		eval('document.images["'+name+'"].src="'+file+'"')
}

function clearText(elmId)
{
  
	if (elmId == null)
	{
	    return;
	}
	
	if (elmId.value == "Enter Description" || elmId.value == "Enter Address" ||  elmId.value == "Start")
	{
	    elmId.value = "";
	}
	 
    	
}


//********************************************************
//Name: Redirect
//Desc: 
//Note:  
//********************************************************
function Redirect(url)
{
    //alert("redirect:" + url);
    window.navigate(url);
}
 
 

//********************************************************
//Name: rightTrim
//Desc: 
//Note:  
//******************************************************** 
function rightTrim(sString) 
{
while (sString.substring(sString.length-1, sString.length) == ' ')
{
sString = sString.substring(0,sString.length-1);
}
return sString;
}


//********************************************************
//Name: leftTrim
//Desc: 
//Note:  
//********************************************************
function leftTrim(sString) 
{
while (sString.substring(0,1) == ' ')
{
sString = sString.substring(1, sString.length);
}
return sString;
}

//********************************************************
//Name: trimAll
//Desc: 
//Note:  
//********************************************************
function trimAll(sString) 
{
while (sString.substring(0,1) == ' ')
{
sString = sString.substring(1, sString.length);
}
while (sString.substring(sString.length-1, sString.length) == ' ')
{
sString = sString.substring(0,sString.length-1);
}
return sString;
}


//********************************************************
//Name: openwindow
//Desc: 
//Note:
//********************************************************
function openWindow(filename, caption, w, h)
{  
	popup = window.open(filename,caption,"width=" + w + ",height=" + h + ",scrollbars=1")
}


