// JavaScript Document

var thePath = '/'; // This should change to '/' or path to locations pages before deploying on portsamerica.com 


// Evaluates current url and compares it's path with the value of all OPTION elements in the locations SELECT list
// If there is a match it sets the value of the SELECT to that OPTION
// Call function from window.onload

function setSelected()
{
	var el = document.getElementById('locations_select');
	
	for(var i=0;i<el.childNodes.length;i++)
	{
		 if (el.childNodes[i].nodeName=="OPTGROUP" ) 
		 {
			 for(var j=0;j<el.childNodes[i].childNodes.length;j++)
			 {
			 	if (el.childNodes[i].childNodes[j].nodeName=="OPTION" && thePath+el.childNodes[i].childNodes[j].value==location.pathname) 
				{
			 		el.value = el.childNodes[i].childNodes[j].value;
				}
		 	  }
		 }
	}
	
}



// Takes an OPTION element passed to it and navigates the browser to url contained in the value property of that OPTION
// Call function from onclick method of FORM BUTTON element

function openURL(theSelect)
{ 
	// grab index number of the selected option
	var selInd = document.getElementById(theSelect).selectedIndex; 
		
	// get value of the selected option
	var goURL = document.getElementById(theSelect).options[selInd].value;
	
	if(goURL!='' && goURL!='#')
	{
	// redirect browser to the grabbed value (here a URL)
		top.location.href = goURL; 
	}else{
		document.getElementById(theSelect).focus();
	}
}
		
function openURLInNewWindow(theSelect)
{
	// grab index number of the selected option
	var selInd = document.getElementById(theSelect).selectedIndex; 
		
	// get value of the selected option
	var goURL = document.getElementById(theSelect).options[selInd].value;
	
	if(goURL!='' && goURL!='#')
	{
	// redirect browser to the grabbed value (here a URL)
	   window.open (goURL, "_blank"); 
	}else{
		document.getElementById(theSelect).focus();
	}
}