﻿function move(srcSelect, trgtSelect)
{
	$("#" + srcSelect +" option:selected").each(function () {
        $(this).appendTo("#" + trgtSelect);
    });
}

function moveAll(srcSelect, trgtSelect)
{
	$("#" + srcSelect +" option").each(function () {
        $(this).appendTo("#" + trgtSelect);
    });
}

function selectAll(srcSelect) {
    var selectedVals = $("#" + srcSelect + " option").each(function () {
        $(this).attr("selected", "true");
    });
}

function getContent(url, divid, isSync, noLoaderImage) {
    var showLoading = true;
    if (noLoaderImage)
        showLoading = false;
    var isasync = true;
    if (isSync)
        isasync = false;
    var res = '';
    if (url != '') {
        if (url.indexOf('?') == -1)
            url = url + '?aj1=true';
        else
            url = url + '&aj1=true';
        var divId = "maincontent";
        if (divid)
            divId = divid;

        if (url.length > 512) {
            var index = url.indexOf('?');
            $.ajax({
                type: "POST",
                url: url.substring(0, index),
                data: url.substring(index + 1),
                cache: false,
                async: isasync,
                beforeSend: function () { requestStart(showLoading); },
                complete: function () { requestEnd(); },
                success: function (html) {
                    html = jQuery.trim(html);
                    if (html == 'login') {
                        changeWindowLocation(ctxPath + "/login");
                    }
                    else if (divId != 'nodiv') {
                        $("#" + divId).html(html);
                    }
                    else {
                        res = html;
                    }
                }
            });
        }
        else {
            $.ajax({
                type: "GET",
                url: url,
                async: isasync,
                cache: false,
                beforeSend: function () { requestStart(showLoading); },
                complete: function () { requestEnd(); },
                success: function (html) {
                    html = jQuery.trim(html);
                    if (html == 'login') {
                        changeWindowLocation(ctxPath + "/login");
                    }
                    else if (divId != 'nodiv') {
                        $("#" + divId).html(html);
                    }
                    else {
                        res = html;
                    }
                }
            });
        }
    }
    return res;
}

function prepareFormURL(formId, newAct) {
    var url = $("#" + formId).serialize();
    var act;
    if (newAct)
        act = newAct;
    else
        act = $("#" + formId).attr('action');

    if (act.indexOf('?') == '-1')
        url = act + '?' + url;
    else
        url = act + '&' + url;
    return url;
}

function requestStart(showLoader) {
    if (showLoader) {
        $('#ajaxloader').center();
        $('#ajaxloader').css('z-index', 2000);
        $('#ajaxloader').show();
    }
}

function requestEnd() {
    $('#ajaxloader').hide();
    if (typeof callback == 'function')
        callback();
}

function showFreeShippingCongrats(congratsText)
{
    alert(congratsText)
}
