function getCompositeInv(itemCode,isFULItem){
	//window.alert('enter');
	// check only for FUL item
	if(isFULItem=='true'){
	   var submitURL = "getLiveInv.ajx";	   
	   //window.alert('isFULItem ' + isFULItem);
	   var vendorId = document.getElementById("vendorId").value;
	   //window.alert('vendorId = ' + vendorId);
	   //window.alert('itemCode = ' + itemCode);   
	   var count = document.getElementById("_attributeCount_0").value;
	   //window.alert('count = ' + count);
	   var selectBoxId = "basketItems[0].attributes[$].optionId";
	   var query = getAttributeFrom(count,selectBoxId);   
	   query += "&vendorId="+vendorId;
	   query += "&itemCode="+itemCode;
	   //window.alert('query = ' + query);
	   
				// AJAX
			    var url = "simpleAJAX.jsp";
			    if (window.XMLHttpRequest) {
			      req = new XMLHttpRequest();
			    } else if (window.ActiveXObject) {
			      req = new ActiveXObject("Microsoft.XMLHTTP");
			    }
			    
			    req.open('POST',submitURL,false);
			    req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			    req.send(query);
			    
			    var response = req.responseText;
			    //window.alert("Response!" + response)	
			    
			    	var liveInv = "N/A";
					var obsolete = "0";
					if(response!=null){
						var tokens = response.split("~"); 			
						liveInv =tokens[0];
						obsolete =tokens[1];
					}		    
			    
	   var divToUpdate = document.getElementById("liveInv");
	   var obs = document.getElementById('obsolete');	
	   var qtyAvailable = document.getElementById('qtyAvailable');		
	   //window.alert('divToUpdate = ' + divToUpdate);
	   if(divToUpdate){
	   // for backward compatibility with previous release
			var is1104 = document.getElementById('is1104');
			if(is1104 != null){
				if(obsolete=="N" || obsolete=="P"){
					//alert(obsolete);
					//alert(liveInv);
					obs.value = obsolete;
					qtyAvailable.value = liveInv;
					divToUpdate.innerHTML = "In Stock: " + liveInv ;
					document.getElementById('qtyDiv1').style.display="inline";	
					document.getElementById('qtyDiv2').style.display="inline";	
				}
				else{
					obs.value = "Z";
					qtyAvailable.value = "0";			
					divToUpdate.innerHTML = "This combination is unavailable";
					document.getElementById('qtyDiv1').style.display="none";	
					document.getElementById('qtyDiv2').style.display="none";	
				}			
			}
			else{
				// pre 1104 release
				divToUpdate.innerHTML = "In Stock: " + liveInv ;
			}
		}
	   
   }
   //window.alert('exit');
}

/** copied from attribPriceAjx.js **/
function getAttributeFrom(count, paramName) {
	var query = "";
	for(var i = 0; i < count; i++) {
		var currParam = paramName.replace("\$", i+"");
		var selectAttr = document.getElementById(currParam);
		if(selectAttr) {
			var attribute = selectAttr.options[selectAttr.selectedIndex].title;
			if(attribute) {
				query += "attribute" + "=" + attribute;
				query += "&"; 
			}
		}
	}
	query = query.substring(0, query.length-1);
	return query;
}

/** logo locker **/
function openWindowWithPost(url,name,keys,values){
	var newWindow = window.open(url, name, 'width=650,height=350,resizable=1,scrollbars=1');
	if (!newWindow) return false;
	var actionURL = "/LogoLocker/LogoLockerTest.php";
	var html = "";
	html += "<html><head></head><body><form id='formid' method='post' action='" + actionURL + "'>";
	if (keys && values && (keys.length == values.length))
		for (var i=0; i < keys.length; i++)
			html += "<input type='hidden' name='" + keys[i] + "' value='" + values[i] + "'/>";
							
	html += "</form><script type='text/javascript'>document.getElementById('formid').submit();</script></body></html>";	
			
	newWindow.document.write(html);
	newWindow.focus();
	//return newWindow;
	return false;
}

function checkPhaseOut(isInvItem){
	//alert('test');
	//alert(isInvItem);
	if(isInvItem=='true'){
		var obsolete = document.getElementById('obsolete').value;
		//alert(obsolete);
			if(obsolete=='P'){
				var qtyAvailable = document.getElementById('qtyAvailable').value;
				qtyAvailable = parseInt(qtyAvailable);
				//alert(qtyAvailable);
				var qty = document.getElementById('qty').value;
				qty = parseInt(qty);
				//alert(qty);
				if(qty>qtyAvailable){
					alert('Only ' +qtyAvailable+' can be ordered for this item');
					return false;
				}
			}
	}
	return true;	
}

function checkMatrixPhaseOut(){
	var isFULItem = document.getElementById('isFULItem');
	//alert('test');
	//alert(isFULItem);
	if(isFULItem && isFULItem.value=='true'){
		var totalRows = document.getElementById('totalRows').value;
		for(var i=0;i<totalRows;i++){
			var obsolete = document.getElementById('obsolete_'+i).value;
			//alert(obsolete);
			if(obsolete=='P'){
				var qtyAvailable = document.getElementById('qtyAvailable_'+i).value;
				qtyAvailable = parseInt(qtyAvailable);
				//alert(qtyAvailable);
				var qty = document.getElementById('qty_'+i).value;
				qty = parseInt(qty);
				//alert(qty);
				if(qty>qtyAvailable){
					alert('Only ' +qtyAvailable+' can be ordered for this combination');
					return false;
				}
			}
		}
	}	
	return true;	
}
