//Thse 4 functions ensure that a user can't submit both an address and a placename.
//They do this by clearing out the other box(es) when they gain focus.
function ClearOriginAddress(){
	document.getElementById("txtOriginStreet").value="";
	document.getElementById("txtOriginCityStateOrZip").value="";
}


function ClearOriginPlace(){
	document.getElementById("txtOriginPlace").value="";
}

function ClearDestinationAddress(){
	document.getElementById("txtDestinationStreet").value="";
	document.getElementById("txtDestinationCityStateOrZip").value="";
}


function ClearDestinationPlace(){
	document.getElementById("txtDestinationPlace").value="";
}

function ShowTables(){
		//if we switch from an auto search to a truck search we need to clear the checkboxes
		//so the user doesn't inadvertently search on something they didn't intend on
	var i=0;
	for (i; i<document.SearchForm.length; i++) {
		if (document.SearchForm[i].type == 'checkbox') {
			document.SearchForm[i].checked = false; 
		} 
	}
	
		var sel=document.SearchForm.SearchType.value;
		switch(sel){
			case "AutoStation":
				ShowAutoStation();
			break;
			
			case "AutoRoute":
				ShowAutoRoutePlanner();
			break;
			
			case "Truckstop":
				ShowTruckStop();
			break;
			
			default:
				ShowSimpleSearch(sel);
			break;
		}
	}
	
	function ShowSimpleSearch(s){
		//this is what is shown on initial entry
		document.getElementById("tblOriginAddress").style.display="";
		document.getElementById("tblDestinationAddress").style.display="none";
		document.getElementById("tblResultPreferences").style.display="";
		document.getElementById("tblAutoAttributes").style.display="none";
		document.getElementById("tblTruckAttributes").style.display="none";
		switch(s){
			case "AutoATM":
				document.getElementById("chkATM").checked=true;
			break;
			
			case "AutoCStore":
				document.getElementById("chkCStore").checked=true;
			break;
			
			case "AutoCare":
				document.getElementById("chkAutoCare").checked=true;
			break;
			
			case "AutoWash":
				document.getElementById("chkCarWash").checked=true;
			break;
			
			case "AutoDiesel":
				document.getElementById("chkDiesel").checked=true;
			break;
			
		}
		//document.getElementById("SearchText").innerText=s;
	}
	function PickInitialSearchForm(){
		
		var QString=window.location.search;
		
		QString=(QString.length>0)?QString.toUpperCase():QString;
		
		if (QString.indexOf("ROUTE")>0){
			document.getElementById("SearchType").selectedIndex=1;
			ShowAutoRoutePlanner();
			return;
		}
		
		if (QString.indexOf("TRUCK")>0){
			document.getElementById("SearchType").selectedIndex=2;
			ShowTruckStop();
			return;
		}
		
		//if we got down here then default to auto station search
		//document.getElementById("SearchType").selectedIndex=0;
		ShowAutoStation();
	}
	
	function ShowAutoStation(){
		//this is what is shown on initial entry
		//document.getElementById("tblOriginAddress").style.display="";
		//document.getElementById("ShowTables").style.display="none";
		//document.getElementById("tblResultPreferences").style.display="";
		//document.getElementById("tblAutoAttributes").style.display="";
		//document.getElementById("tblTruckAttributes").style.display="none";
		
		document.getElementById("tblOriginAddress").style.display="";
                document.getElementById("tblDestinationAddress").style.display="none";
		document.getElementById("tblAutoAttributes").style.display="";
                document.getElementById("tblTruckAttributes").style.display="none";

	}
		
	function ShowAutoRoutePlanner(){
		document.getElementById("tblOriginAddress").style.display="";
		document.getElementById("tblDestinationAddress").style.display="";
		document.getElementById("tblResultPreferences").style.display="none";
		document.getElementById("tblAutoAttributes").style.display="none";
		document.getElementById("tblTruckAttributes").style.display="none";

	}
	
	function ShowTruckStop(){
		document.getElementById("tblOriginAddress").style.display="";
		document.getElementById("tblDestinationAddress").style.display="none";
		document.getElementById("tblResultPreferences").style.display="";
		document.getElementById("tblAutoAttributes").style.display="none";
		document.getElementById("tblTruckAttributes").style.display="";

	}
	
	
	function showhide(id){ 
		if (document.getElementById){ 
			obj = document.getElementById(id); 
			if (obj.style.display == "none"){ 
				obj.style.display = ""; 
			} else { 
			obj.style.display = "none"; 
			} 
		} 
	} 
	
	
	function hideIfNotShow()
	{
		//document.getElementById("TopArticleErrorMessag").style.display = "none";
		//document.all.TopArticleErrorMessag.style.display="none"; 
		window.TopArticleErrorMessag.style.display = "none";
		window.MiddleArticleErrorMessag.style.display = "none";
		window.BottomArticleErrorMessag.style.display = "none";
		window.TopRandArticleErrorMessag.style.display = "none";
		window.MiddleRandArticleErrorMessag.style.display = "none";
		window.BottomRandArticleErrorMessag.style.display = "none";
		
		

		if(window.TopArticleNotShow)
			{
				window.TopArticleNotShow.style.display = "none";
				window.TopArticleErrorMessag.style.display = "block";	
			}
		if(window.MiddleArticleNotShow)
			{
				window.MiddleArticleNotShow.style.display = "none";
				window.MiddleArticleErrorMessag.style.display = "block";	
			}
		if(window.BottomArticleNotShow)
			{
				window.BottomArticleNotShow.style.display = "none";
				window.BottomArticleErrorMessag.style.display = "block";	
			}
		if(window.TopRandArticleNotShow)
			{
				window.TopRandArticleNotShow.style.display = "none";
				window.TopRandArticleErrorMessag.style.display = "block";	
			}
		if(window.MiddleRandArticleNotShow)
			{
				window.MiddleRandArticleNotShow.style.display = "none";
				window.MiddleRandArticleErrorMessag.style.display = "block";	
			}
		if(window.BottomRandArticleNotShow)
			{
				window.BottomRandArticleNotShow.style.display = "none";
				window.BottomRandArticleErrorMessag.style.display = "block";	
			}			
	}