function	CheckForReturn( e ) {
	var	key, target;

	if( e ) {
		key = e.which;
		target = e.target;
	} else {
		key = window.event.keyCode;
		target = window.event.srcElement;
	}

	if( key == 13 )
		GoGoQuickPart();
}

function	FormatAddPartToBasket( partCode ) {
	return "Basket.asmx/Add?PartCode=" + partCode;
}

// Callback function for adding a part from the parts list to the basket.
// The AddPart server call returns the whole shopping basket, so use UpdateBasketTableCallback to respond.
function	AddToBasketCallback() {
	var	row = CalcRowOfImage( this, pl_table );
	StartDownload( FormatAddPartToBasket(g_PartsListArray[ row ].m_PartCode), UpdateBasketTableCallback );
}

// Callback function for downloading a parts list.
function	BasketPageGotPartsList() {
	g_PartsListArray = GetPartsListFromXmlDoc(g_XmlRequester.responseXML);

	if( g_PartsListArray.length == 0 ) {
		pl_table.style.visibility = "hidden";
		alert('Not found.');
	}
	else
		pl_table.style.visibility = "visible";

	GotPartsList();
}

// Callback function for part search images
function	GoGoQuickPart() {
	var	searchCombo = document.getElementById( "SearchType" );
	var	input_box = document.getElementById( "SearchInput" );

	if( input_box.value.length < 2 ) {
		alert("Search requires at least two characters.");
		return;
	}

	var searchType = searchCombo[ searchCombo.selectedIndex ].value;

	if( searchType == "ByDescriptionForModel" )
		StartDownload( FormatPartsSearchByDescription(input_box.value), BasketPageGotPartsList );
	else //if( searchType == "ByPartCode" )
		StartDownload( FormatPartsSearch(input_box.value, null), BasketPageGotPartsList );
}

function initQuickParts() {
	document.getElementById( "SearchInput" ).onkeydown = CheckForReturn;
	document.getElementById( "SearchButton" ).onclick = GoGoQuickPart;

	PartTableInit( false, "Part number does not exist\nor is not available" );
}
