﻿
var returnCountyID = "";
var returnCountyName = "";
var returnCityID = "";
var returnCityName = "";
var returnStateCode = "";
var returnZipCode = "";
var returnIjnQuoteID = "";
var latestRequestStep = "";
var _iJNResponseJSON = [];
var _appraisalJSON = [];
var _CartIDs = "";
var _Quantities = "";

//panel
var _ijnPanel;

YAHOO.util.Event.onDOMReady(
    function() {
        returnCountyID = document.getElementById(__countyid).value;
        returnCountyName = document.getElementById(__countyname).value;
        returnCityID = document.getElementById(__cityid).value;
        returnCityName = document.getElementById(__cityname).value;
        returnStateCode = document.getElementById(__statecode).value;
        returnZipCode = document.getElementById(__zipcode).value;
    }
);

function summary() {
    var Dom = YAHOO.util.Dom;
    document.getElementById(_ddlState).disabled = true;
    document.getElementById(_ddlShippingOptions).disabled = true;
    //document.getElementById(_lblShippingPrice).innerHTML = "0";
    //document.getElementById(_lblShippingOptionPrice).innerHTML = "0";

    //summary
    var subtotal = 0;
    var subtotal_nogift = 0;
    var insurance = 0;
    var appraisal = 0;
    var insurancefactor, appraisalfactor;
    var objs = Dom.getElementsByClassName("total");
    var dis = Dom.getElementsByClassName("discount");
    var alive = Dom.getElementsByClassName("isalive");
    for (var i = 0; i < objs.length; i++) {
        if (Dom.get('row_' + i).style.display != "none" && alive[i].value == "True") {
            subtotal += (tryParseFloat(objs[i]));

            if (Dom.get("producttype_" + i).value != "G") {
                subtotal_nogift += (tryParseFloat(objs[i]));
            }
        }
    }

    var couponamount = parseFloat(Dom.get(__couponAmount).value);
    var promotion = couponamount;
    var info = document.getElementById(_lblPromotionInfo).innerHTML;
    if (info != "") {
        promotion = subtotal * promotion / 100;
        document.getElementById(_lblPromotion).innerHTML = addCommas(promotion.toFixed(2));
    }

    var giftCertificate = tryParseFloat(document.getElementById(_lblGiftCertificate));
    var saleTax = getSaleTax();
    var totalSaleTax = (subtotal_nogift) * saleTax / 100;
    var total = subtotal + insurance - promotion - giftCertificate + totalSaleTax; //subtotal - promotion + totalSaleTax;

    //set text
    document.getElementById(_lblSubTotal).innerHTML = addCommas(subtotal.toFixed(2));
    document.getElementById(_lblSaleTax).innerHTML = addCommas(saleTax.toFixed(2));
    document.getElementById(_lblSaleTaxTotal).innerHTML = addCommas(totalSaleTax.toFixed(2));

    //get shipping options
    var messages = _optionJSON;
    var shippingOptions = document.getElementById(_ddlShippingOptions);
    var curShippingID = shippingOptions.options[shippingOptions.selectedIndex].id;

    for (i = shippingOptions.length - 1; i >= 0; i--) {
        shippingOptions.options[i] = null;
    }
    var op = document.createElement('option');
    op.text = 'Select Shipping';
    op.value = 0;
    shippingOptions.options.add(op);

    //    var messages = _optionJSON;
    var ddlCountry = Dom.get(_ddlCountry);
    var countryCode = ddlCountry.options[ddlCountry.selectedIndex].value;
    var level = 1;
    var lowerbound, upperbound, m;
    var matchLevel = false;

    //check higest free level
    for (var i = 0; i < messages.length; i++) {
        m = messages[i];
        lowerbound = parseFloat(m.freefrom);
        upperbound = parseFloat(m.freeto);

        if (subtotal_nogift >= lowerbound && subtotal_nogift <= upperbound) {
            level = m.level;
            matchLevel = true;
            break;
        }
    }

    var foundFirstFree = false;
    var freeShippingID = 0;
    for (var i = 0; i < messages.length; i++) {
        m = messages[i]

        if (level == m.level) {
            op = document.createElement('option');

            if (matchLevel) {
                op.text = m.shippingname + " - $" + getUpgradePrice(level, m.shippingprice);
                op.value = getUpgradePrice(level, m.shippingprice);
            }
            else {
                op.text = m.shippingname + " - $" + m.shippingprice;
                op.value = m.shippingprice;
            }
            op.id = m.shippingoptionid;

            lowerbound = parseFloat(m.freefrom);
            upperbound = parseFloat(m.freeto);

            //document.getElementById(_lblFreeShipping).innerHTML = "Free " + m.shippingname;
            if (subtotal_nogift >= lowerbound && subtotal_nogift <= upperbound && m.isfree == 'True') {
                op.text = "Free " + m.shippingname;
                op.style.color = "red";
                op.value = "0";

                if (!foundFirstFree) {
                    freeShippingID = m.shippingoptionid;
                    foundFirstFree = true;
                }
            }

            shippingOptions.options.add(op);
        }
    } // for

    document.getElementById(_lblShippingOptionPrice).innerHTML = "0";

    //default free
    for (var i = 0; i < shippingOptions.options.length; i++) {
        if (shippingOptions.options[i].id == freeShippingID) {
            shippingOptions.selectedIndex = i;
            break;
        }
    }

    //set to current
    for (var i = 0; i < shippingOptions.options.length; i++) {
        if (shippingOptions.options[i].id == curShippingID && curShippingID) {
            shippingOptions.selectedIndex = i;
            break;
        }
    }

    var myShoppingPrice;
    if (shippingOptions.selectedIndex == 0 || shippingOptions.options[shippingOptions.selectedIndex].value == "0") {
        Dom.get("ShippingOptionPriceDollarSign").innerHTML = "";
        document.getElementById(_lblShippingOptionPrice).innerHTML = "";
        myShoppingPrice = 0;
    } else {
        Dom.get("ShippingOptionPriceDollarSign").innerHTML = "$";
        document.getElementById(_lblShippingOptionPrice).innerHTML = shippingOptions.options[shippingOptions.selectedIndex].value;
        myShoppingPrice = parseFloat(shippingOptions.options[shippingOptions.selectedIndex].value);
    }



    //insurance & appraisal
    if (_isfree_insurance) {
        insurancefactor = 0;
        Dom.get("insurancetotal").innerHTML = "0";
        Dom.get("freeinsurancetotal").innerHTML = "($" + addCommas(insurance.toFixed(2)) + ")";
    } else {
        insurancefactor = 1;
        Dom.get("insurancetotal").innerHTML = addCommas(insurance.toFixed(2));
        Dom.get("freeinsurancetotal").innerHTML = "";
    }

    if (_isfree_appraisal) {
        appraisalfactor = 0;
        Dom.get("appraisaltotal").innerHTML = "0";
        Dom.get("freeappraisaltotal").innerHTML = "($" + addCommas(appraisal) + ")";
    } else {
        appraisalfactor = 1;
        Dom.get("appraisaltotal").innerHTML = addCommas(appraisal);
        Dom.get("freeappraisaltotal").innerHTML = "";
    }

   
    //plus shipping price
    var baseShippingPrice = 0; //tryParseFloat(document.getElementById(_lblShippingPrice));
    var shippingOption = myShoppingPrice //(document.getElementById(_lblShippingOptionPrice));
    
     //only Gift certificate
    if (subtotal_nogift == 0) {
        baseShippingPrice = 0;
        shippingOption = 0;
        $("#trShippingOption").hide();
        $("#" + _ddlShippingOptions).attr("disabled", true);
        document.getElementById(_ddlShippingOptions).selectedIndex = 1;
    } else {
        $("#trShippingOption").show();
        $("#" + _ddlShippingOptions).attr("disabled", false);
    }
    
    total = subtotal + (insurance * appraisalfactor) + (appraisal * appraisalfactor) + totalSaleTax + baseShippingPrice + shippingOption - promotion;
    setLabelText(document.getElementById(_lblTotal), addCommas(total.toFixed(2)));



    var potentialPromotion = parseFloat(document.getElementById(__giftAmount).value);
    if (total < potentialPromotion) {
        document.getElementById(_lblGiftCertificate).innerHTML = addCommas(total.toFixed(2));
        document.getElementById(_lblGrandTotal).innerHTML = "0";
    } else {
        document.getElementById(_lblGiftCertificate).innerHTML = addCommas(potentialPromotion.toFixed(2));
        total = total - parseFloat(potentialPromotion);
        document.getElementById(_lblGrandTotal).innerHTML = addCommas(total.toFixed(2));
    }

    //display on/off insurance total
    if (insurance > 0) {
        Dom.get("tdinsurance").style.display = "";
    } else {
        Dom.get("tdinsurance").style.display = "none";
    }
    if (appraisal > 0) {
        Dom.get("tdappraisal").style.display = "";
    } else {
        Dom.get("tdappraisal").style.display = "none";
    }
    
    document.getElementById(_ddlState).disabled = false;
    document.getElementById(_ddlShippingOptions).disabled = false;
}

function getUpgradePrice(level, shippingPrice) {
    if (level == 1) return parseFloat(shippingPrice) - 8;
    if (level == 2) return parseFloat(shippingPrice) - 16;
    if (level == 3) return parseFloat(shippingPrice) - 20;
    return parseFloat(shippingPrice);
}

function calculatePrice(i) {
    var Dom = YAHOO.util.Dom;
    var quantity = YAHOO.util.Dom.get('quantity_' + i).value;
    var insurance_quantity = YAHOO.util.Dom.get('insurance_quantity_' + i).value;
    var unitprice = tryParseFloat(YAHOO.util.Dom.get('unitprice_' + i));
    var discount = tryParseFloat(YAHOO.util.Dom.get('discount_' + i));
    var newprice = quantity * (unitprice - discount);

    Dom.get('total_' + i).innerHTML = addCommas(newprice.toFixed(2));
//    Dom.get('appraisal2_' + i).innerHTML = "$" + addCommas((parseFloat(_appraisalamount) * quantity).toFixed(2));

//    //must to request new appraisal
//    Dom.get("cbxinsurance_" + i).checked = false;
//    if (_hasAppraisal_certificate) {
//        if (unitprice >= 500) {
//            Dom.get('linkappriasal_' + i).style.display = "";
//            Dom.get('divlinkappriasal_' + i).style.display = "";
//        }
//        YAHOO.util.Dom.get('divappraisal_' + i).style.display = "none";

//        //count insurnace
//        var hasInsurance = false;
//        for (var count = 0; count < _total_line_item; count++) {
//            if (Dom.get("cbxinsurance_" + count).checked) {
//                hasInsurance = true;
//                break;
//            }
//        }

//        if (hasInsurance == false) {
//            Dom.get(_ddlState).disabled = false;
//            Dom.get(_ddlCountry).disabled = false;

//            //reset
//            Dom.get(__zipcode).value = "";
//            returnCityID = "";
//            returnCityName = "";
//            returnCountyID = "";
//            returnCountyName = "";
//        }
//    }
}

function getSaleTax() {
    var ddlState = YAHOO.util.Dom.get(_ddlState);
    var saleTax = _saleTax;
    var taxState = _taxState
    var taxType = _taxType
    if ((taxType == "A") || (taxState == ddlState.options[ddlState.selectedIndex].value && taxType == "L")) {
        return parseFloat(saleTax);
    } else {
        return 0;
    }
    return 0;
}

function bindState(country) {
    var states = YAHOO.util.Dom.get(_ddlState);
    for (i = states.length - 1; i >= 0; i--) {
        states.options[i] = null;
    }

    var messages = _optionJSON;
    var op, m;
    var countryCode = country.options[country.selectedIndex].value;

    op = document.createElement('option');
    op.text = "Select State of Residence";
    op.value = "0";
    states.options.add(op);

    for (var i = 0; i < messages.length; i++) {
        m = messages[i];
        if (m.countrycode == countryCode) {
            op = document.createElement('option');
            op.text = m.statename;
            op.value = m.statecode;
            states.options.add(op);
        }
    }
    summary();
}

function resetState() {
    var states = YAHOO.util.Dom.get(_ddlState);
    for (i = states.length - 1; i >= 0; i--) {
        states.options[i] = null;
    }

    var messages = _stateJSON;
    var op, m;

    op = document.createElement('option');
    op.text = "Select State of Residence";
    op.value = "0";
    states.options.add(op);

    for (var i = 0; i < messages.length; i++) {
        m = messages[i];
        if (m.countrycode == "US") {
            op = document.createElement('option');
            op.text = m.statename;
            op.value = m.statecode;
            states.options.add(op);
        }
    }
}


function checkCertificate() {
    var Dom = YAHOO.util.Dom;
    var cert = YAHOO.util.Dom.get(_txtGiftCertificate).value;
    if (cert == "") return;

    YAHOO.util.Dom.setStyle("totalProgress", "display", "");
    YAHOO.util.Connect.asyncRequest(
                'get'
                , "AjaxStation.aspx?method=checkcertificate&certificate=" + cert + "&rnd=" + Math.random()
                , {
                    success: function(o) {
                        var msg = o.responseText.split('|');
                        var giftCertificate = YAHOO.util.Dom.get(_lblGiftCertificate);
                        var total = YAHOO.util.Dom.get(_lblTotal);
                        setLabelText(giftCertificate, parseFloat(msg[0]));
                        YAHOO.util.Dom.get(__giftAmount).value = msg[0];

                        if (msg[0] == "0") {
                            YAHOO.util.Dom.get(_txtGiftCertificate).value = "";
                            YAHOO.util.Dom.setStyle("tdgiftcertificate", "display", "none");
                        } else {
                            YAHOO.util.Dom.setStyle("tdgiftcertificate", "display", "");
                        }

                        summary();
                        Dom.get('responseText').innerHTML = msg[1];
                        Dom.get(_btnMessage).click();
                        YAHOO.util.Dom.setStyle("totalProgress", "display", "none");
                    }
                    , failure: function(o) {
                        YAHOO.util.Dom.setStyle("totalProgress", "display", "none");
                        YAHOO.util.Dom.setStyle("tdgiftcertificate", "display", "none");
                        alert(o.responseText);
                        document.location.reload(true);
                    }
                }
            );
}

function checkCoupon() {
    var Dom = YAHOO.util.Dom;
    var coupon = YAHOO.util.Dom.get(_txtCoupon).value;
    if (coupon == "") return;

    YAHOO.util.Dom.setStyle("totalProgress", "display", "");
    YAHOO.util.Connect.asyncRequest(
                'get'
                , "AjaxStation.aspx?method=checkcoupon&coupon=" + coupon + "&rnd=" + Math.random()
                , {
                    success: function(o) {
                        var msg = o.responseText.split('|');
                        var discount = YAHOO.util.Dom.get(_lblPromotion);
                        var total = YAHOO.util.Dom.get(_lblTotal);
                        var subtotal = YAHOO.util.Dom.get(_lblSubTotal);
                        var info = YAHOO.util.Dom.get(_lblPromotionInfo);
                        var amount = YAHOO.util.Dom.get(__couponAmount);

                        var discountVal = parseFloat(msg[0]);
                        amount.value = discountVal;

                        setLabelText(info, "");

                        setLabelText(discount, addCommas(discountVal.toFixed(2)));

                        if (msg[0] == "0") {
                            var txtcoupon = YAHOO.util.Dom.get(_txtCoupon);
                            txtcoupon.value = "";
                            YAHOO.util.Dom.setStyle("tdcoupon", "display", "none");
                        } else {
                            YAHOO.util.Dom.setStyle("tdcoupon", "display", "");
                        }

                        summary();
                        Dom.get('responseText').innerHTML = msg[1];
                        Dom.get(_btnMessage).click();
                        YAHOO.util.Dom.setStyle("totalProgress", "display", "none");
                    }
                    , failure: function(o) {
                        YAHOO.util.Dom.setStyle("totalProgress", "display", "none");
                        YAHOO.util.Dom.setStyle("tdcoupon", "display", "none");
                        alert(o.responseText);
                    }
                }
            );
}


function checkAll(cbx, ulid) {
    $(ulid + " input[type='checkbox']").attr("checked", cbx.checked);
}

function checkOut(obj) {
    //check available IJN for site
    if (!_hasInsurance && !_hasAppraisal_certificate) {
        proceedToCheckout();
        return;
    }

    var xml = "";
    var conf;
    var Dom = YAHOO.util.Dom;
    quans = YAHOO.util.Dom.getElementsByClassName("quantity");
    if (quans.length == 0) {
        conf = new YAHOO.widget.SimpleDialog(
                            "conf",
					         { width: "300px",
					             fixedcenter: true,
					             visible: false,
					             draggable: false,
					             modal: true,
					             close: false,
					             text: _checkoutNoProduct,
					             icon: YAHOO.widget.SimpleDialog.ICON_WARN,
					             constraintoviewport: true,
					             buttons: [{ text: "Ok", handler: function() { this.hide(); }, isDefault: true}]
					         });

        conf.setHeader("Alert");
        conf.render(document.body);
        conf.show();
        return;
    }

    var ddlState = YAHOO.util.Dom.get(_ddlState);
    if (ddlState.selectedIndex == 0) {
        var stateconf = new YAHOO.widget.SimpleDialog(
                            "stateconf",
					         { width: "300px",
					             fixedcenter: true,
					             visible: false,
					             draggable: false,
					             modal: true,
					             close: false,
					             text: "Please Select State of Residence below.",
					             icon: YAHOO.widget.SimpleDialog.ICON_WARN,
					             constraintoviewport: true,
					             buttons: [{ text: "Ok", handler: function() { this.hide(); YAHOO.util.Dom.get(_ddlState).focus(); }, isDefault: true}]
					         });
					         
        stateconf.setHeader("Alert");
        stateconf.render(document.body);
        stateconf.show();
        return;
    }

    // shipping validate
    var ddlShippingOptions = YAHOO.util.Dom.get(_ddlShippingOptions);
    if (ddlShippingOptions.selectedIndex == 0) {
       var shippingconf = new YAHOO.widget.SimpleDialog(
                            "shippingconf",
					         { width: "300px",
					             fixedcenter: true,
					             visible: false,
					             draggable: false,
					             modal: true,
					             close: false,
					             text: "Please Select Shipping Option below.",
					             icon: YAHOO.widget.SimpleDialog.ICON_WARN,
					             constraintoviewport: true,
					             buttons: [{ text: "Ok", handler: function() { this.hide(); YAHOO.util.Dom.get(_ddlShippingOptions).focus(); }, isDefault: true}]
					         });
        shippingconf.setHeader("Alert");
        shippingconf.render(document.body);
        shippingconf.show();
        return;
    }

    var ids = YAHOO.util.Dom.getElementsByClassName("shoppingcartid");
    var pids = YAHOO.util.Dom.getElementsByClassName("productid");
    var objs = Dom.getElementsByClassName("total");
    var aliasitemcode = YAHOO.util.Dom.getElementsByClassName("aliasitemcode");
    var producttitle = YAHOO.util.Dom.getElementsByClassName("producttitle");
    var appValueText = "";

    //IJN Insurance
    var cartItemCount = 0;
    var ijnItemCount = 0;
    var ijnItemHTML = "<tr><td colspan='2'><ul id='ulijn' class='ijnlist'>";
    var appraisalItemHTML = "<tr><td colspan='2'><ul id='ulappraisal' class='ijnlist'>";
    var quan = "";
    for (i = 0; i < objs.length; i++) {
        if (Dom.get('row_' + i).style.display != "none") {
            cartItemCount++;
            
            if(tryParseFloat(objs[i]) >= 500 && Dom.get("producttype_" + i).value != "G"){
                quan = $("#quantity_" + i).val();
                
                if(YAHOO.env.ua.ie <= 7 && YAHOO.env.ua.ie > 0){
                    ijnItemHTML += "<li><input type='checkbox' id='ijn" + ids[i].value + "' lang='" + quan + "' />" + aliasitemcode[i].value + " - " + producttitle[i].value.substring(0, 70) + "</li>";
                    appraisalItemHTML += "<li><input type='checkbox' id='appraisal" + ids[i].value + "'  lang='" + quan + "' />" + aliasitemcode[i].value + " - " + producttitle[i].value.substring(0, 70) + "</li>";
                }else{
                    ijnItemHTML += "<li><input type='checkbox' id='ijn" + ids[i].value + "' lang='" + quan + "' />" + aliasitemcode[i].value + " - " + producttitle[i].value + "</li>";
                    appraisalItemHTML += "<li><input type='checkbox' id='appraisal" + ids[i].value + "'  lang='" + quan + "' />" + aliasitemcode[i].value + " - " + producttitle[i].value + "</li>";
                }
                ijnItemCount++;
            }
        }
    }
    ijnItemHTML += "</td></tr></ul>";
    appraisalItemHTML += "</td></tr></ul>";

    var panelWidth = 'auto', panelHeight = 'auto';
    if(YAHOO.env.ua.ie <= 7 && YAHOO.env.ua.ie > 0){
        if(_hasInsurance && _hasAppraisal_certificate)
            panelHeight = 260;
        else
            panelHeight = 160;
            
        if(cartItemCount == 1){
            panelWidth = '400';
            panelHeight = 205;
        }
        else{
            panelWidth = '575';
        }

        panelHeight += cartItemCount * 33;
    }
    
    // show ijn popup
    if (ijnItemCount > 0) {
        _ijnPanel = new YAHOO.widget.Panel(
                        "ijnPanel",
                        {
                            fixedcenter: true,
                            close: false,
                            draggable: false,
                            zindex: 999999,
                            modal: true,
                            visible: false,
                            width: panelWidth,
                            height: panelHeight
                        }
                    );

        if (ijnItemCount == 1) {
            appValueText = " - $" + _appraisalamount;
        } else {
            appValueText = " - $" + _appraisalamount + " per item";
        }
        
        var insuranceLabel = _isfree_insurance ? '<span style="color:red; font-weight:bold;">Free!!</span>' : 'Buy';
        var certLabel = _isfree_appraisal ? '<span style="color:red; font-weight:bold;">Free!!</span>' : 'Buy';
        
        if(_isfree_appraisal){
            appValueText = "";
        }
        
        if(YAHOO.env.ua.ie <= 7 && YAHOO.env.ua.ie > 0){
            _ijnPanel.setHeader("<div style='z-index: 99999;text-align:center; font-size: 18px; height: 40px;'><table width='100%'><tr><td>Protect Your Purchase</td><td align='right'><img src='pics/close.PNG' style='margin-top: 7px; cursor: pointer;' onclick='_ijnPanel.hide();' /></td></tr></table></div>");
        }else{
            _ijnPanel.setHeader("<div style='text-align:center; font-size: 18px;'>Protect Your Purchase <img src='pics/close.PNG' style='float: right; margin-top: 10px; cursor: pointer;' onclick='_ijnPanel.hide();' /></div>");
        }
        _ijnPanel.setBody(
                  '<table style="z-index: 99999;" id="myijnpanel" border="0" cellpadding="0"  cellspacing="0">'
                + '  <tr>'
                + '    <td align="center" valign="top">'
                + '      <table width="100%" border="0" cellspacing="0" cellpadding="0">'
                + '        <tr>'
                + '          <td align="center">'
                + '             <table id="tbIJN" width="100%" border="0" cellspacing="0" cellpadding="0">'
                + '              <tr valign="top">'
                + '                <td width="30"><input type="checkbox" onclick="checkAll(this, &#39;#ulijn&#39;)" name="checkbox" id="checkbox" /></td>'
                + '                <td class="text11pxblkit">' + insuranceLabel + ' A 1 Year Worldwide Insurance policy Which Includes<br />Accidental Damage And Mysterious Disappearance</td>'
                + '              </tr>'
                + ijnItemHTML
                + '              <tr>'
                + '                <td>&nbsp;</td>'
                + '                <td><table width="100%" border="0" cellspacing="0" cellpadding="0">'
                + '                  <tr>'
                + '                    <td width="230" class="text10blk"><a target="_blank" href="/?page=IJN_insurance">learn more</a></td>'
                + '                    <td align="right" ></td>'
                + '                  </tr>'
                + '                </table></td>'
                + '              </tr>'
                + '          </table></td>'
                + '        </tr>'
                + '        <tr>'
                + '          <td align="center">'
                + '            <table id="tbAppraisal" width="100%" border="0" cellspacing="0" cellpadding="0">'
                + '            <tr>'
                + '              <td width="30"><input type="checkbox" onclick="checkAll(this, &#39;#ulappraisal&#39;)" name="checkbox2" id="checkbox2" /></td>'
                + '              <td class="text11pxblkit">' + certLabel + ' A Certificate of Value (online appraisal)' + appValueText + '</td>'
                + '            </tr>'
                + appraisalItemHTML
                + '            <tr>'
                + '              <td>&nbsp;</td>'
                + '              <td class="text10blk" align="left"><a target="_blank" href="/?page=IJN_appraisal">learn more</a></td>'
                + '            </tr>'
                + '          </table></td>'
                + '        </tr>'
                + '        <tr>'
                + '          <td style="text-align:left; color: red; font-weight:bold;"><label style="padding-left: 15px;" id="lblIJNWarning" ></label>&nbsp;</td>'
                + '        </tr>'
                + '        <tr>'
                + '          <td align="center" style="border-top: solid 1px #dddddd;">&nbsp;</td>'
                + '        </tr>'
                + '        <tr>'
                + '          <td align="center"><img style="cursor:pointer;" onclick="gotoInsurance();" src="images/btn_blue-purc.gif"  /> <img src="images/btn_nothank_red.gif" onclick="noThanks();" style="cursor:pointer;" /></td>'
                + '        </tr>'
                + '      </table>'
                + '    </td>'
                + '  </tr>'
                + '</table>'
        );
        _ijnPanel.render(document.body);
        _ijnPanel.show();

        if (cartItemCount == 1) {
            $("#ulijn", "#myijnpanel").hide();
            $("#ulappraisal", "#myijnpanel").hide();
        }

        if (!_hasInsurance) {
            $("#tbIJN").hide();
        }

        if (!_hasAppraisal_certificate) {
            $("#tbAppraisal").hide();
        }
    } else {
        proceedToCheckout();
    }
}

function noThanks()
{
    _ijnPanel.hide();
    $("#ulijn input[type='checkbox']").attr("checked", false);
    $("#ulappraisal input[type='checkbox']").attr("checked", false);
    _appraisalJSON = {};
    proceedToCheckout();
}


function proceedToCheckout(hasIJN) {
    var xml = "";
    var conf;
    var Dom = YAHOO.util.Dom;

    var ids = YAHOO.util.Dom.getElementsByClassName("shoppingcartid");
    var pids = YAHOO.util.Dom.getElementsByClassName("productid");
    var objs = Dom.getElementsByClassName("total");
    var aliasitemcode = YAHOO.util.Dom.getElementsByClassName("aliasitemcode");
    var producttitle = YAHOO.util.Dom.getElementsByClassName("producttitle");
    var ddlShippingOptions = YAHOO.util.Dom.get(_ddlShippingOptions);
    var ddlState = YAHOO.util.Dom.get(_ddlState);

    //waiting ..
    var wait = new YAHOO.widget.Panel(
                        "wait",
                        { width: "240px",
                            fixedcenter: true,
                            close: false,
                            draggable: false,
                            zindex: 4,
                            modal: true,
                            visible: false
                        }
                    );

    wait.setHeader("Processing.. Please wait..");
    wait.setBody("<img src='pics/ajax-loader3.gif' title='loading..' />");
    wait.render(document.body);
    wait.show();

    var ddlCountry = YAHOO.util.Dom.get(_ddlCountry);

    var shippingOtpion = ddlShippingOptions.options[ddlShippingOptions.selectedIndex].text;
    var shippingOtpionID = ddlShippingOptions.options[ddlShippingOptions.selectedIndex].id;


    for (i = 0; i < objs.length; i++) {
        if (Dom.get('row_' + i).style.display != "none") {
            var pre = "", conv = "", quoteid = "", app = "";
            if (hasIJN) {
                $.each(_iJNResponseJSON.data, function(idx, item) {
                    if (ids[i].value == item.id) {
                        pre = item.premium;
                        conv = item.conveniencefee;
                        quoteid = item.ijnquoteid;
                    }
                });
            }

            if (_appraisalJSON.length > 0) {
                $.each(_appraisalJSON, function(idx, item) {
                    if (ids[i].value == item.id) {
                        app = (parseFloat(item.quantity) * parseFloat(_appraisal_certificate_amount)).toFixed(2);
                    }
                });
            }

            xml += ids[i].value + ';' + YAHOO.util.Dom.get('quantity_' + i).value + ';' + pids[i].value + ';' + pre + ';' + conv + ';' + app + ';' + quoteid + '\n';
        }
    }

    var cert = YAHOO.util.Dom.get(_txtGiftCertificate).value;
    var coupon = YAHOO.util.Dom.get(_txtCoupon).value;

    var countyid = "";
    var countyname = "";
    var cityid = "";
    var cityname = "";
    var zipcode = "";

    if (_iJNResponseJSON.countyid != undefined) countyid = _iJNResponseJSON.countyid;
    if (_iJNResponseJSON.countyname != undefined) countyname = _iJNResponseJSON.countyname;
    if (_iJNResponseJSON.cityid != undefined) cityid = _iJNResponseJSON.cityid;
    if (_iJNResponseJSON.cityname != undefined) cityname = _iJNResponseJSON.cityname;
    if (_iJNResponseJSON.cityid != undefined) zipcode = _iJNResponseJSON.zipcode;
    
    YAHOO.util.Connect.asyncRequest(
            'post'
            , "AjaxStation.aspx?method=checkout&data="
                + encodeURIComponent(xml)
                + "&certificate=" + cert
                + "&rnd=" + Math.random()
                + '&countyid=' + countyid
                + '&countyName=' + countyname
                + '&cityid=' + cityid
                + '&cityname=' + cityname
                + '&zipcode=' + zipcode
            , {
                success: function(o) {
                    var msg = o.responseText;
                    var url = 'checkout.aspx?'
                            + 'country=' + ddlCountry.options[ddlCountry.selectedIndex].value
                            + '&state=' + ddlState.options[ddlState.selectedIndex].value
                            + '&shippingoption=' + encodeURIComponent(shippingOtpion)
                            + '&shippingoptionid=' + shippingOtpionID
                            + '&certificate=' + encodeURIComponent(cert)
                            + '&coupon=' + encodeURIComponent(coupon)
                            + '&countyid=' + countyid
                            + '&countyName=' + encodeURIComponent(countyname)
                            + '&cityid=' + cityid
                            + '&cityname=' + encodeURIComponent(cityname)
                            + '&zipcode=' + zipcode
                    if (msg == "SUCCESS") {
                        document.location = url;
                    } else {
                        wait.hide();
                        conf = new YAHOO.widget.SimpleDialog(
                                    "conf",
				                     { width: "300px",
				                         fixedcenter: true,
				                         visible: false,
				                         draggable: false,
				                         modal: true,
				                         close: false,
				                         text: msg,
				                         icon: YAHOO.widget.SimpleDialog.ICON_ALARM,
				                         constraintoviewport: true,
				                         buttons: [{ text: "Ok", handler: function() { this.hide(); }, isDefault: true}]
				                     });
                        conf.setHeader("Warning");
                        conf.render(document.body);
                        conf.show();
                        return;
                    }
                }
                , failure: function(o) {
                    wait.hide();
                    //alert(o.responseText);
                    alert(_requestUnSuccesfull);
                }
            }
        );
}


function shippingOptionChange(ddl) {
    var Dom = YAHOO.util.Dom;
    document.getElementById(_ddlState).disabled = true;
    document.getElementById(_ddlShippingOptions).disabled = true;

    if (ddl.selectedIndex == 0 || ddl.options[ddl.selectedIndex].value == "0") {
        Dom.get("ShippingOptionPriceDollarSign").innerHTML = "";
        setLabelText(Dom.get(_lblShippingOptionPrice), "");
    }
    else {
        Dom.get("ShippingOptionPriceDollarSign").innerHTML = "$";
        setLabelText(Dom.get(_lblShippingOptionPrice), ddl.options[ddl.selectedIndex].value);
    }

    var subtotal = parseFloat(getLabelText(Dom.get(_lblSubTotal)));
    var shippingPrice = parseFloat(ddl.options[ddl.selectedIndex].value);
    var shippingOptionPrice = 0;
    var saleTaxTotal = parseFloat(getLabelText(Dom.get(_lblSaleTaxTotal)));
    var promotion = parseFloat(getLabelText(Dom.get(_lblPromotion)));


    var total = subtotal + shippingPrice + shippingOptionPrice + saleTaxTotal - promotion;
    setLabelText(Dom.get(_lblTotal), addCommas(total.toFixed(2)));

    var potentialPromotion = parseFloat(Dom.get(__giftAmount).value);
    if (total < potentialPromotion) {
        setLabelText(Dom.get(_lblGiftCertificate), addCommas(total.toFixed(2)));
        setLabelText(Dom.get(_lblGrandTotal), "0");
    } else {
        setLabelText(Dom.get(_lblGiftCertificate), addCommas(potentialPromotion.toFixed(2)));
        total = total - parseFloat(potentialPromotion);
        setLabelText(Dom.get(_lblGrandTotal), addCommas(total.toFixed(2)));
    }
    
    document.getElementById(_ddlState).disabled = false;
    document.getElementById(_ddlShippingOptions).disabled = false;
}

function addToWishList(obj, shoppingcartid, producttype) {
    if (YAHOO.util.Dom.get(__wishlishName).value == '') {
        document.location.href = 'WishList.aspx';
    }
    else {
        YAHOO.util.Dom.get('cartprogress').style.display = '';
        YAHOO.util.Connect.asyncRequest(
                    'get'
                    , "AjaxStation.aspx?method=addtowishlist&shoppingcartid=" + shoppingcartid + '&producttype=' + producttype + '&rnd=' + Math.random()
                    , {
                        success: function(o) {
                            if (o.responseText == 'SUCCESS')
                                document.location = "WishList.aspx";
                            else if (o.responseText == 'SOLDOUT')
                                document.location = "SoldOut.aspx";
                            else {
                                alert(o.responseText);
                            }
                            YAHOO.util.Dom.get('cartprogress').style.display = 'none'
                        }
                        , failure: function(o) {
                            alert(o.responseText);
                            YAHOO.util.Dom.get('cartprogress').style.display = 'none'
                        }
                    }
                );
    }
}

function removeFromCart(id, shoppingcartid, productid) {
    var handleYes = function() {
        this.hide();

        YAHOO.util.Dom.get('cartprogress').style.display = '';


        YAHOO.util.Connect.asyncRequest(
                    'get'
                    , "AjaxStation.aspx?method=removefromcart&shoppingcartid=" + shoppingcartid + "&productid=" + productid + '&rnd=' + Math.random()
                    , {
                        success: function(o) {
                            YAHOO.util.Dom.get('row_' + id).style.display = 'none';
                            YAHOO.util.Dom.get('quantity_' + id).className = '';
                            summary();
                        }
                        , failure: function(o) { alert(o.responseText); document.location.reload(true); }
                    }
                );

        window.setTimeout(
                    function() {
                        YAHOO.util.Dom.get('cartprogress').style.display = 'none';
                    }
                    , 500
                );
    };

    var handleNo = function() {
        this.hide();
    };

    var conf = new YAHOO.widget.SimpleDialog(
                            "conf",
					         { width: "300px",
					             fixedcenter: true,
					             visible: false,
					             draggable: false,
					             modal: true,
					             close: false,
					             text: "Are you sure you want to remove this item from shopping cart?",
					             icon: YAHOO.widget.SimpleDialog.ICON_WARN,
					             constraintoviewport: true,
					             buttons: [{ text: "Yes", handler: handleYes, isDefault: true }, { text: "No", handler: handleNo}]
					         });

    conf.setHeader("Confirm Remove");
    conf.render(document.body);
    conf.show();
}


function popupEmail(productid, producttype) {
    var Dom = YAHOO.util.Dom;
    Dom.get(_btnEmailFriend).click();
    Dom.get(__productID).value = productid;
    Dom.get(__productType).value = producttype;
}


function email() {
    var Dom = YAHOO.util.Dom;
    var from = Dom.get(_txtEmail);
    var to = Dom.get(_txtTo);
    var vldFrom = Dom.get('vldFrom');
    var vldTo = Dom.get('vldTo');
    var isValid = true;

    //validate required
    if (from.value == "") {
        setLabelText(vldFrom, "(*)");
        isValid = false;
    }
    if (to.value == "") {
        setLabelText(vldTo, "(*)");
        isValid = false;
    }

    if (isValid == false) {
        return;
    }
    setLabelText(vldFrom, "");
    setLabelText(vldTo, "");

    //validate required;
    var regexp = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
    if (regexp.test(from.value) == false) {
        setLabelText(vldFrom, "(*invalid email format)");
        return;
    }

    Dom.setStyle("email-loading", "display", "");
    var data = "to=" + encodeURIComponent(to.value)
                     + "&from=" + encodeURIComponent(from.value)
                     + "&message=" + encodeURIComponent(Dom.get(_txtMessage).value)
                     + "&name=" + encodeURIComponent(Dom.get(_txtName).value)
                     + "&productid=" + Dom.get(__productID).value
                     + "&producttype=" + Dom.get(__productType).value;

    YAHOO.util.Connect.asyncRequest(
                'post'
                , "AjaxStation.aspx?method=email&rnd=" + Math.random()
                , {
                    success: function(o) {
                        var msg = o.responseText;
                        if (msg == "SUCCESS") {
                            Dom.setStyle("email-loading", "display", "none");
                            Dom.setStyle(_lblMessage, "display", "block");
                            setLabelText(Dom.get(_lblMessage), "Email successfully sent to " + to.value);
                        } else {
                            var conf = new YAHOO.widget.SimpleDialog(
                            "conf",
					         { width: "300px",
					             fixedcenter: true,
					             visible: false,
					             draggable: false,
					             modal: true,
					             close: false,
					             text: msg,
					             icon: YAHOO.widget.SimpleDialog.ICON_WARN,
					             constraintoviewport: true,
					             buttons: [{ text: "Ok", handler: function() { this.hide(); }, isDefault: true}]
					         });

                            conf.setHeader("Error");
                            conf.render(document.body);
                            conf.show();
                            Dom.setStyle("email-loading", "display", "none");
                        }
                    }
                    , failure: function(o) {
                        alert(o.responseText);
                        Dom.setStyle("email-loading", "display", "none");
                    }
                }
                , data
            );
}

function imgbtnCancel_Click() {
    var Dom = YAHOO.util.Dom;
    var imgbtnCancel = Dom.get(_imgBtnCancel);
    imgbtnCancel.click();
}

function gotoInsurance() {
    //get selected 
    _CartIDs = "";
    _Quantities = "";
    _appraisalJSON = [];
    _iJNResponseJSON = [];
    
    var cbxs = $("#ulijn input[type='checkbox']");
    $.each(cbxs, function(i, item) {
        if (item.checked) {
            _CartIDs += item.id.replace("ijn", "") + "|";
            _Quantities += item.lang + "|";
        }
    });

    cbxs = $("#ulappraisal input[type='checkbox']");
    $.each(cbxs, function(i, item) {
        if (item.checked) {
            _appraisalJSON[_appraisalJSON.length] = { id: item.id.replace("appraisal", ""), quantity: item.lang };
        }
    });

    //noselected
    if (_CartIDs == "" && _appraisalJSON.length == 0) {
        $("#lblIJNWarning").text("*Please select atleast 1 item.");
        return;
    }

    if (_CartIDs != "") {
        _ijnPanel.hide();
        popupInsurance();
    } else if (_CartIDs == "" && _appraisalJSON.length > 0) {
        _ijnPanel.hide();
        proceedToCheckout()
    }
}

function popupInsurance() {
    if (Sys.Application._initialized) {

        var Dom = YAHOO.util.Dom;
        Dom.get("tdzipcode").style.display = "";
        Dom.get(_txtZipCode).value = "";
        $("#lblIJNZipcode").text("");
        Dom.get("tdcity").style.display = "none";
        Dom.get("tdcounty").style.display = "none";

        var ddlCounty = Dom.get(_ddlCounty);
        var ddlCity = Dom.get(_ddlCity);

        //reset county and city
        for (var count = ddlCounty.length - 1; count >= 0; count--) {
            ddlCounty.options[count] = null;
        }

        //reset city
        for (var count = ddlCity.length - 1; count >= 0; count--) {
            ddlCity.options[count] = null;
        }

        //reset questionnair
        Dom.get("questionnairmessage").innerHTML = "";
        Dom.setStyle("btnQuestionNairClose", "display", "none");
        Dom.setStyle("btnQuestionNairSubmit", "display", "");
        Dom.setStyle("questionnairzone2", "display", "none");
        Dom.setStyle("questionnairzone1", "display", "");
        Dom.get("no1").checked = false;
        Dom.get("no2").checked = false;
        Dom.get("no3").checked = false;
        Dom.get("no4").checked = false;
        Dom.get("no5").checked = false;
        Dom.get("yes1").checked = false;
        Dom.get("yes2").checked = false;
        Dom.get("yes3").checked = false;
        Dom.get("yes4").checked = false;
        Dom.get("yes5").checked = false;
        Dom.get("vq1").style.display = "none";
        Dom.get("vq2").style.display = "none";
        Dom.get("vq3").style.display = "none";
        Dom.get("vq4").style.display = "none";
        Dom.get("vq5").style.display = "none";
        Dom.get("questionnair").disabled = "";
        Dom.get(_cbxAppraisal).checked = false;

        Dom.get("questionnair").style.display = "";
        Dom.get("tbgemshieldinfo").style.display = "";
        Dom.get("tddisclosure").style.display = "none";
        Dom.get("vagree").style.display = "none";
        Dom.get("vagree2").style.display = "none";
        Dom.get("radagree").checked = false;
        Dom.get("raddisagree").checked = false;
        Dom.get("radagree2").checked = false;
        Dom.get("raddisagree2").checked = false;

        Dom.get(_btnIjnRequest).click();
    }
}

function popupAppraisal(link, lineitem) {
    var Dom = YAHOO.util.Dom;
    link.style.display = 'none';
    Dom.get("divlinkappriasal_" + lineitem).style.display = "none";
    Dom.get("cbxappraisal_" + lineitem).checked = false;
    Dom.get("appraisalctv_" + lineitem).style.display = "none";
    Dom.get("divappraisal_" + lineitem).style.display = "";
}

function ijnGetRates() {
    var Dom = YAHOO.util.Dom;

    //validate required
    Dom.get("vzipcode").title = "";
    $("#lblIJNZipcode").text("");
    
    if (Dom.get(_txtZipCode).value == "") {
        Dom.get("vzipcode").style.display = "";
        Dom.get("vzipcode").title = "required";
        return;
    } else {
        Dom.get("vzipcode").style.display = "none";
    }

    var loader = Dom.get("requestrate-loader");
    var loader2 = Dom.get("requestrate-loader2");
    var loader3 = Dom.get("requestrate-loader3");
    //var i = Dom.get(__ijnLineItem).value;
    //var quantity = Dom.get("quantity_" + i).value;
    var ddlCounty = document.getElementById(_ddlCounty);
    var ddlCity = document.getElementById(_ddlCity);
    var ddlState = document.getElementById(_ddlState);
    var selectedCounty = "";
    var selectedCountyName = "";
    var selectedCity = "";
    var premium = Dom.get("premium");
    var conveniencefee = Dom.get("conveniencefee");

    //Dom.get("insurance_quantity_" + i).value = quantity;
    loader.style.display = "";
    loader2.style.display = "";
    loader3.style.display = "";
    returnIjnQuoteID = "";

    //set city
    if (ddlCity.selectedIndex >= 0) {
        selectedCity = ddlCity.options[ddlCity.selectedIndex].value;
    }

    //set county
    if (ddlCounty.selectedIndex >= 0) {
        selectedCounty = ddlCounty.options[ddlCounty.selectedIndex].value;
        selectedCountyName = ddlCounty.options[ddlCounty.selectedIndex].text;
    }

    document.getElementById("btnIJNRequestSubmit").disabled = true;
    document.getElementById("btnIJNRequestSubmit2").disabled = true;
    document.getElementById("btnIJNRequestSubmit3").disabled = true;
    YAHOO.util.Connect.asyncRequest(
                'post'
                , "AjaxStation.aspx?method=ijnrequest&shoppingcartids="
                    + _CartIDs
                    + "&quantities=" + _Quantities
                    + "&city=" + selectedCity
                    + "&countyid=" + selectedCounty
                    + "&countyname=" + selectedCountyName
                    + "&zipcode=" + Dom.get(_txtZipCode).value
                    + "&state=" + ddlState.options[ddlState.selectedIndex].value
                , {
                    success: function(o) {
                        _iJNResponseJSON = YAHOO.lang.JSON.parse(o.responseText);
                        document.getElementById("btnIJNRequestSubmit").disabled = false;
                        document.getElementById("btnIJNRequestSubmit2").disabled = false;
                        document.getElementById("btnIJNRequestSubmit3").disabled = false;
    
                        if (_iJNResponseJSON.message == "SUCCESS") {
                            Dom.get(_btnIjnRequestCancel).click();
                            Dom.get(_btnIjn2).click();

                            if (latestRequestStep != "MULTICITY") {
                                latestRequestStep = "SUCCESS";
                            }

                            var totalPremium = 0, totalConvenienceFee = 0;
                            $.each(_iJNResponseJSON.data, function(i, item) {
                                totalPremium += parseFloat(item.premium);
                                totalConvenienceFee += parseFloat(item.conveniencefee);
                            });

                            Dom.get("insuranceamount").innerHTML = addCommas((totalPremium + totalConvenienceFee).toFixed(2));
                            //Dom.get("questionNairAppraisal").innerHTML = addCommas(parseFloat(_appraisal_certificate_amount) * parseFloat(quantity));
                        } else if (_iJNResponseJSON.message == "ZIPCODE_NOT_MATCH") {
                            //Dom.get("vzipcode").style.display = "";
                            //Dom.get("vzipcode").title = "*zipcode not match the state.";
                            $("#lblIJNZipcode").text("*Zipcode does not match selected Sales Tax State.");
                        } else if (_iJNResponseJSON.message == "MULTICITY") {
                            latestRequestStep = "MULTICITY";
                            //bind counties
                            Dom.get("tdzipcode").style.display = "none";
                            Dom.get("tdcity").style.display = "";
                            Dom.get("tdcounty").style.display = "none";

                            _iJNResponseJSON.data;
                            var op = document.createElement('option');
                            for (var count = 0; count < cityList.length; count++) {
                                op = document.createElement('option');
                                op.text = cityList[count].name;
                                op.value = cityList[count].id;
                                ddlCity.options.add(op);
                            }
                        } else if (_iJNResponseJSON.message == "MULTICOUNTY") {
                            //pickup city
                            if (latestRequestStep != "MULTICITY") {
                                latestRequestStep = "MULTICOUNTY";
                            }

                            //bind counties
                            Dom.get("tdzipcode").style.display = "none";
                            Dom.get("tdcity").style.display = "none";
                            Dom.get("tdcounty").style.display = "";

                            var countyList = _iJNResponseJSON.data;
                            var op = document.createElement('option');
                            for (var count = 0; count < countyList.length; count++) {
                                op = document.createElement('option');
                                op.text = countyList[count].name;
                                op.value = countyList[count].id;
                                ddlCounty.options.add(op);
                            }
                        } else {
                            latestRequestStep = "FAILURE";
                            Dom.get(_txtZipCode).value == "";
                            $("#lblIJNZipcode").text(_iJNResponseJSON.message);
                        }
                        loader.style.display = "none";
                        loader2.style.display = "none";
                        loader3.style.display = "none";
                    }
                    , failure: function(o) {
                        alert(o.responseText);
                        document.getElementById("btnIJNRequestSubmit").disabled = false;
                        document.getElementById("btnIJNRequestSubmit2").disabled = false;
                        document.getElementById("btnIJNRequestSubmit3").disabled = false;
                        Dom.get(_txtZipCode).value == "";
                        loader.style.display = "none";
                        loader2.style.display = "none";
                        loader3.style.display = "none";
                    }
                }
            );
}

function QuestionNairSubmit() {
    var Dom = YAHOO.util.Dom;
    var validate = true;

    //validate question
    if (!Dom.get("yes1").checked && !Dom.get("no1").checked) { validate = false; Dom.get("vq1").style.display = ""; } else { Dom.get("vq1").style.display = "none"; }
    if (!Dom.get("yes2").checked && !Dom.get("no2").checked) { validate = false; Dom.get("vq2").style.display = ""; } else { Dom.get("vq2").style.display = "none"; }
    if (!Dom.get("yes3").checked && !Dom.get("no3").checked) { validate = false; Dom.get("vq3").style.display = ""; } else { Dom.get("vq3").style.display = "none"; }
    if (!Dom.get("yes4").checked && !Dom.get("no4").checked) { validate = false; Dom.get("vq4").style.display = ""; } else { Dom.get("vq4").style.display = "none"; }
    if (!Dom.get("yes5").checked && !Dom.get("no5").checked) { validate = false; Dom.get("vq5").style.display = ""; } else { Dom.get("vq5").style.display = "none"; }



    if (validate) {
        if (Dom.get("no1").checked && Dom.get("no2").checked && Dom.get("no3").checked && Dom.get("no4").checked && Dom.get("no5").checked) {

            Dom.get("tddisclosure").style.display = "";
            Dom.get("questionnair").style.display = "none";

            Dom.get("questionnairmessage").innerHTML = "";
            Dom.setStyle("questionnairzone2", "display", "");
            Dom.setStyle("questionnairzone1", "display", "none");

            //Dom.get("questionNairProductPrice").innerHTML = "$" + addCommas(newprice.toFixed(2));
            Dom.get("questionNairInsurance").innerHTML = "$" + addCommas(Dom.get("insuranceamount").innerHTML);
            //Dom.get("cbxinsurance_" + i).checked = true;

            //on/off line stoke
            if (_isfree_insurance) Dom.get("questionNairInsurance").style.textDecoration = "line-through"; else Dom.get("questionNairInsurance").style.textDecoration = "";
            if (_isfree_appraisal) Dom.get("questionNairAppraisal").style.textDecoration = "line-through"; else Dom.get("questionNairAppraisal").style.textDecoration = "";
        }
        else {
            Dom.get("questionnair").disabled = "true";
            Dom.get("tbgemshieldinfo").style.display = "none";
            Dom.get("questionnairmessage").innerHTML = "We are unable to process your request for insurance at this time, please contact Gemshield at 866-207-9482 or gemshield@ijb-usa.com to have your policy submission personally reviewed and underwritten.";
            Dom.setStyle("btnQuestionNairClose", "display", "");
            Dom.setStyle("btnQuestionNairSubmit", "display", "none");
            Dom.setStyle("questionnairzone2", "display", "none");
            Dom.setStyle("questionnairzone1", "display", "");
        }
    }
}

function addInsuranceToCart() {
    var Dom = YAHOO.util.Dom;

    //validate
    var testValidate = true;
    
    var radagree = document.getElementById("vagree2");
    var radagree2 = document.getElementById("radagree2");
    var raddisagree = document.getElementById("raddisagree");
    var raddisagree2 = document.getElementById("raddisagree2");
    var vagree = document.getElementById("vagree");
    var vagree2 = document.getElementById("vagree2");
    
    if (raddisagree.checked || raddisagree2.checked) {
        QuestionNairClose();
        _iJNResponseJSON = [];
        _appraisalJSON = [];
        proceedToCheckout();
        return;
    }
    
    if (radagree2.checked == false && raddisagree2.checked == false) {
        vagree2.style.display = "";
        //document.location = "#agreement";
        testValidate = false; ;
    } else {
        vagree2.style.display = "none";
    }

    if (radagree.checked == false && raddisagree.checked == false) {
        vagree.style.display = "";
        testValidate = false; ;
    } else {
        vagree.style.display = "none";
    }

    if (testValidate == false) return;
    //end validate
    
     
    var default_cityid = Dom.get(__cityid).value;
    var default_countyid = Dom.get(__countyid).value;
    var default_zipcode = Dom.get(__zipcode).value;
    var ddlCounty = document.getElementById(_ddlCounty);
    var ddlCity = document.getElementById(_ddlCity);
    var selectedCounty = "";
    var selectedCountyName = "";
    var selectedCity = "";
    var selectedCityName = "";
    var selectZipCode = Dom.get(_txtZipCode).value
    var i = Dom.get(__ijnLineItem).value;

    if (ddlCity.selectedIndex >= 0) {
        selectedCity = ddlCity.options[ddlCity.selectedIndex].value;
        selectedCityName = ddlCity.options[ddlCity.selectedIndex].text;
    }

    if (ddlCounty.selectedIndex >= 0) {
        selectedCounty = ddlCounty.options[ddlCounty.selectedIndex].value;
        selectedCountyName = ddlCounty.options[ddlCounty.selectedIndex].text;
    } else {
        selectedCounty = returnCountyID;
        selectedCountyName = returnCountyName;
    }

    _iJNResponseJSON.cityid = selectedCity;
    _iJNResponseJSON.cityname = selectedCityName;
    QuestionNairClose();
    proceedToCheckout(true);
}


function QuestionNairClose() {
    var Dom = YAHOO.util.Dom;
    Dom.get(_btnIjn2Cancel).click();

}
