aGlobal = 1;
function checkExemp(tID,city,type){
/*var pos=new Array(2);	
	pos=findPos(tID);
	var cleft=pos[0];
	var ctop=pos[1];
	*/
		var sgObj=document.getElementById(tID);
	/*	
		sgObj.style.display="block";
		sgObj.style.left=cleft;
		sgObj.style.top=ctop+19;
		*/

		var http=getHTTPObject();
		
		var url='doCheckExemp.cfm?nc='+Math.random()+'&q='+city+'&type='+type;

		http.open("GET", url, false);
		http.send(null);
		sgObj.innerHTML="<span align='left' class='smGrayBoldText'>Loading...</span>";
		//sgObj.innerHTML=http.responseText;
		var sugw=http.responseText;
		
		sgObj.innerHTML=sugw;
}



function resetRow(){
	aGlobal = 1;
}
function listView()
{
	hideDiv('divMap');
	hideDiv('divListing');
	hideDiv('divPicture');

	showDiv('divList');
}

function mapView()
{
	hideDiv('divList');
	hideDiv('divListing');
	hideDiv('divPicture');

	showDiv('divMap');
}
function doPubTab()
{
	toggleDiv('divPub');toggleDiv('divPriv');showDiv('divShowPrivs');hideDiv('divShowPubs');		
}

function doPrivTab(){
	toggleDiv('divPub');toggleDiv('divPriv');showDiv('divShowPubs');hideDiv('divShowPrivs');	
}



function setTab(activeTab,activeDiv)
{
	changeClass('tabListings','tabNormal');
	changeClass('tabMap','tabNormal');
	//changeClass('tabPicture','tabNormal');

	hideDiv('divMap');
	hideDiv('divList');
	hideDiv('divListing');
	hideDiv('divPicture');

	changeClass(activeTab,'tabActive');
	showDiv(activeDiv);
}

function setTab2(activeTab,activeDiv)
{
	changeClass('tabMap','tabNormal');
	changeClass('tabList','tabNormal');
	

	hideDiv('divMap');
	hideDiv('divList');
	hideDiv('divPicture');

	changeClass(activeTab,'tabActive');
	showDiv(activeDiv);
}

function doAjaxLoaders()
{
	toggleDiv('working');
	toggleDiv('notWorking');
	toggleDiv('searching');
	toggleDiv('notSearching');
	toggleDiv('divCourseList');
	toggleDiv('divCourseLoading');
	
	toggleDiv('divListNotLoading');
	toggleDiv('divListLoading');
	
	toggleDiv('divPictureNotLoading');
	toggleDiv('divPictureLoading');

}

function doShowMapDetails(mlnum)
{
	var sgObj=document.getElementById('divMapDetails');
	//toggleDiv('divLoading');
	
	sgObj.innerHTML='<br><div class="descLabel"><img src="img/loadRound.gif"></div><br><br>';
	var http=getHTTPObject();
	var url="doHomesPictureView.cfm?mlnum=" +mlnum+ "&nc="+Math.random()+"&sortOrder="+"none";
	http.open("GET", url, true);
	http.send(null);
	http.onreadystatechange = function(){
			if (http.readyState == 4) {
				var allHTML=http.responseText;
				sgObj.innerHTML=allHTML;
				//toggleDiv('divLoading');
			}
		}
	
}

function doPictureList(mapkey,sortOrder)
{
	var sgObj=document.getElementById('divPicture');
	toggleDiv('divLoading');
	sgObj.innerHTML='<br><div class="descLabel" style="width:948px">Loading...</div><br><br>';
	var http=getHTTPObject();
	var url="doHomesPictureView.cfm?mapkey=" +mapkey+ "&nc="+Math.random()+"&sortOrder="+sortOrder;
	http.open("GET", url, true);
	http.send(null);
	http.onreadystatechange = function(){
			if (http.readyState == 4) {
				var allHTML=http.responseText;
				sgObj.innerHTML=allHTML;
				toggleDiv('divLoading');
			}
		}
}

function refreshList()
{
	doAjaxLoaders();
	
	var varType = 'All';
	var varHoles = '';
	var varCourse_Name = '';
	if(document.frmSearch.GolfType[1].checked)
	{
		varType = 'private';	
	}else if(document.frmSearch.GolfType[2].checked)
	{
		varType = 'public';	
	}
	if(document.frmSearch.GolfType[1].checked && document.frmSearch.GolfType[2].checked)
	{
		varType = 'All';
	}
	
	
	if(document.frmSearch.Holes[0].checked)
	{
		varHoles = 'All';
	}
	if(document.frmSearch.Holes[3].checked)
	{
		varHoles+='>18,';
	}if(document.frmSearch.Holes[1].checked)
	{
		varHoles += '<18,';	
	}
	if (document.frmSearch.Holes[2].checked)
	{
		varHoles+='=18,';
	}
	
	if(document.frmSearch.Holes[1].checked && document.frmSearch.Holes[2].checked && document.frmSearch.Holes[3].checked)
	{
		varHoles = 'All';
	}
	if(!document.frmSearch.Holes[1].checked && !document.frmSearch.Holes[2].checked && !document.frmSearch.Holes[3].checked)
	{
		varHoles = 'All';
	}
	
	if(document.frmSearch.Course_Name.value != '')
	{
		varCourse_Name = document.frmSearch.Course_Name.value;
		document.frmSearch.Holes[0].checked = true;
		document.frmSearch.Holes[1].checked = false;
		document.frmSearch.Holes[2].checked = false;
		document.frmSearch.Holes[3].checked = false;
		document.frmSearch.GolfType[0].checked = true;
		document.frmSearch.GolfType[1].checked = false;
		document.frmSearch.GolfType[2].checked = false;
		document.frmSearch.Course_Name.value = '';
		varHoles = 'All';
		varType = 'All';
	}else{
		
	}

	var sgObj=document.getElementById('divCourseList');
	var divListView=document.getElementById('divList');
	var divPicView=document.getElementById('divPicture');
	
	var http=getHTTPObject();
	var url="doGetCourseList.cfm?GolfType=" +varType+ "&nc="+Math.random()+"&Holes="+varHoles+"&Course_Name="+varCourse_Name;
	http.open("GET", url, true);
	http.send(null);
	http.onreadystatechange = function(){
		//	handleHttpResponse(http,dyObj);
	
			if (http.readyState == 4) {
				var allHTML=http.responseText;
				var sideBarHTML = http.responseText;
				var listHTML=http.responseText;
				var picHTML=http.responseText;
				
			if(allHTML.indexOf('.startListView') > -1)
		{
			startAt = 0;
			stopAt = allHTML.indexOf('.startListView');
			sideBarHTML = allHTML.substring(startAt,stopAt);
			
			startAt = allHTML.indexOf('.startListView') + 14;
			stopAt = allHTML.indexOf('.endListView');
			listHTML = allHTML.substring(startAt,stopAt);
			
			startAt = allHTML.indexOf('.startPictureView') + 17;
			stopAt = allHTML.indexOf('.endPictureView');
			picHTML = allHTML.substring(startAt,stopAt);
			
			
		
		}
				
				sgObj.innerHTML=sideBarHTML;
				divListView.innerHTML=listHTML;
				divPicView.innerHTML=picHTML;
				doAjaxLoaders();
				/*if(varType == 'private')
					doPrivTab();
				if(varType == 'public')
					doPubTab();
				*/
			}
		}

}

function showSuggestions(e,sObj,tID,boxName,boxID){

	var fin = 0;
	if(e.keyCode == 40)
	{
		aGlobal +=1;
	}else if(e.keyCode == 38)
	{   
		aGlobal -=1;
	}else if (e.keyCode == 13)
	{
		fin = 1;
	}else{
		resetRow();
	}
	
	
	var pos=new Array(2);	
	pos=findPos(sObj);
	var cleft=pos[0]; 
	var ctop=pos[1];
	if(sObj.value.length==0){
		//hide
		hideSuggestions(tID);
	}
	if(sObj.value.length>0){
		var sgObj=document.getElementById(tID);
	
		sgObj.style.display="";
		sgObj.style.left=cleft;
		sgObj.style.top=ctop+19;

		var http=getHTTPObject();
		var url="doGetSuggestions.cfm?term=" +sObj.value+ "&nc="+Math.random()+"&box="+boxName+'&boxID='+boxID+'&divID='+tID+'&aGlobal='+aGlobal+'&fin='+fin;
	
		http.open("GET", url, false);
		http.send(null);
		
		//sgObj.innerHTML=http.responseText;
		var sugw=http.responseText;
		
		//alert(sugw);
		if(sugw.indexOf('qwer,') > -1)
		{
			startAt = sugw.indexOf('qwer,') + 5;
			stopAt = sugw.indexOf('asdf,');
			var name = sugw.substring(startAt,stopAt);

			startAt = stopAt + 5;
			stopAt = sugw.indexOf(',zxcv');
			var name2 = sugw.substring(startAt,stopAt);

			startAt = stopAt + 5;
			stopAt = sugw.indexOf(',1234');
			var mapkey = sugw.substring(startAt,stopAt);

			updateTerm(name,name2);
			hideSuggestions(tID);
			
			window.location="dispDetail.cfm?mapkey=" + mapkey;
		}
		sgObj.innerHTML=sugw;
	}

}
 
function hideSuggestions(tID){
	document.getElementById(tID).style.display="none";	
}

 function getHTTPObject() {
  var xmlhttp;
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
  
  return xmlhttp;
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}
function getHTTPObject() {
  var xmlhttp;
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
  
  return xmlhttp;
}

function updateTerm(targName,val){
	//auto redirect or fill ?

	//var sugTerm=document.getElementById(termDv).innerHTML;
	//var filename =location.pathname.substring(location.pathname.lastIndexOf('/')+1);
	//document.location="showdetail.cfm?sid="+id;
	sugTerm = val;
	sugTerm = trim(sugTerm);
	document.getElementById(targName).value=sugTerm;	
	// example of using trim, ltrim, and rtrim
	//document.formSearch.CAMPUSmit();
}

function updateNameTerm(targName,termDv){
	//auto redirect or fill ?
	var filename =location.pathname.substring(location.pathname.lastIndexOf('/')+1);
	document.location=filename+"?sl_id="+termDv;
	//document.getElementById(targName).value=sugTerm;	
}

///////////////////////////////////////////////////////////////////////   end ajax stuff
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}


function hideDiv(id){
	if (document.getElementById) { // DOM3 = IE5, NS6
		
			document.getElementById(id).style.display = 'none';			
		
	} else { 
		if (document.layers) {	
						
				document.id.display = 'none';
			
		} else {
			
				document.all.id.style.display = 'none';
			
		}
	}
}
function showDiv(id){
	if (document.getElementById) { // DOM3 = IE5, NS6
		
			document.getElementById(id).style.display = 'block';			
			
	} else { 
		if (document.layers) {	
						
				document.id.display = 'block';
			
		} else {
			
				document.all.id.style.display = 'block';
			
		}
	}
}
function toggleDiv(id) { 
	
	if (document.getElementById) { // DOM3 = IE5, NS6
		if (document.getElementById(id).style.display == "none"){
			document.getElementById(id).style.display = 'block';
					
		} else {
			
			document.getElementById(id).style.display = 'none';			
		}	
	} else { 
		if (document.layers) {	
			if (document.id.display == "none"){
				document.id.display = 'block';
				
			} else {
					
				document.id.display = 'none';
			}
		} else {
			if (document.all.id.style.visibility == "none"){
				document.all.id.style.display = 'block';
			} else {
				
				document.all.id.style.display = 'none';
			}
		}
	}
}

function changeClass(aDiv,aClass){
	
	if (document.getElementById) { // DOM3 = IE5, NS6
	
		document.getElementById(aDiv).className = aClass;
	}else {
		if (document.layers) {
			document.aDiv.className = aClass;
		}else{
			document.all.aDiv.className = aClass;
		}
	}
	
}

function cForm(){
		var checkSelected = false;
		var checkCounter = 0;
		
		for (i = 0;  i < document.compareForm.listMLNUM.length;  i++){
			if (document.compareForm.listMLNUM[i].checked){
				checkSelected = true;
				checkCounter = checkCounter + 1;
				}
		}
		if (!checkSelected)	{
			alert("Please select at least one of the listings.");
			
		}
		if (checkCounter > 5){
			alert("You are only allowed to select up to 5 lisitng.\n Please uncheck one or some of your selection in order to select more.");
			
		}
}///end func


function cForm2(){
		var checkSelected = false;
		var checkCounter = 0;
		for (i = 0;  i < document.compareForm2.listMLNUM.length;  i++){
			if (document.compareForm2.listMLNUM[i].checked){
				checkSelected = true;
				checkCounter = checkCounter + 1;
				}
		}
		if (!checkSelected)	{
			alert("Please select at least one of the listings.");
			
		}
		if (checkCounter > 5){
			alert("You are only allowed to select up to 5 lisitng.\n Please uncheck one or some of your selection in order to select more.");
			
		}
}///end func


function compfrmreturn(form, buttonName){
// require that at least one checkbox be checked


		var checkSelected = false;
		var checkCounter = 0;
		
		for (i = 0;  i < document.compareForm.listMLNUM.length;  i++){
			if (document.compareForm.listMLNUM[i].checked){
				checkSelected = true;
				checkCounter = checkCounter + 1;
	
				}
		}
		if (!checkSelected)	{
			alert("Please select at least one of the listings.");
			return false;
			
		}
		if (checkCounter > 5){
			alert("You are only allowed to select up to 5 lisitng.\n Please uncheck one or some of your selection in order to select more.");
			return false;
		}
	//	if(checkSelected && checkCounter <= 5 ){
			
			if(buttonName =='Compare'){
				 win=window.open('','myWin','width=850,height=900,scrollbars=yes,resizable=yes,left:0px, top:0px'); 
				 form.target='myWin';
				 form.action='http://search.har.com/engine/dispSetMycartTransit.cfm'
		
			 }else if (buttonName == 'Map'){
				form.target = '';
				form.action='dispSearch.cfm';
			 }
	//	}
	
}

function compfrmreturn2(form, buttonName){
// require that at least one checkbox be checked

		var checkSelected = false;
		var checkCounter = 0;
		var listmlnum = '';
		for (i = 0;  i < document.compareForm2.listMLNUM.length;  i++){
			if (document.compareForm2.listMLNUM[i].checked){
				checkSelected = true;
				
				checkCounter = checkCounter + 1;
				listmlnum = listmlnum +document.compareForm2.listMLNUM[i].value + ",";
				}
		}
		if (!checkSelected)	{
			alert("Please select at least one of the listings.");
			return false;
			
		}
		if (checkCounter > 5){
			alert("You are only allowed to select up to 5 lisitng.\n Please uncheck one or some of your selection in order to select more.");
			return false;
		}
	//	if(checkSelected && checkCounter <= 5 ){
			listmlnum = listmlnum+ '-999'
			if(buttonName =='Compare'){
				//alert('i am here:'+listmlnum);
				if(cid ==0 && sitetype ==''){
				 win=window.open('http://search.har.com/engine/dispSetMycartTransit.cfm?listMLNUM='+listmlnum,'myWin','width=850,height=900,scrollbars=yes,resizable=yes,left:0px, top:0px'); 
				}else{
					 win=window.open('http://search.har.com/idx/dispSetMycartTransit.cfm?listMLNUM='+listmlnum+'&cid='+cid+'&sitetype='+sitetype,'myWin','width=850,height=900,scrollbars=yes,resizable=yes,left:0px, top:0px'); 
					}
						
			 }
			 /*
			 else if (buttonName == 'Map'){
				form.target = '';
				form.action='dispSearch.cfm';
			 }*/
	//	}
	
}
////////jane added:



/*************************************************************************
  This code is from Dynamic Web Coding at http://www.dyn-web.com/
  See Terms of Use at http://www.dyn-web.com/bus/terms.html
  Permission granted to use this code 
  as long as this entire notice is included.
*************************************************************************/

// resize fix for ns4
var origWidth, origHeight;
if (document.layers) {
	origWidth = window.innerWidth; origHeight = window.innerHeight;
	window.onresize = function() { if (window.innerWidth != origWidth || window.innerHeight != origHeight) history.go(0); }
}

var page_loaded; // set true onload (avoid errors onmouseover/out before page loaded)
function initInfoLyr() {
  page_loaded = true; 
  writeToLayer('drivedirinfo', origMsg); // write first message onload
}

function writeToLayer(id, sHTML) {
  if (!page_loaded) return;
  var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
  if (!el) return;
  var cntnt = '<div class="info">' + sHTML + '</div>';
  if (typeof el.innerHTML!="undefined") {
      el.innerHTML = cntnt;
  } else if (document.layers) {
			el.document.write(cntnt);
			el.document.close();
  }
}

// Variables for layer content
var origMsg = '<div class="hot">Here is the write layer. Position and style it any way you like.</div>';
var dfltMsg = "";


////drive route:
function showDriveDiv(divname){

if (divname == 'drivedivfrom'){
	document.getElementById('drivedivto').style.display = 'none';
	document.getElementById('drivedivfrom').style.display = 'block';
	}
else {
	document.getElementById('drivedivfrom').style.display ='none';
	document.getElementById('drivedivto').style.display = 'block';
	}
}
function FindLoc(dir){
	
	if(dir =='from'){
		//alert(document.getElementById('txtFrom').value + document.getElementById('fromtxtTo').value);
		map.GetRoute(document.getElementById('txtFrom').value,document.getElementById('fromtxtTo').value,null,null,onGotRoute);
	}else if (dir =='to'){
		//alert(document.getElementById('totxtFrom').value + document.getElementById('txtTo').value);
		map.GetRoute(document.getElementById('totxtFrom').value,document.getElementById('txtTo').value,null,null,onGotRoute);
		}
  //map.GetRoute(document.getElementById('txtFrom').value,document.getElementById('txtTo').value,null,null,onGotRoute);
}

function onGotRoute(route){
		var boxhtml = "<table border='0' width='400' bgcolor='DEE7EF' cellspacing='0' cellpadding='2'><tr><td width='100%'><table border='0' width='100%' cellspacing='0' cellpadding='0' height='36'>";
		boxhtml = boxhtml + "<tr><td id='titleBar' style='cursor:move' width='100%' class='xlBlue'><ilayer width='100%' onSelectStart='return false'><layer width='100%' onMouseover='isHot=true;' onMouseout='isHot=false'>Route info:</layer></ilayer></td><td style='cursor:hand' valign='top'><a href='#' onClick='hideMe();return false'><font color=#ffffff size=4 face=arial  style='text-decoration:none'>X</font></a></td></tr>";
		boxhtml = boxhtml + "<tr><td width='100%' bgcolor='#FFFFFF' style='padding:4px' colspan='2' class='smBlack'>";
		
		var routeinfo="";
		routeinfo+="Total distance: ";
		routeinfo+=   route.Itinerary.Distance+" ";
		routeinfo+=   route.Itinerary.DistanceUnit+"<br>";
		
		
		var steps="";
		var len = route.Itinerary.Segments.length;
		   for(var i = 0; i < len ;i++)
		   {
		      steps+=route.Itinerary.Segments[i].Instruction+" -- (";
		      steps+=route.Itinerary.Segments[i].Distance+") ";
		      steps+=route.Itinerary.DistanceUnit+"<br>";
		   }
		routeinfo+="Steps:\n"+steps;
		
		
		boxhtml = boxhtml + routeinfo;
		boxhtml = boxhtml + "</td></tr></table></td></tr></table>";
		//document.getElementById('theLayer').innerHTML = boxhtml;
		//alert(document.getElementById('theLayer').innerHTML)
		//alert(boxhtml);
		showMe();
		writeToLayer('drivedirinfo', boxhtml);
		//myroutinfobox.style.visibility= ' ';
		//myroutinfobox.innerHTML = routeinfo;
}

function hideMe(){
	
		
	document.getElementById('drivedirinfo').style.display = 'none';

}

function showMe(){
	document.getElementById('drivedirinfo').style.display = 'block';

}


