﻿var xmlHttp;function createXMLHttpRequest(){if(window.XMLHttpRequest){xmlHttp=new XMLHttpRequest();}
else if(window.ActiveXObject){xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}}
function getBrands(id){if(id.len!=0){createXMLHttpRequest();xmlHttp.onreadystatechange=displayBrands;xmlHttp.open("GET","../AJAX/ajax_getBrands.asp?recid="+id,true);xmlHttp.send();}}
function displayBrands(){if(xmlHttp.readyState==4){if(xmlHttp.status==200){document.getElementById("showBrands").innerHTML=xmlHttp.responseText;}else{alert("Error: "+xmlHttp.status+" "+xmlHttp.responseText);}}}
function getTiers(showState,idCust){if(showState=='-1'){createXMLHttpRequest();xmlHttp.onreadystatechange=displayTiers;xmlHttp.open("GET","../AJAX/ajax_getTiers.asp?idCust="+idCust,true);xmlHttp.send();}else{document.getElementById("showTiers").innerHTML='';}}
function displayTiers(){if(xmlHttp.readyState==4){if(xmlHttp.status==200){document.getElementById("showTiers").innerHTML=xmlHttp.responseText;}else{alert("Error: "+xmlHttp.status+" "+xmlHttp.responseText);}}}
function getOptionsInventory(idProduct,theForm){var options=getOptions(theForm);if(options==''){document.getElementById("showInventoryMsg").innerHTML='<b>No options selected!</b><br/>';return;}
var url="../AJAX/ajax_optInventory.asp";var nvp="action=get&idproduct="+idProduct+"&options="+options;createXMLHttpRequest();xmlHttp.open("POST",url,true);xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");xmlHttp.setRequestHeader("Content-length",nvp.length);xmlHttp.setRequestHeader("Connection","close");xmlHttp.onreadystatechange=displayGetOptionsInventory;xmlHttp.send(nvp);}
function setOptionsInventory(idProduct,inventory,theForm){var options=getOptions(theForm);if(options==''){document.getElementById("showInventoryMsg").innerHTML='<b>No options selected!</b><br/>';return;}
var url="../AJAX/ajax_optInventory.asp?action=set&idproduct="+idProduct+"&options="+options+"&inventory="+inventory;createXMLHttpRequest();xmlHttp.onreadystatechange=displaySetOptionsInventory;xmlHttp.open("get",url);xmlHttp.send();}
function displayGetOptionsInventory(){if(xmlHttp.readyState==4){if(xmlHttp.status==200){if(isNaN(parseInt(xmlHttp.responseText))){document.getElementById("showInventoryMsg").innerHTML=xmlHttp.responseText;if(document.getElementById("showInventory").tagName=='INPUT'){document.getElementById("showInventory").value='';}else{document.getElementById("showInventory").innerHTML='0';}}else{document.getElementById("showInventoryMsg").innerHTML='';if(document.getElementById("showInventory").tagName=='INPUT'){document.getElementById("showInventory").value=xmlHttp.responseText;}else{document.getElementById("showInventory").innerHTML=xmlHttp.responseText;}}}else{alert("Error: "+xmlHttp.status+" "+xmlHttp.responseText);}}}
function displaySetOptionsInventory(){if(xmlHttp.readyState==4){if(xmlHttp.status==200){document.getElementById("showInventoryMsg").innerHTML=xmlHttp.responseText;}else{alert("Error: "+xmlHttp.status+" "+xmlHttp.responseText);}}}
function getOptions(theForm){var formElem;var i,j;var iLen;options='';for(i=0;i<theForm.elements.length;i++){formElem=theForm.elements[i];if(formElem.name.substr(0,11)=='OPTidOption'){if(formElem.type=='select-one'){options+=formElem.options[formElem.selectedIndex].value+",";}else{if(formElem.type=='radio'&&formElem.checked){options+=formElem.value+',';}}}}
if(options.length>0){options=options.substr(0,options.length-1);}
return options;}
function getCust(el,id){if(id.len!=0){createXMLHttpRequest();xmlHttp.onreadystatechange=displayCust(el);xmlHttp.open("GET","../AJAX/ajax_getCust.asp?recid="+id,true);xmlHttp.send();}}
function displayCust(el){if(xmlHttp.readyState==4){if(xmlHttp.status==200){el.innerHTML=xmlHttp.responseText;}else{alert("Error: "+xmlHttp.status+" "+xmlHttp.responseText);}}}
function getTableFields(table){var url="../AJAX/ajax_getTableFields.asp";var nvp="table="+table;createXMLHttpRequest();xmlHttp.open("POST",url,true);xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");xmlHttp.setRequestHeader("Content-length",nvp.length);xmlHttp.setRequestHeader("Connection","close");xmlHttp.onreadystatechange=displayGetTableFields;xmlHttp.send(nvp);}
function displayGetTableFields(){if(xmlHttp.readyState==4){if(xmlHttp.status==200){document.getElementById("showFields").innerHTML=xmlHttp.responseText;}else{alert("Error: "+xmlHttp.status+" "+xmlHttp.responseText);}}}