﻿// JScript File



var gXmlHttp;
var pTable = ""; //table pointer
var pErrMsgElement = "";
var pDivAuction = "";

function ProcessWServiceCall(SelectedDate, TableObj, ErrLabel, DivElementObj) 
{
	var sXml;
	var requestUrl;
	pTable = TableObj;
	pErrMsgElement = ErrLabel;
	pDivAuction = DivElementObj;
	
	requestUrl = "http://www.land4bid.com/Include/RemoteCallReceiver.aspx?DateSelected=" + encodeURIComponent(SelectedDate);		
	//requestUrl = "http://localhost/landbluebook/WebService/RemoteCallReceiver.aspx?DateSelected=" + encodeURIComponent(SelectedDate);		

	CreateXmlHttp();

	if(gXmlHttp) // If browser supports XMLHTTPRequest object
	{		
		try
		{
			//alert(requestUrl);
			gXmlHttp.onreadystatechange = HandleStateChange;
			gXmlHttp.open("GET", requestUrl);
			gXmlHttp.send(null);
		}
		catch(ex)
		{
			DisplayRemoteCallMsg(pErrMsgElement, "Error retriving auction listings.");
		}

	}
	else //no support for XMLHTTPRequest
	{
		DisplayRemoteCallMsg(pErrMsgElement, "Browser error retriving state/province data.");
	}
		
}

function ProcessResponseMsg(xmDocReturn)
{

		//var x = pTable.insertRow(0).insertCell(0);
		//x.style.fontFamily = "Verdana";
		//x.style.fontSize = "9pt";
		//x.style.fontColor = "#CC6600";
		//x.align = "right";
		//x.onclick = hideDiv();
		
		//x.innerHTML = "[" + "<font style=\"FONT-WEIGHT: bold; FONT-SIZE: 12px; COLOR: #660033; FONT-FAMILY: Verdana\">"  + 
		//			"x" + "</font>]";
		//alert(xmDocReturn.getElementsByTagName("AuctionCalendar_id").length);

		if (xmDocReturn.getElementsByTagName("AuctionCalendar_id").length > 0)
		{
			for(i = 0; i < xmDocReturn.getElementsByTagName("AuctionCalendar_id").length; i++)
			{
				var x = pTable.insertRow(i).insertCell(0);
				//x.style.fontFamily = "Verdana";
				//x.style.fontSize = "9pt";
				x.align = "left";
				if(Boolean((i) % 2))
					x.bgColor = "#e4e4e6";
				else
					x.bgColor = "#f5f5dc";
				
				x.height = "30pt";
							
			
				var LandId1 = xmDocReturn.getElementsByTagName("Land_id1")[i].childNodes[0].nodeValue;
			
				x.innerHTML = "<font style=\"FONT-WEIGHT: normal; FONT-SIZE: 10px; COLOR: #000000; FONT-FAMILY: Verdana\">" + 
					"<a onmouseover=\"this.style.color='#FF0000'\" onmouseout=\"this.style.color='#000000'\" href=\"ViewLandDetails.aspx?txtLandId1=" + LandId1 + "\">" +
					xmDocReturn.getElementsByTagName("State")[i].childNodes[0].nodeValue + 
					", " + xmDocReturn.getElementsByTagName("LandArea")[i].childNodes[0].nodeValue +
					" " + xmDocReturn.getElementsByTagName("AreaUnitDes")[i].childNodes[0].nodeValue +
					", for " + xmDocReturn.getElementsByTagName("LandUse")[i].childNodes[0].nodeValue + 
					" use, </a><br>" + "Auction date: " + xmDocReturn.getElementsByTagName("AuctionDate")[i].childNodes[0].nodeValue + "</font>";	
			}	
		}	
		
}


function HandleStateChange()
{	
	// To make sure receiving response data from server is completed
	if(gXmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(gXmlHttp.status == 200)
		{			
			//alert(gXmlHttp.responseText);			
			ProcessResponseMsg(gXmlHttp.responseXML);
		}
		else
		{
			DisplayRemoteCallMsg(pErrMsgElement, "Error retriving state data. status= " + gXmlHttp.status + ", " + gXmlHttp.statusText);
		}
	}
}


function CreateXmlHttp()
{
	try
	{
		gXmlHttp = new ActiveXObject(GetProgID(["Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"]));
	}
	catch(Ex)
	{
		gXmlHttp = null;
	}
	
	if(!gXmlHttp && typeof XMLHttpRequest != "undefined") 
	{
		gXmlHttp = new XMLHttpRequest();
	}
	
}


	function GetProgID(IDs)
	{
		var blnFound = false;
		for(var i=0; i < IDs.length && !blnFound; i++)
		{
			try
			{
				var objDoc = new ActiveXObject(IDs[i]);
				ProdId = IDs[i];
				
				blnFound = true;
			}
			catch (objException)
			{
				// trap; try next progID
			}
		}
		if (!blnFound)
			throw "A valid progID not found: " + IDs[IDs.length-1] + ". (Exception: " + e + ")";
		IDs = null;
		return ProdId;
		
	}

function DisplayRemoteCallMsg(pMessageElement, sMessage)
{
	try
	{
		pMessageElement.innerHTML = sMessage;
		//el.style.display = 'inline'
		pMessageElement.style.display = 'block'
	}
	catch(ex)
	{/*trap*/}
}


