var B = { init: function () { this.browser = this.sS(this.dB) || "unknown"; this.version = this.sV(navigator.userAgent) || this.sV(navigator.appVersion) || "unknown";this.OS = this.sS(this.dO) || "unknown";}, sS: function (d) { for (var i=0;i<d.length;i++){ var dStr = d[i].str; var dPp = d[i].p; this.vSS = d[i].vSch || d[i].id; if (dStr){ if (dStr.indexOf(d[i].substr) != -1) return d[i].id; }else if (dPp) return d[i].id; }}, sV: function (dStr) { var i = dStr.indexOf(this.vSS); if (i == -1) return; return parseFloat(dStr.substring(i+this.vSS.length+1)); }, dB: [{str: navigator.userAgent,substr: "OmniWeb",vSch: "OmniWeb/",id: "OmniWeb"},{str: navigator.vendor,substr: "Apple",id: "Safari"},{p: window.opera,id: "Opera"},{str: navigator.vendor,substr: "iCab",id: "iCab"},{str: navigator.vendor,substr: "KDE",id: "Konqueror"},{str: navigator.userAgent,substr: "Firefox",id: "Firefox"},{str: navigator.vendor,substr: "Camino",id: "Camino"},{str: navigator.userAgent,substr: "Netscape",id: "Netscape"},{str: navigator.userAgent,substr: "MSIE",id: "IE",vSch: "MSIE"},{str: navigator.userAgent,substr: "Gecko",id: "Mozilla",vSch: "rv"},{ str: navigator.userAgent,substr: "Mozilla",id: "Netscape",vSch: "Mozilla"}], dO : [{str: navigator.platform,substr: "Win",id: "Windows"},{str: navigator.platform,substr: "Mac",id: "Mac"},{str: navigator.platform,substr: "Linux",id: "Linux"}] }; 
B.init();

/* set a cookie */
	function setCookie(c_name,value,expiredays)
	{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+
	";path=/";
	}


/* get a cookie value */
	function getCookie(c_name)
	{
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
		 { 
		 c_start=c_start + c_name.length+1; 
		 c_end=document.cookie.indexOf(";",c_start);
		 if (c_end==-1) c_end=document.cookie.length;
		 return unescape(document.cookie.substring(c_start,c_end));
		 } 
	  }
	return "";
	}
	

/* Set user's Switcher pref in a cookie */
	function SetSwitcherPref (state) {
		setCookie("IntegraSwitcher", state, 365);	
	}
	
/* Get user's Switcher pref from the cookie */
	function GetSwitcherPref() {
		return getCookie ("IntegraSwitcher");	
	}


/* Set the user's market ID in a cookie */
	function SetMarketId (newmarketId){
		setCookie("IntegraMarketId", newmarketId, 365);	
	}

/* Set the user's market Name in a cookie */
	function SetMarketName (newmarketName){
		setCookie("IntegraMarketName", newmarketName, 365);	
	}
	
/* Get the user's market ID from the cookie */
	function GetMarketId() {
		return getCookie ("IntegraMarketId");
	}
	
	
/* Get the user's market Name from the cookie */
	function GetMarketName() {
		return getCookie ("IntegraMarketName");
	}	


/* Show lightbox to let user select market. */
	function DoLightbox(){
		document.getElementById("usermarket").value = GetMarketId();
		Lightbox.init();	
		Lightbox.showBoxByID('market-selector', 350, 230);
	}


/* Send to Prior Lake 
	Redirects to getintegra.com homepage.
	Used by the Solution Finder when someone chooses Prior Lake.
*/
function SendToPL() {
	location.href = '/priorlake.php';
}
	
	
function AjaxMarketName() {
	var xmlHttp;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	} catch (e)	{
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e)	{
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e)	{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			var newhtml = 'Your Service Area: <a href="javascript:DoLightbox();">' + xmlHttp.responseText + '</a>';
			document.getElementById("YourMarketName").innerHTML = newhtml;
		}
	}
	xmlHttp.open("GET","/includes/ajax_market_name.php",true);
	xmlHttp.send(null);
 }



/* Popup
	Use to make a popup window
*/
function Popup(strURL,strHeight,strWidth) {
	var strOptions = "toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth;
	window.open(strURL, 'newWin', strOptions);
}
