function popup(filename,width,height)
{result=window.open(filename,"popped1","width="+ width+", height="+height+", location=no, menubar=no, status=no, toolbar=no, scrollbars=yes, resizable=no");if(result!=null)html="is not blocking";else alert("Your Browser is blocking popups which is preventing a 3dCart window to appear.");}
function popupsimple(filename,width,height)
{var w=480,h=340;if(document.all||document.layers){w=screen.availWidth;h=screen.availHeight;}
var leftPos=(w-width)/2,topPos=(h-height)/2;result=window.open(filename,"popped1","width="+ width+", height="+height+",top="+ topPos+",left="+ leftPos+",location=no, menubar=no, status=no, toolbar=no, scrollbars=no, resizable=no");if(result!=null)html="is not blocking";else alert("Your Browser is blocking popups which is preventing a 3dCart window to appear.");}
var stocknum='';function SearchAndReplace(Content,SearchFor,ReplaceWith){var tmpContent=Content;var tmpBefore=new String();var tmpAfter=new String();var tmpOutput=new String();var intBefore=0;var intAfter=0;if(SearchFor.length==0)
return;while(tmpContent.toUpperCase().indexOf(SearchFor.toUpperCase())>-1){intBefore=tmpContent.toUpperCase().indexOf(SearchFor.toUpperCase());tmpBefore=tmpContent.substring(0,intBefore);tmpOutput=tmpOutput+ tmpBefore;tmpOutput=tmpOutput+ ReplaceWith;intAfter=tmpContent.length- SearchFor.length+ 1;tmpContent=tmpContent.substring(intBefore+ SearchFor.length);}
return tmpOutput+ tmpContent;}
function Len(str)
{return String(str).length;}
function Left(str,n)
{if(n<=0)
return"";else if(n>String(str).length)
return str;else
return String(str).substring(0,n);}
function Right(str,n)
{if(n<=0)
return"";else if(n>String(str).length)
return str;else{var iLen=String(str).length;return String(str).substring(iLen,iLen- n);}}
function Mid(str,start,len)
{if(start<0||len<0)return"";var iEnd,iLen=String(str).length;if(start+ len>iLen)
iEnd=iLen;else
iEnd=start+ len;return String(str).substring(start,iEnd);}
function InStr(strSearch,charSearchFor)
{for(i=0;i<Len(strSearch);i++)
{if(charSearchFor==Mid(strSearch,i,1))
{return i;}}
return-1;}
var listing_elemLenght=-1;function validateValues(what,alerting){var valid=true;var fieldnamemod=new String();var fieldvaluemod=new String();var checkBoxes=false;var checkboxChecked=false;var price=0;var radioButtons=false;var radioChecked=false;var imagename=new Image;var itemid;stocknum='';if(document.add.std_price==null)
{}
else
{price=document.add.std_price.value;if(document.getElementById("itemid")!=null)
itemid=document.add.itemid.value;else
itemid="";listing_elemLenght=what.elements.length;for(var i=0,j=listing_elemLenght;i<j;i++)
{myType=what.elements[i].type;if(myType!=null&&myType!=undefined)
{fieldnamemod=what.elements[i].name;if(fieldnamemod!='recipientselect'&&fieldnamemod!='reminder'&&fieldnamemod!='qty-0'&&fieldnamemod!='recurring_frequency')
{var field_array;if(fieldnamemod.indexOf("di_")>-1)
{SetSrc(what,"img_"+ fieldnamemod,GetValue(what,"image_"+ what.elements[i].options[what.elements[i].selectedIndex].value));if(1==2&&what.elements[i].options[what.elements[i].selectedIndex].value>"")
{fieldvaluemod=what.elements[i].options[what.elements[i].selectedIndex].value;field_array=fieldvaluemod.split(":::");if(field_array[0]!=undefined){stocknum=stocknum+ field_array[1]+"#"}
price=eval(price)+eval(GetValue(what,"price_"+ what.elements[i].options[what.elements[i].selectedIndex].value));itemid=itemid+''+GetValue(what,"OptID_"+ what.elements[i].options[what.elements[i].selectedIndex].value);}}
if(myType=='radio')
{radioButtons=true;if(what.elements[i].checked)
{radioChecked=true;price=eval(price)+eval(GetValue(what,"price_"+ what.elements[i].value));itemid=(itemid)+GetValue(what,"OptID_"+ what.elements[i].value);stocknum=stocknum+ what.elements[i].value+"#";}}
if(myType=='checkbox')
{checkBoxes=true;if(what.elements[i].checked)
{if(fieldnamemod>"")
price=eval(price)+eval(GetValue(what,"price_"+ fieldnamemod));itemid=(itemid)+GetValue(what,"OptID_"+ fieldnamemod);}}
if(myType=='hidden'||myType=='password'||myType=='text'||myType=='textarea')
if(what.elements[i].value==what.elements[i].defaultValue)valid=false;if(myType=='select-one'||myType=='select-multiple')
{if(what.elements[i].options[what.elements[i].selectedIndex].value>"")
{fieldvaluemod=what.elements[i].options[what.elements[i].selectedIndex].value;field_array=fieldvaluemod.split(":::");if(field_array[0]!=undefined){stocknum=stocknum+ field_array[1]+"#"}
price=eval(price)+eval(GetValue(what,"price_"+ what.elements[i].options[what.elements[i].selectedIndex].value));itemid=itemid+''+GetValue(what,"OptID_"+ what.elements[i].options[what.elements[i].selectedIndex].value);}}}}}
if((checkBoxes&&!checkboxChecked)||(radioButtons&&!radioChecked))valid=false;changeprice(price);changeid(itemid);if(alerting==1)
{return check_stock(what,stocknum);}}}
function changeid(itemid)
{var txt=itemid
changecontent('product_id',txt);}
function GetValue(formx,name){var element=document.getElementsByName(name);if(element!=null&&element!=undefined&&element.length>0)
return element.item(0).value;var i;for(i=0;i<listing_elemLenght;i++){if(formx.elements[i].name==name){return formx.elements[i].value;}}}
var listing_imgslength=-1;function SetSrc(formx,sname,sourcename){var element=document.getElementsByName(sname);if(element!=null&&element!=undefined&&element.length>0)
{if(element.length>0)
element.item(0).src=sourcename;return;}
imgs=document.getElementsByTagName('img');if(listing_imgslength==-1)
listing_imgslength=imgs.length;for(i=0;i<listing_imgslength;i++)
{if(imgs[i].name==sname)
imgs[i].src=sourcename;}}
function recalculate()
{}
function changecontent(fieldname,content1)
{var txt=content1;if(document.getElementById)
{if(document.getElementById(fieldname)!=null)
{document.getElementById(fieldname).innerHTML=txt;document.getElementById(fieldname).style.visibility='visible';}}
else if(document.all)
{if(document.all[fiendname]!=null)
{document.all[fiendname].innerHTML=txt;document.all[fieldname].style.visibility='visible';}}
else if(document.layers)
{if(document.layers[fieldname]!=null)
{document.layers[fieldname].document.open();document.layers[fieldname].document.write(txt);document.layers[fieldname].document.close();document.layers[fieldname].visibility='show';}}}
function changeprice(price)
{var txt=formatCurrency(price);if(document.getElementById("std_price_novat")!=null){var price_novat=parseFloat(document.getElementById("std_price_novat").value);var vattaxrate=parseFloat(document.getElementById("vat_tax_rate").value);var price_vatformat=document.getElementById("vat_tax_price_format").value;var priceAux=price_novat+(price_novat*(vattaxrate/100));if(priceAux==price){txt=price_vatformat;txt=txt.replace("[price_vat]",formatCurrency(price));txt=txt.replace("[price_novat]",formatCurrency(price_novat));txt=txt.replace("[currency]","");}
else{var difference=price- priceAux;difference=difference/(1+(vattaxrate/100));price_novat=price_novat+ difference;txt=price_vatformat;txt=txt.replace("[price_vat]",formatCurrency(price));txt=txt.replace("[price_novat]",formatCurrency(price_novat));txt=txt.replace("[currency]","");}}
changecontent('price',txt);}
function formatCurrency(intNumber){var currencySymbol;var decimalPlaces;try
{currencySymbol=currency_symbol;}
catch(err)
{currencySymbol='$';}
try
{decimalPlaces=parseInt(prod_decimal_places);if(decimalPlaces==0)
decimalPlaces=2;}
catch(err)
{decimalPlaces=2;}
intNumber=parseFloat(intNumber);intNumber=intNumber.toString();if(decimalPlaces>2)
{if(decimalPlaces-(intNumber.length-(intNumber.indexOf(".")+ 1))>0)
decimalPlaces=intNumber.length-(intNumber.indexOf(".")+ 1);if(decimalPlaces<2)
decimalPlaces=2;}
return formatNumberListing(intNumber,decimalPlaces,',','.',currencySymbol,'','','');}
function formatNumberListing(num,dec,thou,pnt,curr1,curr2,n1,n2){var x=Math.round(num*Math.pow(10,dec));if(x>=0)n1=n2='';var y=(''+ Math.abs(x)).split('');var z=y.length- dec;if(z<0)z--;for(var i=z;i<0;i++)y.unshift('0');if(z<0)z=1;y.splice(z,0,pnt);if(y[0]==pnt)y.unshift('0');while(z>3){z-=3;y.splice(z,0,thou);}var r=curr1+ n1+ y.join('')+ n2+ curr2;return r;}
