checkBrowserWidth();

attachEventListener(window, "resize", checkBrowserWidth, false);




function checkBrowserWidth()
{
	//alert('hey');
	var theWidth = getBrowserWidth();
	
	if (theWidth == 0)
	{
		var resolutionCookie = document.cookie.match(/(^|;)getsolar_window_layout[^;]*(;|$)/);

		if (resolutionCookie != null)
		{
			setStylesheet(unescape(resolutionCookie[0].split("=")[1]));
		}
		
		addLoadListener(checkBrowserWidth);
		
		return false;
	}

	if (theWidth > 800 && theWidth < 850)
	{
		setStylesheet("layout1");
		document.cookie = "getsolar_window_layout=" + escape("layout1");
	}
	
	else if (theWidth > 851 && theWidth < 1100)
	{
		setStylesheet("layout2");
		document.cookie = "getsolar_window_layout=" + escape("layout2");
	}
	
	else if (theWidth > 1101 && theWidth < 1400)
	{
		setStylesheet("layout3");
		document.cookie = "getsolar_window_layout=" + escape("layout3");
	}
	
	else if (theWidth > 1401 && theWidth < 5000)
	{
		setStylesheet("layout4");
		document.cookie = "getsolar_window_layout=" + escape("layout4");
	}
	
	else
	{
		setStylesheet("");
		document.cookie = "getsolar_window_layout=";
	}
	
	return true;
};




function getBrowserWidth()
{
	if (window.innerWidth)
	{
		return window.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth != 0)
	{
		return document.documentElement.clientWidth;
	}
	else if (document.body)
	{
		return document.body.clientWidth;
	}
	
	return 0;
};




function setStylesheet(styleTitle)
{
	var currTag;

	if (document.getElementsByTagName)
	{
		for (var i = 0; (currTag = document.getElementsByTagName("link")[i]); i++)
		{
			if (currTag.getAttribute("rel").indexOf("style") != -1 && currTag.getAttribute("title"))
			{
				currTag.disabled = true;

				if(currTag.getAttribute("title") == styleTitle)
				{
					currTag.disabled = false;
				}
			}
		}
	}
	
	return true;
};

function statelanding(name) {	
	if(name=='california' || name=='florida' || name=='texas')
	{
		//alert('yes');
		location.href='http://www.getsolar.com/'+name+'-installers/';
	}
	else
	{
	var str = name;
	name=str.replace(/ /g, "-");
	//alert(name);
	location.href='http://www.getsolar.com/'+name+'-solar-power-panel-installation-professionals.php';
	}
}
