var xmlHttp;
var loaded=0;

var waitingforreply = 0;
var sentmessage = "";
var oldMessage = "";
var lastselectedrow = 0;
var lastselectedcolor = 0;

var queuedmessage = "";

var resultswidth = 250;
function setResultsWidth(width){resultswidth = width;}
try{


// Setup and send the resquest to the server
function sendRequest(event, formvalue){

	if(formvalue.value.length == 0)
	{
		document.getElementById("Possible_Properties").innerHTML = "";
		resizeDropDownMenu();
		//document.getElementById("searchinimg").style.visibility = "hidden";
		return;
	}

	if(waitingforreply == 1)
	{
		queuedmessage = formvalue.value;
		return;
	}

	if(!sendSuggestRequest())
		return;

	var rqst;
	rqst = "/suggestPropertyName.jsp?";
	rqst = rqst + "propname=" + formvalue.value;

	//document.getElementById("Possible_Properties").innerHTML = "Searching...";

	document.getElementById("searchinimg").style.visibility = "visible";

	oldMessage = formvalue.value;

	xmlHttp.open("POST",rqst,true);
	xmlHttp.send(null);

	waitingforreply = 1;
	sentmessage = rqst
	queuedmessage = "";
}

function sendQueuedRequest(){

	if(!sendSuggestRequest())
		return;

	var rqst;
	rqst = "/suggestPropertyName.jsp?";
	rqst = rqst + "propname=" + queuedmessage;

	document.getElementById("searchinimg").style.visibility = "visible";

	xmlHttp.open("POST",rqst,true);
	xmlHttp.send(null);

	waitingforreply = 0;
	queuedmessage = ""
}

var inputsearchfocus = 0;

// Used to help open and close the div properly
var overlist = 0;
function setOverList(){overlist = 1}
function setOutList(){overlist = 0;}

// Closes the div that displays the results
function closelist(){

	if(overlist == 0){
		document.getElementById("Possible_Properties").style.visibility = "hidden";
	}
	else
		document.getElementById("Possible_Properties").focus();

	inputsearchfocus = 0;
}

// Closes the div when the list has focus
function closelistfromlist(){

	document.getElementById("Possible_Properties").style.visibility = "hidden";

	inputsearchfocus = 0;
}

// Open the div that displays the results
function openlist(){

	document.getElementById("Possible_Properties").style.visibility = "visible";

	resizeDropDownMenu();

	inputsearchfocus = 1;
}

// Send what the user has typed so far to see if we can kinda a match
function sendSuggestRequest()
{
	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)
			{
				document.getElementById("Possible_Properties").innerHTML = "Your browser does not support AJAX!";
				return false;
			}
		}
	}
	try{
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			try{
			waitingforreply = 0;

			// Get the servers response
			document.getElementById("Possible_Properties").innerHTML = xmlHttp.responseText;

			document.getElementById("Possible_Properties").style.visibility = "hidden";

			// Set the div to visible if we got a none empty response
			if(document.getElementById("Possible_Properties").innerHTML != "")
				document.getElementById("Possible_Properties").style.visibility = "visible";

			resizeDropDownMenu();

			document.getElementById("searchinimg").style.visibility = "hidden";

			if(queuedmessage != "")
				sendQueuedRequest();

			}catch(e){}
		}
	}
	}
	catch(e){}

	loaded=1;

	return true;
}

// Set the element in the table inside the div to the highlighted colour
function mouseOverTableElement(element){
	try{
		element.style.background = "#C0FEB1";//#FFFF99#3CB401
	}
	catch(e){}
}

// Set the element in the table inside the div back to it's origonal colour
function mouseOutTableElement(element, colour){
	try{
		element.style.background = colour;
	}
	catch(e){}
}

// Check for clicks in the document.  Used to make sure the div for displaying search results closes properly
document.body.onclick = function() {

	if(overlist == 0 && inputsearchfocus == 0){
		document.getElementById("Possible_Properties").style.visibility = "hidden";
	}
}

// Resize the menu if it's not full to max height.  Workaround for IE
function resizeDropDownMenu(){

	try{
		document.getElementById("responsetable").style.width = (document.getElementById("Possible_Properties").offsetWidth - 28) + "px";

		document.getElementById("Possible_Properties").style.height = Math.min(150,(document.getElementById("responsetable").offsetHeight)) + "px";
	}
	catch(e)
	{
		document.getElementById("Possible_Properties").style.visibility = "visible";//hidden

		try{
		document.getElementById("Possible_Properties").style.height = document.getElementById("responsetable").offsetWidth + "px";//"16px";
		}catch(e){document.getElementById("Possible_Properties").style.height="16px";}
	}
}

function tableclicked(tablerow){

	//document.getElementById("search_by_Name").value = tablerow;
	//document.getElementById("search_by_Name").focus();
}
}catch(e){}

var lastinput = null;

function changePosition(top, left, width, imgtop, imgleft, input)
{
	try
	{
		if(input != lastinput)
		{
			document.getElementById("tabletemp").value = document.getElementById("tablerestore").value;

			document.getElementById("tablerestore").value = document.getElementById("Possible_Properties").innerHTML;
			document.getElementById("Possible_Properties").innerHTML = document.getElementById("tabletemp").value;

			//resizeDropDownMenu();
		}
	}
	catch(e){}

	lastinput = input

	if(input != null)
	{
		var parent = input;
		var curTop  = 0;
		var curLeft = 0;

		var oldTop = 0;
		var oldLeft = 0;

		while(parent.offsetParent != null)
		{
			oldLeft = parent.offsetLeft;
			oldTop  = parent.offsetTop;

			curTop  += parent.offsetTop;
			curLeft += parent.offsetLeft;

			parent = parent.offsetParent;
		}

		var locstr= "" + window.location;

		if (locstr == "http://www.hollandin1.com/"  || locstr.indexOf("hollandin1.com/index.jsp") >= 0 ||
			locstr == "http://www1.hollandin1.com/" || locstr == "http://www3t2.hollandin1.com/" ||
			locstr == "http://www2.hollandin1.com/" ||
			locstr == "http://www3.hollandin1.com/" || (locstr.indexOf("/Holland/index.jsp") !=-1)
		   )
		{
			if(top > 0)
				document.getElementById("Possible_Properties").style.top = ((curTop-oldTop)+input.offsetHeight) + "px";
			else
				document.getElementById("Possible_Properties").style.top = (-((curTop-oldTop)+input.offsetHeight-8)) + "px";

			document.getElementById("Possible_Properties").style.left = (curLeft-oldLeft) + "px";
		}
		else
		{
			document.getElementById("Possible_Properties").style.top = (curTop+input.offsetHeight) + "px";
			document.getElementById("Possible_Properties").style.left = (curLeft) + "px";
		}

		document.getElementById("Possible_Properties").style.width = (input.offsetWidth-4) + "px";
	}
	else
	{
		document.getElementById("Possible_Properties").style.top   = top   + "px";
		document.getElementById("Possible_Properties").style.left  = left  + "px";
		document.getElementById("Possible_Properties").style.width = width + "px"; 

		document.getElementById("searchinimg").style.top  = imgtop  + "px";
		document.getElementById("searchinimg").style.left = imgleft + "px";
	}

	try
	{
		if(input != null)
		{
			document.getElementById("responsetable").style.width = (document.getElementById("Possible_Properties").offsetWidth - 28) + "px";

			try{
				document.getElementById("Possible_Properties").style.height = Math.min(150,(document.getElementById("responsetable").offsetHeight)) + "px";
			}catch(e){document.getElementById("Possible_Properties").style.height="16px";}
		}
		else
			document.getElementById("responsetable").stlye.width = width-20;
	}
	catch(e){}
}