var serviceCounter = 0;
var addModuleCounter = 0;
var customServiceCounter = 0;
var customLinks = 0;
var highZ = 3;
var dSearchModuleClosed = 'false';
var browserName = navigator.appName;
var browserVer = parseInt(navigator.appVersion);
var browserPlatform = navigator.platform;
var browserVendor = navigator.vendor;

function runScripts()
{
	var pageNav = document.getElementById('pageNav');
	var ulArray = pageNav.getElementsByTagName('ul');
	
	for (var i = 0; i < ulArray.length; i++)
	{
		if ((ulArray[i].className == 'level2') || (ulArray[i].className == 'level3'))
		{
			ulArray[i].style.display = 'none';
		}
	}
	
	if(document.getElementById('homePic'))
	{
		rotateImages();
	}
	
	if(document.getElementById('rNav'))
	{
		if (document.getElementById('newsModule_outer'))
		{}
		else
		{
			try
			{
				document.getElementById('dsearchModule').style.display = 'none';
				document.getElementById('dinspectionsModule').style.display = 'none';
				document.getElementById('dreferralModule').style.display = 'none';
			
				readCookie();
			}
			catch(err)
			{}
		}
	}
	addMenuJS();
	openMenus();
	/* Page Changes for Accessibility */
	pageChanges();
	
	if (document.getElementById('gCalendar'))
	{
		calvis.ready(main);
	}
}

function addMenuJS()
{
	var pageNav = document.getElementById('pageNav');
	var liArray = pageNav.getElementsByTagName('li');
	
	for (var i = 0; i < liArray.length; i++)
	{
		if (liArray[i].className == 'submenu')
		{	
			if (liArray[i].firstChild.id == 'menuImage')
			{
				replaceMenuElements(liArray[i].firstChild.id,'expand')
			}
			else
			{
				createMenuElements(liArray[i], 'expand')
			}
		
			liArray[i].firstChild.onclick = function()
			{
				menuExpandCollapse(this);
				return false;
			};
		}
		else
		{
			createMenuElements(liArray[i], 'arrow');
		}
	}
}

function openMenus()
{
	try
	{
		var pageNav = document.getElementById('pageNav');
		var liArray = pageNav.getElementsByTagName('li');
		var ulLevel = new Array();
		
		var pageTitle = location.href;
		if (pageTitle.charAt(0) == '/')
		{
			pageTitle = pageTitle.slice(1);
		}
		var pageTitleArray = pageTitle.split('/');
		
		var j = pageTitleArray.length - 2;
		var x = 0;
		while (pageTitleArray[j] !== 'html')
		{
			if (j <= 0)
			{
				break;
			}
			ulLevel[x] = pageTitleArray[j];
			x++;
			j--;
		}
		
		for (var i = 0; i < liArray.length; i++)
		{
			var liPath = liArray[i].childNodes[1].href
			if (liPath.charAt(0) == '/')
			{
				liPath = liPath.slice(1);
			}
			
			if (pageTitle == liPath)
			{
				liArray[i].childNodes[1].style.color = '#A35E13';
				if (liArray[i].firstChild.className == 'imageLink')
				{
					menuExpandCollapse(liArray[i].firstChild);
				}
				if (liArray[i].parentNode == 'div#pageNav')
				{
					break;
				}
				var parentSub = liArray[i].parentNode.parentNode;
				
				if (parentSub.id != 'pageNav')
				{
					if (parentSub.firstChild.className == 'imageLink')
					{
						menuExpandCollapse(parentSub.firstChild);
					}
					parentSub = parentSub.parentNode.parentNode;
					
					if (parentSub.id != 'pageNav')
					{ 
						menuExpandCollapse(parentSub.firstChild);
					}
				}
			}
		}
	}
	catch (err)
	{}
}

function createMenuElements(li, type)
{
	if (type == 'expand')
	{
		var imageLink = document.createElement('a');
		imageLink.setAttribute('href','#');
		imageLink.className = 'imageLink';
		
		var expandImage = document.createElement('img');
		expandImage.setAttribute('src','http://www.co.shasta.ca.us/images/expand_menu.gif');
		/*expandImage.setAttribute('id','menuImage');*/
		expandImage.className = 'menuImage';
		imageLink.appendChild(expandImage);
		
		var liLink = li.firstChild;
		li.insertBefore(imageLink, liLink);
	}
	
	else if (type == 'collapse')
	{
		var imageLink = document.createElement('a');
		imageLink.setAttribute('href','#');
		imageLink.className = 'imageLink';
		
		var collapseImage = document.createElement('img');
		collapseImage.setAttribute('src','http://www.co.shasta.ca.us/images/arrow_menu.gif');
		collapseImage.setAttribute('id','menuImage');
		collapseImage.className = 'menuImage';
		imageLink.appendChild(collapseImage);
		
		var liLink = li.firstChild;
		li.insertBefore(imageLink, liLink);
	}
	
	else if (type == 'arrow')
	{
		var arrowImage = document.createElement('img');
		arrowImage.setAttribute('src','http://www.co.shasta.ca.us/images/link_image.gif');
		arrowImage.className = 'menuArrowImage';
		
		var liLink = li.firstChild;
		li.insertBefore(arrowImage, liLink);
	}
}

function replaceMenuElements(li, type)
{
	try
	{
		var menuImage = li.firstChild.firstChild;
		
		if (type == 'expand')
		{
			menuImage.setAttribute('src','http://www.co.shasta.ca.us/images/expand_menu.gif');
		}
		
		else
		{
			menuImage.setAttribute('src','http://www.co.shasta.ca.us/images/arrow_menu.gif');
		}
	}
	catch(err)
	{}
}

function menuExpandCollapse(menuLink)
{
	var menuItem = menuLink.parentNode;
	var menuLink = menuLink.parentNode.childNodes[3];
	
	if (menuLink.style.display == 'none' || menuLink.style.display == '')
	{
		replaceMenuElements(menuItem, 'collapse')
		menuLink.style.display = 'block';
	}
	
	else
	{
		replaceMenuElements(menuItem, 'expand')
		menuLink.style.display = 'none';
	}
}

function readCookie()
{
	var cookieArray = document.cookie.split(';');
	var returnUser = false;
	for(var i=0; i<cookieArray.length; i++)
	{
		if(cookieArray[i].match('returningUser'))
		{
			returnUser = true;
		}
	}
	
	if(returnUser == false)
	{
		serviceModule('searchModule','serviceModule','Shasta County Site Search');
		serviceModule('inspectionsModule','serviceModule','Food Facility Inspections');
		serviceModule('referralModule','serviceModule','Service Referral Guide');
		setCookie('returningUser','active', 365);
	}	
	else
	{
		for(var i=0; i<cookieArray.length; i++)
		{
			if(cookieArray[i].match('customModule'))
			{
				var title = 'Manage Custom Links';
				serviceModule('customModule', 'serviceModule', title);
			}
			else if(cookieArray[i].match('searchModule'))
			{
				var title = 'Shasta County Site Search';
				serviceModule('searchModule', 'serviceModule', title);
			}
			else if(cookieArray[i].match('inspectionsModule'))
			{
				var title = 'Food Facility Inspections';
				serviceModule('inspectionsModule', 'serviceModule', title);
			}
			else if(cookieArray[i].match('referralModule'))
			{
				var title = 'Service Referral Guide';
				serviceModule('referralModule', 'serviceModule', title);
			}
			else if(cookieArray[i].match('incustodyModule'))
			{
				var title = 'In Custody Search';
				serviceModule('incustodyModule', 'serviceModule', title);
			}
		}
	}
	return null;
}

function addModule()
{
	if(document.getElementById('rNav'))
	{
		
		if(addModuleCounter < 1)
		{
			var divContainer = document.getElementById('rNav');
			var addModulePopup = document.createElement('div');
			var divIdName = 'addModulePopup';
			addModulePopup.setAttribute('id',divIdName);

			if(browserPlatform == "Win32" && browserVendor == "Apple Computer, Inc.")
			{
				addModulePopup.innerHTML = '<div id="addModuleHeaderMac"><div class="addModuleTitle">Personalize Your Site</div><div class="addModuleClose"><a href="javascript:;" onclick="closeWindow(\'addModulePopup\')">x</a></div></div><p>Select services to add:<br><a href="javascript:;" onclick="serviceModule(\'inspectionsModule\',\'serviceModule\',\'Food Facility Inspections\')">Food Facility Inspections</a><br><a href="javascript:;" onclick="serviceModule(\'incustodyModule\',\'serviceModule\',\'In Custody Search\')">In Custody Search</a><br><a href="javascript:;" onclick="createCustomService()">Manage Custom Links</a><br><a href="javascript:;" onclick="serviceModule(\'referralModule\',\'serviceModule\',\'Service Referral Guide\')">Service Referral Guide</a><br><a href="javascript:;" onclick="serviceModule(\'searchModule\',\'serviceModule\',\'Shasta County Site Search\')">Shasta County Site Search</a></p>';
				divContainer.appendChild(addModulePopup);
				xMoveTo('addModulePopup', -370, 75);
				xEnableDrag('addModuleHeaderMac', d2OnDragStart, d2OnDrag, null);
				addModuleCounter++;
			}
			
			else if(browserPlatform == "MacIntel" || browserPlatform == "MacPPC")
			{
				addModulePopup.innerHTML = '<div id="addModuleHeaderMac"><div class="addModuleTitle">Personalize Your Site</div><div class="addModuleClose"><a href="javascript:;" onclick="closeWindow(\'addModulePopup\')">x</a></div></div><p>Select services to add:<br><a href="javascript:;" onclick="serviceModule(\'inspectionsModule\',\'serviceModule\',\'Food Facility Inspections\')">Food Facility Inspections</a><br><a href="javascript:;" onclick="serviceModule(\'incustodyModule\',\'serviceModule\',\'In Custody Search\')">In Custody Search</a><br><a href="javascript:;" onclick="createCustomService()">Manage Custom Links</a><br><a href="javascript:;" onclick="serviceModule(\'referralModule\',\'serviceModule\',\'Service Referral Guide\')">Service Referral Guide</a><br><a href="javascript:;" onclick="serviceModule(\'searchModule\',\'serviceModule\',\'Shasta County Site Search\')">Shasta County Site Search</a></p>';
				divContainer.appendChild(addModulePopup);
				xMoveTo('addModulePopup', -370, 75);
				xEnableDrag('addModuleHeaderMac', d2OnDragStart, d2OnDrag, null);
				addModuleCounter++;
			}
			else
			{
				addModulePopup.innerHTML = '<div id="addModuleHeader"><div class="addModuleTitle">Personalize Your Site</div><div class="addModuleClose"><a href="javascript:;" onclick="closeWindow(\'addModulePopup\')">x</a></div></div><p>Select services to add:<br><a href="javascript:;" onclick="serviceModule(\'inspectionsModule\',\'serviceModule\',\'Food Facility Inspections\')">Food Facility Inspections</a><br><a href="javascript:;" onclick="serviceModule(\'incustodyModule\',\'serviceModule\',\'In Custody Search\')">In Custody Search</a><br><a href="javascript:;" onclick="createCustomService()">Manage Custom Links</a><br><a href="javascript:;" onclick="serviceModule(\'referralModule\',\'serviceModule\',\'Service Referral Guide\')">Service Referral Guide</a><br><a href="javascript:;" onclick="serviceModule(\'searchModule\',\'serviceModule\',\'Shasta County Site Search\')">Shasta County Site Search</a></p>';
				divContainer.appendChild(addModulePopup);
				xMoveTo('addModulePopup', -370, 75);
				xEnableDrag('addModuleHeader', d2OnDragStart, d2OnDrag, null);
				addModuleCounter++;
			}
		}
	}
}

function serviceModule(myId,myClass,title)
{
	var customColumn = "customColumn";

	if(browserPlatform == "MacIntel" || browserPlatform == "MacPPC")
	{
		myClass += "Mac";
		customColumn += "Mac";
	}
	
	if(browserPlatform == "Win32" && browserVendor == "Apple Computer, Inc.")
	{
		myClass += "Mac";
		customColumn += "Mac";
	}
	
	if(serviceCounter < 6)
	{
		if(!document.getElementById(myId))
		{
			var divContainer = document.getElementById('rNav');
			var serviceModule = document.createElement('div');
			
			if(myId == 'customModule')
			{
				if(document.cookie.match('customModule'))
				{
					var cookieArray = document.cookie.split(';');
					for(var i=0; i<cookieArray.length; i++)
					{
						if(cookieArray[i].match('customModule'))
						{
							serviceModule.innerHTML = '<div id="'+myId+'" class="'+myClass+'"><div class="title">Custom Links</div><div class="close"><a href="javascript:;" onclick="closeModule(\'customModule\')">x</a></div><div id="'+customColumn+'1"></div><div id="'+customColumn+'2"></div></div>';
							divContainer.appendChild(serviceModule);
								
							var cookieArray = cookieArray[i].split('=');
							var brokenCookie = cookieArray[1].split('&');
							
							if(brokenCookie != 'undefined')
							{
								for(j=0; j<brokenCookie.length; j+=2)
								{
									var linkName = brokenCookie[j];
									var url = brokenCookie[j+1];
									
									if(!url.match('http://'))
									{
										url = "http://"+url;
									}
									
									if(customLinks <= 3)
									{
										if(url.match('co.shasta.ca.us'))
										{
											document.getElementById(customColumn+'1').innerHTML += '<a href="'+url+'">'+linkName+'</a>';
											customLinks++;
										}
										else
										{
											document.getElementById(customColumn+'1').innerHTML += '<a href="'+url+'" target="_blank">'+linkName+'</a>';
											customLinks++;
										}
									}
									else if((customLinks > 3) && (customLinks < 8))
									{
										if(url.match('co.shasta.ca.us'))
										{
											document.getElementById(customColumn+'2').innerHTML += '<a href="'+url+'">'+linkName+'</a>';
											customLinks++;
										}
										else
										{
											document.getElementById(customColumn+'2').innerHTML += '<a href="'+url+'" target="_blank">'+linkName+'</a>';
											customLinks++;
										}
									}
								}
							}
							else
							{
								closeModule('customModule');
								closeModule('customContainer');
							}
						}
					}
					
					if(browserVendor == "Camino")
					{
						var moduleInput = document.getElementById('customModule').getElementsByTagName('input');
						moduleInput[0].className = "textboxCamino";
						document.getElementById('btnSearch').className = "moduleSubmitCamino";
					}	
				}
			}
			
			if(myId == 'searchModule')
			{
				serviceModule.innerHTML = '<div id="'+myId+'" class="'+myClass+'"><div class="title">'+title+'</div><div class="close"><a href="javascript:;" onclick="closeModule(\''+myId+'\')">x</a></div><form method="get" action="/sitesearch.asp"><label class="moduleLabel">Search Shasta County:</label><input type="text" name="search" maxlength="255" class="textbox"/><input type="submit" id="btnSearch" class="moduleSubmit" value="Search"/></form></div>';
				divContainer.appendChild(serviceModule);
				
				if(browserVendor == "Camino")
				{
					var moduleInput = document.getElementById('searchModule').getElementsByTagName('input');
					moduleInput[0].className = "textboxCamino";
					document.getElementById('btnSearch').className = "moduleSubmitCamino";
				}
				
				setCookie(myId, 'active', 365);
				serviceCounter++;
			}
			else if(myId == 'inspectionsModule')
			{
				var label = 'Facility Name:';
				serviceModule.innerHTML = '<div id="'+myId+'" class="'+myClass+'"><div class="title">'+title+'</div><div class="close"><a href="javascript:;" onclick="closeModule(\''+myId+'\')">x</a></div><form action="http://www.co.shasta.ca.us/EHI/frmPubInspViol.aspx" method="get" runat="server"><label class="moduleLabel">'+label+'</label><input class="textbox" type="text" name="search"><input type="submit" value="Search" id="btnSearch" class="moduleSubmit"></form></div>';
				divContainer.appendChild(serviceModule);
				
				if(browserVendor == "Camino")
				{
					var moduleInput = document.getElementById('inspectionsModule').getElementsByTagName('input');
					moduleInput[0].className = "textboxCamino";
					document.getElementById('btnSearch').className = "moduleSubmitCamino";
				}
				
				setCookie(myId, 'active', 365);
				serviceCounter++;
			}
			else if(myId == 'referralModule')
			{
				var label = 'Subject:';
				serviceModule.innerHTML = '<div id="'+myId+'" class="'+myClass+'"><div class="title">'+title+'</div><div class="close"><a href="javascript:;" onclick="closeModule(\''+myId+'\')">x</a></div><form action="http://www.co.shasta.ca.us/ReferralLookup2/frmReferralGuideLookup.aspx" method="get" runat="server"><label class="moduleLabel">'+label+'</label><input class="textbox" type="text" name="search"><input type="submit" value="Search" id="btnSearch" class="moduleSubmit"></form></div>';
				divContainer.appendChild(serviceModule);
				
				if(browserVendor == "Camino")
				{
					var moduleInput = document.getElementById('referralModule').getElementsByTagName('input');
					moduleInput[0].className = "textboxCamino";
					document.getElementById('btnSearch').className = "moduleSubmitCamino";
				}
				
				setCookie(myId, 'active', 365);
				serviceCounter++;
			}
			else if(myId == 'incustodyModule')
			{
				var label = 'Inmate Search:';
				serviceModule.innerHTML = '<div id="'+myId+'" class="'+myClass+'"><div class="title">'+title+'</div><div class="close"><a href="javascript:;" onclick="closeModule(\''+myId+'\')">x</a></div><form action="http://www.co.shasta.ca.us/html/In_Custody/incustody.aspx" method="get" runat="server"><label class="moduleLabel">'+label+'</label><input class="textbox" type="text" name="search"><input type="submit" value="Search" id="btnSearch" class="moduleSubmit"></form></div>';
				divContainer.appendChild(serviceModule);
				
				if(browserVendor == "Camino")
				{
					var moduleInput = document.getElementById('referralModule').getElementsByTagName('input');
					moduleInput[0].className = "textboxCamino";
					document.getElementById('btnSearch').className = "moduleSubmitCamino";
				}
				
				setCookie(myId, 'active', 365);
				serviceCounter++;
			}
		}
	}
}

function createCustomService()
{
	if(document.getElementById('rNav'))
	{
		
		if(customServiceCounter < 1)
		{
			var divContainer = document.getElementById('rNav');
			var customServicePopup = document.createElement('div');
			var divIdName = 'customServicePopup';
			customServicePopup.setAttribute('id',divIdName);
			if(browserPlatform == "MacIntel" || browserPlatform == "MacPPC")
			{
				customServicePopup.innerHTML = '<div id="customServiceHeaderMac"><div class="customServiceTitle">Manage Custom Links</div><div class="customServiceClose"><a href="javascript:;" onclick="closeWindow(\'customServicePopup\')">x</a></div></div><div><form id="frmCustomService" name="customService"><div id="addLink">Add Link<br /><label class="lblLinkName">Link Name:</label><input id="txtLinkName" type="text" name="link"><label class="lblUrl">URL:</label><input id="txtUrl" type="text" name="url" value="http://"></div><div id="removeLinksMac"><h6>Remove Links</h6><div id="removeColumn1"></div><div id="removeColumn2"></div></div><div id="manageBtns"><input type="submit" value="Add Link" class="moduleSubmit btnAdd" onclick="addLink()"><input type="submit" value="Remove Links" class="moduleSubmit btnRemove" onclick="removeLinks()"></div></form></div>';
				divContainer.appendChild(customServicePopup);
				getLinks();
				xMoveTo2('customServicePopup', -478, 90);
				xEnableDrag2('customServiceHeaderMac', d2OnDragStart2, d2OnDrag2, null);
				customServiceCounter++;
			}
			else
			{
				customServicePopup.innerHTML = '<div id="customServiceHeader"><div class="customServiceTitle">Manage Custom Links</div><div class="customServiceClose"><a href="javascript:;" onclick="closeWindow(\'customServicePopup\')">x</a></div></div><div><form id="frmCustomService" name="customService"><div id="addLink">Add Link<br /><label class="lblLinkName">Link Name:</label><input id="txtLinkName" type="text" name="link"><label class="lblUrl">URL:</label><input id="txtUrl" type="text" name="url" value="http://"></div><div id="removeLinks">Remove Links<div id="removeColumn1"></div><div id="removeColumn2"></div></div><div id="manageBtns"><input type="submit" value="Add Link" class="moduleSubmit btnAdd" onclick="addLink()"><input type="submit" value="Remove Links" class="moduleSubmit btnRemove" onclick="removeLinks()"></div></form></div>';
				divContainer.appendChild(customServicePopup);
				getLinks();
				xMoveTo2('customServicePopup', -478, 90);
				xEnableDrag2('customServiceHeader', d2OnDragStart2, d2OnDrag2, null);
				customServiceCounter++;
			}
		}
	}
}

function addLink()
{
	var myId = 'customModule';
	var linkName = document.customService.link.value;
	var url = document.customService.url.value;
	
	if((linkName == '') || (url == ''))
	{
		alert("A Link Name and a URL are required.");
	}
	else
	{
		var newValue = linkName + '&' + url;
	
		if(document.cookie.match('customModule'))
		{
			if(customLinks < 8)
			{
				addCookieLink(myId,linkName,url);
			}
			else
			{
				alert("At this time you can only have 8 custom links");
			}
		}
		else
		{
			setCookie(myId,newValue,365);
		}
	}
}

function addCookieLink(myId,linkName,url)
{
	var cookieArray = document.cookie.split(';');
	var newValue = "";
	for(var i=0; i<cookieArray.length; i++)
	{
		if(cookieArray[i].match('customModule'))
		{
			var bc2 = cookieArray[i].split('=');
			newValue = bc2[1]+'&'+linkName + '&' + url;
			setCookie(myId,newValue,365);
		}
	}
}

function getLinks()
{
	var htmlString = "";
	var removeLinksCounter = 0;
	if(document.cookie.match('customModule'))
	{
		var cookieArray = document.cookie.split(';');
		for(var i=0; i<cookieArray.length; i++)
		{
			if(cookieArray[i].match('customModule'))
			{		
				var cookieArray = cookieArray[i].split('=');
				var brokenCookie = cookieArray[1].split('&');
				for(j=0; j<brokenCookie.length; j+=2)
				{
					var linkName = brokenCookie[j];
					
					if(removeLinksCounter <= 3)
					{
						document.getElementById('removeColumn1').innerHTML += '<input type="checkbox" name="'+linkName+'" class="linkChkBox">'+linkName+'<br />';
						removeLinksCounter++;
					}
					else if((removeLinksCounter > 3) && (removeLinksCounter < 8))
					{
						document.getElementById('removeColumn2').innerHTML += '<input type="checkbox" name="'+linkName+'" class="linkChkBox">'+linkName+'<br />';
						removeLinksCounter++;
					}
				}
			}
		}
	}
	return htmlString;
}

function removeLinks()
{
	var removeLinks = "removeLinks";
	
	if(browserPlatform == "MacIntel" || browserPlatform == "MacPPC")
	{
		removeLinks += "Mac";
	}

	removeLinks = document.getElementById(removeLinks);
	removeLinks = removeLinks.getElementsByTagName('Input');
	var newValue;
	var removeChecked = false;
	
	for(var i=0; i<removeLinks.length; i++)
	{
		if(document.cookie.match('customModule'))
		{
			var cookieArray = document.cookie.split(';');
			for(var k=0; k<cookieArray.length; k++)
			{
				if(cookieArray[k].match('customModule'))
				{		
					var cookieArray = cookieArray[k].split('=');
					var brokenCookie = cookieArray[1].split('&');
				}
			}
		}
		
		if(removeLinks[i].checked)
		{
			for(var j=0; j<brokenCookie.length; j++)
			{
				if(brokenCookie[j].match(removeLinks[i].name))
				{
					var removeLinkName = brokenCookie[j];
					var removeUrl = brokenCookie[j+1];
					
					brokenCookieJoined = brokenCookie.join('&');
					
					var tempValue = brokenCookieJoined.replace(removeLinkName+'&','');
					newValue = tempValue.replace(removeUrl,'');
					
					if(newValue.charAt(0) == '&')
					{
						newValue = newValue.substr(1,newValue.length);
					}
					if(newValue.charAt(newValue.length-1) == '&')
					{
						newValue = newValue.substr(0,newValue.length-1);
					}
					if(newValue.match('&&'))
					{
						newValue = newValue.replace('&&','&');
					}
					customLinks--;
					if(newValue == '')
					{
						closeModule('customModule');
					}
					else
					{
						setCookie('customModule',newValue,365);
					}
				}
			}
		}
	}
}

function closeModule(myId)
{	
	var d = document.getElementById(myId);
	serviceCounter=0;
	addModuleCounter=0;
	customServiceCounter=0;
	
	var removeBox = confirm("Click OK to remove module or Cancel to keep module.");
	
	if(removeBox == true)
	{
		d.parentNode.removeChild(d);
		
		if(myId == 'customModule')
		{
			customLinks = 0;
		}
		
		setCookie(myId, '', -1);
	}
}

function closeWindow(myId)
{
	var d = document.getElementById(myId);
	d.parentNode.removeChild(d);
	
	customServiceCounter=0;
	addModuleCounter=0;
}

function setCookie(myId, value, days)
{
	if(days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = ";expires="+date.toGMTString();
	}
	else
	{
		expires="";
	}
	document.cookie = myId+"="+value+expires+";path=/";
}

function pageChanges()
{
	if(!document.getElementById('contentcontainer_extra_wide'))
	{
		/* Hide 'Go' Button */
		document.getElementById('servNav').style.display = 'none';
		/*document.getElementById('deptNav').style.display = 'none';*/
		document.getElementById('howNav').style.display = 'none';
		
		/* Adjust Widths */
		document.getElementById('services').style.width = 195+"px";
		document.getElementById('how').style.width = 195+"px";
		/*document.getElementById('departments').style.width = 195+"px";*/
		
		if(browserName == "Microsoft Internet Explorer")
		{
			/* IE Placement Change */
			document.getElementById('frmCountyServices').style.margin = 2+"px "+0;
			/*document.getElementById('frmCountyDepartments').style.margin = 2+"px "+0;*/
			document.getElementById('frmCountyHowDoI').style.margin = 2+"px "+0;
			
			if(!window.XMLHttpRequest)
			{
				document.getElementById('serviceNav').style.margin = 6+"px "+0+" "+22+"px "+0;
			}
			else
			{
				var ua = navigator.userAgent;
				var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
				var result = re.exec(ua);

        		if (result[0] == "MSIE 8.0")
				{
					var hrArray = document.getElementById('serviceNav').getElementsByTagName('hr');
					for (var h = 0; h <= hrArray.length; h++)
					{
						hrArray[h].style.height = 0;
					}
				}
				else
				{
					document.getElementById('serviceNav').style.margin = 9+"px "+0+" "+27+"px "+0;
				}
			}
		}
		
		else if(browserName == 'Opera')
		{
			var operaMenuImage = document.getElementsByTagName('img');
			for (var i = 0; i <= operaMenuImage.length; i++)
			{
				if (operaMenuImage[i].className == 'menuImage')
				{
					operaMenuImage[i].style.position = 'relative';
					operaMenuImage[i].style.top = '0';
			
					operaMenuImage[i].parentNode.style.position = 'absolute';
				}
			}
		}
		
		else if(browserPlatform == "MacIntel" || browserPlatform == "MacPPC")
		{	
			document.getElementById('serviceNav').style.margin = "4px 0 24px 0";
			document.getElementById('frmCountyServices').style.margin = "3px 0";
			/*document.getElementById('frmCountyDepartments').style.margin = "3px 0";*/
			document.getElementById('frmCountyHowDoI').style.margin = "3px 0";
			document.getElementById('pageNav').style.margin = "50px 0 0";
		}
		
		else if((navigator.platform == 'Win32') && (navigator.vendor == 'Apple Computer, Inc.'))
		{
			document.getElementById('serviceNav').style.margin = "4px 0 24px 0";
			document.getElementById('frmCountyServices').style.margin = "3px 0";
			/*document.getElementById('frmCountyDepartments').style.margin = "3px 0";*/
			document.getElementById('frmCountyHowDoI').style.margin = "3px 0";
			document.getElementById('pageNav').style.margin = "50px 0 0";
		}
		
		/* Show Add Module Button */
		if (document.getElementById('addModuleButton'))
		{
			document.getElementById('addModuleButton').style.display = 'block';
		}
	}
}

function d2OnDragStart(ele, mx, my)
{
	xZIndex('addModulePopup', highZ++);
}

function d2OnDragStart2(ele, mx, my)
{
	xZIndex2('customServicePopup', highZ++);
}

function d2OnDrag(ele, mdx, mdy)
{
	xMoveTo('addModulePopup', xLeft('addModulePopup') + mdx, xTop('addModulePopup') + mdy);
}

function d2OnDrag2(ele, mdx, mdy)
{
	xMoveTo2('customServicePopup', xLeft('customServicePopup') + mdx, xTop('customServicePopup') + mdy);
}

function redirect(select)
{
	var selectedAnchor = select.value;
	if (selectedAnchor!=0)
	return location.href = selectedAnchor;
}

function getResults()
{
	var searchTerm = document.frmSearch.q.value;
	alert(searchTerm);
	
	xmlhttp = new XMLHttpRequest();
	
	xmlhttp.open("GET", "../aspx/getResults.asp?url=" + searchTerm, true);
}