﻿// JScript File

var sep = ":::::";
var ua = navigator.userAgent;
var current_X,current_Y;
var dom = (document.getElementById) ? true : false;
var ie4 = (document.all && !dom) ? true : false;
var ie5_5 = ((ua.indexOf("MSIE 5.5")>=0 || ua.indexOf("MSIE 6")>=0) && ua.indexOf("Opera")<0) ? true : false;
var ns4 = (document.layers && !dom) ? true : false;

onerror = function(err,url,l){
    alert(err + " at line " + l);
    return true;
}

function selectEdge(Radid, Details){
    var Otherrads = Getelement("hdnEdgeRadioButtons").value;
    var Otherradids = Otherrads.split(sep);
    var i = 0;
    for(i=0;i<Otherradids.length;i++){
        if(Otherradids[i]!=Radid){
            var Otherrad = Getelement(Otherradids[i]);
            if(Otherrad!=null){
                Otherrad.checked = false;
            }
        }
    }
    var Radiobtn = Getelement(Radid);
    Radiobtn.checked = true;
    var SelEdgeId = Getelement("hdnSelectedEdge");
    var EdgeImage = Getelement("imgEdge");
    var Edgename = Getelement("spnEdgename");
    var EdgePrice = Getelement("txtEdgePrice");
    var EdgeDetails = Getelement(Details).value.split(sep);
    SelEdgeId.value = EdgeDetails[0];
    EdgeImage.src = EdgeDetails[2];
    Edgename.innerHTML = EdgeDetails[1];
    EdgePrice.value = EdgeDetails[4];
    setOptions();
}

function showDetails(Radid, Details, e){
    current_X = mouseX(e);
	current_Y = mouseY(e);
	var MaterialNSlabDetails = new Array();
	MaterialNSlabDetails = document.getElementById(Details).value.split("||||||");	
    var MaterialDetails = MaterialNSlabDetails[0].split(sep);
    if(MaterialNSlabDetails.length==2){
        showMaterialDetails(MaterialDetails[8], MaterialDetails[3], MaterialDetails[9], MaterialDetails[5], MaterialNSlabDetails[1]);
    }else{
        showMaterialDetails(MaterialDetails[8], MaterialDetails[3], MaterialDetails[9], MaterialDetails[5]);
    }
    selectMaterial(Radid, Details);
    //LoadSlabDetails(SampleId,display_slab,slabcount); 
}

function selectMaterial(Radid, Details){    
    var Otherrads = Getelement("hdnMaterialRadioButtons").value;
    var Otherradids = Otherrads.split(sep);
    var i = 0;
    for(i=0;i<Otherradids.length;i++){
        if(Otherradids[i]!=Radid){
            var Otherrad = Getelement(Otherradids[i]);
            if(Otherrad!=null){
                Otherrad.checked = false;
            }
        }
    }
    var Radiobtn = Getelement(Radid);
    Radiobtn.checked = true;
    var SelMaterialId = Getelement("hdnSelectedMaterial");
    var SelMaterialType = Getelement("hdnSelectedMaterialType");
    var CounterImage = Getelement("imgCountertop");
    var Countername = Getelement("spnCountername");
    var SplashImage = Getelement("imgBacksplash");
    var Splashname = Getelement("spnSplashname");
    var CounterPrice = Getelement("txtCountertopPrice");
    var SplashPrice = Getelement("txtSplashPrice");
    var MaterialDetails = Getelement(Details).value.split("||||||")[0].split(sep);
    SelMaterialId.value = MaterialDetails[0];
    SelMaterialType.vale = MaterialDetails[1];
    CounterImage.src = MaterialDetails[3];
    Countername.innerHTML = MaterialDetails[8];
    CounterPrice.value = MaterialDetails[10];
    SplashImage.src = MaterialDetails[3];
    Splashname.innerHTML = MaterialDetails[8];
    SplashPrice.value = MaterialDetails[11];
    setOptions();
}

function setOptions(){    
    var Total = 0;
    
    //by tham on 7 may
    /*// Setting Countertop Values
    Total += parseFloat(setCounterTotal("lblTotalInches","lblTotalCounterSQFT","txtCountertopPrice","lblCountertopSubtotal","hdnCounterSubtotals"));
    // Setting BackSplash Values
    Total += parseFloat(setCounterTotal("lblTotalSplashInches","lblTotalSplashSQFT","txtSplashPrice","lblSplashSubtotal","hdnSplashSubtotals"));
    // Setting Edge Values
    Total += parseFloat(setEdgeTotal("txtEdgeLength","lblTotalLength","txtEdgePrice","lblEdgeSubtotal"));*/
    //end comment
    // Setting Countertop Values
    Total += parseFloat(setCounterTotal("lblTotalInches","lblTotalCounterSQFT","txtCountertopPrice","lblCountertopSubtotal","hdnCounterSubtotals","txtTotalCounterSQFT","hdnCounterTopReset"));
    // Setting BackSplash Values
    Total += parseFloat(setCounterTotal("lblTotalSplashInches","lblTotalSplashSQFT","txtSplashPrice","lblSplashSubtotal","hdnSplashSubtotals","txtBackSplashSQFT","hdnBackSplashReset"));
    // Setting Edge Values
    Total += parseFloat(setEdgeTotal("txtEdgeLength","lblTotalLength","txtEdgePrice","lblEdgeSubtotal","txtTotalEdgeFeet"));
    //end by tham on 7 may
    
    // Setting Sink Hole options
    Total += parseFloat(setSink("txtStainlessQuantity","txtStainlessSteelPrice","divSSteelBump","txtSSteelBupPrice","radSSteelBumpYes","radSSteelBumpNo","lblSSteelSubTotal"));
    Total += parseFloat(setSink("txtCastIronQuantity","txtCastIronPrice","divCIronBump","txtCIronBumpPrice","radCIronBumpYes","radCIronBumpNo","lblCIronSubTotal"));
    Total += parseFloat(setSink("txtDropInQuantity","txtDropInPrice","divDropInBump","txtDropInBumpPrice","radDropInBumpYes","radDropInBumpNo","lblDropInSubTotal"));
    Total += parseFloat(setSink("txtFarmSinkQuantity","txtFarmSinkPrice","divFarmSinkBump","txtFarmSinkBumpPrice","radFarmSinkBumpYes","radFarmSinkBumpNo","lblFarmSinkSubTotal"));
    // Setting Faucet Hole Options
    Total += parseFloat(setPrice("txtFaucetQuantity","txtFaucetPrice","lblFaucetSubtotal"));
    Total += parseFloat(setPrice("txtSoapDispenserQuantity","txtSoapDispenserPrice","lblSoapDispenserSubtotal"));
    Total += parseFloat(setPrice("txtInstantHotQuantity","txtInstantHotPrice","lblInstantHotSubTotal"));
    Total += parseFloat(setPrice("txtSprayerQuantity","txtSprayerPrice","lblSprayerSubtotal"));
    Total += parseFloat(setPrice("txtOtherQuantity","txtOtherPrice","lblOtherSubTotal"));
    var FaucetCount = Getelement("lblFaucetTotalHoles");
    FaucetCount.innerHTML = SumOf("txtFaucetQuantity,txtSoapDispenserQuantity,txtInstantHotQuantity,txtSprayerQuantity,txtOtherQuantity",",");    
    // Setting Cooktop Options
    Total += parseFloat(setPrice("txtCooktopQuantity","txtCooktopPrice","lblCooktopSubtotal"));
    Total += parseFloat(setPrice("txtSlideinQuantity","txtSlideinPrice","lblSlideinSubtotal"));
    Total += parseFloat(setPrice("txtStoveQuantity","txtStovePrice","lblStoveSubtotal"));
    // Setting Radius Corner Options
    Total += parseFloat(setPrice("txtUpto3by4Quantity","txtUpto3by4Price","lblUpto3by4Subtotal"));
    Total += parseFloat(setPrice("txtUpto6Quantity","txtUpto6Price","lblUpto6Subtotal"));
    Total += parseFloat(setPrice("txtUpto18Quantity","txtUpto18Price","lblUpto18Subtotal"));
    Total += parseFloat(setPrice("txtUpto30Quantity","txtUpto30Price","lblUpto30Subtotal"));
    Total += parseFloat(setPrice("txtUpto42Quantity","txtUpto42Price","lblUpto42Subtotal"));
    // Setting Diagonal Corner cut Option
    Total += parseFloat(setPrice("txtDiagonalcutQuantity","txtDiagonalcutPrice","lblDiagonalcutSubtotal"));
    // Setting Outlet cut Option
    Total += parseFloat(setPrice("txtOutletCutQuantity","txtOutletCutPrice","lblOutletCutSubtotal"));    
    // Setting Extra, Discount, Removal Options
    Total += parseFloat(setPrice("txtExtrasPrice","hdnExtraMultiplier","lblExtraSubtotal"));
    Total -= parseFloat(setPrice("txtDiscountPrice","hdnDiscountMultiplier","lblDiscountSubtotal"));
    Total += parseFloat(setRemoval());
    Total += parseFloat(setTilesRemoval());
    // Setting total Value
    var TotalComp = Getelement("lblTotal");
    TotalComp.innerHTML = round_of(Total,2);
}

function ResetPrices(){
    Getelement("txtCountertopPrice").value = "";
    Getelement("txtSplashPrice").value = "";
    Getelement("txtEdgePrice").value = "";
    Getelement("txtStainlessSteelPrice").value = "";
    Getelement("txtSSteelBupPrice").value = "";
    Getelement("txtCastIronPrice").value = "";
    Getelement("txtCIronBumpPrice").value = "";
    Getelement("txtDropInPrice").value = "";
    Getelement("txtDropInBumpPrice").value = "";
    Getelement("txtFarmSinkPrice").value = "";
    Getelement("txtFarmSinkBumpPrice").value = "";
    Getelement("txtFaucetPrice").value = "";
    Getelement("txtSoapDispenserPrice").value = "";
    Getelement("txtInstantHotPrice").value = "";
    Getelement("txtSprayerPrice").value = "";
    Getelement("txtOtherPrice").value = "";
    Getelement("txtCooktopPrice").value = "";
    Getelement("txtSlideinPrice").value = "";
    Getelement("txtStovePrice").value = "";
    Getelement("txtUpto3by4Price").value = "";
    Getelement("txtUpto6Price").value = "";
    Getelement("txtUpto18Price").value = "";
    Getelement("txtUpto30Price").value = "";
    Getelement("txtUpto42Price").value = "";
    Getelement("txtDiagonalcutPrice").value = "";
    Getelement("txtOutletCutPrice").value = "";
    Getelement("txtExtrasPrice").value = "";
    Getelement("txtDiscountPrice").value = "";
    Getelement("txtRemovalPrice").value = "";
    Getelement("txtTileRemovalPrice").value = ""; 
    setOptions();
}

function SumOf(strControls,seperator){
    var ControlIds = strControls.split(seperator);
    var Count = 0;
    for(i=0;i<ControlIds.length;i++){
        var Control = Getelement(ControlIds[i]);
        if(Control!=null){
            var ContVal = 0;
            if(Control.value){
                ContVal = Control.value;                
            }else if(Control.innerHTML){
                ContVal = Control.innerHTML;                
            }
            if(ContVal=="" || isNaN(ContVal)){
                ContVal = 0;
            }
            Count = parseFloat(Count) + parseFloat(ContVal);
        }
    }
    return Count;
}

function setEdgesNMaterialDetails(){
    var Otherrads = Getelement("hdnEdgeRadioButtons").value + Getelement("hdnMaterialRadioButtons").value;
    var Otherradids = Otherrads.split(sep);
    var i = 0;
    for(i=0;i<Otherradids.length;i++){        
      var Otherrad = Getelement(Otherradids[i]);
      if(Otherrad!=null){
        if(Otherrad.checked){
            Otherrad.onclick();            
        }
      }
    }
}

function checkKey(keynum,type){
    var keychar;
    var numcheck;
    if(keynum!=0 && keynum!=8){
        keychar = String.fromCharCode(keynum);
        numcheck = /[0-9]/;
        if(type=="price"){
            numcheck = /[0-9.]/;
        }
        return numcheck.test(keychar);
    }else{
        return true;
    }
}

function setEdgeTotal(txtLength,lbltotlen,txtedgprice,lbledgsubtotal,txtTotlnftId){    
    var LengthCont = Getelement(txtLength);
    var TotLengthCont = Getelement(lbltotlen);
    var PriceCont = Getelement(txtedgprice);
    var SubtotalCont = Getelement(lbledgsubtotal);
    
    var txtTotLnft = Getelement(txtTotlnftId);
    if(txtTotLnft.reset == null){
        txtTotLnft.reset = false;
    }
    if(txtTotLnft.onkeyup==null){
        txtTotLnft.onkeyup = function(){
            txtTotLnft.reset = true;
            setOptions();
        }    
    }
    if(txtTotLnft.onkeypress==null){
        txtTotLnft.onkeypress = function(e){
            var keynum;
            if(window.event){keynum = window.event.keyCode;}else if(e.which){keynum = e.which;}
            return checkKey(keynum,"price");
        }
    }
    
    if(LengthCont.onkeyup==null){
        LengthCont.onkeyup = function(){
            txtTotLnft.reset = false;
            setOptions();
        }
    }
    if(PriceCont.onkeyup==null){
        PriceCont.onkeyup = setOptions;
    }
    if(LengthCont.onkeypress==null){
        LengthCont.onkeypress = function(e){
            var keynum;
            if(window.event){keynum = window.event.keyCode;}else if(e.which){keynum = e.which;}
            return checkKey(keynum,"price");
        }
    }
    if(PriceCont.onkeypress==null){
        PriceCont.onkeypress = function(e){            
            var keynum;
            if(window.event){keynum = window.event.keyCode;}else if(e.which){keynum = e.which;}
            return checkKey(keynum,"price");            
        }
    }
    
    //by tham on 13 may
    if(txtTotLnft.onfocus==null){
        txtTotLnft.onfocus = function(){
            setTxtFocus(this);
        }
    }
    if(txtTotLnft.onblur==null){
        txtTotLnft.onblur = function(){
            setTxtBlur(this);
        }
    }
    if(LengthCont.onfocus==null){
        LengthCont.onfocus = function(){
            setTxtFocus(this);
        }
    }
    if(LengthCont.onblur==null){
        LengthCont.onblur = function(){
            setTxtBlur(this);
        }
    }
    if(PriceCont.onfocus==null){
        PriceCont.onfocus = function(){
            setTxtFocus(this);
        }
    }
    if(PriceCont.onblur==null){
        PriceCont.onblur = function(){
            setTxtBlur(this);
        }
    }
    //end by tham on 13 may
    
    var Price = PriceCont.value;
    if(Price=="" || Price <=0){
        Price = 0;
    }
    var Length ;
    
    if(txtTotLnft.reset == true){
        Length = parseFloat(txtTotLnft.value)*12;
    }else{
        Length = LengthCont.value;
    }
    
    if(Length=="" || Length <= 0){
        Length = 0;
    }
    var pricesub = 0;
    pricesub = (parseFloat(Length)/12);
    TotLengthCont.innerHTML = round_of(pricesub,2);
    SubtotalCont.innerHTML = round_of(parseFloat(pricesub) * parseFloat(Price),2);
    
    if(txtTotLnft.reset == true){
        LengthCont.value = round_of(pricesub*12,2);
    }else{
        txtTotLnft.value = round_of(pricesub,2);
    }
    
    return (parseFloat(pricesub) * parseFloat(Price));
}
//end by tham on 7 may


function setCounterTotal(lblTotinches,lblTotsqft,txtPrice,lblsubtotal,subtotalname,txtTotsqftId,hdnResetId){
    var Labels = document.getElementsByTagName("SPAN");
    var TotInches = Getelement(lblTotinches);
    var Totsqft = Getelement(lblTotsqft);
    var Price = Getelement(txtPrice);
    var subtotal = Getelement(lblsubtotal);
    if(Price.onkeypress==null){
        Price.onkeypress = function(e){
            var keynum;
            if(window.event){keynum = window.event.keyCode;}else if(e.which){keynum = e.which;}
            return checkKey(keynum,"price");
        }
    }
    if(Price.onkeyup==null){
        Price.onkeyup = setOptions;
    }
    
    //by tham on 13 may
    if(Price.onfocus==null){
        Price.onfocus = function(){
            setTxtFocus(this);
        }
    }
    if(Price.onblur==null){
        Price.onblur = function(){
            setTxtBlur(this);
        }
    }
    //end by tham on 13 may
    
    var txtTotsqft = Getelement(txtTotsqftId);
    var hdnReset = Getelement(hdnResetId);    
    txtTotsqft.onfocus = function(){
        this.valueOnFocus = this.value.trim();
        //by tham on 13 may
        setTxtFocus(this);
        //end by tham on 13 may
    }
    txtTotsqft.onblur = function(){
        var curV = this.value.trim();
        if(isNumber(curV)){
            if(isNumber(this.valueOnFocus)){
                if(parseFloat(curV) != 0){
                    if(parseFloat(curV) != parseFloat(this.valueOnFocus)){
                        ResetSqInchesOption(subtotalname);
                        hdnReset.value = "1";
                        setOptions();
                    }
                }else{
                    this.value = this.valueOnFocus;
                }
            }
        }else{
            this.value = this.valueOnFocus;
        }
        //by tham on 13 may
        setTxtBlur(this);
        //end by tham on 13 may
    }
    
    var _TotalInches = 0;
    TotInches.innerHTML = 0;   
    var Subclientids = Getelement(subtotalname).value;
    var Clientids = Subclientids.split(sep); 
    var j = 0;
    for(j=0;j<Clientids.length;j++){        
        var Rowcontrols = Clientids[j].split(":::");
        var LenId = Rowcontrols[0];
        var WidId = Rowcontrols[1]; 
        var TotId = Rowcontrols[2];
        var LenCont = Getelement(LenId);
        var WidCont = Getelement(WidId);
        var TotCont = Getelement(TotId);        
        if(TotCont!=null && WidCont!=null && LenCont!=null){
            if(LenCont.onkeypress==null){
                LenCont.onkeypress = function(e){
                    var keynum;
                    if(window.event){keynum = window.event.keyCode;}else if(e.which){keynum = e.which;}
                    return checkKey(keynum,"price");
                }
            }
            if(LenCont.onkeyup==null){
                LenCont.onkeyup = function(){
                    hdnReset.value = "0";
                    setOptions();
                }    
            }
            if(WidCont.onkeypress==null){
                WidCont.onkeypress = function(e){
                    var keynum;
                    if(window.event){keynum = window.event.keyCode;}else if(e.which){keynum = e.which;}
                    return checkKey(keynum,"price");
                }
            }
            if(WidCont.onkeyup==null){
                WidCont.onkeyup = function(){
                    hdnReset.value = "0";
                    setOptions();
                }
            }
            
            //by tham on 13 may
            if(LenCont.onfocus==null){
                LenCont.onfocus = function(){
                    setTxtFocus(this);
                }
            }
            if(LenCont.onblur==null){
                LenCont.onblur = function(){
                    setTxtBlur(this);
                }
            }
            if(WidCont.onfocus==null){
                WidCont.onfocus = function(){
                    setTxtFocus(this);
                }
            }
            if(WidCont.onblur==null){
                WidCont.onblur = function(){
                    setTxtBlur(this);
                }
            }
            //end by tham on 13 may
            
            var Length = LenCont.value;
            var Width = WidCont.value;
            if(Length=="" || Length <= 0){
                Length = 0;
            }
            if(Width=="" || Width <= 0){
                Width = 0;
            }
            TotCont.innerHTML = parseFloat(Length) * parseFloat(Width);
            TotCont.innerHTML = round_of(TotCont.innerHTML,2);
            if(TotCont.innerHTML!="" && TotCont.innerHTML > 0){
                _TotalInches += (parseFloat(Length) * parseFloat(Width));                
            }
        }
    }
    if(hdnReset.value == "1"){
        _TotalInches = parseFloat(txtTotsqft.value)*144;
    }
    
    TotInches.innerHTML = parseFloat(_TotalInches);
    Totsqft.innerHTML = parseFloat(TotInches.innerHTML)/144;
    txtTotsqft.value = parseFloat(TotInches.innerHTML)/144;
    var Priceval = Price.value;
    if(Price.value=="" || Price.value <= 0){
        Priceval = 0;
    }
    subtotal.innerHTML = parseFloat(Totsqft.innerHTML) * parseFloat(Priceval);
    subtotal.innerHTML = round_of(subtotal.innerHTML,2);
    Totsqft.innerHTML = round_of(Totsqft.innerHTML,2);
    TotInches.innerHTML = round_of(TotInches.innerHTML,2);
    txtTotsqft.value = round_of(txtTotsqft.value,2);
    return ((parseFloat(_TotalInches)/144) * parseFloat(Priceval));
}
//end by tham on 7 may

function setRemoval(){
    var RemoveYes, RemoveNo;
    RemoveYes = Getelement("radRemovalYes");
    RemoveNo = Getelement("radRemovalNo");
    var RemovePrice = Getelement("txtRemovalPrice");
    var RemoveSubtotal = Getelement("lblRemovalSubtotal");
    RemoveSubtotal.innerHTML = 0.00;
    if(RemoveYes!=null &&  RemoveNo!=null && RemovePrice!=null && RemoveSubtotal!=null){
        if(RemoveYes.onclick==null){
            RemoveYes.onclick = setOptions;
        }
        if(RemoveNo.onclick==null){
            RemoveNo.onclick = setOptions;
        }
        if(RemovePrice.onkeyup==null){
            RemovePrice.onkeyup = setOptions;
        }
        if(RemovePrice.onkeypress==null){
            RemovePrice.onkeypress = function(e){
            var keynum;
            if(window.event){keynum = window.event.keyCode;}else if(e.which){keynum = e.which;}
            return checkKey(keynum,"price");
        }
        }
        
        //by tham on 13 may
        if(RemovePrice.onfocus==null){
            RemovePrice.onfocus = function(){
                setTxtFocus(this);
            }
        }
        if(RemovePrice.onblur==null){
            RemovePrice.onblur = function(){
                setTxtBlur(this);
            }
        }
        //end by tham on 13 may
        
        if(!RemoveYes.checked && !RemoveNo.checked){
            RemoveNo.checked = true;
        }
        var RemovalPrice = RemovePrice.value;
        if(RemovalPrice=="" || RemovalPrice<=0 || RemoveNo.checked){
            RemovalPrice = 0;
        }
        RemoveSubtotal.innerHTML = round_of(parseFloat(RemovalPrice),2);        
    }
    return round_of(parseFloat(RemovalPrice),2);
}

function setTilesRemoval()
{
    var ExceptRemoveYes, TilesRemoveNo;
    TilesRemoveYes = Getelement("radTileRemovalYes");
    TilesRemoveNo = Getelement("radTileRemovalNo");
    var TilesRemovePrice = Getelement("txtTileRemovalPrice");
    var TilesRemoveSubtotal = Getelement("lblTileRemovalSubtotal");    
    if(TilesRemoveYes!=null &&  TilesRemoveNo!=null && TilesRemovePrice!=null && TilesRemoveSubtotal!=null){        
        TilesRemoveSubtotal.innerHTML = 0.00;
        if(TilesRemoveYes.onclick==null){
            TilesRemoveYes.onclick = setOptions;
        }
        if(TilesRemoveNo.onclick==null){
            TilesRemoveNo.onclick = setOptions;
        }
        if(TilesRemovePrice.onkeyup==null){
            TilesRemovePrice.onkeyup = setOptions;
        }
        if(TilesRemovePrice.onkeypress==null){
            TilesRemovePrice.onkeypress = function(e){
                var keynum;
                if(window.event){keynum = window.event.keyCode;}else if(e.which){keynum = e.which;}
                return checkKey(keynum,"price");
            }
        }
        
        //by tham on 13 may
        if(TilesRemovePrice.onfocus==null){
            TilesRemovePrice.onfocus = function(){
                setTxtFocus(this);
            }
        }
        if(TilesRemovePrice.onblur==null){
            TilesRemovePrice.onblur = function(){
                setTxtBlur(this);
            }
        }
        //end by tham on 13 may
        
        if(!TilesRemoveYes.checked && !TilesRemoveNo.checked){
            TilesRemoveNo.checked = true;
        }
        var TilesRemovalPrice = TilesRemovePrice.value;
        if(TilesRemovalPrice=="" || TilesRemovalPrice<=0 || TilesRemoveNo.checked){
            TilesRemovalPrice = 0;
        }
        TilesRemoveSubtotal.innerHTML = round_of(parseFloat(TilesRemovalPrice),2);        
    }
    return parseFloat(TilesRemovalPrice);
}

function setPrice(txtQty,txtPrice,lblSubTotal){
    var Qty = Getelement(txtQty);
    var Price = Getelement(txtPrice);
    var Subtotal = Getelement(lblSubTotal);
    Subtotal.innerHTML = "0.00";
    if(Qty!=null && Price!=null && Subtotal!=null){
        if(Qty.onkeyup==null){
            Qty.onkeyup = setOptions;
        }
        if(Qty.onkeypress==null){
            Qty.onkeypress = function(e){
            var keynum;
            if(window.event){keynum = window.event.keyCode;}else if(e.which){keynum = e.which;}
            return checkKey(keynum,"int");
        }
        }
        if(Price.onkeyup==null){
            Price.onkeyup = setOptions;
        }
        if(Price.onkeypress==null){
            Price.onkeypress =function(e){
            var keynum;
            if(window.event){keynum = window.event.keyCode;}else if(e.which){keynum = e.which;}
            return checkKey(keynum,"price");
        }
        }
        
        //by tham on 13 may
        if(Qty.onfocus==null){
            Qty.onfocus = function(){
                setTxtFocus(this);
            }
        }
        if(Qty.onblur==null){
            Qty.onblur = function(){
                setTxtBlur(this);
            }
        }
        if(Price.onfocus==null){
            Price.onfocus = function(){
                setTxtFocus(this);
            }
        }
        if(Price.onblur==null){
            Price.onblur = function(){
                setTxtBlur(this);
            }
        }
        //end by tham on 13 may
        
        var Quantity = Qty.value;
        var HolePrice = Price.value;
        if(Quantity=="" || Quantity<=0){
            Quantity = 0;            
        }
        if(HolePrice=="" || HolePrice<=0){
            HolePrice = 0;            
        }        
        Subtotal.innerHTML = round_of((parseFloat(Quantity) * parseFloat(HolePrice)),2);
    }
    return (parseFloat(Quantity) * parseFloat(HolePrice));
}

function setSink(txtQty,txtPrice,divBump,txtBumpPrice,radBumpyes,radBumpno,lblSubtotal){
    var Qty = Getelement(txtQty);
    var Price = Getelement(txtPrice);
    var Bump = Getelement(divBump);
    var BumpPrice = Getelement(txtBumpPrice);
    var BumpYes = Getelement(radBumpyes);
    var BumpNo = Getelement(radBumpno);
    var Subtotal = Getelement(lblSubtotal);
    Subtotal.innerHTML = 0.00;
    if(Qty!=null && Price!=null && Bump!=null && BumpPrice!=null && BumpYes!=null && BumpNo!=null && Subtotal!=null){            
        if(Qty.onkeyup==null){
            Qty.onkeyup = setOptions;
        }
        if(Qty.onkeypress==null){
            Qty.onkeypress = function(e){
            var keynum;
            if(window.event){keynum = window.event.keyCode;}else if(e.which){keynum = e.which;}
            return checkKey(keynum,"int");
        }
        }
        if(Price.onkeyup==null){
            Price.onkeyup = setOptions;
        }
        if(Price.onkeypress==null){
            Price.onkeypress  = function(e){
            var keynum;
            if(window.event){keynum = window.event.keyCode;}else if(e.which){keynum = e.which;}
            return checkKey(keynum,"price");
        }
        }
        if(BumpPrice.onkeyup==null){
            BumpPrice.onkeyup = setOptions;
        }
        if(BumpPrice.onkeypress==null){
            BumpPrice.onkeypress = function(e){
            var keynum;
            if(window.event){keynum = window.event.keyCode;}else if(e.which){keynum = e.which;}
            return checkKey(keynum,"price");
        }
        }
        if(BumpYes.onclick==null){
            BumpYes.onclick = setOptions;
        }
        if(BumpNo.onclick==null){
            BumpNo.onclick = setOptions;
        }
        
        //by tham on 13 may
        if(Qty.onfocus==null){
            Qty.onfocus = function(){
                setTxtFocus(this);
            }
        }
        if(Qty.onblur==null){
            Qty.onblur = function(){
                setTxtBlur(this);
            }
        }
        if(Price.onfocus==null){
            Price.onfocus = function(){
                setTxtFocus(this);
            }
        }
        if(Price.onblur==null){
            Price.onblur = function(){
                setTxtBlur(this);
            }
        }
        if(BumpPrice.onfocus==null){
            BumpPrice.onfocus = function(){
                setTxtFocus(this);
            }
        }
        if(BumpPrice.onblur==null){
            BumpPrice.onblur = function(){
                setTxtBlur(this);
            }
        }
        //end by tham on 13 may
        
        var Quantity = Qty.value;
        var SinkPrice = Price.value;
        var BumpPr = BumpPrice.value;
        if(Quantity=="" || Quantity <= 0){
            Quantity = 0;
        }
        if(BumpPr=="" || BumpPr <=0){
            BumpPr = 0;
        }
        if(SinkPrice=="" || SinkPrice <= 0){
            SinkPrice = 0;
        }
        var subprice = 0;
        if(Quantity > 0){
            Bump.style.display = "block";
            subprice = parseFloat(Quantity) * parseFloat(SinkPrice);
            Subtotal.innerHTML = subprice;
            if(BumpPr > 0){
                if(BumpYes.checked){
                    subprice = parseFloat(subprice) + parseFloat(BumpPr);
                }
            }
        }else{
            Bump.style.display = "none"
            BumpNo.checked = true;
            BumpYes.checked = false;
        }
        Subtotal.innerHTML = round_of(subprice,2);
    }    
    return subprice;
}

function Getelement(ElementId){
    return document.getElementById(ElementId);
}

function round_of(input, decchars){
	var multiplier = 1;
	if(input=="undefined" || input==null || input=="" || isNaN(input)){
	    input = 0;
    }
	for(i=0;i<decchars;i++){
	    multiplier = parseFloat(multiplier) * 10;					
	}
	input = parseFloat(input) * parseFloat(multiplier);
	input = Math.round(input);
	var In = input;
	var output = parseFloat(In)/multiplier;
	In = "" + output + "";
	if(In.indexOf(".")==-1){
		In = In + ".0";
	}
	var decnums = In.split(".");
	var secondpart = "";
	for(j=0;j<decchars;j++){
		if(!isNaN(decnums[1].charAt(j)) && decnums[1].charAt(j)!=""){
	    	secondpart = secondpart + decnums[1].charAt(j);
		}else{
		    secondpart = secondpart + "0";
		}
	}
	output = decnums[0] + "." + secondpart;
	return output;
}

function showMaterialDetails(tname, timg, txt, perma, SlabDetails) {    
    var wordings = "<table cellpadding=\"1\" cellspacing=\"1\" width=\"300\">";
    wordings += "<tr><td align=\"right\">";
    wordings += "<a class=\"footer_menu\" href=\'javascript:hmhidePopup()\'>";
    wordings += "<span><font face=\"verdana\" size=\"2\">X</font></span>";
    wordings += "</a></td></tr>";
    wordings += "<tr><td align=\"center\">";
    wordings += "<div id=\"loader_container\">";
    wordings += "   <div id=\"loader\">";
    wordings += "       <div align=\"center\">Loading Image...</div>";
    wordings += "       <div id=\"loader_bg\" class=\"lbg\">";
    wordings += "           <div id=\"progress\" class=\"pbg\"> </div>";
    wordings += "       </div>";
    wordings += "   </div>";
    wordings += "</div>";
    wordings += "<img onload=\"javascript:remove_loading();\" onError=\"javascript:remove_loading();\" src=\"";
    
    var word = "\" height=\"150\" width=\"150\" border=\"0\">";
    word += "</td></tr>";
    word += "<tr><td align=\"center\" style=\"color:#81BF46;font-family:Verdana;font-size:13pt;font-weight:bold;\">";    
    
	var wordings1 = "</td></tr>";
	wordings1 += "<tr><td height=\"150\">";
	wordings1 += "<div id=\"aa\" style=\"BORDER-RIGHT: #ffffff 1px solid; PADDING-RIGHT: 2px; BORDER-TOP: #ffffff 1px solid; PADDING-LEFT: 2px; PADDING-BOTTOM: 2px; overflow-x:hidden; OVERFLOW: auto; BORDER-LEFT: #ffffff 1px solid; WIDTH: 300px; height:100%; PADDING-TOP: 2px; BORDER-BOTTOM: #ffffff 1px solid; \" class=\"scrolldiv defaultFont\" align=\"left\">";	
	
	var wordings2 = "<div align=\"center\"><br />";	
	wordings2 += "<a href=\"../PermaShield.htm?type=1&sid=s0pm04bdfd4rms55ryztl145\">";	
	wordings2 += "<img src=\"../Logo/PermaShield_AntiStain_Logo.jpg\" border=\"0\">";
	wordings2 += "</a>";
	wordings2 += "</div>";
	wordings2 += "<br />";
	wordings2 += "<div id=\"perma\">";
	wordings2 += "<TABLE style=\"BORDER-COLLAPSE: collapse\" bgcolor=\"#F8F8F8\" borderColor=\"#8F8F8F\" cellSpacing=\"2\" cellPadding=\"2\" border=\"1\">";
	wordings2 += "<TR><TD class=\"txt1\">";
	wordings2 += "<B><a class=\"home_header\" href=\"../PermaShield.htm?type=1&sid=s0pm04bdfd4rms55ryztl145\">PermaShield</a></B> ";
	wordings2 += "Protected and offers a FREE 15 Yr. Limited Warranty against staining &amp; material integrity.<br />";
	wordings2 += "<B><font color=#ff0000>Note:</font></B> For stains caused by Food &amp; Beverages.";
	wordings2 += "</TD></TR>";
	wordings2 += "</TABLE></div>"
	
	var wordings2_1 = "<div align=\"center\"><br />";	
	wordings2_1 += "<div id=\"perma\">";
	wordings2_1 += "<TABLE style=\"BORDER-COLLAPSE: collapse\" bgcolor=\"#F8F8F8\" borderColor=\"#8F8F8F\" cellSpacing=\"2\" cellPadding=\"2\" border=\"1\" style=\"text-align:left;\">";
	wordings2_1 += "<TR><TD class=\"txt1\">";
	wordings2_1 += "Offers a FREE 15 Year Limited Warranty on Material Integrity<br />";
	wordings2_1 += "<B><font color=\"#ff0000\">Note:</font></B> This warranty does not cover staining.";
	wordings2_1 += "</TD></TR></TABLE></div>"
		
	var wordings3 = "</div></div>";
	wordings3 += "</td></tr>";
	wordings3 += "<tr><td align=\"center\">";
	wordings3 += "<a class=\"home_header\" href=\"../purchase-samples.aspx\" target=\"_blank\"><b>Purchase a stone sample</a>";
	wordings3 += "</td></tr>";	
	
	if(typeof(SlabDetails)!="undefined" && SlabDetails!=null & SlabDetails.trim!=""){	
	    wordings3 += "    <tr>";
        wordings3 += "        <td align='center'><a href='#' onclick='javascript:showSlabImages(\""+ SlabDetails +"\");return false;' class=\"home_header\">View Slab</a></td>";
        wordings3 += "    </tr>";
	}
	wordings3 += "</table>"
	
	if (document.images){
	
		if(perma == 0){
		    txt = wordings + timg + word + tname + wordings1 + txt + wordings2 + wordings3;
		}else{
		    txt = wordings + timg + word + tname + wordings1 + txt + wordings2_1 + wordings3;
		}
		
		var tip = '<table  border="1" cellpadding="1" cellspacing="1" bgcolor="#FFFFFF" style="{border-width:1px; border-color:#535724; border-collapse:collapse;}"><tr valign=top><td><table cellpadding=0 cellspacing=0 border=0 width=100%><tr valign=top><td>'+ txt + '<\/td><\/tr></table></td></tr><\/table>';
		var tooltip = atooltip();				
		var mx = current_X;
    	var my = current_Y;

		var bodyw = (window.innerWidth)  ? window.innerWidth  : document.body.offsetWidth;
		if (ns4){
			tooltip.document.write(tip);
			tooltip.document.close();
			var toolWidth = parseFloat(tooltip.offsetWidth);
			var toolPosition = mx + toolWidth;
			if(bodyw < toolPosition){
			    mx = bodyw - toolWidth + 15;
			}
			tooltip.left = mx;
			tooltip.top = my;
		}else{
			tooltip.innerHTML = tip;			
			var toolWidth = parseFloat(tooltip.offsetWidth);			
			var toolPosition = mx + toolWidth;
			if(bodyw < toolPosition){
			    mx = bodyw - toolWidth + 15;
			}
			tooltip.style.left = mx + "px";
			tooltip.style.top = my + "px";			
		}
		with(tooltip) { ns4 ? visibility="show" : style.visibility="visible" }
	}
}

function mouseX(evt) {
    if (evt.pageX){
        return evt.pageX;
    }else if (evt.clientX){
	    return evt.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
	}else{
	    return null;
	}
}
	
function mouseY(evt) {
	if (evt.pageY){
	     return evt.pageY;
	}else if (evt.clientY){
	     return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
	}else{
	     return null;
	}
}

function hmhidePopup() {
	var tooltip = atooltip();
	ns4 ? tooltip.visibility="hide" : tooltip.style.visibility="hidden";
}

function atooltip(){
    var popupHolder = Getelement("divPopupHolder");
    if(popupHolder==null){
        var newcomp = document.createElement("div");
        newcomp.id = "divPopupHolder";
        newcomp.style.position = "absolute";
        newcomp.style.left = "0px";
        newcomp.style.top = "0px";
        document.forms[0].insertBefore(newcomp,document.forms[0].childNodes[0]);        
        popupHolder = Getelement("divPopupHolder");
    }
    return popupHolder;
}

var t_id = setInterval(animate,20);
var pos=0;
var dir=2;
var len=0;

function animate(){
	var elem = document.getElementById('progress');
	if(elem != null) {if (pos==0) len += dir;
	if (len>32 || pos>79) pos += dir;
	if (pos>79) len -= dir;
	if (pos>79 && len==0) pos=0;
	elem.style.left = pos;
	elem.style.width = len;
	}
}		
function remove_loading() {
	this.clearInterval(t_id);
	var targelem = document.getElementById('loader_container');
	targelem.style.display='none';
	targelem.style.visibility='hidden';
	var t_id = setInterval(animate,60);
}
function popup_window(url, id, width, height ){
	popup = window.open( url, id, 'toolbar=no,scrollbars=yes,location=no,statusbar=no,menubar=no,resizable=no,width=' + width + ',height=' + height + '' );
	popup.focus();
}
function setFocus(){
    var errmsg = Getelement("lblErrorMessage").innerHTML;
    var Subclientids = Getelement("hdnCounterSubtotals").value;
    var Clientids = Subclientids.split(sep); 
    var j = 0;
    var FocusComp = Getelement("lblTotalLength");
    for(j=0;j<Clientids.length;j++){
        var Rowcontrols = Clientids[j].split(":::");
        var LenId = Rowcontrols[0];
        var WidId = Rowcontrols[1];
        var LenCont = Getelement(LenId);
        var WidCont = Getelement(WidId);        
        if(LenCont){
            if(LenCont.value=="" || LenCont.value==0 || isNaN(LenCont.value)){
                FocusComp = LenCont;
                break;
            }
        }
        if(WidCont){
            if(WidCont.value=="" || WidCont.value==0 || isNaN(WidCont.value)){
                FocusComp = WidCont;
                break;
            }
        }
    }
    if(FocusComp){
        if(errmsg!=""){
            FocusComp.focus();
        }
    }
}

//by tham on 4 may
function ResetSqInchesOption(subtotalname){
    var Subclientids = Getelement(subtotalname).value;
    var Clientids = Subclientids.split(sep); 
    var j = 0;
    for(j=0;j<Clientids.length;j++){        
        var Rowcontrols = Clientids[j].split(":::");
        var LenId = Rowcontrols[0];
        var WidId = Rowcontrols[1]; 
        var TotId = Rowcontrols[2];
        var LenCont = Getelement(LenId);
        var WidCont = Getelement(WidId);
        var TotCont = Getelement(TotId);        
        if(TotCont!=null && WidCont!=null && LenCont!=null){
            LenCont.value = "";
            WidCont.value = "";
            TotCont.innerHTML = "0.00";
        }
    }
}
function isNumber(val_)
{
    if((val_ == "") || (val_ == ".")){
        return false;
    }else if(!isNaN(val_)){
        return true;
    }else{
        return false;
    }
}
//end by tham on 4 may

//by tham on 13 may
function setTxtFocus(obj){
    obj.select();
}
function setTxtBlur(obj){
    try{document.selection.empty();}catch(e){}
    try{document.selection.clear();}catch(e){}    
}
//end by tham on 13 may
