﻿var v_informvalidation = false;
var v_inservice = 0;
var v_clicked = false;
var v_inputmappingfield = '';
var v_inpaymentmodule = false;
var v_winpayment = null;
var v_payparams = null;
var v_payresult = 0;
var v_inshowpicture = false;
var v_historycounter = 0;
var v_currentcounter = 0;
var v_firstloaded = false;
var v_formvalues;
var v_inexternpayment = false;
var v_cannavigate;
var v_started = true;
var v_loaded = false;
var v_globalaction1 = -1;
var v_globalaction2 = -1;

var v_hist_counter = -999;
var v_hist_topic = '';
var v_hist_extraparam = 0;
var v_hist_extraparamcontent = '';
var v_hist_extraparamcontentpanel = '';


var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

function pageLoad() {
    v_cannavigate = false;
    if (v_started) {
        v_started = false;
        var v_acceptcoockie = false;
        Set_Cookie('coockietest', '1', '', '/', '', '');
        if (Get_Cookie('coockietest')) {
            var v_c = Get_Cookie('coockietest');
            if (v_c == '1')
                v_acceptcoockie = true;
        }
        var service = WebShop.Framework.Web.Service.WebShop.SetCoockieValue(v_acceptcoockie, pageLoad2);
    }
    else {
        pageLoad2();
    }
    return;
}

function pageLoad2() {
    if (Get_Cookie('externalpay')) {
        var v_payment = Get_Cookie('externalpay');
        Delete_Cookie('externalpay', '/', '');
        setPaymentValue(parseInt(v_payment) + 101);
        return;
    }
    //***
    v_formvalues = new Hashtable();
    v_formvalues.clear();
    v_clicked = false;
    hideWorking();
    setTimer();
    window.scrollTo(0, 0);
    // var v_url = document.URL;
    var v_url = top.location.href;
    
    v_pos = v_url.indexOf('#');
    if (v_pos > 0) {
        v_cannavigate = true;
        v_url = v_url.substring(v_pos + 4);
        if (v_url.length > 0) {
            var v_params = v_url.split("%26");
            var v_id = 0;
            var v_p1 = '';
            var v_p2 = '';
            try {
                v_id = parseInt(v_params[0]);
            }
            catch (e) { }

            try {
                v_p1 = v_params[2]
            }
            catch (e) { }

            try {
                v_p2 = v_params[3]
            }
            catch (e) { }
            
            if ((v_id != v_currentcounter) && (v_currentcounter == 0)) {
                v_currentcounter = v_id;
                doAction(parseInt(v_params[1]), 'maincontainer', v_p1, '', '', v_p2);
            }
        }
    }
    else {
        // doChatTracking();
    }
}


function executeScriptFunction(v_javascript) {
    try
    {
        if (v_javascript.length > 0) {
            v_javascript = unescape(v_javascript);
            v_returnvalue = eval(v_javascript);
            return v_returnvalue;
        }
    }
    catch (e) { }
}

//**** ACTION FUNCTIONS
function doAction2(v_action, v_panelid, v_params, v_breadcrump, v_javascript, v_contentpanelid, v_extraparam, v_extraparamcontent, v_extraparamcontentpanel) {
    v_globalaction1 = v_action;
    setWorking();

    //*** track page
    var v_searchinput = '';
    if (v_action == 47) {
        var v_search = new WebShop.Framework.Web.Service.SearchParameters();
        v_search = fillServiceParamsWithInputFields(v_search, v_params);
        v_searchinput = v_search.search;
    }
    doPageTracking(v_action, v_params, v_searchinput);

    //***
    v_hist_counter = -999;
    v_hist_topic = '';
    v_hist_extraparam = 0;
    v_hist_extraparamcontent = '';
    v_hist_extraparamcontentpanel = '';
    
    
    if ((v_action != 1) && (v_action != 9) && (v_action != 33) && (v_action != 20) && (v_action != 23) && (v_action != 24) && (v_action != 25) && (v_action != 26) && (v_action != 27) && (v_action != 28) && (v_action != 10) && (v_action != 14) && (v_action != 16) && (v_action != 18) && (v_action != 75) && (v_action != 77) && (v_action != 79) && (v_action != 29) && (v_action != 82) && (!((v_action >= 51) && (v_action <= 57))) && (v_action != 85) && (v_action != 65) && (v_action != 66) && (!((v_action >= 65) && (v_action <= 72))))
    {
        var v_actiontotrace = ";" + v_action + ";";
        var v_legend = 'Webshop';
        var v_topic = '';
        try {
            v_legend = v_company + ' -- ' + v_actionlegend[v_action];
        }
        catch (xerr) { }

        //***
        v_historycounter++;
        v_currentcounter = v_historycounter;

        v_topic = v_historycounter + '&' + v_action;
        // if (v_params.indexOf('=') < 0) {
            // v_topic = v_topic + '&' + v_params;
            // if (v_contentpanelid.indexOf('=') < 0)
                // v_topic = v_topic + '&' + v_contentpanelid;
        // }

        // v_topic = v_historycounter + '&' + v_action;
        try {
            v_usernavigated = false;
            Sys.Application.addHistoryPoint({ id: v_topic }, v_legend);
            document.title = v_company;
            //***
            v_hist_counter = v_historycounter;
            v_hist_topic = v_topic;
            v_hist_extraparam = v_extraparam;
            v_hist_extraparamcontent = v_extraparamcontent;
            v_hist_extraparamcontentpanel = v_extraparamcontentpanel;

            //***    
            doServiceAction(v_action, v_panelid, v_params, v_breadcrump, v_javascript, v_contentpanelid, 1, 0);
            // var service = WebShop.Framework.Web.Service.WebShop.SetHistory(v_historycounter, v_action, v_panelid, v_params, v_breadcrump, v_javascript, v_contentpanelid, v_topic, v_extraparam, v_extraparamcontent, v_extraparamcontentpanel, setHistoryCompleted);
        }
        catch (ee) {
            doServiceAction(v_action, v_panelid, v_params, v_breadcrump, v_javascript, v_contentpanelid, 1, 0);
        }
    }
    else {
        doServiceAction(v_action, v_panelid, v_params, v_breadcrump, v_javascript, v_contentpanelid, 1, 0);
    }
}
function doAction(v_action, v_panelid, v_params, v_breadcrump, v_javascript, v_contentpanelid) {
    doAction2(v_action, v_panelid, v_params, v_breadcrump, v_javascript, v_contentpanelid, 0, '', '');
}

function setHistoryCompleted(v_result) {

    v_hist_counter = -999;
    v_hist_topic = '';
    v_hist_extraparam = 0;
    v_hist_extraparamcontent = '';
    v_hist_extraparamcontentpanel = '';

    doServiceAction(v_result.Action, v_result.PanelId, v_result.Parameters, v_result.Breadcrump, v_result.Javascript, v_result.ContentPanelId, 1, v_result.FromHistory);
}

function doServiceAction(v_action, v_panelid, v_params, v_breadcrump, v_javascript, v_contentpanelid, v_count, v_fromhistory) {
    v_globalaction2 = v_action;
    v_originaljavascript = v_javascript;
    v_returnvalue = executeScriptFunction(v_javascript);
    if (typeof (v_returnvalue) == 'boolean') {
        if (!v_returnvalue) {
            v_clicked = false;
            hideWorking();
            return;
        }
    }
    //***
    v_inputmappingfield = '';
    try {
        switch (v_action) {
            case 82:
                SetMoreFilter(v_action, v_panelid, v_params, v_breadcrump, v_javascript, v_contentpanelid);
                break;
            case 75:
                var serviceset = WebShop.Framework.Web.Service.WebShop.SetCustomerType(v_params, setCustomerTypeCompleted);
                break;
            case 72: // SUBMIT CHANGE USER
                if (!checkInputFields(v_params)) {
                    v_clicked = false;
                    hideWorking();
                    return;
                }
                doChangeUserAction(setActionParameters(v_action, v_panelid, v_params, v_breadcrump, v_originaljavascript, v_contentpanelid, v_fromhistory));
                break;
            case 70: // DELETE USER
                var v_splitusr = v_contentpanelid.split(",");
                if (v_splitusr[0].length > 0) {
                    if (!confirm(v_splitusr[0])) {
                        v_clicked = false;
                        hideWorking();
                        return;
                    }
                }
                doDeleteUserAction(setActionParameters(v_action, v_panelid, v_params, v_breadcrump, v_originaljavascript, v_contentpanelid, v_fromhistory));
                break;
        
            case 69: // SUBMIT CHANGE PASSWORD
                if (!checkInputFields(v_params)) {
                    v_clicked = false;
                    hideWorking();
                    return;
                }
                doChangePasswordAction(setActionParameters(v_action, v_panelid, v_params, v_breadcrump, v_originaljavascript, v_contentpanelid, v_fromhistory));
                break;
            case 68: // SUBMIT NEW USER
                if (!checkInputFields(v_params)) {
                    v_clicked = false;
                    hideWorking();
                    return;
                }
                doNewUserAction(setActionParameters(v_action, v_panelid, v_params, v_breadcrump, v_originaljavascript, v_contentpanelid, v_fromhistory));
                break;
            case 66: // SUBMIT CREDITLIMIT
                if (!checkInputFields(v_params)) {
                    v_clicked = false;
                    hideWorking();
                    return;
                }
                doNewCreditAction(setActionParameters(v_action, v_panelid, v_params, v_breadcrump, v_originaljavascript, v_contentpanelid, v_fromhistory));
                break;
            case 86: // SUBMIT CREDITLIMIT
                doDocumentFilterAction(setActionParameters(v_action, v_panelid, v_params, v_breadcrump, v_originaljavascript, v_contentpanelid, v_fromhistory));
                break;
            case 65: // SUBMIT RMA
                if (!checkInputFields(v_params)) {
                    v_clicked = false;
                    hideWorking();
                    return;
                }
                doNewRmaAction(setActionParameters(v_action, v_panelid, v_params, v_breadcrump, v_originaljavascript, v_contentpanelid, v_fromhistory));
                break;
            case 47: // STARTSEARCH
                if (!checkInputFields(v_params)) {
                    v_clicked = false;
                    hideWorking();
                    return;
                }
                var v_search = new WebShop.Framework.Web.Service.SearchParameters();
                v_search = fillServiceParamsWithInputFields(v_search, v_params);
                v_params = v_params + ',' + v_search.search;
                var servicesearch = WebShop.Framework.Web.Service.WebShop.SetAction(setActionParameters(v_action, v_panelid, v_params, v_breadcrump, v_originaljavascript, v_contentpanelid, v_fromhistory), setActionCompleted);
                break;
            case 83:
                var servicesearchhist = WebShop.Framework.Web.Service.WebShop.SetAction(setActionParameters(v_action, v_panelid, v_params, v_breadcrump, v_originaljavascript, v_contentpanelid, v_fromhistory), setActionCompleted);
                break;
            case 40:
                doSetComponentItem(setActionParameters(v_action, v_panelid, v_params, v_breadcrump, v_originaljavascript, v_contentpanelid, v_fromhistory));
                break;
            case 33:
                doCommitOrderAction(setActionParameters(v_action, v_panelid, v_params, v_breadcrump, v_originaljavascript, v_contentpanelid, v_fromhistory));
                break;
            case 1: // New Account
            case 79: // Cashout New Account
                if (!checkInputFields(v_params)) {
                    v_clicked = false;
                    hideWorking();
                    return;
                }
                doNewAccountAction(setActionParameters(v_action, v_panelid, v_params, v_breadcrump, v_originaljavascript, v_contentpanelid, v_fromhistory));
                break;
            case 24: // New Delivery Address
            case 53: // New Delivery Address
                if (!checkInputFields(v_params)) {
                    v_clicked = false;
                    hideWorking();
                    return;
                }
                doNewDeliveryAction(setActionParameters(v_action, v_panelid, v_params, v_breadcrump, v_originaljavascript, v_contentpanelid, v_fromhistory));
                break;
            case 27: // Commit Delivery Address
            case 56: // Commit Delivery Address
                if (!checkInputFields(v_params)) {
                    v_clicked = false;
                    hideWorking();
                    return;
                }
                doCommitDeliveryAction(setActionParameters(v_action, v_panelid, v_params, v_breadcrump, v_originaljavascript, v_contentpanelid, v_fromhistory));
                break;
            case 31: // Commit Invoice Address
            case 52: // Commit Change Invoice Address
                if (!checkInputFields(v_params)) {
                    v_clicked = false;
                    hideWorking();
                    return;
                }
                doCommitInvoiceAddressAction(setActionParameters(v_action, v_panelid, v_params, v_breadcrump, v_originaljavascript, v_contentpanelid, v_fromhistory));
                break;
            case 54: // DELETE Delivery Address from list
                var v_splitdel = v_contentpanelid.split(",");
                if (v_splitdel[0].length > 0) {
                    if (!confirm(v_splitdel[0])) {
                        v_clicked = false;
                        hideWorking();
                        return;
                    }
                }
                doDeleteDeliveryAction(setActionParameters(v_action, v_panelid, v_params, v_breadcrump, v_originaljavascript, v_contentpanelid, v_fromhistory));
                break;
            case 28: // DELETE Delivery Address
                if (v_params.length > 0) {
                    if (!confirm(v_params)) {
                        v_clicked = false;
                        hideWorking();
                        return;
                    }
                }
                doDeleteDeliveryAction(setActionParameters(v_action, v_panelid, v_params, v_breadcrump, v_originaljavascript, v_contentpanelid, v_fromhistory));
                break;
            case 9: // Process Login Request
            case 21: // Process Login Request
                if (!checkInputFields(v_params)) {
                    hideWorking();
                    v_clicked = false;
                    return;
                }
                doLoginAction(setActionParameters(v_action, v_panelid, v_params, v_breadcrump, v_originaljavascript, v_contentpanelid, v_fromhistory));
                break;
            case 20: // Process Forgot Password
            case 77: // Process Forgot Password
                if (!checkInputFields(v_params)) {
                    hideWorking();
                    v_clicked = false;
                    return;
                }
                doForgotPasswordAction(setActionParameters(v_action, v_panelid, v_params, v_breadcrump, v_originaljavascript, v_contentpanelid, v_fromhistory));
                break;
            case 10: // Activate Account
                if (!checkInputFields(v_params)) {
                    hideWorking();
                    v_clicked = false;
                    return;
                }
                doActivateAccountAction(setActionParameters(v_action, v_panelid, v_params, v_breadcrump, v_originaljavascript, v_contentpanelid, v_fromhistory));
                break;
            case 42:
                if (!checkInputFields(v_params)) {
                    v_clicked = false;
                    hideWorking();
                    return;
                }
                var v_ol1 = new WebShop.Framework.Web.Service.OrderLineParameters();
                v_ol1 = fillServiceParamsWithInputFields(v_ol1, v_params);
                v_contentpanelid = v_contentpanelid + ',' + v_ol1.quantity;
                doCheckConfigurationAction(setActionParameters(v_action, v_panelid, v_params, v_breadcrump, v_originaljavascript, v_contentpanelid, v_fromhistory));
                break;
            case 15: // Add detail to order
                if (!checkInputFields(v_params)) {
                    v_clicked = false;
                    hideWorking();
                    return;
                }
                var v_ol = new WebShop.Framework.Web.Service.OrderLineParameters();
                v_ol = fillServiceParamsWithInputFields(v_ol, v_params);
                var v_splitx = v_contentpanelid.split(",");
                v_params = v_splitx[0] + ',' + v_ol.quantity + ',' + v_splitx[1];
                v_contentpanelid = v_splitx[2];
                v_action = 13;
                var serviceadd = WebShop.Framework.Web.Service.WebShop.SetAction(setActionParameters(v_action, v_panelid, v_params, v_breadcrump, v_originaljavascript, v_contentpanelid, v_fromhistory), setActionCompleted);
                break;
            default:
                var servicedef = WebShop.Framework.Web.Service.WebShop.SetAction(setActionParameters(v_action, v_panelid, v_params, v_breadcrump, v_originaljavascript, v_contentpanelid, v_fromhistory), setActionCompleted);
                break;
        }
    }
    catch (e) {
        v_clicked = false;
        hideWorking();
    }
}

function checkInputFields(v_mappings) {
    v_informvalidation = true;
    //***
    var v_inputisvalid = true;
    var v_mapping = v_mappings.split(",");
    for (var v_i = 0; v_i < v_mapping.length; v_i++) {
        if (!checkInputField(v_mapping[v_i])) {
            v_inputisvalid = false;
            v_i = v_mapping.length;
        }
    }
    //***
    v_informvalidation = false;
    //***
    return v_inputisvalid;        
}

function validateOrderQty(v_controlname, v_lineno, v_content, v_contentpanel, v_updatepanel, v_breadcrump) {
    var v_control = $get( v_controlname );
    var v_value = getInputValue( v_control );
    if (!checkRequired(v_control, v_value)) {
        hideWorking();
        var v_errormessage = v_control.getAttribute("validateerror");
        alert(v_errormessage);
        v_control.focus();
        return false;
    }
    //***
    setWorking();
    var service = WebShop.Framework.Web.Service.WebShop.SetAction(setActionParameters(16, v_updatepanel, v_lineno + ',' + v_value + ',' + v_content, v_breadcrump, '', v_contentpanel, 0), setActionCompleted);
}

function checkInputField( v_mapping ) {
    var v_validinput = true;
    var v_split = v_mapping.split("=");
    try {
        if (v_inputmappingfield == '')
            v_inputmappingfield = v_split[1];
        var v_control = $get(v_split[1]);
        var v_isrequired = v_control.getAttribute("required");
        var v_errormessage = v_control.getAttribute("error");
        if (v_isrequired == 'true') {
            v_value = getInputValue(v_control);
            if (!checkRequired(v_control, v_value)) {
                hideWorking();
                v_validinput = false;
                try {
                    if (v_errormessage.length > 0)
                        alert(v_errormessage);
                }
                catch (ex) { }
                v_control.focus();
            }
        }
    }
    catch (e) {}
    return v_validinput;
}

function checkRequired(v_control, v_value) {
    var v_valid = true;
    switch (v_control.type) {
        case 'textarea':
            v_valid = (v_value.length > 0);
            break;
        case 'text':
        case 'password':
        case 'select-one':
            v_valid = (v_value.length > 0);
            if (v_valid) {
                v_type = v_control.getAttribute("webtype");
                if (v_type == 'webshop:intinput') {
                    var v_int = 0;
                    try {
                        v_int = parseInt(v_value);
                    }
                    catch (e) { }
                    v_valid = (v_int > 0);
                }
            }
            break;
        case 'checkbox':
            v_valid = (v_value.toLowerCase() == 'true');
            break;
    }
    return v_valid;
}

//***
function radioIndexChanged(v_action, v_params, v_panel, v_confirm) {
    doAction(v_action, v_panel, v_params, v_confirm, '', '');
}
function selectedIndexChanged(v_controlname, v_action, v_params) {
    if (v_action == 0) { // RESET
        var v_split = v_params.split(",");
        for (var v_i = 0; v_i < v_split.length; v_i++) {
            try
            {
                $get( v_split[v_i] ).value = '';
            }
            catch (e) {}
        }
    }
    else {
        switch (v_action) {
        case 23: // CHANGE DELIVERY
            doAction( v_action, v_params, getInputControlValue(v_controlname),'','','');
            break;
        case 29: // CHANGE SHIPMETHOD
            doAction(v_action, v_params, getInputControlValue(v_controlname), '', '', '');
            break;
        case 32: // CHANGE PAYMENT
            doAction(v_action, v_params, getInputControlValue(v_controlname), '', '', '');
            break;
        case 58: // CHANGE DOCUMENT
            var v_splitx = v_params.split(",");
            v_x = getInputControlValue(v_controlname) + ',' + v_splitx[1];
            doAction(v_action, v_splitx[0], v_x, '', '', v_splitx[0]);
            break;
        case 84: // CHANGE DOCUMENT
            var v_splitx1 = v_params.split(",");
            v_x = getInputControlValue(v_controlname) + ',' + v_splitx1[1];
            doAction(v_action, v_splitx1[0], v_x, '', '', v_splitx1[0]);
            break;
        case 64:
            try {
                var v_controls = v_params.split(",");
                checkCalendar(getInputControlValue(v_controlname), v_controlname, v_controls[0], v_controls[1], v_controls[2]);
            }
            catch (e) { }
            break;
        case 73:
            v_x = getInputControlValue(v_controlname);
            doAction(v_action, v_params, v_x, '', '', v_params);
            break;
        case 88:
            v_sortvalue = getInputControlValue(v_controlname);
            doAction(v_action, v_params, v_sortvalue, '', '', v_params);
            break;
    }
    }
}

function checkCalendar(v_selectedvalue, v_controlname, v_controlday, v_controlmonth, v_controlyear) {
    var v_day = $get(v_controlday);
    var v_month = $get(v_controlmonth);
    var v_year = $get(v_controlyear);
    if (v_selectedvalue == 0) {
        v_day.value = 0;
        v_month.value = 0;
        v_year.value = 0;
    }
    else {
        if (v_day.value == 0)
            v_day.value = 1;
        if (v_month.value == 0)
            v_month.value = 1;
        if (v_year.value == 0)
            v_year.selectedIndex = 1;

        if (v_month.value == 2) {
            if (((v_year.value % 4 == 0) && (v_year.value % 100 != 0)) || (v_year.value % 400 == 0)) { // leap year
                if (v_day.value > 29) {
                    v_day.value = 29;
                }
            }
            else { if (v_day.value > 28) { v_day.value=28; } }
        }
        if ((v_month.value == 4) || (v_month.value == 6) || (v_month.value == 9) || (v_month.value == 11)) {
            if (v_day.value > 30) { v_day.value=30; }
        }
    }
}


//*** VAT VALIDATION
function validateVatno(v_countrycontrol, v_vatcontrol) {
    v_inservice = 1;
    var v_countrycode = getInputControlValue(v_countrycontrol);
    var v_vat = getInputControlValue(v_vatcontrol);
    //***
    if (v_vat.length == 0) {
        v_inservice = 0;
        return;
    }
    //***
    try {
        var v_p = new WebShop.Framework.Web.Service.VatParameters();
        v_p.countrycode = v_countrycode;
        v_p.vatno = v_vat;
        v_p.vatnocontrol = v_vatcontrol;
        v_p.result = '';
        var service = WebShop.Framework.Web.Service.WebShop.CheckVat(v_p, validateVatnoCompleted);
    }
    catch (e) {
        v_inservice = 2;
    }
}
function validateVatnoCompleted(v_result) {
    var v_split = v_result.result.split(";");
    var v_control = $get(v_result.vatnocontrol);
    switch (v_split[0]) {
        case '0':
            v_inservice = 0;
            return true;
        case '1':
            break;
        case '2':
            alert(v_split[1]);
            v_control.focus();
            v_inservice = 2;
            return false;
    }
    var v_errormessage = v_control.getAttribute("validateerror");
    if (v_errormessage.length > 0)
        alert(v_errormessage);
    v_control.focus();
    v_inservice = 2;
    return false;
}

//*** PASSWORD VALIDATION
function validatePassword(v_pwdcontrol1, v_pwdcontrol2) {
    v_inservice = 1;
    try
    {
        v_control1 = $get(v_pwdcontrol1);
        v_control2 = $get(v_pwdcontrol2);
        if (v_control2.value.length > 0) {
            if (v_control1.value != v_control2.value) {
                var v_errormessage = v_control2.getAttribute("validateerror");
                if (v_errormessage.length > 0)
                    alert(v_errormessage);
                v_control2.focus();
                v_inservice = 2;
                return false;
            }
        }
    }
    catch (e) {
        v_inservice = 2;
        return false;
    }
    //***
    v_inservice = 0;
    return true;
}

//*** POSTCODE VALIDATION
function validatePostcode(v_countrycontrol, v_postcodecontrol, v_citycontrol) {
    v_inservice = 1;
    //***
    var v_countrycode = getInputControlValue(v_countrycontrol);
    var v_postcode = getInputControlValue(v_postcodecontrol);
    //***
    if ((!v_informvalidation) && (v_postcode.length == 0)) {
        v_inservice = 0;
        return;
    }
    //***
    try {
        var v_p = new WebShop.Framework.Web.Service.PostcodeParameters();
        v_p.countrycode = v_countrycode;
        v_p.postcode = v_postcode;
        v_p.postcodecontrol = v_postcodecontrol;
        v_p.citycontrol = v_citycontrol;
        v_p.result = '';
        var service = WebShop.Framework.Web.Service.WebShop.CheckPostcode(v_p, validatePostcodeCompleted);
    }
    catch (e) {
        v_inservice = 2;
    }
}
function validatePostcodeCompleted(v_result) {
    var v_split = v_result.result.split(";");
    var v_control = $get(v_result.postcodecontrol);
    switch (v_split[0]) {
        case '0':
            v_control.value = v_split[2];
            v_control = $get(v_result.citycontrol);
            if (v_control.value.length == 0)
                v_control.value = v_split[1];
            v_inservice = 0;
            return true;
        case '1':
            break;
        case '2':
            alert(v_split[1]);
            v_control.focus();
            v_inservice = 2;
            return false;
            break;
    }
    var v_errormessage = v_control.getAttribute("validateerror");
    if (v_errormessage.length > 0)
        alert(v_errormessage);
    v_control.focus();
    v_inservice = 2;
    return false;
}

//*** EMAIL VALIDATION
function validateEmail(v_emailcontrol) {
    v_inservice = 1;
    var v_email = '';
    var v_control = $get(v_emailcontrol);
    try {
        v_email = v_control.value;
    }
    catch (e) { }
    //***
    if (v_email.length > 0) {
        if (emailCheck(v_email) != 0) {
            var v_errormessage = v_control.getAttribute("validateerror");
            if (v_errormessage.length > 0)
                alert(v_errormessage);
            v_control.focus();
            v_inservice = 2;
            return;
        }
    }
    v_inservice = 0;
    return;
}
function emailCheck(emailStr) {
    var checkTLD = 1;
    var knownDomsPat = /^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
    var emailPat = /^(.+)@(.+)$/;
    var specialChars = "\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
    var validChars = "\[^\\s" + specialChars + "\]";
    var quotedUser = "(\"[^\"]*\")";
    var ipDomainPat = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
    var atom = validChars + '+';
    var word = "(" + atom + "|" + quotedUser + ")";
    var userPat = new RegExp("^" + word + "(\\." + word + ")*$");
    var domainPat = new RegExp("^" + atom + "(\\." + atom + ")*$");
    var matchArray = emailStr.match(emailPat);
    //***
    if (matchArray == null) {
        return 1;
    }
    var user = matchArray[1];
    var domain = matchArray[2];
    for (i = 0; i < user.length; i++) {
        if (user.charCodeAt(i) > 127) {
            return 2;
        }
    }
    //***
    for (i = 0; i < domain.length; i++) {
        if (domain.charCodeAt(i) > 127) {
            return 3;
        }
    }
    if (user.match(userPat) == null) {
        return 4;
    }
    var IPArray = domain.match(ipDomainPat);
    if (IPArray != null) {
        for (var i = 1; i <= 4; i++) {
            if (IPArray[i] > 255) {
                return 5;
            }
        }
        return 0;
    }
    //***
    var atomPat = new RegExp("^" + atom + "$");
    var domArr = domain.split(".");
    var len = domArr.length;
    for (i = 0; i < len; i++) {
        if (domArr[i].search(atomPat) == -1) {
            return 6;
        }
    }
    if (checkTLD && domArr[domArr.length - 1].length != 2 && domArr[domArr.length - 1].search(knownDomsPat) == -1) {
        return 7;
    }
    if (len < 2) {
        return 8;
    }
    return 0;
}

//***
function doSetComponentItem(v_actionparameters) {
    try {
        var service = WebShop.Framework.Web.Service.WebShop.SetComponentItem(v_actionparameters, doSetComponentItemCompleted);
    }
    catch (e) {
        hideWorking();
        v_clicked = false;
    }
}
function doSetComponentItemCompleted(v_result) {
    if (v_result.ShowConfirm == 1) {
        if (!confirm(v_result.Confirm)) {
            hideWorking();
            v_clicked = false;
            updatePanel('up' + v_result.UpdatePanel);
            return;
        }
    }
    doAction(v_result.Action, v_result.UpdatePanel, v_result.Parameters, v_result.BreadCrump,v_result.Javascript, v_result.ContentPanel);
}

//*** ACTIVATE ACCOUNT
function doActivateAccountAction(v_actionparameters) {
    try {
        var v_p = new WebShop.Framework.Web.Service.UserParameters();
        v_p = fillServiceParamsWithInputFields(v_p, v_actionparameters.Parameters);
        var service = WebShop.Framework.Web.Service.WebShop.ProcessActivateAccountRequest(v_actionparameters, v_p, processActivateAccountCompleted);
    }
    catch (e) {
        hideWorking();
        v_clicked = false;
    }
    return;
}
function processActivateAccountCompleted(v_result) {
    if (v_result.Result == -1) {
        updatePanel(v_result.UpdatePanel);
        return;
    }
    alert(v_result.Message);
    v_clicked = false;
    hideWorking();
}

//*** NEW CREDIT
function doNewCreditAction(v_actionparameters) {
    try {
        var v_p = new WebShop.Framework.Web.Service.CreditParameters();
        v_p = fillServiceParamsWithInputFields(v_p, v_actionparameters.Parameters);
        var service = WebShop.Framework.Web.Service.WebShop.ProcessNewCreditRequest(v_actionparameters, v_p, processNewCreditCompleted);
    }
    catch (e) {
        v_clicked = false;
        hideWorking();
    }
    return;
}
function processNewCreditCompleted(v_result) {
    if (v_result.Result == -1) {
        updatePanel(v_result.UpdatePanel);
        return;
    }
    alert(v_result.Message);
    v_clicked = false;
    hideWorking();
}

//*** Docuemnt Filter List
function doDocumentFilterAction(v_actionparameters) {
    try {
        var v_p = new WebShop.Framework.Web.Service.DocumentFilterParameters();
        v_p = fillServiceParamsWithInputFields(v_p, v_actionparameters.Parameters);
        var service = WebShop.Framework.Web.Service.WebShop.ProcessDocumentFilterAction(v_actionparameters, v_p, processDocumentFilterActionCompleted);
    }
    catch (e) {
        v_clicked = false;
        hideWorking();
    }
    return;
}
function processDocumentFilterActionCompleted(v_result) {
    if (v_result.Result == -1) {
        updatePanel(v_result.UpdatePanel);
        return;
    }
    alert(v_result.Message);
    v_clicked = false;
    hideWorking();
}



//*** NEW RMA
function doNewRmaAction(v_actionparameters) {
    try {
        var v_p = new WebShop.Framework.Web.Service.RMAParameters();
        v_p = fillServiceParamsWithInputFields(v_p, v_actionparameters.Parameters);
        var service = WebShop.Framework.Web.Service.WebShop.ProcessNewRMARequest(v_actionparameters, v_p, processNewRmaCompleted);
    }
    catch (e) {
        v_clicked = false;
        hideWorking();
    }
    return;
}
function processNewRmaCompleted(v_result) {
    if (v_result.Result == -1) {
        updatePanel(v_result.UpdatePanel);
        return;
    }
    alert(v_result.Message);
    v_clicked = false;
    hideWorking();
}



//*** CHANGE PASSWORD
function doChangePasswordAction(v_actionparameters) {
    try {
        var v_p = new WebShop.Framework.Web.Service.UserFormParameters();
        v_p = fillServiceParamsWithInputFields(v_p, v_actionparameters.Parameters);
        var service = WebShop.Framework.Web.Service.WebShop.ProcessChangePasswordRequest(v_actionparameters, v_p, processChangePasswordCompleted);
    }
    catch (e) {
        v_clicked = false;
        hideWorking();
    }
    return;
}
function processChangePasswordCompleted(v_result) {
    if (v_result.Result == -1) {
        updatePanel(v_result.UpdatePanel);
        return;
    }
    alert(v_result.Message);
    v_clicked = false;
    hideWorking();
}



//*** NEW USER
function doNewUserAction(v_actionparameters) {
    try {
        var v_p = new WebShop.Framework.Web.Service.UserFormParameters();
        v_p = fillServiceParamsWithInputFields(v_p, v_actionparameters.Parameters);
        var service = WebShop.Framework.Web.Service.WebShop.ProcessNewUserRequest(v_actionparameters, v_p, processNewUserCompleted);
    }
    catch (e) {
        v_clicked = false;
        hideWorking();
    }
    return;
}
function processNewUserCompleted(v_result) {
    if (v_result.Result == -1) {
        updatePanel(v_result.UpdatePanel);
        return;
    }
    alert(v_result.Message);
    v_clicked = false;
    hideWorking();
}

//*** CHANGE USER
function doChangeUserAction(v_actionparameters) {
    try {
        var v_p = new WebShop.Framework.Web.Service.UserFormParameters();
        v_p = fillServiceParamsWithInputFields(v_p, v_actionparameters.Parameters);
        var service = WebShop.Framework.Web.Service.WebShop.ProcessChangeUserRequest(v_actionparameters, v_p, processNewUserCompleted);
    }
    catch (e) {
        v_clicked = false;
        hideWorking();
    }
    return;
}


//*** NEW ACCOUNT
function doNewAccountAction(v_actionparameters) {
    try {
        var v_p = new WebShop.Framework.Web.Service.UserParameters();
        v_p = fillServiceParamsWithInputFields(v_p, v_actionparameters.Parameters);
        var service = WebShop.Framework.Web.Service.WebShop.ProcessNewAccountRequest(v_actionparameters, v_p, processNewAccountCompleted);
    }
    catch (e) {
        v_clicked = false;
        hideWorking();
    }
    return;
}
function processNewAccountCompleted(v_result) {
    if (v_result.Result == -1) {
        updatePanel(v_result.UpdatePanel);
        return;
    }
    alert(v_result.Message);
    v_clicked = false;
    hideWorking();
}

//*** NEW DELIVERY ADDRESS
function doNewDeliveryAction(v_actionparameters) {
    try {
        var v_p = new WebShop.Framework.Web.Service.UserParameters();
        v_p = fillServiceParamsWithInputFields(v_p, v_actionparameters.Parameters);
        var service = WebShop.Framework.Web.Service.WebShop.ProcessNewDeliveryRequest(v_actionparameters, v_p, processNewDeliveryCompleted);
    }
    catch (e) {
        v_clicked = false;
        hideWorking();
    }
    return;
}
function processNewDeliveryCompleted(v_result) {
    if (v_result.Result == -1) {
        updatePanel(v_result.UpdatePanel);
        return;
    }
    alert(v_result.Message);
    v_clicked = false;
    hideWorking();
}

//*** COMMIT CHANGES  DELIVERY ADDRESS
function doCommitInvoiceAddressAction(v_actionparameters) {
    try {
        var v_p = new WebShop.Framework.Web.Service.UserParameters();
        v_p = fillServiceParamsWithInputFields(v_p, v_actionparameters.Parameters);
        var service = WebShop.Framework.Web.Service.WebShop.ProcessCommitInvoiceAddressRequest(v_actionparameters, v_p, processCommitInvoiceAddressCompleted);
    }
    catch (e) {
        v_clicked = false;
        hideWorking();
    }
    return;
}
function processCommitInvoiceAddressCompleted(v_result) {
    if (v_result.Result == -1) {
        updatePanel(v_result.UpdatePanel);
        return;
    }
    alert(v_result.Message);
    v_clicked = false;
    hideWorking();
}


//*** COMMIT CHANGES  DELIVERY ADDRESS
function doCommitDeliveryAction(v_actionparameters) {
    try {
        var v_p = new WebShop.Framework.Web.Service.UserParameters();
        v_p = fillServiceParamsWithInputFields(v_p, v_actionparameters.Parameters);
        var service = WebShop.Framework.Web.Service.WebShop.ProcessCommitDeliveryRequest(v_actionparameters, v_p, processCommitDeliveryCompleted);
    }
    catch (e) {
        v_clicked = false;
        hideWorking();
    }
    return;
}
function processCommitDeliveryCompleted(v_result) {
    if (v_result.Result == -1) {
        updatePanel(v_result.UpdatePanel);
        return;
    }
    alert(v_result.Message);
    v_clicked = false;
    hideWorking();
}

//*** DELETE DELIVERY ADDRESS
function doDeleteDeliveryAction(v_actionparameters) {
    try {
        var service = WebShop.Framework.Web.Service.WebShop.ProcessDeleteDeliveryRequest(v_actionparameters, processDeleteDeliveryCompleted);
    }
    catch (e) {
        v_clicked = false;
        hideWorking();
    }
    return;
}
function processDeleteDeliveryCompleted(v_result) {
    if (v_result.Result == -1) {
        updatePanel(v_result.UpdatePanel);
        return;
    }
    alert(v_result.Message);
    v_clicked = false;
    hideWorking();
}

//*** DELETE USER
function doDeleteUserAction(v_actionparameters) {
    try {
        var service = WebShop.Framework.Web.Service.WebShop.ProcessDeleteUserRequest(v_actionparameters, processDeleteUserCompleted);
    }
    catch (e) {
        v_clicked = false;
        hideWorking();
    }
    return;
}
function processDeleteUserCompleted(v_result) {
    if (v_result.Result == -1) {
        updatePanel(v_result.UpdatePanel);
        return;
    }
    alert(v_result.Message);
    v_clicked = false;
    hideWorking();
}




//*** LOGIN
function doLoginAction(v_actionparameters) {
    try {
        var v_p = new WebShop.Framework.Web.Service.LoginParameters();
        v_p = fillServiceParamsWithInputFields(v_p, v_actionparameters.Parameters);
        var service = WebShop.Framework.Web.Service.WebShop.ProcessLoginRequest(v_actionparameters, v_p, processLoginCompleted);
    } catch (e) {
        v_clicked = false;
        hideWorking();
    }
    return;
}
function processLoginCompleted(v_result) {
    if (v_result.Result == -1) {
        var service = WebShop.Framework.Web.Service.WebShop.NavigateFromHistory(v_currentcounter, v_currentcounter, '', setHistoryCompleted); 
        // updatePanel(v_result.UpdatePanel);
        return;
    }
    alert(v_result.Message);
    v_clicked = false;
    hideWorking();
    setFocusOnField(v_inputmappingfield);
}

function setFocusOnField(v_controlname) {
    try {
        $get(v_controlname).focus();
    }
    catch (e) { }
}


//*** FORGOT PASSWORD
function doForgotPasswordAction(v_actionparameters) {
    try {
        var v_p = new WebShop.Framework.Web.Service.LoginParameters();
        v_p = fillServiceParamsWithInputFields(v_p, v_actionparameters.Parameters);
        var service = WebShop.Framework.Web.Service.WebShop.ProcessForgotPasswordRequest(v_actionparameters, v_p, processForgotPasswordCompleted);
    } catch (e) {
        v_clicked = false;
        hideWorking();
    }
    return;
}
function processForgotPasswordCompleted(v_result) {
    if (v_result.Result == -1) {
        updatePanel(v_result.UpdatePanel);
        return;
    }
    alert(v_result.Message);
    v_clicked = false;
    hideWorking();
}

//*** Commit Order
function doCommitOrderAction(v_actionparameters) {
    var service = WebShop.Framework.Web.Service.WebShop.PreProcessOrder(v_actionparameters, doCommitOrderActionCompleted);
}    
function doCommitOrderActionCompleted(v_actionparameters) {


    var v_args;
    var v_mapping = v_actionparameters.ContentPanel.split(",");

    if (v_mapping[0] == '2') { // ERROR
        alert(v_mapping[1]);
        v_clicked = false;
        hideWorking();
        return;
    }
    
    
    if (v_mapping[0] == '0') {
        if (v_mapping[1].length > 0) {
            if (!confirm(v_mapping[1])) {
                v_clicked = false;
                hideWorking();
                return;
            }
            commitOrderAction(v_actionparameters);                
            return;
        }
    }
    //***
    if (v_mapping[0] == '1') {
        v_inexternpayment = true;
        v_payresult = 0;
        v_payparams = v_actionparameters;
        // v_inpaymentmodule = true;
        v_clicked = false;
        hideWorking();
        //***
        var service = WebShop.Framework.Web.Service.WebShop.SetPaymentValue(v_actionparameters, showPayment2);
    }
}

function showPayment2(v_result) {
    // Set_Cookie('externalpay', '99', '10', '/', '', '');
    // Set_Cookie('externaldocno', v_result, '10', '/', '', '');
    showPayment();
}


function commitOrderAction(v_actionparameters) {
    var service = WebShop.Framework.Web.Service.WebShop.ProcessOrder(0,v_actionparameters, commitOrderActionCompleted);
}
function commitOrderActionCompleted(v_result) {
    if (v_result.Result == -1) {
        doWebsiteECommerceTracking(v_result);
        if (v_result.Message.length > 0)
            alert(v_result.Message);
        updatePanel(v_result.UpdatePanel);
        return;
    }
    alert(v_result.Message);
    v_clicked = false;
    hideWorking();
}

function doCheckConfigurationAction(v_actionparameters) {
    var service = WebShop.Framework.Web.Service.WebShop.CheckConfiguration(v_actionparameters, doCheckConfigurationActionCompleted);
}
function doCheckConfigurationActionCompleted(v_result) {
    if (v_result.Action == 42) {
        if ( v_result.Parameters.length > 0 )
            alert(v_result.Parameters);
        v_clicked = false;
        hideWorking();
        return;
    }
    //***
    var v_splitx = v_result.ContentPanel.split(",");
    var v_params = v_splitx[0] + ',' + v_splitx[1] + ',' + v_splitx[3];
    var v_contentpanelid = v_splitx[2];
    //***
    doAction(v_result.Action, v_result.UpdatePanel, v_params, v_result.BreadCrump, v_result.Javascript, v_contentpanelid);
}




//**** GENERAL FUNCTIONS
function fillServiceParamsWithInputFields( v_p, v_mappings ) {
    var v_mapping = v_mappings.split(",");
    for (var v_i = 0; v_i < v_mapping.length; v_i++)
        v_p = fillServiceParameter(v_p, v_mapping[v_i]);
    return v_p;
}
function fillServiceParameter(v_p, v_mapping) {
    var v_split = v_mapping.split("=");
    var v_value = '';
    try {
        var v_control = $get(v_split[1]);
        v_value = getInputValue(v_control);
    }
    catch (e) {}
    try {
        // var v_macro = "v_p." + v_split[0].toLowerCase() + "='" + escape(v_value) + "'";
        var v_macro = "v_p." + v_split[0].toLowerCase() + "='" + v_value.replace("'", "''") + "'";
        if (v_value.indexOf("'") >= 0)
            v_macro = 'v_p.' + v_split[0].toLowerCase() + '="' + v_value + '"';
        eval(v_macro);
    }
    catch (e) {
        // alert(e.Message);
    }
    return v_p;
}
function getInputValue(v_control) {
    var v_value = '';
    try {
        switch (v_control.type) {
            case 'textarea':
            case 'text':
            case 'password':
            case 'select-one':
                v_value = '' + v_control.value;
                break;
            case 'checkbox':
                v_value = '' + v_control.checked;
                break;
        }
    }
    catch (e) { }
    return v_value;
}
function getInputControlValue(v_controlname) { 
    var v_value = '';
    try {
        var v_control = $get(v_controlname);
        v_value = getInputValue(v_control);
    }
    catch (e) {
    }
    return v_value;
}


function updatePanel(v_panelid) {
    try {
        __doPostBack(v_panelid, '');
    }
    catch (err) {
        // alert(err.description);
    }
}
function setActionCompleted(v_panelid) {
    updatePanel(v_panelid);
}

function setActionParameters(v_actionid, v_panelid, v_params, v_breadcrump, v_javascript, v_contentpanelid,v_fromhistory) {
    var v_p = new WebShop.Framework.Web.Service.ActionParameters();
    v_p.Action = v_actionid;
    v_p.UpdatePanel = v_panelid;
    v_p.Parameters = v_params;
    v_p.BreadCrump = v_breadcrump;
    v_p.Javascript = v_javascript;
    v_p.ContentPanel = v_contentpanelid;
    v_p.FromHistory = v_fromhistory;
    v_p.HistoryCounter = v_hist_counter;
    v_p.HistoryTopic = v_hist_topic;
    v_p.HistoryExtraParam = v_hist_extraparam;
    v_p.HistoryExtraParamContent = v_hist_extraparamcontent;
    v_p.HistoryExtraParamContentPanel = v_hist_extraparamcontentpanel;
    //***
    $get('hfaction').value = v_actionid;
    $get('hfparams').value = v_params;
    //***    
    return v_p;
}
function setVisible(v_elementid, v_visible) {
    try {
        if (v_visible)
            $get(v_elementid).style.display = '';
        else
            $get(v_elementid).style.display = 'none';
    }
    catch (e) { }
}
function integerInput(v_control) {
    event.returnValue = false;
    if ((event.keyCode >= 48) && (event.keyCode <= 57)) {
        event.returnValue = true;
        return;
    }
}

function openDialog(v_page, v_args, v_width, v_height) {
    var v_left = 200;
    var v_top = 200;
    var v_settings = 'width=' + v_width + ',height=' + v_height + ',top=' + v_top + ',left=' + v_left + ',location=0,directories=0,status=0,menubar=0,toolbar=0,resizable=0';
    try {
        var v_win = window.open(v_page, v_args, v_settings);
        v_winpayment = v_win;
    }
    catch (e) {
    }
}
function openPrintDialog(v_page, v_args, v_width, v_height) {
    var v_left = 0;
    var v_top = 0;
    var v_settings = 'width=' + v_width + ',height=' + v_height + ',top=' + v_top + ',left=' + v_left + ',location=0,directories=0,status=0,menubar=0,toolbar=0,resizable=1';
    try {
        var v_win = window.open(v_page, v_args, v_settings);
    }
    catch (e) {
    }
}

function setWorking() { 
    var v_object = $get('modalpopup');
    var v_height = 2000;
    var v_width = 2000;
    //***
    if (navigator.appName == "Netscape") {
        v_width = window.innerWidth;
        v_height = window.innerHeight;
    }
    if (navigator.appName.indexOf("Microsoft") != -1) {
        v_width = document.body.offsetWidth + 20;
        v_height = document.documentElement.clientHeight;
    }
    if (typeof (window.innerWidth) == 'number') {
        v_width = window.innerWidth;
        v_height = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
            //IE 6+ in 'standards compliant mode'
        v_width = document.documentElement.clientWidth;
        v_height = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        v_width = document.body.clientWidth;
        v_height = document.body.clientHeight;
    }
    var iebody = (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body
    var dsocleft = document.all ? iebody.scrollLeft : pageXOffset
    var dsoctop = document.all ? iebody.scrollTop : pageYOffset
    var v_w = document.all ? iebody.clientWidth : window.innerWidth;
    v_object.style.top = "0px";
    v_object.style.left = "0px";
    v_object.style.width = (v_w) + "px";
    v_object.style.height = "2000px";
    v_object.style.display = '';



    // var v_w = document.all ? iebody.clientWidth : window.innerWidth;
    var v_h = document.all ? iebody.clientHeight : window.innerHeight;
    var v_object2 = $get('modalpopupcontent');
    v_object2.style.top = dsoctop + "px";
    v_object2.style.left = "0px";
    // v_object2.style.width = (v_w - 650)+ "px";
    v_object2.style.width = (v_w - 800) + "px";
    v_object2.style.height = v_h + "px";
    v_object2.style.paddingLeft = "45%";
    v_object2.style.paddingTop = "20%";

    setVisible('modalpopupcontent', true);
}

function setTimer() {
    setTimeout('checkDialog()', 500)
}
function checkDialog() {
    if (v_winpayment && !v_winpayment.closed && v_winpayment.focus) {
        // v_winpayment.focus();
    }
    else {
        v_winpayment = null;
        if (v_inpaymentmodule) {
            v_inpaymentmodule = false;
            processExternalPayment();
            return;
        }
    }
    setTimer();
}
function processExternalPayment() {
    var service = WebShop.Framework.Web.Service.WebShop.ProcessExternalPayment(v_payresult, v_payparams, processExternalPaymentCompleted);
}
function processExternalPaymentCompleted(v_result) {
    if (v_result.Result == -1) {
        doWebsiteECommerceTracking(v_result);
        if (v_result.Message.length > 0)
            alert(v_result.Message);
        updatePanel(v_result.UpdatePanel);
        return;
    }
    alert(v_result.Message);
    v_clicked = false;
    hideWorking();
}
function processExternalPaymentFromCoockieCompleted(vResult) {
    if (vResult.Result == -1) {
        doWebsiteECommerceTracking(vResult);
        if (vResult.Message.length > 0)
            alert(vResult.Message);
        updatePanel(vResult.UpdatePanel);
        return;
    }
    alert(vResult.Message);
    v_clicked = false;
    hideWorking();
}


function hideWorking() {
    setVisible('modalpopup', false);
    setVisible('modalpopupcontent', false);
}
// function setPaymentValue( v_value ){
//     var service = WebShop.Framework.Web.Service.WebShop.ProcessExternalPayment(v_value, v_payparams, processExternalPaymentCompleted);
// }
function openImgSmallPopup(el, url) {
    v_inshowpicture = true;
    var bpop = document.getElementById('imgpopupdiv');
    if (bpop) {
   
        var pos = findPos(el);
        // var orgpos = findPos(document.getElementById('imgpopupdivorgpos'));
        bpop.style.left = ((pos[0] - 3) ) + 'px';
        bpop.style.top = ((pos[1] - 1)) + 'px';
        bpop.innerHTML = '<div style="width: 200px; height: 150px; overflow: hidden; background-color: #FFF; text-align: left;"><img src="' + url + '" alt="" id="imgpopupdivimg" /></div>';
        bpop.style.display = '';
    }
}
function openImgLargePopup(el, url) {
    v_inshowpicture = true;
    var bpop = document.getElementById('imgpopupdivlarge');
    if (bpop) {

        var pos = findPos(el);
        // var orgpos = findPos(document.getElementById('imgpopupdivorgpos'));
        bpop.style.left = ((pos[0] - 3)) + 'px';
        bpop.style.top = ((pos[1] - 1)) + 'px';
        bpop.innerHTML = '<div style="width: 400px; height: 350px; overflow: hidden; background-color: #FFF; text-align: left;"><img src="' + url + '" alt="" id="imgpopupdivimg" /></div>';
        bpop.style.display = '';
    }
}
function findPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft
            curtop += obj.offsetTop
        }
    }
    return [curleft, curtop];
}
function checkPopup() {
    if (!v_inshowpicture) {
        setVisible('imgpopupdiv', false);
        setVisible('imgpopupdivlarge', false);
        setVisible('divinventory', false);
    }
    v_inshowpicture = false;
}
function openInventory(el) {
    v_inshowpicture = true;
    var bpop = document.getElementById('divinventory');
    var binv = document.getElementById('popupinventory');
    if (bpop) {
        var pos = findPos(el);
        bpop.style.left = ((pos[0] - 3)) + 'px';
        bpop.style.top = ((pos[1] + 15)) + 'px';
        bpop.innerHTML = binv.innerHTML
        bpop.style.display = '';
    }
}


function checkForEnter(v_control, v_submitid, e) {
    var v_keycode = e.which ? e.which : e.keyCode;
    if (v_keycode == 13) {
        v_control.disabled = true;
        v_control.disabled = false;
        e.preventDefault ? e.preventDefault() : e.returnValue = false; 
        clickElement(v_submitid);
    }
}

function clickElement(elementid) {
    var e = document.getElementById(elementid);
    if (typeof e == 'object') {
        if (document.createEvent) {
            var evObj = document.createEvent('MouseEvents');
            evObj.initEvent('click', true, true);
            e.dispatchEvent(evObj);
            return false;
        }
        else if (document.createEventObject) {
            e.fireEvent('onclick');
            return false;
        }
        else {
            e.click();
            return false;
        }
    }
}

function pageInit() {
    Sys.Application.add_navigate(onStateChanged);
    // Sys.Application.add_pageLoaded(pageLoaded);
    
}

function onStateChanged(sender, e) {
    if (v_cannavigate) {
        var v_val = parseInt(e.get_state().id || '0');
        if (v_currentcounter != v_val) {
            var v_topic = '';
            if (typeof (e.get_state().id) != "undefined")
                v_topic = e.get_state().id;
            var v_old = v_currentcounter;
            setWorking();
            v_currentcounter = v_val;
            var service = WebShop.Framework.Web.Service.WebShop.NavigateFromHistory(v_currentcounter, v_old, v_topic, setHistoryCompleted);
            return;
        }
    }
}

function setCustomerTypeCompleted() {
    v_clicked = false;
    hideWorking();
}

function showPayment() {
    window.scrollTo(0, 0);
    
    var v_object = $get('modalpopup');
    var v_height = 2000;
    var v_width = 2000;
    //***
    if (navigator.appName == "Netscape") {
        v_width = window.innerWidth;
        v_height = window.innerHeight;
    }
    if (navigator.appName.indexOf("Microsoft") != -1) {
        v_width = document.body.offsetWidth + 20;
        v_height = document.documentElement.clientHeight;
    }
    if (typeof (window.innerWidth) == 'number') {
        v_width = window.innerWidth;
        v_height = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        v_width = document.documentElement.clientWidth;
        v_height = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        v_width = document.body.clientWidth;
        v_height = document.body.clientHeight;
    }
    var iebody = (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body
    var dsocleft = document.all ? iebody.scrollLeft : pageXOffset
    var dsoctop = document.all ? iebody.scrollTop : pageYOffset
    var v_w = document.all ? iebody.clientWidth : window.innerWidth;
    v_object.style.top = "0px";
    v_object.style.left = "0px";
    v_object.style.width = (v_w) + "px";
    v_object.style.height = "2000px";
    v_object.style.display = '';
    // v_object.style.backgroundColor = 'Black';

    // alert(dsoctop);



    v_mid = $get('upmaincontainer');

    // var v_w = document.all ? iebody.clientWidth : window.innerWidth;
    var v_h = document.all ? iebody.clientHeight : window.innerHeight;
    var v_object2 = $get('divpayment');
    // v_object2.style.top = dsoctop + "px";
    v_object2.style.top = "0px";
    v_object2.style.left = "0px";
    v_object2.style.width = "790px";
    v_object2.style.height = "570px";
    v_object2.style.paddingLeft = (v_mid.offsetLeft + 195) + "px";
    v_object2.style.paddingTop = "205px";
    v_object2.innerHTML = '<div class="secured">Ogone: Identified by VeriSign</div><iframe frameborder="0" width="100%" height="95%" src="page/form.aspx"></iframe>';
    setVisible('divpayment', true);
}

function setPaymentValue(v_value) {
    Delete_Cookie('externalpay', '/', '');
    var v_object2 = $get('divpayment');
    v_object2.innerHTML = "";
    setVisible('divpayment', false);
    setVisible('modalpopup', false);
    setWorking();
    if (v_value > 100) {
        var service1 = WebShop.Framework.Web.Service.WebShop.ProcessExternalPayment(v_value - 101, v_payparams, processExternalPaymentFromCoockieCompleted);
    }
    else
        var service2 = WebShop.Framework.Web.Service.WebShop.ProcessExternalPayment(v_value, v_payparams, processExternalPaymentCompleted);
}

function ProcessExternalPaymentWithErrorCompleted(v_result) {
    var v_post = 0;
    if (confirm(v_result))
        v_post = 1;
    setWorking();
    v_orderno = Get_Cookie('externaldocno');
    Delete_Cookie('externaldocno', '/', '');
    var service1 = WebShop.Framework.Web.Service.WebShop.ProcessExternalPaymentWithErrorPost(v_post, v_orderno, ProcessExternalPaymentWithErrorPostCompleted);
}

function ProcessExternalPaymentWithErrorPostCompleted(v_result) {
    // if (v_result.Result == -1) {
        // doWebsiteECommerceTracking(v_result);
    // }
    if (v_result.Message.length > 0)
        alert(v_result.Message);
    v_clicked = false;
    hideWorking();
}


function doPageTracking(v_action, v_params, v_search) {
    try
    {
    v_search = v_search.replace(" ", "%20");
    }
    catch (e) { }
    //***
    if (v_action == 8) {
        var service = WebShop.Framework.Web.Service.WebShop.GetPartnrId(v_action, v_params, v_search, doPageTrackingEnded);
        return;
    }
    TrackPage(v_action, v_params, v_search);
}

function doPageTrackingEnded(v_result) {
    TrackPage(v_result.Result, v_result.Message, v_result.UpdatePanel);
}
function TrackPage(v_action,v_params,v_search)
{
    var v_legend = '/WEBSHOP';
    
    var v_topic = '';
    try {
        v_legend = '/WEBSHOP/' + v_actionlegend[v_action];
        if ((v_action == 3) || (v_action == 4) || (v_action == 5) || (v_action == 8))
            v_legend = v_legend + '/' + v_params.replace(/,/g, "/");
        v_legend = v_legend.replace(/\s/g, "").toUpperCase();

        if (v_search.length > 0) {
            v_legend = v_legend + "?searchval=" + v_search;
        }
    }
    catch (xerr) { }
    //***
    try {
        doWebsitePageTracking(v_legend);
    }
    catch (e) {
    }
}

function SetMoreFilter(v_action, v_panelid, v_params, v_breadcrump, v_javascript, v_contentpanelid) {
    var v_mapping = v_params.split(";");
    var v_parent = v_mapping[0];

    setVisible('m_' + v_parent, false);
    for (var v_i = 1; v_i < v_mapping.length - 1; v_i++) {
        $get('f_' + v_parent + '_' + v_mapping[v_i]).className = 'filterelement';
        $get('c_' + v_parent + '_' + v_mapping[v_i]).className = 'filtercount';
    }
    var servicedef = WebShop.Framework.Web.Service.WebShop.SetAction(setActionParameters(v_action, v_panelid, v_parent, v_breadcrump, v_originaljavascript, v_contentpanelid, 0), SetMoreFilterCompleted);
}

function SetMoreFilterCompleted(v_result) {
    hideWorking();
}

function printInvoice(docno) {
    var v_args;
    openPrintDialog('page/invoice.aspx?doc=' + docno + '&ts=' + Math.random(), v_args, 800, 600);
}

function printDocument(doctype,docno) {
    var v_args;
    openPrintDialog('page/document.aspx?typ=' + doctype + '&doc=' + docno + '&ts=' + Math.random(), v_args, 800, 600);
}

//*** POSTCODE VALIDATION
function validatepartnr(v_partnrcontrol, v_legendcontrol, v_serialnocontrol, v_invoicenocontrol, v_daycontrol, v_monthcontrol, v_yearcontrol) {
    v_inservice = 1;
    //***
    var v_partnrid = getInputControlValue(v_partnrcontrol);
    var v_control = $get(v_partnrcontrol);
    var v_originalvalue = '';
    try {
        if (v_formvalues.containsKey(v_control.id)) {
            v_originalvalue = v_formvalues.get(v_control.id);
        }
    }
    catch (e1) {}
    if ( v_partnrid == v_originalvalue )
    {
        v_inservice = 0;
        return;
    }
    
    
    if ((!v_informvalidation) && (v_partnrid.length == 0)) {
        v_inservice = 0;
        return;
    }
    
    //***
    try {
        var v_p = new WebShop.Framework.Web.Service.PartNrParameters();
        v_p.partnrid = v_partnrid;
        v_p.partnrcontrol = v_partnrcontrol;
        v_p.legentcontrol = v_legendcontrol;
        v_p.serialcontrol = v_serialnocontrol;
        v_p.invoicecontrol = v_invoicenocontrol;
        v_p.daycontrol = v_daycontrol;
        v_p.monthcontrol = v_monthcontrol;
        v_p.yearcontrol = v_yearcontrol;
        v_p.result = '';
        var service = WebShop.Framework.Web.Service.WebShop.CheckPartnrId(v_p, validatepartnrCompleted);
    }
    catch (e) {
        v_inservice = 2;
    }
}
function validatepartnrCompleted(v_result) {
    var v_split = v_result.result.split(";");
    var v_control = $get(v_result.partnrcontrol);
    var v_legendcontrol = $get(v_result.legentcontrol);
    var v_scontrol = $get(v_result.serialcontrol);
    var v_icontrol = $get(v_result.invoicecontrol);

    switch (v_split[0]) {
        case '0':
            v_legendcontrol.innerText = v_split[1];
            v_scontrol.value = '';
            v_icontrol.value = '';
            v_inservice = 0;
            resetFieldValue(v_control);
            v_scontrol.focus();
            return true;
        case '1':
            break;
        case '2':
            alert(v_split[1]);
            v_legendcontrol.innerText = '';
            v_control.focus();
            v_inservice = 2;
            return false;
            break;
    }
    var v_errormessage = v_control.getAttribute("validateerror");
    if (v_errormessage.length > 0)
        alert(v_errormessage);
    v_control.focus();
    v_legendcontrol.innerText = '';
    v_inservice = 2;
    return false;
}



function validateserialno(v_partnrcontrol, v_serialnocontrol, v_invoicenocontrol, v_daycontrol, v_monthcontrol, v_yearcontrol ) {
    v_inservice = 1;
    //***
    var v_partnrid = getInputControlValue(v_partnrcontrol);
    var v_serialno = getInputControlValue(v_serialnocontrol);
    var v_control = $get(v_serialnocontrol);
    var v_originalvalue = '';
    try {
        if (v_formvalues.containsKey(v_control.id)) {
            v_originalvalue = v_formvalues.get(v_control.id);
        }
    }
    catch (e1) { }
    if (v_serialno == v_originalvalue) {
        v_inservice = 0;
        return;
    }
    if ((!v_informvalidation) && (v_serialno.length == 0)) {
        v_inservice = 0;
        return;
    }

    //***
    try {
        var v_p = new WebShop.Framework.Web.Service.SerialParameters();
        v_p.partnrid = v_partnrid;
        v_p.serialno = v_serialno;
        v_p.partnrcontrol = v_partnrcontrol;
        v_p.serialcontrol = v_serialnocontrol;
        v_p.invoicecontrol = v_invoicenocontrol;
        v_p.daycontrol = v_daycontrol;
        v_p.monthcontrol = v_monthcontrol;
        v_p.yearcontrol = v_yearcontrol;
        v_p.result = '';
        var service = WebShop.Framework.Web.Service.WebShop.CheckSerialNo(v_p, validateserialnoCompleted);
    }
    catch (e) {
        v_inservice = 2;
    }
}
function validateserialnoCompleted(v_result) {
    var v_split = v_result.result.split(";");
    var v_pcontrol = $get(v_result.partnrcontrol);
    var v_scontrol = $get(v_result.serialcontrol);
    var v_icontrol = $get(v_result.invoicecontrol);
    var v_daycontrol = $get(v_result.daycontrol);
    var v_monthcontrol = $get(v_result.monthcontrol);
    var v_yearcontrol = $get(v_result.yearcontrol);
   
    
    switch (v_split[0]) {
        case '0':
            v_inservice = 0;
            v_icontrol.value = v_split[1];
            v_daycontrol.value = '';
            v_monthcontrol.value = '';
            v_yearcontrol.value = '';
            if (v_split[2].length == 10) {
                var v_date = v_split[2].split('-');
                v_daycontrol.value = v_date[2];
                v_monthcontrol.value = v_date[1];
                v_yearcontrol.value = v_date[0];
            }
            resetFieldValue(v_scontrol);
            v_icontrol.focus();
            return true;
        case '1':
            break;
        case '2':
            alert(v_split[1]);
            v_scontrol.focus();
            v_inservice = 2;
            return false;
            break;
    }
    var v_errormessage = v_scontrol.getAttribute("validateerror");
    if (v_errormessage.length > 0)
        alert(v_errormessage);
    v_pcontrol.focus();
    v_inservice = 2;
    return false;
}

function setFieldValue(v_control) {
    var v_controlvalue = '';
    try
    {
        v_controlvalue = getInputValue(v_control);
    }
    catch (e) { }
    //
    if (!v_formvalues.containsKey(v_control.id)) {
        v_formvalues.put(v_control.id, v_controlvalue);
    }
}
function resetFieldValue(v_control) {
    var v_controlvalue = '';
    try {
        v_controlvalue = getInputValue(v_control);
    }
    catch (e) { }
    //
    if (v_formvalues.containsKey(v_control.id)) {
        v_formvalues.remove(v_control.id);
        v_formvalues.put(v_control.id, v_controlvalue);
    }
}

function validateexternaldoc(v_doccontrol) {
    v_inservice = 1;
    //***
    var v_doccontrolvalue  = getInputControlValue(v_doccontrol);
    try {
        var service = WebShop.Framework.Web.Service.WebShop.AssignExternalDoc(v_doccontrolvalue, validateexternaldocCompleted);
    }
    catch (e) {
        v_inservice = 2;
    }
}
function validateexternaldocCompleted() {
    v_inservice = 0;
}

function gup(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else
        return results[1];
}

function Get_Cookie(check_name) {
    // first we'll split this cookie up into name/value pairs
    // note: document.cookie only returns name=value, not the other components
    var a_all_cookies = document.cookie.split(';');
    var a_temp_cookie = '';
    var cookie_name = '';
    var cookie_value = '';
    var b_cookie_found = false; // set boolean t/f default f

    for (i = 0; i < a_all_cookies.length; i++) {
        // now we'll split apart each name=value pair
        a_temp_cookie = a_all_cookies[i].split('=');


        // and trim left/right whitespace while we're at it
        cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

        // if the extracted name matches passed check_name
        if (cookie_name == check_name) {
            b_cookie_found = true;
            // we need to handle case where cookie has no value but exists (no = sign, that is):
            if (a_temp_cookie.length > 1) {
                cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, ''));
            }
            // note that in cases where cookie is initialized but no value, null is returned
            return cookie_value;
            break;
        }
        a_temp_cookie = null;
        cookie_name = '';
    }
    if (!b_cookie_found) {
        return null;
    }
}

function Delete_Cookie(name, path, domain) {
    if (Get_Cookie(name)) document.cookie = name + "=" +
((path) ? ";path=" + path : "") +
((domain) ? ";domain=" + domain : "") +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function Set_Cookie(name, value, expires, path, domain, secure) {
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime(today.getTime());

    /*
    if the expires variable is set, make the correct
    expires time, the current script below will set
    it for x number of days, to make it for hours,
    delete * 24, for minutes, delete * 60 * 24
    */
    if (expires) {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date(today.getTime() + (expires));

    document.cookie = name + "=" + escape(value) +
                ((expires) ? ";expires=" + expires_date.toGMTString() : "") +
                ((path) ? ";path=" + path : "") +
                ((domain) ? ";domain=" + domain : "") +
                ((secure) ? ";secure" : "");
}

function doChatTracking() {
    try {
        if (window.Cobrowser)
            window.Cobrowser.trackPageview();
    }
    catch (e) {
    }
}

function fct_pageloaded(sender, e) {
    if (!v_loaded) {
        v_loaded = true;
        doChatTracking();
    }
}

function fct_beginrequesthandler(sender, e) {
    // var request = e.get_request();
    // var customData = { requestStart: new Date(),action1: v_globalaction1,action2: v_globalaction2 };
    // request.set_userContext(customData);
}

function fct_endrequesthandler(sender, args) {
    var response = args.get_response();
    if (response.get_responseAvailable()) {
        // var webRequest = response.get_webRequest();
        // var customData = webRequest.get_userContext();
        // var v_d1 = new Date();
        doChatTracking();
        // var v_d2 = new Date();
        //***
        // var sb = new Sys.StringBuilder();
        // sb.append("ENDREQUEST1;");
        // sb.append(customData.action1);
        // sb.append(";");
        // sb.append(customData.action2);
        // sb.append(";");
        // sb.append(customData.requestStart.toTimeString());
        // sb.append(";");
        // sb.append(v_d1.toTimeString());
        // sb.append(";");
        // sb.append(v_d2.toTimeString());
        //***
        // var service = WebShop.Framework.Web.Service.WebShop.SetDebugInfo(sb.toString(), SetDebugInfoEnded);
    }
}

function SetDebugInfoEnded(v_result) {
    // var v_d2 = new Date();
    // v_result = v_result + ';' + v_d2.toTimeString() + ';ENDED';
    // var service = WebShop.Framework.Web.Service.WebShop.SetDebugInfo(v_result, SetDebugEnded);
}
function SetDebugEnded(v_result) {
}


Sys.Application.add_init(pageInit);


