
function SaveSession(name, value) {
    var siteDomain = 'http://' + document.domain + '/';

    var url = siteDomain + "set_value.asp";
    $.ajax({
        type: "GET",
        contentType: "application/json; charset=utf-8",
        url: url,
        data: "name=" + name + "&value=" + value,
        dataType: "json",
        success: function (response) {
            var result = (typeof response.j) == 'string' ? eval('(' + response.j + ')') : response.j;
        }
    });
}

// equal heights modified works on class element

function equalHeights(className) {
    var currentTallest = 0;
    jQuery('.' + className).each(function () {
        if (jQuery(this).height() > currentTallest)
            currentTallest = jQuery(this).height();
    });

    jQuery('.' + className).height(currentTallest);
}

jQuery.fn.equalHeights = function (px) {
    jQuery(this).each(function () {
        var currentTallest = 0;
        jQuery(this).children().each(function (i) {
            if ($(this).height() > currentTallest) { currentTallest = jQuery(this).height(); }
        });
        if (!px || !Number.prototype.pxToEm)
            currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
        // for ie6, set height since min-height isn't supported
        if (jQuery.browser.msie && jQuery.browser.version == 6.0) { jQuery(this).children().css({ 'height': currentTallest }); }
        jQuery(this).children().css({ 'min-height': currentTallest });
    });
    return this;
};

// PX to EM

Number.prototype.pxToEm = String.prototype.pxToEm = function (settings) {
    //set defaults
    settings = jQuery.extend({
        scope: 'body',
        reverse: false
    }, settings);

    var pxVal = (this == '') ? 0 : parseFloat(this);
    var scopeVal;
    var getWindowWidth = function () {
        var de = document.documentElement;
        return self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
    };

    /* When a percentage-based font-size is set on the body, IE returns that percent of the window width as the font-size. 
    For example, if the body font-size is 62.5% and the window width is 1000px, IE will return 625px as the font-size. 	
    When this happens, we calculate the correct body font-size (%) and multiply it by 16 (the standard browser font size) 
    to get an accurate em value. */

    if (settings.scope == 'body' && $.browser.msie && (parseFloat($('body').css('font-size')) / getWindowWidth()).toFixed(1) > 0.0) {
        var calcFontSize = function () {
            return (parseFloat($('body').css('font-size')) / getWindowWidth()).toFixed(3) * 16;
        };
        scopeVal = calcFontSize();
    }
    else { scopeVal = parseFloat(jQuery(settings.scope).css("font-size")); };

    var result = (settings.reverse == true) ? (pxVal * scopeVal).toFixed(2) + 'px' : (pxVal / scopeVal).toFixed(2) + 'em';
    return result;
};

// Minimum height checker for catalog landing pages!
function catLandingMinHeight() {
    var minHeight = $("#problemYesProblemNo").height() + 180;

    if ($(".catLanding").height() < minHeight)
        $(".catLanding").height(minHeight);

    if ($(".ezineLanding").height() < minHeight)
        $(".ezineLanding").height(minHeight);

}

$(window).load(function () {
    catLandingMinHeight();
});

function MM_openBrWindow(theURL, winName, features) { //v2.0
    window.open(theURL, winName, features);
}

function ElementClearDefaultValue(id, value, def_value, color) {
    if (value == def_value) {
        document.getElementById(id).value = '';
        document.getElementById(id).style.color = color;
    }
}

function ElementFillDefaultValue(id, value, def_value, color) {
    if (value == '') {
        document.getElementById(id).value = def_value;
        document.getElementById(id).style.color = color;
    }
}

function changeProductContent(pid, c, referrer, content_type) {
    //trackPageView(window.location+'&nav=' + content_type);
    var randomNumber = Math.floor(Math.random() * 101);
    url = 'inc_product_description_ajax.asp?pid=' + pid + '&c=' + c + '&referrer=' + referrer + '&content_type=' + content_type + '&rand=' + randomNumber;
    if (checkIfCADomainJS() == 0)
        url = 'http://' + document.domain + '/' + url

    ajaxpageContent(url, 'mainProductDesc', content_type);
}

function changeProductContent_v3(pid, c, referrer, content_type) {
    //trackPageView(window.location+'&nav=' + content_type);
    var randomNumber = Math.floor(Math.random() * 101);
    url = 'inc_product_description_v3_ajax.asp?pid=' + pid + '&c=' + c + '&referrer=' + referrer + '&content_type=' + content_type + '&rand=' + randomNumber;
    if (checkIfCADomainJS() == 0)
        url = 'http://' + document.domain + '/' + url

    ajaxpage2(url, 'mainProductDesc', pid, content_type);
}

function SetActiveTab(activeID) {

    if (document.getElementById("tabNav") != null) {
        ulNav = document.getElementById("tabNav");
        lis = ulNav.getElementsByTagName("LI");
        for (var i = 0; i < lis.length; i++) {
            as = lis[i].getElementsByTagName("A");
            for (var j = 0; j < as.length; j++)
                if (as[j] != null)
                { as[j].className = ''; }
        }
    }
    if (document.getElementById(activeID) != null)
    { document.getElementById(activeID).className = 'active'; }
}

var bustcachevar = 0 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects = ""
var rootdomain = "http://" + window.location.hostname
var bustcacheparameter = ""

function ajaxpageClearContent(url, containerid) {
    document.getElementById(containerid).innerHTML = '';
    var page_request = false
    if (window.XMLHttpRequest) // if Mozilla, Safari etc
        page_request = new XMLHttpRequest()
    else if (window.ActiveXObject) { // if IE
        try {
            page_request = new ActiveXObject("Msxml2.XMLHTTP")
        }
        catch (e) {
            try {
                page_request = new ActiveXObject("Microsoft.XMLHTTP")
            }
            catch (e) { }
        }
    }
    else
        return false

    page_request.onreadystatechange = function () {
        loadpage(page_request, containerid)
    }

    if (bustcachevar) //if bust caching of external page
        bustcacheparameter = (url.indexOf("?") != -1) ? "&" + new Date().getTime() : "?" + new Date().getTime()

    page_request.open('GET', url + bustcacheparameter, true)
    page_request.send(null)
}


function ajaxpage(url, containerid) {
    var page_request = false
    if (window.XMLHttpRequest) // if Mozilla, Safari etc
        page_request = new XMLHttpRequest()
    else if (window.ActiveXObject) { // if IE
        try {
            page_request = new ActiveXObject("Msxml2.XMLHTTP")
        }
        catch (e) {
            try {
                page_request = new ActiveXObject("Microsoft.XMLHTTP")
            }
            catch (e) { }
        }
    }
    else
        return false

    page_request.onreadystatechange = function () {
        loadpage(page_request, containerid)
    }

    if (bustcachevar) //if bust caching of external page
        bustcacheparameter = (url.indexOf("?") != -1) ? "&" + new Date().getTime() : "?" + new Date().getTime()

    page_request.open('GET', url + bustcacheparameter, true)
    page_request.send(null)
}

function ajaxpageContent(url, containerid, content_type) {
    var page_request = false
    if (window.XMLHttpRequest) // if Mozilla, Safari etc
        page_request = new XMLHttpRequest()
    else if (window.ActiveXObject) { // if IE
        try {
            page_request = new ActiveXObject("Msxml2.XMLHTTP")
        }
        catch (e) {
            try {
                page_request = new ActiveXObject("Microsoft.XMLHTTP")
            }
            catch (e) { }
        }
    }
    else
        return false

    page_request.onreadystatechange = function () {
        loadpageContent(page_request, containerid, content_type)
    }

    if (bustcachevar) //if bust caching of external page
        bustcacheparameter = (url.indexOf("?") != -1) ? "&" + new Date().getTime() : "?" + new Date().getTime()

    page_request.open('GET', url + bustcacheparameter, true)
    page_request.send(null)
}

function loadpage(page_request, containerid) {
    if (page_request.readyState == 4 && (page_request.status == 200 || window.location.href.indexOf("http") == -1)) {

        if (document.getElementById(containerid) != null) {

            if (page_request.responseText != 'reload') document.getElementById(containerid).innerHTML = page_request.responseText;
            else window.location.href = window.location.href;

            tb_init('a.thickbox, area.thickbox, input.thickbox, div.thickbox'); //DON'T REMOVE THIS! Thickbox duplication is fixed in thickboxJS.asp script

            // FOR VIDEO2 CONTENT INICIALIZATION OF EQUAL HEIGHTS
            $(function () { equalHeights('ebTitle'); });
            $(function () { equalHeights('ebTxt'); });
            $(function () { equalHeights('whoTitle'); });
            $(function () { equalHeights('whoTxt'); });

            // INITIALIZATON FOR RATING
            rating_init();
        }
    }
}

function loadpageContent(page_request, containerid, content_type) {
    if (page_request.readyState == 4 && (page_request.status == 200 || window.location.href.indexOf("http") == -1)) {

        if (document.getElementById(containerid) != null) {

            SetActiveTab(content_type);

            if (page_request.responseText != 'reload') document.getElementById(containerid).innerHTML = page_request.responseText;
            else window.location.href = window.location.href;


            tb_init('a.thickbox, area.thickbox, input.thickbox, div.thickbox'); //DON'T REMOVE THIS! Thickbox duplication is fixed in thickboxJS.asp script

            // FOR VIDEO2 CONTENT INICIALIZATION OF EQUAL HEIGHTS
            $(function () { equalHeights('ebTitle'); });
            $(function () { equalHeights('ebTxt'); });
            $(function () { equalHeights('whoTitle'); });

            // INITIALIZATON FOR RATING
            rating_init();

        }
    }
}

function ValidatePhoneNumberDropdown(field, childField) {
    var error = false;
    $(field).removeClass('inputboxerror');
    $(childField).removeClass('inputboxerror');
    var GoodChars = "0123456789.()-+/ ";
    var fieldValue = $(field).val();

    for (i = 0; i <= fieldValue.length - 1; i++) {
        if (GoodChars.indexOf(fieldValue.charAt(i)) == -1) {
            error = true;
        }

        samCifre = fieldValue.replace(/[\(\)\.\-\+\/\ ]/g, '');
    }

    if (($(field).val() == "") && ($(childField).val().length > 4) && !error) {
        error = false;
    }
    else if (($(field).val().length > 4) && (!error)) {
        error = false;
    }
    else {
        error = true;
        $(field).addClass('inputboxerror');
        $(childField).addClass('inputboxerror');
    }

    return error;
}


function open_popup(theURL) { //v2.0
    MM_openBrWindow(theURL, '', 'scrollbars=yes,resizable=yes,width=520,height=500');
}

jQuery('.mainCatalogList .sort .table a, .mainCatalogList .sort .row a, .mainCatalogList .sort .cel a, .mainCatalogList_v2 .sort .table a, .mainCatalogList_v2 .sort .row a, .mainCatalogList_v2 .sort .cel a, .mainCatalogList_v3 .sort .table a, .mainCatalogList_v3 .sort .row a, .mainCatalogList_v3 .sort .cel a').live('click', function () {
    var oldListClass;

    if (jQuery(this).closest('tr').children('td.active').hasClass('table'))
        oldListClass = 'mainCatTableList';
    else if (jQuery(this).closest('tr').children('td.active').hasClass('row'))
        oldListClass = 'mainCatRowList';

    else if (jQuery(this).closest('tr').children('td.active').hasClass('cel'))
        oldListClass = 'mainCatCelList';

    jQuery(this).closest('tr').children('td.active').removeClass('active');
    jQuery(this).closest('td').addClass('active');

    var currentListClass;

    if (jQuery(this).closest('tr').children('td.active').hasClass('table')) {
        currentListClass = 'mainCatTableList';
        SaveSession("CatalogPageView", "table");
        _gaq.push(['_trackPageview', '/TabView']);
    }
    else if (jQuery(this).closest('tr').children('td.active').hasClass('row')) {
        currentListClass = 'mainCatRowList';
        SaveSession("CatalogPageView", "row");
        _gaq.push(['_trackPageview', '/RowView']);
    }
    else if (jQuery(this).closest('tr').children('td.active').hasClass('cel')) {
        currentListClass = 'mainCatCelList';
        SaveSession("CatalogPageView", "cel");
    }

    var div = jQuery('div.' + oldListClass);
    div.removeClass(oldListClass);
    div.addClass(currentListClass);

    return false;
})

//ajax version - old
jQuery('.contentTabs ul.tabNav li a').live('click', function () {
    var activeLink = this;
    jQuery(this).closest('ul.tabNav').children('li').children('a.active').removeClass('active');
    jQuery(this).addClass('active');
})

//reset all filters
/*
jQuery('.filter .reset a').live('click', function () {
jQuery(this).closest('.filter ').children('tbody').children('tr').children('td').children('select').val('-');
return false;
})
*/

function Show(id) {
    if (document.getElementById(id) != null) document.getElementById(id).style.display = "";
}

function Hide(id) {
    if (document.getElementById(id) != null) document.getElementById(id).style.display = "none";
}

//-- VALIDATION FUNCTIONS --
// isValidEmail() returns 
//    - [false] if there is no error
//    - [true] if an error is found
function isValidEmail(fld) {

    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/;
    var illegalChars = /[\(\)\<\>\,\&\=\#\;\:\\\"\[\]]/;
    var error_mail = false;
    $(fld).removeClass('inputboxerror');

    if ($(fld).val() == "") {
        error_mail = true;
        $(fld).addClass('inputboxerror');
    } else if (!emailFilter.test($(fld).val())) {              //test email for illegal character
        error_mail = true;
        $(fld).addClass('inputboxerror');
    } else if ($(fld).val().match(illegalChars)) {
        error_mail = true;
        $(fld).addClass('inputboxerror');
    } else {
        error_mail = false;
        $(fld).removeClass('inputboxerror');
    }
    return error_mail;
}

function isValidEmailRo(fld) {

    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/;
    var illegalChars = /[\(\)\<\>\,\&\=\#\;\:\\\"\[\]]/;
    var error_mail = false;

    if ($(fld).val() == "") {
        error_mail = true;
    } else if (!emailFilter.test($(fld).val())) {              //test email for illegal character
        error_mail = true;
    } else if ($(fld).val().match(illegalChars)) {
        error_mail = true;
    } else {
        error_mail = false;
    }
    return error_mail;
}



function checkPhoneNumber(nbr, lang) {
    var valid = true
    var GoodChars = "0123456789.()-+/ "
    var i = 0
    var samCifre = 0;

    if (nbr == "") {
        // Return false if number is empty
        valid = false
    }

    for (i = 0; i <= nbr.length - 1; i++) {
        if (GoodChars.indexOf(nbr.charAt(i)) == -1) {
            valid = false
        } // End if statement

        samCifre = nbr.replace(/[\(\)\.\-\+\/\ ]/g, '');

    } // End for loop

    if (lang == 'SI') {

        if ((samCifre.length == 13 && samCifre.substring(0, 5) == "00386") || (samCifre.length == 11 && samCifre.substring(0, 3) == "386") || (samCifre.length == 9 && samCifre.substring(0, 1) == 0)) {
            valid = true;
        }
        else {
            valid = false;
        }
    }
    return valid
}

//showErr, idDivErr, idDiv
function IsNumberValid(fld, Min, Max) {
    $(fld).removeClass('inputboxerror');
    var valid = true;
    if ($(fld).val() == "") {
        valid = false;
        $(fld).addClass('inputboxerror');
    }
    else if (isNaN($(fld).val())) {
        valid = false;
        $(fld).addClass('inputboxerror');
    }
    else if ($(fld).val() < Min || $(fld).val() > Max) {
        valid = false;
        $(fld).addClass('inputboxerror');
    }

    return valid;
}

//showErr, idDiv, idDivErr
function IsStringValid(fld, minStringLength) {

    var illegalChars = /[a-zA-Z0-9 ]+$/; // allow letters, numbers, and underscores
    var length = minStringLength;
    var valid = true;
    $(fld).removeClass('inputboxerror');

    //if (($(fld).val().length < length) || ($(fld).val().length == 0)) {
    if ($(fld).val().length == 0) {
        valid = false;
        $(fld).addClass('inputboxerror');
    }

    return valid;
}

function IsSelectionBoxValid(id) {
    var valid = false;

    if (document.getElementById(id) != null) {
        var region_inx = document.getElementById(id).selectedIndex;

        if (document.getElementById(id).options[region_inx].value == '') {
            document.getElementById(id).setAttribute('class', 'inputboxerror');
            valid = false;
        }
        else {
            document.getElementById(id).setAttribute('class', '');
            valid = true;
        }
    }
    return valid;
}

function IsSelectionValid(fld) {
    var valid = true;
    var checkbox = document.getElementById('deliveryaf');
    var tableaf = document.getElementById('deliverytableaf');
    $(fld).removeClass('inputboxerror');
    var zip = document.getElementById('userZip').value;
    switch (zip) {
        case "1000":
        case "1001":
        case "1002":
        case "1104":
        case "1107":
        case "1508":
        case "1510":
        case "1516":
        case "1514":
        case "1518":
        case "1520":
        case "1521":
        case "1527":
        case "1528":
        case "1533":
        case "1544":
        case "1600":
        case "1113":
        case "1125":
        case "1132":
        case "1133":
        case "1132":
        case "1117":
        case "1120":
        case "1122":
        case "1108":
        case "1119":
        case "1110":
        case "1126":
        case "1106":
        case "1115":
        case "1111":
        case "1129":
        case "1231":
        case "1261":
        case "1260":
        case "1210":
        case "1211":
        case "1293":
            if (tableaf != null) {
                checkbox.checked = 0;
                checkbox.removeAttribute('disabled', true);
                tableaf.style.removeProperty("display");
            }
            break;
        default:
            if (tableaf != null) {
                checkbox.checked = 0;
                checkbox.setAttribute('disabled', false);
                tableaf.style.display = "none";
            }
            break;
    }
    if ($(fld).val() == 0) {
        valid = false;
        $(fld).addClass('inputboxerror');
    }


    return valid;
}

function IsPhoneNumberValid(fld, lang) {
    var valid = true;
    var GoodChars = "0123456789.()-+/ ";
    var i = 0;
    var samCifre = 0;
    $(fld).removeClass('inputboxerror');

    if ($(fld).val() == "") {
        // Return false if number is empty
        valid = false;
        $(fld).addClass('inputboxerror');
    }

    for (i = 0; i <= $(fld).val().length - 1; i++) {
        if (GoodChars.indexOf($(fld).val().charAt(i)) == -1) {
            valid = false;
            $(fld).addClass('inputboxerror');
        } // End if statement

        samCifre = $(fld).val().replace(/[\(\)\.\-\+\/\ ]/g, '');

    } // End for loop

    if (lang == 'SI') {
        if ((samCifre.length == 13 && samCifre.substring(0, 5) == "00386") || (samCifre.length == 11 && samCifre.substring(0, 3) == "386") || (samCifre.length == 9 && samCifre.substring(0, 1) == 0)) {
            valid = true;
            $(fld).removeClass('inputboxerror');
        }
        else {
            valid = false;
            $(fld).addClass('inputboxerror');
        }
    }
    return valid;
}

function IsCommentBoxValid(s) {
    var re = new RegExp('\<\s*.*\s*>');
    var m = re.exec(s);
    if (m == null) {
        return false;
    } else {
        return true;
    }
}



//-- END OF VALIDATE FUNCTIONS --

function resetControlList(controlList) {
    for (i = 0; i < controlList.length; i++) {
        $(controlList[i]).removeClass('inputboxerror');
    }
}

function resetParentControlList(controlList) {
    for (i = 0; i < controlList.length; i++) {
        $(controlList[i]).closest('div').removeClass('inputboxerror');
    }
}

function submitFormIfValid(formName, lang) {

    var isError = false;
    var inputs = $("#" + formName + " :input");
    var checkboxes = $("#" + formName + " :checkbox");

    resetControlList(inputs);
    resetParentControlList(checkboxes);

    for (i = 0; i < inputs.length; i++) {
        if ($(inputs[i]).attr('rel') == 'o' && ($(inputs[i]).val() == '' || ($(inputs[i]).val() == 0 && !(lang == 'LV' || lang == 'LVRU')) || $(inputs[i]).val() == '-' || $(inputs[i]).val() == -1)) {
            isError = true;
            $(inputs[i]).addClass('inputboxerror');
        }
        else if ($(inputs[i]).attr('name') == "email" && $(inputs[i]).attr('rel') == 'o' && isValidEmail($(inputs[i]))) {
            isError = true;
            $(inputs[i]).addClass('inputboxerror');
        }
        else if ($(inputs[i]).attr('name') == "phone" && $(inputs[i]).attr('rel') == 'o' && !checkPhoneNumber($(inputs[i]).val(), lang)) {
            isError = true;
            $(inputs[i]).addClass('inputboxerror');
        }
    }

    for (i = 0; i < checkboxes.length; i++) {
        if (!$(checkboxes[i]).attr('checked') && $(checkboxes[i]).attr('rel') == 'o') {
            isError = true;
            $(checkboxes[i]).closest('div').addClass('inputboxerror');
        }
    }

    if (lang == 'PL') {
        var tel_code = document.getElementById('tel_code');

        if (tel_code.value == "0") {
            tel_code.setAttribute("class", "inputboxerror");
        } else {
            tel_code.setAttribute("class", "");
        }
    }

    if (lang == 'SI') {
        var mob = document.getElementById('mob');
        var tel = document.getElementById('tel');
        var GoodChars = "0123456789.()-+/ ";

        if ((mob != null) && (tel != null)) {
            if ((mob.value.length < 5) && (tel.value.length < 5)) {
                isError = true;
                mob.setAttribute("class", "inputboxerror");
                tel.setAttribute("class", "inputboxerror");
            }

            for (i = 0; i <= mob.value.length - 1; i++) {
                if (GoodChars.indexOf(mob.value.charAt(i)) == -1) {
                    isError = true;
                    mob.setAttribute("class", "inputboxerror");
                    tel.setAttribute("class", "inputboxerror");
                }
            }

            for (i = 0; i <= tel.value.length - 1; i++) {
                if (GoodChars.indexOf(tel.value.charAt(i)) == -1) {
                    isError = true;
                    mob.setAttribute("class", "inputboxerror");
                    tel.setAttribute("class", "inputboxerror");
                }
            }
        }
    }
    else if (lang = 'TR') {
        if ((document.getElementById('order_agreement_input') != null) && (document.getElementById('order_agreement') != null)) {
            if (document.getElementById('order_agreement_input').checked == false) {
                document.getElementById('order_agreement').setAttribute('class', 'inputboxerror');
                isError = true;
            }
            else {
                document.getElementById('order_agreement').setAttribute('class', '');
            }
        }
    }

    if (document.getElementById('region') != null) {
        var region_inx = document.getElementById('region').selectedIndex;

        if (region_inx != null) {
            if (document.getElementById('region').options[region_inx].value == '') {
                document.getElementById('region').setAttribute('class', 'inputboxerror');
                isError = true;
            }
            else {
                document.getElementById('region').setAttribute('class', '');
            }
        }
    }

    if (document.getElementById('postOffice') != null) {
        var post_inx = document.getElementById('postOffice').selectedIndex;

        if (post_inx != null) {
            if (document.getElementById('postOffice').options[post_inx].value == '') {
                document.getElementById('postOffice').setAttribute('class', 'inputboxerror');
                isError = true;
            }
            else {
                document.getElementById('postOffice').setAttribute('class', '');
            }
        }
    }

    if (!isError) {
        setCookie('subscribed', 'true', 365);
        $('#' + formName).closest('div').children('.error').hide();
        jQuery(document.forms[formName]).submit();
    }
    else {
        $('#' + formName).closest('div').children('.error').show();
    }
}

// More generic form validation
/*
function submitFormIfValid(formName) {
var isError = false;
var inputs = $("#" + formName + " :input");
var checkboxes = $("#" + formName + " :checkbox");

resetControlList(inputs);
resetParentControlList(checkboxes);

for (i = 0; i < inputs.length; i++) {

if ($(inputs[i]).attr('name') == 'name' && $(inputs[i]).attr('rel') == 'o' && $(inputs[i]).val() == '') {
isError = true;
$(inputs[i]).addClass('inputboxerror');
}

if ($(inputs[i]).attr('name') == 'surname' && $(inputs[i]).attr('rel') == 'o' && $(inputs[i]).val() == '') {
isError = true;
$(inputs[i]).addClass('inputboxerror');
}

if ($(inputs[i]).attr('name') == 'email' && $(inputs[i]).attr('rel') == 'o' && ($(inputs[i]).val() == '' || ($(inputs[i]).val() != '' && isValidEmail($(inputs[i]).val())))) {
isError = true;
$(inputs[i]).addClass('inputboxerror');
}

if ($(inputs[i]).attr('name') == 'addressName' && $(inputs[i]).attr('rel') == 'o' && $(inputs[i]).val() == '') {
isError = true;
$(inputs[i]).addClass('inputboxerror');
}

if ($(inputs[i]).attr('name') == 'addressLine1' && $(inputs[i]).attr('rel') == 'o' && $(inputs[i]).val() == '') {
isError = true;
$(inputs[i]).addClass('inputboxerror');
}

if ($(inputs[i]).attr('name') == 'streetNumber' && $(inputs[i]).attr('rel') == 'o' && $(inputs[i]).val() == '') {
isError = true;
$(inputs[i]).addClass('inputboxerror');
}

if ($(inputs[i]).attr('name') == 'addressLine2' && $(inputs[i]).attr('rel') == 'o' && $(inputs[i]).val() == '') {
isError = true;
$(inputs[i]).addClass('inputboxerror');
}

if ($(inputs[i]).attr('name') == 'region' && $(inputs[i]).attr('rel') == 'o' && $(inputs[i]).val() == '') {
isError = true;
$(inputs[i]).addClass('inputboxerror');
}

if ($(inputs[i]).attr('name') == 'city' && $(inputs[i]).attr('rel') == 'o' && $(inputs[i]).val() == '') {
isError = true;
$(inputs[i]).addClass('inputboxerror');
}

if ($(inputs[i]).attr('name') == 'zip' && $(inputs[i]).attr('rel') == 'o' && $(inputs[i]).val() == '') {
isError = true;
$(inputs[i]).addClass('inputboxerror');
}

if ($(inputs[i]).attr('name') == 'phone' && $(inputs[i]).attr('rel') == 'o' && $(inputs[i]).val() == '') {
isError = true;
$(inputs[i]).addClass('inputboxerror');
}

if ($(inputs[i]).attr('name') == 'mobile' && $(inputs[i]).attr('rel') == 'o' && $(inputs[i]).val() == '') {
isError = true;
$(inputs[i]).addClass('inputboxerror');
}

if ($(inputs[i]).attr('name') == 'message' && $(inputs[i]).attr('rel') == 'o' && $(inputs[i]).val() == '') {
isError = true;
$(inputs[i]).addClass('inputboxerror');
}

if ($(inputs[i]).attr('name') == 'send_from' && $(inputs[i]).attr('rel') == 'o' && $(inputs[i]).val() == '') {
isError = true;
$(inputs[i]).addClass('inputboxerror');
}

if ($(inputs[i]).attr('name') == 'subject' && $(inputs[i]).attr('rel') == 'o' && $(inputs[i]).val() == '') {
isError = true;
$(inputs[i]).addClass('inputboxerror');
}

if ($(inputs[i]).attr('name') == 'houseNbr' && $(inputs[i]).attr('rel') == 'o' && $(inputs[i]).val() == '') {
isError = true;
$(inputs[i]).addClass('inputboxerror');
}

if ($(inputs[i]).attr('name') == 'userZip' && $(inputs[i]).attr('rel') == 'o' && $(inputs[i]).val() == 0) {
isError = true;
$(inputs[i]).addClass('inputboxerror');
}

if ($(inputs[i]).attr('name') == 'datum' && $(inputs[i]).attr('rel') == 'o' && $(inputs[i]).val() == 0) {
isError = true;
$(inputs[i]).addClass('inputboxerror');
}

if ($(inputs[i]).attr('name') == 'banka' && $(inputs[i]).attr('rel') == 'o' && $(inputs[i]).val() == '-') {
isError = true;
$(inputs[i]).addClass('inputboxerror');
}

if ($(inputs[i]).attr('name') == 'st_trr' && $(inputs[i]).attr('rel') == 'o' && $(inputs[i]).val() == '') {
isError = true;
$(inputs[i]).addClass('inputboxerror');
}

if ($(inputs[i]).attr('name') == 'st_osebnega' && $(inputs[i]).attr('rel') == 'o' && $(inputs[i]).val() == '') {
isError = true;
$(inputs[i]).addClass('inputboxerror');
}

if ($(inputs[i]).attr('name') == 'davcna' && $(inputs[i]).attr('rel') == 'o' && $(inputs[i]).val() == '') {
isError = true;
$(inputs[i]).addClass('inputboxerror');
}

if ($(inputs[i]).attr('name') == 'emso' && $(inputs[i]).attr('rel') == 'o' && $(inputs[i]).val() == '') {
isError = true;
$(inputs[i]).addClass('inputboxerror');
}
}

for (i = 0; i < checkboxes.length; i++) {
if (!$(checkboxes[i]).attr('checked') && $(checkboxes[i]).attr('rel') == 'o') {
isError = true;
$(checkboxes[i]).closest('div').addClass('inputboxerror');
}
}

if (!isError)
jQuery(document.forms[formName]).submit();
}
*/


//Form validation --> old version
/*
function submitFormIfValid(formName) {
if (formName == 'frmEbook') {
if (jQuery("#ebookFormName").val() != ''
&& jQuery("#ebookFormSurname").val() != ''
&& (jQuery("#ebookFormEmail").val() != '' && isValidEmail(jQuery("#ebookFormEmail").val()))) {
jQuery(document.forms[formName]).submit();
}
else
jQuery("#ebookFormName").focus();
}
else if (formName == 'frmEzine') {
if (jQuery(document.forms[formName]).children('#email').val() != '' && isValidEmail(jQuery(document.forms[formName]).children('#email').val())) {
jQuery(document.forms[formName]).submit();
}
}
else if (formName == 'frmEbookLeft') {
if (jQuery(document.forms[formName]).children('#email').val() != '' && isValidEmail(jQuery(document.forms[formName]).children('#email').val())) {
jQuery(document.forms[formName]).submit();
}
}
else if (formName == 'frmContact') {
if (jQuery('#send_from').val() != '' && jQuery('#subject').val() != '' && jQuery('#message').val() != '')
jQuery(document.forms[formName]).submit();
}
else if (formName == 'frmConfUserForm') {
if (jQuery('#name').val() != '' && jQuery('#surname').val() != '' && (jQuery('#email').val() != '' && isValidEmail(jQuery('#email').val())) && jQuery('#phone').val() != '')
jQuery(document.forms[formName]).submit();
}
else if (formName == 'frmCatalogLanding') {
var isError = false;

var inputs = $(document.forms[formName] + ":input");

for (i = 0; i < inputs.length; i++) {
if ($(inputs[i]).attr('name') == 'name' && $(inputs[i]).val() == '') {
isError = true;
$(inputs[i]).addClass('inputboxerror');
break;
}
else
$(inputs[i]).removeClass('inputboxerror');


if ($(inputs[i]).attr('name') == 'surname' && $(inputs[i]).val() == '') {
isError = true;
$(inputs[i]).addClass('inputboxerror');
break;
}
else
$(inputs[i]).removeClass('inputboxerror');

if ($(inputs[i]).attr('name') == 'addressLine1' && $(inputs[i]).val() == '') {
isError = true;
$(inputs[i]).addClass('inputboxerror');
break;
}
else
$(inputs[i]).removeClass('inputboxerror');

if ($(inputs[i]).attr('name') == 'city' && $(inputs[i]).val() == '') {
isError = true;
$(inputs[i]).addClass('inputboxerror');
break;
}
else
$(inputs[i]).removeClass('inputboxerror');

if ($(inputs[i]).attr('name') == 'zip' && $(inputs[i]).val() == '') {
isError = true;
$(inputs[i]).addClass('inputboxerror');
break;
}
else
$(inputs[i]).removeClass('inputboxerror');

if ($(inputs[i]).attr('name') == 'mail' && $(inputs[i]).val() == ''
&& !isValidEmail($(inputs[i]).val())) {
isError = true;
$(inputs[i]).addClass('inputboxerror');
break;
}
else
$(inputs[i]).removeClass('inputboxerror');
}
		
if (isError) {
$('.catInnerForm > .error').show();
}
else
jQuery(document.forms['frmCatalogLanding']).submit();
}
else if (formName == 'frmDreamsLanding') {
var isError = false;

//var inputs = $(document.forms[formName] + ":input");

var parentElt = $("#frmDreamsLanding > .dreamsForm").children("tbody").children("tr").children("td.dCnt");

if ($($(parentElt).children("#name")).val() == '') {
isError = true;
$($(parentElt).children("#name")).addClass('inputboxerror');
}
else
$($(parentElt).children("#name")).removeClass('inputboxerror');

if ($($(parentElt).children("#email")).val() == ''
&& !isValidEmail($($(parentElt).children("#email")).val())) {
isError = true;
$($(parentElt).children("#email")).addClass('inputboxerror');
}
else
$($(parentElt).children("#email")).removeClass('inputboxerror');
        
if (isError) {
$('.error').show();
}
else
jQuery(document.forms['frmDreamsLanding']).submit();
}
else if (formName == 'frmCartOrderConfirm') {
var isError = false;
var selector, value;
//------------------------------------------------------
// name
selector = "input[name=name]";
value = $(selector).val();
if (value.length > 0) value = $.trim(value);
if (value == '') {
isError = true;
$(selector).removeClass("noerror");
$(selector).addClass("error");
}
else {
$(selector).removeClass("error");
$(selector).addClass("noerror");
}

//------------------------------------------------------
// name
selector = "input[name=surname]";
value = $(selector).val();
if (value.length > 0) value = $.trim(value);
if (value == '') {
isError = true;
$(selector).removeClass("noerror");
$(selector).addClass("error");
}
else {
$(selector).removeClass("error");
$(selector).addClass("noerror");
}
//------------------------------------------------------
// address
selector = "input[name=addressLine1]";
value = $(selector).val();
if (value.length > 0) value = $.trim(value);
if (value == '') {
isError = true;
$(selector).removeClass("noerror");
$(selector).addClass("error");
}
else {
$(selector).removeClass("error");
$(selector).addClass("noerror");
}
//------------------------------------------------------
// house number
selector = "input[name=houseNbr]";
value = $(selector).val();
if (value.length > 0) value = $.trim(value);
if (value == '') {
isError = true;
$(selector).removeClass("noerror");
$(selector).addClass("error");
}
else {
$(selector).removeClass("error");
$(selector).addClass("noerror");
}
//------------------------------------------------------
// zip
selector = "#userZip";
value = $(selector).val();
if (value == "0") {
isError = true;
$(selector).removeClass("noerror");
$(selector).addClass("error");
}
else {
$(selector).removeClass("error");
$(selector).addClass("noerror");
}
//------------------------------------------------------
// e-mail
selector = "input[name=email]";
value = $(selector).val();
if (value.length > 0) value = $.trim(value);
if ((value == "") || !isValidEmail(value)) {
isError = true;
$(selector).removeClass("noerror");
$(selector).addClass("error");
}
else {
$(selector).removeClass("error");
$(selector).addClass("noerror");
}
			
if (isError) {
Show('cartFormError');
}
else
jQuery(document.forms['form_cart_order_confirm']).submit(); 
}
else if (formName == 'frmCartOrderInstall') {
var isError = false;
var selector, value;

//------------------------------------------------------
// EMSO
selector = "#emso";
value = $(selector).val();
if (value.length > 0) value = $.trim(value);
//if ((value.length != 13) || (!isNumeric(value))) {
if (value.length != 13) {
isError = true;
$(selector).removeClass("noerror");
$(selector).addClass("error");
}
else {
$(selector).removeClass("error");
$(selector).addClass("noerror");
}
//------------------------------------------------------
// Tax number
selector = "#davcna";
value = $(selector).val();
if (value.length > 0) value = $.trim(value);
//if (((value.length == 8) && (isNumeric(value))) ||
//     (value.length == 10) && (value.substring(0,1) == "SI") && (isNumeric(value.substring(2)))) {
if (value.length < 8) {
isError = true;
$(selector).removeClass("noerror");
$(selector).addClass("error");
}
else {
// No error
$(selector).removeClass("error");
$(selector).addClass("noerror");
}
//------------------------------------------------------
// ID Number
selector = "#st_osebnega";
value = $(selector).val();
if (value.length > 0) value = $.trim(value);
if (value.length == 0) {
isError = true;
$(selector).removeClass("noerror");
$(selector).addClass("error");
}
else {
$(selector).removeClass("error");
$(selector).addClass("noerror");
}
//------------------------------------------------------
// St. trr
selector = "#st_trr";
value = $(selector).val();
if (value.length > 0) value = $.trim(value);
if (value.length < 10) {
isError = true;
$(selector).removeClass("noerror");
$(selector).addClass("error");
}
else {
$(selector).removeClass("error");
$(selector).addClass("noerror");
}
//------------------------------------------------------
// Bank
selector = "#banka";
value = $(selector).val();
//if ((value == "0") || (!isNumeric(value))) {
if ((value == "0") || (value == "-")) {
isError = true;
$(selector).removeClass("noerror");
$(selector).addClass("error");
}
else {
$(selector).removeClass("error");
$(selector).addClass("noerror");
}
//------------------------------------------------------
if (isError) {
//$('cartFormErrorbbb').show();
}
else
jQuery(document.forms[formName]).submit();
}
}
*/

//function for main price set up on site
var ProductPrice = [];
function SetPrice(id, val) {

    var domainanme = window.location.hostname;


    var normalselect = document.getElementById('select_menu' + id);
    var v2Select = document.getElementById('v2select_menu' + id);
    var savePrice = ProductPrice[val]["you_save"];

    //v1 prices
    if (document.getElementById('yourPriceWhole' + id) != null) {
        document.getElementById('yourPrice' + id).innerHTML = ProductPrice[val]["your_price"];
        if (ProductPrice[val]["your_price"] == '')
            Hide('yourPriceWhole' + id);
        else
            Show('yourPriceWhole' + id);
    };


    if (savePrice == '') {
        if (document.getElementById('regulaPriceWhole' + id) != null) {
            document.getElementById('regulaPriceWhole' + id).className = 'yourPrice';
        }
    }
    else {

        if (document.getElementById('regulaPriceWhole' + id) != null) {
            document.getElementById('regulaPriceWhole' + id).className = 'regPrice';
        }
    }




    if (document.getElementById('savePriceWhole' + id) != null)
        document.getElementById('savePrice' + id).innerHTML = ProductPrice[val]["you_save"];

    if (document.getElementById('savePriceWhole' + id) != null) {
        if (ProductPrice[val]["you_save"] == '')
            Hide('savePriceWhole' + id);
        else {

            Show('savePriceWhole' + id);
        }
    }

    if (document.getElementById('regulaPriceWhole' + id) != null) {

        document.getElementById('regulaPrice' + id).innerHTML = ProductPrice[val]["reg_price"];
        if (ProductPrice[val]["reg_price"] == '')
            Hide('regulaPriceWhole' + id);
        else
            Show('regulaPriceWhole' + id);
    };

    if (document.getElementById('installPriceWhole' + id) != null)
        document.getElementById('installPrice' + id).innerHTML = ProductPrice[val]["min_install"];

    if (document.getElementById('installPriceWhole' + id) != null) {
        if (ProductPrice[val]["min_install"] == '')
            Hide('installPriceWhole' + id);
        else
            Show('installPriceWhole' + id);
    }

    //v2 prices
    if (document.getElementById('v2yourPriceWhole' + id) != null) {
        document.getElementById('v2yourPrice' + id).innerHTML = ProductPrice[val]["your_price"];
        if (ProductPrice[val]["your_price"] == '')
            Hide('v2yourPriceWhole' + id);
        else
            Show('v2yourPriceWhole' + id);
    };

    if (savePrice == '') {
        if (document.getElementById('v2regulaPriceWhole' + id) != null) {
            document.getElementById('v2regulaPriceWhole' + id).className = 'yourPrice';
        }
    }
    else {
        if (document.getElementById('v2regulaPriceWhole' + id) != null) {
            document.getElementById('v2regulaPriceWhole' + id).className = 'regPrice';
        }
    }


    if (document.getElementById('v2savePriceWhole' + id) != null)
        document.getElementById('v2savePrice' + id).innerHTML = ProductPrice[val]["you_save"];

    if (document.getElementById('v2savePriceWhole' + id) != null) {
        if (ProductPrice[val]["you_save"] == '')
            Hide('v2savePriceWhole' + id);
        else
            Show('v2savePriceWhole' + id);
    }

    if (document.getElementById('v2regulaPriceWhole' + id) != null) {
        document.getElementById('v2regulaPrice' + id).innerHTML = ProductPrice[val]["reg_price"];
        if (ProductPrice[val]["reg_price"] == '')
            Hide('v2regulaPriceWhole' + id);
        else
            Show('v2regulaPriceWhole' + id);
    };

    if (document.getElementById('v2installPriceWhole' + id) != null)
        document.getElementById('v2installPrice' + id).innerHTML = ProductPrice[val]["min_install"];

    if (document.getElementById('v2installPriceWhole' + id) != null) {
        if (ProductPrice[val]["min_install"] == '')
            Hide('v2installPriceWhole' + id);
        else
            Show('v2installPriceWhole' + id);
    }

    if (normalselect != null) {
        for (index = 0; index < normalselect.length; index++) {

            if (normalselect[index].value == val) {
                normalselect.selectedIndex = index;
            }
        }
    }


    if (v2Select != null) {
        for (index = 0; index < v2Select.length; index++) {
            if (v2Select[index].value == val) {
                v2Select.selectedIndex = index;
            }
        }
    }




}

function setQuantity(id, val) {
    var normalQ = document.getElementById('quantity' + id);
    var v2Q = document.getElementById('v2quantity' + id);

    if (normalQ != null) {
        for (index = 0; index < normalQ.length; index++) {

            if (normalQ[index].value == val) {
                normalQ.selectedIndex = index;
            }
        }
    }


    if (v2Q != null) {
        for (index = 0; index < v2Q.length; index++) {
            if (v2Q[index].value == val) {
                v2Q.selectedIndex = index;
            }
        }
    }

}

function SetPriceQuantity(pid, divChange, diferencVar, tn) {

    var opid = 0;
    var opidDD = document.getElementById('select_menu' + pid);
    var opidDDv2 = document.getElementById('v2select_menu' + pid);
    var _thisOpid;
    var inxOpid = 0;

    var q = 1;
    var qDD = document.getElementById('quantity' + pid);
    var _thisQ;
    var inxQ = 0;
    var path_sep = '/';

    var sLink = '';


    if (diferencVar == "v2") {
        if (opidDDv2 != null) {
            _thisOpid = opidDDv2;
            inxOpid = _thisOpid.selectedIndex;
            opid = _thisOpid.options[inxOpid].value;
        }

        if (opidDD != null) {
            for (index = 0; index < opidDD.length; index++) {
                if (opidDD[index].value == opid) {
                    opidDD.selectedIndex = index;
                }
            }
        }
    }
    else {
        if (opidDD != null) {
            _thisOpid = opidDD;
            inxOpid = _thisOpid.selectedIndex;
            opid = _thisOpid.options[inxOpid].value;
        }

        if (opidDDv2 != null) {
            for (index = 0; index < opidDDv2.length; index++) {
                if (opidDDv2[index].value == opid) {
                    opidDDv2.selectedIndex = index;
                }
            }
        }
    }

    if (qDD != null) {
        _thisQ = qDD;
        inxQ = _thisQ.selectedIndex;
        q = _thisQ.options[inxQ].value;
    }

    sLink = 'ajax_product_prices.asp?pid=' + pid + '&opid=' + opid + '&q=' + q + '&diferencVar=&tn=' + tn + '&nocache=' + Math.random();
    csLink = 'ajax_ChangeStock.asp?pid=' + pid + '&opid=' + opid + '&nocache=' + Math.random();

    if (checkIfCADomainJS() == 0) {
        var sLink = path_sep + sLink;
        var csLink = path_sep + csLink;
    }
     
    ajaxpage(sLink, divChange + pid);
    ajaxpage(csLink, 'ChangeStock' + pid);

    sLink = 'ajax_product_prices.asp?pid=' + pid + '&opid=' + opid + '&q=' + q + '&diferencVar=v2&tn=' + tn + '&nocache=' + Math.random();
    csLink = 'ajax_ChangeStock.asp?pid=' + pid + '&opid=' + opid + '&nocache=' + Math.random();

    if (checkIfCADomainJS() == 0) {
        var sLink = path_sep + sLink;
        var csLink = path_sep + csLink;
    }

    ajaxpage(sLink, 'v2' + divChange + pid);
    ajaxpage(csLink, 'ChangeStock' + 'v2');

}

//Functions for CART
function addToCart(pid, ptype) {
    var opid = 0;
    var opidDD = 'select_menu' + pid;
    var _thisOpid;
    var inxOpid = 0;

    var q = 1;
    var qDD = 'quantity' + pid;
    var _thisQ;
    var inxQ = 0;
    var path_sep = '/';

    if (document.getElementById(opidDD) != null) {
        _thisOpid = document.getElementById(opidDD);
        inxOpid = _thisOpid.selectedIndex;
        opid = _thisOpid.options[inxOpid].value;
    }

    if (document.getElementById(qDD) != null) {
        _thisQ = document.getElementById(qDD);
        inxQ = _thisQ.selectedIndex;
        q = _thisQ.options[inxQ].value;
    }

    var sLink = 'cart_add.asp?pid=' + pid + '&ptype=' + ptype + '&opid=' + opid + '&q=' + q;


    if (checkIfCADomainJS() == 0) {
        var sLink = path_sep + sLink;
    }

    document.location.href = sLink;
}

function addToCartRef(pid, ptype, refVariable) {
    var opid = 0;
    var opidDD = 'select_menu' + pid;
    var _thisOpid;
    var inxOpid = 0;

    var q = 1;
    var qDD = 'quantity' + pid;
    var _thisQ;
    var inxQ = 0;
    var path_sep = '/';

    if (document.getElementById(opidDD) != null) {
        _thisOpid = document.getElementById(opidDD);
        inxOpid = _thisOpid.selectedIndex;
        opid = _thisOpid.options[inxOpid].value;
    }

    if (document.getElementById(qDD) != null) {
        _thisQ = document.getElementById(qDD);
        inxQ = _thisQ.selectedIndex;
        q = _thisQ.options[inxQ].value;
    }
    var sLink = 'cart_add.asp?pid=' + pid + '&ptype=' + ptype + '&opid=' + opid + '&q=' + q + '&refVariable=' + refVariable;


    if (checkIfCADomainJS() == 0) {
        var sLink = path_sep + sLink;
    }
    
    document.location.href = sLink;
}



function goToCart1(lang) {
    var sLink = "";
    
    var paymentType = $("input[name='payment']:checked").attr('id');

    if (lang == "LT") {
        paymentType = $('div.personal_lt').children('select').val();
        if (paymentType == 'webtopay_shop') {
            if ($("input[name='shop']:checked").val() == undefined) {
                $('#choose_value').show();
                return;
            }
        }

    }

    sLink = "cart1.asp?payment_type=" + paymentType;

    if (paymentType == 'instal') {
        if (lang != "LT") {
            sLink += "&installment=" + $('div.installments').children('select').val();
        }
        else {
            sLink += "&installment=" + $('div.installments_lt').children('select').val();
        }
    }
    else if (paymentType == 'ccard') {
        if (lang == "LT") {
            //var bank = $("input[name='cc']:checked").attr('id');
            sLink += "&bank=1&bank_installment=1";
        }
        else
            sLink += "&ccard=" + $('div.ccard').children('select').val();
    }

    if (document.getElementById("regularPrice") != null)
    { sLink += "&regularPrice=" + document.getElementById("regularPrice").value; }

    if (document.getElementById("discount") != null)
    { sLink += "&discount=" + document.getElementById("discount").value; }

    if (document.getElementById("discountCoupon") != null)
    { sLink += "&discountCoupon=" + document.getElementById("discountCoupon").value; }

    if (document.getElementById("yourPrice") != null)
    { sLink += "&yourPrice=" + document.getElementById("yourPrice").value; }

    if (document.getElementById("postage") != null)
    { sLink += "&postage=" + document.getElementById("postage").value; }

    if (document.getElementById("finalPrice") != null)
    { sLink += "&finalPrice=" + document.getElementById("finalPrice").value; }

    if (document.getElementById("installmentText") != null)
    { sLink += "&installmentText=" + document.getElementById("installmentText").value; }

    if (lang == "LT") {
        if (document.getElementById("postage_temp") != null)
        { sLink += "&postage_temp=" + document.getElementById("postage_temp").value; }

        if (document.getElementById("finalPrice_temp") != null)
        { sLink += "&finalPrice_temp=" + document.getElementById("finalPrice_temp").value; }
    }


    if (document.getElementsByName("payment") != null) {

        if (lang != "LT") {
            var paymentLength = document.getElementsByName("payment").length;
            var paymentObj = document.getElementsByName("payment");
            for (var i = 0; i < paymentLength; i++) {
                if (paymentObj[i].checked)
                { sLink += "&payment=" + paymentObj[i].value; }
            }
        }
        else {
            var payment = $('div.personal_lt').children('select').val();
            if (payment == 'webtopay_shop') {
                if ($("input[name='shop']:checked").val() != undefined) {
                    sLink += "&shop=" + $("input[name='shop']:checked").val();
                }
                payment = 'webtopay';
            }
            sLink += "&payment=" + payment;
        }
    }

    if (document.getElementById("nbr_install") != null) {
        sLink += "&nbr_install=" + document.getElementById("nbr_install").value;
    }

    if (document.getElementById("nbr_install_ccard") != null) {
        sLink += "&nbr_install_ccard=" + document.getElementById("nbr_install_ccard").value;
    }

    if (document.getElementById("nbr_install_leasing") != null) {
        sLink += "&nbr_install_leasing=" + document.getElementById("nbr_install_leasing").value;
    }

    if (document.getElementById("nbr_install_dividend") != null) {
        sLink += "&nbr_install_dividend=" + document.getElementById("nbr_install_dividend").value;
    }

    if (document.getElementById("collect") != null) {
        if (document.getElementById("collect").checked == true) {
            sLink += "&collect=" + document.getElementById("collect").value;
        }


    }

    // changing gift in cart
    var s = jQuery("select[name='gift_select_menu']");
    var b = true;

    if (s != null) {
        for (var i = 0; i < s.length; i++) {
            if (jQuery(s[i]).val() == 0) {
                jQuery(s[i]).css('border', '5px solid #E80000');
                b = false;
            }
            else {
                jQuery(s[i]).css('border', '1px solid #30547D');
            }
        }
    }

    if (lang == "RO") {
        var numericExpression = /^[0-9]+$/;
        var isNumber = 0;
        var wrongpostage = 0;
        var emailro = 0;

        if (document.getElementById("wrongpostage") != null) {
            wrongpostage = document.getElementById("wrongpostage").value;
        }

        if ((document.getElementById("post_nbr").value != "") && (isValidEmailRo(document.getElementById("email_txt")) == false)) {
            var post_nbr = trim(document.getElementById("post_nbr").value);
            var emailtxt = trim(document.getElementById("email_txt").value);

            if (post_nbr.match(numericExpression))
            { isNumber = 1; }

            if (emailtxt.match("@")) {
                emailro = 1;
            }
            else {
                emailro = 0;
                document.getElementById("email_txt").className = "inputboxerrorStrong";
            }

            if (post_nbr.length == 6 && isNumber == 1 && wrongpostage != 1 && emailro == 1) {
                document.getElementById("postage_ok").value = 'OK';
                document.getElementById("post_nbr").className = "";
                document.getElementById("email_txt").className = "";
                setCookie("delivery_parameter", trim(document.getElementById("post_nbr").value), 365);
                setCookie("email", trim(document.getElementById("email_txt").value), 365);
                sLink += "&post_nbr=" + document.getElementById("post_nbr").value;
                document.location.href = sLink;
            }
        }
        else {
            if (document.getElementById("post_nbr").value == "") {
                document.getElementById("postage_ok").value = 'NOTOK';
                document.getElementById("post_nbr").className = "inputboxerrorStrong";
            }
            else if (emailro == 0) {
                document.getElementById("email_txt").className = "inputboxerrorStrong";
            }
        }

    }
    else {
        if (b && check_gift_dimension_div()) {
            document.location.href = sLink;
        }
    }
    
}
function goToCart2() {
    var gender = $("input[name='sex']:checked").attr('id'); //m, f
    var firstName = $("input[name='name']").val();
    var lastName = $("input[name='surname']").val();
    var birthYear = $("select[name='year']").val();
    var birthMonth = $("select[name='month']").val();
    var birthDay = $("select[name='day']").val();
    var address1 = $("input[name='addressLine1']").val();
    var zip = $("input[name='zip']").val();
    var city = $("input[name='city']").val();
    var phone = $("input[name='phone']").val();
    var email = $("input[name='email']").val();
    var comments = $("textarea[name='comments']").val();

    SaveSession("gender", gender);
    SaveSession("name", firstName);
    SaveSession("surname", lastName);
    SaveSession("address", address1);
    SaveSession("zip", zip);
    SaveSession("city", city);
    SaveSession("phone", phone);
    SaveSession("email", email);
    SaveSession("comment", comments);

    jQuery(document.forms['frmCartOrderConfirm']).submit();
}

function redirectToParent(linkid) {
    if (trim(document.getElementById('clubCard').value) != '') {
        opener.location.href = 'activateClubCard.asp?redirectParam=' + document.getElementById('redirectParam').value + '&clubCard=' + document.getElementById('clubCard').value;
        window.close();
    }
    else {
        document.getElementById('clubCard').className = 'error';
    }
}


function refreshToParent(linkid) {
    if (trim(document.getElementById('clubCard').value) != '') {
        window.location.href = 'activateClubCard.asp?redirectParam=' + document.getElementById('redirectParam').value + '&clubCard=' + document.getElementById('clubCard').value;
		
		$("#club5_floating_tab_close_btn").click(function(){
			$("#club5_floating_tab_content").animate({marginLeft:'-600px'},'slow');
		});
		
    }
    else {
        document.getElementById('clubCard').className = 'error';
    }
}

function editToggle() {
    if (
	$('#editON').is(':visible')
	)
    { $('#editON').hide(); $('#editOFF').show(); }
    else
    { $('#editOFF').hide(); $('#editON').show(); }
}

function editToggleCupon() {
    $('.cartCupon').hide();
    $('.cartCuponBox').show();

    _gaq.push(['_trackEvent', 'cart', 'coupon', 'open', 1]);
}


function editToggle1() {

    $('.installments > select').hide();
    $('.ccard > select').hide();
    $('.ccw').hide();
    $('.cartTotal').removeClass("instTotal");
    $('.cartCredOptionsR').hide();
}

function editToggle2() {

    $('.ccw').hide();
    $('.ccard > select').hide();
    $('.installments > select').show();
    $('.cartTotal').addClass("instTotal");
    $('.cartCredOptionsR').hide();
}

function editToggle3() {
    $('.installments > select').hide();
    $('.ccard > select').show();
    $('.cartTotal').removeClass("instTotal");
}

function editToggleLT() {

    $('.installments > select').hide();
    $('.ccw').show();
    $('.cartTotal').removeClass("instTotal");
    $('.cartCredOptionsR').show();
}

//END functions for CART

function searchFor(id, defaultText, event) {

    var url = '';

    if (checkIfCADomainJS() == 0)
        url = 'http://' + document.domain + '/'


    if (event != null) {
        if (event.keyCode == 13) {
            var searchText = $('#' + id).val();

            if (searchText != defaultText) {
                var searchLink = url + "index.asp?tn=search&search=" + encodeURIComponent(searchText);
                document.location.href = searchLink;
            }
        }
    }
    else {
        var searchText = $('#' + id).val();

        if (searchText != defaultText) {
            var searchLink = url + "index.asp?tn=search&search=" + encodeURIComponent(searchText);
            document.location.href = searchLink;
        }
    }
}

//Lines

$(document).ready(function () {
    $('.mainNav > .dormeoType').click(function () {
        $('.dormeoTypeWin').slideDown('fast', function () {
            $('#typBtn').addClass("hidden");
            $('#typBtnT').addClass("hidden");
        });
    });

    $('.topSdw > .dormeoType').click(function () {
        $('.dormeoTypeWin').slideUp('fast', function () {
            $('#typBtn').removeClass("hidden");
            $('#typBtnT').removeClass("hidden");
        });
    });

    $('.mainNav > .dormeoTypeWin').hover(
        function () { },
        function () {
            $('.dormeoTypeWin').slideUp('fast', function () {
                $('#typBtn').removeClass('hidden'); $('#typBtnT').removeClass('hidden');
            });
        });

    $('.headerCarW').hover(
        function () { },
        function () {
            $('.headerCarW').slideUp('fast', function () {
            });
        });



});

// END Lines


// Header mini cart
function showHeadCart() {
    $('.headerCarW').slideDown('fast');
};


// END Header mini cart

function openCreditPopup(priceTotal, spec, payment) {
    var url = '';
    var nbr_install = 0;
    var inx = 0;

    if (payment == 'install') {
        if (document.getElementById('nbr_install') != null) {
            inx = document.getElementById('nbr_install').selectedIndex;
            nbr_install = document.getElementById('nbr_install').options[inx].value;
        }
    }
    if (payment == 'ccard') {
        if (document.getElementById('nbr_install_ccard') != null) {
            inx = document.getElementById('nbr_install_ccard').selectedIndex;
            nbr_install = document.getElementById('nbr_install_ccard').options[inx].value;
        }
    }


    url = 'popup_credit.asp?height=380&width=540&payment=' + payment + '&priceTotal=' + priceTotal + '&spec=' + spec + '&nbr_install=' + nbr_install;

    //alert('popup_credit.asp?height=380&width=540&payment='+payment+'&priceTotal='+priceTotal+'&spec='+spec+'&nbr_install='+nbr_install);
    tb_show('', url, '');
}


function RefreshPrices_Ajax(tip) {

    var tn = getUrlParam('tn');
    var inx = 0;

    document.getElementById('pcouponValue').style.display = "block";

    url = 'engine_cart_coupon.asp?tip=' + tip;

    url += '&validate_coupon=1'

    url += '&tn=' + tn

    var postNbr = document.getElementById("post_nbr");
    if (postNbr != null) {
        if (postNbr.value != "") {
            url += '&post_nbr='+postNbr.value;
        }
    }

    if (document.getElementById('courier') != null) {
        if (document.getElementById('courier').checked) {
            if (document.getElementById('zone_courier') != null) {
                url += "&zone_courier=" + document.getElementById('zone_courier').value;
            }
        }
    }

    if (document.getElementById('post') != null) {
        if (document.getElementById('post').checked) {
            if (document.getElementById('zone_post') != null) {
                url += "&zone_post=" + document.getElementById('zone_post').value;
            }
        }
    }

    if (document.getElementById('express') != null) {
        if (document.getElementById('express').checked) {
            if (document.getElementById('zone_express') != null) {
                url += "&zone_express=" + document.getElementById('zone_express').value;
            }
        }
    }

    // Delivery For MD /MDRU
    if (document.getElementById('chisinau') != null) {
        if (document.getElementById('chisinau').checked) {
            if (document.getElementById('chisinau_zone') != null) {
                url += "&delivery_option=" + document.getElementById('chisinau_zone').value + "&delivery_value=chisinau";
            }
        }
    }

    if (document.getElementById('municipiu') != null) {
        if (document.getElementById('municipiu').checked) {
            if (document.getElementById('municipiu_zone') != null) {
                url += "&delivery_option=" + document.getElementById('municipiu_zone').value + "&delivery_value=municipiu";
            }
        }
    }

    if (document.getElementById('raioane') != null) {
        if (document.getElementById('raioane').checked) {
            if (document.getElementById('raioane_zone') != null) {
                url += "&delivery_option=" + document.getElementById('raioane_zone').value + "&delivery_value=raioane";
            }
        }
    }

    if (document.getElementById('sate') != null) {
        if (document.getElementById('sate').checked) {
            if (document.getElementById('sate_zone') != null) {
                url += "&delivery_option=" + document.getElementById('sate_zone').value + "&delivery_value=sate";
            }
        }
    }
    // End Delivery For MD /MDRU

    // Installments
    if (tip == 11) {
        if (document.getElementById('nbr_install') != null) {
            inx = document.getElementById('nbr_install').selectedIndex;
            nbr_install = document.getElementById('nbr_install').options[inx].value;
            url += "&nbr_install=" + nbr_install;
        }
    }
    // Leasing EE/EERU
    else if (tip == 15) {
        inx = document.getElementById('leasing_percent').selectedIndex;
        nbr_install = document.getElementById('leasing_percent').options[inx].value;

        url += "&leasing_percent=" + nbr_install;

        inx = document.getElementById('leasing_months').selectedIndex;
        nbr_install = document.getElementById('leasing_months').options[inx].value;

        url += "&leasing_months=" + nbr_install;
    }
    // Credit Card Installments
    else if (tip == 16) {
        if (document.getElementById('nbr_install_ccard') != null) {
            inx = document.getElementById('nbr_install_ccard').selectedIndex;
            nbr_install = document.getElementById('nbr_install_ccard').options[inx].value;
            url += "&nbr_install_ccard=" + nbr_install;
        }
    }

    if (document.getElementById('post') != null) {
        url += "&post=" + document.getElementById('post').value;
    }

    if (document.getElementById('installmentText') != null) {
        url += "&installmentText=" + escape(document.getElementById('installmentText').value);
    }

    if (document.getElementById('coupontext') != null) {
        url += "&coupontext=" + document.getElementById('coupontext').value.replace("%", "");
    }

    if (document.getElementById('personalPickup') != null) {
        if (document.getElementById('personalPickup').checked) {
            url += "&personalPickup=" + document.getElementById('personalPickup').value + "&store=" + document.getElementById('personalPickup_town').value;
        }
    }

    if (document.getElementById('delivery') != null) {
        if (document.getElementById('delivery').checked) {
            url += "&delivery=" + document.getElementById('delivery').value;
        }
    }

    if (document.getElementById("collect") != null) {
        if (document.getElementById("collect").checked == true)
            url += "&collect=" + document.getElementById("collect").value;
        else
            url += "&collect=0";
    }

    if (document.getElementById('RemovalMatrresses') != null) {
        if (document.getElementById('RemovalMatrresses').checked == true) {
            url += "&RemovalMatrresses=" + document.getElementById('RemovalMatrresses').value;
        }
        else {
            url += "&RemovalMatrresses=disable";
        }
    }

    if (checkIfCADomainJS() == 0)
        url = 'http://' + document.domain + '/' + url;

    url += "&no_cache=" + Math.round((new Date().getTime() * Math.random()));

    ajaxpage(url, 'divIncCartTotals');

    refreshCart();

}

function CouponActivation() {

    var tn = getUrlParam('tn');


    url = 'engine_cart_coupon.asp?tip=999';

    url += '&validate_coupon=1'

    url += '&tn=' + tn

    var postNbr = document.getElementById("post_nbr");
    if (postNbr != null) {
        if (postNbr.value != "") {
            url += '&post_nbr=' + postNbr.value;
        }
    }

    if (document.getElementById('coupontext') != null) {
        url += "&coupontext=" + document.getElementById('coupontext').value.replace("%", "");
    }


    if (checkIfCADomainJS() == 0)
        url = 'http://' + document.domain + '/' + url;


    document.location.href = url;


}

function refreshCart() {
    if (document.getElementById("jsTip") != null) {
        if (document.getElementById("jsTip").value == 1) {
            alert('*');
        }
    }
}


function activateCoupon(coupon) {

    url += '&tn=' + tn

    url = 'engine_cart_coupon.asp?';

    url += '&validate_coupon=1'

    url += '&tn=' + tn

    var postNbr = document.getElementById("post_nbr");
    if (postNbr != null) {
        if (postNbr.value != "") {
            url += '&post_nbr=' + postNbr.value;
        }
    }

    if (document.getElementById('installmentText') != null) {
        url += "&installmentText=" + document.getElementById('installmentText').value;
    }

    if (document.getElementById('activateDisc') != null) {
        if (document.getElementById('activateDisc').checked == true) {
            url += "&coupontext=" + coupon;
        }
        else {
            url += "&coupontext=errorXXX";
        }
    }

    if (document.getElementById("collect") != null) {
        if (document.getElementById("collect").checked == true)
            url += "&collect=" + document.getElementById("collect").value;
        else
            url += "&collect=0";
    }

    if (checkIfCADomainJS() == 0)
        url = 'http://' + document.domain + '/' + url

    ajaxpage(url, 'divIncCartTotals');
}


function RefreshPaymentOptions_Ajax(tip) {

    var url = 'ajax_cart_payment_options_SI.asp?tip=' + tip;

    if (document.getElementById("collect") != null) {
        if (document.getElementById("collect").checked == true)
            url += "&collect=" + document.getElementById("collect").value;
        else
            url += "&collect=0";
    }

    if (checkIfCADomainJS() == 0)
        url = 'http://' + document.domain + '/' + url;

    url += "&no_cache=" + Math.round((new Date().getTime() * Math.random()));

    ajaxpage(url, 'cartPayOpt');
}

function hideElementsByNameAndShowPassed(name, id) {
    var elements = document.getElementsByName(name);

    for (var i = 0; i < elements.length; i++) {
        elements[i].style.display = 'none';
    }

    document.getElementById(id).style.display = 'block';
}

function changeDelivery(type, lang, name, id) {
    if ((lang == 'MD') || (lang == 'MDRU')) {
        hideElementsByNameAndShowPassed(name, id);
    }

    RefreshPrices_Ajax(0);
}

function changeDeliveryLV(type) {
    if (type == 'courier') {
        if (document.getElementById('zone_courier') != null) {
            document.getElementById('zone_courier').style.display = "block";
        }
        if (document.getElementById('zone_post') != null) {
            document.getElementById('zone_post').style.display = "none";
        }
        if (document.getElementById('zone_express') != null) {
            document.getElementById('zone_express').style.display = "none";
        }
    }
    else if (type == 'post') {
        if (document.getElementById('zone_courier') != null) {
            document.getElementById('zone_courier').style.display = "none";
        }
        if (document.getElementById('zone_post') != null) {
            document.getElementById('zone_post').style.display = "block";
        }
        if (document.getElementById('zone_express') != null) {
            document.getElementById('zone_express').style.display = "none";
        }
    }
    else if (type == 'express') {
        if (document.getElementById('zone_courier') != null) {
            document.getElementById('zone_courier').style.display = "none";
        }
        if (document.getElementById('zone_post') != null) {
            document.getElementById('zone_post').style.display = "none";
        }
        if (document.getElementById('zone_express') != null) {
            document.getElementById('zone_express').style.display = "block";
        }
    }

    RefreshPrices_Ajax(0);
}

function changeInstall(payment) {
    var url = '';
    var nbr_install = 0;
    var inx = 0;

    if (payment == 'cash') {
        if (document.getElementById('pInstallment') != null) {
            document.getElementById('pInstallment').style.display = "none";
        }
        if (document.getElementById('nbr_install') != null) {
            document.getElementById('nbr_install').style.display = "none";
        }
        if (document.getElementById('nbr_install_ccard') != null) {
            document.getElementById('nbr_install_ccard').style.display = "none";
        }
        if (document.getElementById('nbr_install_leasing') != null) {
            document.getElementById('nbr_install_leasing').style.display = "none";
        }
        if (document.getElementById('nbr_install_dividend') != null) {
            document.getElementById('nbr_install_dividend').style.display = "none";
        }
        if (document.getElementById('divcartTotal') != null) {
            document.getElementById('divcartTotal').className = "cartTotal";
        }
        nbr_install = '';
    }
    if (payment == 'install') {
        if (document.getElementById('pInstallment') != null) {
            document.getElementById('pInstallment').style.display = "block";
        }
        if (document.getElementById('nbr_install') != null) {
            document.getElementById('nbr_install').style.display = "block";
        }
        if (document.getElementById('nbr_install_ccard') != null) {
            document.getElementById('nbr_install_ccard').style.display = "none";
        }
        if (document.getElementById('divcartTotal') != null) {
            document.getElementById('divcartTotal').className = "cartTotal instTotal";
        }
        if (document.getElementById('nbr_install') != null) {
            inx = document.getElementById('nbr_install').selectedIndex;
            nbr_install = document.getElementById('nbr_install').options[inx].text;
        }
    }
    if (payment == 'install_dividend') {
        if (document.getElementById('pInstallment') != null) {
            document.getElementById('pInstallment').style.display = "block";
        }
        if (document.getElementById('nbr_install_dividend') != null) {
            document.getElementById('nbr_install_dividend').style.display = "block";
        }
        if (document.getElementById('nbr_install_leasing') != null) {
            document.getElementById('nbr_install_leasing').style.display = "none";
        }
        if (document.getElementById('divcartTotal') != null) {
            document.getElementById('divcartTotal').className = "cartTotal instTotal";
        }
        if (document.getElementById('nbr_install_dividend') != null) {
            inx = document.getElementById('nbr_install_dividend').selectedIndex;
            nbr_install = document.getElementById('nbr_install_dividend').options[inx].text;
        }
    }
    if (payment == 'install_leasing') {
        if (document.getElementById('pInstallment') != null) {
            document.getElementById('pInstallment').style.display = "block";
        }
        if (document.getElementById('nbr_install_dividend') != null) {
            document.getElementById('nbr_install_dividend').style.display = "none";
        }
        if (document.getElementById('nbr_install_leasing') != null) {
            document.getElementById('nbr_install_leasing').style.display = "block";
        }
        if (document.getElementById('divcartTotal') != null) {
            document.getElementById('divcartTotal').className = "cartTotal instTotal";
        }
        if (document.getElementById('nbr_install_leasing') != null) {
            inx = document.getElementById('nbr_install_leasing').selectedIndex;
            nbr_install = document.getElementById('nbr_install_leasing').options[inx].text;
        }
    }
    if (payment == 'leasing') {
        if (document.getElementById('nbr_install_leasing') != null) {
            document.getElementById('nbr_install_leasing').style.display = "block";
        }
    }

    if (payment == 'ccard') {
        if (document.getElementById('pInstallment') != null) {
            document.getElementById('pInstallment').style.display = "block";
        }
        if (document.getElementById('nbr_install') != null) {
            document.getElementById('nbr_install').style.display = "none";
        }
        if (document.getElementById('nbr_install_ccard') != null) {
            document.getElementById('nbr_install_ccard').style.display = "block";
        }
        if (document.getElementById('divcartTotal') != null) {
            document.getElementById('divcartTotal').className = "cartTotal instTotal";
        }
        if (document.getElementById('nbr_install_ccard') != null) {
            inx = document.getElementById('nbr_install_ccard').selectedIndex;
            nbr_install = document.getElementById('nbr_install_ccard').options[inx].text;
        }
    }

    if (payment == 'personalPickup') {

        if (document.getElementById('personalPickup_town') != null) {
            document.getElementById('personalPickup_town').style.display = "block";
            document.getElementById('installments').style.display = "none";
            document.getElementById('cash').checked = 'checked';
            document.getElementById('installmentText').value = 0; 
        }   

        if (document.getElementById('personalPickup_town') != null) {
            inx = document.getElementById('personalPickup_town').selectedIndex;
            nbr_install = document.getElementById('personalPickup_town').options[inx].text;
            var store = document.getElementById('personalPickup_town').value;
        }
        RefreshPrices_Ajax(12);
    }
     
    if (payment == 'delivery') {
     
        if (document.getElementById('personalPickup_town') != null) {
            document.getElementById('personalPickup_town').style.display = "none";
            document.getElementById('installments').style.display = "block";
        }
        RefreshPrices_Ajax(13);
    }


    if (document.getElementById('sInstallment') != null) {
        document.getElementById('sInstallment').innerHTML = nbr_install;
    }

    if (document.getElementById('installmentText') != null) {
        document.getElementById('installmentText').value = nbr_install;
    }

    if (payment == 'RemovalMatrresses') {
        if (document.getElementById('RemovalMatrresses').checked) {
            if (document.getElementById('PersonalPickD') != null) {
                document.getElementById('PersonalPickD').style.display = "none";
            }
            if (document.getElementById('delivery') != null) {
                document.getElementById('delivery').checked = 'checked';
            }
        }
        else {
            if (document.getElementById('PersonalPickD') != null) {
                document.getElementById('PersonalPickD').style.display = "block";
            }
        }

        RefreshPrices_Ajax(14);
    }

    if (payment == 'cash') {
        RefreshPrices_Ajax(10);
    }
    else if (payment == 'install') {
        RefreshPrices_Ajax(11);
    }
    else if (payment == 'ccard') {
        RefreshPrices_Ajax(16);
    }
    else if (payment == 'leasing') {
        // LEASING EE/EERU
        RefreshPrices_Ajax(15);
    }
}

function isNumeric(inputValue) {
    return typeof inputValue === 'number' && isFinite(inputValue);
}

function DownloadPDF(link) {
    window.open(link);
    return false;
}

function disableEnterKey(e) {
    var key;

    if (window.event)
        key = window.event.keyCode;     //IE
    else
        key = e.which;     //firefox

    if (key == 13)
        return false;
    else
        return true;
}

function fbs_click(u) {
    if (u == '')
        u = location.href;

    t = document.title;
    window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t), 'sharer', 'toolbar=0,status=0,width=626,height=436');
    return false;
}

function SetActionGift(type) {
    if (type == 1) {
        // free gift
        addToCartGift(101927, 'gift');
    }
    else {
        // free postage
        removeFromCartGift(101927, 'gift');
    }
}

function removeFromCartGift(pid, ptype) {
    var path_sep = '/';
    var sLink = 'cart_delete_product.asp?pid=' + pid + '&ptype=' + ptype;

    if (checkIfCADomainJS() == 0) {
        var sLink = path_sep + sLink;
    }

    document.location.href = sLink;
}

function addToCartGift(pid, ptype) {
    var path_sep = '/';
    var sLink = 'cart_gift_add.asp?pid=' + pid + '&ptype=' + ptype;

    if (checkIfCADomainJS() == 0) {
        var sLink = path_sep + sLink;
    }

    document.location.href = sLink;
}

function trim(stringToTrim) {
    return stringToTrim.replace(/^\s+|\s+$/g, "");

}

//filter category
function GetSelectedValue(id, catalogId, reset_filter, tn) {
    var filter = "";
    var sURL = "";
    var value = "";
    var m = querySt("m");
    var currentValueId = 0;
    var path_sep = '/';
    //var filterNumber = 0;

    if (reset_filter != 1) {
        if ($('#' + id + ' :selected').val() != '-') {
            currentValueId = $('#' + id + ' :selected').val();
            //filterNumber = parseInt(id.split('_')[1]);
        }
    }

    if (reset_filter)
        jQuery('td.reset').closest('.filter ').children('tbody').children('tr').children('td').children('select').val('-');

    var properties = jQuery('.property');

    if (id == 'p_help_2') {
        // filter and help filter on the same page
        for (i = 1; i <= 4; i++) {
            if (jQuery('#p_help_' + i).length > 0) {
                if (jQuery('#p_help_' + i).val() != '-') {
                    filter += jQuery('#p_help_' + i).val() + ",";
                    value += jQuery('#p_help_' + i).attr("name") + ";";
                }
                else {
                    filter += "-1,";
                    value += ';';
                }
            }
            else {
                filter += "-1,";
                value += ';';
            }
        }
    }
    else {
        for (i = 1; i <= 4; i++) {
            if (jQuery('#p_' + i).length > 0) {
                if (jQuery('#p_' + i).val() != '-') {
                    filter += jQuery('#p_' + i).val() + ",";
                    value += jQuery('#p_' + i).attr("name") + ";";
                }
                else {
                    filter += "-1,";
                    value += ';';
                }
            }
            else {
                filter += "-1,";
                value += ';';
            }
        }
    }

    value = value.replace("ž", "z");
    value = value.replace("š", "s");
    // value = value.replace("è", "c");
    value = value.replace(/\u2019/g, "'");
    value = value.replace("'", "\'");

    if (filter != "") {
        sURL += "?tn=" + tn + "&c=" + catalogId + "&fmode=" + filter.substring(0, filter.length - 1) + "&cselection=" + currentValueId + "#filterAnchor";
        //_gaq.push(['_trackEvent', 'configurator', 'filter', '<%= Catalog_Name %> | ' + value, 1]);
    }
    else {
        sURL += "?tn=" + tn + "&c=" + catalogId;
        //_gaq.push(['_trackEvent', 'configurator', 'filter', '<%= Catalog_Name %> | ' + value, 1]);
    }

    if (checkIfCADomainJS() == 0) {
        var sURL = path_sep + sURL;
    }

    window.location = sURL
}

function querySt(ji) {
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    for (i = 0; i < gy.length; i++) {
        ft = gy[i].split("=");
        if (ft[0] == ji) {
            return ft[1];
        }
    }
}


function errorMark(el) {
    if (el.substring(0, 1) == ".")
        $(el).addClass("error");
    else
        $("#" + el).addClass("error");
}

function errorUnmark(el) {
    if (el.substring(0, 1) == ".")
        $(el).removeClass("error");
    else
        $("#" + el).removeClass("error");
}

function checkfinishform() {
    var napaka = 0;
    if ($.trim($("#answer").val()) == '') {
        napaka = 1;
        errorMark('answer', 1);
    }
    else
        errorUnmark('answer', 0);

    if ($("#rules").attr("checked") == false) {
        napaka = 1;
        errorMark('emaillista_div', 1);
    }
    else
        errorUnmark('emaillista_div', 0);

    if (napaka == 1)
        $("#form_viral_error").show();
    else
        $("#form_viral").submit();
}

function GetSelectedValueVideo(filter_by, catalog_id, reset_filter) {
    var filter = "";
    var sURL = "";

    if (reset_filter)
        jQuery('td.reset').closest('.filter ').children('tbody').children('tr').children('td').children('select').val('-');

    var properties = jQuery('.' + filter_by);

    for (i = 0; i < properties.length; i++) {
        if (jQuery(properties[i]).val() != '-')
            filter += jQuery(properties[i]).val();
    }

    if (filter_by == 'filter_by_product')
        sURL += "index.asp?tn=videos&c=" + catalog_id + "&pmode=" + filter + "#filterAnchor";
    else if (filter_by == 'filter_by_video_category')
        sURL += "index.asp?tn=videos&c=" + catalog_id + "&vcmode=" + filter + "#filterAnchor";
    else
        sURL += "index.asp?tn=videos&c=" + catalog_id;
    window.location = sURL;
}

function errorMark(elementId) {
    $("#" + elementId).addClass("error");
}

function errorUnmark(elementId) {
    $("#" + elementId).removeClass("error");
}

function askUsSubmit() {
    var errorFound = false;
    var userName = $.trim($("#user_name").val());
    var userEmail = $.trim($("#user_email").val());
    var userQuestion = $.trim($("#user_question").val());

    // Name
    if (userName.length == 0) {
        errorFound = true;
        errorMark("user_name");
    }
    else
        errorUnmark("user_name");

    // Email
    if ((userEmail.length == 0) || (!isValidEmail("#user_email") == false)) {
        errorFound = true;
        errorMark("user_email");
    }
    else
        errorUnmark("user_email");

    // Question
    if (userQuestion.length == 0) {
        errorFound = true;
        errorMark("user_question");
    }
    else
        errorUnmark("user_question");

    if (errorFound == false) {
        $("#frmAskUs").submit();
    }
}

function check_gift_dimension_selected() {
    var s = jQuery("select[name='gift_select_menu']");
    var b = true;

    if (s != null) {
        for (var i = 0; i < s.length; i++) {
            if (jQuery(s[i]).val() == 0) {
                jQuery(s[i]).css('border', '5px solid #E80000');
                b = false;
            }
            else {
                jQuery(s[i]).css('border', '1px solid #30547D');
            }
        }
    }
}

function check_gift_dimension_div() {
    var s = jQuery("div.cart_gift_selected_header");
    var b = true;

    if (s != null) {
        for (var i = 0; i < s.length; i++) {
            var id = jQuery(s[i]).attr('id');
            if (jQuery(s[i]).html() == "") {
                jQuery('#s_' + id).css('border', '5px solid #E80000');
                b = false;
            }
            else {
                jQuery('#s_' + id).css('border', '1px solid #30547D');
            }
        }
    }

    return b;
}

function ajax_cart_change_dimension(div, cart_id, opid) {
    var link = 'ajax_cart_change_dimension.asp?cart_id=' + cart_id + '&opid=' + opid;

    ajaxpage(link, div);
}

//function ajax_cart_change_dimension(get_site_id, get_session_id, get_lang_id, coupontext) {
//    var link = 'ajax_inc_cart_product_list.asp.asp?get_site_id=' + get_site_id + '&get_session_id=' + get_session_id + '&get_lang_id=' + get_lang_id + '&coupontext=' + coupontext;
//	
//
//    ajaxpage(link, 'inc_cart_prod_list');
//}

//RO postage

function check_post_number_ro(weight, priceTotal) {

    var numericExpression = /^[0-9]+$/;
    var isNumber = 0;

    if (document.getElementById("post_nbr") != null) {
        var post_nbr = trim(document.getElementById("post_nbr").value);

        if (post_nbr.match(numericExpression))
        { isNumber = 1; }

        if (post_nbr.length == 6 && isNumber == 1) {
            document.getElementById("postage_ok").value = 'OK';
            document.getElementById("post_nbr").className = "";
            CPostage(post_nbr, weight, priceTotal);
        }

        else {
            document.getElementById("postage_ok").value = 'NOTOK';
            document.getElementById("post_nbr").className = "inputboxerrorStrong";
        }
    }
}

function free_delivery_RO(freeDelivery) {
    var tn = getUrlParam('tn');
    url = 'engine_cart_coupon.asp?tip=0';
    url += '&tn=' + tn;
    url += '&freeDelivery=' + freeDelivery;

    if (document.getElementById("post_nbr") != null) {
        var post_nbr = trim(document.getElementById("post_nbr").value);
        url += "&post_nbr=" + post_nbr
    }

    ajaxpage(url, 'divIncCartTotals');
}

function CPostage(post_nbr, weight, priceTotal) {

    var tn = getUrlParam('tn');

    url = 'engine_cart_coupon.asp?tip=0';

    url += '&validate_coupon=1'

    url += '&tn=' + tn

    if (document.getElementById('installmentText') != null) {
        url += "&installmentText=" + document.getElementById('installmentText').value;
    }

    if (document.getElementById('coupontext') != null) {
        url += "&coupontext=" + document.getElementById('coupontext').value.replace("%", "");
    }

    if (document.getElementById("collect") != null) {
        if (document.getElementById("collect").checked == true)
            url += "&collect=" + document.getElementById("collect").value;
        else
            url += "&collect=0";
    }


    url += "&post_nbr=" + post_nbr

    if (checkIfCADomainJS() == 0)
        url = 'http://' + document.domain + '/' + url;

    ajaxpage(url, 'divIncCartTotals');



    // var url='ajax_cart_postage_change.asp?extra_parameter='+extra_parameter+'&teza='+teza+'&znesek_postage='+znesek_postage+'&price_total_without_postage='+price_total_without_postage+'&wdiscount_value='+wdiscount_value+ '&club_saving='+club_saving; 
    //    	
    //
    //		
    //	    divId='prices_table_' + <%=site_id%>;
    //
    //		
    //    	
    //        if(enableCache && jsCache[url]){
    //            document.getElementById(divId).innerHTML = jsCache[url];
    //            return;
    //        }	
    //        var ajaxIndex = AjaxObjects.length;
    //        document.getElementById(divId).innerHTML = '<img src="/image/snake_transparent.gif" border="0" />';
    //        AjaxObjects[ajaxIndex] = new sack();
    //        AjaxObjects[ajaxIndex].requestFile = url;
    //        AjaxObjects[ajaxIndex].onCompletion = function(){ 
    //
    //	        ShowContent(divId,ajaxIndex,url)
    //	    };
    //        AjaxObjects[ajaxIndex].runAJAX();
}

function setCookie(c_name, value, exdays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
    document.cookie = c_name + "=" + c_value;
}

function getCookie(c_name) {
    var i, x, y, ARRcookies = document.cookie.split(";");
    for (i = 0; i < ARRcookies.length; i++) {
        x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
        y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
        x = x.replace(/^\s+|\s+$/g, "");
        if (x == c_name) {
            return unescape(y);
        }
    }
}

function showOrderAgreementPopUp() {
    var name = '';
    name = document.getElementById('name').value;

    var surname = '';
    surname = document.getElementById('surname').value;

    var phone = '';
    phone = document.getElementById('phone').value;

    var email = '';
    email = document.getElementById('email').value;

    var address = '';
    address = document.getElementById('addressline1').value;

    var houseNumber = '';
    houseNumber = document.getElementById('houseNbr').value;

    var city = '';
    city = document.getElementById('city').value;

    var url = '';
    url = 'site_content.asp?cn=order_agreement&width=920&height=500&name=' + encodeURI(name);
    url = url + '&surname=' + encodeURI(surname);
    url = url + '&address=' + encodeURI(address);
    url = url + '&houseN=' + encodeURI(houseNumber);
    url = url + '&city=' + encodeURI(city);
    url = url + '&phone=' + encodeURI(phone);
    url = url + '&email=' + encodeURI(email);

    if (checkIfCADomainJS() == 0) {
        url = 'http://' + document.domain + '/' + url;
    }

    tb_show('', url, '');
}

function getUrlParam(name) {
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var tmpURL = window.location.href;
    var results = regex.exec(tmpURL);
    if (results == null)
        return "";
    else
        return results[1];
}

function SendReview(Product_ID, Catalog_ID, Button_ID) {
    var button = document.getElementById(Button_ID);
    var comment = document.getElementById('comment');
    var name = document.getElementById('name');
    var surname = document.getElementById('surname');
    var email = document.getElementById('email');
    var rateDiv = document.getElementById('rate');
    var rate = document.getElementsByName('api-select-rate');
    var option_list = document.getElementsByName('review_options_list');
    var option_list_ids = '';
    var rateVal = 0;
    var first = true;
    var error = false;

    // COMMENT
    if (comment.value.length == 0) {
        comment.className = 'error';
        error = true;
    }
    else {
        comment.className = '';
    }

    //NAME
    if (name.value.length == 0) {
        name.className = 'error';
        error = true;
    }
    else {
        name.className = '';
    }

    //SURNAME
    if (surname.value.length == 0) {
        surname.className = 'error';
        error = true;
    }
    else {
        surname.className = '';
    }

    //EMAIL
    if (email.value.length == 0) {
        email.className = 'error';
        error = true;
    }
    else {
        email.className = '';
    }

    //RATE
    rateVal = $(document.forms['api-select']).serialize().replace('api-select-rate=', '');
    if (rateVal == '') {
        rateDiv.className = 'error';
        error = true;
        rateVal = 0;
    }
    else {
        rateVal = parseInt(rateVal);
        rateDiv.className = '';
    }

    //SELECTED OPTION LIST IDs
    for (var i = 0; i < option_list.length; i++) {
        if (option_list[i].checked) {
            if (first == false) {
                option_list_ids = option_list_ids + ',';
            }
            first = false;
            option_list_ids = option_list_ids + option_list[i].value;
        }
    }

    //GENERATE URL
    var url = '';
    url = url + 'ajax_user_comments.asp?thankyou=1';
    url = url + '&productId=' + Product_ID;
    url = url + '&catalogId=' + Catalog_ID;
    url = url + '&comment=' + encodeURI(comment.value);
    url = url + '&name=' + encodeURI(name.value);
    url = url + '&surname=' + encodeURI(surname.value);
    url = url + '&email=' + encodeURI(email.value);
    url = url + '&rate=' + encodeURI(rateVal);
    url = url + '&option_list_ids=' + encodeURI(option_list_ids);

    if (checkIfCADomainJS() == 0) {
        url = 'http://' + document.domain + '/' + url;
    }

    if (error == false) {

        // BUTTON PREVENT DOUBLE POST
        if (button.className == 'divBtn') {
            button.className = 'divBtn off';
        }
        else {
            return false;
        }

        ajaxpage(url, 'userComment');
    }
}

function validateNumberOfCharactersInTextarea(id, maxNumber, writeId) {
    var value = document.getElementById(id).value;

    document.getElementById(writeId).innerHTML = maxNumber - value.length;

    if (maxNumber - value.length <= 0) {
        document.getElementById(id).value = value.substring(0, maxNumber);
    }
}

function ChangeGuide(guideLink, tabName, tabID) {
    var tabs = document.getElementsByName(tabName);

    for (var i = 0; i < tabs.length; i++) {
        tabs[i].className = '';
    }

    document.getElementById(tabID).className = 'active';
    ajaxpage(guideLink, 'guide_content');
}

function ajaxpage2(url, containerid, pid, content_type) {
    var page_request = false
    if (window.XMLHttpRequest) // if Mozilla, Safari etc
        page_request = new XMLHttpRequest()
    else if (window.ActiveXObject) { // if IE
        try {
            page_request = new ActiveXObject("Msxml2.XMLHTTP")
        }
        catch (e) {
            try {
                page_request = new ActiveXObject("Microsoft.XMLHTTP")
            }
            catch (e) { }
        }
    }
    else
        return false


    page_request.onreadystatechange = function () {

        if (page_request.readyState == 4 && (page_request.status == 200 || window.location.href.indexOf("http") == -1)) {

            if (document.getElementById(containerid) != null) {
                document.getElementById(containerid).innerHTML = page_request.responseText;

                var selectedOptionID = 0;
                var selectedQuantity = 0;
                var normalselect = document.getElementById('select_menu' + pid);
                var quantityselect = document.getElementById('quantity' + pid);

                if (normalselect != null) {
                    if (normalselect.selectedIndex == -1)
                        selectedOptionID = 0;
                    else
                        selectedOptionID = document.getElementById('select_menu' + pid).value;
                }

                if (quantityselect != null) {
                    if (quantityselect.selectedIndex == -1)
                        selectedQuantity = 1;
                    else
                        selectedQuantity = document.getElementById('quantity' + pid).value;
                }

                if (normalselect != null) {
                    SetPrice(pid, selectedOptionID);
                }
                setQuantity(pid, selectedQuantity);
                SetPriceQuantity(pid, 'divChangePrices', '', '');

                tb_init('a.thickbox, area.thickbox, input.thickbox, div.thickbox'); //DON'T REMOVE THIS! Thickbox duplication is fixed in thickboxJS.asp script

                // FOR VIDEO2 CONTENT INICIALIZATION OF EQUAL HEIGHTS
                $(function () { equalHeights('ebTitle'); });
                $(function () { equalHeights('ebTxt'); });
                $(function () { equalHeights('whoTitle'); });

                // INITIALIZATON FOR RATING
                rating_init();

                SetActiveTab(content_type);
            }
        }
    }

    if (bustcachevar) //if bust caching of external page
        bustcacheparameter = (url.indexOf("?") != -1) ? "&" + new Date().getTime() : "?" + new Date().getTime()

    page_request.open('GET', url + bustcacheparameter, true)
    page_request.send(null)

}



function checkIfCADomainJS() {
    var dom

    dom = document.domain;

    if (dom == 'ca.avenija.com' || dom == 'ca.testavenija.com') {
        return 1;
    }
    else {
        return 0;
    }
}


function ajaxCall(xml, working_div_id, response_div_id, ajax_file, file_params, responseHTML) {
    // Kreiranje objekta
    var XMLHttpRequestObject = false;
    var params = file_params;
    var working = document.getElementById(working_div_id);

    // V odvisnosti od brskalnika se odloeim kako narediti XMLHttoRequest
    if (window.XMLHttpRequest) {
        // Za Mozillo in ostale brskalnike
        XMLHttpRequestObject = new XMLHttpRequest();
        // Če server vrne xml dokument
        if (xml) {
            XMLHttpRequestObject.overrideMimeType("text/xml");
        }
    }
    else if (window.ActiveXObject) {
        // Za Internet explorer
        XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
    }

    if (working) {
        working.innerHTML = '<span class="saving">Working</span>';
    }

    var response_id = document.getElementById(response_div_id);
    if (response_id) {
        if (XMLHttpRequestObject) {
            // Odprem XMLHttpRequest objekt z metodo GET
            XMLHttpRequestObject.open("POST", ajax_file);

            //Send the proper header information along with the request
            XMLHttpRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            XMLHttpRequestObject.setRequestHeader("Content-length", params.length);
            XMLHttpRequestObject.setRequestHeader("Connection", "close");

            XMLHttpRequestObject.onreadystatechange = function () {
                if (XMLHttpRequestObject.readyState == 4) { // Zaključen (complete)
                    if (XMLHttpRequestObject.status == 200) { // vse je v redu (ok)
                        if (working) {
                            working.innerHTML = responseHTML;
                        }
                        if (response_id) {
                            response_id.innerHTML = XMLHttpRequestObject.responseText;
                        }
                    }
                }
                else {
                    //alert(XMLHttpRequestObject.readystate);
                    //alert(XMLHttpRequestObject.status);
                }
            }
            XMLHttpRequestObject.send(params);
        }
        else {
            working.innerHTML = '<span class="zeleno">Sorry, your browser does not support Ajax.</span>';
        }
    }

}

function ajaxCallSendRecommend() {
    var params = '';
    var error = false;

    params = params + 'sender=' + document.getElementById('recommend_sender').value;
    params = params + '&receiver=' + document.getElementById('recommend_receiver').value;
    params = params + '&message=' + encodeURIComponent(document.getElementById('recommend_message').value);

    if (document.getElementById('recommend_sender').value == 'example@mail.com') {
        document.getElementById('recommend_sender').value = '';
    }

    if (document.getElementById('recommend_receiver').value == 'example@mail.com') {
        document.getElementById('recommend_receiver').value = '';
    }

    if (isValidEmail(document.getElementById('recommend_sender'))){
        error = true;
    }

    if (isValidEmail(document.getElementById('recommend_receiver'))){
        error = true;
    }

    if (!error) {
        ajaxCall(false, '', 'popup_mailFriend', 'engine_recommend_send_email.asp', params, '');
    }
}

/* ADDED ON 25.1.2012
* By Peter Trobec
* Adds some functionality for tn=cart2 city and zip code autocompletion
*/

function changeclass(id, newClass) {

    identity = document.getElementById(id);
    identity.className = newClass;

}

var digitsAndDashes = /[1234567890-]/g;
var digitsOnly = /[1234567890]/g;

function restrictCharacters(myfield, e, restrictionType) {
    if (!e) var e = window.event
    if (e.keyCode) code = e.keyCode;
    else if (e.which) code = e.which;
    var character = String.fromCharCode(code);

    // if they pressed esc... remove focus from field...
    if (code == 27) { this.blur(); return false; }

    // ignore if they are press other keys
    // strange because code: 39 is the down key AND ' key...
    // and DEL also equals .
    if (!e.ctrlKey && code != 9 && code != 8 && code != 36 && code != 37 && code != 38 && (code != 39 || (code == 39 && character == "'")) && code != 40) {
        if (character.match(restrictionType)) {
            return true;
        } else {
            return false;
        }

    }
}


/* ******************************************************* */
