
// **************************************************************
// launched from event
var fCheckItemCode = function (strInputId,strOutputId) {
	
	// build up the post string when passing variables to the server side page
	var strInputVal = document.getElementById(strInputId).value;
	var PostStr = "tmpVal=" + strInputVal + "|" + strOutputId;	
	//if (strInputVal!=''){
		// use the generic function to make the request
		doAJAXCall('../../../Ko-Includes/f_CheckItemCode.asp', 'GET', PostStr, showMessageResponse);
	//}
}

var fCheckItemCodeSingle = function (strInputId) {	

	// build up the post string when passing variables to the server side page
	var PostStr = "tmpVal=" + document.getElementById(strInputId).value;		
	// use the generic function to make the request
	doAJAXCall('../../../Ko-Includes/f_CheckItemCodeSingle.asp', 'GET', PostStr, showMessageResponseSingle);
}

// The function for handling the response from the server
var showMessageResponse = function (oXML) {
	// get the response text, into a variable
    var response = oXML.responseText;
	
	// split results
	var myArray = response.split('|');	
	var id = myArray[1]
	var strStkName = myArray[0];
	var strStkSize =  myArray[2];
	var strOutputName = 'Details' + id;
	var strDivName = 'DivId' + id;
	var strInputName = 'ItemCode' + id;
	var strQtyName = 'Quantity' + id;
	var resetFld = 'Reset' + id;
	var prevId = id - 1;
	var resetFldPrev = 'Reset' + prevId;
	var nxtId = id + 1;
	var resetFldNxt = 'Reset' + nxtId;
	var intTotalRow = 0;
	
	
		
	if (strStkName=='none'){
		document.getElementById(strInputName).style.backgroundColor="#FF2400";
		document.getElementById(strInputName).style.color="#FFFFFF";
		
		document.getElementById(strOutputName).style.color="#FF2400";
		document.getElementById(strOutputName).innerHTML = "The catalogue number you have entered is invalid";
			
		document.getElementById(strQtyName).value = "";
					
				
	}
	else if (strStkName=='empty'){
		
		//document.getElementById(strOutputName).innerHTML = "";
	
	}
	else {
		document.getElementById(strOutputName).style.color="#000000";
		document.getElementById(strOutputName).innerHTML = Left(strStkName, 35) + ' - ' + strStkSize;
		document.getElementById(strInputName).style.color="#000000";
		
		document.getElementById(strInputName).style.backgroundColor="#FFFFFF";
		
		// increase validRow count
		//var intValidRows = document.getElementById('validRows').value;
		//intValidRows = intValidRows + 1;
		//document.getElementById('validRows').value = intValidRows;
				
		id++	
		
		//if(id < 11){
		
			//document.getElementById('ItemCode'+id).disabled=false;
			//document.getElementById('Quantity'+id).disabled=false;
		
		//}
		
		intTotalRow = intTotalRow + id
	
	}
	
	
	
				
};


// The function for handling the response from the server
var showMessageResponseSingle = function (oXML) {
	// get the response text, into a variable
    var response = oXML.responseText;
	
	var strInputName = 'StockCode';
	var strDivName = 'DivId';
	
		
	if (response=='none'){
	
		//document.getElementById(strInputName).style.backgroundColor="#FF2400";
		//document.getElementById(strInputName).style.color="#FFFFFF";
		document.getElementById(strDivName).style.display = "block";
		document.getElementById(strDivName).style.fontSize="8pt";
		document.getElementById(strDivName).style.color="#FF2400";
		document.getElementById(strDivName).innerHTML = "The catalogue number you have entered is invalid";
					
	}
	else {
	
		document.getElementById(strInputName).style.color="#000000";
		//document.getElementById(strInputName).style.backgroundColor="#BFFBD1";
		document.getElementById(strDivName).style.display = "none";
		document.getElementById(strDivName).innerHTML = "";
		
		// all ok so post form
		document.QuickAdd.submit(); 

		
	}	
	
	
				
};




function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n) + "...";
}

// **************************************************************




