function showLayer(whichLayer){  
	var elem, vis;  
	if( document.getElementById ) // this is the way the standards work    
	elem = document.getElementById( whichLayer );  
	else if( document.all ) // this is the way old msie versions work      
	elem = document.all[whichLayer];  
	else if( document.layers ) // this is the way nn4 works    
	elem = document.layers[whichLayer];  
	vis = elem.style;  // if the style.display value is blank we try to figure it out here  
	vis.display = 'block'; 
} 

function hideLayer(whichLayer){  
	var elem, vis;  
	if( document.getElementById ) // this is the way the standards work    
	elem = document.getElementById( whichLayer );  
	else if( document.all ) // this is the way old msie versions work      
	elem = document.all[whichLayer];  
	else if( document.layers ) // this is the way nn4 works    
	elem = document.layers[whichLayer];  
	vis = elem.style;  // if the style.display value is blank we try to figure it out here  
	vis.display = 'none'; 
} 
 
function toggleLayer(whichLayer){  
	var elem, vis;  
	if( document.getElementById ) // this is the way the standards work    
	elem = document.getElementById( whichLayer );  
	else if( document.all ) // this is the way old msie versions work      
	elem = document.all[whichLayer];  
	else if( document.layers ) // this is the way nn4 works    
	elem = document.layers[whichLayer];  
	vis = elem.style;  // if the style.display value is blank we try to figure it out here  
	if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)    
	vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';  
	vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

function toggleLayers(whichLayers){
    var thelayers = whichLayers.split(",");
	var numberoflayers = thelayers.length;
	for (var i=0;i<numberoflayers;i++){
		toggleLayer(thelayers[i]);
	}
} 

function toggleButton(buttonSpan) {
	var currentClassName = buttonSpan.className;
	if(currentClassName == 'depressed') 
		buttonSpan.className='raised';
	else
	    buttonSpan.className='depressed';
}


function showContent(section){
	//hide all sections
    document.getElementById('cityguidecontent').style.display='none';
    document.getElementById('thingstoseeanddocontent').style.display='none';
	document.getElementById('restaurantscontent').style.display='none';
	document.getElementById('hotelscontent').style.display='none';
	document.getElementById('mapcontent').style.display='none';
	document.getElementById('weathercontent').style.display='none';
	document.getElementById('photoscontent').style.display='none';
	document.getElementById('videoscontent').style.display='none';
	 
      //unhighlight all navigation buttons	
 	document.getElementById('cityguidenav').style.backgroundColor='#cccccc';      
	document.getElementById('thingstoseeanddonav').style.backgroundColor='#cccccc';
	document.getElementById('restaurantsnav').style.backgroundColor='#cccccc';
	document.getElementById('hotelsnav').style.backgroundColor='#cccccc';
	document.getElementById('mapnav').style.backgroundColor='#cccccc';
	document.getElementById('weathernav').style.backgroundColor='#cccccc';
	document.getElementById('photosnav').style.backgroundColor='#cccccc';
	document.getElementById('videosnav').style.backgroundColor='#cccccc';

	//show selected section and highlight the navigation button of the selected section
	document.getElementById(section+'content').style.display='block';
	document.getElementById(section+'nav').style.backgroundColor='white';
}
 
function hideAlertWindow(){
  document.getElementById("alertWindow").style.visibility="hidden";
  
}

function showAlertWindow(text){
  document.getElementById("alertWindowText").innerHTML = text; 
  document.getElementById("alertWindow").style.visibility = "visible";
}
 
function loadFileIntoLayer(url,layer)
{
  // 
  //document.getElementById(layer).innerHTML=content;
}

function getXMLHttpRequestInstance() {
    var httpRequest;
    if (window.XMLHttpRequest) { // Mozilla, Safari, ...
        httpRequest = new XMLHttpRequest();
        if (httpRequest.overrideMimeType) {
            httpRequest.overrideMimeType('text/xml');
        }
    } 
    else if (window.ActiveXObject) { // IE
        try {
        	httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch (e) {
        	try {
            	httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
         	} 
            catch (e) {}
             }
        }
    if (!httpRequest) {
        alert('Giving up :( Cannot create an XMLHTTP instance');
        return false;
    }
    return httpRequest;
}

function loadURLIntoLayer(url,layer)
{
    //alert("url="+url);
    httpRequest = getXMLHttpRequestInstance();
    httpRequest.onreadystatechange = function() { handleHttpResponse(httpRequest,layer); };
    httpRequest.open('GET', url, true);
    httpRequest.send('');
}


function handleHttpResponse(httpRequest,layer) {
	//alert("httpRequest.readyState="+httpRequest.readyState);
	//alert("httpRequest.status="+httpRequest.status);
	if (httpRequest.readyState == 4) {
	    if (httpRequest.status == 200) {
          document.getElementById(layer).innerHTML = httpRequest.responseText;
          //alert(httpRequest.responseText);
	    } else {
	         alert('Oops. We encountered a problem\n' + 
	        	   'while trying provide this service\n' +
	        	   'to you.\n\n' +
	        	   'javascripts.js>\n' +
	        	   'handleHttpResponse.httpRequest.status=\n' +
	        	   httpRequest.status);
	       document.location.href('report_problem.jsp'); 	   
	    }
	}

}

 //To initialize the slider control call this function on BODY onload event 
function loadSliderControl()
{
  window.onload = function() {
  var el = document.getElementById("speed2");
  el.onDragStart = function() {
	in_elem = document.getElementById('speed2in').className = "move2ondrag";
	in_elem = document.getElementById('speed2').className = "sliderondrag";
  }
  el.onDrag = function() {
	var value_elem = document.getElementById('speed2_value');
	value_elem.innerHTML = Math.round(Number(this.value)) + ' miles';
  };
  el.onDragStop = function() {
	in_elem = document.getElementById('speed2in').className = "move2";
	in_elem = document.getElementById('speed2').className = "slider";
	//x_sajax_update('speed_2', this.value, confirm);
  }
  form_slider(el, '100');
  }
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}  

function Querystring(qs) { // optionally pass a querystring to parse
	this.params = {};
	this.get=Querystring_get;
	
	if (qs == null);
		qs=location.search.substring(1,location.search.length);

	if (qs.length == 0) 
		return;

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&'); // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i=0;i<args.length;i++) {
		var pair = args[i].split('=');
		var name = unescape(pair[0]);
		
		var value = (pair.length==2)
			? unescape(pair[1])
			: name;
		
		this.params[name] = value;
	}
}

function Querystring_get(key, default_) {
	var value=this.params[key];
	return (value!=null) ? value : default_;
}


function removeAllChildrenFromDOMObject(AnyDOMObject)
{
	if(AnyDOMObject!=null)
	{
		while (AnyDOMObject.firstChild) 
		{
	 		 AnyDOMObject.removeChild(AnyDOMObject.firstChild);
		}
	}
}

function toggleTableElement(tableElementName)
{
	var tableElement = document.getElementById(tableElementName);
	if(tableElement.style.visibility=='visible')
	{
		hideTableElement(tableElementName);
	}
	else
	{
		showTableElement(tableElementName);
	}
}

function hideTableElement(tableElementName)
{
	var tableElement = document.getElementById(tableElementName);
	tableElement.style.visibility='hidden';
}

function showTableElement(tableElementName)
{
	var tableElement = document.getElementById(tableElementName);
	tableElement.style.visibility='visible';
} 

function isCheckboxChecked(checkboxid)
{
	var checked=false;
	var checkbox=document.getElementById(checkboxid);
	if(checkbox.checked) checked=true;
	return checked;
}

function getValueOfSelectedOption(menuid)
{
	var menu = document.getElementById(menuid);
	var value = menu.options[menu.selectedIndex].value;
	return value;
}

function setSelectedOption(menuid,value)
{
	var menu = document.getElementById(menuid);
	var options = menu.options;
	for(var i=0;i<options.length;i++)
	{
		//alert('options[i].value='+options[i].value);
		if(options[i].value==value)
			options[i].selected = true;
	}
}

function findLocation() 
{
	var city = document.locationSearchForm.city.value;
	//city_uid is set by autocom.js getSelectionId();
	var cityUID = document.locationSearchForm.city_uid.value; 
	if(cityUID!='')	
		document.location.href="planner.jsp?city="+city+"&cityUID="+cityUID;
}

/**
 * 
 * @param divName - the div where the wait indicator should be displayed
 * @return
 */
function showWaitIndicator(divName)
{
	var adiv = document.createElement("DIV");
	adiv.style.textAlign='center';
	adiv.style.padding='10px';
	var text = document.createTextNode("Loading search results. Please wait...");
	var tagB = document.createElement("B");
	tagB.appendChild(text);
	adiv.appendChild(tagB);
	adiv.appendChild(document.createElement("BR"));
	var tagIMG = document.createElement("IMG");
	tagIMG.setAttribute("src","img/tripposlogoanimatedglobe.gif");
	adiv.appendChild(tagIMG);
	tagIMG = tagIMG.cloneNode(false);
	adiv.appendChild(tagIMG);
	tagIMG = tagIMG.cloneNode(false);
	adiv.appendChild(tagIMG);
	var theDiv = document.getElementById();
	removeAllChildrenFromDOMObject(theDiv);
	theDiv.appendChild(adiv);
}

//stores a value in the J2EE session
function storeSessionVariable(key, value)
{

	if (typeof XMLHttpRequest != "undefined") {
       req = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
       req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	req.open("GET", 'TripposServlet?command=storeSessionVariable&key='+key+'&value='+value,true);
	req.send(null);	
}