// JavaScript Document
//**************************************************************************************
// browser.js

function browserApp()
{
	var application = navigator.appName;
	//alert(application);	
	return application;
}

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

function browserVendor()
{
	var vendor = navigator.vendor;
	//alert(application);	
	return vendor;
}

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

function browserVer()
{
	var version = navigator.appVersion;
	//alert(version);
	return version;
}

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

function operatingSys()
{
	var os = navigator.platform;
	//alert(os);
	return os;
}

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

function windowsOnly()
{
	var platform = operatingSys();
	var regPlatform = RegExp("Win.+", 'i');
		
	if (regPlatform.test(platform) == true)
	{ return true; }
	else
	{ return false; }
}

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

function windowsExplorer()
{
	var platform = windowsOnly();
	var browser = browserApp();
	
	var regBrowser = RegExp(".+Explorer", 'i');
	
	if (platform == true && regBrowser.test(browser) == true)
	{ return true; }
	else
	{ return false; }
}

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

function ffColourShift()
{
	var browser = browserVendor();
	
	if (browser == "Firefox")
	{
		document.getElementById('leftBar').style.backgroundColor = "#E8E3D3";
		document.getElementById('colour3BG').style.backgroundColor = "#E8E3D3";
	}
}

//**************************************************************************************
// standard.js

/*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 == "advanced")
	{
		setTabs(document.getElementById('tw_advanced'));
		setTabs(document.getElementById('headerSearch'));
		setTabs(document.getElementById('searchOptionNavBar'));
		document.forms['BusinessSearch']['firstname'].focus();
	}
	else if(pageName == "address")
	{
		setTabs(document.getElementById('tw_address'));
		setTabs(document.getElementById('headerSearch'));
		setTabs(document.getElementById('searchOptionNavBar'));
		document.forms['BusinessSearch']['st'].focus();
	}
	else if(pageName == "reverse")
	{
		setTabs(document.getElementById('tw_reverse'));
		setTabs(document.getElementById('headerSearch'));
		setTabs(document.getElementById('searchOptionNavBar'));
		document.forms['BusinessSearch']['pac'].focus();
	}
	else if(pageName == "proximity")
	{
		setTabs(document.getElementById('tw_proximity'));
		setTabs(document.getElementById('headerSearch'));
		setTabs(document.getElementById('searchOptionNavBar'));
		document.forms['BusinessSearch']['what'].focus();
	}
	else if(pageName == "areaCode")
	{
		setTabs(document.getElementById('tw_areaCode'));
		setTabs(document.getElementById('headerSearch'));
		setTabs(document.getElementById('searchOptionNavBar'));
		document.forms['GetMap']['pc'].focus();
	}
	else if(pageName == "map")
	{
		setTabs(document.getElementById('tw_map'));
		setTabs(document.getElementById('headerSearch'));
		setTabs(document.getElementById('searchOptionNavBar'));
		document.forms['GetMap']['st'].focus();
	}
	else if(pageName == "directions")
	{
		setTabs(document.getElementById('tw_directions'));
		setTabs(document.getElementById('headerSearch'));
		setTabs(document.getElementById('searchOptionNavBar'));
		document.forms['DrivingDirections']['fromSt'].focus();
	}
	else if(pageName == "basic")
	{
		document.forms['wp_pers_form']['what'].focus();
	}
//	else if(pageName == "category")
//	{
//		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"; }
	var left = parseInt((screen.availWidth/2) - (w/2));
    var top = parseInt((screen.availHeight/2) - (h/2));
	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+',left='+left+',top='+top);
	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;                                                      
	}
	
//--------------------------------------------------------------------------------------

/*

-------  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 = null; //(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 toggleDisplay(one, other, displayAttr)
{
	if (document.getElementById(one).style.display == 'none') {
		document.getElementById(one).style.display = displayAttr;
		document.getElementById(other).style.display = "none";
	} else {
		document.getElementById(one).style.display = "none";
		document.getElementById(other).style.display = displayAttr;
	}
}

function switchReportErrorLink(target)
{
	try
	{
		if (target == "wp")
		{
			document.getElementById("wp_report_error").style.display = "inline";
			document.getElementById("yp_report_error").style.display = "none";
		}
		else
		{
			document.getElementById("wp_report_error").style.display = "none";
			document.getElementById("yp_report_error").style.display = "inline";
		}
	}
	catch (err)
	{
		// ids are not defined in footer - ignore
	}
}

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


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

/*

-------  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;
}

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

tab = 1;
recurse = new Array();
if(document.all && !document.getElementById) {
    document.getElementById = function(id) { return document.all[id]; }
}

function setTabs (node) {
	if (node == null) return;

	for (j=0;j<node.childNodes.length;j++) {
		child = node.childNodes[j];
		if (child.nodeType==1) {
			if (node.id=='searchOptionNavBar') { 
				if (child.nodeName=='A') {
				    try {
					    child.tabIndex = tab;
					   	tab++;
					}
					catch (e) {
					}
				}
			}
			else if (child.nodeName=='INPUT' || child.nodeName=='SELECT' || child.onClick!=null) {
			    if (child.type!='hidden') {
			    	try {
					    child.tabIndex = tab;
				    	tab++;
					}
					catch (e) {
					}
				}
		    }

			if (child.childNodes.length>0) { //check not necessary but faster
				recurse.push(j);
				recurse.push(node);
				setTabs(child);
				node = recurse.pop();
				j = recurse.pop();
			}
		}
	}
}


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

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 searchOnEnterKey(formName)
{
	if (event.keyCode == 13)
	{
		event.cancelBubble = true;
		event.returnValue = false;
		document.forms[formName].submit();
	}
}

//**************************************************************************************
// menu.js
// Don't change these parameters
var delay        = 550; /////
var menuElement  = new Array ();
var usedWidth    = 0;
var numOfMenus   = 0;
/// ----------------------------

var topID  = -1;

var xPos = 0;
var yPos = 0;

function offsetLeft(o){
    var i = 0;
    while (o.offsetParent!=null) {
        i += o.offsetLeft;
        o = o.offsetParent;
    }
    return i + o.offsetLeft;
}
function offsetTop(o){
    var i = 0;
    while (o.offsetParent!=null) {
        i += o.offsetTop;
        o = o.offsetParent;
    }
    return i + o.offsetTop;
}

function menuPos(ID)
{
	var explorerTest = windowsExplorer();
	
	xPos = offsetLeft(document.getElementById('ref' + ID));
	xSitePos = offsetLeft(document.getElementById('PhoneBook'));
	
	xPos = xPos - xSitePos;
	
//	explorerTest == true ? yPos = 5 : yPos = 128;
	yPos = offsetTop(document.getElementById('ref' + ID));
	ySitePos = offsetTop(document.getElementById('PhoneBook'));
	
	yPos = yPos - ySitePos + 15;


}

// constructor of menu elements
function menuConstructor(id)
{
	this.ID            = id; // the Current Menu ID
	this.parentID      = -1; // the Current Menu's Parent Menu ID
	this.parentItemID  = -1; // the Current Menu's Parent Menu Item ID
	this.timerID       = -1; // the Current Menu's Delay timer
	this.isOn          = false; // the Current Menu's Display Status
	this.currItemID    = -1; // the i don't know
	
	/*if(id > 1)
	{
		this.parentID      = 1;
		this.parentItemID  = id - 2;
	}*/
	
	return this;
}

function enterTopItem(ID)
{//alert('enterTopItem');
	if (topID != ID && topID != -1)
	{
		hideTree(topID);
	}
	menuPos(ID);
	releaseTree(ID);
	topID = ID;
	show(ID);
	document.getElementById('ref' + ID).style.color = "#996600";
}

function enterSearchOpsItem(ID)
{//alert('enterTopItem');
	if (topID != ID && topID != -1)
	{
		hideTree(topID);
	}
	menuPos(ID);
	releaseTree(ID);
	topID = ID;
	showSearchOps(ID);
	document.getElementById('ref' + ID).style.color = "#996600";
}

function enterBucketItem(ID)
{//alert('enterTopItem');
	if (topID != ID && topID != -1)
	{
		hideTree(topID);
	}
	menuPos(ID);
	releaseTree(ID);
	topID = ID;
	showBucket(ID);
	document.getElementById('ref' + ID).style.color = "#996600";
}

function exitTopItem(ID)
{//alert('exitTopItem');
	menuElement[ID].timerID = setTimeout('hide (' + ID + ')', delay);
}


// Called by PopMenu Items

function enterItem(menuID, itemID)
{//alert('enterItem');
	var currItemID = menuElement[menuID].currItemID;
	menuPos(2, itemID);
	if (currItemID > -1)	
	{
		hide (currItemID);
	}

	for (var i = 0; i < numOfMenus; i++)
	{
		if (menuElement[i].parentID == menuID && menuElement[i].parentItemID == itemID)
		{
			clearTimeout (menuElement[i].timerID);
			menuElement[i].timerID = -1;
			show(i);
			return 0;
		}
	}

	return -1;
}

function exitItem(menuID, itemID)
{//alert('exitItem');
	
	for (var i = 0; i < numOfMenus; i++)
	{
		if (menuElement[i].parentID == menuID && menuElement[i].parentItemID == itemID)
		{
			menuElement[i].timerID = setTimeout ('hide (' + i + ')', delay);
			return 0;
		}
	}
	
	/*menuElement[menuID].timerID = setTimeout ('hide (' + menuID + ')', delay);
		
	if (menuElement[menuID].parentID > -1)
	{
		menuElement[menuElement[menuID].parentID].timerID = setTimeout ('hide (' + menuElement[menuID].parentID + ')', delay);
	}*/
}


// Called By Main Div Holders of Nav Peace

function enterMenu(ID)
{//alert('enterMenu');
	var parentID = menuElement[ID].parentID;
	
	if (parentID == -1)
	{
		clearTimeout (menuElement[ID].timerID);
		menuElement[ID].timerID = -1;
	}
	else
	{
		releaseTree(ID);
	}
}

function exitMenu(ID)
{//alert('exitMenu');
	timeoutTree(ID);
}


function hideTree(ID)
{//alert('hideTree');
	if(ID == "all")
	{
		for (var j = 0; j < numOfMenus; j++)
		{
			if (menuElement[j].isOn)
			{
				hide(j);
			}
		}
	}
	else
	{
		hide(ID);
		
		for (var j = 0; j < numOfMenus; j++)
		{
			if (menuElement[j].parentID == ID && menuElement[j].isOn)
			{
				hideTree(j);
				return 0;
			}
		}
	}
}

function releaseTree(ID)
{//alert(ID);
	clearTimeout(menuElement[ID].timerID);
	menuElement[ID].timerID = -1;

	var parentID = menuElement[ID].parentID;
	
	if (parentID > -1)
	{
		releaseTree(parentID);
	}
}

function timeoutTree(ID)
{//alert('timeoutTree');
	menuElement[ID].timerID = setTimeout ('hide (' + ID + ')', delay);
	
	var parentID = menuElement[ID].parentID;
	
	if (parentID > -1)
	{
		timeoutTree(parentID);
	}
}


function showHolder()
{//alert('showHolder');
	document.getElementById('MenuHolder').style.display = 'block';
}

function hideHolder()
{//alert('hideHolder');
	document.getElementById('MenuHolder').style.display = "none";
}

function show(ID)
{//alert('show');
	//showHolder();

	document.getElementById('Menu' + ID).style.visibility = 'visible';
	document.getElementById('Menu' + ID).style.left = xPos + 'px';
	document.getElementById('Menu' + ID).style.top =  yPos + 'px';

	menuElement[ID].isOn = true;

	if (menuElement[ID].parentID > -1)
	{
		menuElement[menuElement[ID].parentID].currItemID = ID;
	}
	document.getElementById('ref' + ID).style.color = "#996600";
}

function showSearchOps(ID)
{//alert('show');
	//showHolder();

	document.getElementById('Menu' + ID).style.visibility = 'visible';
	
		document.getElementById('Menu' + ID).style.top =  yPos + 'px';
		document.getElementById('Menu' + ID).style.left =  xPos + 'px';
	
	menuElement[ID].isOn = true;

	if (menuElement[ID].parentID > -1)
	{
		menuElement[menuElement[ID].parentID].currItemID = ID;
	}
	document.getElementById('ref' + ID).style.color = "#996600";
}

function showBucket(ID)
{//alert('show');
	//showHolder();

	document.getElementById('Menu' + ID).style.visibility = 'visible';
	
	document.getElementById('Menu' + ID).style.left = xPos + 35 + 'px';
	document.getElementById('Menu' + ID).style.top =  yPos - 35 + 'px';
	
	menuElement[ID].isOn = true;

	if (menuElement[ID].parentID > -1)
	{
		menuElement[menuElement[ID].parentID].currItemID = ID;
	}
	document.getElementById('ref' + ID).style.color = "#996600";
}

function hide(ID)
{//alert('hide');
	document.getElementById('Menu' + ID).style.visibility = "hidden";
	menuElement[ID].isOn = false;

	if (menuElement[ID].parentID > -1)
	{
		menuElement[menuElement[ID].parentID].currItemID = -1;
	}
	
	var elementOn = 0;
	
	for(var j = 0; j < numOfMenus; j++)
	{
		if(menuElement[j].isOn)
		{
			elementOn++;
		}
	}
	
	if(elementOn == 0)
	{
		//hideHolder();
	}
	document.getElementById('ref' + ID).style.color = "#000000";
}


function createMenuTree()
{
	for (var i = 0; i < 71; i++)
	{
		menuElement[i] = new menuConstructor(i);
		numOfMenus++;
	}
}

createMenuTree ();

//**************************************************************************************
// se_hilite_src.js

/**
 * Search Engine Keyword Highlight (http://fucoder.com/code/se-hilite/)
 *
 * This module can be imported by any HTML page, and it would analyse the
 * referrer for search engine keywords, and then highlight those keywords on
 * the page, by wrapping them around <span class="hilite">...</span> tags.
 * Document can then define styles else where to provide visual feedbacks.
 *
 * Usage:
 *
 *   In HTML. Add the following line towards the end of the document.
 *
 *     <script type="text/javascript" src="se_hilite.js"></script>
 *
 *   In CSS, define the following style:
 *
 *     .hilite { background-color: #ff0; }
 *
 *   If Hilite.style_name_suffix is true, then define the follow styles:
 *
 *     .hilite1 { background-color: #ff0; }
 *     .hilite2 { background-color: #f0f; }
 *     .hilite3 { background-color: #0ff; }
 *     .hilite4 ...
 *
 * @author Scott Yang <http://scott.yang.id.au/>
 * @version 1.3
 */

// Configuration:
Hilite = {
    /**
     * Element ID to be highlighted. If set, then only content inside this DOM
     * element will be highlighted, otherwise everything inside document.body
     * will be searched.
     */
    elementid: 'content',
    
    /**
     * Element class to be highlighted. If set, only content inside elements
     * of his class will be highlighted.
     *
     */
    elementclass: null,
    
    /**
     * Whether we are matching an exact word. For example, searching for
     * "highlight" will only match "highlight" but not "highlighting" if exact
     * is set to true.
     */
    exact: true,

    /**
     * Maximum number of DOM nodes to test, before handing the control back to
     * the GUI thread. This prevents locking up the UI when parsing and
     * replacing inside a large document.
     */
    max_nodes: 1000,

    /**
     * Whether to automatically hilite a section of the HTML document, by
     * binding the "Hilite.hilite()" to window.onload() event. If this
     * attribute is set to false, you can still manually trigger the hilite by
     * calling Hilite.hilite() in Javascript after document has been fully
     * loaded.
     */
    onload: true,

    /**
     * Name of the style to be used. Default to 'hilite'.
     */
    style_name: 'hilite',
    
    /**
     * Whether to use different style names for different search keywords by
     * appending a number starting from 1, i.e. hilite1, hilite2, etc.
     */
    style_name_suffix: true,

    /**
     * Set it to override the document.referrer string. Used for debugging
     * only.
     */
    debug_referrer: '',
		
		/**
     * Set it to override the keyword.
     */
    keyword_override: ''
};

Hilite.search_engines = [
		['^http://.*', 'what=']             // Yellowpages
];

/**
 * Decode the referrer string and return a list of search keywords.
 */
Hilite.decodeReferrer = function(referrer) {
    var query = null;
    var match = new RegExp('');

    for (var i = 0; i < Hilite.search_engines.length; i ++) {
        match.compile(Hilite.search_engines[i][0], 'i');
        if (referrer.match(match)) {
            match.compile('^.*'+Hilite.search_engines[i][1]+'([^&]+)&?.*$');
            query = referrer.replace(match, '$1');
            if (query) {
                query = decodeURIComponent(query);
                query = query.replace(/\'|"/, '');
                query = query.split(/[\s,\+\.]+/);
                return query;
            }
        }
    }
    return null;
};

/**
 * Highlight a DOM element with a list of keywords.
 */
Hilite.hiliteElement = function(elm, query) {
    if (!query || elm.childNodes.length == 0)
	return;

    var qre = new Array();
    for (var i = 0; i < query.length; i ++) {
        query[i] = query[i].toLowerCase();
        if (Hilite.exact)
            qre.push('\\b'+query[i]+'\\b');
        else
            qre.push(query[i]);
    }

    qre = new RegExp(qre.join("|"), "i");

    var stylemapper = {};
    for (var i = 0; i < query.length; i ++)
        stylemapper[query[i]] = Hilite.style_name+(i+1);

    var textproc = function(node) {
        var match = qre.exec(node.data);
        if (match) {
            var val = match[0];
            var k = '';
            var node2 = node.splitText(match.index);
            var node3 = node2.splitText(val.length);
            var span = node.ownerDocument.createElement('SPAN');
            node.parentNode.replaceChild(span, node2);
            span.className = stylemapper[val.toLowerCase()];
            span.appendChild(node2);
            return span;
        } else {
            return node;
        }
    };
    Hilite.walkElements(elm.childNodes[0], 1, textproc);
};

/**
 * Highlight a HTML document using keywords extracted from document.referrer.
 * This is the main function to be called to perform search engine highlight
 * on a document.
 *
 * Currently it would check for DOM element 'content', element 'container' and
 * then document.body in that order, so it only highlights appropriate section
 * on WordPress and Movable Type pages.
 */
Hilite.hilite = function() {
    // If 'debug_referrer' then we will use that as our referrer string
    // instead.
    var q = Hilite.debug_referrer ? Hilite.debug_referrer : document.referrer;
    var e = null;
    q = Hilite.keyword_override ? [Hilite.keyword_override] : Hilite.decodeReferrer(q);
    if (q && ((Hilite.elementid && 
               (e = document.getElementById(Hilite.elementid))) || 
              (e = document.body)))
    {
	Hilite.hiliteElement(e, q);
    }
};

Hilite.walkElements = function(node, depth, textproc) {
    var skipre = /^(script|style|textarea)/i;
    var count = 0;
    while (node && depth > 0) {
        count ++;
        if (count >= Hilite.max_nodes) {
            var handler = function() {
                Hilite.walkElements(node, depth, textproc);
            };
            setTimeout(handler, 50);
            return;
        }

        if (node.nodeType == 1) { // ELEMENT_NODE
            if (!skipre.test(node.tagName) && node.childNodes.length > 0) {
                node = node.childNodes[0];
                depth ++;
                continue;
            }
        } else if (node.nodeType == 3 && 
        	(node.className == Hilite.elementclass || node.parentNode.className == Hilite.elementclass) ) { // TEXT_NODE
            node = textproc(node);
        }

        if (node.nextSibling) {
            node = node.nextSibling;
        } else {
            while (depth > 0) {
                node = node.parentNode;
                depth --;
                if (node.nextSibling) {
                    node = node.nextSibling;
                    break;
                }
            }
        }
    }
};

// Trigger the highlight using the onload handler.
if (Hilite.onload) {
    if (window.attachEvent) {
        window.attachEvent('onload', Hilite.hilite);
    } else if (window.addEventListener) {
        window.addEventListener('load', Hilite.hilite, false);
    } else {
        var __onload = window.onload;
        window.onload = function() {
            Hilite.hilite();
            __onload();
        };
    }
}

//**************************************************************************************
// 

// Add address to list
function addAddress(a, list, i) {
	list[i] = new Array(6);
	list[i][0] = "a.street";
	list[i][1] = "a.city";
	list[i][2] = "a.province";
	list[i][3] = "a.postalCode";
	list[i][4] = "a.lat";
	list[i][5] = "a.lon";
}

// Add landmark address to list
function addLmAddress(lm, list, i) {
	list[i] = new Array(6);
	list[i][0] = "lm.landmarkName";
	list[i][1] = "lm.address.city";
	list[i][2] = "lm.address.province";
	list[i][3] = "lm.address.postalCode";
	list[i][4] = "lm.address.lat";
	list[i][5] = "lm.address.lon";
}

// Set form fields from address in list
function setAddress(id, list, i) {
	document.forms[id]['st'].value = list[i][0];
	document.forms[id]['ci'].value = list[i][1];
	document.forms[id]['pv'].value = list[i][2];
	document.forms[id]['pc'].value = list[i][3];
	document.forms[id]['lat'].value = list[i][4];
	document.forms[id]['lon'].value = list[i][5];
}

// Set form fields from landmark address in list
function setLmAddress(id, list, i) {
	document.forms[id]['lm'].value = list[i][0];
	document.forms[id]['st'].value = "";
	document.forms[id]['ci'].value = list[i][1];
	document.forms[id]['pv'].value = list[i][2];
	document.forms[id]['pc'].value = list[i][3];
	document.forms[id]['lat'].value = list[i][4];
	document.forms[id]['lon'].value = list[i][5];
}

// Set form fields from Saved Location
function setLocation(id, name) {
	if ('' != name) {
		document.forms[id]['st'].value = locals[name]['street'];
		document.forms[id]['ci'].value = locals[name]['city'];
		document.forms[id]['pc'].value = locals[name]['postalCode'];
		for (var i = 0; i < document.forms[id]['pv'].length; i++) {
			if(document.forms[id]['pv'][i].value == locals[name]['province']) {
				document.forms[id]['pv'].selectedIndex = i;
			}
		}
		return false;
	} else {
		document.forms[id]['st'].value = "";
		document.forms[id]['ci'].value = "";
		document.forms[id]['pc'].value = "";
		document.forms[id]['pv'].selectedIndex = 0;
		return false;	
	}
}