﻿var validatecreatedheader = 0;
var proceedconfirmation = false;
var modelTypee = "";
var deviceCheckConfigg = "";
function ShowWarningPopup(controlId, controlClass) {

    CreateWarningPopup(controlId, controlClass, 400, true, true);
}

function CreateWarningPopup(controlId, controlClass, width, hideTitle, IsModal) {
    var dialogObj
    if (controlId != '')
        dialogObj = $("#" + controlId);
    else
        dialogObj = $("." + controlClass);
    $(dialogObj).dialog({
        width: width,
        resizable: false,
        draggable: false,
        closeOnEscape: false,
        height: 550,
        modal: IsModal,
        position: ["center", 95],
        open: function (event, ui) {
            $('html').css({ overflow: 'hidden' });
            $(this).dialog("widget").css("padding-bottom", "0px");
            $('.ui-widget-overlay').bind('click', function () {
                $(dialogObj).dialog('destroy');
                $(dialogObj).hide();
            });
        },
        close: function (event, ui) {
            $('html').css({ overflow: 'scroll' });
        }
    });

    if (hideTitle)
        $(dialogObj).dialog("widget").find(".ui-dialog-titlebar").hide();
}


$(document).ready(function () {
    $('form').find('input').keypress(function (e) {
        if (e.which == 13) // Enter key = keycode 13
            return false;
    });

    $('#ctl00_ContentPlaceHolder1_CustomerInfo1_NameTitle-menu').css("width", "50px");
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_endRequest(function (sender, args) {
        $('.open-dialog').click(function () {
            $(".ui-dialog-content").dialog("close");
            $($(this).attr("href")).dialog({
                width: 750,
                height: 563,
                resizable: false,
                draggable: false,
                modal: true,
                position: ["center", 45],
                open: function (event, ui) {
                    $('html').css({ overflow: 'hidden' });
                },
                close: function (event, ui) {
                    $('html').css({ overflow: 'scroll' });
                }
            });

            return false;
        });

        jQuery("#ctl00_ContentPlaceHolder1_CustomerInfo1_Postcode").blur(function () {
            if ($(this).val().trim() == "") {

                $('#ctl00_ContentPlaceHolder1_CustomerInfo1_lblErrorPostCode').html("");

                //alert(getresourcefunc('ReqPostCode'));
                $('#ctl00_ContentPlaceHolder1_CustomerInfo1_lblErrorPostCode').html("<b>" + getresourcefunc('ReqPostCode') + "</b>");

            }
            else {

                $('#ctl00_ContentPlaceHolder1_CustomerInfo1_lblErrorPostCode').html("");
            }
        });

        function ProceedToContinue() {

            $("#Terms_and_conditionsbtn_dialog").dialog({
                width: 980,
                height: 540,
                resizable: false,
                draggable: false,
                modal: true,
                position: ["center", 95],
                buttons: {
                    "send": {

                        text: getresourcefunc('AcceptBtnTxt'),
                        "class": 'ui-button'
                    },
                    "cancel": {
                        text: getresourcefunc('DeclineBtnTxt'),
                        "class": 'ui-button'
                    }
                },
                open: function (event, ui) {
                    $('html').css({ overflow: 'hidden' });
                },
                close: function (event, ui) {
                    $('html').css({ overflow: 'scroll' });
                }
            });
        }
        jQuery("#ctl00_ContentPlaceHolder1_CustomerInfo1_EmailAddress").blur(function () {



            var emailRegexStr = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
            if (emailRegexStr.test($('#ctl00_ContentPlaceHolder1_CustomerInfo1_EmailAddress').val()) == false) {

                //alert(getresourcefunc('RegexpWrongEmail'));
                $('#spnEmailaddress').text(getresourcefunc('RegexpWrongEmail'));

            }
            else
                $('#spnEmailaddress').empty();
        });



        //jQuery("#ctl00_ContentPlaceHolder1_CustomerInfo1_MobileNo").blur(function() {

        //    var str =$("#ctl00_ContentPlaceHolder1_CustomerInfo1_MobileNo").val().trim();
        //     var MobileNo=str.replace(/-/g,""); 
        //  
        //    


        //    mobilenumber = $('#ctl00_ContentPlaceHolder1_CustomerInfo1_MobileNo').val().trim().substring(0, 2);
        //   var phoneRegExp = /^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/;
        //   if (phoneRegExp.test(MobileNo) == false)
        //   $('#spnMobileNo').text("Not a valid phone number format.");

        // else
        // $('#spnMobileNo').empty();


        //});

    });

    prm.add_endRequest(function (sender, args) {
        $(".open-dialog-small").click(function () {

            $($(this).attr("href")).dialog({
                width: 750,
                height: 510,
                resizable: false,
                draggable: false,
                modal: true,
                position: ["center", 45],
                open: function (event, ui) {
                    $('html').css({ overflow: 'hidden' });
                },
                close: function (event, ui) {
                    $('html').css({ overflow: 'scroll' });
                }
            });
            return false;
        });


        $(".open-dialog-ht").click(function () {
            $($(this).attr("href")).dialog({
                width: 680,
                height: 209,
                resizable: false,
                draggable: false,
                modal: true,
                position: ["center", 45],
                open: function (event, ui) {
                    $('html').css({ overflow: 'hidden' });
                },
                close: function (event, ui) {
                    $('html').css({ overflow: 'scroll' });
                }
            });
            return false;
        });

    });
    $(".open-dialog-ht").click(function () {

        $($(this).attr("href")).dialog({
            width: 680,
            height: 209,
            resizable: false,
            draggable: false,
            modal: true,
            position: ["center", 45],
            open: function (event, ui) {
                $('html').css({ overflow: 'hidden' });
            },
            close: function (event, ui) {
                $('html').css({ overflow: 'scroll' });
            }
        });
        return false;
    });

    $(function () {

        $('#ctl00_ContentPlaceHolder1_CustomerInfo1_Firstname').keydown(function (e) {
            var key = e.keyCode;

            if (key == 191 || key == 16 || key == 190 || key == 188 || key == 111 || key == 106 || key == 107 || key == 59 || key == 219 || key == 221 || key == 220 || key == 222 || key == 106 || key == 109 || key == 110 || key == 173 || key == 61) {

                e.preventDefault();
                return false;
            }


            if (key >= 48 && key <= 57) {
                e.preventDefault();
                return false;
            }
            else if (key >= 96 && key <= 105) {
                e.preventDefault();
                return false;
            }
        });
        $('#ctl00_ContentPlaceHolder1_CustomerInfo1_Lastname,#ctl00_ContentPlaceHolder1_CustomerAccount1_Lastname').keydown(function (e) {
            var key = e.keyCode;
            if (key == 111 || key == 106 || key == 109 || key == 107)
                return true;
            if ((e.shiftKey) && (key == 49 || key == 50 || key == 51 || key == 52 || key == 53 || key == 54 || key == 55 || key == 56 || key == 57 || key == 58 || key == 192 || key == 219 || key == 221 || key == 220 || key == 222 || key == 191 || key == 48))
                return true;
            if ((e.shiftKey) && (key == 190 || key == 188))
                return false;
            if (key == 16 || key == 111 || key == 106 || key == 107 || key == 59 || key == 106 || key == 109 || key == 173 || key == 61) {

                e.preventDefault();
                return false;
            }
            if (key >= 48 && key <= 57) {
                e.preventDefault();
                return false;
            }
            else if (key >= 96 && key <= 105) {
                e.preventDefault();
                return false;
            }
        });
        $('#ctl00_ContentPlaceHolder1_CustomerInfo1_EmailAddress').keydown(function (e) {
            var key = e.keyCode;
            if (key == 32) {
                e.preventDefault();
                return false;
            }
        });
        $('#ctl00_ContentPlaceHolder1_CustomerInfo1_MobileNo').keydown(function (e) {
            //Restrict special characters and alphabets
            var _key = e.keyCode;
            if (_key >= 65 && _key <= 90 || (_key >= 97 && _key <= 122) || (_key > 32 && _key < 48) || (_key > 57 && _key < 65) || (_key > 90 && _key < 97)) {
                e.preventDefault();
                return false;
            }

        });




    });

    var currentpath = window.location.pathname;
    var currentpathname = currentpath.substring(path.lastIndexOf('/') + 1);
    if (currentpathname == "search.aspx" || currentpathname == "inspection.aspx" || currentpathname == "valuation.aspx") {
        // var   resultresource1 = getresourcefunc('ItemsInCartText');
        //alert(getresourcefunc('ItemsInCartText'));
        $('#ctl00_Header1_lblItems').html(getresourcefunc('ItemsInCartText'));

    }


    //    if ($('#ctl00_ContentPlaceHolder1_hrnQuoteValue').val() == "0")
    //        $('#ValuationContainer_btnGroup').addClass("ui-state-disabled");




    $('#AnchorHide').click(function () {


        $('#Terms_and_conditions2_dialog').modal('hide');
        //$('#Terms_and_conditions2_dialog').dialog('close');

    });





    $(".login-dialog").dialog({
        width: 650,
        resizable: false,
        draggable: false,
        modal: true,
        position: ["center", 95],
        dialogClass: "home-login",
        open: function (event, ui) {
            $('html').css({ overflow: 'hidden' });
        },
        close: function (event, ui) {
            $('html').css({ overflow: 'scroll' });
        }
    });
    $(".login-dialog").dialog("widget").find(".ui-dialog-titlebar").hide();

    documentLoad();

    ///Apple White Label

    $('#faq').click(function () {
        // Hide tr of FAQ where ts value is NULL

        $('td', '#tb_FaqTable').filter(function () { // select all the TDs

            if ($(this).text().trim().toUpperCase().indexOf("NULL") >= 0) {
                $(this).closest('tr').hide();
            }
        }).each(function () { // loop through each of the ones that matched
        });

        //$(".ui-dialog-content").dialog("close");
        //$($(this).attr("href")).dialog({
        //    width: 750,
        //    height: 563,
        //    resizable: false,
        //    draggable: false,
        //    modal: true,
        //    position: ["center", 45],
        //    open: function (event, ui) {
        //        $('html').css({ overflow: 'hidden' });
        //    },
        //    close: function (event, ui) {
        //        $('html').css({ overflow: 'scroll' });
        //    }
        //});
        //return false;
    });


    $(".open-dialog-small").click(function () {

        $($(this).attr("href")).dialog({
            width: 750,
            height: 510,
            resizable: false,
            draggable: false,
            modal: true,
            position: ["center", 45],
            open: function (event, ui) {
                $('html').css({ overflow: 'hidden' });
            },
            close: function (event, ui) {
                $('html').css({ overflow: 'scroll' });
            }
        });
        return false;
    });

    $(".open-dialog-narrow").click(function () {
        $($(this).attr("href")).dialog({
            width: 550,
            height: 500,
            resizable: false,
            draggable: false,
            modal: true,
            position: ["center", 45],
            open: function (event, ui) {
                $('html').css({ overflow: 'hidden' });
            },
            close: function (event, ui) {
                $('html').css({ overflow: 'scroll' });
            }
        });
        return false;
    });
    $('#CarrierDialog').click(function () {
        $($('#PopUp_Carrier')).dialog({
            width: 450,
            height: 500,
            resizable: false,
            draggable: false,
            modal: true,
            position: ["center", 45],
            open: function (event, ui) {
                $('html').css({ overflow: 'hidden' });
            },
            close: function (event, ui) {
                $('html').css({ overflow: 'scroll' });
            }
        });
    });

    if ($('#ctl00_ContentPlaceHolder1_hrnQuoteValue').val() == "0") {

        $("#ProceedBox").dialog({
            width: 480,
            height: 240,
            resizable: false,
            draggable: false,
            modal: true,
            position: ["center", 95],
            open: function (event, ui) { $('html').css({ overflow: 'hidden' }); $(".ui-dialog-titlebar-close", ui.dialog || ui).hide(); },
            close: function (event, ui) {
                $('html').css({ overflow: 'scroll' });
            }
        });
        $(".ui-dialog-titlebar-close").hide();
        $('#ctl00_ContentPlaceHolder1_LnkBtnProceed').button({ disabled: true });
        //        $('#ctl00_ContentPlaceHolder1_LnkBtnProceed').addClass(" ui-button-disabled ui-state-disabled");
    }
    $("#ProceedBox").click(function () {
        $("#ProceedBox").dialog({
            width: 480,
            height: 240,
            resizable: false,
            draggable: false,
            modal: true,
            position: ["center", 95],
            open: function (event, ui) { $('html').css({ overflow: 'hidden' }); $(".ui-dialog-titlebar-close", ui.dialog || ui).hide(); },
            close: function (event, ui) {
                $('html').css({ overflow: 'scroll' });
            }
        });
    });
    $('#valuationlink').on('click', function () {
        window.open('http://www.apple.com/de/recycling/computer/', '_blank');
    });

    //    if ($('#ctl00_ContentPlaceHolder1_WithZero').text()=='RECYCLE FOR FREE') {
    //        $("#ProceedBox").dialog({
    //            width: 480,
    //            height: 240,
    //            resizable: false,
    //            draggable: false,
    //            modal: true,
    //            position: ["center", 95],
    //            open: function(event, ui) { $(".ui-dialog-titlebar-close", ui.dialog || ui).hide(); }
    //        });
    //        $(".ui-dialog-titlebar-close").hide();
    //        
    //    }



});

function getresourcefunc(paramresourcekey) {

    var resultresource;
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "confirm.aspx/GetResourceJS",
        data: "{'resourcekey':'" + paramresourcekey + "'}",
        dataType: "json",
        async: false,
        success: function (data) {
            //alert(data.d);
            resultresource = data.d;
            //return resultresource;
        },
        error: function (result) {
            resultresource = '';
        }
    });
    return resultresource;

}

function documentLoad() {
    //$("input[type=submit], button, .ui-btn, #SelectPhone_container input, #SelectModel_container input, #SelectColor_container input,#SelectHandset_btnGroup a,#InspectionContainer_btnGroup a,#ValuationContainer_btnGroup #ctl00_ContentPlaceHolder1_LnkBtnProceed,#ReturnBag2_view_btnGroup #ctl00_ContentPlaceHolder1_btnUpdate,#CompleteContract_content a,#CompleteContract_submit a,.noprint #lnkPrintReceipt,input[type=radio]").button();
    $("input[type=submit]").button();
    $("button").button();
    $(".ui-btn").button();
    $("#SelectPhone_container input").button();
    $("#SelectModel_container input").button();
    $("#SelectColor_container input").button();
    $("#SelectHandset_btnGroup a").button();
    $("#InspectionContainer_btnGroup a").button();
    $("#ValuationContainer_btnGroup #ctl00_ContentPlaceHolder1_LnkBtnProceed").button();
    $("#ValuationContainer_btnGroup #ctl00_ContentPlaceHolder1_Btnback").button();
    $("#ReturnBag2_view_btnGroup #ctl00_ContentPlaceHolder1_btnUpdate").button();
    $("#CompleteContract_content a").button();
    $("#CompleteContract_submit a").button();
    $(".noprint #lnkPrintReceipt").button();
    $("input[type=radio]").button();
    $('input').placeholder();
    $('td', '#tb_FaqTable').filter(function () { // select all the TDs

        if ($(this).text().trim().toUpperCase().indexOf("NULL") >= 0) {
            $(this).closest('tr').hide();
        }
    }).each(function () { // loop through each of the ones that matched
    });
    $(".open-dialog-narrow").click(function () {

        if ($(this).attr("href") == "#PopUp_6" || $(this).attr("href") == "#Terms_and_conditions_dialog") {
            $($(this).attr("href")).dialog({
                width: 980,
                height: 540,
                resizable: false,
                draggable: false,
                modal: true,
                position: ["center", 95],
                open: function (event, ui) {
                    $('html').css({ overflow: 'hidden' });
                },
                close: function (event, ui) {
                    $('html').css({ overflow: 'scroll' });
                }
            });
        }
        else {
            $($(this).attr("href")).dialog({
                width: 550,
                height: 500,
                resizable: false,
                draggable: false,
                modal: true,
                position: ["center", 95],
                open: function (event, ui) {
                    $('html').css({ overflow: 'hidden' });
                },
                close: function (event, ui) {
                    $('html').css({ overflow: 'scroll' });
                }
            });
        }

        return false;
    });
    $("#lblTermsConditions").click(function () {
        $("#Terms_and_conditions_dialog").dialog({
            width: 980,
            height: 540,
            resizable: false,
            draggable: false,
            modal: true,
            position: ["center", 95],
            open: function (event, ui) {
                $('html').css({ overflow: 'hidden' });
            },
            close: function (event, ui) {
                $('html').css({ overflow: 'scroll' });
            }
        });
        return false;
    });

    $("#lblPrivacyPolicy").click(function () {
        $("#Privacy_policy_dialog").dialog({
            width: 980,
            height: 540,
            resizable: false,
            draggable: false,
            modal: true,
            position: ["center", 95],
            open: function (event, ui) {
                $('html').css({ overflow: 'hidden' });
            },
            close: function (event, ui) {
                $('html').css({ overflow: 'scroll' });
            }
        });

        return false;
    });

    $("#lblContactUs").click(function () {
        $("#ContactUs_Dialog").dialog({
            width: 980,
            height: 540,
            resizable: false,
            draggable: false,
            modal: true,
            position: ["center", 95],
            open: function (event, ui) {
                $('html').css({ overflow: 'hidden' });
            },
            close: function (event, ui) {
                $('html').css({ overflow: 'scroll' });
            }
        });

        return false;
    });

    $("#ctl00_ContentPlaceHolder1_btnUpdate").click(function () {


        if ($(this).attr("disabled") == "disabled")
            return false;


        if ($(this).prop("disabled") == true) {
            return false;
        }
        else {

            $("#Terms_and_conditionsbtn_dialog").dialog({
                width: 980,
                height: 540,
                resizable: false,
                draggable: false,
                modal: true,
                position: ["center", 95],
                open: function (event, ui) {
                    $('html').css({ overflow: 'hidden' });
                },
                close: function (event, ui) {
                    $('html').css({ overflow: 'scroll' });
                }
            });
            return false;
        }
    });
    $('.dialog-close').click(function () {
        try {
            $('.dialog').dialog('close');
        }
        catch (rx)
        { }

        try {
            $('.login-dialog').dialog('close');
        }
        catch (rx)
        { }

    });
    $("#tabs").tabs();

    $('select.ui-drp').selectmenu({ width: 258 });
    $('select.ui-drp-wide').selectmenu({ width: 421 });

    // Run on load
    validate_confirmation();
    validate_devicecheck();


    $('#SelectTrade_container input[type="radio"]').change(function (e) {
        validate_confirmation();
    });

    $('.deviceCheck_view input[type="checkbox"]').change(function () {
        validate_poweron();
    });

    $('#deviceCheck_view input[type="checkbox"]').change(function () {
        validate_devicecheck();
    });

    $('#IMEIDetails_view input[type="checkbox"]').change(function () {
        has_IMEI();
    });

    var arraySizes = new Array();
    arraySizes['iphone5'] = ['16gb', '32gb', '64gb'];
    arraySizes['iphone4s'] = ['16gb', '32gb', '64gb'];
    arraySizes['iphone4'] = ['8gb', '16gb', '32gb'];
    arraySizes['iphone3gs'] = ['8gb', '16gb', '32gb'];
    arraySizes['iphone3g'] = ['8gb', '16gb', ];
    arraySizes['iphone'] = ['4gb', '8gb'];

    var arrayColours = new Array();
    arrayColours['iphone5'] = ['black', 'white'];
    arrayColours['iphone4s'] = ['black', 'white'];
    arrayColours['iphone4'] = ['black', 'white'];
    arrayColours['iphone3gs'] = ['black', 'white'];
    arrayColours['iphone3g'] = ['black', 'white'];
    arrayColours['iphone'] = ['black'];

    $("#SelectPhone_container input").change(function () {
        var sizes = arraySizes[$(this).val()];
        var colours = arrayColours[$(this).val()];

        $("#SelectModel_container input").button("option", "disabled", true);
        $("#SelectColor_container input").button("option", "disabled", true);


        try {
            var length = sizes.length;
        }
        catch (ex) {
            var length = 0;
        }



        for (var i = 0; i < length; i++) {
            $("#" + sizes[i]).button("option", "disabled", false);
            $("#" + colours[i]).button("option", "disabled", false);
        }
    });

    try {
        check_carrier();
    }
    catch (ex)
    { }

    $("#ctl00_ContentPlaceHolder1_DDLockedToNetwork").change(function () {
        check_carrier();
    });

    $('#WebGridInspectionContainer_view input[type="radio"]').change(function () {
        check_carrier();
    });
     
}

function check_carrier() {

    var totalOptions = (jQuery('.ui-radio-lbl').length / 2);
    var currentlyTicked = 0;

    $('#WebGridInspectionContainer_view input[type="radio"]').filter(':checked').each(function (i) {
        currentlyTicked++;
        console.log(currentlyTicked);
    });


    //var carriervalue = jQuery("#ctl00_ContentPlaceHolder1_DDLockedToNetwork").val();
    var carriervalue = 1;
    if (eval(carriervalue) > 0 && currentlyTicked == totalOptions) {
        jQuery("#InspectionContainer_btnGroup #ctl00_ContentPlaceHolder1_btnSubmit").button("option", "disabled", false);
    } else {
        jQuery("#InspectionContainer_btnGroup #ctl00_ContentPlaceHolder1_btnSubmit").button("option", "disabled", true);
    }
    console.log(carriervalue);
    return false;
}
var path = window.location.pathname;

var name = path.substring(path.lastIndexOf('/') + 1);

function validate_confirmation() {
    var _control = $('#SelectColor_container .ui-state-active');
    var _noniosmodelselection = $('#SelectPhone_container .ui-state-active');
    var _nonioscapacityselection = $('#SelectModel_container .ui-state-active');
    var _noniosstorageselection = $('#SelectModel_container .ui-helper-hidden-accessible:enabled');
    var _nonioscolorselection = $('#SelectColor_container .ui-helper-hidden-accessible:enabled');
    if ($('#SelectBrand_container').length > 0) {
        if ((_noniosmodelselection.length > 0 && _noniosstorageselection.length == 0) || (_nonioscapacityselection.length > 0 && _nonioscolorselection.length == 0)) {
            jQuery('#SelectHandset_btnGroup #ctl00_ContentPlaceHolder1_LnkBtnContinue').button("option", "disabled", false);
            jQuery('#ctl00_ContentPlaceHolder1_LnkBtnContinue').button("refresh");
            jQuery('#ctl00_ContentPlaceHolder1_bypassslavemodelselection').val(1);
            setTimeout(function () {
                document.getElementById('ctl00_ContentPlaceHolder1_LnkBtnContinue').scrollIntoView();
            }, 100)
            return;
        }
    }
    if (_control.length != 0) {
        jQuery('#SelectHandset_btnGroup #ctl00_ContentPlaceHolder1_LnkBtnContinue').button("option", "disabled", false);
    }
    else {
        jQuery('#SelectHandset_btnGroup #ctl00_ContentPlaceHolder1_LnkBtnContinue').button("option", "disabled", true);
    }

    jQuery('#ctl00_ContentPlaceHolder1_LnkBtnContinue').button("refresh");
}




function validate_poweron() {
    var totalOptions = jQuery('#IMEIDetails_view .ui-toggle-lbl').length;
    var currentlyTicked = jQuery('#IMEIDetails_view input[type="checkbox"]').filter(':checked').length;
    if (currentlyTicked == totalOptions) {
        jQuery('#SelectHandset_btnGroup #btnContinue').button("option", "disabled", false);
    } else {
        jQuery('#SelectHandset_btnGroup #btnContinue').button("option", "disabled", true);
    };
    jQuery('#btnContinue').button("refresh");
}

function validate_devicecheck() {

    
    jQuery('#btnContinue').button("refresh");
}

function has_IMEI() {
    if (jQuery('#ctl00_ContentPlaceHolder1_ChkDisplay').is(':checked')) {
        jQuery('#ctl00_ContentPlaceHolder1_txtIMEI').removeAttr("disabled");
        jQuery('#ctl00_ContentPlaceHolder1_txtSerialNo').removeAttr("disabled");
    } else {
        jQuery('#ctl00_ContentPlaceHolder1_txtIMEI').val("");
        jQuery('#ctl00_ContentPlaceHolder1_txtSerialNo').val("");
        jQuery('#ctl00_ContentPlaceHolder1_txtIMEI').attr("disabled", "disabled");
        jQuery('#ctl00_ContentPlaceHolder1_txtSerialNo').attr("disabled", "disabled");
    };
}

function ValidateHeaderSaving() {
    if ($('#ctl00_ContentPlaceHolder1_btnSaveQuote').attr("disabled") == "disabled")
        return false;
    else
        return true;
}

function openLock() {
    $('.inspection').removeClass('disable');
    $('.specMsg').hide();
    $('#InspectionContainer_view .disableblock').remove();
}

function Lock() {
    $('.inspection').removeClass('disable').addClass('disable');
    $('.inspection .disableblock').remove();
    $('.inspection').append('<div class="disableblock"></div>')
}
function enableContinueInspection() {
    var check = true;
    $('.inspection input[type="radio"]:not(:checked)').each(function () {
        if ($('input[name="' + $(this).attr('name') + '"]:not(:checked)').length >= 2)
            check = false;
    });
    if (check == false)
        $('#ctl00_ContentPlaceHolder1_btnSubmit').attr('disabled', 'disabled');
    else
        $('#ctl00_ContentPlaceHolder1_btnSubmit').removeAttr('disabled');
}
var proceed = setInterval(function () { CheckValidationCreateHeaderPageFunction() }, 100);

function CheckValidationCreateHeaderPageFunction() {
    if (name.toLowerCase() == "thankyou.aspx" || name.toLowerCase() == "myorders.aspx" || name.toLowerCase() == "myorderdetails.aspx") {
        $('#liCart').remove();
        $('#UlCart').width('176px');
    }
    //if (name.toLowerCase() == "search.aspx")
    //    $('.cookie-div').show();
    //else
    //    $('.cookie-div').hide();
    if (name == "SearchResults.aspx") {
        var _controlLocal = $('#SelectPhone_container .ui-state-active');
        if (_controlLocal.length != 0) {
            jQuery('#SelectHandset_btnGroup #ctl00_ContentPlaceHolder1_LnkBtnContinue').button("option", "disabled", false);
        }
        else {
            jQuery('#SelectHandset_btnGroup #ctl00_ContentPlaceHolder1_LnkBtnContinue').button("option", "disabled", true);
        }

        jQuery('#ctl00_ContentPlaceHolder1_LnkBtnContinue').button("refresh");
    }
    if (name.toLowerCase() == "inspection.aspx") {

        if ($('#ctl00_ContentPlaceHolder1_hdn_GSXSuccess').val() == "1") {
            $('.specMsg').hide();
            openLock();
            $('.specMsg,.deviceColor,.capacity,.serial').hide();
        }
        else {
            $('.GSX').hide();
            if ($('#ctl00_ContentPlaceHolder1_hdnModelType').val().toLowerCase() == "mac") {
                $('.specMsg,.deviceColor,.capacity,.imei').hide();
                $('.serial').show(); $('#ctl00_ContentPlaceHolder1_txt_SerialNumber').prop('disabled', true);
                $('.specMsg').hide();
                if ($('#ctl00_ContentPlaceHolder1_txt_SerialNumber').text().trim() != "")
                    openLock();
                else
                    Lock();
            }
            else if ($('#ctl00_ContentPlaceHolder1_hdnModelType').val().toLowerCase() == "ipad") {
                $('.inspection').removeClass('disable').addClass('disable');
                $('.serial').show();
                if ($('#ctl00_ContentPlaceHolder1_hdnIMEI').val().trim() == "") {
                    $('#ctl00_ContentPlaceHolder1_txt_SerialNumber').prop('disabled', true);
                    if ($('.capacity .active').length != 0 && $('.deviceColor .active').length != 0 && $('.technology .active').length != 0) {
                        $('.specMsg').hide();
                        if ($('#ctl00_ContentPlaceHolder1_txt_SerialNumber').length != 0) {
                            if ($('#ctl00_ContentPlaceHolder1_txt_SerialNumber').text().trim() != "")
                                openLock();
                            else
                                Lock();
                        }
                        else
                            openLock();
                    }
                    else {
                        $('.specMsg').show();
                        Lock();
                    }
                    $('.imei').hide();
                }
                else {
                    $('#ctl00_ContentPlaceHolder1_txt_SerialNumber').prop('disabled', false);
                    if ($('.capacity .active').length != 0 && $('.deviceColor .active').length != 0) {
                        $('.specMsg').hide();
                        if ($('#ctl00_ContentPlaceHolder1_txt_SerialNumber').length != 0) {
                            if ($('#ctl00_ContentPlaceHolder1_txt_SerialNumber').text().trim() != "")
                                openLock();
                            else
                                Lock();
                        }
                        else
                            openLock();
                    }
                    else {
                        Lock();
                        $('.specMsg').show();
                    }
                    $('.imei').show();
                }

            }
            else if ($('#ctl00_ContentPlaceHolder1_hdnModelType').val().toLowerCase() == "iwatch") {
                //  if ($('.deviceColor .active').length != 0) {
                $('.specMsg').hide();
                openLock();
                // }
                //else {
                //    $('.inspection').removeClass('disable').addClass('disable');
                //    Lock();
                //    $('.specMsg').show(); $('.deviceColor,imei').show();
                //}
            }
            else if ($('#ctl00_ContentPlaceHolder1_hdnModelType').val().toLowerCase() == "android") {
                if ($('.capacity li').length <= 2) {
                    $('.specMsg').hide();
                    openLock(); $('.deviceColor,.capacity').hide();

                    enableContinueInspection();
                    return;
                }
                if ($('.capacity .active').length != 0) {
                    $('.specMsg').hide();
                    openLock();

                }
                else {
                    $('.inspection').removeClass('disable').addClass('disable');
                    Lock();
                    $('.specMsg').show(); $('.deviceColor,.capacity,.imei').show();
                }
            }
            // TFS Id 34434 Changes for iwatch
            else if (($('#ctl00_ContentPlaceHolder1_txt_SerialNumber').text().trim().length == 10) && $('#ctl00_ContentPlaceHolder1_hdnModelType').val().toLowerCase() == "watch") {
                $('.specMsg').hide();
                $('.inspection').removeClass('disable');
                $('.specMsg').hide();
                $('#InspectionContainer_view .disableblock').remove();
            }
                //END TFS Id 34434 Changes
            else {
                if ($('.capacity .active').length != 0 && $('.deviceColor .active').length != 0) {
                    $('.specMsg').hide();
                    openLock();
                }
                else {
                    $('.inspection').removeClass('disable').addClass('disable');
                    Lock();
                    $('.specMsg').show(); $('.deviceColor,.capacity,.imei').show();
                }
            }
        }
        enableContinueInspection();

    }
    if (name == "MyOrderDetails.aspx") {
        if ($('#ctl00_ContentPlaceHolder1_hdnCancelquote').val() == "Sucess") {
            $('#ctl00_ContentPlaceHolder1_hdnCancelquote').val("");
            //$('#CancelOrderDialog').dialog({
            //    dialogClass: "no-close",
            //    width: 450,
            //    height: 250,
            //    resizable: false,
            //    draggable: false,
            //    modal: true,
            //    position: ["center", 45],
            //    open: function (event, ui) {
            //        $('html').css({ overflow: 'hidden' });
            //    },
            //    close: function (event, ui) {
            //        $('html').css({ overflow: 'scroll' });
            //    }
            //});
            //$('#CancelOrderDialog').dialog('open');
            //$($('#CancelOrderDialog').parent()).wrap('<div class="CancelPopup-wrapper"></div>');
            //$(".close-icon").insertBefore(".CancelPopup-wrapper .ui-dialog-titlebar span.ui-dialog-title");
            $('#DeviceShipped_no').show();
            $('#CancelOrder_options').hide();
            $('#cancelorder').click();
            $('#modalfooter').hide();

        }
    }



    if (name.toLowerCase() == "delivery.aspx") {
        var CounttextboxCreateHeader = 0;
        if (modelTypee) {
            if (modelTypee.toLowerCase() == 'android') {
                $('#link_SimRemovedDialog').attr('href', '#SimRemovedDialog_NONIOS');
                $('#deviceCheck-datacard').show(); //$('#deviceCheck_view .deviceCheck-item').width(230);
                $('.decisioniosnonios').hide(); $('#nonios').show(); $('#myModalDatawipenonios').show(); $('#DataWipeDialog').attr('title', 'Data Wiped');
                $('#deviceCheck-datawiped').find('#datawipedtitle').html('Data Wiped');
                $('#datawipe_description').text('I have wiped the device of all personal data.');
                if ($('#deviceCheck-inputs').find('.active').length > 4)
                    CounttextboxCreateHeader = parseInt(CounttextboxCreateHeader) + 1;
            }
            else if (modelTypee.toLowerCase() == 'mac') {
                if ($('#deviceCheck-inputs').find('.active').length > 3)
                    CounttextboxCreateHeader = parseInt(CounttextboxCreateHeader) + 1;
            }
            else {

                $('#link_SimRemovedDialog').attr('href', '#SimRemovedDialog');
                $('#deviceCheck-datacard').hide();// $('#deviceCheck_view .deviceCheck-item').width(200);
                if ($('#ctl00_ContentPlaceHolder1_wifi').val() == 'wii-fii') {
                    if ($('#deviceCheck-inputs').find('.active').length > 2)
                        CounttextboxCreateHeader = parseInt(CounttextboxCreateHeader) + 1;
                }
                else {
                    if ($('#deviceCheck-inputs').find('.active').length > 3)
                        CounttextboxCreateHeader = parseInt(CounttextboxCreateHeader) + 1;
                }

            }
        }
        else {

            $('#link_SimRemovedDialog').attr('href', '#SimRemovedDialog');
            $('#deviceCheck-datacard').hide();// $('#deviceCheck_view .deviceCheck-item').width(200);
            if ($('#ctl00_ContentPlaceHolder1_wifi').val() == 'wii-fii') {
                if ($('#deviceCheck-inputs').find('.active').length > 2)
                    CounttextboxCreateHeader = parseInt(CounttextboxCreateHeader) + 1;
            }
            else {
                if ($('#deviceCheck-inputs').find('.active').length > 3)
                    CounttextboxCreateHeader = parseInt(CounttextboxCreateHeader) + 1;
            }

        }
        var arr = deviceCheckConfig.split(',');

        if (arr.length > 4) {
            for (var i = 0; i < arr.length; i++) {
                $('#deviceCheck-' + arr[i]).removeAttr('class');
                if (i == 3)
                    $('#deviceCheck-' + arr[i]).addClass("deviceCheck-item clearfix col-xs-12 col-sm-6 col-md-4 col-sm-offset-2");
                else
                    $('#deviceCheck-' + arr[i]).addClass("deviceCheck-item clearfix col-xs-12 col-sm-6 col-md-4 ");

                $('#deviceCheck-' + arr[i]).show();
            }
        }
        else if (arr.length == 3) {
            for (var i = 0; i < arr.length; i++) {
                $('#deviceCheck-' + arr[i]).removeAttr('class');
                $('#deviceCheck-' + arr[i]).addClass("deviceCheck-item clearfix col-xs-12 col-sm-6 col-md-4 ").show();

            }
        }
        else {
            for (var i = 0; i < arr.length; i++) {
                $('#deviceCheck-' + arr[i]).show();
            }
        }

    }
    if (name.toLowerCase() == "confirm.aspx") {
        var CounttextboxCreateHeader = 0;
        if ($('#ctl00_ContentPlaceHolder1_CustomerInfo1_hdnEnvelop').val() == "true") {

            CounttextboxCreateHeader = parseInt(CounttextboxCreateHeader) + 1;
        }
        else {
            CounttextboxCreateHeader = parseInt(CounttextboxCreateHeader) + 1;
        }
        if ($('#ctl00_ContentPlaceHolder1_CustomerInfo1_hqValidationVal').val() == "False") {
            $('#chkRemoved').attr('checked', 'checked');
            $('#chkRemoved2').attr('checked', 'checked');
            $('#chkCustomerConfirm').attr('checked', 'checked');
            $('#chkCustomerConfirm2').attr('checked', 'checked');
        }
        if ($.trim($('#ctl00_ContentPlaceHolder1_CustomerInfo1_Postcode').val()).length == 0) {
            $('#ctl00_ContentPlaceHolder1_CustomerInfo1_txtAddress1').css('display', 'none');
            $('#ctl00_ContentPlaceHolder1_CustomerInfo1_txtHouseNumber').css('display', 'none')
            $('#ctl00_ContentPlaceHolder1_CustomerInfo1_txtAddressLine2').css('display', 'none')
            $('#ctl00_ContentPlaceHolder1_CustomerInfo1_txtAddressLine3').css('display', 'none')
            $('#ctl00_ContentPlaceHolder1_CustomerInfo1_txtCity').css('display', 'none')
        }



        var RegexValidation = /^\d+$/;
        var emailRegexStr = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
        if ($.trim($('#ctl00_ContentPlaceHolder1_CustomerInfo1_Firstname').val()).length > 0)
            CounttextboxCreateHeader = parseInt(CounttextboxCreateHeader) + 1;
        if ($.trim($('#ctl00_ContentPlaceHolder1_CustomerInfo1_Lastname').val()).length > 0)
            CounttextboxCreateHeader = parseInt(CounttextboxCreateHeader) + 1;
        if ($.trim($('#ctl00_ContentPlaceHolder1_CustomerInfo1_EmailAddress').val()).length > 0)
            CounttextboxCreateHeader = parseInt(CounttextboxCreateHeader) + 1;




        if ($.trim($('#ctl00_ContentPlaceHolder1_CustomerInfo1_EmailAddress').val()).length > 0) {
            if (emailRegexStr.test($('#ctl00_ContentPlaceHolder1_CustomerInfo1_EmailAddress').val()) == true)
                CounttextboxCreateHeader = parseInt(CounttextboxCreateHeader) + 1;
        }

        if ($.trim($('#ctl00_ContentPlaceHolder1_CustomerInfo1_ConfirmEmailAddress').val()).length > 0) {

            if ($('#ctl00_ContentPlaceHolder1_CustomerInfo1_ConfirmEmailAddress').val().toLowerCase() == $('#ctl00_ContentPlaceHolder1_CustomerInfo1_EmailAddress').val().toLowerCase()) {

                CounttextboxCreateHeader = parseInt(CounttextboxCreateHeader) + 1;

            }


        }



        if ($.trim($('#ctl00_ContentPlaceHolder1_CustomerInfo1_MobileNo').val()).length > 0) {
            CounttextboxCreateHeader = parseInt(CounttextboxCreateHeader) + 1;


            //var phoneRegExp = /^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{5})$/;
            var str = $("#ctl00_ContentPlaceHolder1_CustomerInfo1_MobileNo").val().trim();
            var MobileNo = str.replace(/-/g, "");
            if (MobileNo.length >= 5)
                CounttextboxCreateHeader = parseInt(CounttextboxCreateHeader) + 1;
        }
        if ($("#ctl00_ContentPlaceHolder1_CustomerInfo1_txtIdentificationNo").length != 0) {
            var str = $("#ctl00_ContentPlaceHolder1_CustomerInfo1_txtIdentificationNo").val().trim();
            $('#ctl00_ContentPlaceHolder1_CustomerInfo1_txtIdentificationNo').addClass('form-control');
            if (str != '') {
                $('#errorIndentificationNo').css('display', 'block');
                $('#ctl00_ContentPlaceHolder1_CustomerInfo1_txtIdentificationNo').addClass('form-control error');
                if ($('#ctl00_ContentPlaceHolder1_CustomerInfo1_ddlIdentificationType :selected').text() == 'National Identity Card') {
                    var RegexStr = /^[0-9\b]+$/;
                    if (str.length > 15) {
                        $('#spnIdentificationNo').text('Length should not exceed 15 digits');
                    }
                    else if (RegexStr.test(str) == false) {
                        $('#spnIdentificationNo').text('Only digits are allowed');
                    }
                    else {
                        $('#errorIndentificationNo').css('display', 'none');
                        $('#spnIdentificationNo').empty();
                        $('#ctl00_ContentPlaceHolder1_CustomerInfo1_txtIdentificationNo').removeClass('form-control error');
                        $('#ctl00_ContentPlaceHolder1_CustomerInfo1_txtIdentificationNo').addClass('form-control');
                        CounttextboxCreateHeader = parseInt(CounttextboxCreateHeader) + 1;
                    }
                }
                else if ($('#ctl00_ContentPlaceHolder1_CustomerInfo1_ddlIdentificationType :selected').text() == 'Passport') {
                    var RegexStr = /^[0-9\b]+$/;
                    if (str.length > 9) {
                        $('#spnIdentificationNo').text('Length should not exceed 9 digits');
                    }
                    else if (RegexStr.test(str) == false) {
                        $('#spnIdentificationNo').text('Only digits are allowed');
                    }
                    else {
                        $('#errorIndentificationNo').css('display', 'none');
                        $('#ctl00_ContentPlaceHolder1_CustomerInfo1_txtIdentificationNo').removeClass('form-control error');
                        $('#ctl00_ContentPlaceHolder1_CustomerInfo1_txtIdentificationNo').addClass('form-control');
                        $('#spnIdentificationNo').empty();
                        CounttextboxCreateHeader = parseInt(CounttextboxCreateHeader) + 1;
                    }
                }
                else if ($('#ctl00_ContentPlaceHolder1_CustomerInfo1_ddlIdentificationType :selected').text() == 'Driving Licence') {
                    var RegexStr = /^[a-zA-Z0-9]*$/;
                    if (RegexStr.test(str) == false) {
                        $('#spnIdentificationNo').text('Only alphabets and digits are allowed');
                    }
                    else {
                        $('#ctl00_ContentPlaceHolder1_CustomerInfo1_txtIdentificationNo').removeClass('form-control error');
                        $('#ctl00_ContentPlaceHolder1_CustomerInfo1_txtIdentificationNo').addClass('form-control');
                        $('#errorIndentificationNo').css('display', 'none');
                        $('#spnIdentificationNo').empty();
                        CounttextboxCreateHeader = parseInt(CounttextboxCreateHeader) + 1;
                    }
                }
                else if ($('#ctl00_ContentPlaceHolder1_CustomerInfo1_ddlIdentificationType :selected').text() == 'UAE Citizen Card') {
                    var RegexStr = /^[a-zA-Z0-9]*$/;
                    if (RegexStr.test(str) == false) {
                        $('#spnIdentificationNo').text('Only alphabets and digits are allowed');
                    }
                    else {
                        $('#ctl00_ContentPlaceHolder1_CustomerInfo1_txtIdentificationNo').removeClass('form-control error');
                        $('#ctl00_ContentPlaceHolder1_CustomerInfo1_txtIdentificationNo').addClass('form-control');
                        $('#errorIndentificationNo').css('display', 'none');
                        $('#spnIdentificationNo').empty();
                        CounttextboxCreateHeader = parseInt(CounttextboxCreateHeader) + 1;
                    }
                }
                else {
                    $('#errorIndentificationNo').css('display', 'none');
                    $('#ctl00_ContentPlaceHolder1_CustomerInfo1_txtIdentificationNo').removeClass('form-control error');
                    $('#ctl00_ContentPlaceHolder1_CustomerInfo1_txtIdentificationNo').addClass('form-control');
                }
            }
        }
        /* Need Uncomment when Bank Account Enable.

        //if ($.trim($('#ctl00_ContentPlaceHolder1_CustomerInfo1_txtAcountNo').val()).length > 0)
        //    CounttextboxCreateHeader = parseInt(CounttextboxCreateHeader) + 1;


        //if ($.trim($('#ctl00_ContentPlaceHolder1_CustomerInfo1_txtSortcode').val()).length > 0)
        //    CounttextboxCreateHeader = parseInt(CounttextboxCreateHeader) + 1;

        */

        if (($.trim($('#ctl00_ContentPlaceHolder1_CustomerInfo1_txtHouseNumber').val()).length > 0))
            CounttextboxCreateHeader = parseInt(CounttextboxCreateHeader) + 1;
        if (($.trim($('#ctl00_ContentPlaceHolder1_CustomerInfo1_txtAddress1').val()).length > 0))
            CounttextboxCreateHeader = parseInt(CounttextboxCreateHeader) + 1;

        if ($.trim($('#ctl00_ContentPlaceHolder1_CustomerInfo1_txtCity').val()).length > 0)
            CounttextboxCreateHeader = parseInt(CounttextboxCreateHeader) + 1;

        if ($.trim($('#ctl00_ContentPlaceHolder1_CustomerInfo1_Postcode').val()).length > 0)
            CounttextboxCreateHeader = parseInt(CounttextboxCreateHeader) + 1;

        if ($('#deliveryDetails_content').find('.ui-state-active').length > 0)
            CounttextboxCreateHeader = parseInt(CounttextboxCreateHeader) + 1;

        if ($('#ctl00_ContentPlaceHolder1_CustomerInfo1_wifi').val() == 'wi-fi') {
            if (!($('#chkRemoved2').is(':checked')))
                $('#chkRemoved2').click();
            //$('#deviceCheck-sim').hide();
            $('#txt_cellular').hide(); $('#txt_wifi').show();
        }
        else {

            //if ($('#ctl00_ContentPlaceHolder1_CustomerInfo1_hdntheme').val() != null) {
            //    if ($('#ctl00_ContentPlaceHolder1_CustomerInfo1_hdntheme').val().trim() == "AppleUAE" || $('#ctl00_ContentPlaceHolder1_CustomerInfo1_hdntheme').val().trim() == "AppleBelgium") {
            //        if (modelTypee != null) {
            //            if (modelTypee == "mac") {
            //                $('#deviceCheck-sim').hide();
            //            }
            //        }
            //    }
            //    else {
            //        $('#deviceCheck-sim').show();
            //    } 
            $('#txt_cellular').show(); $('#txt_wifi').hide();
        }


        if (modelTypee) {

            if (modelTypee.toLowerCase() == 'android') {
                $('#link_SimRemovedDialog').attr('href', '#SimRemovedDialog_NONIOS');
                $('#deviceCheck-datacard').show(); //$('#deviceCheck_view .deviceCheck-item').width(230);
                $('.decisioniosnonios').hide(); $('#nonios').show(); $('#myModalDatawipenonios').show(); $('#DataWipeDialog').attr('title', 'Daten gelöscht');
                $('#deviceCheck-datawiped').find('#datawipedtitle').html('Daten gelöscht');
                $('#datawipe_description').text('Ich habe sämtliche persönlichen Daten vom Gerät gelöscht ');
                if ($('#deviceCheck-inputs').find('.active').length > 4)
                    CounttextboxCreateHeader = parseInt(CounttextboxCreateHeader) + 1;
            }
            else if (modelTypee.toLowerCase() == 'mac') {
                if ($('#deviceCheck-inputs').find('.active').length > 3)
                    CounttextboxCreateHeader = parseInt(CounttextboxCreateHeader) + 1;
            }
            else {

                $('#link_SimRemovedDialog').attr('href', '#SimRemovedDialog');
                $('#deviceCheck-datacard').hide();// $('#deviceCheck_view .deviceCheck-item').width(200);
                if ($('#ctl00_ContentPlaceHolder1_CustomerInfo1_wifi').val() == 'wii-fii') {
                    if ($('#deviceCheck-inputs').find('.active').length > 2)
                        CounttextboxCreateHeader = parseInt(CounttextboxCreateHeader) + 1;
                }
                else {
                    if ($('#deviceCheck-inputs').find('.active').length > 3)
                        CounttextboxCreateHeader = parseInt(CounttextboxCreateHeader) + 1;
                }

            }
        }
        else {

            $('#link_SimRemovedDialog').attr('href', '#SimRemovedDialog');
            $('#deviceCheck-datacard').hide();// $('#deviceCheck_view .deviceCheck-item').width(200);
            if ($('#ctl00_ContentPlaceHolder1_CustomerInfo1_wifi').val() == 'wii-fii') {
                if ($('#deviceCheck-inputs').find('.active').length > 2)
                    CounttextboxCreateHeader = parseInt(CounttextboxCreateHeader) + 1;
            }
            else {
                if ($('#deviceCheck-inputs').find('.active').length > 3)
                    CounttextboxCreateHeader = parseInt(CounttextboxCreateHeader) + 1;
            }

        }
        var count = 0;
        if ($('#ctl00_ContentPlaceHolder1_CustomerInfo1_hdntheme').val() != null) {
            if ($('#ctl00_ContentPlaceHolder1_CustomerInfo1_hdntheme').val().trim() == "AppleUAE") {
                count = 13;
            }
            else {
                if ($('#ctl00_ContentPlaceHolder1_CustomerInfo1_DivConfirmEmail').is(":visible"))
                    count = 13;
                else
                    count = 12;
            }
        }
        if (CounttextboxCreateHeader >= count)
            $('#ctl00_ContentPlaceHolder1_CustomerInfo1_btnOrderConfirm').removeAttr('disabled');
        //else
        //$('#ctl00_ContentPlaceHolder1_CustomerInfo1_btnOrderConfirm').attr('disabled', 'disabled');


        var arr = deviceCheckConfig.split(',');

        if (arr.length > 4) {
            for (var i = 0; i < arr.length; i++) {
                $('#deviceCheck-' + arr[i]).removeAttr('class');
                if (i == 3)
                    $('#deviceCheck-' + arr[i]).addClass("deviceCheck-item clearfix col-xs-12 col-sm-6 col-md-4 col-sm-offset-2");
                else
                    $('#deviceCheck-' + arr[i]).addClass("deviceCheck-item clearfix col-xs-12 col-sm-6 col-md-4 ");

                $('#deviceCheck-' + arr[i]).show();
            }
        }
        else if (arr.length == 3) {
            for (var i = 0; i < arr.length; i++) {
                $('#deviceCheck-' + arr[i]).removeAttr('class');
                $('#deviceCheck-' + arr[i]).addClass("deviceCheck-item clearfix col-xs-12 col-sm-6 col-md-4 ").show();

            }
        }
        else {
            for (var i = 0; i < arr.length; i++) {
                $('#deviceCheck-' + arr[i]).show();
            }
        }

    }
    if (name.indexOf('Thankyou.aspx') != -1) {
        if ($('#ctl00_ContentPlaceHolder1_iosnoniosdecision').val() == 'android') {
            $('#link_SimRemovedDialog').attr('href', '#SimRemovedDialog_NONIOS');
            $('#deviceCheck-datacard').show(); //$('#deviceCheck-inputs .deviceCheck-item').width(230);
            $('.decisioniosnonios').hide(); $('#nonios').show(); $('#myModalDatawipenonios').show(); $('#DataWipeDialog').attr('title', 'Data Wiped');
            $('#deviceCheck-datawiped').find('#datawipedtitle').html('Data Wiped');
            $('#datawipe_description').text('I have wiped the device of all personal data.');
        }
        else {

            $('#link_SimRemovedDialog').attr('href', '#SimRemovedDialog');
            $('#deviceCheck-datacard').hide(); //$('#deviceCheck-inputs .deviceCheck-item').width(200);
            //if ($('#ctl00_ContentPlaceHolder1_wifi').val() == 'wi-fi')
            //    $('#deviceCheck-sim').hide();

            //else {
            //    if (theme == "AppleUAE" || theme == "AppleBelgium") {
            //        if (modelType == "mac") {
            //            $('#deviceCheck-sim').hide();
            //        }
            //    }
            //    else {
            //        $('#deviceCheck-sim').show();
            //    }
            //}
        }
        var arr = deviceCheckConfig.split(',');

        if (arr.length > 4) {
            for (var i = 0; i < arr.length; i++) {
                $('#deviceCheck-' + arr[i]).removeAttr('class');
                if (i == 3)
                    $('#deviceCheck-' + arr[i]).addClass("deviceCheck-item clearfix col-xs-12 col-sm-6 col-md-4 col-sm-offset-2");
                else
                    $('#deviceCheck-' + arr[i]).addClass("deviceCheck-item clearfix col-xs-12 col-sm-6 col-md-4 ");

                $('#deviceCheck-' + arr[i]).show();
            }
        }
        else if (arr.length == 3) {
            for (var i = 0; i < arr.length; i++) {
                $('#deviceCheck-' + arr[i]).removeAttr('class');
                $('#deviceCheck-' + arr[i]).addClass("deviceCheck-item clearfix col-xs-12 col-sm-6 col-md-4 ").show();

            }
        }
        else {
            for (var i = 0; i < arr.length; i++) {
                $('#deviceCheck-' + arr[i]).show();
            }
        }

    }


    $(document).ready(function () {
        $('.accordion').accordion({
            active: false,
            collapsible: true
        });


        $("#InspectionContainer_btnGroup #btnContinue").button("option", "disabled", true);
        $("#carriers").change(function () {
            check_carrier();
        });


    });
}

function has_IMEI() {
    if (jQuery('#chkPowerOn').is(':checked')) {
        jQuery('#txtIMEI').removeAttr("disabled");
        jQuery('#txtSerialNo').removeAttr("disabled");
    } else {
        jQuery('#txtIMEI').attr("disabled", "disabled");
        jQuery('#txtSerialNo').attr("disabled", "disabled");
    };
}

$(document).ready(function () {

    $(".open-dialog-small-no-close").click(function () {
        $($(this).attr("href")).dialog({
            dialogClass: "no-close",
            width: 450,
            height: 250,
            resizable: false,
            draggable: false,
            modal: true,
            position: ["center", 45],
            open: function (event, ui) {
                $('html').css({ overflow: 'hidden' });
            },
            close: function (event, ui) {
                $('html').css({ overflow: 'scroll' });
            }
        });
        return false;



    });






    $('#btnCancelOrderClose').click(function (ev) {
        ev.preventDefault();
        $('#CancelOrderDialog').dialog('close');
    });




    $('.close-icon').click(function (ev) {
        ShowLoading();
        window.location.href = "MyOrders.aspx";
    });


});
//(function (i, s, o, g, r, a, m) {
//    i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
//        (i[r].q = i[r].q || []).push(arguments)
//    }, i[r].l = 1 * new Date(); a = s.createElement(o),
//    m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
//})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');

////ga('create', 'UA-57670542-1', 'auto');
//ga('create', 'UA-58619757-1', 'auto');
//ga('send', 'pageview');


function showdialog(target) {

    $($(target).attr("href")).dialog({
        width: 750,
        height: 510,
        resizable: false,
        draggable: false,
        modal: true,
        position: ["center", 50],
        open: function (event, ui) {
            $($(target).attr("href")).hide();

            window.setTimeout(function () {

                $($(target).attr("href")).show();
                $('body').scrollTop(420);
                $('html').css({ overflow: 'hidden' });
            }, 0);
        },
        close: function (event, ui) {

            $('html').css({ overflow: 'scroll' });
        }
    });

    return false;
}

function ShowLoading() {
    //var modal = $('<div  />');
    //modal.addClass("modal");
    //modal.attr("id", "modalSending");
    //$('body').append(modal);
    //var loading = $("#modalSending.loading");
    //loading.show();
    //var top = '40%';
    //var left = '45%';
    //loading.css({ top: top, left: left, color: '#ffffff' });
    onUpdating();
}


function StopLoading() {

    //$("div.modal").hide();

    //var loading = $(".loading");
    //loading.hide();
    onUpdated();
}
