var ajax_response;
function ajax(requestType, url, param, callbackFunc, divId) {  
var xmlHttp;
try {    // Firefox, Opera 8.0+, Safari    
		xmlHttp=new XMLHttpRequest();    
	}  
	catch (e) {    // Internet Explorer    
		try	{      
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
		}
   		 catch (e) {      
		 	try {        
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
			}
      		catch (e) {        
				//alert("Your browser does not support AJAX!");        
				return false;       
			 }
		}
	} 	 
	 xmlHttp.onreadystatechange=function()
	  {
	  if(xmlHttp.readyState==4)
	    {
	   	 	// Get the data from the server's response
			ajax_response=xmlHttp.responseText;
			switch(callbackFunc){
				case 'replaceDivContent':
					replaceDivContent(ajax_response, divId);
					break;
				case 'displayCaptcha':
					displayCaptcha(ajax_response, divId);
					break;
				case 'showLodgingSkiMileage':
					showLodgingSkiMileage(ajax_response);
				case 'doNothing':
					doNothing(ajax_response);
					break;
				default:
					doNothing(ajax_response);
			}		
	    }
	  }
	if(requestType == 'POST'){
		// Post Request
		xmlHttp.open("POST", url, true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	    xmlHttp.setRequestHeader("Content-length", param.length);
	    xmlHttp.setRequestHeader("Connection", "close");
	    xmlHttp.send(param);
	} else {
		// Get Request
		var geturl = url + '?' + param;
		xmlHttp.open("GET", geturl, true);
		xmlHttp.send(null);
	}
 }

 function doNothing(ajax_response){
 	// empty function
	 //alert(ajax_response);
 }
 
 function replaceDivContent(resp, divId){
 	if(resp != ''){
 		document.getElementById(divId).innerHTML = resp;
	}
 	document.getElementById(divId).style.display = 'block';
 }
 
 function showPhoneNumber(thing_id, divId){
 	var url;
	var param = 'thing_id=' + thing_id + '&click_type=phone';
	url = '/utah_logs/thing_click_log.php';
	var ucdate = new Date();
	var timestamp = Math.random();
	param = param + '&time=' + timestamp;
	//document.write(url + '?' + param);
	ajax('POST', url, param, 'replaceDivContent', divId);
 }
 
 function showTollFreeNumber(thing_id, divId){
 	var url;
	var param = 'thing_id=' + thing_id + '&click_type=tollphone';
	url = '/utah_logs/thing_click_log.php';
	var ucdate = new Date();
	var timestamp = Math.random();
	param = param + '&time=' + timestamp;
	//document.write(url + '?' + param);
	ajax('POST', url, param, 'replaceDivContent', divId);
 }
 
 function displayVideoListingPhoto(place_id, activity_id, video_thing, divId){
 	var url;
	var param = 'place_id=' + place_id + '&activity_id=' + activity_id + '&video_thing=' + escape(video_thing);
	url = '/video/getVideoListingPhoto.php';
	var ucdate = new Date();
	var timestamp = Math.random();
	param = param + '&time=' + timestamp;
	//alert('Div: ' + divId + ' ' + url + '?' + param);
	ajax('POST', url, param, 'replaceDivContent', divId);
 }
 
 function displayVideoListing(video_id){
 	var content = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="406" height="600" id="video_interface" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="flashVars" value="videoId=' + video_id + '" /><param name="movie" value="video_interface_embedded2.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#000000" /><embed src="video_interface_embedded2.swf" flashVars="videoId=' + video_id + '" quality="high" bgcolor="#000000" width="406" height="600" name="video_interface" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
	replaceDivContent(content, 'photoDiv')
 }
 
 function displayVideoListing2(video_id){
 	var content = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="406" height="600" id="video_interface" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="flashVars" value="videoId=' + video_id + '" /><param name="movie" value="/video/video_interface_embedded2.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#000000" /><embed src="/video/video_interface_embedded2.swf" flashVars="videoId=' + video_id + '" quality="high" bgcolor="#000000" width="406" height="600" name="video_interface" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
	replaceDivContent(content, 'video-shell')
 }
 
 function logVideoImpression(video_id, ad_video_id){
  	var url;
	var param = 'video_id=' + video_id + '&ad_video_id=' + ad_video_id + '&imp=1';
	url = '/video/logVideoImpression.php';
	var ucdate = new Date();
	var timestamp = Math.random();
	param = param + '&time=' + timestamp;
	//alert('Div: ' + divId + ' ' + url + '?' + param);
	ajax('POST', url, param, 'doNothing', '');
 }
 
 function logVideoClick(thing_id, page_id){
  	var url;
	var param = 'thing_id='+thing_id+'&page_id='+page_id;
	url = '/utah_logs/video_click_log.php';
	var ucdate = new Date();
	var timestamp = Math.random();
	param = param + '&time=' + timestamp;
	//alert('Div: ' + divId + ' ' + url + '?' + param);
	ajax('POST', url, param, '', '');
	//window.status = 'Log: thing=' + thing_id + ' page=' +page_id;
	//return true;
 }
 
 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 getLodgingSkiMileage(thing_id){
 	var url;
	var param = 'thing_id=' + thing_id;
	url = '/database/lodging/getlodgingresortdistance.php';
	var ucdate = new Date();
	var timestamp = Math.random();
	param = param + '&time=' + timestamp;
	//document.write(url + '?' + param);
	ajax('POST', url, param, 'showLodgingSkiMileage', '');
}

function showLodgingSkiMileage(resp){
	var data = resp.split('|');
	document.getElementById("ski-mileage").innerHTML = data[1];
	linkid = "ski-mileage-" + data[0];
	placement = findPos(document.getElementById(linkid));
	var left = placement[0] - 115;
	var top = placement[1] - 78;
	document.getElementById("ski-mileage").style.left=left+"px";
	document.getElementById("ski-mileage").style.top=top+"px";
	document.getElementById("ski-mileage").style.display="block";
}

function hideSkiMileage(){
	setTimeout("hideSkiMileageDiv()", 500);
}

function hideSkiMileageDiv(){
	document.getElementById("ski-mileage").style.display="none";
}

function toggle2(id){
	togid = getSty(id, window.document);
	if(togid.display=='block'){
		togid.display='none';
	} else {
		togid.display='block';
	}
}