﻿function FindLot(lotv, sessionid, pgSize)
{
	var varData = {
		command: "findlot",
		lot: lotv,
		as: sessionid,
		ps: pgSize
	};

	$.ajax({
		type:"GET",
		url:"handlers/pages/auction.ashx",
		data:varData,
		success:function(responseText){FindLot_Success(responseText);},
		error:function(responseText){FindLot_Failure(responseText);}
	});
}

function FindLot_Success(xml_response)
{
	var response = $(xml_response).find("response");
	var lotNumber;

	switch(response.attr("type"))
	{
		case "success":
			var pgNumber = response[0].getElementsByTagName("pgnumber")[0].firstChild.nodeValue;
			var pgSize = response[0].getElementsByTagName("pgsize")[0].firstChild.nodeValue;
			var sessionID = response[0].getElementsByTagName("sessionid")[0].firstChild.nodeValue;
			var itemID =  response[0].getElementsByTagName("itemid")[0].firstChild.nodeValue;
			location.href='auction.aspx?as=' + sessionID + '&p=' + pgNumber + '&ps=' + pgSize + '#i' + itemID;
			return;
		case "failure_lotnotfound":
			lotNumber = response[0].getElementsByTagName("lotnumber")[0].firstChild.nodeValue;
			alert("Lot " + lotNumber + " not found");
			$("#txtFindLot").select();
			return;
		case "failure_invalidlot":
			alert("Invalid lot number");
			$("#txtFindLot").select();
			return;
		default:
			break;
	}
}

function FindLot_Failure(xml_response)
{
	var responseText = $(xml_response).find("response")[0].getElementsByTagName("error")[0].firstChild.nodeValue;

	alert("fail: " + responseText);
}

function SearchSession(searchField, sessionID, ps)
{
	location.href = 'auction.aspx?as=' + sessionID + '&p=1&ps=' + ps + '&kw=' + escape($(searchField).attr("value"));
}

function FilterItems(filter)
{
	alert(filter);
}