
function sh(e,h){if(e){e.innerHTML=h;e.htmlContent=h;}}
function checkInstallation(showAlert)
{if(typeof showAlert=='undefined')
var showAlert=false;if(typeof sl_elements=='undefined'||typeof sl_validAssignIds=='undefined'||typeof sl_stockInfo=='undefined'||typeof sl_prodCode=='undefined'||typeof sl_totalStock=='undefined'||typeof sl_useStock=='undefined'||typeof sl_showStockLevel=='undefined'||typeof sl_allowOutOfStock=='undefined'||typeof sl_appendCode=='undefined'||typeof sl_appendChar=='undefined'||typeof sl_langInStock=='undefined'||typeof sl_langOutOfStock=='undefined'||typeof sl_langVariantOutOfStock=='undefined'||typeof sl_langVariantNotAvail=='undefined'||typeof sl_langOutOfStockAlert=='undefined'||typeof sl_langNotAvailAlert=='undefined'){if(showAlert)alert("Please make a note of the following message and contact the store owner...\nthen continue your shopping!\n\nStock Levels for Product Options has not been installed correctly, make sure all new files are uploaded successfully then carefully check:\n- styleTemplates/content/viewProd.tpl\n- includes/content/viewProd.inc.php");return false;}
return true;}
function getIndex(assignIds)
{var index='';for(var i=0;i<sl_validAssignIds.length;++i){for(var j=0;j<assignIds.length;++j){if(sl_validAssignIds[i]==assignIds[j]){if(index.length>0)index+=',';index+=sl_validAssignIds[i];}}}
return index;}
function updateStockLevel()
{if(!checkInstallation()){return;}
var assignIds=[];var stockString='';var outStockString='';var prodCode='';var a=gv(sl_elements);var incompleteSelection=false;for(var i=0;i<a.length;++i){if(a[i].charAt(0)=='0'){a.length=0;incompleteSelection=true;}}
var index=getIndex(a);var stockLevel=-1;if(sl_stockInfo[index]!=undefined){prodCode=sl_stockInfo[index][1];stockLevel=sl_stockInfo[index][0];}else if(index==''){stockLevel=sl_totalStock;}
if(sl_useStock){if(incompleteSelection){stockString=outStockString='';}else if(sl_totalStock<=0){stockString='';outStockString=sl_langOutOfStock;}else if(stockLevel>0){stockString='<img src="/skins/FixedSize/styleImages/backgrounds/instock.jpg" border="0" style="border:none;" align="middle" />&nbsp;&nbsp;'+sl_langInStock;if(sl_showStockLevel)stockString+=': '+stockLevel;outStockString='';}else if(stockLevel==0){stockString='';outStockString=sl_langVariantOutOfStock;}else{stockString='';outStockString=sl_langVariantNotAvail;}}
var inStockSpan=document.getElementById('inStock');var outOfStockSpan=document.getElementById('outOfStock');var prodCodeSpan=document.getElementById('prodCode');sh(inStockSpan,stockString);sh(outOfStockSpan,outStockString);if(prodCode!=''&&sl_appendCode){st(prodCodeSpan,sl_prodCode+sl_appendChar+prodCode);}else if(prodCode!=''&&!sl_appendCode){st(prodCodeSpan,prodCode);}else{st(prodCodeSpan,sl_prodCode);}}
function checkStock()
{if(!checkInstallation(true)){return true;}
if(!sl_useStock){return true;}
var a=gv(sl_elements);var index=getIndex(a);var stockLevel=-1;if(sl_stockInfo[index]!=undefined){stockLevel=sl_stockInfo[index][0];}else if(index==''){stockLevel=sl_totalStock;}
if(stockLevel>0){return true;}else if(stockLevel==0&&sl_allowOutOfStock){return true;}else if(stockLevel==0&&!sl_allowOutOfStock){alert('We are sorry, but this product is out of stock');return false;}else{alert('We are sorry, but this product is out of stock');return false;}}
