/*
*   Release notes
*   ----------------------------------------------------------------
*   Name: ecShopLibrary
*   Authors: R&D / Special Projects
*   Version: 2.16
*   Last modified: 12 Feb 2010 by Jai
*
*   Note: This file is maintained in the .NET solution "ecShop".
*   Do not modify it directly on the server.
*                                            
*   Naming conventions:                                
*   - global variables: _ecshopXXXX
*   - functions: ecShopXXX()
*
*   Last modified:
*   Optimized global variables and local variables.
*   
*   URL to Compress JS http://javascriptcompressor.com/
*/


_esOkBtn = ecTranslate("common-buttons.common-ok");
_esCancelBtn = ecTranslate("common-buttons.common-cancel");
_esClose = ecTranslate("common-buttons.common-close-window");
_esNoStockMsg = ecTranslate("product-labels.product-nostock");
_ecshopShowSearchResult = ecTranslate("product-labels.product-back-to-search");
_ecshopHideSearchResult = ecTranslate("product-labels.product-search-hide-result");
var mod_pos = "";

/***************************************\\
//                                      \\
//             Login starts             \\
//                                      \\
//***************************************/
function dontShowLogin(a){
    /* Update cookie for dontregister*/
    /* To skip login page for anonymous user*/
    if(a.checked)
        ecShopAddOrUpdateArray("dontregister","true");
}
/* Clear loggedin cookies when the user logs out.*/
function ecShopLogout(){
    /* Cookie to store userid*/
    createCookie('ecwebuserid' + _ecshopWebsiteId + 'd','',0);
    /* Cookie to store user logged in or not*/
    createCookie(_esUserLogInCookie,'',0);
}
/***************************************\\
//                                      \\
//             Login ends               \\
//                                      \\
//***************************************/

/***************************************\\
//                                      \\
//          Checkout starts             \\
//                                      \\
//***************************************/
/* Calls in smallcart and largecart to redirect checkout page after checking authentication*/
function ecShopGoToCheckout(a,b,d){
    /*a = LoginLink, b = CheckoutLink, c = UserId*/
    var c = readCookie(_esUserLogInCookie);
    var l;
    /*Set cookie as "0" if undefined or null*/
    if(c == 'undefined' || c == '' || c == null){
        c = "0";
    }
    /* Checking userId
     If true - add checkout link
     else - add login link*/
    if(d.length>0){
        l = b;
    }
    else{
        l = a;
    }
    /* Check value To skip login page for anonymous user*/
    var e = ecShopReturnFieldFromCookie("dontregister");
    var f = 1;
    
    /* 'sign_in' - page name
    // If sign_in page - redirect to sign_in page 
    // else - redirect to checkout page with step1*/
    var g = (l.indexOf('sign_in')>0)?l:(l + "#step" + f);
    
    /* Google tracker in checkout step*/
    ecShopGoogleTrackCheckout(f);
    
    /* To skip login page for anonymous user
    // If true -  redirect to checkout step1
    // else - redirect to specifie link (sign_in page or checkout step1 page)*/
    if(e == "true" && b.length>0){
        location.replace(b + '#step' + f);
    }
    else{
        var h = document.location.href;
        /* Checks if current page is checkout step4, true - return to step1*/
        if(h.indexOf('#step4')>0){
            location.replace(l + "#step1");
            /* Hack for IE browser to refresh the page*/
            if(navigator.appName == 'Microsoft Internet Explorer'){
                /* way to refresh the current page in IE browser*/
                history.go(0); 
            }
            else{
                /* way to refresh the current page for other browsers*/
                window.location.reload();
            }
        }
        else{
            location.replace(g);
        }
    }
}
/*Calls in checkout step1 page onload - in ecShop - Order form template
Show addresses based on registered user and non registered users*/
function ecShopLoadCheckout(){
    /* Sets true till the user is in checkout page - Used for checkout history from browser back button*/
    _esInOrderProcess = true;
    /* Update CSS to Highlight the tab to let the user know that we are in step1*/
    ecShopChangeSelectedTab(1);
    /* To let the code knows that the user left checkout page*/
    window.onunload = ecShopLeaveCheckout;
    /* If user loggedin - loads address for that registered user*/
    /* else - Load address form to fill address as anonymous user*/
    if(_esUserId.length>0){
        ecShopGetAddresses("webshop",_esUserId,"ecshopfx_address_list",true);
    }
    else{
        /* Load addresses from global variable */
        /* Else get the form from webservice*/
        if(_esAddrFormat != null){
            ecShopLoadStep1NotRegistered(_esAddrFormat);
        }
        else{
            /*ecShopLoadStep1NotRegistered - Success response - Call back function 
            OnError - Error response - Call back function*/
            ecShop.Web.Soap.ecShopWS.GetAddressForm(ecShopLoadStep1NotRegistered,OnError);
        }
    }
}
/*Update cookies and timer when the user leaves checkout*/
function ecShopLeaveCheckout(){
    /* Sets false till the user comes back to checkout page - Used for checkout history from browser back button*/
    _esInOrderProcess = false;
    /* Clears timer which runs in checkout when the page is idle */
    /* Helps to retirect the user to home page after timeout limit given in ecShop settings*/
    clearInterval(_esObserveTimer);
    
    /* Sets global variable to use the cookies again in checkout*/
    if(_esUseCookiesInCheckout){
        /* Updated cookie with info of user leaving checkout*/
        ecShopAddOrUpdateArray("leftcheckout",true);
    }
}
/*Updates checkout steps everytime the users goes to each step*/
function ecShopUpdateCheckoutUrl(a){
    if(location.hash != "#step" + a){
        location.href = location.pathname + location.search + "#step" + a;
    }
}
/*Load registered users addresses in step1*/
function ecShopLoadStep1Registered(){
    /*Checks for cookies for already loaded address*/
    if(_esUseCookiesInCheckout){
        var a = ecShopReturnFieldFromCookie("leftcheckout");
        /*Checks cookie for left checkout before*/
        if(a == "true"){
            /* Gets selected billing position from cookie*/
            var b = ecShopReturnFieldFromCookie("selectedbilling");
            var c = 0;
            /* Default position for billing address is set to 0*/
            if(b == null || b == ""){
                b = 0;
            }
            else{
                /*Checked already selected billing address option*/
                var d = document.getElementById("ecshopfx_billing_radio_" + b);
                if(d){
                    d.checked = true;
                }
            }
            /* Check for show shipping option*/
            var e = ecShopReturnFieldFromCookie("showshipping");
            
            if(e == "true"){
                var f = document.getElementById("ecshopfx_other_shipping_address");
                /* Gets selected shipping position from cookie*/
                c = ecShopReturnFieldFromCookie("selectedshipping");
                /* Default position for shipping address is set to 0*/
                if(c == null || c == ""){
                    c = 0;
                }
                else{
                    /*Checked already selected shipping address option*/
                    var g = document.getElementById("ecshopfx_shipping_radio_" + b);
                    if(g){
                        g.checked = true;
                    }
                }
                /* Show shipping address area if show shipping is true*/
                if(f){
                    f.checked = true;
                    toggleObject("ecshopfx_shipping_address");
                }
            }
            /* Checks for current step from cookie 
             Helps to return back to step2 if the user left checkout form 2nd or 3rd step*/
            var s = ecShopReturnFieldFromCookie("step");
            if(s.length>0){
                if(s == 2 || s == 3){
                    /* Hides step1 and shows step2*/
                    goStep2();
                    /* Updates urls for history*/
                    ecShopUpdateCheckoutUrl(2);
                }
            }
            /* User is in checkout now so, sets to false*/
            ecShopAddOrUpdateArray("leftcheckout",false);
        }
    }
}
/*Load address form for not registered users in step1*/
function ecShopLoadStep1NotRegistered(r){
    /* Loads form in global variable if the user is coming back to checkout for 2nd time*/
    if(_esAddrFormat == null){
        _esAddrFormat = r;
    }
    /* Creates address form*/
    ecShopCreateAddressForm(r,"ecshopfx_billing_box",_esShopParam,"billing");
    /*Checks for cookies for already loaded address*/
    if(_esUseCookiesInCheckout){
        var a = ecShopReturnFieldFromCookie("leftcheckout");
        /*Checks cookie for left checkout before*/
        if(a == "true"){
            /*Get billing address details from cookie*/
            ecShopUpdateAddressFromCookie("billing");
            
            /* Check for show shipping option*/
            var b = ecShopReturnFieldFromCookie("showshipping");
            if(b == "true"){
                var d = document.getElementById("ecshopfx_other_shipping_address");
                /* Enable shipping address form*/
                if(d){
                    d.checked = true;
                    ecShopShowShippingAddress();
                }
            }
            /*Get entered e-mail from cookie and update value in field*/
            var e = ecShopReturnFieldFromCookie("email");
            var c = document.getElementById(_esShopParam + "email");
            if(c){
                if(c.value == ""){
                    c.value = e;
                }
            }
            /* Checks for current step from cookie 
             Helps to return back to step2 if the user left checkout form 2nd or 3rd step*/
            var s = ecShopReturnFieldFromCookie("step");
            if(s.length>0){
                if(s == 2 || s == 3){
                    /* Hides step1 and shows step2*/
                    goStep2();
                    /* Updates urls for history*/
                    ecShopUpdateCheckoutUrl(2);
                }
            }
            /* User is in checkout now so, sets to false*/
            ecShopAddOrUpdateArray("leftcheckout",false);
        }
    }
}
/*Address management
Create address for to display in checkout step 1 for anonymous user*/
function ecShopCreateAddressForm(r,a,b,c){
    /*r - results (from webservice), a - elementId (ecshopfx_billing_box or ecshopfx_shipping_box), b - shopparam (ec_webshop_page_{position}_), c - prefix (shipping or billing)*/
    if(c == undefined)
        c = "";
    var d = '';
    /* Forming HTML with form values*/
    for(var i=0;i<r.length;i++){
        /* Lang translation - collection*/
        var e = "common-labels.";
        /* Lang translation - word*/
        var f = "common-field-" + r[i].Xml;
        /* Get translated value*/
        var t = ecTranslate(e+f);
        /* Checks the translation result is giving error or result, If error - displays name in 'En' else displays translated name*/
        var n = (t.indexOf(f)>-1)?r[i].Name:t;
        d += '<div class="clear">';
        d += '   <label for="' + b+c+r[i].Xml + '">' + (r[i].Validation.indexOf("validate")>-1?'* ':'') + ' ' + n + '</label>';
        /* if true - Disabling edit preference for readonly field*/
        if(r[i].IsReadOnly){
            d += '   <input id="' + b+c+r[i].Xml + '" name="' + b+r[i].Xml + '" class="' + r[i].Validation + '" size="20" maxlength="' + r[i].MaxLength + '" value="' + r[i].DefaultValue + '" readonly="readonly"></input>';
        }else{
            d += '   <input id="' + b+c+r[i].Xml + '" name="' + b+r[i].Xml + '" class="' + r[i].Validation + '" size="20" maxlength="' + r[i].MaxLength + '" value=""></input>';
        }
        d += '</div>';
    }
    /* Overwrites HTML in the given id.*/
    ReplaceContent(a,d);
}

/* Toggle shipping show and hide option based on 'Other than billing' option*/
function ecShopShowShippingAddress(){
    var a = document.getElementById("ecshopfx_shipping_address");
    if(a){
        toggleObject("ecshopfx_shipping_address");
        if(a.className.indexOf("ecshop_hide")<0){
            var b = document.getElementById("ecshopfx_shipping_box");
            if(b){
                /* Creates address form*/
                ecShopCreateAddressForm(_esAddrFormat,"ecshopfx_shipping_box",_esShopParam,"shipping");
                /* Get values from cookie and update shipping details*/
                if(_esUseCookiesInCheckout)
                    ecShopUpdateAddressFromCookie("shipping");
            }
        }
    }
    /* Update show shipping in cookie*/
    var c = document.getElementById("ecshopfx_other_shipping_address");
    if(c){
        ecShopAddOrUpdateArray("showshipping",c.checked);
    }
}

/*Read addresses from step1 and display in step2*/
function ecShopLoadAddressesFromStep1(a,b){
    /* a - Position of selected billing option, b - Position of selected shipping option  */
    if(_esAddrFormat == null){
        /* If global variable is null, then get arry format*/
        ecShopGetAddressFormatArray();
        /* Recursive call to get the values of the selected option*/
        setTimeout("ecShopLoadAddressesFromStep1('" + a + "', '" + b + "')",500);
    }
    else{
        /* Setting default position as 0 for the billing option*/
        if(a == undefined)
            a = 0;
        /* Setting default position as 0 for the shipping option*/
        if(b == undefined)
            b = 0;
            
        if(a>0){
            /*Checked selected option*/
            var c = document.getElementById("ecshopfx_billing_radio_" + a);
            if(c){
                c.checked = true;
            }
            /* Update in cookie array*/
            ecShopAddOrUpdateArray("selectedbilling",a);
        }
        /* Get selected billing address details/values*/
        var d = ecShopLoadAddress("billing",a);
        /* Display selected billing address in step2*/
        ReplaceContent("ecshopfx_billing_from_step_1",d);
        /* Check for shipping address is enabled 
         If true - Get address details and display shipping address in step2
         else - Display billing address in shipping address area and show 'Same as billing address' text.*/
        var e = document.getElementById("ecshopfx_other_shipping_address");
        if(e.checked){
            if(b>0){
                var f = document.getElementById("ecshopfx_shipping_radio_" + b);
                if(f){
                    f.checked = true;
                }
                ecShopAddOrUpdateArray("selectedshipping",b)
            }
            /* Get selected shipping address details/values*/
            var g = ecShopLoadAddress("shipping",b);
            /* Display selected shipping address in step2*/
            ReplaceContent("ecshopfx_shipping_from_step_1",g);
            hideObject("ecshopfx_same_as_billing");
        }
        else{
            /*Display billing address in shipping address area*/
            ReplaceContent("ecshopfx_shipping_from_step_1",d);
            /*show 'Same as billing address' text*/
            showObject("ecshopfx_same_as_billing");
        }
    }
}

/* Get address values for the fields based on the selected option*/
function ecShopLoadAddress(b,d){
    var e = '';
    var a = _esCookieArray;
    if(d == undefined){
        d = 0;
    }
    /* If the address exist in cookie, load from cookie*/
    if(_esUseCookiesInCheckout  &&  d == 0){
        ecShopUpdateAddressFromCookie(b);
    }
    /* Get values of each field in the address format*/
    for(var i=0;i<_esAddrFormat.length;i++){
        var v = "";
        var c = "";
        /* Get value for registered users from div*/
        if(d>0){
            var f = "ecshopfx_" + b + "_option_" + d + "_" + _esAddrFormat[i].Xml;
            c = document.getElementById(f);
            if(c){
                v = c.innerHTML;
            }
        }
        /* Get value for anonymous users from form fields*/
        else{
            c = document.getElementById(_esShopParam+b+_esAddrFormat[i].Xml);
            if(c){
                v = c.value;
            }
        }
        /* If the value for that field is empty, then get value form cookie "a[b+_esAddrFormat[i].Xml]" - eg: a['shippingfirstname'] or a['billingfirstname']*/
        if(v == "" || v == undefined || v == "undefined"){
            v = a[b+_esAddrFormat[i].Xml];
        }
        /* Combines all address field values and with line break if added and returns.*/
        if(v != "" && v != undefined){
            e += v;
            if(_esAddrFormat[i].LineBreak){
                e += '<br/>';
            }
            else{
                e += ' ';
            }
        }
    }
    /* Return value eg: 4304158399<br/>Karlls Lidin<br/>Junibacksg 42<br/>Sweden<br/>Hollviken<br/>23634<br/>*/
    return e;
}
/*Add or update selected address details in array*/
function ecShopChooseAddress(a,b){
    /* a - selected option position, b - "shipping" or "billing"
     _esXmlAttribs - requested attributes array - hardcoded in global variable declaration file.*/
    var d = _esXmlAttribs.length;
    for(var i=0;i<d;i++){
        /* eg: "ecshopfx_billing_option_1_firstname*/
        var e = "ecshopfx_" + b + "_option_" + a + "_" + _esXmlAttribs[i];
        var c = document.getElementById(e);
        if(c){
            var v = c.innerHTML;
            /* Updates in array*/
            ecShopAddOrUpdateArray(b+_esXmlAttribs[i],v);
        }
    }
}
/* To select selected shipping and payment method*/
function ecShopLoadMethods(a,b){
    var v = ecShopReturnFieldFromCookie(a);
    var n = ecShopReturnFieldFromCookie(b);
    if(v.length>0){
        var c = document.getElementsByName(_esShopParam+a);
        if(c){
            for(var i=0;i<c.length;i++){
                if(c[i].value == (n + "|" + v)){
                    c[i].checked = true;
                    return true;
                }
            }
        }
    }
    return false;
}

/*Form xml for address to add in orderInfo xml.*/
function ecShopCreateOrderAddressXml(a,b){
    /* a - shipping or billing, b - Number of addresses*/
    var n = "";
    /* default position if not sent*/
    if(b == undefined){
        b = "1";
        _esAddrXml = "";
    }
    /* Check for shipping values if, if not checked, then assign billing*/
    if(a == "shipping"){
        var c = ecShopReturnFieldFromCookie("showshipping");
        var d = ecShopReturnFieldFromCookie("shippingfirstname");
        if(c == "false" || d == undefined || d == ""){
            a = "billing";
        }
    }
    /* _esXmlAttribs - requested attributes array - hardcoded in global variable declaration file.*/
    var e = _esXmlAttribs.length;
    /* Get values and form Xml*/
    for(var i=0; i<e; i++){
        /* a+_esXmlAttribs[i] - eg: billingfirstname or shippingfirstname*/
        /* Get field value from cookie*/
        var v = ecShopReturnFieldFromCookie(a+_esXmlAttribs[i]);
        /* If we have both shipping and billing address then we need to add the billing address as custom attributes*/
        n = (a == "billing" && b == "2") ? ("custom_billing_" + _esXmlAttribs[i]) : _esXmlAttribs[i];
        if(v != undefined && v != ""){
            _esAddrXml += "<attribute><name>" + n + "</name><value>" + v + "</value></attribute>";
        }
    }
     /* If we have both shipping and billing address, add shipping values in normal attributes and billing in custom attributes*/
    if(a == "shipping"){
        ecShopCreateOrderAddressXml("billing","2");
        /* Return value eg: <attribute><name>custom_billing_firstname</name><value>Karlls Lidin</value></attribute><attribute><name>custom_billing_address</name><value>Junibacksg 42</value></attribute><attribute><name>custom_billing_region</name><value>Sweden</value></attribute><attribute><name>custom_billing_state</name><value>Hollviken</value></attribute><attribute><name>custom_billing_phone</name><value>23634</value></attribute><attribute><name>ssn</name><value>4304158399</value></attribute><attribute><name>firstname</name><value>Karlls Lidin</value></attribute><attribute><name>address</name><value>Junibacksg 42</value></attribute><attribute><name>region</name><value>Sweden</value></attribute><attribute><name>state</name><value>Hollviken</value></attribute><attribute><name>phone</name><value>23634</value></attribute>*/
        return _esAddrXml;
    }
    else{
        /* Return value eg: <attribute><name>firstname</name><value>Karlls Lidin</value></attribute><attribute><name>address</name><value>Junibacksg 42</value></attribute><attribute><name>region</name><value>Sweden</value></attribute><attribute><name>state</name><value>Hollviken</value></attribute><attribute><name>phone</name><value>23634</value></attribute>*/
        return _esAddrXml;
    }
}

/* display cookie values in form fileds*/
function ecShopUpdateAddressFromCookie(a){
    _esCookieArray = ecShopReturnArray();
    var d = _esXmlAttribs.length;
    for(var b=0;b<d;b++){
        /* Read value from cookie array and display in field, _esShopParam+a+_esXmlAttribs[b] - eg: ec_webshop_page_6_billingfirstname*/
        /* Get field object*/
        var c = document.getElementById(_esShopParam+a+_esXmlAttribs[b]);
        if(c){
            /* read value from cookie and update value*/
            var v = _esCookieArray[a+_esXmlAttribs[b]];
            if(v != null && c.value == ""){
                c.value = v;
            }
        }
    }
}

/*Save address values in array*/
function ecShopSaveAddressInArray(a){
    /* _esXmlAttribs - requested attributes array - hardcoded in global variable declaration file.*/
    var b = _esXmlAttribs.length;
    /* Get each address field values and save it in array*/
    for(var c=0;c<b;c++){
        var c = document.getElementById(_esShopParam+a+_esXmlAttribs[c]);
        if(c){
            /* a+_esXmlAttribs[c] - eg: billingfirstname or shippingfirstname*/
            ecShopAddOrUpdateArray(a+_esXmlAttribs[c],c.value);
        }
    }
}

/*Timeout functions*/
/* To track browser idle time in checkout*/
function ecShopTrackIdleTime(){
    var a = document.body;
    /* resets counter for every mousemove and keydown event*/
    if(a.attachEvent){
        a.attachEvent('onmousemove',ecShopResetCounter);
        a.attachEvent('onkeydown',ecShopResetCounter);
    }
    /* resets counter for every mousemove and keydown event listners */
    else if(a.addEventListener){
        try{
            emulateAttachEvent();
            a.attachEvent('mousemove',ecShopResetCounter);
            a.attachEvent('keydown',ecShopResetCounter);
        }
        catch(err){
            a.onmousemove = ecShopResetCounter;
            a.onkeydown = ecShopResetCounter;
        }
    }
    ecShopStartCounter();
}

function emulateAttachEvent(){
    HTMLDocument.prototype.attachEvent = HTMLElement.prototype.attachEvent = function(a,b){
        var c = a.replace(/on/,"");
        b._ieEmuEventHandler = function(e){
            window.event = e;
            return b();
        };
        this.addEventListener(c,b._ieEmuEventHandler,false);
    };
    HTMLDocument.prototype.detachEvent = HTMLElement.prototype.detachEvent = function(a,b){
        var c = a.replace(/on/,"");
        if(typeof b._ieEmuEventHandler == "function")
            this.removeEventListener(c,b._ieEmuEventHandler,false);
        else 
            this.removeEventListener(c,b,true);
    }
}
/* To increment counter*/
function ecShopIncreaseCounter(){
    var x = 0;
    /* Reading cookie value*/
    x = (readCookie(_esTimeoutCookie) != null || readCookie(_esTimeoutCookie) != undefined)?readCookie(_esTimeoutCookie):0;
    var a = parseInt(x);
    /* Check idle delay period*/
    var d = 60000;
    /*_ecshopIdleTimeout - Timeout value entered in ecShop settings*/
    var b = parseInt(_ecshopIdleTimeout);
    /* Check and increase timer for every delay time*/
    if(a<b){
        a = a+1;
        createCookie(_esTimeoutCookie,a,1);
        _esTimeoutObj = setTimeout("ecShopIncreaseCounter()",d);
    }
    /* If it reaches the timeout limit, then clear all cookies and redirect the user to home page if they are in account or checkout page.*/
    else if(a >= b){
        clearTimeout(_esTimeoutObj);
        createCookie(_esTimeoutCookie,'-1',-1);
        ecShopLogout();
        ecShopDeleteAllCookies();
        var c = document.location.href;
        if(c.toLowerCase().indexOf('checkout')>-1 || c.toLowerCase().indexOf('account')>-1){
            document.location.href = ecShopReturnHost();
        }
    }
}
/*Create tiout cookie and increase counter*/
function ecShopStartCounter(){
    createCookie(_esTimeoutCookie,'0',1);
    ecShopIncreaseCounter();
}
/* Clear counter and restart the counter*/
function ecShopResetCounter(){
    clearTimeout(_esTimeoutObj);
    ecShopStartCounter();
}
/* Onload event*/
ecShopAddLoadEvent(ecShopTrackIdleTime);

/*Cookie handling functions
 Add new node in cookie*/
function ecShopSaveNodesInCookie(){
    var a = "";
    /* Already added new node in array, gets every array nodes and adds separator and save in cookie*/
    var b = _esNodeArray.length;
    for(var x=0;x<b;x++){
        a += _esNodeArray[x] + "|";
    }
    createCookie(_esNodeCookie,a,1);
}
function ecShopReturnNodesFromCookie(a){
    /* a - cookie name*/
    /* b - eg: showshipping|billingfirstname|billinglastname|billingaddress|billingpostalcode|billingcity|billingstate|email|step|shippingfirstname|shippinglastname|shippingaddress|shippingpostalcode|shippingcity|shippingstate|paymentmethod|paymentname|shippingmethod|shippingname|leftcheckout|*/
    var b = readCookie(a);
    var c = 0;
    var n = new Array();
    if(b == null){
        b = "";
    }
    if(b.length>0){
        var d = b.split("|");
        for(var y=0;y<d.length;y++){
            if(d[y] != ""){
                n[c] = d[y];
                c++;
            }
        }
    }
    /* Returns nodes as eg: n[0] = showshipping, n[1] = billingfirstname, etc..*/
    return n;
}
function ecShopReturnArray(a){
    if(a == undefined){
        a = "";
    }
    /* Returns nodes array*/
    if(a == "nodes"){
        if(_esNodeArray.length == 0){
            _esNodeArray = ecShopReturnNodesFromCookie(_esNodeCookie);
        }
        /* Returns nodes as eg: showshipping|billingfirstname|billinglastname|billingaddress|billingpostalcode|billingcity|billingstate|email|step|shippingfirstname|shippinglastname|shippingaddress|shippingpostalcode|shippingcity|shippingstate|paymentmethod|paymentname|shippingmethod|shippingname|leftcheckout|*/
        return _esNodeArray;
    }
    else{
        /* Checks for name fields*/
        /* If true - Returns "shopinfo" cookie values*/
        if(_esCookieArray["billingfirstname"] == undefined || _esCookieArray["billingfirstname"] == ""){
            _esCookieArray = ecShopReturnArrayFromCookie(_esCheckoutCookie);
        }
        
        /* Return value - eg: showshipping:ecsplit:true^ecsplit^billingfirstname:ecsplit:BillFname^ecsplit^billinglastname:ecsplit:BillLname^ecsplit^billingaddress:ecsplit:Billaddress^ecsplit^billingpostalcode:ecsplit:123^ecsplit^billingcity:ecsplit:^ecsplit^billingstate:ecsplit:BillState^ecsplit^email:ecsplit:jaisuganthi@ec.is^ecsplit^step:ecsplit:1^ecsplit^shippingfirstname:ecsplit:ShipFname^ecsplit^shippinglastname:ecsplit:ShipLname^ecsplit^shippingaddress:ecsplit:Shipaddress^ecsplit^shippingpostalcode:ecsplit:111^ecsplit^shippingcity:ecsplit:^ecsplit^shippingstate:ecsplit:ShipState^ecsplit^paymentmethod:ecsplit:b460ed0e-a5b1-4a4c-9b8a-3bfdfca3a4e3^ecsplit^paymentname:ecsplit:Invoice^ecsplit^shippingmethod:ecsplit:d53e34d2-8628-4746-a1c2-9fbbf8a7237f^ecsplit^shippingname:ecsplit:Dynamic rate order price^ecsplit^leftcheckout:ecsplit:false^ecsplit^*/
        return _esCookieArray;
    }
}
/* Update array values to save in cookie*/
function ecShopAddOrUpdateArray(a,b){
    /* a - Node name, b - Node value*/
    /* Reads cookie array - eg: showshipping:ecsplit:true^ecsplit^billingfirstname:ecsplit:BillFname^ecsplit^billinglastname:ecsplit:BillLname^ecsplit^*/
    _esCookieArray = ecShopReturnArray();
    /* Reads nodes array - eg: showshipping|email|userid|*/
    _esNodeArray = ecShopReturnArray("nodes");
    
    var c = _esCookieArray[a];
    if(c == null || c == undefined){
        /* Add name as node with existing array nodes*/
        _esNodeArray[_esNodeArray.length] = a;
        /* Get all nodes from array and save in cookie*/
        ecShopSaveNodesInCookie();
    }
    /* Assign value to the newly added node*/
    _esCookieArray[a] = b;
    /* Check cookie enable, and save the node and values in cookie*/
    if(_esUseCookiesInCheckout){
        ecShopSaveArrayInCookie(_esCheckoutCookie,_esCookieArray);
    }
}

function ecShopSaveArrayInCookie(a,b){
    var c = "";
    var d = _esNodeArray.length;
    for(var z=0;z<d;z++){
        /*_esNodeArray[z] - node name, b[_esNodeArray[z]] - node value*/
        c += _esNodeArray[z] + ":ecsplit:" + b[_esNodeArray[z]] + "^ecsplit^";
    }
    createCookie(a,c,1);
}
function ecShopReturnArrayFromCookie(b){
    /* b - Cookie name*/
    var c = readCookie(b);
    var d = new Array();
    if(c == null){
        c = "";
    }
    /* Splits cookie and form as array*/
    if(c.length>0){
        var e = c.split("^ecsplit^");
        for(var a=0;a<e.length;a++){
            if(e[a].length>0){
                var v = e[a].split(":ecsplit:");
                if(v[0] != null && v[1] != null){
                    d[v[0]] = v[1];
                }
            }
        }
    }
    /* Return value - Eg: showshipping:ecsplit:true^ecsplit^billingfirstname:ecsplit:BillFname^ecsplit^billinglastname:ecsplit:BillLname^ecsplit^billingaddress:ecsplit:Billaddress^ecsplit^billingpostalcode:ecsplit:123^ecsplit^billingcity:ecsplit:^ecsplit^billingstate:ecsplit:BillState^ecsplit^email:ecsplit:jaisuganthi@ec.is^ecsplit^step:ecsplit:1^ecsplit^shippingfirstname:ecsplit:ShipFname^ecsplit^shippinglastname:ecsplit:ShipLname^ecsplit^shippingaddress:ecsplit:Shipaddress^ecsplit^shippingpostalcode:ecsplit:111^ecsplit^shippingcity:ecsplit:^ecsplit^shippingstate:ecsplit:ShipState^ecsplit^paymentmethod:ecsplit:b460ed0e-a5b1-4a4c-9b8a-3bfdfca3a4e3^ecsplit^paymentname:ecsplit:Invoice^ecsplit^shippingmethod:ecsplit:d53e34d2-8628-4746-a1c2-9fbbf8a7237f^ecsplit^shippingname:ecsplit:Dynamic rate order price^ecsplit^leftcheckout:ecsplit:false^ecsplit^*/
    return d;
}
/* Returns node value*/
function ecShopReturnFieldFromCookie(a){
    /* a - node name*/
    _esCookieArray = ecShopReturnArray();
    var v = _esCookieArray[a];
    if(v != null){
        return v;
    }
    else{
        return"";
    }
}
/* Checkout history*/
function ecShopHistoryStep(a,b){
    /* a - step, b - goingback (true or false)*/
    var c = false;
    _esInOrderProcess = true;
    if(a == 1){
        goBackToStep1();
    }
    else{
        /* If left checkout stays in same step*/
        if(_esUseCookiesInCheckout){
            var d = ecShopReturnFieldFromCookie("leftcheckout");
            if(d == "true"){
                c = true;
            }
        }
        if(!c){
            ecShopCheckoutStep(a,b);
        }
    }
}

function ecShopCheckoutStep(a,b){
    /* a - step, b - goingback (true or false)*/
    if(b == undefined)
        b = false;
    if(b){
        if(a == 1)
            goBackToStep1();
        else if(a == 2)
            goBackToStep2();
    }
    else{
        if(a == 2)
            goStep2();
        else if(a == 3)
            goStep3();
        else if(a == 4)
            goStep4();
    }
}
/* GO back from checkout step2 to step1*/
function goBackToStep1(){
    ecShopCheckoutTransform(1);
}
/* Go to checkout step2*/
function goStep2(){
    /* Logged in userid - Guid*/
    var a = _esUserId;
    var b = document.getElementById("ecshopfx_other_shipping_address");
    if(b){
        ecShopAddOrUpdateArray("showshipping",b.checked);
    }
    /* If anonymous user, then get values from address fields and update in address array*/
    if(a == ""){
        if(validateForm("ecshopfx_billingAddressForm")){
            ecShopSaveAddressInArray("billing");
            var c = document.getElementById(_esShopParam + "email");
            ecShopAddOrUpdateArray("email",c.value);
            if(b.checked){
                if(validateForm("ecshopfx_shipping_address")){
                    ecShopSaveAddressInArray("shipping");
                }
                else{
                    /* Hide step1 and Show step2*/
                    ecShopUpdateStepUrl(2,1);
                    /* Updates urls for history*/
                    ecShopUpdateCheckoutUrl(1);
                    return;
                }
            }
        }
        else{
            return;
        }
        /*display address in step2*/
        ecShopLoadAddressesFromStep1();
    }
    /* If Registered user, get address form selected option and update address array*/
    else{
        var d = 0;
        /* returns selected option value using radio button name*/
        var e = getSelectedValue("billing_options");
        ecShopAddOrUpdateArray("email",_esUserEmail);
        ecShopAddOrUpdateArray("userid",a);
        if(e>0){
            ecShopChooseAddress(e,"billing");
            if(b.checked){
                /* returns selected option value using radio button name*/
                d = getSelectedValue("shipping_options");
                if(d>0){
                    ecShopChooseAddress(d,"shipping");
                }else{
                    CreateError(ecTranslate("checkout-errors.checkout-address-select-shipping-address"));
                    /* Hide step1 and Show step2*/
                    ecShopUpdateStepUrl(2,1);
                    /* Updates urls for history*/
                    ecShopUpdateCheckoutUrl(1);
                    return;
                }
            }
        }
        /* If returns error in address*/
        else{
            CreateError(ecTranslate("checkout-errors.checkout-address-select-billing-address"));
            /* Hide step1 and Show step2*/
            ecShopUpdateStepUrl(2,1);
            /* Updates urls for history*/
            ecShopUpdateCheckoutUrl(1);
            return;
        }
        /*display address in step2*/
        ecShopLoadAddressesFromStep1(e,d);
    }
    /* Stores dynamic shipping test with pincode info in global variable*/
    var f = ecShopReturnFieldFromCookie("shippingpostalcode");
    _esDynamicRatePostcode = (f != "")?f:ecShopReturnFieldFromCookie("billingpostalcode");;
    ecShopSelectShippingMethod();
    ecShopCheckoutTransform(2);
}
function ecShopSelectShippingMethod(){
    /* Radio button name of shipping method - ec_webshop_page_6_shippingmethod*/
    var ship = _esShopParam + 'shippingmethod';
    /* returns selected radio object of shipping method*/
    var a = getSelectedObj(ship);
    /* The ID of that field will be like ship1, ship2, etc*/
    var b = (a)?a.getAttribute("id").replace("ship",""):1;
    /* returns selected radio value of shipping method*/
    var c = getSelectedValue(ship);
    /* The value will be like - shipping method name | shipping method guid eg: DHL|d53e34d2-8628-4746-a1c2-9fbbf8a7237f*/
    var d = c.split('|');
    var e = (d.length>0)?d[0]:"";
    var f = (d.length>1)?d[1]:"";
    /* The restriction given for shipping methods are saved in hidden field with shipping guid*/
    var g = document.getElementById("ecshopfx_shipping_restriction_" + f);
    var h = document.getElementById("ecshopfx_total_product_price").value;
    /* If the restriction is "dynamic-rate", validate and display dynamic shipping rate
     This condition is for adding shipping rate based on the products volume, weight and quantity*/
    if(g && g.value == "dynamic-rate"){
        var i = document.getElementById("ecshopfx_shipping_dynamic_" + f);
        _esDynamicRateSelected = true;
        ecShopFillDynamicShippingRate(i,false,'ecshopfx_shipping_price','ecshopfx_totalprice',b,h);
    }
    /* If restriction is "dynamic-rate-orderprice", validate and display dynamic shipping rate for order*/
    /* This condition is for adding discount for orderprice, eg: if total order price is 3000, the shipping is free, else add default shipping rate*/
    else if(g && g.value == "dynamic-rate-orderprice"){
        _esDynamicRateSelected = true;
        ecShopGetDynamicShippingRate('ecshopfx_shipping_price','ecshopfx_totalprice',b,h);
    }
    /* Else - set there is no dynamic shipping selected*/
    else{
        _esDynamicRateSelected = false;
    }
}
/* Go back from checkout step3 to step2*/
function goBackToStep2(){
    ecShopCheckoutTransform(2,true);
}
/* Go to checkout step3*/
function goStep3(){
    var a = document.getElementById("ecshopfx_container_step3");
    var pay = _esShopParam + 'paymentmethod';
    if(a){
        a.innerHTML = ""
    }
    if(_esCheckoutComplete) {
        /* Redirects to home page
        document.location.href = _esRedirectTo; */
    }
    else{
        /* Validate and get all the payment and shipping informations and and update in array*/
        var b = false;
        var c = "";
        var d = "";
        var e = getSelectedValue(_esShopParam + 'shippingmethod');
        var f = getSelectedValue(pay);
        var g = getSelectedObj(pay);
        var h = "";
        if(e != -1 && f != -1){
            var i = f.split('|');
            var j = (i.length>0)?i[0]:"";
            var k = (i.length>1)?i[1]:"";
            var l = g.getAttribute("id");
            var m = "";
            var n = document.getElementById('payex_factory' + k);
            if(l != null){
                var o = document.getElementById("ecshopfx_" + l);
                if(o){
                    m = o.innerHTML
                }
            }
            ecShopAddOrUpdateArray("paymentmethod",k);
            ecShopAddOrUpdateArray("paymentname",j);
            var p = e.split('|');
            var q = (p.length>0)?p[0]:"";
            var r = (p.length>1)?p[1]:"";
            ecShopAddOrUpdateArray("shippingmethod",r);
            ecShopAddOrUpdateArray("shippingname",q);
            /* Select payment informations*/
            if(f != -1){
                if(n){
                    h = n.value
                }
                /* For Kth factory - credit card*/
                if(m.toLowerCase() == 'credit card'){
                    var s = getSelectedValue('credit_card_type');
                    ecShopAddOrUpdateArray("ecshopcardtype",s);
                    var t = ecTranslate("common-labels.common-form-validate-ccexpired");
                    if(!validateForm("ecshopfx_credit_card_info")){
                        ecShopUpdateStepUrl(3,2);
                        ecShopUpdateCheckoutUrl(2);
                        return
                    }
                }
                /* For Kreditor - needs ssn value*/
                else if(h == 'LifeKreditorPG,LifeKreditorPG.KreditorPG'){
                    var u = document.getElementById("kreditor_ssn").value;
                    if(!validateForm("ecshopfx_kreditor")){
                        ecShopUpdateStepUrl(3,2);
                        ecShopUpdateCheckoutUrl(2);
                        return
                    }
                }
                /* For Payex cash - needs bank name, Payex card*/
                else if(h == 'PayexPayment3DSecureReDirect,PayexPayment3DSecureReDirect.PayexPayment3DSecureReDirect' && f.split("|")[0] != 'card'){
                    var v = document.getElementById('payex_bank');
                    if(v.options[v.selectedIndex].value == 0){
                        CreateError(ecTranslate("checkout-errors.checkout-payment-select-bank"));
                        ecShopUpdateStepUrl(3,2);
                        ecShopUpdateCheckoutUrl(2);
                        return
                    }
                }
            }
            /* Validate dynamic shipping selections*/
            var w = document.getElementById("ecshopfx_shipping_restriction_" + r);
            var x = document.getElementById("ecshopfx_shipping_agent");
            if(w && w.value == "dynamic-rate"){
                if(!_esDynamicRateValid){
                    d = ecTranslate("checkout-errors.checkout-select-valid-shipping");
                    CreateError(d);
                    ecShopUpdateStepUrl(3,2);
                    ecShopUpdateCheckoutUrl(2);
                    return
                }
                if(x && _esSelectedDeliveryAgent == ""){
                    d = ecTranslate("checkout-errors.checkout-select-valid-shippingtime");
                    CreateError(d);
                    ecShopUpdateStepUrl(3,2);
                    ecShopUpdateCheckoutUrl(2);
                    return
                }
            }
        }
        /* Error message display if shipping method or payment method is not selected*/
        else{
            if(e == -1){
                d = ecTranslate("checkout-errors.checkout-select-shipping") + "<br/>"
            }
            if(f == -1){
                d += ecTranslate("checkout-errors.checkout-select-payment") + "\n"
            }
            CreateError(d);
            ecShopUpdateStepUrl(3,2);
            ecShopUpdateCheckoutUrl(2);
            return
        }
        /* Hide step1, step2 and show step3*/
        hideObject("ecshopfx_container_step1");
        hideObject("ecshopfx_container_step2");
        showObject("ecshopfx_container_step3");
        var y = "";
        /* If selected shipping is dynamic shipping, then add dynamic shipping rate in custom_dynamicshippingcost in attribute to form xml*/
        /* else add payment and shipping method in attribute to form xml*/
        if(_esDynamicRateSelected){
            y += '<orderinfo><paymentmethod>' + k + '</paymentmethod><shippingmethod updaterate="' + _esDynamicRate + '">' + r + '</shippingmethod><attributes><attribute><name>custom_dynamicshippingcost</name><value>' + _esDynamicRate + '</value></attribute><attribute><name>deliverydate</name><value>' + _esSelectedDeliveryTime + '|' + _esSelectedDeliveryDate + '</value></attribute>';
        }
        else{
            y += '<orderinfo><paymentmethod>' + k + '</paymentmethod><shippingmethod>' + r + '</shippingmethod><attributes>';
        }
        /* Add address attributes to xml*/
        y += ecShopCreateOrderAddressXml("shipping");
        /* Read email address for cookie and append to xml*/
        y += "<attribute><name>email</name><value>" + ecShopReturnFieldFromCookie("email") + "</value></attribute>";
        /* Collect payment attributes and add to form xml*/
        if(getSelectedValue(pay) != -1){
            var z = getSelectedValue(pay);
            /* For Payex cash - needs bank name*/
            var v = document.getElementById("payex_bank");
            /* For Kth factory credit card*/
            if(m.toLowerCase() == 'credit card'){
                var A = document.getElementById('exp_month');
                var B = document.getElementById('exp_year');
                var C = document.getElementById('cvc');
                var D = document.getElementById('name_on_card');
                y += "<attribute><name>credit_card_expire</name><value>" + A.options[A.selectedIndex].value + "/" + B.options[B.selectedIndex].value + "</value></attribute>";
                y += "<attribute><name>credit_card_number</name><value>" + document.getElementById('card_number').value + "</value></attribute>";y += "<attribute><name>cardtype</name><value>" + getSelectedValue('credit_card_type') + "</value></attribute>";
                y += "<attribute><name>cvc</name><value>" + C.value + "</value></attribute>";
                y += "<attribute><name>name_on_card</name><value>" + D.value + "</value></attribute>";
            }
            /* For Kreditor - needs ssn value*/
            else if(h == 'LifeKreditorPG,LifeKreditorPG.KreditorPG'){
                var E = document.getElementById("kreditor_ssn");
                if(E){
                    y += "<attribute><name>ssn_number</name><value>" + E.value + "</value></attribute>";
                }
            }
            /* For Payex cash - needs bank name*/
            else if(v){
                y += "<attribute><name>bank_name</name><value>" + v.options[v.selectedIndex].value + "</value></attribute>";
            }
        }
        /* Checkout user comments*/
        if(_ecshopUserComments == "true"){
            var F = document.getElementById("ecshopfx_usercomments");
            /* notes field cannot be updated once added in xml, so if it is empty add N/A - not applicable while going from step2 to step3
             To fix the issue like comments not getting cleared when the user entered some comment in step2 and goes to step3, Later he returns back to step2 and clear teh comments and proceed again the comments will not be removed*/
            if(F && F.value.length>0){
                y += "<attribute><name>notes</name><value>" + HtmlEncode(F.value) + "</value></attribute>";
            }else if(F){
                y += "<attribute><name>notes</name><value>N/A</value></attribute>";
            }
        }
        y += "</attributes><queryparams><querystring><name>confirm</name><value>false</value></querystring>";
        y += "<querystring><name>infostage</name><value>confirm</value></querystring></queryparams></orderinfo>";
        ecShopCheckoutTransform(3);
        /* Calls webservice to go to confirmation step*/
        ecShopUpdateOrder('confirm','false',HtmlEncode(y),'ecshopfx_container_step3','orderprocess',b,c);
    }
}
/* Confirmed - redirects to payment step if any card or bank site, else goes to receipt step*/
function goStep4(a){
    /* a - reference id from creit card payment or bank site payment*/
    if(a == undefined){
        a = "";
    }
    /* To hide the 'confirm' button - to restrict the user from mulitiple click*/
    disable('ecshopfx_gostep4');
    /* Continue to process the payment and place the order*/
    ecShopProcessPayment(a);
}
function ecShopProcessPayment(a){
    var b = '';
    /* Temporarily disabled 
     Used to check the user clicks - browser back button from step4 to redirect them to home page*/
    if(_esCheckoutComplete){}
    else{
        var d = false;
        var f = "";
        var g = "";
        var h = getSelectedValue(_esShopParam + 'paymentmethod');
        var i = getSelectedObj(_esShopParam + 'paymentmethod');
        /* Checks for payment method based on the payment type restrictions given in ecommerce settings*/
        if(h != -1){
            var j = h.split('|');
            var k = i.getAttribute("id");
            var l = "";
            /* Reads payment type value*/
            if(k != null){
                var m = document.getElementById("ecshopfx_" + k);
                if(m){
                    l = m.innerHTML;
                }
            }
            /* Splitting credit card payment methods - For valitor - "webpayment-redirect-valitorconnectpg", For Payex - "webpayment-redirect"*/
            /* valitorconnectpg - aspx file name, should not be changes unless the redirection file name is changed*/
            if(l.toLowerCase().indexOf("webpayment-redirect")>-1){
                if(l.toLowerCase().indexOf("webpayment-redirect-valitorconnectpg")>-1){
                    d = true;
                    g = l.toLowerCase().replace("webpayment-redirect-","");
                }
                else{
                    g = l.toLowerCase().replace("webpayment-","");
                }
            }
        }
    }
    /* Validating privacy and policy, terms and conditions fields*/
    var n = document.getElementById('privacy_policy');
    var t = document.getElementById('terms_and_conditions');
    if(n && t){
        if((!n.checked) || (!t.checked)){
            if(!(n.checked) && !(t.checked)){
                b = ecTranslate("checkout-errors.checkout-accept-both-policyandterms");
            }else if(!(t.checked)){
                b = ecTranslate("checkout-errors.checkout-accept-termsandconditions");
            }else if(!n.checked){
                b = ecTranslate("checkout-errors.checkout-accept-privacyandpolicy");
            }
        }if(b != ''){
            /* Displays if there is error in privacy and policy, terms and conditions*/
            CreateError(b);
            /* Enabling step4 button to confirm it again*/
            enable('ecshopfx_gostep4');
            /* Redirecting back to step3*/
            ecShopUpdateStepUrl(4,3);
            return;
        }
    }
    /* For payments methods redirection to other site urls.*/
    if((ecShopReturnFieldFromCookie("paymentmethod") && g.toLowerCase() == 'redirect' || g.toLowerCase() == 'valitorconnectpg') && a == ""){
        var o = document.getElementById("ecshopfx_redirect_model_webpayment");
        /* Redirecting to valitor payment gateway url and opening the valitor link in Iframe through "valitorconnectpg.aspx" by overwriting the content of step3
         After success payment it redirects to receipt page*/
        if(g.toLowerCase() == 'valitorconnectpg'){
            var c = document.getElementById("ecshopfx_container_step3");
            var p = '<iframe name="webpayment" id="webpayment" src="about:blank" height="100%" width="100%" class="ecshop_webpayment_iframe" frameborder="0" scrolling="0"></iframe>';
            c.innerHTML = p;
            hideObject("ecshopfx_container_step1");
            hideObject("ecshopfx_container_step2");
            showObject("ecshopfx_container_step3");
            try{
                _ecShopPostStep2Webpayment();
            }
            catch(e){}
            /* Change target of the form for valitor and submit in "valitorconnectpg.aspx" page*/
            if(o){
                o.setAttribute("target","webpayment");
                o.submit();
            }
        }
        /* This is for payex, kreditor, and all other redirecting to different sites webpayment methods - Opens the related sites in same page
         After success payment it redirects to receipt page*/
        else if(g.toLowerCase() == 'redirect'){
            if(o){
                o.submit();
            }
        }
    }
    /* For payment methods like korta, Invoice, Postal card etc... - Confirm payment and moves to receipt page directly from step3*/
    else{
        var q = "";
        /* If selected shipping is dynamic shipping, then add dynamic shipping rate in custom_dynamicshippingcost in attribute to form xml
         else add payment and shipping method in attribute to form xml*/
        if(_esDynamicRateSelected){
            q += '<orderinfo><paymentmethod>' + ecShopReturnFieldFromCookie("paymentmethod") + '</paymentmethod><shippingmethod updaterate="' + _esDynamicRate + '">' + ecShopReturnFieldFromCookie("shippingmethod") + '</shippingmethod><attributes><attribute><name>deliverydate</name><value>' + _esSelectedDeliveryTime + '|' + _esSelectedDeliveryDate + '</value></attribute><attribute><name>custom_dynamicshippingcost</name><value>' + _esDynamicRate + '</value></attribute>';
        }
        else{
            q += '<orderinfo><paymentmethod>' + ecShopReturnFieldFromCookie("paymentmethod") + '</paymentmethod><shippingmethod>' + ecShopReturnFieldFromCookie("shippingmethod") + '</shippingmethod><attributes>';
        }
        /* Add address attributes to xml*/
        q += ecShopCreateOrderAddressXml("shipping");
        /* Read email address for cookie and append to xml*/
        q += "<attribute><name>email</name><value>" + ecShopReturnFieldFromCookie("email") + "</value></attribute>";
        var h = getSelectedValue(_esShopParam + 'paymentmethod');
        var i = getSelectedObj(_esShopParam + 'paymentmethod');
        if(h != -1){
            /* Read payment type (restriction) based on the selected payment method*/
            var k = i.getAttribute("id");
            var l = "";
            if(k != null){
                var m = document.getElementById("ecshopfx_" + k);
                if(m){
                    l = m.innerHTML;
                }
            }
            /* Collect payment attributes and add to form xml*/
            var r=getSelectedValue(_esShopParam + 'paymentmethod');
            /* For Kth factory credit card*/
            if(l.toLowerCase() == 'credit card'){
                var s = document.getElementById('exp_month');
                var u = document.getElementById('exp_year');
                var v = document.getElementById('cvc');
                q += "<attribute><name>credit_card_expire</name><value>" + s.options[s.selectedIndex].value + "/" + u.options[u.selectedIndex].value + "</value></attribute>";
                q += "<attribute><name>credit_card_number</name><value>" + document.getElementById('card_number').value + "</value></attribute>";
                q += "<attribute><name>cardtype</name><value>" + getSelectedValue('credit_card_type') + "</value></attribute>";
                q += "<attribute><name>cvc</name><value>" + v.value + "</value></attribute>";
                q += "<attribute><name>name_on_card</name><value>" + ecShopReturnFieldFromCookie("billingfirstname") + ' ' + ecShopReturnFieldFromCookie("billinglastname") + "</value></attribute>";
            }
        }
        /* Checkout user comments*/
        if(_ecshopUserComments == "true"){
            var w = document.getElementById("ecshopfx_usercomments");
            if(w && w.value.length>0){
                q += "<attribute><name>notes</name><value>" + HtmlEncode(w.value) + "</value></attribute>";
            }
            else if(w){
                q += "<attribute><name>notes</name><value></value></attribute>";
            }
        }
        q += "</attributes><queryparams><querystring><name>confirm</name><value>true</value></querystring></queryparams></orderinfo>";
        ecShopCheckoutTransform(4);
        /* Calls webservice to go to payment site or complete the order*/
        ecShopUpdateOrder('confirm','true',HtmlEncode(q),'ecshop_checkout_container','orderreceipt',false,"",a);
    }
}
/* Function to hide one step and show other specified step in checkout steps*/
function ecShopCheckoutTransform(a,b){
    /* a - New step, b - Go back to step (true/false)*/
    if(b == undefined){
        b = false;
    }
    /* Highlight current step tab in checkout nav (Map)*/
    ecShopChangeSelectedTab(a);
    /* Check for go back to step condition and update google tracker*/
    if(!b)
        ecShopGoogleTrackCheckout(a);
    /* Update current step in cookie*/
    if(a<4)
        ecShopAddOrUpdateArray("step",a);
    /* Hide current step and show step mentioned in a
     i<5 - since we have only 4 steps in checkout*/
    for(var i = 1;i<5;i++){
        if(i == a){
            showObject("ecshopfx_container_step" + i);
        }
        else{
            hideObject("ecshopfx_container_step" + i);
        }
    }
}
/* Update current step in array*/
function ecShopUpdateStepUrl(a,b){
    ecShopAddOrUpdateArray("step",b);
}
/*Function to highlight current step tab in checkout nav (Map)*/
function ecShopChangeSelectedTab(a){
    var t = ecTranslate("checkout-headings.checkout-map");
    for(var i=1;i<5;i++){
        var s = document.getElementById("step" + i + "_tab_lbl");
        var b = document.getElementById("step" + i + "_sep");
        
        if(i == a){
            /* current - Specifies current step*/
            b.className = "sep current";
            s.className = "current";
        }
        else if(i<a){
            /* completed - Specifies completed step*/
            b.className = "sep completed";
            s.className = "completed";
        }
        else{
            b.className = "sep";
            s.className = "";
        }
        /* Append current step name in title*/
        if(i <= a){
            t += " > " + s.innerHTML.replace("&amp;","&");
        }
    }
    document.title = t;
}
/* Delete cookies after placeing the order, Timeout expired in checkout*/
function ecShopDeleteAllCookies(){
    createCookie(_esShopParamCookie,'',0);
    createCookie(_esSelectedShipGuidCookie,'',0);
    createCookie(_esSelectedShipPosCookie,'',0);
    createCookie(_esCheckoutCookie,'',0);
    createCookie(_esNodeCookie,'',0);
    _esCookieArray = new Array();
    _esNodeArray = new Array();
}
/* Function to send the xml and address informations to saveinvoice.aspx and process and form PDF using the XML.*/
function ecShopSaveInvoice(){
    /*_esSaveInvoiceXml - Gives order responce XML
     _esSaveInvoiceCookie - Order cookie*/
    document.getElementById("ecshopfx_saveinvoiceval").value = _esSaveInvoiceXml;
    document.getElementById("ecshopfx_addrs_cookie").value = _esSaveInvoiceCookie;
    document.ecshopfx_saveinvoice.submit();
}

function ecShopUpdateWebpaymentOrder(a,b,c,d){
    /* a - Order refrence guid, b - Shop refrence guid, c - Refrence id of webpayment - Return response from redirect model webpayment, d - Shipping informations that need to be saved*/
    if(d == undefined){
        d = "";
    }
    ecShop.Web.Soap.ecShopWS.UpdateWebpaymentOrderComments(b,a,c,d,OnOrderCommentsUpdated,OnError);
}
/* Update comments in ecommerce module*/
function ecShopUpdateOrderComments(a,b,c){
    /* a - Order refrence guid, b - Shop refrence guid, c - Refrence id of webpayment - Return response from redirect model webpayment*/
    ecShop.Web.Soap.ecShopWS.UpdateOrderComments(b,a,c,OnOrderCommentsUpdated,OnError);
}

function OnOrderCommentsUpdated(){}


function ecShopPrintInvoice(){
    var a = document.getElementById("ecshop_printinvoice_container").innerHTML;
    var b = '<div id="ecshop_product_container" class="basket_view">' + a + '</div>';
    printContent(b);
}

function ecShopUpdateShippingCollection(){
    /* Enable selected shipping, show its description and mark it selected*/
    if(_esSelectedShipPos != null && _esSelectedShipPos != ''){
        ecShopHideAndShow('ecshopfx_shipDesc',_esSelectedShipPos);
        ecShopSelectShippingMethod();
    }
}
/* Process order through Order process webservice*/
function ecShopUpdateOrder(H,I,J,K,L,M,N,O){
    /* H - stage = To process webservice, I - createOrder = To process webservice, J - orderxml = To process webservice, K - elementID = To overwrite inner HTML with the response HTML content, L - entity, M - isWebpayment, N - typeOfWebpayment, O - webpaymentRefId*/
    /* If createOrder = true - Open update window for saying that "Submitting order..."*/
    if(I == "true"){
        CreateUpdate(ecTranslate("checkout-labels.checkout-submitting-order"));
    }
    else if(I == "false" && H != "info"){
        /* If createOrder = false - Open update window for saying that "Preparing order..." in confirmation step*/
        CreateUpdate(ecTranslate("checkout-labels.checkout-preparing-order"))
    }
    /* Entity - To read HTML - value will be like orderprocess or orderreceipt etc*/
    if(L == undefined)
        L = "orderprocess";
    /* Is payment is through redirect model webpayment*/
    if(M == undefined)
        M = false;
    /* Type of webpayment*/
    if(N == undefined)
        N = "";
    /* Refrence id of webpayment - Return response from redirect model webpayment*/
    if(O == undefined)
        O = "";
    /* Order process pageId and positionId - Value is set in ecShop - Order form v2.0 XSLT*/
    var P = _esOrderPageId;
    var Q = _esOrderPosId;
    /* Page type - 1 = Module is inserted in page, 2 - Module is inserted in area template*/
    var R = "1";
    
    var V = new SOAPObject("orderProcess");
    V.ns = "http://tempuri.org/";
    V.appendChild(new SOAPObject("pageId")).val(P);
    V.appendChild(new SOAPObject("positionId")).val(Q);
    V.appendChild(new SOAPObject("pageType")).val(R);
    V.appendChild(new SOAPObject("stage")).val(H);
    V.appendChild(new SOAPObject("createorder")).val(I);
    V.appendChild(new SOAPObject("orderInfoXml")).val(J);
    var W = new SOAPRequest("http://tempuri.org/orderProcess",V);
    W.addNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
    W.addNamespace("xsd","http://www.w3.org/2001/XMLSchema");
    SOAPClient.Proxy = ecShopReturnHost() + "/editor/soap/ecbusiness.asmx";
    SOAPClient.SOAPServer = ecShopReturnHost() + "/editor/soap/ecbusiness.asmx";
    /***
     // Expected input for the webservice that is sent eg: 
     // If only billing address is sent: <soapenv:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><orderProcess xmlns="http://tempuri.org/"><pageId>16017</pageId><positionId>6</positionId><pageType>1</pageType><stage>confirm</stage><createorder>false</createorder><orderInfoXml>&lt;orderinfo&gt;&lt;paymentmethod&gt;8a6dd9bd-5f67-4749-941a-d406bbe0633e&lt;/paymentmethod&gt;&lt;shippingmethod&gt;2810ca47-a5ff-4d51-8bb7-16117b434f2b&lt;/shippingmethod&gt;&lt;attributes&gt;&lt;attribute&gt;&lt;name&gt;firstname&lt;/name&gt;&lt;value&gt;dfg&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;middlename&lt;/name&gt;&lt;value&gt;&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;lastname&lt;/name&gt;&lt;value&gt;fsdf&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;address&lt;/name&gt;&lt;value&gt;sdfssdf&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;addressdescription&lt;/name&gt;&lt;value&gt;&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;apartment&lt;/name&gt;&lt;value&gt;&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;careof&lt;/name&gt;&lt;value&gt;&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;postalcode&lt;/name&gt;&lt;value&gt;323&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;city&lt;/name&gt;&lt;value&gt;qweqwe&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;state&lt;/name&gt;&lt;value&gt;&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;pobox&lt;/name&gt;&lt;value&gt;&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;region&lt;/name&gt;&lt;value&gt;asdasd&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;phone&lt;/name&gt;&lt;value&gt;&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;mobile&lt;/name&gt;&lt;value&gt;&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;fax&lt;/name&gt;&lt;value&gt;&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;organisation&lt;/name&gt;&lt;value&gt;&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;vatnumber&lt;/name&gt;&lt;value&gt;0000000001&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;email&lt;/name&gt;&lt;value&gt;jaisuganthi@ec.is&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;bank_name&lt;/name&gt;&lt;value&gt;0&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;notes&lt;/name&gt;&lt;value&gt;N/A&lt;/value&gt;&lt;/attribute&gt;&lt;/attributes&gt;&lt;queryparams&gt;&lt;querystring&gt;&lt;name&gt;confirm&lt;/name&gt;&lt;value&gt;false&lt;/value&gt;&lt;/querystring&gt;&lt;querystring&gt;&lt;name&gt;infostage&lt;/name&gt;&lt;value&gt;confirm&lt;/value&gt;&lt;/querystring&gt;&lt;/queryparams&gt;&lt;/orderinfo&gt;</orderInfoXml></orderProcess></soapenv:Body></soapenv:Envelope>
     // If both shipping and billing address is sent: <soapenv:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><orderProcess xmlns="http://tempuri.org/"><pageId>16017</pageId><positionId>6</positionId><pageType>1</pageType><stage>confirm</stage><createorder>false</createorder><orderInfoXml>&lt;orderinfo&gt;&lt;paymentmethod&gt;8a6dd9bd-5f67-4749-941a-d406bbe0633e&lt;/paymentmethod&gt;&lt;shippingmethod&gt;2810ca47-a5ff-4d51-8bb7-16117b434f2b&lt;/shippingmethod&gt;&lt;attributes&gt;&lt;attribute&gt;&lt;name&gt;firstname&lt;/name&gt;&lt;value&gt;Test&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;middlename&lt;/name&gt;&lt;value&gt;&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;lastname&lt;/name&gt;&lt;value&gt;Test&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;address&lt;/name&gt;&lt;value&gt;Test&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;addressdescription&lt;/name&gt;&lt;value&gt;&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;apartment&lt;/name&gt;&lt;value&gt;&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;careof&lt;/name&gt;&lt;value&gt;&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;postalcode&lt;/name&gt;&lt;value&gt;112&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;city&lt;/name&gt;&lt;value&gt;Iceland&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;state&lt;/name&gt;&lt;value&gt;&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;pobox&lt;/name&gt;&lt;value&gt;&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;region&lt;/name&gt;&lt;value&gt;Test&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;phone&lt;/name&gt;&lt;value&gt;&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;mobile&lt;/name&gt;&lt;value&gt;&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;fax&lt;/name&gt;&lt;value&gt;&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;organisation&lt;/name&gt;&lt;value&gt;&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;vatnumber&lt;/name&gt;&lt;value&gt;0000000001&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;custom_billing_firstname&lt;/name&gt;&lt;value&gt;Karlls&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;custom_billing_middlename&lt;/name&gt;&lt;value&gt;&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;custom_billing_lastname&lt;/name&gt;&lt;value&gt;Lidin&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;custom_billing_address&lt;/name&gt;&lt;value&gt;Junibacksg 42&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;custom_billing_addressdescription&lt;/name&gt;&lt;value&gt;&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;custom_billing_apartment&lt;/name&gt;&lt;value&gt;&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;custom_billing_careof&lt;/name&gt;&lt;value&gt;&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;custom_billing_postalcode&lt;/name&gt;&lt;value&gt;23634&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;custom_billing_city&lt;/name&gt;&lt;value&gt;Hollviken&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;custom_billing_state&lt;/name&gt;&lt;value&gt;&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;custom_billing_pobox&lt;/name&gt;&lt;value&gt;&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;custom_billing_region&lt;/name&gt;&lt;value&gt;Sweden&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;custom_billing_phone&lt;/name&gt;&lt;value&gt;&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;custom_billing_mobile&lt;/name&gt;&lt;value&gt;&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;custom_billing_fax&lt;/name&gt;&lt;value&gt;&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;custom_billing_organisation&lt;/name&gt;&lt;value&gt;&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;custom_billing_vatnumber&lt;/name&gt;&lt;value&gt;4304158399&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;email&lt;/name&gt;&lt;value&gt;jaisuganthi@ec.is&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;bank_name&lt;/name&gt;&lt;value&gt;0&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;notes&lt;/name&gt;&lt;value&gt;N/A&lt;/value&gt;&lt;/attribute&gt;&lt;/attributes&gt;&lt;queryparams&gt;&lt;querystring&gt;&lt;name&gt;confirm&lt;/name&gt;&lt;value&gt;false&lt;/value&gt;&lt;/querystring&gt;&lt;querystring&gt;&lt;name&gt;infostage&lt;/name&gt;&lt;value&gt;confirm&lt;/value&gt;&lt;/querystring&gt;&lt;/queryparams&gt;&lt;/orderinfo&gt;</orderInfoXml></orderProcess></soapenv:Body></soapenv:Envelope>
    ***/
    SOAPClient.SendRequest(W,orderProcessResponse);_esOrderXML = "";
    
    function orderProcessResponse(a,b,d){
        /* a - orderRespObj, b - orderRespText, d - orderRespXml*/
        try{
            var f = a.Body[0].orderProcessResponse[0].orderProcessResult[0].root[0];
            var g = f.htmldata[0].Text;
            var h = b;
            
            /* To split the html from the XSLT, "<!--shipping-starts-->" the same type of comments will be given in XSLT, Used to read the code between the comments 
             Reading the HTML from this start comment "<!--shipping-starts-->" and ends reading the HTML "<!--shipping-ends-->" when reads this comment.*/
            var i = g.indexOf('<!--' + L + '-starts-->');
            var j = g.indexOf('<!--' + L + '-ends-->');
            
            /* Gets shipping HTML details*/
            var k = g.indexOf('<!--shipping-starts-->');
            var l = g.indexOf('<!--shipping-ends-->');
            var m = g.substring(k,l);
            
            /* Gets error message display, if any*/
            var n = g.indexOf('<!--ordererror-starts-->');
            var o = g.indexOf('<!--ordererror-ends-->');
            var p = g.substring(n,o);
            
            /* Object to overwrite HTML content*/
            var c = document.getElementById(K);
            
            /* If createOrder = true*/
            if(I == "true"){
                /* Checking for error if any - If yes, don't replace the HTML instead show error message*/
                /* else -  Overwrite HTML content*/
                if(p.length>0){
                    CreateError(p);
                    enable('ecshopfx_gostep4');
                }
                else{
                    /* Overwrite innerHTML*/
                    if(c){
                        c.innerHTML = g.substring(i,j);
                    }
                    /* Clear Small cart and make the cart Empty*/
                    ecShopResetBasketHtml();
                    /* Read receipt XML and save it in global variable to use in save Invoice*/
                    var q = "<!--receiptxml-starts-->";
                    var r = g.indexOf(q);
                    var s = r+q.length;
                    var t = g.indexOf('<!--receiptxml-ends-->');
                    var u = g.substring(s,t);
                    /* Global variable to save receipt XML*/
                    _esSaveInvoiceXml = u;
                    
                    /* Delete all cookies that is set for checkout process*/
                    ecShopDeleteAllCookies();
                    
                    /* Added to fix the issue of automatic redirection to home page before showing receipt*/
                    window.onbeforeunload = null;
                    
                    /* Clear checkout timer*/
                    clearInterval(_esObserveTimer);
                    /* Hide other steps and Show step 4*/
                    ecShopHideAndShow('ecshopfx_container_step',4);
                    /* Dont show related products in step4*/
                    var v = document.getElementById("related_products_container");
                    if(v){
                        v.innerHTML = "";
                    }
                    /* Google analytics*/
                    var w = "<!--googleanalytics-starts-->";
                    var x = g.indexOf(w);
                    var y = x+w.length;
                    var z = g.indexOf('<!--googleanalytics-ends-->');
                    var A = g.substring(y,z);
                    if(A.length>0){
                        ecShopGoogleTrackOrder(A);
                    }
                }
                /* To save dynamic shipping information in ecommerce - shop comments */
                if(f.information[0].orders != undefined){
                    var B = f.information[0].orders[0].order[0].guid[0].Text;
                    var C = f.information[0].shop[0].guid[0].Text;
                    var D = '<p><strong>Sendingarmáti</strong><br/>';
                    D += 'Sendingartími: ' + _esSelectedDeliveryTime + '<br/>';
                    D += 'Sendingardagur: ' + _esSelectedDeliveryDate + '<br/>';
                    D += '</p>';
                    /* Update order if we have refrence id from redirect model webpayment and dynamic shipping exist*/
                    if(O != "" && _esDynamicRateSelected){
                        ecShopUpdateWebpaymentOrder(B,C,O,D);
                    }
                    /* Update order if we have refrence id from redirect model webpayment and dynamic shipping doesnot exist*/
                    else if(O != "" && !_esDynamicRateSelected){
                        ecShopUpdateWebpaymentOrder(B,C,O);
                    }
                    /* If there is no refrence ID then just update shop comments*/
                    else if(_esDynamicRateSelected){
                        ecShopUpdateOrderComments(B,C,D);
                    }
                }
                /* Extra function for the stuffs AD needs to add in to step 4*/
                try{
                    _ecShopPostStep3();
                }
                catch(e){}
            }
            /* If stage = confirm [Checkout Step3]*/
            else if(H == "confirm"){
                /*Save checkout cookie for invoice*/
                ecShopHideAndShow('ecshopfx_container_step',3);
                _esSaveInvoiceCookie = readCookie(_esCheckoutCookie);
                if(M){
			        /* Extra function for the stuff AD needs to add in to in step 3*/
		            /*try {
		                _ecShopPostStep2Webpayment();
		            } catch (e){}*/
                }
                else{
                    /* Overwrite html content in step3*/
                    if(c){
                        c.innerHTML = g.substring(i,j);
                }
                /* Copy and display address information from step2 to step3*/
                var E = document.getElementById("ecshopfx_address_preview");
                if(E){
                    ReplaceContent("ecshopfx_address_confirmation",E.innerHTML);
                }
                /* Reading the selected cardType from the cookie and displaying the value in the card type container*/
                var F = ecShopReturnFieldFromCookie("ecshopcardtype");
                var G = document.getElementById('ecshopfx_cardtype');
                if(F == "" || F == 'undefined' || F == null)
                    F = "";
                    if(F.length>0){
                        if(G)G.innerHTML = ecShopReturnFieldFromCookie("ecshopcardtype");
                    }
                }
            }
            else{
                if(c){
                    c.innerHTML = g.substring(i,j);
                }
                /* Update shipping information*/
                if(c.innerHTML.length>0){
                    var D = document.getElementById("ecshopfx_shipping_methods");
                    if(D){
                        D.innerHTML = m;
                        /* Enable selected shipping, show its description and mark it selected*/
                        ecShopUpdateShippingCollection();
                    }
                }
                else{
                    /* If order innerHTML is empty then redirect the user to home page*/
                    document.location.href = _esRedirectTo;
                }
            }
            DeleteUpdate();
        }
        catch(e){
            CreateError(e);
            DeleteUpdate();
        }
    }
}

/***************************************\\
//                                      \\
//          Checkout ends               \\
//                                      \\
//***************************************/

/***************************************\\
//                                      \\
//          Basket starts               \\
//                                      \\
//***************************************/

/* Function to add product to basket*/
function ecShopAddProduct(a,b,d,f,g,h,i,j,k){
    /*a - product id, b - quantity, d - image Url, f - image Name, g - image Version, h - product Name, i - stock, j - optionString, k - variationType (fixed or "")*/
    var l = "";
    /* Variation type - fixed or null, to hide package modify option in large cart if some of the package combination is "inValid"*/
    if(k == undefined){
        k = "";
    }
    /* Validation for quantity - must be numeric always*/
    if(!validateNumerics(b) || b==0){
        l = ecTranslate("product-errors.product-invalid-quantity");
    }
    /* If optionstring null or "", then form optionstring for packages*/
    /* Format: <options><option prodid="a53e34d2-8628-4746-a1c2-9fbbf8a7237f"><attribs><attrib><name>Color</name><value>Red</value></attrib><attrib><name>Size</name><value>10</value></attrib>...</attribs></option></options>*/
    else if(j == null || j == ''){
        var m = 1;
        var o = '<options><option prodid="' + a + '">';
        if(document.getElementById('ecshopfx_' + a + "_1") != null){
            o = o + '<attribs>';
            while(document.getElementById('ecshopfx_' + a + '_' + m)){
                /* selectbox id*/
                var p = document.getElementById('ecshopfx_' + a + '_' + m);
                var q = '';
                var v = '';
                var n = '';
                /* Getting all select boxes and its selected value*/
                if(p.tagName.toLowerCase() == 'select'){
                    q = p.options[p.selectedIndex];
                    v = q.value;
                    n = q.getAttribute("title");
                }
                /* If the package has only one variation or one valid variation, there will not be select box, instead we have displayed the variation in span, reading those values here*/
                else if(p.tagName.toLowerCase() == 'span'){
                    q = p.getAttribute("title").split(":");
                    v = q[1];
                    n = q[0];
                }
                /* Check for variation name, if exist  - add attribute name and value*/
                /* else - give error message to select variations*/
                if(v != '0'){
                    o = o + '<attrib><name>' + n + '</name><value>' + v + '</value></attrib>';
                    m++;
                }
                else{
                    l = (l != ""?l + "," + n:ecTranslate("product-errors.product-select-variation") + ":" + n);
                    m++;
                }
            }
            /* In "ecshopfx_color_selection" input field we have <attrib> values if we have Palette type of color display*/
            var c = document.getElementById("ecshopfx_color_selection");
            if(c != null && c.value.length>0){
                o = o+c.value + '</attribs>';
            }
            else{
                o = o + '</attribs>';
            }
        }
        /* In "ecshopfx_color_selection" input field we have <attrib> values if we have Palette type of color display*/
        else if(document.getElementById("ecshopfx_color_selection")){
            o = o + '<attribs>';
            var c = document.getElementById("ecshopfx_color_selection");
            if(c != null && c.value.length>0){
                o = o+c.value + '</attribs>';
            }
            else{
                o = o + '</attribs>';
            }
        }
        o = o + '</option></options>';
    }
    /* else optionstring is set to null or empty*/
    else{
        o = j;
    }
    /* Check for product image and exist or not if yes read the image*/
    if(document.getElementById('prod_image')){
        var r = document.getElementById('prod_image').src;
        var s = r.split("ecshop_detail_");
        d = s[0];
        f = s[1];
    }
    /* Display error message if exist, else add product to basket*/
    if(l.length>0){
        CreateError(l);
    }
    else{
        /* If product name Show just added popup message*/
        if(h != ""){
            try{
                ecShopJustAddedToBasket(h,d,f,g);
            }
            catch(e){}
        }
        /* Add product to basket*/
        try{
            ecShopAddProductToBasket(a,b,HtmlEncode(o),k);
        }
        catch(e){}
    }
}
function ecShopAddProductToBasket(a,b,c,d){
    /* a - Product id, b - Product quantity, c - option string in encoded format, d - variation type (fixed or null)*/
    /* action for webservice*/
    var f = "add";
    /* Element id*/
    var g = "ecshop_small_basket";
    /* Page id - Value is set in small cart*/
    var i = _esBskPageId;
    /* Position id - Value is set in small cart*/
    var j = _esBskPosId;
    /* Page type - 1 - Module is inserted in page, 2 - Module is inserted in area template*/
    var k = "2";
    var l = document.location.href;
    /* If current location of the user is in checkout, need to update order also, elese just update basket*/
    try{
        if(l.indexOf("?ec_webshop_page")>0){
            ecShopUpdateBasketInfoStage(a,b,f,c,g);
        }
        else{
            ecShopUpdateBasket(a,b,f,d,c,g,i,j,k);
        }
    }
    catch(e){}
}
/* Function to show the popup while adding the product to basket*/
function ecShopJustAddedToBasket(a,b,d,e){
    /*a - Product name, b - Image Url, d - Image name, e - Image version*/
    /* Forming HTML for the popup*/
    var c = document.getElementById("ecshopfx_small_cart");
    var f = '<div id="ecshop_added_to_basket" class="ecshop_basket ecshop_hide">';
    f += '<div class="content just_added">';
    f += '<h3>' + ecTranslate("basket-labels.basket-just-added") + '</h3>';
    if(b.length>0){
        /*Forming image src*/
        var g=b+e+d;
        f += '<div class="product_img"><img src="' + g + '" /></div>';
    }
    /* product name*/
    f += '<h2>' + a + '</h2>';
    f += '</div>';
    f += '</div>';
    if(c){
        /* Overwrite HTML*/
        c.innerHTML = f;
        /* Functionality to show popup based on the cursor position - The position alignment x-axis and y-axis are specified in ecShop settings*/
        floatingMenu.menu = document.getElementById("ecshop_added_to_basket");
        floatingMenu.computeShifts();
        var h = (floatingMenu.shiftY+parseInt(_ecshopFloatingMenuYAdjustment));
        var i = (floatingMenu.shiftX+parseInt(_ecshopFloatingMenuXAdjustment));
        if(floatingMenu.shiftY>170){
            if(document.layers){
                floatingMenu.menu.left = i;
                floatingMenu.menu.top = h;
            }
            else{
                floatingMenu.menu.style.left = i + 'px';
                floatingMenu.menu.style.top = h + 'px';
            }
        }
        /* Show popup*/
        showObject("ecshop_added_to_basket");
    }

    /* Hide the basket automatically after specified time*/
    setTimeout("ecShopHideJustAdded()",2000);
}

function ecShopHideJustAdded(){
    /* Function to hide the item by fading it*/
    FadeItem('ecshop_added_to_basket','out',2000,true);
}
/* Show Small basket dropdown onmouseover small basket*/
function ecShopShowBasket(){
    if(_esDropdownBskTimer != null){
        clearTimeout(_esDropdownBskTimer);
    }
    hideObject("ecshop_added_to_basket");
    showObject("ecshop_small_basket_dropdown");
    showObject("ecshopfx_dropdown_basket");
}
/* Hide Small basket dropdown onmouseout small basket*/
function ecShopHideBasket(){
    _esDropdownBskTimer = setTimeout("ecShopFadeBasket()",2000);
}
function ecShopFadeBasket(){
    /* Function to hide the item by fading it*/
    FadeItem('ecshopfx_dropdown_basket','out',3000,false);
}
/* To update product count using + and - buttons*/
function UpdateProductCount(a,b,c,d,e){
    /*a - product Guid, b - Quantity, c - action (update), d - optionstring (for packages), e - increment count(inc) or decrement count (dec)*/
    var f = 'ecshop_checkout_container';
    /* set default value for e - if nothing is sent (inc or dec)*/
    if(typeof(e) == 'undefined'){
        e = 'empty';
    }
    /* If decrement, Check quantity, 
     if 1 - ask user an alert to remove product, 
     else decrement count*/
    if(e == 'dec'){
        if(b == 1){
            checkUpdateBasket(a,b,"remove",d,f,"remove","large_basket");
            return;
        }
        else{
            b--;
        }
    }
    
    /* Increment count*/
    if(e == 'inc')
        b++;
    /* Function to update basket with result*/
    ecShopUpdateLargeBasket(a,b,c,HtmlEncode(d),f);
}
/* To update product count by changing number in input field*/
function UpdateProductQuantity(a,b,c,d,e){
    /*a - Input field object, b - Old Quantity, c - Product guid, d - action (update), e - optionstring (for packages)*/
    var f = 'ecshop_checkout_container';
    validateNumber(a);
    /* Get updated quantity from the field*/
    var g = a.value;
    /* Check the quantity is 0 - then remove the product*/
    if(g == 0){
        d = "remove";
        g = 1;
    }
    /* Check field exist and old quantity value and new quantity value are different, if yes, Process updating the basket*/
    if(a.value != "" && b != g){
        ecShopUpdateLargeBasket(c,g,d,HtmlEncode(e),f);
    }
}
/* Alerts user while, removing the last product from the basket*/
function ecShopEmptyBasketConfirmation(a,b,c,d,e,f,g){
    var h = '';
    var m = '';
    var r = true;
    
    if(f == 1){
        /* Message if we reduce the quantity to 0, if there is only one product in basket*/
        h = ecTranslate("checkout-headings.checkout-remove-last-product-from-basket-heading");
        m = ecTranslate("checkout-messages.checkout-remove-last-product-from-basket-message");
    }
    else if(f == "cancel"){
        /* Message if we cancel the order in checkout*/
        h = ecTranslate("checkout-headings.checkout-cancel-order-heading");
        m = ecTranslate("checkout-messages.checkout-cancel-order-message");
    }
    else if(f == "clear"){
        /* Message if we clear the basket*/
        h = ecTranslate("checkout-headings.checkout-clear-basket-heading");
        m = ecTranslate("checkout-messages.checkout-clear-basket-message");
    }
    else if(f == "remove"){
        /* Message if we remove the last product from the basket*/
        h = ecTranslate("checkout-headings.checkout-remove-product-heading");
        m = ecTranslate("checkout-messages.checkout-remove-product-message");
        r = false;
    }
    /* Forming HTML for displaying the message*/
    var i='<div class="ecshop_form_container">';
    i += '<p>' + m + '</p>';
    /* Ok button function call changes for large cart and checkout*/
    
    if(g == "large_basket"){
        /* To update large basket and small basket*/
        i += '<div class="buttons"><button onclick="ecShopUpdateLargeBasket(\'' + a + '\',\'' + b + '\',\'' + c + '\',\'' + escape(HtmlEncode(d)) + '\',\'' + e + '\');removePopup(\'last_product\')" class="ecshop_send">' + _esOkBtn + '</button><button onclick="removePopup(\'last_product\')" class="ecshop_cancel">' + _esCancelBtn + '<br/><span>' + _esClose + '</span></button></div>';
    }
    else{
        /* To update checkout and small basket*/
        i += '<div class="buttons"><button onclick="ecShopUpdateBasketInfoStage(\'' + a + '\',\'' + b + '\',\'' + c + '\',\'' + escape(d) + '\',\'' + e + '\',\'' + r + '\');removePopup(\'last_product\')" class="ecshop_send">' + _esOkBtn + '</button><button onclick="removePopup(\'last_product\')" class="ecshop_cancel">' + _esCancelBtn + '<br/><span>' + _esClose + '</span></button></div>';
    }
    
    i += '<div class="clear"></div></div>';
    /* Creating popup alert*/
    CreateConfirmation(h,i,"last_product");
}

/* Check for quantity and action and show alert or process basket*/
function checkUpdateBasket(a,b,c,d,f,g,h){
    /* a - product Guid, b - Quantity, c - action, d - optionstring (for packages), f - divId, g - noOfProductsInBasket, h - location*/
    
    /* g values:
     1 - if the user decrement the quantity to 0 when the quantity is 1
     clear - If the link "Clear basket" is clicked in small basket or large basket
     cancel - If the user cancels the order in the middle of checkout process
     remove - If the user removes the last product from the basket*/
    if(g == 1 || g == "clear" || g == "cancel" || g == "remove"){
        ecShopEmptyBasketConfirmation(a,b,c,d,f,g,h);
    }
    else{
        /* else process basket*/
        ecShopUpdateBasketInfoStage(a,b,c,escape(d),f);
    }
}
// This function id used to update product count in checkout step2
function updateBasketInfoStage(a,b,c,d,e,f,g){
    /*a - product Guid, b - Quantity, c - action (update), d - optionstring (for packages), e - increment count(inc) or decrement count (dec), f - divId, g - noOfProductsInBasket*/
    d = unescape(d);
    /* set default value for e - if nothing is sent (inc or dec)*/
    if(typeof(e) == undefined || e == ''){
        e = 'empty';
    }
    /* If decrement, Check quantity, 
     if 1 - ask user an alert to remove product, 
     else decrement count*/
    if(e == 'dec'){
        if(b == 1){
            if(g == 1){
                ecShopEmptyBasketConfirmation(a,b,"remove",d,f,1);
                return;
            }
            else{
                checkUpdateBasket(a,b,"remove",d,f,"remove","checkout");
                return;
            }
        }
        else{
            b--;
        }
    }
    /* Increment count*/
    if(e == 'inc'){
        b++;
    }
    /* Function to update small basket and checkout with result*/
    ecShopUpdateBasketInfoStage(a,b,c,d,f);
}
/* To update product count by changing number in input field in checkout*/
function updateQuantityInfoStage(a,b,c,d,e,f){
    /*a - Input field object, b - Old Quantity, c - Product guid, d - optionstring (for packages), e - divId, f - noOfProductsInBasket*/
    d = unescape(d);
    var g = "update";
    /* Read new quantity from input field*/
    var h = a.value;
    /*If the quantity field value is 0, then the show alert message to remove that product 
    else set action as "remove" and process basket*/
    if(h == 0){
        if(f == 1){
            ecShopEmptyBasketConfirmation(c,b,"remove",d,e);
            return;
        }
        else{
            g = "remove";
        }
    }
    /* Check field exist and old quantity value and new quantity value are different, if yes, Process updating small basket and checkout */
    if(a.value != "" && b != h){
        ecShopUpdateBasketInfoStage(c,h,g,d,e);
    }
}
/* Function used to change the variation in the basket and updating both small and large basket*/
var _esFirstVariation = true;
var _esPrevVariationTxt = null;
var _esPrevVariationMenu = null;
var _esPrevLink = null;
var _esPrevFunc = null;

/* To cancel the variation in large basket and checkout if the variation is changed by the user */
function ecShopCancelVariation(){
    if(_esPrevVariationMenu != null){
        hideObject(_esPrevVariationMenu);
    }
    if(_esPrevVariationTxt != null){
        showObject(_esPrevVariationTxt);
    }
    if(_esPrevLink != null){
        _esPrevLink.innerHTML = ecTranslate("basket-buttons.basket-modify");
        _esPrevLink.onclick = _esPrevFunc;
    }
    var a = document.getElementById("ecshopfx_cancel_variation");
    if(a){
        a.parentNode.removeChild(a);
    }
}
function ecShopChangeVariation(h,i,j,k,l,m,n){
    /*h - Modify link's Object, i - Quantity, j - Selected property Object, k - Select box Object, l - Number of row in product list added in basket, m - optionXML, n - inOrderProcess (true or false)*/
    /* If n is undefined, set inOrderProcess as false, So that it will not run orderProcess webservice */
    if(n == undefined){
        n = false;
    }
    
    /*Lets hide the previously selected object if the user did not click on Save,
    instead clicked on Modify for another variation*/
    /*By default the first variation change is set to true*/
    if(_esFirstVariation){
        _esFirstVariation = false;
    }
    /* If the user clicked on modify, store the old property in global variable, to retrieve it back, if cancelled*/
    else{
        /* Hide dropdown menu*/
        if(_esPrevVariationMenu != null){
            hideObject(_esPrevVariationMenu);
        }
        /* Show selected option as text*/
        if(_esPrevVariationTxt != null){
            showObject(_esPrevVariationTxt);
        }
        /* Replace save and cancel links with modify link */
        if(_esPrevLink != null){
            _esPrevLink.innerHTML = ecTranslate("basket-buttons.basket-modify");
            _esPrevLink.onclick = _esPrevFunc;
        }
    }
    /* Save Select box Object in global variable*/
    _esPrevVariationMenu = k;
    /* Save Selected property Object in global variable*/
    _esPrevVariationTxt = j;
    /*Save modify link oject in global variable*/
    _esPrevLink = h;
    _esPrevFunc = h.onclick;
    /* On clicking modify link, hide selected property,
    and Show dropdown menu,
    Overwrite modify innerHTML with save and cancel links*/
    hideObject(j);
    showObject(k);
    h.innerHTML = ecTranslate("basket-buttons.basket-variation-save");
    /*Forming HTML for cancel button*/
    var q = document.getElementById("ecshopfx_cancel_variation");
    if(q){
        q.parentNode.removeChild(q);
    }
    q = document.createElement("span");
    q.setAttribute("id","ecshopfx_cancel_variation");
    q.setAttribute("title",_esCancelBtn);
    /*Remove button*/
    q.innerHTML = " (x)";
    /*Adding onclick event for cancel button*/
    q.onclick = function(){
        ecShopCancelVariation();
    };
    q.style.cursor = "pointer";
    /* Append with save div*/
    h.parentNode.appendChild(q);
    /*On clicking save get selected option
    Form selected name and value and update it in optionstring
    and Update basket - if inOrderProcess = false 
    else - Update checkout and small basket */
    h.onclick = function(){
        /*Getting selection option*/
        var a = k.options[k.selectedIndex].value.split('|');
        /*Finding old option using the name of the property*/
        var b = new RegExp(">" + a[0] + "</name><value>[^>]*</value>","i");
        /*Forming new option*/
        var c = ">" + a[0] + "</name><value>" + a[1] + "</value>";
        /*Replacing old option with new option*/
        var d = m.replace(b,c);
        _esNewOptions = HtmlEncode(d);
        /*Replace save and cancel link area with the text and "updating..."*/
        h.innerHTML = ecTranslate("basket-buttons.basket-variation-updating");
        
        if(!n){
            /*Update large basket and small basket*/
            ecShopUpdateLargeBasket(_esVariationParam[l][0],i,'remove',HtmlEncode(m),'ecshop_checkout_container',false,false,true);
        }else{
            /* Calls function to form order xml*/
            var e = formOrderXml();
            
            var g = "ecshop_small_basket";
            ecShopUpdateOrderBasket(_esVariationParam[l][0],i,'remove',HtmlEncode(m),HtmlEncode(e),g,false,true,true);
        }
    }
}
/*Function to form order xml*/
function formOrderXml(a){
    var g = "<orderinfo>"; 
    var h = getSelectedValue(_esShopParam + 'paymentmethod');
    var i = getSelectedValue(_esShopParam + 'shippingmethod');
    if(h != -1){
        pV = h.split('|');
        g += "<paymentmethod>" + pV[1] + "</paymentmethod>";
    }
    if(i != -1){
        sV = i.split('|');
        if(_esDynamicRateSelected){
            g += '<shippingmethod updaterate="' + _esDynamicRate + '">' + sV[1] + '</shippingmethod><attributes><attribute><name>deliverydate</name><value>' + _esSelectedDeliveryTime + '|' + _esSelectedDeliveryDate + '</value></attribute></attributes>';
        }
        else{
            g += '<shippingmethod>' + sV[1] + '</shippingmethod>';
        }
    }
   
    g += "</orderinfo>";
    return g;
}
function ecShopUpdateBasketInfoStage(a,b,c,d,e,f){
    if(f == undefined)
        f = false;
    d = unescape(d);
    
    /* Calls function to form order xml*/
    var g = formOrderXml(c);
    
    if(f == true){
        _esRedirect = _esRedirectTo;
    }
    else{
        _esRedirect = "";
    }
    ecShopUpdateOrderBasket(a,b,c,HtmlEncode(d),HtmlEncode(g),e);
}

/*** SHIPPING RATES CALCULATION AND DISPLAY ***/
function ecShopResetShippingArrays(){
    _esShipRates = new Array();
    _esShipRatesFormatted = new Array();
    _esOrderTotal = new Array();
    _ecshopOrderTotalFormated = new Array();
    _esOrderFormatted = new Array();
    _esShipName = new Array();
    _esShipDesc = new Array();
    _esShipTime = new Array();
    _esShipGuid = new Array();
}
function ecShopAddToShippingArrays(a,b,c,d,e,f,g,h,i,j){
    _esShipRates[a] = b;
    _esShipRatesFormatted[a] = c;
    _esOrderTotal[a] = d;
    _ecshopOrderTotalFormated[a] = e;
    _esOrderFormatted[a] = f;
    _esShipName[a] = g;
    _esShipDesc[a] = h;
    _esShipTime[a] = i;
    _esShipGuid[a] = j;
}
function ecShopLoadShippingRates(){
    var a = 1;
    var b = readCookie(_esSelectedShipGuidCookie);
    if(b != ""){
        for(var i=1;i<_esShipGuid.length;i++){
            if(b == _esShipGuid[i]){
                a = i;
            }
        }
    }
    ecShopShowShippingRates(a,'ecshopfx_shipping_rate','ecshopfx_order_total','ecshopfx_current_shipping_description');
}
/*Calculate and display shipping rates in the large basket*/
function ecShopShowShippingRates(a,b,c,d){
    var e = document.getElementById(d);
    var f = document.getElementById(c);
    var g = document.getElementById(b);
    var h = ecTranslate('basket-labels.basket-shipping-sentwith');
    var i = ecTranslate('basket-labels.basket-shipping-time');
    var j = ecTranslate('basket-labels.basket-shipping-days');
    _esShipTotalContainer = b;
    _esOrderTotalContainer = c;
    _esShipDescContainer = d;
    if(_esShipRetainCookie == '1'){
        /*Storing the selected shipping method in the cookie*/
        createCookie(_esSelectedShipGuidCookie,_esShipGuid[a],1);
        createCookie(_esSelectedShipPosCookie,a,1);
        _esShipRetainCookie = "0";
    }
    if(e){
        var k = '<p><strong>' + h + ': ' + _esShipName[a] + '</strong><br/>';
        k += replaceBreaks(unescape(decodeURI(_esShipDesc[a]))) + '</p>';
        k += '<p><small>' + i + ': ' + _esShipTime[a] + ' ' + j + '</small></p>';
        e.innerHTML = k;
    }
    if(g){
        g.innerHTML = _esShipRatesFormatted[a];
    }
    if(f){
        var l = f.className;
        if(l != null && l != _esOrderTotal[a]){
            var m = (l*1)+(_esShipRates[a]*1);
            var n = "0";
            f.innerHTML = ecShopFormatPrice(_ecshopPriceFormatCulture,m,n);
        }
        else{
            f.innerHTML = _esOrderFormatted[a];
        }
    }
}
function ecShopFormatPrice(a,b,c){
    ecShop.Web.Soap.ecShopWS.FormatNumberByCulture(a,b,c,OnFormatePrice,OnError);
}
function OnFormatePrice(r){
    var a = document.getElementById('ecshopfx_order_total');
    a.innerHTML = r;
}
function ecShopChangeShippingRates(a,b,c,d,e,f){
    _esShipRetainCookie = "1";
    var g = ecTranslate('basket-labels.basket-shipping-time');
    var h = ecTranslate('basket-labels.basket-shipping-days');
    var j = '<h3>Available shipping rates</h3>';
    j += '<table cellpadding="3" cellspacing="0" width="100%">';
    j += '<thead>';
    j += '<tr><th>' + e + '</th><th>' + g + '</th><th>' + d + '</th></tr>';
    j += '</thead>';
    j += '<tbody>';
    for(var i=1;i<_esShipRates.length;i++){
        j += '<tr onclick="ecShopDoChangeShippingRates(\'' + i + '\', \'' + a + '\', \'' + b + '\', \'' + c + '\')">';
        j += '<td>' + _esShipName[i] + '</td>';
        j += '<td>' + _esShipTime[i] + ' ' + h + '</td>';
        j += '<td>' + _esShipRatesFormatted[i] + '</td>';
        j += '</tr>';
    }
    j += '</tbody>';
    j += '</table>';
    createPopup(j,"ecshop_shipping_rates","shippingrates");
}
function ecShopDoChangeShippingRates(a,b,c,d){
    ecShopShowShippingRates(a,b,c,d);
    removePopup("shippingrates");
}
/*Display shipping rates in the order form*/
function ecShopAddToShippingCollection(a,b,c,d,e,f){
    _esShipGuidCol[a] = b;
    _esShipPricesColFormatted[a] = d;
    _esOrderTotalPriceFormatted[a] = f;
}
function ecShopSetSelectedShippingCollection(a,b,c,d){
    _esSelectedShipPos = a;
    _esSelectedShipGuid = b;
    _esSelectedShipPrice = c;
    _esSelectedShipPriceFormatted = d;
}
function ecShopLoadSelectedShippingCollection(){
    var a = document.getElementById("ecshopfx_totalprice");
    var b = document.getElementById("ecshopfx_shipping_price");
    if(_esSelectedShipPos != null){
        if(a){
            a.innerHTML = _esOrderTotalPriceFormatted[_esSelectedShipPos];
        }
        if(b){
            b.innerHTML = _esSelectedShipPriceFormatted;
        }
    }
}
function ecShopProcessShipping(a,b,c,d,e){
    /* Show the selected shipping description and hide the rest*/
    ecShopHideAndShow(a,d);
    createCookie(_esSelectedShipGuidCookie,_esShipGuidCol[d],1);
    _esSelectedShipPos = d;
    document.getElementById(b).innerHTML = _esShipPricesColFormatted[d];
    document.getElementById(c).innerHTML = e;
    ecShopSelectShippingMethod();
}
/* Function for displaying related description when any option in shipping/payment selected 
// E.g. showDescription('ec_webshop_page_6_paymentmethod', 'paydesc')*/
function ecShopShowDescription(a,b){
    var c = document.getElementsByName(a);
    var l = c.length;
    for(i=0;i<l;i++){
        if(c[i].checked)
            ecShopHideAndShow(b,(i+1));
    }
}
/* Dynamic shipping rate calculation*/
function ecShopGetDynamicShippingRate(b,c,d,e){
    var f = getSelectedValue(_esShopParam + 'shippingmethod');
    var h = f.split('|');
    var j = (h.length>1)?h[1]:"";
    var k = document.getElementById("ecshopfx_shipping_restriction_" + j);
    var l = document.getElementById("ecshopfx_products_in_basket_guid_array").value;
    var m = document.getElementById("ecshopfx_products_in_basket_quantity_array").value;
    var g = l.split("|");
    var q = m.split("|");
    if(g.length>0){
        var n = document.getElementById("ecshopfx_shipping_agent");
        var o = (n)?n.value:"";
        var a = (_esSelectedDeliveryAgent.length>0)?_esSelectedDeliveryAgent:o;
        var s = document.getElementById("ecshopfx_shipping_postcode");
        var p = (s)?s.value:"";
        if(p == "" && _esDynamicRatePostcode != ""){
            p = _esDynamicRatePostcode;
        }
        var t = new Array();
        t[0] = "";
        var u = new Array();
        u[0] = 0;
        for(var i=1;i<g.length;i++){
            t[i] = g[i];
            u[i] = q[i];
        }
        if(k && k.value == 'dynamic-rate-orderprice'){
            p = 0;
        }
        if(validateForm("ecshopfx_shipping_dynamic_" + j)){
            CreateUpdate(ecTranslate("basket-labels.basket-updating"));
            ecShop.Web.Soap.ecShopWS.GetShippingRate(a,p,t,u,e,OnShowShippingCost,OnShippingCostError);
        }
    }
    function OnShowShippingCost(r){
        DeleteUpdate();
        _esDynamicRateValid = true;
        document.getElementById(b).innerHTML = r.FormattedCost;
        document.getElementById(c).innerHTML = r.FormattedTotal;
        document.getElementById("ecshopfx_dynamicrate_" + j).innerHTML = r.FormattedCost;
        _esDynamicRate = r.Cost;
    }
    function OnShippingCostError(a){
        _esDynamicRateValid = false;
        OnError(a);
    }
}
function ecShopFillDynamicShippingRate(a,b,c,d,e,f){
    if(b == undefined){
        b = true;
    }
    var g = '';
    if(b){
        g += '<div>';
        g += ' <label for="ecshopfx_shipping_postcode">' + ecTranslate("checkout-labels.checkout-shipping-selectpostcode") + ' *</label>';
        g += ' <input id="ecshopfx_shipping_postcode" class="validate number" />';
        g += ' </div>';
    }
    if(ecShopIsShortDistance(_esDynamicRatePostcode)){
        g += ' <div>';
        g += ' <label for="ecshopfx_shipping_agent">' + ecTranslate("checkout-labels.checkout-shipping-selectdeliverytime") + ' *</label>';
        g += ' <input id="ecshopfx_shipping_agent" type="hidden" value="H10-12"/>';
        g += ecShopCreateDynamicRateTable(e);
        g += ' </div>';
    }
    if(b){
        g += ' <button onclick="ecShopGetDynamicShippingRate(\'' + c + '\', \'' + d + '\', \'' + e + '\', \'' + f + '\')" class="ecshop_send">Sjá sendingarkostnað</button>';
    }
    if(a){
        a.innerHTML = g;
    }
    if(!b){
        ecShopGetDynamicShippingRate(c,d,e,f);
    }
}
function ecShopCreateDynamicRateTable(b){
    var c = '<table cellpadding="3" cellspacing="0" class="clear dynamic-rate" id="ecshopfx_dynamicrate_table_' + b + '">';
    var d = new Array(7);
    d[0] = ecTranslate("common-labels.common-day-sunday");
    d[1] = ecTranslate("common-labels.common-day-monday");
    d[2] = ecTranslate("common-labels.common-day-tuesday");
    d[3] = ecTranslate("common-labels.common-day-wednesday");
    d[4] = ecTranslate("common-labels.common-day-thursday");
    d[5] = ecTranslate("common-labels.common-day-friday");
    d[6] = ecTranslate("common-labels.common-day-saturday");
    var a = new Array("H11-13","H13-15","H14-16","H17-19","H18-21");
    var s = new Array("11 - 13","13 - 15","14 - 16","17 - 19","18 - 21");
    var e = new Array(true,false,true,false,true);
    var f = new Array(true,false,true,true,false);
    var g = new Array(false,true,false,true,false);
    c += '<tr>';
    var h = "";
    var k = "";
    var l = "";
    /*Write headers*/
    for(var j=0;j<4;j++){
        h = new Date();
        h.setDate(h.getDate()+(1+j));
        k = h.toDateString();
        l = h.getDay();
        c += '<th>' + d[l] + '</th>'
    }
    c += '</tr>';
    /*Write time slots*/
    for(var i=0;i<a.length;i++){
        c += '<tr>';
        for(var j=0;j<4;j++){
            h = new Date();
            h.setDate(h.getDate()+(1+j));
            k = h.toDateString();
            l = h.getDay();
            if((l == 0 && g[i]) || (l == 6 && f[i]) || ((l>0 && l<6) && e[i])){
                c += '<td onclick="ecShopSetSelectedDeliveryTime(this,\'ecshopfx_dynamicrate_table_' + b + '\',\'' + a[i] + '\',\'' + s[i] + '\', \'' + k + '\')" class="click-me">' + s[i] + '</td>';
            }
            else{
                c += '<td class="na">&nbsp;</td>';
            }
        }
        c += '</tr>';
    }
    c += '</table>';
    return c;
}
function ecShopSetSelectedDeliveryTime(a,b,c,d,e){
    var f = document.getElementById("ecshopfx_shipping_agent");
    if(f){
        f.value = c;
    }
    _esSelectedDeliveryAgent = c;
    _esSelectedDeliveryTime = d;
    _esSelectedDeliveryDate = e;
    var g = document.getElementById(b);
    var h = g.getElementsByTagName("td");
    for(var i=0;i<h.length;i++){
        if(h[i].className == "selected"){
            h[i].className = "click-me";
        }
    }
    a.className = "selected";
}
function ecShopIsShortDistance(a){
    var b = false;
    if(a == ""){
        b = true;
    }
    else if(a >= 101 && a <= 113){
        b = true;
    }
    else if(a >= 116 && a <= 172){
        b = true;
    }
    else if(a >= 200 && a <= 225){
        b = true;
    }
    else if(a == 270){
        b = true;
    }
    return b;
}
/* ecShop Basket Webservice - These functions interact with ecWeb*/
function TransformBasketXml(a,b,c){
    ecShop.Web.Soap.ecShopWS.TransformBasketXml(a,b,OnTransformBasket,OnError);

    function OnTransformBasket(r){
        if(r.length>0){
            for(var i=0;i<c.length;i++){
                ReplaceHtml(c[i],r[i],i);
            }
            ecShopUpdateShippingRates();
        }
    }
}
function ecShopUpdateShippingRates(){
    var a = readCookie(_esSelectedShipPosCookie);
    if(a == null || a == ""){
        a = 1;
    }
    ecShopShowShippingRates(a,_esShipTotalContainer,_esOrderTotalContainer,_esShipDescContainer);
    var c = document.getElementById(_esOrderTotalContainer);
    if(c){
        var b = c.getAttribute("price");
        if(b != null){
            var d = (orderPrice*1)+(_esShipRates[a]*1);
            var e = "0";
            c.innerHTML = ecShopFormatPrice(_ecshopPriceFormatCulture,d,e);
        }
    }
}
/* The following functions are used in conjunction with jquery to update the basket in ecWeb.*/
function ecShopClearBasketReceipt(){
    ecShopUpdateLargeBasket('','0','clear','','ecshop_small_basket');
}
function ecShopUpdateLargeBasket(a,b,c,d,e,f,g,h){
    var i = _esBskPageId;
    var j = _esBskPosId;
    var k = "2";
    if(g == undefined)
        g = true;
    if(f == undefined)
        f = false;
    if(h == undefined)
        h = false;
    ecShopUpdateBasket(a,b,c,"",unescape(d),e,i,j,k,g,f,h);
}
function ecShopUpdateOrderBasket(a,b,c,d,e,f,g,h,i){
    if(g == undefined)
        g = true;
    if(i == undefined)
        i = false;
    if(h == undefined)
        h = true;
    _esOrderXML = e;
    ecShopUpdateLargeBasket(a,b,c,d,f,h,g,i);
}
function ecShopResetBasketHtml(){
    var a = document.getElementById("ecshop_small_cart");
    var b = document.getElementById("ecshop_small_basket_dropdown");
    if(a){
        a.innerHTML = ' <span class="basket_center"><span class="basket_center_content">' + ecTranslate("basket-labels.basket-is-empty") + '</span></span>';
    }
    if(b){
        b.innerHTML = "";
    }
}
function ecShopUpdateBasket(q,r,s,u,v,w,x,y,z,A,B,C){
    if(A == undefined)
        A = true;
    if(A)
        CreateUpdate(ecTranslate("basket-labels.basket-updating"));
    if(B == undefined)
        B = false;
    if(C == undefined)
        C = false;
        
    _esShipRetainCookie = '0';
    
    var D = new SOAPObject("processBasket");
    D.ns = "http://tempuri.org/";
    D.appendChild(new SOAPObject("pageId")).val(x);
    D.appendChild(new SOAPObject("positionId")).val(y);
    D.appendChild(new SOAPObject("pageType")).val(z);
    D.appendChild(new SOAPObject("productId")).val(q);
    D.appendChild(new SOAPObject("quantity")).val(r);
    D.appendChild(new SOAPObject("comments")).val(u);
    D.appendChild(new SOAPObject("action")).val(s);
    D.appendChild(new SOAPObject("option")).val(v);
    /*Create a new SOAP Request*/
    var E = new SOAPRequest("http://tempuri.org/processBasket",D);/*Request is now ready to be sent to a web-service*/
    E.addNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
    E.addNamespace("xsd","http://www.w3.org/2001/XMLSchema");
    /*Lets send it*/
    SOAPClient.Proxy = ecShopReturnHost() + "/editor/soap/ecbusiness.asmx";/*Specify web-service address (if local to your domain) or a proxy file*/
    SOAPClient.SOAPServer = ecShopReturnHost() + "/editor/soap/ecbusiness.asmx";
    SOAPClient.SendRequest(E,processResponse);/*Send request to server and assign callback function*/
    
    function processResponse(a,b,d){
        try{
            var e = a.Body[0].processBasketResponse[0].processBasketResult[0].root[0];
            var f = e.htmldata[0].Text;
            if(C){
                /*Call the webservice again to add the new variations*/
                ecShopUpdateBasket(q,r,'add',u,_esNewOptions,w,x,y,z,true,B,false);
            }
            else{
                if(A){
                    var g = new Array();
                    var h = new Array();
                    var j = new Array("ecshop_small_basket","ecshop_large_cart");
                    var k = new Array("ecShop - Small cart v2.0","ecShop - Large cart v2.0");
                    var l = 0;
                    var t = false;
                    for(var i=0;i<j.length;i++){
                        var c = document.getElementById(j[i]);
                        if(c){
                            if(j[i] == w){
                                ReplaceHtml(w,f,i);
                            }
                            else{
                                g[l] = k[i];
                                h[l] = j[i];
                                l++;
                                t = true;
                            }
                        }
                    }
                    if(t){
                        var m = document.location.href;
                        if(m.indexOf("?ec_webshop_page")<0){
                            TransformBasketXml(b,g,h);
                        }
                    }
                    /* Credit limit*/
                    if(f.indexOf("ecshopfx_credit_limit")>-1){
                        if(_esCreditLimitHead == "" || _esCreditLimitMsgS == "" || _esCreditLimitMsgE == ""){
                            _esCreditLimitHead = ecTranslate("basket-headings.basket-credit-limit-exceeds");
                            _esCreditLimitMsgS = ecTranslate("basket-messages.basket-credit-limit-exceeds-message-start");
                            _esCreditLimitMsgE = ecTranslate("basket-messages.basket-credit-limit-exceeds-message-end");
                        }
                        CreateMessage(_esCreditLimitHead,_esCreditLimitMsgS + " " + _esCreditLimitPrice + ". " + _esCreditLimitMsgE,"credit_limit_exceeds");
                    }
                    /* Stock limit*/
                    if(f.indexOf("ecshopfx_stock_limitexceed")>-1){
                        if(_esStockLimitHead == "")
                            _esStockLimitHead = ecTranslate("basket-headings.basket-stock-limit-exceeds");
                        CreateMessage(_esStockLimitHead,_esNoStockMsg,"stock_limit_exceeds");
                    }
                }
                if(B){
                    var n = document.location.href;
                    if(_esRedirect != ""){
                        var o = _esRedirect;
                        _esRedirect = "";
                        if(n.indexOf("?ec_webshop_page")>0){
                            document.location.href = o;
                        }
                        else{
                            DeleteUpdate();
                        }
                    }
                    else if(n.indexOf("?ec_webshop_page")>0 && _esOrderXML.length>0){
                        var p = ecShopReturnFieldFromCookie("step");
                        if(p == '3'){
                            ecShopUpdateOrder("info","false",_esOrderXML,"ecshop_basket_container_step3","basketinfostep3");
                        }
                        else{
                            ecShopUpdateOrder("info","false",_esOrderXML,"ecshop_basket_container","basketinfo");
                        }
                    }
                    else{
                        DeleteUpdate();
                    }
                }
                else{
                    DeleteUpdate();
                }
            }
        }
        catch(err){
            if(b != "" || b != undefined)
                CreateError(err.description + "<br/><br/>" + b);
            DeleteUpdate();
        }
    }
}
/***************************************\\
//                                      \\
//          Basket ends                 \\
//                                      \\
//***************************************/

/***************************************\\
//                                      \\
//       Save basket starts             \\
//                                      \\
//***************************************/
function ecShopSaveBasket(a,b,c,d,e,f){
    /*a - loginLink, b - userId, c - basketId, d - basketName, e - action, f - elementId*/
    if(b.length>0){
        if(d == "" && e == "save"){
            var g = "";
            g += '<h3>Enter basket name<h3>';
            g += '<form id="save_basket_form" name="save_basket_form"><div><label>Basket name</label><input type="text" class="validate" name="basket_name" id="basket_name" /></div>';
            g += '<button onclick="ecShopCallWSSaveBasket(\'' + c + '\',\'' + "" + '\',\'' + e + '\',\'' + f + '\'); return false;">' + ecTranslate("common-buttons.common-save") + '</button>';
            g += '<button onclick="removePopup(\'save_basket\'); return false;" class="ecshop_cancel">' + _esCancelBtn + '<br/><span>' + _esClose + '</span></button></form>';
            createPopup(g,"save_basket","save_basket");
        }
        else{
            ecShopCallWSSaveBasket(c,d,e,f);
        }
    }
    else{
        document.location.href = a;
    }
}
function ecShopCallWSSaveBasket(a,b,c,d){
    /*a - basketId, b - basketName, c - action, d - elementId*/
    if(c == "save"){
        if(validateForm("save_basket_form")){
            var e = document.getElementById("basket_name");
            if(e)
                b = trim(e.value);
            if(b != ""){
                removePopup("save_basket");
                ecShopUpdateSavedBasket(a,b,c,d);
            }
        }
    }
    else{
        ecShopUpdateSavedBasket(a,b,c,d);
    }
}
function ecShopUpdateSavedBasket(m,n,o,p){
    /*m - basketId, n - basketName, o - action, p - elementId*/
    CreateUpdate(ecTranslate("basket-labels.basket-savebasket-updating"));
    if(m == "" || m == undefined){
        m = "";
    }
    var q = _esBskPageId;
    var r = _esBskPosId;
    var s = "1";
    var u = new SOAPObject("saveBasket");
    u.ns = "http://tempuri.org/";
    u.appendChild(new SOAPObject("pageId")).val(q);
    u.appendChild(new SOAPObject("positionId")).val(r);
    u.appendChild(new SOAPObject("pageType")).val(s);
    u.appendChild(new SOAPObject("basketId")).val(m);
    u.appendChild(new SOAPObject("basketName")).val(n);
    u.appendChild(new SOAPObject("action")).val(o);
    var v = new SOAPRequest("http://tempuri.org/saveBasket",u);
    v.addNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
    v.addNamespace("xsd","http://www.w3.org/2001/XMLSchema");
    SOAPClient.Proxy = ecShopReturnHost() + "/editor/soap/ecbusiness.asmx";
    SOAPClient.SOAPServer = ecShopReturnHost() + "/editor/soap/ecbusiness.asmx";
    SOAPClient.ContentType = "text/xml";
    SOAPClient.SendRequest(v,saveBasketResponse);
    
    function saveBasketResponse(a,b,c){
        try{
            var d = a.Body[0].saveBasketResponse[0].saveBasketResult[0].root[0];
            var e = d.htmldata[0].Text;
            var f = new Array();
            var g = new Array();
            var h = new Array();
            var j = new Array();
            var k = 0;
            var t = false;
            if(o == "overwrite" || o == "append"){
                h[0] = "ecshop_small_basket";
                j[0] = "ecShop - Small cart v2.0";
                h[1] = "ecshop_large_cart";
                j[1] = "ecShop - Large cart v2.0";
            }
            else{
                h[0] = "ecshopfx_save_basket";
                j[0] = "ecShop - View saved basket v2.0";
            }
            for(var i=0;i<h.length;i++){
                var l = document.getElementById(h[i]);
                if(l){
                    if(h[i] == p){
                        ReplaceHtml(p,e,i);
                    }
                    else{
                        f[k] = j[i];
                        g[k] = h[i];
                        k++;
                        t = true;
                    }
                }
            }
            if(t){
                TransformBasketXml(b,f,g);
            }
            if(htmlData.indexOf("ecshopfx_credit_limit")>-1){
                if(_esCreditLimitHead == "" || _esCreditLimitMsgS == "" || _esCreditLimitMsgE == ""){
                    _esCreditLimitHead = ecTranslate("basket-headings.basket-credit-limit-exceeds");
                    _esCreditLimitMsgS = ecTranslate("basket-messages.basket-credit-limit-exceeds-message-start");
                    _esCreditLimitMsgE = ecTranslate("basket-messages.basket-credit-limit-exceeds-message-end");
                }
                CreateMessage(_esCreditLimitHead,_esCreditLimitMsgS + " " + _esCreditLimitPrice + ". " + _esCreditLimitMsgE,"credit_limit_exceeds");
            }
            if(htmlData.indexOf("ecshopfx_stock_limitexceed")>-1){
                if(_esStockLimitHead == "")
                    _esStockLimitHead = ecTranslate("basket-headings.basket-stock-limit-exceeds");
                CreateMessage(_esStockLimitHead,_esNoStockMsg,"stock_limit_exceeds");
            }
        }
        catch(err){}
        DeleteUpdate();
    }
}
/***************************************\\
//                                      \\
//       Save basket ends               \\
//                                      \\
//***************************************/

/******************************************************\\
//                                                     \\
//    Related products-Large cart, checkout starts     \\
//                                                     \\
//******************************************************/
function ecShopGetRelatedProducts(){
    ecShop.Web.Soap.ecShopWS.GetRelatedProducts(_esProdGuidArray,OnRelatedProducts,OnError);
}
function OnRelatedProducts(r){
    var a = document.getElementById("related_products_container");
    if(a){
        a.innerHTML = r;
    }
}
function ecShopMoreRelatedProducts(a,b,d){
    for(var i=1;i <= d;i++){
        var c = document.getElementById(a);
        if(c){
            if(i == b){
                hideObject('page' + b);
            }
            showObject(a);
        }
    }
}
/******************************************************\\
//                                                     \\
//    Related products-Large cart, checkout ends       \\
//                                                     \\
//******************************************************/

/***************************************\\
//                                      \\
//       Product details starts         \\
//                                      \\
//***************************************/
function quantityCheck(a,b){
    /* Read value of quantity fromt he field*/
    var c = document.getElementById('product_qty' + a).value;
    var d = document.getElementById('ecshopfx_product_stock_hidden' + a).value;
    if(c == 0){
        CreateError(ecTranslate("product-messages.product-quantity-zero"));
    }
    if(parseInt(d)<parseInt(c)){
        if(b == 'zero-stock' || b == ''){}
        else if(b == 'no-stock' || b == 'hide-stock'){
            CreateError(ecTranslate("product-messages.product-limitedstock-no-stock"));
            if(!d>0){
                document.getElementById('product_qty' + a).value = "1";
            }
            else{
                document.getElementById('product_qty' + a).value = d;
            }
        }
    }
}
/* The following functions are used to display prices for unlimited package variations (dropdown selections) */
function ecShopSaveColorSelection(a,b,c){
    var d = document.getElementById("ecshopfx_color_selection");
    
    /*Create the option XML for the selected color*/
    if(d){
        var e = '<attrib><name>' + b + '</name><value>' + c + '</value></attrib>';
        d.value = HtmlEncode(e);
    }
    
    /*Change the styles of the color samples, and high-light the currently selected color*/
    var f = a.parentNode;
    for(var i=0;i<f.childNodes.length;i++){
        var g = f.childNodes[i];
        g.className = g.className.replace(" selected","").replace("selected","");
    }
    a.className += " selected";
    
    /*Update the package to get thec correct image, stock and price*/
    var h = document.getElementById("ecshopfx_color_package");
    if(h){
        h.value = b + ":" + c + "|";
    }
    ecShopUpdatePackagePrice();
}

function ecShopShowProductDetail(a,pos){
    var b = null;
    mod_pos = pos;
    if(_esLastOpenedProd == null)
        _esLastOpenedProd = "";
    _esLastOpenedProd = _esLastOpenedProd.indexOf(mod_pos+"_")> -1 ? _esLastOpenedProd:"";
    if(_esLastOpenedProd == ""){
        _esLastOpenedProd = readCookie("ecshoptable_" + mod_pos + "_" + _ecshopWebsiteId);
    }
    if(_esLastOpenedProd != "" && _esLastOpenedProd != a){
        b = document.getElementById("ecshopfx_detail_" + _esLastOpenedProd);
        var c = document.getElementById("ecshopfx_table_line_" + _esLastOpenedProd);
        if(b){
            hideObject(b);
            c.className = "line";
        }
    }
    var d = document.getElementById("ecshopfx_detail_" + a);
    var c = document.getElementById("ecshopfx_table_line_" + a);
    if(d){
        if(d.className.indexOf("ecshop_hide")>-1){
            showObject(d);
            c.className = "line with_bkg";
        }
        else{
            hideObject(d);
            c.className = "line";
        }
    }
    _esLastOpenedProd = a;
    createCookie("ecshoptable" +"_"+ mod_pos+"_"+ _ecshopWebsiteId,a,0);    
}


function CloseOption(a,p)
{
     var d = document.getElementById("ecshopfx_detail_" + p + "_" + a);
     var c = document.getElementById("ecshopfx_table_line_" + p + "_" + a);
     c.className = "line with_bkg";
     d.className = "ecshop_table_details ecshop_hide";
}


var _esLastOpenedProdnew ="";
function ecShopShowProductDetailNew(a){
    var b = null;
    if(_esLastOpenedProdnew == ""){
        _esLastOpenedProdnew = readCookie("ecshoptablenew" + _ecshopWebsiteId);
    }
    if(_esLastOpenedProdnew != "" && _esLastOpenedProdnew != a){
        b = document.getElementById("ecshopfx_new_detail_" + _esLastOpenedProdnew);
        var c = document.getElementById("ecshopfx_new_table_line_" + _esLastOpenedProdnew);
        if(b){
            hideObject(b);
            c.className = "line";
        }
    }
    var d = document.getElementById("ecshopfx_new_detail_" + a);
    var c = document.getElementById("ecshopfx_new_table_line_" + a);
    if(d){
        if(d.className.indexOf("ecshop_hide")>-1){
            showObject(d);
            c.className = "line with_bkg";
        }
        else{
            hideObject(d);
            c.className = "line";
        }
    }
    _esLastOpenedProdnew = a;
    createCookie("ecshoptablenew" + _ecshopWebsiteId,a,0);        
}

function ecShopGoToProductDetail(a){
    createCookie("ecshoptable" + _ecshopWebsiteId,_esLastOpenedProd,1);
    document.location.href = a;
}
function ecShopResetPackagePricing(a){
    _esPkgPriceArray = new Array();
    _esStockType = a;
}

function displayPackagePrice(a,b){
    var c = ecTranslate("product-labels.product-price");
    if(a == undefined){
        a = (lowestBudgetPrice == "")?lowestPrice:lowestBudgetPrice;
    }
    if(b == undefined){
        b = lowestPrice;
    }
    /*Update price*/
    var d = document.getElementById("ecshopfx_product_price");
    var e = document.getElementById("ecshopfx_product_price_hidden");
    var f = document.getElementById("strike");
    if(d)
        d.innerHTML = '<span class="label">' + c + ':</span> <span class="value">' + a + '</span>';
    if(e)
        e.value = a;
    if((a != b) && f){
        f.innerHTML = '<span class="label">' + c + ':</span> <span class="value">' + b + '</span>';
        showObject("strike");
    }
    else{
        hideObject("strike");
    }
}
function displayPackageStock(a,b){
    var g = "";
    if(b <= 0){
        g = "0";
    }
    else{
        g = b;
    }
    var h = document.getElementById("ecshopfx_product_stock");
    var l = document.getElementById("ecshopfx_product_stock_hidden");
    if(h)
        h.innerHTML = '<span class="label">' + ecTranslate("product-labels.product-stock") + ':</span> <span class="value">' + g + '</span>';
    showObject("ecshopfx_product_stock");
    if(l)
        l.value = g;
    if(_esManageStock){
        if(a == 'zero-stock'){
            var m = "ecshopfx_product_out_of_stock_addtobasket";
            var o = "ecshopfx_product_out_of_stock";
            var p = "ecshopfx_buy_button";
            var q = "ecshopfx_stock_available_date";
            if(b<parseInt(_esReOrderLvl) && b>parseInt(_esStockLwstLvl)){
                showObject(m);
                hideObject(o);
                showObject(p);
                hideObject(q);
            }else if(b <= parseInt(_esStockLwstLvl)){
                hideObject(m);
                showObject(o);
                hideObject(p);
                /* Site specific : Life - Display stock available date*/
                if(_esPkgPriceArray[a][13].length>0){
                    displayStockAvailabaleDate(a);
                }
            }
            else{
                hideObject(o);
                hideObject(m);
                showObject(p);
                hideObject(q);
            }
        }
        else if(a == 'no-stock'){
            if(b <= 0){
                hideObject(p);
                showObject(o);
                /* Site specific : Life - Display stock available date*/
                if(_esPkgPriceArray[a][13].length>0){
                    displayStockAvailabaleDate(a);
                }
            }
            else{
                hideObject(o);
                showObject(p);
                hideObject(q);
            }
        }
    }
}
function displayPackageImage(i){
    /*Change images - if image exist, show it, otherwise go back to the default image for the package.*/
    var r = document.getElementById("ecshopfx_image_viewer");
    var s = document.getElementById("ecshopfx_large_image");
    var b = _esPkgPriceArray[i][4];
    var c = _esPkgPriceArray[i][5];
    var d = _esPkgPriceArray[i][7];

    /*On first load - save the default image and link to a global variable for later use*/
    if(r && _esPkgImg.length == 0){
        _esPkgImg = r.innerHTML;
        _esPkgLink = s.href;
    }
    if(r){
        if(b.length == 0){
            if(_esPkgImg.length>0){
                r.innerHTML = _esPkgImg;
                if(s){
                    s.href = _esPkgLink;
                }
            }
            else{
                r.innerHTML = ecTranslate("product-labels.product-noimage");
            }
        }
        else{
            var t = new Image();
            t.src = b;
            var u = t.height;
            var w = getImageSize(b);
            r.innerHTML = '<img alt="' + _esPkgPriceArray[i][2] + '"' + w[1]+w[0] + 'src="' + t.src + '" id="prod_image" jqimg="' + c + '"/>';
            if(s){
                s.href = c;
            }
        }
        if(d.length>0 && _esPkgPriceArray[i][11] == "1"){
            var x = d.split("|");
            var y = _esPkgPriceArray[i][10].split("|");
            var z = document.getElementById("ecshopfx_more_images");
            if(z){
                var A = '';
                for(var j=0;j<x.length-1;j++){
                    A += '<a href="javascript:void(0)" onclick="ecShopSwapImageInViewer(' + i + ', ' + j + ');">';
                    A += '<img class="image" src="' + x[j] + '" border="0" id="img_1" alt="' + x[j] + '" />';
                    A += '</a>';
                }
                z.innerHTML = A;
            }
            showObject("ecshopfx_more_images");
        }
        else{
            hideObject("ecshopfx_more_images");
        }
    }
}
function ecShopUpdatePackagePrice(){
    var a = _esStockType;
    /*Form current package*/
    var c = document.getElementById("ecshopfx_product_variations");
    var b = c.getElementsByTagName("select");
    var d = '';
    
    for(var i=0;i<b.length;i++){
        var e = b[i].selectedIndex;
        var v = b[i].options[e].value;
        var n = b[i].options[e].getAttribute("title");
        d += n + ":" + v + "|";
    }
    
    var f=document.getElementById("ecshopfx_color_package");
    if(f){
        d += f.value;
    }
    /*Check package combination*/
    for(var i=1;i<_esPkgPriceArray.length;i++){
        if(_esPkgPriceArray[i][0] == d){
            
            /*Update price*/
            displayPackagePrice(_esPkgPriceArray[i][1],_esPkgPriceArray[i][6]);
            
            
            /*Update stock*/
            displayPackageStock(i,_esPkgPriceArray[i][3]);
            
            /*Update Image*/
            displayPackageImage(i);
            
            /* Update Custom property*/
            if(_esPkgPriceArray[i][12].length>0){
                var B = document.getElementById("ecshopfx_custom_property");
                if(B){
                    var C = '';
                    var D = _esPkgPriceArray[i][12].split("|");
                    C += '<div class="product_custom_property">';
                    C += '<h5>' + ecTranslate("product-headings.product-custom-property") + '</h5>';
                    for(var k=0;k<D.length-1;k++){
                        var E = D[k].split(":");
                        C += '<span class="property_name">' + E[0] + '</span> : ';
                        C += '<span class="property_value">' + E[1] + '</span><br />';
                    }
                    C += '<div class="clear"></div>';
                    B.innerHTML = C;
                    showObject("ecshopfx_custom_property");
                }
            }
            else if(_esPkgPriceArray[i][12].length == 0){
                hideObject("ecshopfx_custom_property");
            }
        }
    }
}
function ecShopAddToPackagePricing(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r){
    var s = (f.length>0 && e.length>0)?(f + 'ecshop_detail_' + e):"";
    var t = (f.length>0 && e.length>0)?(f + 'ecshop_zoom_' + e):"";
    _esPkgPriceArray[a] = [];
    _esPkgPriceArray[a][0] = b;
    _esPkgPriceArray[a][1] = c;
    _esPkgPriceArray[a][2] = e;
    _esPkgPriceArray[a][3] = g;
    _esPkgPriceArray[a][4] = s;
    _esPkgPriceArray[a][5] = t;
    _esPkgPriceArray[a][6] = h;
    _esPkgPriceArray[a][7] = l;
    _esPkgPriceArray[a][8] = n;
    _esPkgPriceArray[a][9] = m;
    _esPkgPriceArray[a][10] = o;
    _esPkgPriceArray[a][11] = p;
    _esPkgPriceArray[a][12] = q;
    _esPkgPriceArray[a][13] = r;
    _esManageStock = i;
    _esReOrderLvl = j;
    _esStockLwstLvl = k;
}
/* Stock available date*/
function displayStockAvailabaleDate(i){
    var a = "ecshopfx_stock_available_date";
    var b = document.getElementById(a);
    if(b){
        var c = '';
        var d = _esPkgPriceArray[i][13].split(":");
        c += '<span class="label">' + d[0] + '</span>';
        c += '<span class="value">' + d[1] + '</span>';
        b.innerHTML = c;
        showObject(a);
    }
    return;
}
/* Product images */
function ecShopShowImageViewer(a,b,c){
    var d = a + "ecshop_zoom_" + b;
    var e = a+c+b;
    var f = document.getElementById('ecshopfx_image_viewer');
    var g = document.getElementById('ecshopfx_large_image');
    if(f){
        var h = new Image();
        h.src = e;
        var i = getImageSize(e);
        f.innerHTML = '<img src="' + h.src + '"' + i[1]+i[0] + ' id="prod_image" jqimg="' + d + '" alt=""/>';
    }
    if(g){
        g.href = d;
    }
}
function ecShopAddProductImages(a,b,c,d){
    /*a - Image name, b - ecshop_detail variation image path, c - ecshop_thumb variation image path, d - ecshop_zoom variation image path,*/
    _esImgNameArray[_esImgCounter] = a;
    _esImgVersionArray[_esImgCounter] = b;
    _esImgThumbnailArray[_esImgCounter] = c;
    _esImgOrigArray[_esImgCounter] = d;
    _esImgCounter++;
}
function ecShopLoadProductImages(a){
    /*Preload all images;*/
    var b = new Image();
    var d = new Image();
    var e = new Image();
    var f = "";
    var g = "";
    var h = "";
    if(_esImgNameArray.length>0){
        for(var i=0;i<_esImgVersionArray.length;i++){
            b.src = _esImgVersionArray[i];
            d.src = _esImgOrigArray[i];
        }
        f = _esImgVersionArray[0];
        g = _esImgOrigArray[0];
        h = _esImgNameArray[0];
    }
    else if(a != undefined){
        b.src = _esPkgPriceArray[a][4];
        d.src = _esPkgPriceArray[a][5];
        f = _esPkgPriceArray[a][4];
        g = _esPkgPriceArray[a][5];
        h = _esPkgPriceArray[a][2];
    }
    var c = document.getElementById("ecshopfx_image");
    if(c){
        var j = new Image();
        j.src = f;
        var k = getImageSize(f,"1");
        var l = '<div class="image_container">';
        l += '   <div class="product_img">';
        l += '       <div class="jqzoom" id="ecshopfx_image_viewer">';
        l += '           <img jqimg="' + g + '"' + k[1]+k[0] + ' src="' + j.src + '" alt="' + h + '" />';
        l += '       </div>';
        l += '</div>';
        l += '<div class="image_options">';
        l += ecTranslate("product-labels.product-zoom-in");
        l += '   <div class="product_larger_view">';
        l += '       <a id="ecshopfx_large_image" href="' + g + '" rel="lightbox">' + ecTranslate("product-buttons.product-see-large-image") + '</a>';
        l += '   </div>';
        l += '</div></div>';
        l += '<div class="clear"></div>';
        l += '<div class="more_images" id="ecshopfx_more_images">';
        if(_esImgNameArray.length>1){
            for(var i=0;i<_esImgNameArray.length;i++){
                l += '<a href="javascript:void(0)" onclick="ecShopSwapImageInViewer(' + i + ');">';
                l += '<img class="image" src="' + _esImgThumbnailArray[i] + '" border="0" id="img_1" alt="' + _esImgNameArray[i] + '" />';
                l += '</a>';
            }
            l += '</div><div class="clear"></div><p class="ecshop_hide"></div>';
        }
        else if(a != undefined){
            if(_esPkgPriceArray[a][7].length>0 && _esPkgPriceArray[a][11] == "1"){
                l += '<div class="more_images" id="ecshopfx_more_images">';
                var m = _esPkgPriceArray[a][7].split("|");
                var n = _esPkgPriceArray[a][10].split("|");
                for(var i=0;i<m.length-1;i++){
                    l += '<a href="javascript:void(0)" onclick="ecShopSwapImageInViewer(' + a + ', ' + i + ');">';
                    l += '<img class="image" src="' + m[i] + '" border="0" id="img_1" alt="' + n[i] + '" />';
                    l += '</a>';
                }
            }
        }
        l += '</div><div class="clear"></div><p class="ecshop_hide"></div>';
        c.innerHTML = l;
        initLightbox();
    }
}
function getImageSize(a,b){
    if(b == undefined)
        b = 0;
    var c = new Image();
    var d = new Array();
    c.src = a;
    var e = c.height;
    var f = c.width;
    if(b == "1"){
        d[1] = (e>5)?' height="' + e + '"':"";
        d[0] = (f>5)?' width="' + f + '"':"";
    }
    else if(e<5 || f<5){
        if(e<5)
            d[1]=c.height>5?'height = "' + c.height + '"':"";
        if(f<5)
            d[0]=c.width>5?'width = "' + c.width + '"':"";
    }
    else{
        d[1] = 'height="' + e + '"';
        d[0] = 'width="' + f + '"';
    }
    return d;
}
function ecShopSwapImageInViewer(a,b){
    var c = document.getElementById("ecshopfx_image_viewer");
    var d = document.getElementById("ecshopfx_large_image");
    var e = "";
    var f = "";
    var g = "";
    if((b == undefined)){
        e = _esImgVersionArray[a];
        f = _esImgOrigArray[a];
        g = _esImgNameArray[a];
    }
    else{
        e = _esPkgPriceArray[a][9].split("|")[b];
        f = _esPkgPriceArray[a][8].split("|")[b];
        g = _esPkgPriceArray[a][10].split("|")[b];
    }
    if(c){
        var h = new Image();
        h.src = e;
        var i = getImageSize(e);
        var j = new Image();
        j.src = f;
        var k = '<img jqimg="' + j.src + '"' + i[0]+i[1] + 'src="' + h.src + '" alt="' + g + '" />';
        c.innerHTML = k;
    }
    if(d){
        d.href = f;
    }
}
/*Start: Functions to hide invalid combination in options*/
function ecShopGroupCombination(a,b){
    var c = a.selectedIndex;
    var d = a.options[c].value;
    var e = a.options[c].getAttribute("title");
    var f = new Array();
    var g = '';
    var h = '';
    var j = '';
    for(var i=1;i  <=  _esNoOfPackage;i++){
        var k = b.split("|");
        var l = _esPkgPriceArray[i][0].split("|");
        var m = e + ":" + d + "|";
        if(l.length == k.length){
            h = _esPkgPriceArray[i][0].replace(m,"");
            g += h;
        }
        else if(_esPkgPriceArray[i][0].indexOf(b)>-1){
            h = _esPkgPriceArray[i][0].replace(b,"");
            g += h;
        }
    }
    f[0] = h;
    f[1] = g;
    ecShopFormSelectOptions(a,f);
}
function ecShopFormSelectOptions(a,b){
    /*a - obj, b - changeBoxes*/
    var c = document.getElementById("ecshopfx_product_variations");
    var d = c.getElementsByTagName("select");
    var e = '';
    var f = '';
    var g = '';
    var h = a.getAttribute("id");
    var i = '';
    var o = b[0].split("|");
    for(var j=0;j<o.length-1;j++){
        var p = o[j].split(":");
        e += p[0] + "|";
    }
    var q = e.split("|");
    for(var k=0;k<q.length-1;k++){
        f = b[1].split('|');
        var r = '';
        for(var l=0;l<f.length;l++){
            var s = f[l].split(":");
            if(q[k] == s[0]){
                i = s[0];
                if(i == s[0] && r.indexOf(s[0])  <=  -1){
                    r += i + ":";
                }
                if(g.indexOf(s[1])  <=  -1){
                    g += s[1] + "|";
                    if(i == s[0]){
                        r += s[1] + "~";
                    }
                }
            }
        }
        for(var m=1;m  <=  d.length;m++){
            var t = h.split("_");
            var u = t[0] + "_" + t[1] + "_" + m;
            var v = document.getElementById(u);
            var w = document.getElementById(h);
            if(u != h){
                if(v && (i == v.options[v.selectedIndex].getAttribute("title"))){
                    var x = v.selectedIndex;
                    var y = v.options[x].value;
                    var z = v.options[x].getAttribute("title");
                    v.innerHTML = '';
                    var A = r.split(":");
                    var B = A[1].split("~");
                    addOption(v,"0",_esSelectboxDefaultText + " " + A[0],A[0],z,y);
                    for(var n=0;n<B.length-1;n++){
                        addOption(v,B[n],B[n],A[0],z,y);
                    }
                }
            }
        }
    }
    ecShopUpdatePackagePrice();
}
function SwapCombinations(a){
    var b = '';
    var c = a.split("|");
    for(var y=1;y<_esInitialArray.length;y++){
        for(var x=0;x<c.length;x++){
            var d = c[x].split(":");
            if(d[0] == _esInitialArray[y]){
                b += c[x] + "|";
            }
        }
    }
    return b;
}
function ecShopUpdatePackageOptions(a){
    var b = a.selectedIndex;
    var c = a.options[b].value;
    var d = a.options[b].getAttribute("title");
    if(_esPackAllVariations.length == 0){
        for(var i=1;i  <=  _esNoOfPackage;i++){
            _esPackAllVariations += _esPkgPriceArray[i][0];
        }
    }
    if(c == "0"){
        var e = "";
        var f = "";
        for(var i=1;i  <=  _esNoOfPackage;i++){
            if(_esPkgPriceArray[i][0].indexOf(d)>-1){
                var g = _esPkgPriceArray[i][0].split("|");
                for(var j=0;j<g.length;j++){
                    f = g[j].split(":");
                    if(d == f[0]){
                        if(e.indexOf(f[1])  <=  -1){
                            e += f[1] + "|";
                        }
                    }
                }
            }
        }
        var h = e.split("|");
        var k = a.getElementsByTagName("option");
        if(h.length>k.length){
            a.innerHTML = "";
            addOption(a,"0",_esSelectboxDefaultText + " " + d,d);
            for(var i=0;i<h.length-1;i++){
                addOption(a,h[i],h[i],d);
            }
        }
    }
    else{
        if(_esSelectedCombination.indexOf(d)>-1){
            var l = d + ":" + c;
            var m = _esSelectedCombination.split('|');
            for(var i=0;i<m.length;i++){
                if(m[i].indexOf(d)>-1){
                    _esSelectedCombination = _esSelectedCombination.replace(m[i],l);
                }
            }
        }
        else{
            _esSelectedCombination += d + ":" + c + "|";
        }
        _esSelectedCombination = SwapCombinations(_esSelectedCombination);
        if(_esPackAllVariations.indexOf(_esSelectedCombination)  <=  -1){
            _esSelectedCombination = d + ":" + c + "|";
        }
        ecShopGroupCombination(a,_esSelectedCombination);
    }
}
function ecshopDisplayOptions(){
    var c = document.getElementById("ecshopfx_product_variations");
    var a = c.getElementsByTagName("select");
    var b = '';
    for(var i=1;i  <=  _esNoOfPackage;i++){
        b += _esPkgPriceArray[i][0];
    }
    var d = b.split("|");
    for(var j=0;j<a.length;j++){
        var e = a[j].options[a[j].selectedIndex].getAttribute("title");
        var f = '';
        a[j].innerHTML = '';
        addOption(a[j],"0",_esSelectboxDefaultText + " " + e,e);
        for(var k=0;k<d.length;k++){
            var g = d[k].split(":");
            if(g[0].indexOf(e)>-1 && f.indexOf(g[1])  <=  -1){
                f += '<option value="' + g[1] + '" title="' + g[0] + '">' + g[1] + '</option>';
                e = g[0];
                addOption(a[j],g[1],g[1],g[0]);
            }
        }
    }
}
function getOtherSelection(a,b){
    var c = document.getElementById("ecshopfx_product_variations");
    var d = c.getElementsByTagName("select");
    for(var j=0;j<d.length;j++){
        var e = d[j].getAttribute("id");
        var f = d[j].options[d[j].selectedIndex].getAttribute("title");
        var g = d[j].options[d[j].selectedIndex].value;
        if(f != b){
            if(a.indexOf(f)  <=  -1 && g != "0"){
                a += f + ":" + g;
            }
        }
    }
    return a;
}
function addOption(a,b,c,d,e,f){
    var g = document.createElement("option");
    g.setAttribute("title",d);
    g.value = b;
    g.text = c;
    g.innerText = c;
    if(c == f && d == e){
        var h = _esSelectedCombination;
        if(h.indexOf(d)>-1){
            h = h.replace(e + ":" + f + "|",d + ":" + b + "|");
        }
        else{
            h += d + ":" + b + "|";
        }
        h = getOtherSelection(h,d);
        h = SwapCombinations(h);
        if(_esPackAllVariations.indexOf(h)>-1){
            g.setAttribute("selected","selected");
        }
    }
    a.appendChild(g);
}
/*End: Functions to hide invalid combination in options*/
/***************************************\\
//                                      \\
//       Product details ends           \\
//                                      \\
//***************************************/
/***************************************\\
//                                      \\
//       Product list starts            \\
//                                      \\
//***************************************/
function redirectPackageProducts(a,b){
    _esLastOpenedProd = a;
    var t = ecTranslate("product-labels.product-package-redirect");
    CreateUpdate(t);
    window.setTimeout("closePackagePopup('" + b + "')",2000);
}
function closePackagePopup(a){
    DeleteUpdate();
    ecShopGoToProductDetail(a);
}
function ecShopBottomPagingDisplay(a,b){
    if(a == undefined){
        a = "ecshop_bottom_paging";
    }
    if(b == undefined){
        b = "ecshop_top_paging";
    }
    var c = document.getElementById(a);
    var d = document.getElementById(b);
    if(c && d){
        c.innerHTML = d.innerHTML;
    }
}
/*** Common partial rendering starts ***/
function LoadPartialRender(){
    var r = readCookie("ecshoppartialrender" + _ecshopWebsiteId);
    if(r != null && r.length>0){
        var a = r.split("|");
        if(a.length>2){
            var b = document.location.href;
            var c = ecShopGetCurrentLang();
            var d = a[1];
            /* Check if the user changed the language of the site*/
            var e = d.indexOf("lang=");
            var f = e+5;
            var g = e+7;
            if(d.length<g){
                g = d.length;
            }
            var h = d.substring(f,g);
            if(h != c){
                d = d.replace("lang=" + h,"lang=" + c);
            }
            /*end lang check */
            var i = "";
            if(a[2].indexOf("&category_name=")>-1 || b.indexOf("&category_name=")>-1){
                var j = a[2].split("&category_name=");
                var k = b.split("&category_name=");
                i = j[0];
                b = k[0];
            }
            else{
                i = a[2];
            }
            if(b == i){
                var l = "pr_225_130_" + a[0];
                var m = document.getElementById(l);
                webSite = m.getAttribute("webSite");
                siteName = m.getAttribute("siteName");
                handlerPage = "/" + siteName+staticHandlerPath;
                tagId = l;
                var x = (a[2].indexOf("?"))?a[2].split("?")[0]+d:a[2]+d;
                getContent("",x,l,"");
            }
            else{
                createCookie("ecshoppartialrender" + _ecshopWebsiteId,"",0);
                showObject("ecshop_product_container");
            }
        }
        else{
            showObject("ecshop_product_container");
        }
    }
    else{
        showObject("ecshop_product_container");
    }
}
function PrePartialRender(a,b){
    var c = a.value;
    createCookie("ecshoppartialrender" + _ecshopWebsiteId,b + "|" + c + "|" + document.location.href,1);
}
/*This function is called in partialrender.js*/
function partialRenderLoading(){
    CreateUpdate(ecTranslate("product-messages.product-updating-list"));
}
function partialRenderLoaded(){
    DeleteUpdate();
    var a = readCookie("ecshoptable" + "_" + mod_pos +_ecshopWebsiteId);
    if(a != ""){
        oldC = document.getElementById("ecshopfx_detail_" + a);
        lineC = document.getElementById("ecshopfx_table_line_" + a);
        if(oldC){
            showObject(oldC);
            lineC.className = "line with_bkg";
        }
        _esLastOpenedProd = a;
        createCookie("ecshoptable" +"_"+ mod_pos + _ecshopWebsiteId,"",0);
        createCookie("ecshoptablenew" + _ecshopWebsiteId,"",0);        
    }
    showObject("ecshop_product_container");
    LoadCompareProducts();
}
/*** Common partial rendering ends ***/
/***************************************\\
//                                      \\
//       Product list ends              \\
//                                      \\
//***************************************/

/***************************************\\
//                                      \\
//       Common Util functions starts   \\
//                                      \\
//***************************************/
/*** ecShopAddLoadEvent()
// Adds event to window.onload without overwriting currently assigned onload functions.
// Function found at Simon Willison's weblog - http://simon.incutio.com/ ***/
function ecShopAddLoadEvent(a){
    var b = window.onload;
    if(typeof window.onload != 'function'){
        window.onload = a;
    }
    else{
        window.onload = function(){
            if(b){
                b();
            }
            a();
        }
    }
}
function ecShopGetFrameContent(a,b){
    var c = document.getElementById(a);
    if(c){
        ReplaceContent(a,b);
    }
}
function ecShopReturnHost(){
    return _ecshopHost;
}
function createCookie(a,b,c){
    if(c){
        var d = new Date();
        d.setTime(d.getTime()+(c*24*60*60*1000));
        var e = "; expires=" + d.toGMTString();
    }
    else 
        var e = "";
    document.cookie = a + "=" + b+e + "; path=/";
}
function readCookie(a){
    var b = "";
    if(document.cookie.length>0){
        cS = document.cookie.indexOf(a + "=");
        if(cS != -1){
            cS = cS+a.length+1;
            cE = document.cookie.indexOf(";",cS);
            if(cE == -1)
                cE = document.cookie.length;
            b = unescape(document.cookie.substring(cS,cE));
        }
    }
    if(b == null || b == "null")
        b = "";
    return b;
}
function HtmlEncode(a){
    return a.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
}
/*  The below function used to show the current object and hide the other series of objects 
//  For eg. if the function is called like ecShopHideAndShow(selectObj, 2), the function make the selectObj2 to the show mode 
//  and rest of objects like selectObj1, selectObj3, selectObj4, etc. will be hidden */
function ecShopHideAndShow(a,b){
    var c;
    for(var i=1;document.getElementById(a+i) != null;i++){
        c = document.getElementById(a+i);
        if(b == i){
            showObject(c);
        }
        else{
            hideObject(c);
        }
    }
}
function getSelectedValue(a){
    /*This function returns the value of the radio button checked, if nothing is checked then returns -1*/
    var b = document.getElementsByName(a);
    for(i=0;i<b.length;i++){
        if(b[i].checked)
            return b[i].value;
        }
    return-1;
}
function getSelectedObj(a){
    /*This function returns the value of the radio button checked, if nothing is checked then returns -1*/
    var b = document.getElementsByName(a);
    for(i=0;i<b.length;i++){
        if(b[i].checked)
            return b[i];
        }
    return-1;
}
function replaceBreaks(a){
    var b = /(&lt;)/g;
    var c = /(&gt;)/g;
    return a.replace(c,">").replace(b,"<");
}
function ReplaceHtml(a,b,d){
    var c = document.getElementById(a);
    if(d == undefined){
        d = 0;
    }
    if(c){
        var p = c.parentNode;
        var e = document.createElement("div");
        e.setAttribute("id","temp_replacement_" + d);
        e.style.display = "none";
        e.innerHTML = b.replace(a,a + "_temp_" + d);
        p.appendChild(e);
        var x = document.getElementById(a + "_temp_" + d);
        var f = "";
        if(x) {
            f = x.innerHTML;
            c.innerHTML = f;
            p.removeChild(e);
        } else {
            CreateError(b.replace("<!--","").replace("-->",""));
        }
    }
}
function ecShopGetStyle(a,b){
    var x = document.getElementById(a);
    if(x.currentStyle)
        var y = x.currentStyle[b];
    else if(window.getComputedStyle)
        var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(b);
    return y;
}
/*For Captcha image verification in forms*/
function LoadCaptcha(){
    ecShop.Web.Soap.ecShopWS.GetCaptcha(OnSuccessCaptcha,OnError);
}
function OnSuccessCaptcha(r){
    var a = r[0];
    var b = r[1];
    var c = r[2];
    var d = document.getElementById("captchaimg");
    if(d){
        d.src = c + '/upload/files/templates/controls/CaptchaImage.aspx?height=100&width=200&text=' + a;
        document.getElementById("captchahash").value = b;
    }
}
/*For web services*/
function OnError(a){
    if(a.get_message().indexOf("ecshop-error:")>-1){
        var b = a.get_message().replace("ecshop-error:","");
        CreateError(ecTranslate(b));
    }
    else{
        CreateError(a.get_message());
    }
    DeleteUpdate();
}
/*word needs to be label.name*/
function ecTranslate(a){
    var b = readCookie(_esLangCookie);
    if(b == "" || b == null)
        b = _ecshopDefaultLang;
        
    /*_ecTranslate is a function from the ecWeb translation module js file
    //This file needs to be added to the area templates
    //Location: /webpages/templates/translation/js/translation.js*/
    try{
        return _ecTranslate(a + "." + b);
    }
    catch(err){
        return a + "[JSERR]";
    }
}
function ecShopGetCurrentLang(){
    var a = readCookie(_esLangCookie);
    if(a == "" || a == null)
        a = _ecshopDefaultLang;
    return a;
}
function disable(a){
    hideObject(a);
}
function enable(a){
    showObject(a);
}
function ReplaceContent(a,b){
    var c = document.getElementById(a);
    if(c != null){
        c.innerHTML = b;
    }
}
function trim(a){
    return a.replace(/^\s*|\s*$/g,"");
}
/*** Common popups ***/
var _zIndex = 500;
function createPopup(a,b,d){
    var c = document.getElementById("ecshop-hover_" + d);
    if(c == null){
        c = document.createElement("div");
    }
    else{
        c.innerHTML = "";
    }
    c.className = "ecshop_hover_window";
    c.setAttribute("id","ecshop-hover_" + d);
    c.style.zIndex = _zIndex++;
    var e = document.createElement("div");
    e.className = "ecshop_hover_content " + b;
    e.setAttribute("id","ecshop-content_" + d);
    var f = document.createElement("div");
    f.className = "ecshop_hover_close";
    f.innerHTML = '<a href="javascript:removePopup(\'' + d + '\')" class="img_replace" title="' + _esClose + '"><span>' + _esClose + '</span></a>';
    var g = document.createElement("div");
    g.innerHTML = a;
    e.appendChild(g);
    e.appendChild(f);
    c.appendChild(e);
    var p = document.body;
    p.insertBefore(c,p.firstChild);
}
function removePopup(a){
    var b = document.getElementById("ecshop-hover_" + a);
    if(b){
        b.parentNode.removeChild(b);
    }
    var c = document.getElementById('ecshopfx_container_step3');
    if(c && c.className != 'ecshop_hide')
        try{
            enableElements(c)
        }
        catch(err){}
}
function enableElements(a){
    if(a.disabled == undefined){
        a.disabled = false;
    }
    try{
        if(a.disabled == true)
            a.disabled = false;
    }
    catch(E){}
    if(a.childNodes && a.childNodes.length>0){
        for(var x=0;x<a.childNodes.length;x++){
            enableElements(a.childNodes[x]);
        }
    }
}
function disableElements(a){
    if(a.disabled == undefined){
        a.disabled = false;
    }
    try{
        if(a.disabled == false)
            a.disabled = true;
    }
    catch(E){}
    if(a.childNodes && a.childNodes.length>0){
        for(var x=0;x<a.childNodes.length;x++){
            disableElements(a.childNodes[x]);
        }
    }
}
function toggleDisabled(a){
    if(a.disabled == undefined){
        a.disabled = false;
    }
    try{
        a.disabled = (a.disabled)?false:true;
    }
    catch(E){}
    if(a.childNodes && a.childNodes.length>0){
        for(var x=0;x<a.childNodes.length;x++){
            toggleDisabled(a.childNodes[x]);
        }
    }
}
/*Common confirmations/messages/errors to the user*/
function CreateError(a){
    var b = '<h2>' + ecTranslate("common-headings.common-error") + '</h2><p>' + a + '</p>';
    createPopup(b,"ecshop_error","ecshoperror");
    var c = document.getElementById('ecshopfx_container_step3');
    if(c && c.className != 'ecshop_hide')
        try{
            disableElements(c);
        }
        catch(err){}
}
function CreateConfirmation(a,b,c){
    var d = '<h2>' + a + '</h2>' + b;
    createPopup(d,"ecshop_confirmation",c);
}
function CreateMessage(a,b,c){
    var d = '<h2>' + a + '</h2><p>' + b + '</p>';
    createPopup(d,"ecshop_message",c);
    /*automatically fade away*/
    setTimeout("FadeItem('ecshop-content_" + c + "','out',1000)",3000,true);
    /*remove popup when faded*/
    setTimeout("removePopup('" + c + "')",5000);
}
function FadeItem(a,b,c,d){
    if(c == undefined)
        c = 1000;
    if(b == undefined)
        b = "out";
    if(b == "in"){
        $("#" + a).fadeIn(c);
    }
    else if(b == "out"){
        $("#" + a).fadeOut(c);
    }
}

/* Create / Delete update 
// Used when creating small process/update notifications to the user to let them know that there's a process going on.*/

/*** Examples: 
// - When adding or removing from the basket
// - Creating or editing an address
// - Searching for products ***/
function CreateUpdate(a){
    var b = '<p>' + a + '</p>';
    createPopup(b,"ecshop_update","ecshop_update");
}
function DeleteUpdate(){
    removePopup("ecshop_update");
}
function showObject(a){
    var b = null;
    if(typeof(a) == "string"){
        b = document.getElementById(a);
    }
    else{
        b = a;
    }
    if(b){
        if(b.className.indexOf(" ecshop_hide")>-1){
            b.className = b.className.replace(" ecshop_hide","");
        }
        else if(b.className.indexOf("ecshop_hide")>-1){
            b.className = b.className.replace("ecshop_hide","");
        }
        else if(b.className.indexOf(" ecshop_obscure")>-1){
            b.className = b.className.replace(" ecshop_obscure","");
        }
        else if(b.className.indexOf("ecshop_obscure")>-1){
            b.className = b.className.replace("ecshop_obscure","");
        }
        if(b.style.display == 'none'){
            b.style.display = '';
        }
        if(b.style.visibility == 'hidden'){
            b.style.visibility = '';
        }
    }
}
function obscureObject(a){
    var b = null;
    if(typeof(a) == "string"){
        b = document.getElementById(a);
    }
    else{
        b = a;
    }
    if(b){
        if(b.className.indexOf("ecshop_obscure") == -1){
            if(b.className.length>0){
                b.className += " ecshop_obscure";
            }
            else{
                b.className = "ecshop_obscure";
            }
        }
    }
}
function hideObject(a){
    var b = null;
    if(typeof(a) == "string"){
        b = document.getElementById(a);
    }
    else{
        b = a;
    }
    if(b){
        if(b.className.indexOf("ecshop_hide") == -1){
            if(b.className.length>0){
                b.className += " ecshop_hide";
            }
            else{
                b.className = "ecshop_hide";
            }
        }
    }
}
function deleteObject(a){
    var b = document.getElementById(a);
    if(b){
        var c = b.parentNode;
        if(c){
            b.parentNode.removeChild(b);
        }
    }
}
function toggleObject(a){
    var b = document.getElementById(a);
    if(b){
        if(b.className.indexOf("ecshop_hide") == -1){
            hideObject(a);
        }
        else{
            showObject(a);
        }
    }
}
function overwriteInnerHTML(a,b,c){
    if(a){
        if(a.innerHTML.indexOf(b)>-1){
            a.innerHTML = c;
        }
        else{
            a.innerHTML = b;
        }
    }
}
function printContent(a){
    var b = "toolbar=yes,location=no,directories=yes,menubar=yes,scrollbars=yes,height=800,width=800;top=100";
    var c = window.open("","",b);
    c.document.open();
    c.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xmlns:asp><head><title>PrintInvoice</title>');
    c.document.write('<link href="' + ecShopReturnHost() + '/webpages/templates/css/global.css" media="all" rel="stylesheet" type="text/css">');
    c.document.write('<link href="' + ecShopReturnHost() + '/webpages/templates/css/webshop.css" media="all" rel="stylesheet" type="text/css" />');
    c.document.write('<link href="' + ecShopReturnHost() + '/webpages/templates/css/font.css" media="all" rel="stylesheet" type="text/css" />');
    c.document.write('</head><body id="print" onload="window.print()">');
    c.document.write(a);
    c.document.write('</body></html>');
    c.document.close();
    c.focus();
}
/* Main function to retrieve mouse x-y pos.s*/
function ecShopCaptureMouse(e){
    if(!document.all){
        _esTempX = e.pageX; 
        _esTempY = e.pageY;
    }
}
function ecShopCaptureHistory(e){
    /* grab the x-y pos.s if browser is IE*/
    if(document.all){
        _esTempX = event.clientX;
        _esTempY = event.clientY;
    }
    if(_esTempY<1){
        return ecTranslate("checkout-errors.checkout-navigate-back");
    }
}
/***************************************\\
//                                      \\
//       Common Util functions ends     \\
//                                      \\
//***************************************/


/***************************************\\
//                                      \\
// Account - Address management starts  \\
//                                      \\
//***************************************/
/* Count and List Address */
function ecShopAccountLoadAddress() {
    ecShopGetAddresses(_esPageType, _esAccUser, 'ecshopfx_address_list');
}

/*Get all address starts*/
function ecShopGetAddresses(a,b,c,d){
    /*a - pageType, b - userId, c - addressContainer, d - webshop (to identify location - webshop page or account page)*/
    if(d == undefined)
        d = false;
    _esPageType = a;
    _esAccUser = b;
    _esAddrContainer = c;
    _esGetWebshop = d;
    /* Display message if user is not logged in*/
    if(b  ==  0 || b  ==  null){
        document.getElementById(c).innerHTML = ecTranslate("account-labels.account-order-message-anonymoususer");
    }
    /*For registered users*/
    else if(b != null){
        CreateUpdate(ecTranslate("account-labels.account-address-loading"));
        
        var g = new SOAPObject("GetAllAddress");
		g.ns = "http://tempuri.org/";
		g.appendChild(new SOAPObject("userId")).val(_esAccUser);			
       
   	    //Create a new SOAP Request
		var sr = new SOAPRequest("http://tempuri.org/GetAllAddress", g); //Request is now ready to be sent to a web-service
		sr.addNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
		sr.addNamespace("xsd","http://www.w3.org/2001/XMLSchema");

        //Lets send it
		SOAPClient.Proxy = ecShopReturnHost() + "/editor/soap/registeredUsers.asmx"; //Specify web-service address (if local to your domain) or a proxy file
		SOAPClient.SOAPServer = ecShopReturnHost() + "/editor/soap/registeredUsers.asmx";
		SOAPClient.SendRequest(sr, OnListAddresses); //Send request to server and assign callback function
    }
}

function OnListAddresses(rO){
    /*rO - Response object from GetAllAddress webservice*/
    /*r - Read HTML after transforming xml to xslt from the response object*/
    var r = rO.Body[0].GetAllAddressResponse[0].GetAllAddressResult[0].Text;
    /*If there is address - then load address*/
    if(r.length>0){
        ReplaceContent(_esAddrContainer,r);
    }
    /*If response is null - then load option to add address*/
    else if(r.length  ==  0){
        var a = '<div class="ecshop_form_container" id="ecshop_form_container">';
        a += '<h3>' + ecTranslate("account-headings.account-address-create") + '</h3>';
        a += '<button class="ecshop_send" value="add_address" onclick="addAddress(\'' + _esAccUser + '\')">' + ecTranslate("account-buttons.account-address-create") + '</button>';
        a += '</div><div class="clear"></div>';
        ReplaceContent(_esAddrContainer,a);
    }
    DeleteUpdate();
    if(_esGetWebshop){
        /*To maintain the old selection, if any */
        ecShopLoadStep1Registered();
        _esGetWebshop = false;
    }
}
/*Get all address ends*/

/*Get Address detail Form starts*/
function ecShopAddAddress() {                            
    ecShopGetAddressForm();
}
function ecShopGetAddressForm(){
    if(_esAddrFormat != null){
        OnAddressForm(_esAddrFormat);
    }
    else{
        OnAddressForm();
    }
}

function OnAddressForm(){
    var a = new SOAPObject("GetAddressdetailForm");
	a.ns = "http://tempuri.org/";
	a.appendChild(new SOAPObject("userID")).val(_esAccUser);       
    //Create a new SOAP Request
	var sr = new SOAPRequest("http://tempuri.org/GetAddressdetailForm", a); //Request is now ready to be sent to a web-service
	sr.addNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
	sr.addNamespace("xsd","http://www.w3.org/2001/XMLSchema");
	

    //Lets send it
	SOAPClient.Proxy = ecShopReturnHost() + "/editor/soap/registeredUsers.asmx"; //Specify web-service address (if local to your domain) or a proxy file
	SOAPClient.SOAPServer = ecShopReturnHost() + "/editor/soap/registeredUsers.asmx";
	SOAPClient.SendRequest(sr, GetAddressdetailFormResponse); //Send request to server and assign callback function

    function GetAddressdetailFormResponse(rO,b,c)
    {   
        var u = document.location.href;
        var r = rO.Body[0].GetAddressdetailFormResponse[0].GetAddressdetailFormResult[0].root[0];
        var f = r.htmldata[0].Text;

        createPopup(f,"ecshop_create-address","create-address"); 
    }
}
/*Get Address detail Form ends*/

/*Create address - starts*/
function ecShopCreateAddress(){
    var a = document.getElementById("ecshop_address_form");
    var b = a.getElementsByTagName("input");
    var c = "<root>"; /*Form address XML*/
    var e = 0; /*Is primary*/
    
    for(var i = 0; i < b.length; i++) {
    	c += "<info><id>" + b[i].getAttribute("id")+ "</id><name>" + b[i].name  + "</name><value>"+b[i].value +"</value><order>"+b[i].getAttribute("order")+"</order><linebreak>"+b[i].getAttribute("linebreak")+"</linebreak><validation>"+b[i].getAttribute("validation")+"</validation><xmlnode>"+b[i].getAttribute("xml")+"</xmlnode></info>";    
    }
    c += "</root>";
    
    if(validateForm("ecshop_address_form")){
        removePopup("create-address");
        CreateUpdate(ecTranslate("account-labels.account-address-saving"));
        c = c.replace(/</g,'&lt;').replace(/>/g,'&gt;');
		var d = new SOAPObject("CreateAddress");
		d.ns = "http://tempuri.org/";
		d.appendChild(new SOAPObject("userId")).val(_esAccUser);
		d.appendChild(new SOAPObject("addressinfo")).val(c);
		d.appendChild(new SOAPObject("isPrimary")).val(e);
	
        //Create a new SOAP Request
		var sr = new SOAPRequest("http://tempuri.org/CreateAddress", d); //Request is now ready to be sent to a web-service
		sr.addNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
		sr.addNamespace("xsd","http://www.w3.org/2001/XMLSchema");
		
        //Lets send it
		SOAPClient.Proxy = ecShopReturnHost() + "/editor/soap/registeredUsers.asmx"; //Specify web-service address (if local to your domain) or a proxy file
		SOAPClient.SOAPServer = ecShopReturnHost() + "/editor/soap/registeredUsers.asmx";
		SOAPClient.SendRequest(sr, CreateAddressResponse); //Send request to server and assign callback function
    }
}

function CreateAddressResponse(r){
    /*r - Response from CreateAddress webservice*/
    /*Load address in account*/
	ecShopAccountLoadAddress();
	/*Update added address in webpage*/
	OnListAddresses(r);
}
/*Create address - ends*/

/*Edit Address - starts*/
function ecShopShowAddress(a){
    var b = new SOAPObject("EditAddress");
	b.ns = "http://tempuri.org/";
	b.appendChild(new SOAPObject("addressId")).val(a);
   
    //Create a new SOAP Request
	var sr = new SOAPRequest("http://tempuri.org/EditAddress", b); //Request is now ready to be sent to a web-service
	sr.addNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
	sr.addNamespace("xsd","http://www.w3.org/2001/XMLSchema");
	
    //Lets send it
	SOAPClient.Proxy = ecShopReturnHost() + "/editor/soap/registeredUsers.asmx"; //Specify web-service address (if local to your domain) or a proxy file
	SOAPClient.SOAPServer = ecShopReturnHost() + "/editor/soap/registeredUsers.asmx";
	SOAPClient.SendRequest(sr, EditAddressResponse); //Send request to server and assign callback function	
}

function EditAddressResponse(r)
{ 
    var a = r.Body[0].EditAddressResponse[0].EditAddressResult[0].Text;
    if(a != "") {    
        createPopup(a,"ecshop_create-address","edit-address");          
    }
    ecShopAccountLoadAddress();
    OnListAddresses(respObj);
}

/*Edit Address - ends*/

/*Update Address - starts*/



function ecShopUpdateAddress(a) {
	var b = document.getElementById("ecshop_address_form");     
	var c = b.getElementsByTagName("input"); 
	var d = "<root>"; /*Form address XML*/
    for(var i = 0; i < c.length; i++) {
    	d += "<info><id>" + c[i].getAttribute("id")+ "</id><name>" + c[i].name  + "</name><value>"+c[i].value +"</value><order>"+c[i].getAttribute("order")+"</order><linebreak>"+c[i].getAttribute("linebreak")+"</linebreak><validation>"+c[i].getAttribute("validation")+"</validation><xmlnode>"+c[i].getAttribute("xml")+"</xmlnode></info>";    
    }
    d += "</root>";
    d = d.replace(/</g,'&lt;').replace(/>/g,'&gt;');

	var f = new SOAPObject("UpdateAddress");
	f.ns = "http://tempuri.org/";
	f.appendChild(new SOAPObject("addressId")).val(a);
	f.appendChild(new SOAPObject("addressinfo")).val(d);
       
    //Create a new SOAP Request
    var sr = new SOAPRequest("http://tempuri.org/UpdateAddress", f); //Request is now ready to be sent to a web-service
    sr.addNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
    sr.addNamespace("xsd","http://www.w3.org/2001/XMLSchema");
       
    //Lets send it
    SOAPClient.Proxy = ecShopReturnHost() + "/editor/soap/registeredUsers.asmx"; //Specify web-service address (if local to your domain) or a proxy file
    SOAPClient.SOAPServer = ecShopReturnHost() + "/editor/soap/registeredUsers.asmx";
    SOAPClient.SendRequest(sr, UpdateAddressResponse); //Send request to server and assign callback function
    
    function UpdateAddressResponse()
    {
	    ecShopAccountLoadAddress();
	    removePopup("edit-address");		
    }
}
/*Update Address - ends*/

/*Delete Address - starts*/
function ecShopDeleteAddress(a){
    var b = '<div class="ecshop_form_container">';
    b += '<p>' + ecTranslate("account-labels.account-address-delete") + '</p>';
    b += '<div class="buttons"><button onclick="ecShopDoDeleteAddress(\'' + a + '\')" class="ecshop_send">' + _esOkBtn + '</button>';
    b += '<button onclick="removePopup(\'confirm-delete\')" class="ecshop_cancel">' + _esCancelBtn + '<br/><span>' + _esClose + '</span></button></div>';
    b += '<div class="clear"></div></div>';
    CreateConfirmation(ecTranslate("account-headings.account-address-delete"),b,"confirm-delete");
}
function ecShopDoDeleteAddress(a){
    removePopup("confirm-delete");
    var b = new SOAPObject("DeleteAddress");
	b .ns = "http://tempuri.org/";
	b .appendChild(new SOAPObject("addressId")).val(a);       

    //Create a new SOAP Request
	var sr = new SOAPRequest("http://tempuri.org/DeleteAddress", b); //Request is now ready to be sent to a web-service
	sr.addNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
	sr.addNamespace("xsd","http://www.w3.org/2001/XMLSchema");

    //Lets send it
	SOAPClient.Proxy = ecShopReturnHost() + "/editor/soap/registeredUsers.asmx"; //Specify web-service address (if local to your domain) or a proxy file
	SOAPClient.SOAPServer = ecShopReturnHost() + "/editor/soap/registeredUsers.asmx";
	SOAPClient.SendRequest(sr, DeleteAddressResponse); //Send request to server and assign callback function

	CreateMessage(ecTranslate("common-headings.common-success"), ecTranslate("account-labels.account-address-deleted"),"deleteaddress_message");  
	window.setTimeout("removePopup('deleteaddress_message')",1000); 
}

function DeleteAddressResponse(r){
    ecShopAccountLoadAddress();
    OnListAddresses(r);
}
/*Delete Address - ends*/

/*Used in checkout process - starts*/
function ecShopGetAddressFormatArray(){
    if(!_esGettingFormat){
        _esGettingFormat = true;
        
        /**** Dont remove this commented code - The below webservice can be used only when we add ScriptReference in area template for checkout process ****/

        /*var a = new SOAPObject("GetAddressFormatArray");
		a.ns = "http://tempuri.org/";     

   	    //Create a new SOAP Request
	    var sr = new SOAPRequest("http://tempuri.org/GetAddressFormatArray", a); //Request is now ready to be sent to a web-service
		sr.addNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
		sr.addNamespace("xsd","http://www.w3.org/2001/XMLSchema");

        //Lets send it
		SOAPClient.Proxy = ecShopReturnHost() + "/editor/soap/registeredUsers.asmx"; //Specify web-service address (if local to your domain) or a proxy file
		SOAPClient.SOAPServer = ecShopReturnHost() + "/editor/soap/registeredUsers.asmx";
		SOAPClient.SendRequest(sr, GetAddressFormatArrayResponse); //Send request to server and assign callback function
        */
        ecWeb.Web.SOAP.registeredUsers.GetAddressFormatArray(GetAddressFormatArrayResponse, OnError);
    }
}

function GetAddressFormatArrayResponse(r) {
    _esAddrFormat = r;
    _esGettingFormat = false;
}
/*Used in checkout process - ends*/

/***************************************\\
//                                      \\
// Account - Address management ends    \\
//                                      \\
//***************************************/

/***************************************\\
//                                      \\
//   Account - Order history starts     \\
//                                      \\
//***************************************/
function ecShopFilterOrder(a,b,c,d,e,f){
    var g = b.selectedIndex;
    var h = b.options[g].value;
    var i = "";
    if(h  ==  c){
        CreateError(ecTranslate("account-labels.account-order-filter-alert"));
    }
    else if(h  ==  d){
        CreateUpdate(ecTranslate("account-messages.account-updating-the-orderlist"));
        ecShopFilter(a,l,2);
    }
    else if(h  ==  e){
        CreateUpdate(ecTranslate("account-messages.account-updating-the-orderlist"));
        var j = new Date();
        var k = new Date(j.getTime()-(14*24*60*60*1000));
        i = k.getMonth()+1;
        var l = k.getFullYear().toString()+(i<10?"0" + i.toString():i.toString())+(k.getDate()<10?"0" + k.getDate().toString():k.getDate().toString());
        ecShopFilter(a,l,1);
    }
    else if(h  ==  f){
        CreateUpdate(ecTranslate("account-messages.account-updating-the-orderlist"));
        var j = new Date();
        var k = new Date(j.getTime()-(182*24*60*60*1000));
        i = k.getMonth()+1;
        var l = k.getFullYear().toString()+(i<10?"0" + i.toString():i.toString())+(k.getDate()<10?"0" + k.getDate().toString():k.getDate().toString());
        ecShopFilter(a,l,1);
    }
    else{
        CreateUpdate(ecTranslate("account-messages.account-updating-the-orderlist"));
        ecShopFilter(a,h,0);
    }
}
function ecShopFilter(a,b,c){
    for(var i=0;i<a.rows.length;i++){
        var d = a.rows[i].getElementsByTagName('td');
        if(c  ==  0 && d[c].innerHTML != b){
            hideObject(a.rows[i]);
        }
        else if(c  ==  1 && d[c].innerHTML<b){
            hideObject(a.rows[i]);
        }
        else{
            showObject(a.rows[i]);
        }
    }
    setTimeout("DeleteUpdate()",2000);
}
function ecShopPrintOrderhistory(a){
    var b = document.getElementById(a).innerHTML;
    var c = '';
    c += '<div class="site_container"><div id="content_container"><div id="ecshop_product_container" class="account_view">' + b + '</div></div></div>';
    printContent(c);
}
/***************************************\\
//                                      \\
//   Account - Order history ends       \\
//                                      \\
//***************************************/
/***************************************\\
//                                      \\
//         Validation starts            \\
//                                      \\
//***************************************/
function validateForm(a){
    var b = document.getElementById(a);
    var c = b.getElementsByTagName("input");
    var d = b.getElementsByTagName("textarea");
    var e = b.getElementsByTagName("select");
    var f = validateElements(c);
    var g = validateElements(d);
    var h = validateElements(e);
    return(f && g && h);
}
function validateElements(a){
    var b = true;
    var c = (ecTranslate("common-labels.common-form-validate-ismissing").length>0)?ecTranslate("common-labels.common-form-validate-ismissing"):"";
    var d = (ecTranslate("common-labels.common-form-validate-passwordmismatch").length>0)?ecTranslate("common-labels.common-form-validate-passwordmismatch"):"";
    var e = (ecTranslate("common-labels.common-form-validate-notvalid").length>0)?ecTranslate("common-labels.common-form-validate-notvalid"):"";
    var f = (ecTranslate("common-labels.common-form-validate-ccexpired").length>0)?ecTranslate("common-labels.common-form-validate-ccexpired"):"";
    var g = (ecTranslate("common-labels.common-form-validate-singlechar").length>0)?ecTranslate("common-labels.common-form-validate-singlechar"):"";
    var h = (ecTranslate("common-labels.common-form-validate-sixchar").length>0)?ecTranslate("common-labels.common-form-validate-sixchar"):"";
    for(var i=0;i<a.length;i++){
        var j = a[i];
        var k = j.parentNode;
        var l;
        var m;
        var n;
        var o = (j.className.indexOf("email")>-1 && !validateEmail(j.value));
        var p = (j.className.indexOf("alphabet")>-1 && !validateAlphabet(j.value));
        var q = (j.className.indexOf("alphanumeric")>-1 && !validateAlphaNumerics(j.value));
        var r = (j.className.indexOf("number")>-1 && !validateNumerics(j.value));
        var s = (j.className.indexOf("cvc")>-1 && !validateCVCNumber(j.value));
        var t = (j.className.indexOf("ccn")>-1 && !validateCreditCardNumber(j.value));
        var u = (j.className.indexOf("cexp")>-1 && !validateCCExpires(j.value,j.className));
        var v = (j.className.indexOf("ssn")>-1 && !validateSSN(j.value));
        var w = (j.className.indexOf("cmail_")>-1 && !validateEmailConfirm(j.value,j.className));
        var x = (j.className.indexOf("password_")>-1 && !validatePassword(j.value,j.className));
        var y = (j.className.indexOf("select")>-1 && !validateSelect(j));
        var z = (j.className.indexOf("single")>-1 && !validateSingle(j.value));
        var A = (j.className.indexOf("phone")>-1 && !validatePhone(j.value));
        
        /*Validate mandatory fields*/
        if(j.className.indexOf("validate")>-1 || j.className.indexOf("required")>-1){
            j.className = j.className.replace("required","validate");
            l = k.getElementsByTagName("label")[0];
            if(l != null){
                var B = (l.getAttribute("orig") != null && l.getAttribute("orig") != "")?l.getAttribute("orig"):l.innerHTML;
                l.innerHTML = B;
                l.className = l.className.replace(" error","").replace("error","");
            }
            if(trim(j.value)  ==  "" || o || v || x || w || s || t || u || y || p || q || r || z || A){
                b = false;
                j.className = j.className.replace("validate","required");
                l = k.getElementsByTagName("label")[0];
                if(l){
                    var B = (l.getAttribute("orig") != null && l.getAttribute("orig") != "")?l.getAttribute("orig"):l.innerHTML;
                    var C = "";
                    l.setAttribute("orig",B);
                    if(trim(j.value)  ==  ""){
                        C = B.replace(" *","") + " " + c;
                    }
                    else if(x || w){
                        C = d;
                    }
                    else if(t || s || o || v || p || q || r){
                        C = B.replace(" *","") + " " + e;
                    }
                    else if(u){
                        C = f;
                    }
                    else if(A){
                        C = B.replace(" *","") + " " + h;
                    }
                    else if(z){
                        C = B.replace(" *","") + " " + g;
                    }
                    else if(y){
                        C = B.replace(" *","") + " " + c;
                    }
                    l.innerHTML = C;
                    if(l.className  ==  ""){
                        l.className = "error";
                    }
                    else{
                        l.className += " error";
                    }
                }
            }
        }
        /*Validate optional fields if they are filled in*/
        else if((j.className.indexOf("optional")>-1 || j.className.indexOf("incorrect")>-1) && trim(j.value) != ""){
            j.className = j.className.replace("incorrect","optional");
            l = k.getElementsByTagName("label")[0];
            if(l){
                var B = (l.getAttribute("orig") != null && l.getAttribute("orig") != "")?l.getAttribute("orig"):l.innerHTML;
                l.innerHTML = B;
                l.className = l.className.replace(" error","").replace("error","");
                if(o || v || x || w || s || t || u || p || q || r || z || A){
                    b = false;
                    j.className = j.className.replace("optional","incorrect");
                    l = k.getElementsByTagName("label")[0];
                    B = (l.getAttribute("orig") != null && l.getAttribute("orig") != "")?l.getAttribute("orig"):l.innerHTML;
                    C = "";
                    l.setAttribute("orig",B);
                    if(e  ==  ""){
                        e = c;
                    }
                    if(v || t || s || p || q || r){
                        C = B.replace(" *","") + " " + e;
                    }
                    else if(u){
                        C = f;
                    }
                    else if(z){
                        C = B.replace(" *","") + " " + g;
                    }
                    else if(A){
                        C = B.replace(" *","") + " " + h;
                    }
                    else{
                        C = B.replace(" *","") + " " + c;
                    }
                    l.innerHTML = C;
                    if(l.className  ==  ""){
                        l.className = "error";
                    }
                    else{
                        l.className += " error";
                    }
                }
            }
        }
    }
    return b;
}
function validateSingle(a){
    if(a.length>1)
        return true;
    else 
        return false;
}
function validatePhone(a){
    if(a.length>6)
        return true;
    else 
        return false;
}
function validateSelect(a){
    if(a.options[a.selectedIndex].value  ==  '0')
        return false;
    return true;
}
function validateName(a){
    var b = new RegExp("[\\[\\]{}%*`~^$#@&()| != (0-9)]","gi");
    if(b.test(a))
        return false;
    return true;
}
function validatePassword(a,b){
    var c = b.replace("validate ","");
    var d = c.replace("required ","");
    var e = document.getElementById(d.replace("password_","")).value;
    if(a != e)
        return false;
    else 
        return true;
}
function validateSSN(a){
    var b = /[0-9]/g;
    if(a.length != 10){
        return false;
    }
    else{
        if(b.test(a)){
            return true;
        }
        else{
            return false;
        }
    }
}
function validateEmail(a){
    var b = /([a-zA-Z0-9_-])+(\.{0,1})+([a-zA-Z0-9_-])+([\.][a-zA-Z0-9_-]+){0,1}@{1}([a-zA-Z0-9_-])+(\.{1})+([a-zA-Z0-9]{0,4})+(\.{0,1})+[a-zA-Z]{2,4}$/;
    if(b.test(a)){
        return true;
    }
    else{
        return false;
    }
}
function validateEmailConfirm(a,b){
    var c = b.replace("validate ","");
    var d = c.replace("required ","");
    var e = document.getElementById(d.replace("cmail_","")).value;
    if(a != e)
        return false;
    else return true;
}
function validateNumerics(a){
    var b = /^-{0,1}\d+$/;
    if(b.test(a)){
        return true;
    }
    else{
        return false;
    }
}
function validateAlphaNumerics(a){
    var b = /[a-z0-9]/g;
    if(b.test(a)){
        return true;
    }
    else{
        return false;
    }
}
function validateAlphabet(a){
    var b = /[a-z]/g;
    if(b.test(a)){
        return true;
    }
    else{
        return false;
    }
}
function validateNumber(a){
    var b = /[^0-9]/g;
    var c = a.value;
    a.value = c.replace(b,'');
}
function validateCreditCardNumber(b){
    var c = "0123456789";
    var d = "";
    for(var i=0;i<b.length;i++){
        Temp = b.charAt(i);
        if(c.indexOf(Temp,0) != -1){
            d += Temp;
        }
    }
    var e = d.length/2;
    if(e<6.5 || e>8 || e  ==  7)
        return false;
    var f = Math.floor(e);
    var g = Math.ceil(e)-f;
    var h = 0;
    for(var i=0;i<f;i++){
        a = d.charAt(i*2+g)*2;h += a>9?Math.floor(a/10+a%10):a;
    }
    for(var i=0;i<f+g;i++){
        h += d.charAt(i*2+1-g)*1;
    }
    return(h%10  ==  0);
    return false;
}
function validateCVCNumber(a){
    var b=/^\d{3}$/;
    if(a.length>3){
        return false;
    }
    else if(a.length<3){
        return false;
    }
    else if(a.search(b)  ==  -1){
        return false;
    }
    else{
        return true;
    }
}
/*Checks if the credit card has expired or not*/
function validateCCExpires(a,b){
    var c = b.replace("validate ","").replace("required ","").replace("cexp_","");
    var d = document.getElementById(c);
    var e = d.options[d.selectedIndex].text;
    var f = new Date();
    var g = (f.getMonth()+1);
    var h = f.getFullYear();
    if(a.substring(0,1)  ==  0){
        a = a.substring(1,2);
    }
    if(h<e){
        return true;
    }
    else if(h  ==  e && g  <=  a){
        return true;
    }
    else{
        return false;
    }
}
/*Converts an optional field to a mandatory field*/
function makeMandatory(a,b){
    var c = document.getElementById(a);
    c.className = b;
    var d = c.parentNode.getElementsByTagName("label")[0];
    if(d != null){
        if(d.innerHTML.indexOf("*")<0){
            d.innerHTML = d.innerHTML + " *";
        }
    }
}
/*Converts a mandatory field to an optional field*/
function makeOptional(a){
    var b = document.getElementById(a);
    var c = b.parentNode;
    b.className = "";
    var d = c.getElementsByTagName("label")[0];
    if(d != null){
        d.innerHTML = d.innerHTML.replace(" *","");
    }
    if(c.getElementsByTagName("small").length>0){
        var e = c.getElementsByTagName("small")[0];
        c.removeChild(e);
    }
}
/*Limit the number of characters in a text area */
function limitCharacters(a,b){
    var c = a.value;
    if(c.length>b){
        a.value = text.substring(0,b);
    }
}
/*Clear a form on cancel*/
function clearForm(a){
    var b = document.getElementById(a);
    var c = b.getElementsByTagName("input");
    for(var i=0;i<c.length;i++){
        var d = c[i];
        if(d.type  ==  "text" || d.type  ==  "hidden" || d.type  ==  "password"){
            d.value = "";
        }
        else if(d.type  ==  "checkbox"){
            d.checked = false;
        }
    }
}
/***************************************\\
//                                      \\
//         Validation ends              \\
//                                      \\
//***************************************/
 

/***************************************\\
//                                      \\
//         Breadcrumb starts            \\
//                                      \\
//***************************************/
/*Breadcrumbs - merge webtree and product category*/
function ecShopAddToBreadCrumbs(a,b,c,d,e){
    _esBreadCrumbContainer = a;
    if(d){
        _esBreadCrumbs += '<span class="location">' + b + '</span>';
    }
    else{
        _esBreadCrumbs += '<a href="' + c + '">' + b + '</a><span class="sep"> / </span>';
    }
}
function ecShopLoadBreadCrumbs(){
    var c = document.getElementById(_esBreadCrumbContainer);
    if(c){
        c.innerHTML += _esBreadCrumbs;
    }
    ecShopChangePageTitle();
}
//Change the page title to the 
function ecShopChangePageTitle(){
    var a = document.all;
    var b = document.getElementById("breadcrumb_container");
    var c = (_esLastPage.length>0)?_esLastPage + " - ":"";
    if(b){
        if(a){
            document.title = c+ecShopReverseBreadcrumbs(b.innerText);
        }
        else{
            document.title = "Vistor.is "+b.textContent.substring(b.textContent.indexOf(':'),b.textContent.length);//document.title = c+ecShopReverseBreadcrumbs(b.textContent);
        }
    }
}
function ecShopReverseBreadcrumbs(a){
    var b = a.split(" > ");
    var c = "";
    for(var i=b.length-1;i >= 0;i--){
        if(b[i] != ""){
            c += b[i];
            if(i>0){
                c += " - ";
            }
        }
    }
    return c;
}
/***************************************\\
//                                      \\
//         Breadcrumb ends              \\
//                                      \\
//***************************************/
/***************************************\\
//                                      \\
//         Product detail starts        \\
//                                      \\
//***************************************/

function GetComments(a){
    /*
        Check if #ecshop_product_reviews is display:none or not,
        if it is "none", do not get the comments.
    */
    var b = document.getElementById("ecshop_product_reviews");
    if(b){
        var c = ecShopGetStyle("ecshop_product_reviews","display").toLowerCase();
        if(c != "none"){
            if(a != undefined){
                ecShop.Web.Soap.ecShopWS.GetPosts(a,OnComments,OnError);
            }
        }
    }
}
function getForumForm(a,b,c){
    var r = "";
    var b = (b.indexOf("\'")>-1)?b.replace("\'","\\'"):b;
    r += '<h2>' + ecTranslate("product-headings.product-review-product") + '</h2>';
    r += '<div class="ecshop_form_container" id="comment_container">';
    r += '<div>';
    r += '<label for="comment_author">' + ecTranslate("common-labels.common-field-name") + ' *</label>';
    r += '<input id="comment_author" maxlength="30" size="30" class="validate"/>';
    r += '</div>';
    r += '<div>';
    r += '<label for="comment_content">' + ecTranslate("common-labels.common-field-message") + ' *</label>';
    r += '<textarea id="comment_content" rows="3" cols="30" class="validate"></textarea>';
    r += '</div>';
    r += '<div>';
    r += '<input type="hidden" id="captchahash" value=""/>';
    r += '<div class="ecshop_captcha"><img id="captchaimg" src="' + ecShopReturnHost() + '/upload/files/templates/controls/captcha.gif" onclick="return LoadCaptcha();" height="100" width="200" alt="Image verification" title="' + ecTranslate("common-tooltips.common-field-imgregenerate") + '" /></div>';
    r += '</div>';
    r += '<div>';
    r += '<label for="captcha_input" title="' + ecTranslate("common-tooltips.common-field-verification") + '">' + ecTranslate("common-labels.common-field-verification") + ' *</label>';
    r += '<input type="text" id="captcha_input" size="20" class="validate" maxlength="20" />';
    r += '</div>';
    r += '<div class="ecshop_form_buttons">';
    r += '<button onclick="postComment(\'' + a + '\',\'' + b + '\',\'' + c + '\')" class="ecshop_send">' + ecTranslate("common-buttons.common-send") + '</button><button onclick="removePopup(\'forum-form\')" class="ecshop_cancel">' + _esCancelBtn + '<br/><span>' + _esClose + '</span></button>';
    r += '<div class="clear"></div>';
    r += '</div>';
    r += '</div>';
    LoadCaptcha();
    createPopup(r,"ecshop_create-address","forum-form");
}
function postComment(a,b,c){
    var d = document.getElementById('comment_author').value;
    var e = "";/*Not used in release v1.0 or v2.0*/
    var f = document.getElementById('comment_content').value;
    var g = document.getElementById('captcha_input').value;
    var h = document.getElementById('captchahash').value;
    var i = document.getElementById("ecshopfx_first_post").value;
    var j = 0;/*0: Post is submitted as unapproved, 1: Post is submitted as approved*/
    var k = "<root/>";/*<root/>: no custom properties, else use XML structure for ptyxml*/
    var l = "true";/*false: status will always be 0, true: status will take given value 1 or 0*/
    if(validateForm("comment_container")){
        CreateUpdate(ecTranslate("product-messages.product-comment-posting"));
        ecShop.Web.Soap.ecShopWS.PostComment(a,c,b,f,d,e,k,l,j,i,h,g,OnPostComments,OnError);
    }
}
function OnPostComments(){
    DeleteUpdate();
    CreateMessage(ecTranslate("common-headings.common-success"),ecTranslate("product-labels.product-comment-posted"),"postedcomment");
    removePopup("forum-form");
    document.getElementById("ecshopfx_first_post").value = "false";
}
function OnComments(r){
    DeleteUpdate();
    if(r.indexOf("class=\"ecshop_forum\"")>-1){
        ReplaceContent("ecshopfx_product_comments",r);
        document.getElementById("ecshopfx_first_post").value = "false";
    }
    else if(r.indexOf("class=\"ecshop_forum_empty\"")>-1){
        ReplaceContent("ecshopfx_product_comments",ecTranslate("product-labels.product-nocomments"));
        document.getElementById("ecshopfx_first_post").value = "false";
    }
    else if(r.indexOf("<threaderror>")>-1 || r  ==  ""){
        ReplaceContent("ecshopfx_product_comments",ecTranslate("product-labels.product-nocomments"));
        document.getElementById("ecshopfx_first_post").value = "true";
    }
}

var _esRedirectParamIndex = _esCrntUrl.indexOf("?noredirect=true&from=");
if(_esRedirectParamIndex>-1){
    var redirectTo = _esCrntUrl.substring(_esRedirectParamIndex,_esCrntUrl.length);
    document.location.href = _ecshopSignInPage;
}

function ecShopHideCategoryTree(){
    var a = document.getElementById("content_area");
    var c = document.getElementById("content_container");
    if(a){
        a.className = "right_sidebar";
    }
    if(c){
        c.className = "product";
    }
}
function sendToFriend(){
    if(validateForm("ecshop_send_to_friend_popup")){
        var a = document.getElementById('captcha_input').value;
        var b = document.getElementById('captchahash').value;
        validateCaptcha("captchaimg",a,b);
    }
}
function validateCaptcha(b,c,d){
    if(c.length>0){
        ecShop.Web.Soap.ecShopWS.ValidateCaptcha(b,c,d,OnSuccessCaptchaVerification,OnError);
    }
    
    function OnSuccessCaptchaVerification(r){
        if(r){
            var a = document.getElementById("ecshopfx_product_price_hidden");
            if(a){
                document.getElementById("item_price").value = a.value;
            }
            document.getElementById("buy_link").value = document.location.href;
            document.getElementById("ecshopfx_send_to_friend").submit();
        }
        else{
            CreateError(ecTranslate("common-errors.common-error-ecs02"));
        }
    }
}

function validateCaptchaVal(b,c,d){

    if(c.length>0){

        ecShop.CaptchaValidation.CaptchaValidation.ValidateCaptcha(b,c,d,OnSuccessCaptchaVerification,OnError);

    }  
    function OnSuccessCaptchaVerification(r){
        if(r){
            var a = document.getElementById("ecshopfx_product_price_hidden");
            if(a){
                document.getElementById("item_price").value = a.value;
            }
            document.getElementById("buy_link").value = document.location.href;
            document.getElementById("ecshopfx_send_to_friend").submit();
        }
        else{
            //CreateError(ecTranslate("common-errors.common-error-ecs02"));
            alert('Error Captcha');
        }
    }
}

function OnSendToFriend(a){
    if(a  ==  'undefined'){
        a = "sent";
    }
    hideObject("ecshop_send_to_friend_popup");
    document.getElementById("friend_name").value = "";
    document.getElementById("friend_email").value = "";
    document.getElementById("your_email").value = "";
    document.getElementById("message").value = "";
    if(!(a  ==  'clear')){
        CreateMessage(ecTranslate("common-headings.common-success"),ecTranslate("common-headings.common-login-mail-sent"),'send-to-friend');
    }
}
/*** function: showProductRating(params) 
*
*    Available params:
*    totalRating = total rating for this product
*    totalVotes = total votes this product has received
*    productId = ID of the product
*    containerId = div#id of the container where the stars should be generated
***/
function showProductRating(a,b,c,d){
    if(a  ==  "")
        a = 0;
    if(b  ==  "")
        b = 0;
    var e = document.getElementById(d);
    _esRatingContainerId = d;
    _esRatingProdId = c;
    if(e){
        var f = readCookie(_esProdRatingCookie);
        var g = false;
        if(f  ==  null){
            f = "";
        }
        if(f.length>0 && f.indexOf(c + "|")>-1){
            g = true;
            var h = document.getElementById("ecshopfx_rating_status");
            if(h){
                h.innerHTML = ecTranslate("product-labels.product-rated");
            }
        }
        var j = (b>0)?Math.round(a/b):0;
        var k = '';
        for(var i=1;i  <=  5;i++){
            var l = (j != 0 && j >= i)?"full":"empty";
            if(g){
                k += '<div title="' + ecTranslate("product-labels.product-already-rated") + '" class="star ' + l + '"></div>';
            }
            else{
                k += '<div title="' + ecTranslate("product-labels.product-rate-prefix") + ' ' + i + ' ' + ecTranslate("product-labels.product-rate-appendix") + '" class="star ' + l + ' vote" onclick="updateProductRating(\'' + a + '\',\'' + b + '\',\'' + i + '\',\'' + c + '\')"></div>';
            }
        }
        k += '<span>' + j + '/5</span>';
        e.innerHTML = k;
    }
}
function updateProductRating(a,b,c,d){
    _esUserRating = c;
    ecShop.Web.Soap.ecShopWS.UpdateProductRating(a,b,c,d,OnProductRatingUpdated,OnError);
}
function OnProductRatingUpdated(r){
    if(r.length>1){
        var a = readCookie(_esProdRatingCookie);
        var b = "";
        if(a != null && a != ""){
            b = a+_esRatingProdId + "|";
        }
        else{
            b = _esRatingProdId + "|";
        }
        createCookie(_esProdRatingCookie,b,365);
        //Set stars as user's rating
        showProductRating(_esUserRating,1,_esRatingProdId,_esRatingContainerId);
        var c = document.getElementById("ecshopfx_rating_status");
        if(c){
            c.innerHTML = ecTranslate("product-labels.product-rated");
            c.className += " high-light";
            setTimeout("removeHighLight('ecshopfx_rating_status')",3000);
        }
        _esRatingContainerId = null;
        _esRatingProdId = null;
        _esUserRating = null;
    }
}
function removeHighLight(a){
    var c = document.getElementById(a);
    if(c){
        var b = c.className;
        if(b.indexOf(" high-light")>-1){
            c.className = b.replace(" high-light","");
        }
        else{
            c.className = b.replace("high-light","");
        }
    }
}
function ecShopSaveProductDetail(){
    document.ecshopfx_saveProductDetail.submit();
}
/***************************************\\
//                                      \\
//         Product detail ends          \\
//                                      \\
//***************************************/
/***************************************\\
//                                      \\
//         Search starts                \\
//                                      \\
//***************************************/
var ProdSearchList = {
    ProductsPerPage:_ecshopSearchProductsPerPage,
    ProductsFrom:null,
    ProductsTo:null,
    CurrentPage:1,
    SortBy1:1,
    SortBy2:3,
    View:'grid',
    Key:'',
    Cat:'',
    Columns:3,
    PrevPage:function(){
        if(this.CurrentPage>1){
            this.CurrentPage--;
            this.ProductsTo = (this.ProductsPerPage*this.CurrentPage);
            this.ProductsFrom = (this.ProductsPerPage*this.CurrentPage)-this.ProductsPerPage+1;
            this.Update();
        }
    },
    NextPage:function(){
        this.ProductsFrom = (this.ProductsPerPage*this.CurrentPage)+1;
        this.CurrentPage++;
        this.ProductsTo = (this.ProductsPerPage*this.CurrentPage);
        this.Update();
    },
    ChangeView:function(a){
        this.View = a;
        this.Update();
    },
    SetPage:function(a){
        this.ProductsFrom = (this.ProductsPerPage*(a-1))+1;
        this.ProductsTo = (this.ProductsPerPage*a);
        this.CurrentPage = a;
        this.Update();
    },
    SortProduct:function(a){
        this.SortBy1 = a;
        this.Update();
    },
    Reset:function(){
        this.ProductsPerPage = _ecshopSearchProductsPerPage;
        this.ProductsFrom = 1;
        this.ProductsTo = _ecshopSearchProductsPerPage;
        this.CurrentPage = 1;
        this.SortBy1 = 1;
    },
    Update:function(){
        //ecShopSaveSearch();
        //ecShop.Web.Soap.ecShopWS.SearchProducts(this.ProductsFrom,this.ProductsTo,this.SortBy1,this.SortBy2,this.Cat,this.Key,this.Columns,OnProductSearchUpdated,OnError);
        VistorShop.Soap.VistorShopWS.SearchProducts(this.ProductsFrom, this.ProductsTo, this.SortBy1, this.SortBy2, this.Cat, this.Key, this.Columns, this.ProductsPerPage, OnProductSearchUpdated, OnError);
    }
}
function OnLyfSearchUpdated(r) {
    var c = document.getElementById("lyfsearch");
    if (c) {
        var a = r;
        c.innerHTML = a;
    }
}
function OnProductSearchUpdated(r){
    //var c = document.getElementById("ecshop_search");
    var c = document.getElementById("lyfsearch");
    
    if(c){
        //var a = '<div class="ecshop_hover_close"><a href="javascript:ecShopCloseSearch()" class="img_replace" title="' + _esClose + '"><span>' + _esClose + '</span></a></div>';
        var a = r;
        //a += r;
        //a += '<div class="clear"></div>';
        c.innerHTML = a;
    }
}
function ecShopSearch(a,b,c,d,e,f,g){
    var h = document.getElementById("ecshopfx_search_default").value;
    var aRes = document.getElementById('autoresults');
    if(e  ==  undefined){
        var i = document.getElementById("ecshopfx_search_columns");
        if(i != null && i.value.length>0){
            e = i.value;
        }
        else{
            e = _ecshopSearchColumns;
        }
    }
    if(f  ==  undefined){
        var j = document.getElementById("ecshopfx_search_word");
        if(j != null){
            f = trim(j.value);
        }
        else{
            f = "";
        }
    }
    if(g  ==  undefined){
        var k = document.getElementById("ecshopfx_search_cat");
        if(k != null && k.selectedIndex != 0)
            g = k.value;
        else
            g = "";
    }
    if(a  ==  undefined)
        a = null;
    if(b  ==  undefined)
        b = null;
    if(c  ==  undefined)
        c = null;
    if(d  ==  undefined)
        d = null;
    if (f.length != 0 && f.length < 2)
        CreateError(ecTranslate("common-errors.common-search-minchars"));
    else if(f != h && f != ""){
        ecShopCloseSearch();
        //ecShopGoogleTrackSearch(f,g);
        CreateUpdate(ecTranslate("common-messages.common-searching"));
        ProdSearchList.ProductsFrom = a;
        ProdSearchList.ProdctsTo = b;
        ProdSearchList.SortBy1 = c;
        ProdSearchList.SortBy2 = d;
        ProdSearchList.Key = f;
        ProdSearchList.Cat = g;
        ProdSearchList.Columns = e;
        ProdSearchList.Reset();
        ecShopSaveSearch();
        aRes.style.display = 'none';
        aRes.innerHTML = '';
        VistorShop.Soap.VistorShopWS.SearchProducts(a,b,c,d,unescape(g),unescape(f),e,'',OnProductSearch,OnError);
    }
    else{
        CreateError(ecTranslate("common-errors.common-search-novalue"));
    }
}
function OnProductSearch(r) {
    var aRes = document.getElementById('autoresults');
    var sRes = document.getElementById('searchresults');
    aRes.style.display = 'none';
    aRes.innerHTML = '';
    sRes.style.display = 'block';
    DeleteUpdate();
    ecShopOnSearchResult(r);
    $('div#ecshop_search').slideToggle("slow");
}
function ecShopOnSearchResult(r) {
    var s = document.getElementById("searchcont");
    var a = document.getElementById("searchresults");
    var str = 'searchcontent';
    if (s) {
        var start = r.indexOf('<!--' + str + '-starts-->');
        var end = r.indexOf('<!--' + str + '-ends-->');
        DeleteUpdate();
        s.innerHTML = r.substring(start, end);
    }
    else {
        a.innerHTML = "";
        if (r.length > 0) {
            a.style.display = 'block';
            //var b='<div class="ecshop_hover_close"><a href="javascript:ecShopCloseSearch()" class="img_replace" title="' + _esClose + '"><span>' + _esClose + '</span></a></div>';
            var b = '';
            b += r;
            b += '<div class="clear"></div>';
            a.innerHTML = b;
            //document.body.insertBefore(a,document.body.firstChild);
            $('#searchresults').ready(function() {
                var tabs = document.getElementById('searchtabs');
                var li = tabs.getElementsByTagName('li');
                if (li[li.length-1].getAttribute('class') == 'selected')
                    li[li.length-1].setAttribute('class', 'last selected');
                else
                    li[li.length-1].setAttribute('class', 'last')
            });
        }
    }
}
ecShopAddLoadEvent(ecShopCheckSavedSearch);

function searchCatProds(obj, parent) {
    var k = document.getElementById("ecshopfx_search_cat");

    var a = ProdSearchList.ProductsFrom;
    var b = ProdSearchList.ProdctsTo;
    var c = ProdSearchList.SortBy1;
    var d = ProdSearchList.SortBy2;
    var g = HtmlEncode(k.value);
    if (g == '') g = HtmlEncode(parent);

    var f = trim(document.getElementById("ecshopfx_search_word").value);
    var e = ProdSearchList.Columns;

    ProdSearchList.Key = f;
    ProdSearchList.Cat = g;
    var t = document.getElementById('searchtabs')
    var li = t.getElementsByTagName('li');
    var j = 0;
    for (j=0; j < li.length; j++) {
        li[j].removeAttribute('class');
    }
    li[j - 1].setAttribute('class','last');

    var liObj = obj.parentNode;
    if(liObj.getAttribute('class') == 'last')
        liObj.setAttribute('class', 'last selected');
    else
        liObj.setAttribute('class', 'selected');

    CreateUpdate(ecTranslate("common-messages.common-searching"));
    VistorShop.Soap.VistorShopWS.SearchProducts(a, b, c, d, unescape(g), unescape(f), e, unescape(parent), ecShopOnSearchResult, OnError);
}

function ecShopSaveSearch(){
    var a = "key:" + ProdSearchList.Key + "|cat:" + ProdSearchList.Cat + "|columns:" + ProdSearchList.Columns + "|currentPage:" + ProdSearchList.CurrentPage;
    createCookie(_esSearchValueCookie,a,1);
}
function ecShopGetSearch(){
    var a = readCookie(_esSearchValueCookie);
    if((a != null || a != undefined) && a.length>0){
        var b = a.split("|");
        return b;
    }
}

//Search
$(document).ready(function() {
    var sRes = document.getElementById('searchresults');
    var aRes = document.getElementById('autoresults');

    var ENTER = 13; var TAB = 9; var ESC = 27; var KEYUP = 38; var KEYDN = 40; var LEFT = 37; var RIGHT = 39;
    var END = 35; var HOME = 36; var SHIFT = 16; var CTRL = 17; var ALT = 18; var CAPS = 20;

    $('#searchitem').keyup(function(event) {
        var k = (event.keyCode ? event.keyCode : event.which);
        if (k == ENTER) lyfSearch();
    });

    $('#ecshopfx_search_word').keyup(function(event) {
        var k = (event.keyCode ? event.keyCode : event.which);
        var sTxt = trim(document.getElementById("ecshopfx_search_word").value);
        if (k != ENTER && k != TAB && k != ESC && k != KEYUP && k != KEYDN && k != LEFT && k != RIGHT && k != HOME && k != END && k != SHIFT && k != ALT && k != CTRL) {
            if (sTxt.length > 1) {
                $('#ecshopfx_search_cat').val('');
                $('#searchresults').children().remove();
                sRes.style.display = 'none';
                VistorShop.Soap.VistorShopWS.AutoSuggest(sTxt, OnSuggestion, OnError);
            }
            else {
                aRes.style.display = 'none';
                aRes.innerHTML = '';
            }
        }
        else if (k == ENTER) {
            aRes.style.display = 'none';
            aRes.innerHTML = '';
            ecShopSearch();
        }
        else if (k == KEYDN) {
            navigate('down');
        }
        else if (k == KEYUP) {
            navigate('up');
        }
        else if (k == ESC) {
            sRes.style.display = 'none';
            $('#searchresults').children().remove();
        }
    });
});
function OnSuggestion(results) {
    var aRes = document.getElementById('autoresults');
    var resultshtml = '';

    if (results.length > 0) {
        aRes.style.display = 'block';
        //document.getElementById('ecshopfx_search_cat').value = results[0].Parent;
        for (var i = 0; i < results.length; i++) {
            var pt = results[i].Parent;
            var pn = results[i].ProductName;
            var ch = pn + ' (' + pt + ')';
            //var extra = ch.length - 32;
            var extra = ch.length - 38;
            if (extra > 1) {
                var c = Math.ceil(extra / 2);
                pt = pt.substring(0, (pt.length - c)) + '..';
                pn = pn.substring(0, (pn.length - (extra - c))) + '..';//gopi2
            }
            //resultshtml += '<li title="' + HtmlEncode(results[i].ProductName) + '|' + HtmlEncode(results[i].Parent) + '" onClick="javascript:setSearch(\'' + HtmlEncode(results[i].ProductName) + '\',\'' + HtmlEncode(results[i].Parent) + '\')" onmouseout="javascript:removeHighlight(this)" onmouseover="javascript:setHighlight(this)"><a href="javascript:void(0)"><span class="L">' + pn + '</span> <span class="R">(' + pt + ')</span></a></li>';
            resultshtml += '<li title="' + results[i].ProductName + '|' + results[i].Parent + '" onClick="javascript:setSearch(\'' + escape(HtmlEncode(results[i].ProductName)) + '\',\'' + escape(HtmlEncode(results[i].Parent)) + '\')" onmouseout="javascript:removeHighlight(this)" onmouseover="javascript:setHighlight(this)"><a href="javascript:void(0)"><span class="L">' + pn + '</span> <span class="R">(' + pt + ')</span></a></li>';
        }
        aRes.innerHTML = '<ul class="cnt">' + resultshtml + '</ul>';
    }
    else {
        aRes.style.display = 'none';
    }
}
function setSearch(prod, parent) {
    var sRes = document.getElementById('searchresults');
    var aRes = document.getElementById('autoresults');
    aRes.style.display = 'none';
    /*aRes.innerHTML = '';
    sRes.innerHTML = '';*/
    $('#searchresults').children().remove();
    $('#autoresults').children().remove();
    document.getElementById("ecshopfx_search_word").value = unescape(prod);
    document.getElementById("ecshopfx_search_cat").value = parent;
    document.getElementById("ecshopfx_search_word").focus();
    ecShopSearch();
}
function setHighlight(obj) {
    obj.setAttribute("class", "selected");
}
function removeHighlight(obj) {
    obj.setAttribute("class", "");
}
function lyfSearch() {
    var lyfTxt = trim(document.getElementById("searchitem").value);
    var lyfFrm = document.getElementById("lyf_search");
    var d = document.getElementById("lyf_search_default").value;

    if (d == lyfTxt)
        CreateError(ecTranslate("common-errors.common-search-novalue"));
    else if (lyfTxt.length != 0 && lyfTxt.length < 2)
        CreateError(ecTranslate("common-errors.common-search-minchars"));
    else if (lyfTxt.length > 1)
        lyfFrm.submit();
    else
        CreateError(ecTranslate("common-errors.common-search-novalue"));
}
var curSel = 0;
function navigate(dir){
   if($('#autoresults ul li.selected').size() == 0)
        curSel = -1;
   var as = $('#autoresults ul li');
   if(dir == 'up' && curSel != -1){
        if(curSel!=0) curSel--;
   }
   else if(dir == 'down'){
        if(curSel != as.size()-1) curSel++;
   }
   as.removeClass('selected');
   as.eq(curSel).addClass('selected');
   var s = as.eq(curSel).attr('title');
   var sp = s.split('|');
   $('#ecshopfx_search_word').val(sp[0]);
   $('#ecshopfx_search_cat').val(sp[1]);
}


/*Start : Maintain search in all pages*/
function ecShopCheckSavedSearch(){
    var a = readCookie(_esSearchCookie);
    if(a  ==  "1"){
        ecShopCreateSearchButton(_ecshopShowSearchResult,"ecshop_search_toggle");
        var b = ecShopGetSearch();
        if((b != null || b != undefined) && b.length>2){
            if(b[3].split(":")[1]>1){
                ProdSearchList.CurrentPage = b[3].split(":")[1];
            }
        }
        ecShopLoadSavedSearch();
    }
}
function ecShopCreateSearchButton(a,b){
    var c = document.getElementById("ecshop_search_toogle");
    if(c  ==  null){
        c = document.createElement("div");
    }
    else{
        c.innerHTML = "";
    }
    c.className = b;
    c.setAttribute("id","ecshop_search_toogle");
    c.style.zIndex = _zIndex++;
    var d = document.createElement("div");
    d.setAttribute("id","ecshop_search_toogle_text");
    d.innerHTML = a;
    var e = document.createElement("div");
    e.className = "ecshop_hover_close";
    e.innerHTML = '<a href="javascript:ecShopCloseSearch()" class="img_replace" title="' + _esClose + '"><span>' + _esClose + '</span></a>';
    c.appendChild(d);
    c.appendChild(e);
    var f = document.body;
    f.insertBefore(c,f.firstChild);
    $('div#ecshop_search_toogle_text').click(function(){
        ecShopPositionToggle(true);
        $('div#ecshop_search').slideToggle("slow",ecShopPositionToggle);
    });
}
function ecShopPositionToggle(a){
    if(a  ==  undefined)
        a = false;
    var b = document.getElementById("ecshop_search_toogle");
    var c = document.getElementById("ecshop_search");
    var d = document.getElementById("ecshop_search_toogle_text");
    if(a){
        if(c.style.display  ==  'none'){
            b.style.position = 'relative';
        }
    }
    else{
        if(c.style.display  ==  'none'){
            b.style.position = 'absolute';
        }
    }
    if(a && d){
        overwriteInnerHTML(d,_ecshopShowSearchResult,_ecshopHideSearchResult);
    }
}
function ecShopCloseSearch(){
    var a = document.getElementById("ecshop_search_toogle");
    var b = document.getElementById("ecshop_search");
    if(a){
        a.parentNode.removeChild(a);
    }
    if(b)
        b.parentNode.removeChild(b);
    createCookie(_esSearchCookie,"",0);
    createCookie(_esSearchValueCookie,"",0);
}
function ecShopLoadSavedSearch(){
    var a = ecShopGetSearch();
    if((a  !=  null || a  !=  undefined) && a.length>1){
        ProdSearchList.Key = a[0].replace("key:","");
        ProdSearchList.Cat = a[1].replace("cat:","");
        ProdSearchList.Columns = a[2].replace("columns:","");
    }
    //ecShop.Web.Soap.ecShopWS.GetSearchFromSession(ecShopOnSearchResult,OnError);
    VistorShop.Soap.VistorShopWS.GetSearchFromSession(ecShopOnSearchResult, OnError);
}

/*End : Maintain search in all pages*/
/***************************************\\
//         Search ends                  \\
//***************************************/
/***************************************\\
//         Google Analytics starts      \\
//***************************************/
/* Calls in the 4th step*/
function ecShopGoogleTrackOrder(a){
    if(pageTracker  !=  null){
        try{
            eval(a);
        }
        catch(err){}
    }
}
/* Calls for all the 3 steps in checkout*/
function ecShopGoogleTrackCheckout(a){
    if(pageTracker  !=  null){
        pageTracker._trackPageview("/checkout/step" + a + ".html");
    }
}
/* Calls when click on search go button*/
function ecShopGoogleTrackSearch(a,b){
    if(pageTracker  !=  null){
        pageTracker._trackPageview("/quicksearch/search.html?search=" + a + "&cat=" + b);
    }
}
/***************************************\\
//         Google Analytics ends        \\
//***************************************/
/***************************************\\
//         News letter starts           \\
//***************************************/
function ecValidateNewsletter(){
    var a = true;
    var b = document.getElementById("ecshopfx_error");
    if(validateForm("registrationform_newsletter")){
        mailText = document.getElementById('emailid').value;
        if(mailText  !=  "")
            frameXml();
    }
    else if(b){
        showObject("ecshopfx_error");
    }
}
function frameXml(){
    /*Frame users Detail*/
    var a = '<root><registeredusers><users uniquefieldscope="group" uniquefield="email">';
    var b = '<user><groupname>' + catalog_group_name_mail + '</groupname>';
    b = b + "<email>" + document.getElementById('emailid').value + "</email>";
    b = b + "</user>";
    a = a+b;
    a = a + "</users></registeredusers></root>";
    newsLetterSubscription(a);
}
function newsLetterSubscription(a){
    var b = _ecshopEditorUserName;
    var c = _ecshopEditorPassword;
    var d = new SOAPObject("importUsers");
    d.ns = "http://tempuri.org/";
    d.appendChild(new SOAPObject("XML")).val(a);
    d.appendChild(new SOAPObject("username")).val(b);
    d.appendChild(new SOAPObject("password")).val(c);
    var e = new SOAPRequest("http://tempuri.org/importUsers",d);
    e.addNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
    e.addNamespace("xsd","http://www.w3.org/2001/XMLSchema");
    SOAPClient.Proxy = ecShopReturnHost() + "/editor/soap/registeredusers.asmx";
    SOAPClient.SOAPServer = ecShopReturnHost() + "/editor/soap/registeredusers.asmx";
    SOAPClient.SendRequest(e,importUsersResponse);
}
function importUsersResponse(a,b,c){
    var d = b;
    var e = d.indexOf('<faultstring>');
    var f = d.indexOf('</faultstring>');
    var g = d.substring(e,f);
    if(g.length>0)
        CreateMessage(ecTranslate("common-messages.common-newsletter-validation"),'','');
    else 
        CreateMessage(ecTranslate("common-messages.common-postlist-success-message"),'','');
}
/***************************************\\
//                                      \\
//         News letter ends             \\
//                                      \\
//***************************************/

/***************************************\\
//                                      \\
//         Compare starts               \\
//                                      \\
//***************************************/

/*To create an area for droping the products to compare and to show the list of products selected to compare*/
function ecShopCreateCompareArea(){
    var C = document.getElementById('ecshopfx_compare_products');
    var a = document.createElement("div");
    a.id = "ecshopfx_compare_container";
    a.className = "ecshopfx_compare_container";
    a.innerHTML = '<div id="ecshopfx_comp_desc">' + ecTranslate("product-messages.product-compare") + '</div><button class="compare_btn" onclick="ecShopCompareProducts(\'' + document.getElementById("modulePosition").value + '\')">' + ecTranslate("product-buttons.product-compare-button") + '</button>';
    var b = document.createElement("div");
    /*Id and class must not be changed - used to identify the div for drag and drop functionality*/
    b.id = "dropZ";
    b.className = "dropZone";
    var c = document.createElement("div");
    c.className = "clear";
    a.appendChild(b);
    a.appendChild(c);
    if(C)
        C.appendChild(a);
}

function ecShopCompareProducts(a){
    /*_esCompareContainer - Object of input field which is used to save selected products guid separated by comma(,)*/
    if(_esCompareContainer  !=  null){
        var b = _esCompareContainer.value.split(",");
        var c = document.location.href.split("?")[1];
        /*Check for product count if it is more than 1 then proceed to compare
           else give error message - There must be minimum of 2 products to compare.
        */
        if(b.length>2){
            var d = new Array();
            d = _esCompareContainer.value.split(',');
            
            if(d.length>1){
                if(c  !=  undefined){
                    if(c.length>0){
                        document.location.href = 'http://' + document.domain+window.location.pathname + '?SelectedProducts=' + b + '&ew_' + a + '_p_comp=true&' + c;
                    }
                }
                else{
                    document.location.href = 'http://' + document.domain+window.location.pathname + '?SelectedProducts=' + b + '&ew_' + a + '_p_comp=true';
                }
            }
            else{
                CreateError(ecTranslate("product-messages.product-compare-min-limit-message"));
            }
        }
        else{
            CreateError(ecTranslate("product-messages.product-compare-min-limit-message"));
        }
    }
}
var d;
var a;
var l;
var prodListArray = "";
var str1 = "Remove";
var drag = "";

function LoadCompareProducts(){
    $(".ecshopfx_draggable h3").draggable({
        helper:"clone",
        opacity:"0.5"
    });
    $(".dropZone").droppable({
        accept:".ecshopfx_draggable h3",
        hoverClass:"dropHover",
        drop:function(a,b){
            var c = b.draggable.clone().addClass("droppedItem");
            var d = (c[0].className);
            var e = d.substring(2,38);
            var f = document.getElementById(e);
            if(_esCount<4){
                if((_esCompareContainer.value).indexOf(e) <= -1){
                    $(this).append(c);
                    var g = document.createElement("a");
                    g.id = "remove_link";
                    g.href = "javascript:void(0)";
                    $(this).append(g);
                    cntIncrease(e);
                    g.onclick = function(){
                        $(".dropZone").children().remove("." + c[0].className);
                        cntDecrease(e);
                    };
                    c[0].appendChild(g);
                    $(this).append(c);
                }
                else{
                    if(_esCompExistHead  ==  "" || _esCompExistMsg  ==  ""){
                        _esCompExistMsg = ecTranslate("product-messages.product-compare-exist-message");
                        _esCompExistHead = ecTranslate("product-headings.product-compare-exist-heading");
                    }
                    CreateMessage(_esCompExistHead,_esCompExistMsg);
                }
            }
            else{
                if(_esCompLimitExistHead  ==  "" || _esCompLimitExistMsg  ==  ""){
                    _esCompLimitExistHead = ecTranslate("product-headings.product-compare-max-limit-heading");
                    _esCompLimitExistMsg = ecTranslate("product-messages.product-compare-max-limit-message");
                }
                CreateMessage(_esCompLimitExistHead,_esCompLimitExistMsg);
                if(f.checked){
                    f.checked = false;
                }
            }
        }
    });
}
function ecShopInsertProducts(a,b){
    var c = document.getElementById(a);
    if(c.checked){
        ecShopInsert(a,b);
    }
    else{
        remove(a);
    }
}
function remove(c,d){
    if(d  ==  undefined)
        d = "";
    var e = c;
    var a = document.getElementById("a_" + c);
    var b = document.getElementById("drop_" + c);
    var f = b || a;
    var p = f.parentNode;p.removeChild(f);
    if(d  ==  'clear'){
        var g = document.getElementById(c);
        if(g.checked){
            g.checked = false;
        }
    }
    else{
        cntDecrease(c);
    }
}
function ecShopInsert(b,c){
    var e = b;
    var f = c;
    var g = document.getElementById(b);
    if(_esCount >= 4){
        if(_esCompLimitExistHead  ==  "" || _esCompLimitExistMsg  ==  ""){
            _esCompLimitExistHead = ecTranslate("product-headings.product-compare-max-limit-heading");
            _esCompLimitExistMsg = ecTranslate("product-messages.product-compare-max-limit-message");
        }
        CreateMessage(_esCompLimitExistHead,_esCompLimitExistMsg);
        if(g.checked){
            g.checked = false;
        }
    }
    else{
        if(_esCompareContainer.value.indexOf(b) <= -1){
            d = document.createElement("div");
            d.className = "a_" + b + " droppedItem";
            d.id = "drop_" + b;
            d.name = "drop_" + b;
            var h = document.getElementById('dropZ');
            h.appendChild(d);
            a = document.createElement("a");
            a.className = "dropped_product";
            a.appendChild(document.createTextNode(f));
            a.setAttribute("href","javascript:void(0);");
            l = document.createElement("a");
            l.className = "remove_link";
            l.setAttribute("href","javascript:void(0);");
            d.appendChild(a);
            d.appendChild(l);
            cntIncrease(b);
            l.onclick = function(){
                remove(b);
            }
        }
        else{
            CreateMessage(_esCompExistHead,_esCompExistMsg);
        }
    }
}
function cntIncrease(a){
    var b = document.getElementById(a);
    _esCount = eval(_esCount+1);
    prodListArray += a + ",";
    _esCompareContainer.value = prodListArray;
    if(!(b).checked){
        b.checked = true;
    }
}
function cntDecrease(a){
    var b = document.getElementById(a);
    _esCount = eval(_esCount-1);
    prodListArray = prodListArray.replace(a + ",","");
    _esCompareContainer.value = prodListArray;
    if(b.checked){
        b.checked = false;
    }
}
/***************************************\\
//                                      \\
//         Compare ends                 \\
//                                      \\
//***************************************/


/***************************************\\
//                                      \\
//         Custom function              \\
//                                      \\
//***************************************/



