function goProductPage(ipage){
//    CookieUtil.setCookie("product-current-page",ipage);
//    location.reload();
    var url=location.href;
    var qs=LocationUtil.queryString("page");
    if(qs){
        location.href=url.slice(0,url.length-1)+ipage;}
    else
        location.href=url+"?page="+ipage;
}
var PROPHOTOKEY='';
function ViewProductPhoto(ssku,stype,iindex,iptotal,ietotal,skey){
    var oLayer;
    var oRegion=$("PhotoLayer");
    var oImg=$("PhotoLayerImg");
    var oUl=$("PhotoLayerUl");
    if(skey){PROPHOTOKEY=skey;ssku=ssku.replace(skey+"-","");}
    var pky=(PROPHOTOKEY&&skey&&stype=="product")?"key":'';
    var simgpath=String.format("{0}images/{1}{2}-285x285/",LIBRARYURL,stype,pky);
    if(!oRegion){
        oRegion=document.createElement("div");
        oRegion.setAttribute("id","PhotoLayer");
        oRegion.style.top=document.documentElement.scrollTop+100+"px";
        document.body.appendChild(oRegion);
        oImg=document.createElement("img");
        oImg.setAttribute("id","PhotoLayerImg");
        oRegion.appendChild(oImg);
        
        var sb=new StringBuilder();
        sb.append("<li style=\"padding-left:65px\"><input id=\"btnPreviousPhoto\" type=\"button\" value=\"Previous\" class=\"btnCss\" /></li>");
        sb.append("<li><input id=\"btnNextPhoto\" type=\"button\" value=\"Next\" class=\"btnCss\" /></li>");
        sb.append("<li><input id=\"btnClosePhoto\" type=\"button\" value=\"Close\" class=\"btnCss\" /></li>");
        oUl=document.createElement("ul");
        oUl.setAttribute("id","PhotoLayerUl");
        oUl.innerHTML=sb.toString();
        oRegion.appendChild(oUl);
        
        oLayer=LayerShield();
        
        $("btnClosePhoto").onclick=function(){
            document.body.removeChild(oRegion);
            document.body.removeChild(oLayer);
        };
    }
    
    oImg.setAttribute("src",String.format("{0}{1}{2}-{3}.jpg",simgpath,(skey&&(stype=="product"))?(skey+"-"):'',ssku,iindex));
    
    var oBtnPr=$("btnPreviousPhoto");
    if(stype=="product"&&iindex<=1)oBtnPr.disabled=true;
    else oBtnPr.disabled=false;
    oBtnPr.onclick=function(){
        var type=stype;index=iindex-1,ky=skey;
        if(index<=0){
            if(type=="product")index=1;
            if(type=="effect"){
                type="product";
                index=iptotal;
                ky=PROPHOTOKEY;
            }
        }
        ViewProductPhoto(ssku,type,index,iptotal,ietotal,ky);
    }
    
    var oBtnNe=$("btnNextPhoto");
    if(stype=="effect"&&(iindex>=ietotal||ietotal==0))oBtnNe.disabled=true;
    else oBtnNe.disabled=false;
    oBtnNe.onclick=function(){
        var type=stype;index=iindex+1,ky=skey;
        if(type=="product"&&index>iptotal){
            type="effect";
            index=1;
            ky='';
        }
        if(type=="effect"){
            if(index>ietotal)index=ietotal;
            if(index==0){oBtnNe.disabled=true;return false;}
        }
        ViewProductPhoto(ssku,type,index,iptotal,ietotal,ky);
    }
}
function ProductDetailTab(oli,stab){
    var olis=oli.parentNode.getElementsByTagName("li");
    if(olis){
        for(var i=0;i<olis.length;i++)
            olis[i].style.borderBottom="solid 1px #e7ae63";
        oli.style.borderBottom="solid 1px #fff7ef";
    }
    
    var otab=$("PD"+stab);
    if(otab){
        var oregions=otab.parentNode.getElementsByTagName("div");
        for(var i=0;i<oregions.length;i++)
            oregions[i].style.display="none";
        otab.style.display="block";
    }
    
    if(IEXPLORER){
        otab.parentNode.style.height="auto";
        if(otab.parentNode.offsetHeight>250)otab.parentNode.style.height="250px";
        if(otab.parentNode.offsetHeight<30)otab.parentNode.style.height="30px";
    }
}
function ProductQuantity(squantity,stype,sorderid,sboxesid,sminorderid,sminboxesid,stotalorderid,stotalpriceid){
    if(!/^\d+$/.test(squantity)){
        alert("The number format is wrong.");
        return;
    }
    //wait
    var owait=$(sboxesid);
    if(!owait){
        alert("System error.");
        return;
    }
    var oawait=owait.parentNode.getElementsByTagName("a");
    var oimgwait=owait.parentNode.getElementsByTagName("img");
    if(!oawait||!oimgwait){
        alert("System error.");
        return;
    }
    oawait[0].style.display="none";
    oimgwait[0].style.display="inline";
    
    var arg1=String.format("{0},{1}",squantity,stype);
    var arg2=String.format("{0},{1},{2},{3},{4},{5}",sorderid,sboxesid,sminorderid,sminboxesid,stotalorderid,stotalpriceid);
    _productQuantity(arg1,arg2);
}
function ProductQuantityAsync(result,context){
    var argids=context.split(",");
    if(!argids||argids.length<=0){
        alert("System error.");
        return;
    }
    var oawait=$(argids[1]).parentNode.getElementsByTagName("a");
    var oimgwait=$(argids[1]).parentNode.getElementsByTagName("img");
    if(!oawait||!oimgwait){
        alert("System error.");
        return;
    }
    oawait[0].style.display="inline";
    oimgwait[0].style.display="none";
    
    if(result){
        if(result=="2"){
            alert("You must input integer number.");
            return;
        }
        if(result=="3"){
            alert("The number format is wrong.");
            return;
        }
        if(result=="4"){
            alert("The number out of stock.");
            return;
        }
        if(result=="5"){
            alert("Input quantity does not meet the minimum quantity requirement, please re-enter.");
            return;
        }
    
        var array=result.split("|");
        if(array&&array.length>=0)
            for(var i=0;i<array.length;i++){
                if(i<2) $(argids[i]).value=array[i];
                else $(argids[i]).innerHTML=array[i];
            }
                
    }
    else alert("operation failure.");
}

function ProductCalculateArea(fwidth,fheight,fboxsqft){
    var region=$("CalculateRegion");
    if(!region)return;
    region.style.display="block";
    if(IEXPLORER)region.style.paddingTop="7px";
    else region.style.top="-1px";
    $("CalculateConfirm").onclick=function(){
        var fwidtharea=parseFloat($("InpWidth").value)+parseFloat($("SelWidth").value)/12
        var fheightarea=parseFloat($("InpHeight").value)+parseFloat($("SelHeight").value)/12
        var ftotalsqft=fwidtharea*fheightarea;
        var ftotalsheet=Math.ceil(ftotalsqft/(fwidth*fheight));
        var ftotalbox=Math.ceil(ftotalsqft/fboxsqft);
        $("SpnSqft").innerHTML=isNaN( ftotalsqft)?0:ftotalsqft.toFixed(2);
        $("SpnSheet").innerHTML=isNaN(ftotalsheet)?0:ftotalsheet;
        $("SpnBox").innerHTML=isNaN(ftotalbox)?0:ftotalbox;
    };
    $("CalculateCancel").onclick=function(){region.style.display="none";};
}

function SurchAFavorite(ipid){
    var stotalpid=CookieUtil.getCookie("REFavoriteIds");//alert(stotalpid);return false;
    var value=[];
    if(!stotalpid)value.push(ipid);
    else {
        value=stotalpid.split(",");
        if(value.indexOf(ipid)==-1)
            value.push(ipid);
    }
    CookieUtil.setCookie("REFavoriteIds",value.join(","),new Date("Dec 30, 2019"),"/");
    if(confirm("item added to wish list.\r\ndo you want to go wish list?"))
        location.href=SITEURL+"favorite.aspx";
}
function TellAFriendProduct(){
    var sb=new StringBuilder();
    sb.append("<label class=\"tellafriendlabel\">Your Name: <input id=\"inputName\" type=\"text\" class=\"tbxCss\" style=\"margin-left:45px\" /> <span>*</span></label>");
    sb.append("<label class=\"tellafriendlabel\">Your Email: <input id=\"inputEmail\" type=\"text\" class=\"tbxCss\" style=\"margin-left:47px\" /> <span>*</span></label>");
    sb.append("<label class=\"tellafriendlabel\">Your Friend's Email: <input id=\"inputEmail1\" type=\"text\" class=\"tbxCss\" /> <span>*</span></label>");
    sb.append("<ul class=\"tellafriendul\"><li style=\"float:left\">");
    sb.appendFormat("<img id=\"imgWait\" src=\"{0}images/re/be-wait.jpg\" style=\"display:none\"/>",LIBRARYURL);
    sb.append("<input class=\"btnCss\" id=\"inputTellAFriendBtn1\" type=\"button\" value=\"Send\" /></li>");
    sb.append("<li style=\"float:right\"><input class=\"btnCss\" id=\"inputTellAFriendBtn2\" type=\"button\" value=\"Cancel\" /></li></ul>");
    sb.append("<div class=\"clear\"></div>");
    
    var oLayer=LayerShield();
    var oRegion=LayerTable("Tell a Friend Product",sb.toString());
    oRegion.style.width="275px";
    oRegion.style.left="50%";
    oRegion.style.marginLeft="-137px";
    oRegion.style.top=document.documentElement.scrollTop+175+"px";
    
    var obtn=$("inputTellAFriendBtn1");
    obtn.focus();
    
    obtn.onclick=function(){
        var name=$("inputName").value.trim();
        var email=$("inputEmail").value.trim();
        var femail=$("inputEmail1").value.trim();
        if(!name||!email||!femail)
        {alert("input box is not null.");return false;}
        var emailReg=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
        if(!emailReg.test(email)||!emailReg.test(femail))
        {alert("email format wrong.");return false;}
        
        EventUtil.getEvent().target.style.display="none";
        $("imgWait").style.display="inline";
        
        _tellAFriend(String.format("{0},{1},{2}",name,email,femail),oRegion);
    };
    $("inputTellAFriendBtn2").onclick=function(){
        document.body.removeChild(oLayer);
        document.body.removeChild(oRegion);
    };
    
    document.body.onkeypress=function(){
        var e=EventUtil.getEvent();
        if(e.charCode==13)obtn.click();
    }
}
function TellAFriendAsync(result,context){
    $("inputTellAFriendBtn1").style.display="inline";
    $("imgWait").style.display="none";
    if(result=="1"){
        alert("email is on its way, thank you for sharing!");
        document.body.removeChild(context);
        document.body.removeChild($("divShieldLayer"));
    }
    else switch(result){
        case "-1":{alert("send email failure");break;}
        case "2":{alert("input error.");break;}
        case "3":{alert("can not find out the email server.");break;}
        default:{alert("system error.");break;}
    }
}
function BulkOrderContactUs(ssqft, imin,istock){
    var sb=new StringBuilder();
    sb.append("<h5 style=\"margin:10px 0px;color:#9f0609\">For special order, please provide us following info</h5>");
    sb.append("<div style=\"color:#999999;font-size:11px\">We will quote you the final delivered price based on your info within 24 hours.</div>");
    sb.appendFormat("<label class=\"bulkorderlabel\">Quantity: <input id=\"inpQuantity\" type=\"text\" class=\"tbxCss\" style=\"margin-left:40px;width:80px\"/> {0} <span>*not less than {1}</span></label>",ssqft,imin);
    sb.append("<label class=\"bulkorderlabel\">Ship to Country: <input id=\"inpCountry\" type=\"text\" class=\"tbxCss\"/> <span>*</span></label>");
    sb.append("<label class=\"bulkorderlabel\">Shipp to State: <input id=\"inpState\" type=\"text\" class=\"tbxCss\" style=\"margin-left:7px\"/> <span>*</span></label>");
    sb.append("<label class=\"bulkorderlabel\">Phone: <input id=\"inpPhone\" type=\"text\" class=\"tbxCss\" style=\"margin-left:50px\"/> <span>*</span></label>");
    sb.append("<label class=\"bulkorderlabel\">Email: <input id=\"inpEmail\" type=\"text\" class=\"tbxCss\" style=\"margin-left:54px\"/></label>");
    sb.append("<label class=\"bulkorderlabel\">Comment: <textarea id=\"taaComment\" class=\"tbxCss\" cols=\"25\" style=\"margin-left:30px\"></textarea></label>");
    sb.append("<ul class=\"bulkorderul\"><li style=\"float:left\">");
    sb.appendFormat("<img id=\"imgWait\" src=\"{0}images/re/be-wait.jpg\" style=\"display:none\"/>",LIBRARYURL);
    sb.append("<input class=\"btnCss\" id=\"inputBulkOrderBtn1\" type=\"button\" value=\"Submit\" /></li>");
    sb.append("<li style=\"float:right\"><input class=\"btnCss\" id=\"inputBulkOrderBtn2\" type=\"button\" value=\"Cancel\" /></li></ul>");
    sb.append("<div class=\"clear\"></div>");
    
    var oLayer=LayerShield();
    var oRegion=LayerTable("Special Order",sb.toString());
    oRegion.style.width="350px";
    oRegion.style.left="50%";
    oRegion.style.marginLeft="-175px";
    oRegion.style.top=document.documentElement.scrollTop+75+"px";
    
    var obtn=$("inputBulkOrderBtn1");
    obtn.focus();
    
    $("inputBulkOrderBtn1").onclick=function(){
        var quantity=$("inpQuantity").value;
        var country=$("inpCountry").value;
        var state=$("inpState").value;
        var phone=$("inpPhone").value;
        var email=$("inpEmail").value;
        var comment=$("taaComment").value;
        if(isNaN(quantity)){alert("quantity format is wrong and not null.");return false;}
        if(parseFloat(quantity)<imin){alert(String.format("quantity is not less than {0}.",imin));return false;}
        if(!quantity){alert("quantity is not null.");return false;}
        if(!country){alert("country is not null.");return false;}
        if(!state){alert("state is not null.");return false;}
        if(!phone){alert("phone is not null.");return false;}
        if(!email)email="email";
        if(!comment)comment="comment";
        
        EventUtil.getEvent().target.style.display="none";
        $("imgWait").style.display="inline";
        var args=String.format("{0}<|>{1}<|>{2}<|>{3}<|>{4}<|>{5}",quantity,country,state,phone,email,comment);
        _bulkOrder(args,oRegion);
    };
    
    $("inputBulkOrderBtn2").onclick=function(){
        document.body.removeChild(oLayer);
        document.body.removeChild(oRegion);
    };
    
    document.body.onkeypress=function(){
        var e=EventUtil.getEvent();
        if(e.charCode==13)obtn.click();
    }
}
function BulkOrderAsync(result,context){
    $("inputBulkOrderBtn1").style.display="inline";
    $("imgWait").style.display="none";
    if(result=="1"){
        alert("email is on its way.");
        document.body.removeChild(context);
        document.body.removeChild($("divShieldLayer"));
    }
    else switch(result){
        case "-1":{alert("send email failure");break;}
        case "2":
        case "3":{alert("input error.");break;}
        case "4":{alert("can not find out the email server.");break;}
        default:{alert("system error.");break;}
    }
}
function BulkOrderMore(){
    var region=$("BulkOrderMore");
    if(!region)return false;

    if(!region.style.display||region.style.display=="none")
        region.style.display="block";
    else region.style.display="none";
    
  /*  if(IEXPLORER)region.style.width="93%";
    else{
        region.style.left="-1px";
        region.style.width="97.8%";
    }*/
}

/* rss */
function SHRssFeed(ospan,show){
    var otab=ospan.getElementsByTagName("table");
    if(!otab||otab.length<=0)return false;
    if(show)otab[0].style.display="inline";
    else otab[0].style.display="none";
}