/*function autoFieldChange(input, length, e)
{
	if (length == 0 || length == null)
	{
		return false;
	}	
	else if (input.value.length >= length)
	{
		for (var x=0; x < document.forms[0].length; x++ )
		{
			if(document.forms[0][x].name == input.name)
			{
				document.forms[0][x+1].focus()
			}
		}
	}

	 return false;
}
*/

var ypmapcreatemap = "";

var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function autoFieldChange(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;
}


//--------------------------------------------------------------------------------------

/*

-------  Number Validation -----------

    Version:        1.0		March 10th 2006 8:30 am
	Author:			Todd Hunt
	Description:    called to Validate if submited obj is a numeric character.

*/


function IsNumerical(charObj)

{
	var ValidChars = "0123456789";
	var IsNumber=true;
		
	for (i = 0; i < charObj.length && IsNumber == true; i++) 
	{ 
		var Char = charObj.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{
			IsNumber = false;
		}
	}
		
	return IsNumber;
	
 }

//--------------------------------------------------------------------------------------

/*

-------  Phone Number Validation -----------

    Version:        1.0		March 10th 2006 8:15 am
	Author:			Todd Hunt
	Description:    called to Validate Phone NUmber Search only contains Numbers.

*/


function phoneNumberValaidation(formObj, lang)
{	
	var message = new Array()
	var numberTest = true;
	
	message["en"] = "Please enter Only Numerical Characters for the Phone Number Search.";
	message["fr"] = "Veuillaz entrer uniquement des caract\u00E8tres num\u00E9riques pour effectuer une recherche par n\u00BA de t\u00E9l\u00E9phone.";
	
	var x=0;
	var formItem;
	
	for (x; x < formObj.length && numberTest == true; x++ )
	{
		switch(formObj[x].name) 
		{
			case "pac":
				for(var y=0; y < formObj['pac'].value.length && numberTest == true; y++)
				{
					var numberTest = IsNumerical(formObj['pac'].value);
				}
				break;
			case "pex":
				for(var y=0; y < formObj[x].value.length && numberTest == true; y++)
				{
					var numberTest = IsNumerical(formObj['pex'].value);
				}
				break;
			case "pnum":
				for(var y=0; y < formObj[x].value.length && numberTest == true; y++)
				{
					var numberTest = IsNumerical(formObj['pnum'].value);
				}
				break;
			default:
				break;
		}
		
	}
	
	
	if(numberTest == true)
	{
		return true;	
	}
	else
	{
		alert(message[lang])
		return false;
	}
	
}

//--------------------------------------------------------------------------------------

function focusForm(pageName)
{
	if(pageName == "reverse")
	{
		document.forms['BusinessSearch']['pac'].focus();
	}
	else if(pageName == "map")
	{
		document.forms['GetMap']['st'].focus();
	}
	else if(pageName == "directions")
	{
		document.forms['DrivingDirections']['fromSt'].focus();
	}
	else if(pageName != "category" && pageName != "location")
	{
		document.forms['BusinessSearch']['what'].focus();
	}
	else
	{
		return;
	}
}

/*function focusForm(formObject)
{
	if(arguments.length > 1)
	{
		document.forms[arguments[1]][formObject].focus();
	}
	else
	{
		document.forms['BusinessSearch'][formObject].focus();
	}
}
*/

//--------------------------------------------------------------------------------------

function loadCitySite(site)
{
	if(site.citySite.value != '')
	{
		window.open(site.citySite.value);
		return false;
	}
	else
	{
		return false;
	}
}

//--------------------------------------------------------------------------------------

/*

-------  Popup Window -----------

    Version:        1.3		June 24th 2003 9:23 am
	Author:			Todd Hunt
	Description:    called to open Popup when products requiring further instruction or options for the customers to select.

*/

var win;
var winStatus;
var winname = 'infoWin';

function openWin(file,w,h,rs) 
/*	Opens 'file' in a new window with 'w' width (optional)
	and 'h' height (optional); 
*/
{
	if (!w) { w = 450; }
	if (!h) { h = 300; }
	if (!rs) { rs = "yes"; }
	winStatus = true;
	win = window.open(file,winname,'toolbar=no,location=no,directories=no,status=no,'+
								   'menubar=no,resizable='+rs+',copyhistory=no,scrollbars'+
								   '=yes,width='+w+',height='+h);
	win.creator = self;
	
	win.focus();
}

function closeWin()
{
	top.opener.winStatus = false;
	top.close();
}

function closeChildWin()
{
	winStatus = false;
	win.close();
}

// -- END -- //

//--------------------------------------------------------------------------------------

function areaCodeSubmit(areaCode)
{
	window.opener.document.forms['BusinessSearch']['pac'].value = areaCode;
	window.close();
	window.opener.document.forms['BusinessSearch']['pex'].focus();
}

//--------------------------------------------------------------------------------------

function preFetch(imgObj,imgSrc)
{
	if (document.images) 
	{
		eval(imgObj + ' = new Image()');
		eval(imgObj + '.src = "' + imgSrc + '"');
	}
}

//--------------------------------------------------------------------------------------

  var timerID = null;

  function getObj(objid) 
  {
    if (document.getElementById)
      return document.getElementById(objid)
    if (document.all)
      return document.all[objid]
    if (document.layers)
      return document.layers[objid]
    return null
  }

  function ScrollUp(elementName, speed, step) 
  {
    var el = getObj(elementName);
	var elPos = parseInt(el.style.top);
	
    if (el != null) 
	{
      if (isNaN(elPos)) 
	  {
        el.style.top = "0px";
      }
      if (elPos < 0) 
	  {
        if ((elPos + step) > 0) 
		{
          el.style.top = "0px";
        }
        else 
		{
          var changePlacement = elPos + step;
		  el.style.top = changePlacement+"px";
        }
      }
      ScrollStop();
      timerID = setTimeout("ScrollUp('" + elementName + "', " + speed + ", " + step + ")", speed);
    }
  }

  function ScrollDown(elementName, speed, step) 
  {
    var el = getObj(elementName);
	var elPos = parseInt(el.style.top);
	var elParentHeight = el.parentNode.offsetHeight;
	var elHeight = el.offsetHeight;
	
    if (el != null) 	
	{
      if (isNaN(elPos)) 
	  {
        el.style.top = "0px";
      }
      if (elPos > elParentHeight - elHeight) 
	  {
        if ((elPos - step) < elParentHeight - elHeight) 
		{
          var changePlacement = elParentHeight - elHeight;
		  el.style.top = changePlacement+"px";
        }
        else 
		{
          var changePlacement = elPos - step;
		  el.style.top = changePlacement+"px";
        }
      }
      ScrollStop();
      timerID = setTimeout("ScrollDown('" + elementName + "', " + speed + ", " + step + ")", speed);
    }
  }

  function ScrollStop() {
    if (timerID != null) {
      clearTimeout(timerID);
      timerID = null;
    }
  }


//--------------------------------------------------------------------------------------  


function clearValue(formObject, value)
{
	if(formObject.value == value)
	{
		formObject.value = "";
		return;
	}
	else
	{
		return;
	}
	
}

//--------------------------------------------------------------------------------------  

/*

-------  Snap Location Check -----------

    Version:        1.0 May 26, 2006 10:05 am 
	Author:			Todd Hunt
	Description:    Called to replace Location Drop Down field with a text field when the option of Other is selected.

*/

function snapLocationCheck(optionMenu)
{
	var optionValue = optionMenu.options[optionMenu.selectedIndex].value;
	
	if(optionValue == "other")
	{
		document.getElementById('cityList').innerHTML = "<input type='text' id='ac2' name='where' value='' style='width: 98%;' tabindex='2' maxlength='250' />";
		
		document.forms['BusinessSearch']['where'].focus()
	}
}

//--------------------------------------------------------------------------------------  

/*

-------  Text Size Changer -----------

    Version:        1.0 January 4, 2007 1:35 pm 
	Author:			Todd Hunt
	Description:    Used to modify the Font Size displaid in selected areas of the site.

*/

var sizeCount = 0;
var sizePref = 0;

var textSize= new Array(1, 1.1, 1.3, 1.5)
var footerTextSize= new Array(0.9, 1, 1.1, 1.3 );

	function textSizePref(lang)
	{
		var textSizePref = GetCookies('textSize_pref');
		if(textSizePref > 0)
		{
			enlargeText(textSizePref, lang)
		}
	}

	function reduceText(lang)
	{
		if(sizeCount != 0)
		{
			sizeCount = parseInt(sizeCount);
		}
		
		sizeCount = sizeCount-1;
		if(sizeCount <= 0)
		{
			sizeCount = 0;
		}
		
		document.getElementById("contentArea").style.fontSize = textSize[sizeCount]+"em";
		if(document.getElementById("footerBorder"))
		{
			document.getElementById("footerBorder").style.fontSize = footerTextSize[sizeCount]+"em";
		} 
		else if(document.getElementById("footer"))
		{
			document.getElementById("footer").style.fontSize = footerTextSize[sizeCount]+"em";
		}
		
		if(lang == "en")
		{ var siteUrl = '.yellowpages.ca'; }
		else
		{ var siteUrl = '.pagesjaunes.ca'; }
	
		var exp     = new Date(); 
		var expDays = 365;
		exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
		SetCookie('textSize_pref', sizeCount, exp, '/', siteUrl);
		window.status = sizeCount;
	}
	
	function enlargeText(tSize, lang)
	{
		if(sizeCount != 0)
		{
			sizeCount = parseInt(sizeCount);
		}
		
		var textOptLength = textSize.length-1;
		
		if(tSize != null) {
			sizeCount = tSize;
		} else {
			sizeCount = sizeCount+1;
		}
		
		if(sizeCount >= textOptLength)
		{
			sizeCount = textOptLength;
		}	
		
		document.getElementById("contentArea").style.fontSize = textSize[sizeCount]+"em";
		
		if(document.getElementById("footerBorder"))
		{
			document.getElementById("footerBorder").style.fontSize = footerTextSize[sizeCount]+"em";
		} 
		else if(document.getElementById("footer"))
		{
			document.getElementById("footer").style.fontSize = footerTextSize[sizeCount]+"em";
		}
		
		if(lang == "en")
		{ var siteUrl = '.yellowpages.ca'; }
		else
		{ var siteUrl = '.pagesjaunes.ca'; }
		
		var exp     = new Date(); 
		var expDays = 365;
		exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
		SetCookie('textSize_pref', sizeCount, exp, '/', siteUrl);
		window.status = sizeCount;                                                      
	}
	
	function setTextsize(size, lang) {
		document.body.style.fontSize = size;
		var exp = new Date(); 
		exp.setTime(exp.getTime() + (365*24*60*60*1000));
		SetCookie('ypTextsize', size, exp);
	}

	function applyTextsize(lang) {
		var size = GetCookies('ypTextsize');
		if (size) {
			document.body.style.fontSize = size;
		}
	}
	
//--------------------------------------------------------------------------------------

/*

-------  Cookie Manager -----------

    Version:        1.0
	Author:			Delano Mandelbaum
	Description:    Used to Save, Delete and Get Cookies via Javascript.

*/

function GetCookies (name) 
{  
    var arg = name + "=";  
    var alen = arg.length;  
    var clen = document.cookie.length;  
    var i = 0;  
    while (i < clen) 
    {
        var j = i + alen;    
        if (document.cookie.substring(i, j) == arg)      
        {
            return getCookieVal (j);    
        }
        i = document.cookie.indexOf(" ", i) + 1;    
        if (i == 0) break;   
    }  
    return null;
}

//--------------------------------------------------------------------------------------

function SetCookie (name, value) 
{  
    var argv = SetCookie.arguments;  
    var argc = SetCookie.arguments.length;  
    var expires = (argc > 2) ? argv[2] : null;  
    var path = (argc > 3) ? argv[3] : null;  
    var domain = (argc > 4) ? argv[4] : null;  
    var secure = (argc > 5) ? argv[5] : false;  
    document.cookie = name + "=" + escape (value) + 
        ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
        ((path == null) ? "" : ("; path=" + path)) +  
        ((domain == null) ? "" : ("; domain=" + domain)) +    
        ((secure == true) ? "; secure" : "");
}

//--------------------------------------------------------------------------------------

function DeleteCookie (name) 
{  
    var exp = new Date();  
    exp.setTime (exp.getTime() - 1);  
    var cval = GetCookies(name);  
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

//--------------------------------------------------------------------------------------

function getCookieVal(offset) 
{
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
    {
        endstr = document.cookie.length;
    }
    
    return unescape(document.cookie.substring(offset, endstr));
}

//--------------------------------------------------------------------------------------

function showStatus(displayText) 
{
    window.status = displayText;
    return true ;
}

//--------------------------------------------------------------------------------------

/*

-------  Form Switch -----------

    Version:        1.0
	Author:			Todd Hunt
	Description:    Used Switch from Visible Content, mainly the Business to People Finder Form on the homepage.

*/

function switchForms(selectedObj)
{
	if (selectedObj == "people")
	{
		document.getElementById("businessForm").style.display = "none";
		document.getElementById("peopleForm").style.display = "inline";
	}
	else if (selectedObj == "business")
	{
		document.getElementById("peopleForm").style.display = "none";
		document.getElementById("businessForm").style.display = "inline";
	}
}

function switchTab(tabToShow) 
{
	if (!tabReady) return;
	
	// Special handling for Map/Dir tab
	if (tabToShow == "prodMap")
	{
		if(tabToHide != "prodMap")
		{
			// Hide the previous tab section			
			if (/^(?:prodBrochure|prodCoupon|prodCatalogue|prodFlyer|prodP2WMenu|prodDocument)$/.test(tabToHide))
			{
				document.getElementById("prodPrint2web").style.display = 'none';
			}
			else
			{
				document.getElementById(tabToHide).style.display = 'none';
			}
		}
		
		document.getElementById("productTabArea").style.display = "none";
		document.getElementById("merchantMapArea3").style.display = "block";

		// Change the last tab ear to inactive
		document.getElementById(tabToHide + "TabActive").style.display = "none";
		document.getElementById(tabToHide + "TabInActive").style.display = "inline";
		
		// Change the Map tab ear to active
		document.getElementById(tabToShow + "TabInActive").style.display = "none";		
		document.getElementById(tabToShow + "TabActive").style.display = "inline";
		tabToHide = tabToShow;
		return;
	}
	else if (tabToShow != "prodMap")
	{
		document.getElementById("merchantMapArea3").style.display = "none";
		document.getElementById("productTabArea").style.display = "block";
	}


	if(tabToHide != "")
	{
		if(tabToHide != "prodMap")
		{
			if (/^(?:prodBrochure|prodCoupon|prodCatalogue|prodFlyer|prodP2WMenu|prodDocument)$/.test(tabToHide))
			{
				document.getElementById("prodPrint2web").style.display = 'none';
			}
			else
			{
				document.getElementById(tabToHide).style.display = 'none';
			}
		}
		
		// Change the tab ear to inactive
		document.getElementById(tabToHide + "TabActive").style.display = "none";
		document.getElementById(tabToHide + "TabInActive").style.display = "inline";	
	}

	//if variable tabToShow is one of prodBrochure, prodCoupon, prodCatalogue, prodFlyer, prodP2WMenu, prodDocument force prodToShow var to use value prodPrint2Web

	if (/^(?:prodBrochure|prodCoupon|prodCatalogue|prodFlyer|prodP2WMenu|prodDocument)$/.test(tabToShow))
	{
		var prodToShow = document.getElementById("prodPrint2web");
	}
	else
	{
		var prodToShow = document.getElementById(tabToShow);
	}

	if (prodToShow)
	{
		prodToShow.style.display = 'block';
		
		// Change the tab ear to active
		document.getElementById(tabToShow + "TabInActive").style.display = "none";		
		document.getElementById(tabToShow + "TabActive").style.display = "inline";
	}

	tabToHide = tabToShow;
}
//--------------------------------------------------------------------------------------

/*

-------  Map Click -----------

    Version:        1.0
	Author:			Todd Hunt
	Description:    Used to select or deselect the map checkbox.

*/

var mapCheck = false;

function mapClick()
{
	var mapCheck = document.forms['BusinessSearch']['map'].checked;
	
	if(mapCheck == false)
	{
		document.forms['BusinessSearch']['map'].checked = true;
	} else {
		document.forms['BusinessSearch']['map'].checked = false;	
	}
}


//--------------------------------------------------------------------------------------

/*

-------  Map Status Cookie -----------

    Version:        1.0
	Author:			Todd Hunt
	Description:    Used to save current Map Status when user is opening a print friendly page containing 
					a map so the printable map will be the same.

*/

function makeMapStatusCookie(mapName, lang)
{
	var mapObj = new YPGMapControl(mapName);
	
	/*if(lang == "en")
	{ var siteUrl = '.yellowpages.ca'; }
	else
	{ var siteUrl = '.pagesjaunes.ca'; }
	
	switch(mapName)
	{
		case "resultPage":
			var mapStatus = ypmapmaplistings.getState();
			break;
		case "merchantPage":
			var mapStatus = ypmapmaplisting.getState();
			break;
		case "mapPage":
			var mapStatus = ypmapcreatemap.getState();
			break;	
		default:
			break;
	}
	
	var statusSave = '';
	for (var i in mapStatus) statusSave += i+'='+mapStatus[i]+'&';
	
	var exp     = new Date(); 
	exp.setTime(exp.getTime() + (180000));	
	SetCookie('printMapStatus', statusSave, exp, '/', siteUrl)*/ 
	
	/*var d = '';
	for (var i in S) d += i+' = '+S[i]+'\n';
	alert(d);*/
}

//--------------------------------------------------------------------------------------

/*

-------  Get Listing Link -----------

    Version:        1.0
	Author:			Todd Hunt
	Description:    Retrieves Listing Link form listing area for the pop up area to link to listing site.

*/

function getListingLink(linkCount)
{
	var listingLink = document.getElementById('mapLink'+linkCount);
	var listingURL = listingLink.getAttribute("href")
	var i = listingURL.indexOf("/")
	listingURL = listingURL.slice(i);
	window.open(listingURL);
}


//--------------------------------------------------------------------------------------

/*

-------  Get Print Map -----------

    Version:        1.0
	Author:			Todd Hunt
	Description:    Retrieves map status cookie to set the status to the current map on 
					the page. It then calls the buildStatic function to retrieve a printable map.

*/

function getPrintMap(mapName)
{
	var mapStatus = GetCookies('printMapStatus');

	if(mapStatus != null)
	{
		var pairs = mapStatus.split("&"); 
		
		switch(mapName)
		{
			case "resultPage":
				var newMapStatus = ypmapmaplistings.getState();
				break;
			case "merchantPage":
				var newMapStatus = ypmapmaplisting.getState();
				break;
			case "mapPage":
				var newMapStatus = ypmapcreatemap.getState();
				break;
			default:
				break;
		}
		
		for(var i = 0; i < pairs.length; i++) 
		{
			var pos = pairs[i].indexOf('='); 
	
			if (pos == -1) continue; 
			argname = pairs[i].substring(0,pos); 
			value = pairs[i].substring(pos+1); 
			value = value.split('+');
			value = value.join(' ');
			if(argname != "Markup")
			{
				newMapStatus[argname] = unescape(value); 
			}
		}
		
		/*switch(mapName)
		{
			case "resultPage":
				yp_map_map_listings.setState(newMapStatus);
				break;
			default:
				break;
		}*/
		
	//buildStatic(newMapStatus, );
	/*	
}



-------  Build Static Map -----------

    Version:        1.0
	Author:			Todd Hunt
	Description:    Retrieves static image based on the status of the map on the page.




function buildStatic(state, trgContainer) { 
*/
//build state object 
//var state = yp_map_map_listings.getState(); 

		//build static map string 
		var staticMapStr = "<img src=\"http://service.maptuit.com/htmlclient/map.cgi?"; 
		staticMapStr+= newMapStatus.Lon + "," + newMapStatus.Lat + ","; 
		staticMapStr+= newMapStatus.mapW + "," + newMapStatus.mapH + ",0," + newMapStatus.Scale; 
		staticMapStr+= ",1,printableMap,0,YPGPartnersDevEN" + "+m+" + newMapStatus.Markup + newMarkup + "\" />"; 
		
		//inject/hide content 
		//document.getElementById("controlContainer").style.visibility = "hidden"; 
		document.getElementById('printMap').innerHTML = staticMapStr;
		
		DeleteCookie('printMapStatus');
		
		setTimeout ('window.print()', 2000);
	}
}

//--------------------------------------------------------------------------------------

/*

------- Open Survey -----------

    Version:        1.0
	Author:			Todd Hunt
	Description:    Opens actuall Survey from Popup that is served from the OAS server and 
					sets the cookie to stop the survey request to appear again.

*/

function openSurvey(srvyName, srvyURL, lang)
{
	if(lang == "en")
	{ var siteUrl = '.yellowpages.ca'; }
	else
	{ var siteUrl = '.pagesjaunes.ca'; }
	
	var exp     = new Date(); 
	var expDays = 365;
	exp.setTime(exp.getTime() + (expDays*24*60*60*1000));	
	SetCookie(srvyName, 'true', exp, '/', siteUrl);
	
	window.open(srvyURL, '','toolbar=yes,location=yes,directories=no,status=yes,'+
								   'menubar=yes,resizable=yes,copyhistory=no,scrollbars'+
								   '=yes');
	window.close();
}


//--------------------------------------------------------------------------------------

/*

------- Close Survey -----------

    Version:        1.0
	Author:			Todd Hunt
	Description:   	Closes Survey Popup that is served from the OAS server and 
					sets the cookie to stop the survey request to appear again.

*/

function closeSurvey(srvyName, lang)
{
	if(lang == "en")
	{ var siteUrl = '.yellowpages.ca'; }
	else
	{ var siteUrl = '.pagesjaunes.ca'; }
	
	var exp     = new Date(); 
	var expDays = 365;
	exp.setTime(exp.getTime() + (expDays*24*60*60*1000));	
	SetCookie(srvyName, 'true', exp, '/', siteUrl);
	
	window.close();
}

//--------------------------------------------------------------------------------------

function copyrightYear()
{
	var thisDate = new Date();
	
	var thisYear = thisDate.getYear();
	
	var regYear = new RegExp("10+", 'i')
	
	if(regYear.test(thisYear) == true)
	{
		return (thisYear + 1900);
	}
	else
	{
		return (thisYear);
	}
}

//--------------------------------------------------------------------------------------

var args = getParams();

function getParam(name)
{
	if (args == null) { return; }
	else
	{
		return args[name];
	}
}

//--------------------------------------------------------------------------------------

function queryString()
{
	var query_string;
	var queryVar = document.location.href;
	var inq = queryVar.indexOf('?');
	queryVar = queryVar.substring(inq + 1);
	
	if (inq > 0)
	{
		query_string = queryVar;
	}
	
	return query_string;
}

//--------------------------------------------------------------------------------------

function getParams() 
{
	var args = new Object();
	var query = queryString(); 
	
	if (query == null || query == '') { return; }
	
	var pairs = query.split("&"); 
	
	for(var i = 0; i < pairs.length; i++) 
	{
		var pos = pairs[i].indexOf('='); 

		if (pos == -1) continue; 
		argname = pairs[i].substring(0,pos); 
		value = pairs[i].substring(pos+1); 
		value = value.split('+');
		value = value.join(' ');
		args[argname] = unescape(value); 
	}
	
	return args;
}

function getHTTPObject ()
{
	var httpRequest;

	try
	{
		httpRequest = new ActiveXObject("Msxml2.XMLHTTP");    // Try Internet Explorer 
	}
	catch (e)
	{
		try
		{
			httpRequest = new ActiveXObject("Microsoft.XMLHTTP");    // Try Internet Explorer 
		}
		catch(e)
		{
			try
			{
				httpRequest = new XMLHttpRequest();    // Try other browsers
			}
			catch(e)
			{
				return false;
			}
		}
	}

	return httpRequest;
}

function RadioOption(id, selectedClass, unselectedClass) {
	this.id = id;
	this.selectedClass = selectedClass;
	this.unselectedClass = unselectedClass;
}

RadioOption.prototype.setSelected = function(selected) {
	var element = document.getElementById(this.id);
	if (selected) {
		element.setAttribute('class', this.selectedClass);
		element.setAttribute('className', this.selectedClass);
	} else {
		element.setAttribute('class', this.unselectedClass);
		element.setAttribute('className', this.unselectedClass);
	}
}

function RadioToggle() {
	this.active = null;
	this.options = new Array();
}

RadioToggle.prototype.add = function(option) {
	if ((null != option) && (null != option.id)) {
		this.options[this.options.length] = option;
	}
}

RadioToggle.prototype.select = function(id) {
	var activateOption = null;
	for (var i = 0; i < this.options.length; i++) {
		if (id == this.options[i].id) {
			if (this.active != this.options[i]) {
				activateOption = this.options[i];
			}
		} else {
			if (this.active == this.options[i].id) {
				this.options[i].setSelected(false);
				this.active = null;
			}
		}
	}
	if (null != activateOption) {
		activateOption.setSelected(true);
		this.active = activateOption.id;
	}
}

function toggleMenu(id, menuPlus, menuMinus, display) {
	if (display != document.getElementById(id).style.display) {
		document.getElementById(id).style.display = display;
		document.getElementById(menuPlus).style.display = 'none';
		document.getElementById(menuMinus).style.display = display;
	} else {
		document.getElementById(id).style.display = 'none';
		document.getElementById(menuPlus).style.display = display;
		document.getElementById(menuMinus).style.display = 'none';
	}
}

function ToggleChild(parent, child, visible, hidden) {
	this.parentId = parent;
	this.childId = child;
	this.visibleClass = visible;
	this.hiddenClass = hidden;
}

ToggleChild.prototype.toggle = function() {
	var parent = document.getElementById(this.parentId);
	var child = document.getElementById(this.childId);
	if ((null != parent) && (null != child)) {
		if ('none' == parent.style.display) {
			child.setAttribute('class', this.hiddenClass);
			child.setAttribute('className', this.hiddenClass);
		} else {
			child.setAttribute('class', this.visibleClass);
			child.setAttribute('className', this.visibleClass);
		}
	}
}

function ToggleMenu(id, itemId, menuId, display, delay) {
	this.id = id;
	this.itemId = itemId;
	this.menuId = menuId;
	this.display = display;
	this.delay = delay;
	this.timerId = 0;
	this.children = new Array();
}

ToggleMenu.prototype.getItemId = function() {
	return this.itemId;
}

ToggleMenu.prototype.isExpanded = function() {
	return document.getElementById(this.menuId).style.display == this.display;
}

ToggleMenu.prototype.addChild = function(id, visible, hidden) {
	this.children[this.children.length] = new ToggleChild(this.menuId, id, visible, hidden);
}

ToggleMenu.prototype.cancelToggle = function() {
	if (0 != this.timerId) {
		clearTimeout(this.timerId);
		this.timerId = 0;
	}
}

ToggleMenu.prototype.delayVisible = function(visible) {
	this.cancelToggle();
	if ((null != this.delay) && (0 < this.delay)) {
		this.timerId = setTimeout(this.id + ".setVisible('" + visible + "')", this.delay);
	} else {
		this.setVisible(visible);
	}
}

ToggleMenu.prototype.setVisible = function(visible) {
	var menuElement = document.getElementById(this.menuId);
	if (('true' == visible) && (this.display != menuElement.style.display)) {
		menuElement.style.display = this.display;
		this.toggleChildren();
	} else if (('false' == visible) && ('none' != menuElement.style.display)) {
		menuElement.style.display = 'none';
		this.toggleChildren();
	}
}

ToggleMenu.prototype.toggleChildren = function() {
	for (var i = 0; i < this.children.length; i++) {
		this.children[i].toggle();
	}
}

ToggleMenu.prototype.toggleVisible = function() {
	var menuElement = document.getElementById(this.menuId);
	if (this.display != menuElement.style.display) {
		menuElement.style.display = this.display;
		this.toggleChildren();
	} else {
		menuElement.style.display = 'none';
		this.toggleChildren();
	}
}

function closeList(list)
{
	document.getElementById(list).style.display = "none";
}


function openList(list)
{
	document.getElementById(list).style.display = "block";
}

/**
 * Toggle Collapse/Expand of a DIV and sync icon state for Collapse/Expand state
 * @param section id of section to show/hide
 * @param css class name to show in collapsed state
 * @param css class name to show in expanded state
 * NOTE: id of icon is assumed to be same as section with "Toggle" appended
 * NOTE: On hover image rollovers done via CSS a:hover
 */
function toggleSection(section, collapsedStateClass, expandedStateClass)
{
	if(section && section != "") {
		var el = $(section);
		var elIcon = $(section + "Toggle");
		
		if ("none" == el.getStyle('display')) {
			el.style.display = "block";
			
			elIcon.addClassName(collapsedStateClass);
			elIcon.removeClassName(expandedStateClass);
			
			if (section == 'mapHolder')
				$('navcontrol').style.display = "block";
			
		} else {
			el.style.display = "none";
			elIcon.addClassName(expandedStateClass);
			elIcon.removeClassName(collapsedStateClass);

			if (section == 'mapHolder')
				$('navcontrol').style.display = "none";
		}
	}
}

/**
 * send out HBX data (for lid and lpos only) only when expand toggle, and do NOT send out HBX data when hide toggle.  
 * @param section id of section to show/hide.
 * @param lidValue  HBX "lid" value which will be sent out.
 * @param lposValue HBX "lpos" value which will be sent out.
 * @return
 */
function hbxFromExpandToggle(section, lidValue, lposValue)
{
	if(section && section != "") {
		
		if ("none" == $(section).getStyle('display')) {
			_hbSet('lid',lidValue);
			_hbSet('lpos',lposValue);
			_hbSend();
		}
	}
	
}