var searchDelayTimerId
var mouseOverLinks = false


var xmlHttp
var siteHost = window.location.hostname
if(siteHost=='lsnetbook' || siteHost=='devbox.pg54.com' || siteHost=='devbox')siteHost=siteHost+'/melandmal'
siteHost = 'http://'+siteHost



// Ajax Common =========================================================================

function nowTime(){
	var date = new Date();
	var timestamp = date.getTime();
	return timestamp
}

function GetXmlHttpObject(){
	var objXMLHttp=null
	if (window.XMLHttpRequest){
		objXMLHttp=new XMLHttpRequest()
	}else if (window.ActiveXObject){
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}


// Search =========================================================================

function hideSearch(){
	document.getElementById('PredictiveSearchResults').style.display='none'
}

function resetSearchText(){
	if(!mouseOverLinks)document.getElementById('PredictiveSearchResults').style.display='none'
	var searchText = document.getElementById('SearchText').value
	if(searchText==''){
		document.getElementById('SearchText').value='Search'
	}else{
		if(searchText=='Search'){
			document.getElementById('SearchText').value=''
		}
	}
}

function startSearchTimer(){
	clearTimeout(searchDelayTimerId)
	searchDelayTimerId = setTimeout('doSearch()',100)
}

function doSearch(){
	var searchText = document.getElementById('SearchText').value
	if(searchText!=''){
		var url=siteHost+'/Modules/melandmal_PredictiveSearch.php?host='+siteHost+'&searchText='+searchText+'&nochache='+nowTime()
		xmlHttp=GetXmlHttpObject()
		xmlHttp.open("GET",url,true)
		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){

				if(xmlHttp.responseText!=''){
					//alert(xmlHttp.responseText)
					document.getElementById('PredictiveSearchResults').innerHTML=xmlHttp.responseText
					document.getElementById('PredictiveSearchResults').style.display='block'

				}else{
					document.getElementById('PredictiveSearchResults').style.display='none'
				}
			}
		}
		xmlHttp.send(null);
	}else{
		document.getElementById('PredictiveSearchResults').style.display='none'
	}
}

function selectVideo(encodedPath){
	document.getElementById('VideoPlayer').src='Modules/PlayFLV.php?movie='+encodedPath
}
function selectYouTubeVideo(encodedPath){
	document.getElementById('VideoPlayer').src='Modules/PlayYouTube.php?movie='+encodedPath
}

function moveHPOject(objectId,direction){
	var currentObjectPosition = parseInt(document.getElementById(objectId).style.left)
	if(direction=='Left')currentObjectPosition = currentObjectPosition + 264
	if(direction=='Right')currentObjectPosition = currentObjectPosition - 264
	document.getElementById(objectId).style.left = currentObjectPosition+'px'
}
