
var ELEMENT_NODE = 1;
var TEXT_NODE = 3;
var IMAGES_DIR = "/Site/Images/";
var s_openMenu = null;

setTimeout('window_onload()', 275);


function window_onload() 
{
	SetElementAttributeByTag('input', 'date', 'size', '12');
	SetElementFocus('input', 'btnUserAction', 'next');
	initMenu("residentialMenu");
	initMenu("commercialMenu");	
} 

function SetCookie(sName, sValue)
{
	date = new Date();
	date.setFullYear(2020);
	document.cookie = sName + "=" + escape(sValue) + "; expires=" + date.toGMTString() + "; path=/";
}

function GetCookie(sName)
{
	 var aCookie = document.cookie.split("; ");
	 
	 for (var i=0; i < aCookie.length; i++)
	 {
		var aCrumb = aCookie[i].split("=");
		if (sName == aCrumb[0]) 
		   return unescape(aCrumb[1]);
	 }

	 return null;
}

function CheckAllCheckBoxesByTag(elms) 
{	
	try
	{
		if(elms.checked == true)
			return true;
	}
	catch(e){}
		
	for(i = 0; i <= elms.length - 1; i++)
		if(elms[i].checked == true)
			return true;	
	
	alert('Please select a parcel.');
	return false;
}


function DelCookie(sName, sValue)
{
    document.cookie = sName + "=" + escape(sValue) + "; expires=Fri, 31 Dec 1999 23:59:59 GMT; path=/";
}

function SetElementAttributeByTag(tag, elmName, att, attValue)
{
	var elms = document.getElementsByTagName(tag); 
	
	for(i = 0; i <= elms.length - 1; i++)
	{
		if(elms[i].name.toUpperCase().indexOf(elmName.toUpperCase()) > -1)
		{
			for(j = 0; j <= elms[i].attributes.length - 1; j++)
			{
				var attr = elms[i].attributes[j];
				
				if(attr.name == att)
					attr.value = attValue;				
			}
		}	
	
	}
}

function SetElementFocus(tag, elmId, elmValue)
{
	var elms = document.getElementsByTagName(tag);
	
	for(i = 0; i <= elms.length - 1; i++)
	{
		if(elms[i].value.toUpperCase().indexOf(elmValue.toUpperCase()) > -1)
		{
			try
			{
				elms[i].focus();
			}
			catch(e){}
			return;
		}	
	
	} 
}

function initMenu(menuID)
{
	var menu = document.getElementById(menuID); 
	
	if(menu == null)
		return;
	    
	var titles = menu.getElementsByTagName("h4");     
	var arrowNode = null;
	var expanderNode = null;
	var testNode = null;
	var nodesExists = false; 	 
	    
	for(i = 0; i <= titles.length - 1; i++)
	{
		titles[i].onclick = title_onclick;
		nodesExist = false;
	  	childNodes = titles[i].childNodes;
	  	testNode = null;
	  		
	  	if(titles[i].id == "ToggleAll")
	  	{
	  		titles[i].onclick = title_onclick_viewAll;	    

	  		for(j = 0; j < childNodes.length; j++)
	  		{
	  			testNode = childNodes[j];
	  			
	  			with(testNode)
	  				nodesExist = tagName == "IMG" && (src.indexOf("minus2.gif") > 0 || src.indexOf("plus2.gif") > 0);
	  			
	  			if(nodesExist) break;       
	  		}  
		    
	  		if(!nodesExist)
	  		{
	  			with(document)
	  			{
	  				if(document.createElementNS)
	  					expanderNode = createElementNS("http://www.w3.org/1999/xhtml", "img");
	  				else
	  					 expanderNode = createElement("img");
	  			} 
	  			
	  			expanderNode.src = IMAGES_DIR + "plus2.gif";
	  			
	  			with(titles[i])
	  			{
	  				insertBefore(expanderNode, lastChild);
	  				style.padding = "3px";
	  			}
						
	  			expanderNode.className = "leftNavExpander";      
	  		}
									
	  		continue;
		}

		for(j = 0; j < childNodes.length; j++)
		{
			testNode = childNodes[j];
			
			with(testNode)
			{
				nodesExist = tagName == "IMG" && (src.indexOf("minus.gif") > 0 || src.indexOf("plus.gif") > 0 || src.indexOf("arrow") > 0);
			}
			
			if(nodesExist) break;       
		}  
				  
		if(!nodesExist)
		{
			with(document)
			{
				if(document.createElementNS)
				{
				  	arrowNode = createElementNS("http://www.w3.org/1999/xhtml", "img");
				  	expanderNode = createElementNS("http://www.w3.org/1999/xhtml", "img");
				}
				else
				{
					arrowNode = createElement("img");
					expanderNode = createElement("img");
				} 
			} 
							
			arrowNode.src = IMAGES_DIR + "arrow_right.gif";
			expanderNode.src = IMAGES_DIR + "plus.gif";
							
			with(titles[i])
			{												
				insertBefore(arrowNode, firstChild); 
				insertBefore(expanderNode, lastChild);
				style.padding = "5px";
				onclick(true);      
			}
							
			arrowNode.className = "leftNavArrow";
			expanderNode.className = "leftNavExpander";      
		}
	} 
	  
	return true;
} 

function title_onclick(pageLoading)
{  
	var title = this;                             
	var menu = title.nextSibling;    

	if(!menu)
	{
		return false;
	} //if(!menu)
	  

	while(menu.nodeType == TEXT_NODE)
	{
		menu = menu.nextSibling

		if(!menu) 
		{
		  return false;
		}
	} 	    

	if(menu.nodeType != ELEMENT_NODE)
	{
		return false;
	} 	  

	var arrowNode = title.firstChild;
	var expanderNode = title.lastChild.previousSibling;
	      
	if(menu.style.display == "block" || !menu.style.display)
	{
		if(pageLoading != true)
			DelCookie(menu.id, 'show');
			
		HideItem(menu, arrowNode, expanderNode);
		//s_openMenu = null;
	}
	else
	{
		ShowItem(menu, arrowNode, expanderNode, true);	    
		  
		//if(s_openMenu)
			//s_openMenu.onclick();
		 
		//s_openMenu = title;	  
	}   
	  
	return false;
}

function title_onclick_viewAll(e)
{	
	var expand = (this.lastChild.previousSibling.src.indexOf("plus2.gif") > 0)					
	var titles = this.parentNode.parentNode.getElementsByTagName("h4");
	var menu;  
	var arrowNode; 
	var expanderNode;         
			  
	for(i = 0; i <= titles.length - 1; i++)
	{ 	
		if(titles[i] == this)
			continue;		
							
		menu = titles[i].nextSibling;
		arrowNode = titles[i].firstChild;
		expanderNode = titles[i].lastChild.previousSibling;		
					
		if(!menu)
		  continue;		
					  
		while(menu.nodeType == TEXT_NODE)
		{
			menu = menu.nextSibling
			if(!menu) 
			  return false;
		} 
								  
		if(menu.nodeType != ELEMENT_NODE)
			return false;	  
								    
		if(expand)
		{
			DelCookie(menu.id, 'show');
			ShowItem(menu, arrowNode, expanderNode, false);
		}					
		else
		{
			DelCookie(menu.id, 'show');
			HideItem(menu, arrowNode, expanderNode);
		}			
	}
			
	if(expand)
	{
		this.childNodes[1].innerHTML = "hide all";
		this.title = "Click to collapse.";
		this.lastChild.previousSibling.src = IMAGES_DIR + "minus2.gif";
	}
	else
	{
		this.childNodes[1].innerHTML = "show all";
		this.title = "Click to expand.";
		this.lastChild.previousSibling.src = IMAGES_DIR + "plus2.gif";							  
	}
					  
	return false;
}

function HideItem(menu, arrowNode, expanderNode)
{
	var menuCookie = GetCookie(menu.id, 'show');
	
	if(menuCookie == "show")
		return;		
	
	menu.style.display = "none";
	arrowNode.src = IMAGES_DIR + "arrow_right.gif";
	expanderNode.src = IMAGES_DIR + "plus.gif";
}

function ShowItem(menu, arrowNode, expanderNode, createCookie)
{
	if(createCookie)	
		SetCookie(menu.id, 'show');
	
	with(menu.style)
	{
		display = "block";
		position = "static";
		border = "none";
	}
	
	arrowNode.src = IMAGES_DIR + "arrow_down.gif";
	expanderNode.src = IMAGES_DIR + "minus.gif";
}

/******************************************************************************
Procedure:        getTitleTextNode
Purpose:          Retrieves the first text node in an element
Assumptions:      None.
Effects:          Nothing.
Inputs:           elementObject  ->  element object in which to find text node
Returns:          text node object or null.                  
******************************************************************************/
function getElementTextNode(elementObject)
{
  if(!elementObject.hasChildNodes)
  {
    return null;
  }
  //Get the first child of the title element
  var textNode = elementObject.firstChild;
  
  //Loop through the children of the first child element, checking for a text node
  while(textNode.nodeType != TEXT_NODE)
  {
    textNode = textNode.firstChild;
  }
  
  //Return the text node
  return textNode;
}

function UpdateElementValue(elmID, val)
{
	var element = document.getElementById(elmID);	
	element.value =  val;
}

// ----------------------------------------------
// StyleSwitcher functions written by Paul Sowden
// http://www.idontsmoke.co.uk/ss/
// - - - - - - - - - - - - - - - - - - - - - - -
// For the details, visit ALA:
// http://www.alistapart.com/stories/alternate/
//
// nifty StyleSwitcher scripts modified by Aaron Jones 10/10/2002
// ----------------------------------------------

function setActiveStyleSheet(title, reset) 
{
  var i, a, main;
  
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) 
  {
	if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) 
	{
		a.disabled = true;
		if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  
  if (reset == 1) 
  {
	  SetCookie("wstyle", title);
  }
}

function setStyle() {
	var style = GetCookie("wstyle"); 
	if (style != null) {
		setActiveStyleSheet(style, 0);
	}
}
function fnCheckAll(theForm, check) 
{
  var objForm = theForm;
  var colEls = theForm.elements;
  var lngEls = colEls.length;
  var objEl = null;
  
  for (var lngCounter = 0; lngCounter < lngEls; lngCounter++)
  {
    objEl = colEls[lngCounter]
    if(objEl.type == "checkbox")
    {
      objEl.checked = check;
    }
  }
  
  return;
}


var cX = 0; 
var cY = 0; 
var rX = 0; 
var rY = 0;

function UpdateCursorPosition(e)
{
	cX = e.pageX; 
	cY = e.pageY;
}
function UpdateCursorPositionDocAll(e)
{ 
	cX = event.clientX; 
	cY = event.clientY;
}

if(document.all) 
	document.onmousemove = UpdateCursorPositionDocAll; 
else 
	document.onmousemove = UpdateCursorPosition; 
	
function AssignPosition(d) 
{
	if(self.pageYOffset) 
	{
		rX = self.pageXOffset;
		rY = self.pageYOffset;
	}
	else if(document.documentElement && document.documentElement.scrollTop) 
	{
		rX = document.documentElement.scrollLeft;
		rY = document.documentElement.scrollTop;
	}
	else if(document.body) 
	{
		rX = document.body.scrollLeft;
		rY = document.body.scrollTop;
	}

	if(document.all) 
	{
		cX += rX; 
		cY += rY;
	}
	
	d.style.left = (cX-360) + "px";
	d.style.top = (cY+20) + "px";
}

function HideContent(d) 
{
	if(d.length < 1) 
		return; 

	document.getElementById(d).style.display = "none";
}

function ShowContent(elementId, parentId, hideTag, hideId) 
{
	if(elementId.length < 1)
		return; 
	
	var elms = null;
	if(parentId)
	{
		var parent = document.getElementById(parentId);
		elms = parent.getElementsByTagName(hideTag);
	}
	else
		elms = document.getElementsByTagName(hideTag);
		
	for(i = 0; i <= elms.length - 1; i++)
	{
		var element = elms[i];
		var elmId = element.id;
		if(elmId.toUpperCase().indexOf(hideId.toUpperCase()) > -1)
			HideContent(elmId);	
	}
	
	var dd = document.getElementById(elementId);
	AssignPosition(dd);
	dd.style.display = "block";
}

function ReverseContentDisplay(d) 
{
	if(d.length < 1)
		return; 
	
	var dd = document.getElementById(d);
	AssignPosition(dd);
	
	if(dd.style.display == "none")
		dd.style.display = "block"; 
	else 
		dd.style.display = "none";
}


