﻿jQuery(document).ready(function() {
    try {
        jQuery('img.tooltip').cluetip({ splitTitle: '|', cluetipClass: 'wctip' });
        //alert("1");
        jQuery('a.tooltip').cluetip({ showTitle: false, dropShadow: false, splitTitle: '|', cluetipClass: 'wctip', width: '150px' });
        jQuery('span.tooltip').cluetip({ showTitle: false, dropShadow: false, splitTitle: '|', cluetipClass: 'wctip' });
        jQuery('#minicartex').cluetip({
            local: true,
            hideLocal: true,
            cursor: 'pointer',
            closePosition: 'top',
            showTitle: false,
            positionBy: 'mouse',
            dropShadow: true,
            dropShadowSteps: '3',
            closePosition: 'top',
            closeText: '<div align="right"><img src="/images/close.gif" alt="" style="border:none;" /></div>',
            mouseOutClose: false,
            sticky: true,
            mouseOutClose: true
        });
        jQuery('.imgButton_font').hover(
            function() {
                this.className += " sfhover";
            },
            function() {
                this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
            });
        jQuery('tr', jQuery('.wc_productsList')).hover(
            function() {
                //if (!jQuery(this).hasClass("wc_head"))
                jQuery(this).addClass("highlight");                
            },
            function() {
                jQuery(this).removeClass("highlight");
            });
    }
    catch (err) { alert(err) }
});

function changeModuleTitle(id, title) 
{
	try
	{
    	//jQuery("#"+id+"_dnnTITLE_lblTitle").get()[0].innerHTML = title;
	}
	catch(err){}
}

function ExpandAllRows(id)
{ 
    var ctrl = jQuery("a", jQuery("#"+id)).get()
    
    for(var i=0;i<ctrl.length;i++)
    {
        if(ctrl[i].className == "expander")
            TglRow(ctrl[i]);
    } 
}

function CollapseAllRows(id)
{
    var ctrl = jQuery("a", jQuery("#"+id)).get()
    
    for(var i=0;i<ctrl.length;i++)
    {
        if(ctrl[i].className == "collapser")
            TglRow(ctrl[i]);
    }
}

function encodeMyHtml(ctrlFromID, ctrlToID) 
{
    try{
        // save to hiden filed
        jQuery('#'+ctrlToID).val(htmlEncode(jQuery('#'+ctrlFromID).val()));
        // clear textbox
        jQuery('#'+ctrlFromID).val("");
        return true;
    }
    catch(err)
    {
        return false;
    }
    return true;
} 
function decodeMyHtml(ctrlFromID, ctrlToID) 
{       
    jQuery('#'+ctrlToID).val(htmlDecode(jQuery('#'+ctrlFromID).val()));
} 
function htmlEncode(s) {
        var str = new String(s);
        str = str.replace(/&/g, "&amp;");
        str = str.replace(/</g, "&lt;");
        str = str.replace(/>/g, "&gt;");
        str = str.replace(/"/g, "&quot;");
        return str;
}
function htmlDecode(s) {
        var str = new String(s);
        str = str.replace("&amp;", "&" );
        str = str.replace("&lt;", "<" );
        str = str.replace("&gt;", ">" );
        str = str.replace("&quot;", "\"" );
        return str;
}
function encodeStaticTextInLanguageEditor(containerID)
{
    var inputs = jQuery("textarea", jQuery('#'+containerID)).get();
    for(var i=0;i<inputs.length;i++)
    {
        try{
            inputs[i].value = htmlEncode(inputs[i].value);
        }
        catch(er){
            alert(er)
            break;
        }
    }
}

function changePriceWay(ctrlShow, ctrlHide)
{
    jQuery("#"+ctrlShow).css("display", "block");
    jQuery("#"+ctrlHide).css("display", "none");
}


// hide module if it shouldn't be visible
function hideModule(ctrlModule, show)
{
    if (show.toLowerCase() == "false")
    {
       var div = jQuery("#"+ctrlModule).parents("div.wcInfoContainer").get();
       jQuery(div).css("display", "none");
    }
}

function showDiv(source, id) {
    jQuery(id).css('display', 'block');
    jQuery(source).css('cursor', 'default');
    //jQuery(source).attr('href', 'javascript:hideDiv('+source+','+id+')');
}

function hideDiv(source, id) {
    jQuery(id).css('display', 'block');
    //jQuery(source).attr('href', 'javascript:showDiv(' + source + ',' + id + ')');
}

function openOtherCountry(ddl) {
    location.href = jQuery('#'+ddl).val();
}

function showLostPassword() {
    jQuery.get("/Default.aspx?tabid=57&ctl=SendPassword", function(data) {
        var div = jQuery("#lostPassword"); 
        //var lostPasswordContentID = ".containercontent_white";
        var lostPasswordContentID = ".containerempty_center_dark";
        div.html(jQuery(lostPasswordContentID, data).html());
        div.css("display", "block");
        jQuery("#lostPasswordMessage").css("display", "none");
        jQuery("#lostPasswordMessageError").css("display", "none");
    });
}

function sendLostPassword(user) {
    jQuery.get("/Default.aspx?tabid=57&ctl=SendPassword&user=" + user, function(data) {
        jQuery("#lostPassword").css("display", "none");
        if (user.trim() != "" && jQuery("#dnn_ctr_ctl00_lblMessage", data).html() == null)
            jQuery("#lostPasswordMessage").css("display", "block");
        else if (user.trim() != "")
            jQuery("#lostPasswordMessageError").css("display", "block");
    });
}

//function hideItemsInMiniCart() {
//    //jQuery.get("/Default.aspx?tabid=177&hideContent=minicart", function(data) {
//        
//    //});
//}


/* menu [START] */
var timeout;
var menus = Array();
//var $j = jQuery.noConflict();
var isIE = jQuery.browser.msie;
var pageLoaded = false;

if (window.addEventListener)
    window.addEventListener("load", pageLoad, false);
else if (window.attachEvent)
    window.attachEvent("onload", pageLoad);

function pageLoad() {
    pageLoaded = true;
    if (isIE) {
        // Finesse IE into not displaying "Click to activate and use this control"
        objects = document.getElementsByTagName("object");
        for (var i = 0; i < objects.length; i++) {
            objects[i].outerHTML = objects[i].outerHTML;
        }
    }
}
function DOMBrowser() {
    return document.body && document.body.style && document.getElementById;
}
function getX(elem) {
    var x = 0;
    if (elem.offsetParent)
        x = getX(elem.offsetParent);
    return x + elem.offsetLeft;
}
function getY(elem) {
    var y = 0;
    if (elem.offsetParent)
        y = getY(elem.offsetParent);
    return y + elem.offsetTop;
}
var lastMenu;
function enterMenu(elem, below) {
    if (DOMBrowser()) {
        parentDiv = elem.offsetParent.id;
        hideMenus(parentDiv, elem);
        showSubmenu(elem, below);
        if (timeout)
            clearTimeout(timeout);
    }
    return true;
}
function leaveMenu(elem) {
    if (DOMBrowser()) {
        lastMenu = "";
        if (elem)
            lastMenu = elem.offsetParent.id;
        timeout = setTimeout("hideMenus()", 500);
    }
    return true;
}
function getXPos(elem, child, below) {
    child.visible = false;
    // Temporarily set the display to block so that we can calculate offsetWidth/Height
    child.style.display = "block";
    parentX = getX(elem);
    if (below)
        x = parentX + 5;
    else
        x = parentX + elem.offsetWidth - 5;
    if (x + child.offsetWidth > document.body.clientWidth + document.body.scrollLeft) { // If the menu would appear offscreen:
        if (parentX - child.offsetWidth - document.body.scrollLeft + 5 > 0) { // If there's room to the left of the parent menu:
            x = parentX - child.offsetWidth + document.body.scrollLeft + 5;
        } else { // Fit as much in as possible:
            availSpace = (document.body.clientWidth - elem.offsetWidth) / 2;
            x = document.body.clientWidth + document.body.scrollLeft - child.offsetWidth;
            if (parentX > availSpace)
                x = 0;
            //Don't overlap the parent:
            if (x == parentX) x -= 5;
        }
    }
    child.style.display = "none";
    return x;
}
function getYPos(elem, child, below) {
    child.visible = false;
    // Temporarily set the display to block so that we can calculate offsetWidth/Height
    child.style.display = "block";
    parentY = getY(elem);
    if (below)
        y = parentY + elem.offsetHeight - 5;
    else
        y = parentY + 5;
    if (y + child.offsetHeight > document.body.clientHeight + document.body.scrollTop) { // If the menu would appear offscreen:
        if (parentY - child.offsetHeight - document.body.scrollTop + 20 > 0) { // If there's room above the parent menu:
            y = parentY - child.offsetHeight + document.body.scrollTop + 20;
        } else { // Fit as much in as possible:
            y = document.body.clientHeight + document.body.scrollTop - child.offsetHeight - 5;
            if (y < 0) y = 0;
        }
    }
    child.style.display = "none";
    return y;
}
function showSubMenu(id) { }
function showSubmenu(elem, below) {
    var id = elem.id + "_submenu";
    menu = document.getElementById(id);
    if (menu && lastMenu != id) {
        // Reset display so that browsers are not confused when we postion (Opera in particular)
        // No longer needed?  11/30/05 MO
        //menu.style.display = "none";

        //menu.style.top = getYPos(elem, menu, below);
        jQuery(menu).css("top", getYPos(elem, menu, below));
        //menu.style.left = getXPos(elem, menu, below);
        jQuery(menu).css("left", getXPos(elem, menu, below));
        //menu.style.zIndex = 1000;
        jQuery(menu).css("zIndex", 1000);
        //menu.style.display = "block";
        jQuery(menu).css("display", "block");

        tab = document.getElementById(elem.id + "_img");
        if (tab)
            tab.src = tab.src.replace(/(.*)_off\.(.*)/, "$1_on.$2");
        // Only create the iframe element if the page has been loaded.  Otherwise, 
        // "Operation aborted" messages appear and the page won't load.
        if (isIE && pageLoaded) {
            var ifr = document.createElement("IFRAME");
            if (ifr) {
                document.body.appendChild(ifr);
                ifr.style.position = "absolute";
                ifr.style.width = menu.offsetWidth;
                ifr.style.height = menu.offsetHeight;
                ifr.style.top = menu.style.top;
                ifr.style.left = menu.style.left;
                ifr.style.zIndex = menu.style.zIndex - 1;
                ifr.style.display = "block";
                menu.iframe = ifr;
            }
        }
        menus.push(menu);
    }
}
function hideMenus(elemID, currentTarget) {
    if (currentTarget) {
        var nextChild = document.getElementById(currentTarget.id + "_submenu");
        // If we're about to re-show the currently displayed menu, bail early to
        // avoid flickering
        if (nextChild && nextChild.id == lastMenu)
            return;
    }
    // Hide up to the passed element:
    var elem;
    if (elemID)
        elem = document.getElementById(elemID);
    while (men = menus.pop()) {
        if (elem && men.id == elem.id) {
            menus.push(men); // Put the match back into the array
            return;
        } else {
            men.style.display = "none";
            if (isIE && men.iframe)
                document.body.removeChild(men.iframe);
            tab = document.getElementById(men.id.replace(/(.*)_submenu/, "$1") + "_img");
            if (tab)
                tab.src = tab.src.replace(/(.*)_on\.(.*)/, "$1_off.$2");
        }
    }
}
/* menu [END] */

function block(e) {
    return (e.keyCode == 8 || e.keyCode == 46 || e.keyCode == 9); 
}
function blockDecimal(e) {
    if (e.shiftkey) return false;
    return (e.keyCode == 8 || e.keyCode == 46 || e.keyCode == 9 || e.keyCode == 109 || (e.keyCode >= 48 && e.keyCode <= 57) || (e.keyCode >= 96 && e.keyCode <= 105));
}

/* OfferCreator [START] */

// .quantity
// .priceNettoRRC
// .priceNetto
// .totalPriceNettoRRC
// .totalPriceNetto
// .currencyRRC
// .currency

function CurrencyFormatted(amount) {
    var i = parseFloat(amount);
    if (isNaN(i)) { i = 0.00; }
    var minus = '';
    if (i < 0) { minus = '-'; }
    i = Math.abs(i);
    i = parseInt((i + .005) * 100);
    i = i / 100;
    s = new String(i).replace('.', ',');
    if (s.indexOf(',') < 0) { s += ',00'; }
    if (s.indexOf(',') == (s.length - 2)) { s += '0'; }
    s = minus + s;
    return s;
}

function getPrice(str) {
    if (str == undefined)
        return parseFloat('0');
    var p = parseFloat(str.toString().replace(',', '.'));
    if (p.toString() == 'NaN')
        p = parseFloat('0');
    return Math.round(p * 100) / 100;
}
function setPrice(dec) {
    var p = getPrice(dec.toString());
    return CurrencyFormatted(p);
}
function getExRate(arg1, arg2) {
    //return getPrice(getExchangeRate(arg1) / getExchangeRate(arg2));
    return getExchangeRate(arg1) / getExchangeRate(arg2);
}
function getExchangeRate(value) {
    var exchangeRate;
    if (value == 'PLN') {
        exchangeRate = getPrice('1');
    }
    else if (value == 'USD') {
        exchangeRate = getPrice(jQuery(txtCurrencyUSD).val());
        jQuery(txtCurrencyUSD).val(setPrice(exchangeRate));
        // correct eur exchange rate
        jQuery(txtCurrencyEUR).val(setPrice(jQuery(txtCurrencyEUR).val()));
    }
    else if (value == 'EUR') {
        exchangeRate = getPrice(jQuery(txtCurrencyEUR).val());
        jQuery(txtCurrencyEUR).val(setPrice(exchangeRate));
        // correct usd exchange rate
        jQuery(txtCurrencyUSD).val(setPrice(jQuery(txtCurrencyUSD).val()));
    }
    return exchangeRate;
}
function changeItemPrices() {
    // show item price
    if (jQuery(chbChangePrices + ':checked').length != 0) {
        jQuery('input.priceNetto', lstItems).show();
        jQuery('span.priceNetto', lstItems).hide();
        jQuery(rdoCoating + ',' + rdoMargin + ',' + txtPercent + ',' + chbAllPrice).attr('disabled', 'disabled');
    }
    else {
        jQuery('input.priceNetto', lstItems).hide();
        jQuery('span.priceNetto', lstItems).show();
        jQuery(rdoCoating + ',' + rdoMargin + ',' + txtPercent + ',' + chbAllPrice).removeAttr('disabled');
    }
    recountAll();    
}
function recountAll() {
    if (stopRecount) return;

    stopRecount = true;

    // show part number    
    if (jQuery(chbProductCode + ':checked').length != 0) {
        jQuery('.pn', lstItems).show();
    }
    else {
        jQuery('.pn', lstItems).hide();
    }
    
    var totalRRC = parseFloat('0');
    var total = parseFloat('0');
    var clientNetto = parseFloat('0');
    var vat = parseFloat('0');
    var totalVat = parseFloat('0');
    var percent = parseFloat(jQuery(txtPercent).val()) / 100;
    var rrcCur = jQuery(ddlCurrencyRRC).val();
    var offerCur = jQuery(ddlCurrencyOffer).val();
    var exr = getExRate(offerCur, rrcCur);

    jQuery('tr', lstItems).each(function(i, e) {
        if (!jQuery(this).hasClass('wc_head')) {
            var q = getPrice(jQuery('.quantity', jQuery(this)).val());
            var pRRC = getPrice(jQuery('.priceNettoRRC', jQuery(this)).text());
            var cRRC = jQuery('.currencyRRC', jQuery(this)).text();

            pRRC = pRRC * getExRate(cRRC, rrcCur);

            var price;
            if (jQuery(rdoCoating + ':checked').length != 0) { // narzut
                price = (pRRC / (1 - percent)) / exr;
            }
            else { // marża
                price = (pRRC + pRRC * percent) / exr;
            }
            jQuery('span.priceNetto', jQuery(this)).text(setPrice(price));

            // override item price
            var p = parseFloat('0');
            if (jQuery(chbChangePrices + ':checked').length != 0) {
                p = getPrice(jQuery('input.priceNetto', jQuery(this)).val());
                //jQuery('span.priceNetto', jQuery(this)).text(p);
            }
            else {
                p = getPrice(jQuery('span.priceNetto', jQuery(this)).text());
            }
            //jQuery('input.priceNetto', jQuery(this)).val(p);

            jQuery('.totalPriceNetto', jQuery(this)).text(setPrice(p * q));
            jQuery('.totalPriceNettoRRC', jQuery(this)).text(setPrice(pRRC * q));

            var tp = getPrice(jQuery('.totalPriceNetto', jQuery(this)).text());
            var tpRRC = getPrice(jQuery('.totalPriceNettoRRC', jQuery(this)).text());

            jQuery('.currency', jQuery(this)).text(offerCur);

            total += tp;
            totalRRC += tpRRC;
        }
    });

    clientNetto = total;
        
    // set total & client netto
    if (jQuery(chbAllPrice + ':checked').length != 0) {
        clientNetto = getPrice(jQuery(txtAllPrice).val());
        jQuery(txtAllPrice).val(clientNetto);
        jQuery(txtAllPrice + ',' + chbChangePrices).removeAttr('disabled')
        jQuery(chbChangePrices).attr('disabled', 'disabled');
        jQuery('#clientNetto').show();
    }
    else {
        //jQuery(txtAllPrice).val(setPrice(total));
        jQuery(txtAllPrice).val('');
        jQuery(txtAllPrice + ',' + chbChangePrices).attr('disabled', 'disabled');
        jQuery(chbChangePrices).removeAttr('disabled')
        jQuery('#clientNetto').hide();
    }
    
//    // set coating or margin
//    if (jQuery(chbChangePrices + ':checked').length != 0) {
//        if (jQuery(rdoCoating + ':checked').length != 0) { // narzut
//            jQuery(txtPercent).val(setPrice(Math.max(Math.round(((clientNetto - totalRRC) / clientNetto) * 100)), 0));   
//        }
//        else { // marża
//            jQuery(txtPercent).val(setPrice(Math.max(Math.round(((clientNetto - totalRRC) / totalRRC) * 100)), 0));
//        }        
//    }    

    // set summary
    jQuery(lblSummary).text(format(summaryText, setPrice(clientNetto - totalRRC /* exr*/), offerCur));

    var showVat = false;
    if (jQuery(chbVat + ':checked').length != 0) {
        vat = clientNetto * 0.23;
        showVat = true;
        jQuery('.vat_switch').show();
        jQuery('.not_vat_switch').hide();
        if (jQuery(chbAllPrice + ':checked').length != 0) {
            jQuery('#clientNetto').show();
        }
        else {
            jQuery('#clientNetto').hide();
        }
    }
    else {
        jQuery('.vat_switch').hide();
        jQuery('.not_vat_switch').show();
    }

    totalVat = clientNetto + vat;

    var percentText = marginText;
    if (jQuery(rdoCoating + ':checked').length != 0) { // narzut
        percentText = coatingText;
    }

    // set price settings summary
    if (jQuery(chbAllPrice + ':checked').length != 0) {
        jQuery(lblPricesSettingsSummary).text(format(pricesSettingsSummaryText, percentText, setPrice(percent * 100), setPrice(clientNetto), offerCur, showVat ? 'VAT 23% | ' : '', jQuery(txtCurrencyUSD).val(), jQuery(txtCurrencyEUR).val()));
    }
    else {
        jQuery(lblPricesSettingsSummary).text(format(pricesSettingsSummaryText2, percentText, setPrice(percent * 100), showVat ? 'VAT 23% | ' : '', jQuery(txtCurrencyUSD).val(), jQuery(txtCurrencyEUR).val()));
    }

    // set prices
    jQuery(lblNettoValue).text(format('{0} {1}', setPrice(total), offerCur));
    jQuery(lblClientNettoValue).text(format('{0} {1}', setPrice(clientNetto), offerCur));
    jQuery(lblVatValue).text(format('{0} {1}', setPrice(vat), offerCur));
    jQuery(lblBruttoValue).text(format('{0} {1}', setPrice(totalVat), offerCur));

    stopRecount = false;

    return false;
}
function printOffer() {

    var writer =jQuery('<div>');
    var content = jQuery('<div>').attr('id', 'copyToClipboard').attr('class','offer');
    content.append(format('<div class="offerWindowTitle">{0}</div>', jQuery(lblOfferWindowTitle).text()));
    content.append(format('<div class="offerWindowInstrucion">{0}</div>', jQuery(lblOfferWindowInstrucion).text()));
    content.append('<div class="offerWindowSpliter">&nbsp;</div>');
    if (jQuery(txtNumber).val().trim() != '') {
        content.append(format('<div class="offerWindowLine1a">{0}: {1}</div>',
            jQuery(lblNumber).text(),
            jQuery(txtNumber).val()));
    }
    if (jQuery(txtCreateDate).val().trim() != '' ) {
        content.append(format('<div class="offerWindowLine1b">{0}: {1}</div>',
            jQuery(lblCreateDate).text(),
            jQuery(txtCreateDate).val()));
    }
    if (jQuery(txtDate).val().trim() != '') {
        content.append(format('<div class="offerWindowLine1c">{0}: {1}</div>',
            jQuery(lblDate).text(),
            jQuery(txtDate).val()));
    }
    if (jQuery(txtCreatedFor).val().trim() != '') {
        content.append(format('<div class="offerWindowLine2">{0}: {1}</div>', jQuery(lblCreatedFor).text(), jQuery(txtCreatedFor).val()));
    }
    if (jQuery(txtCreatedBy).val().trim() != '' || jQuery(txtCompanyName).val().trim() != '') {
        content.append(format('<div class="offerWindowLine3">{0}: {1}{2}{3}</div>',
            jQuery(lblCreatedBy).text(),
            jQuery(txtCreatedBy).val().trim() != '' ? jQuery(txtCreatedBy).val() : '',
            jQuery(txtCreatedBy).val().trim() != '' && jQuery(txtCompanyName).val().trim() != '' ? ' | ' : '',
            jQuery(txtCompanyName).val()));
    }
    if (jQuery(txtPrefix).val().trim() != '') {
        content.append(format('<div class="offerWindowLine4">{0}</div>', jQuery(txtPrefix).val()));
    }

    //var table = jQuery(jQuery(lstItems).parent().html());
    var table = jQuery(lstItems).clone();

    var index = 0;
    var quantitiesArray = new Array();
    jQuery('tr', lstItems).each(function(i, e) {
        if (!jQuery(this).hasClass('wc_head')) {
            var q = getPrice(jQuery('.quantity', jQuery(this)).val());
            quantitiesArray[index] = q;
            index++;
        }
    });
    index = 0;
    jQuery('tr', table).each(function(i, e) {
        if (!jQuery(this).hasClass('wc_head')) {
            jQuery('input.quantity', jQuery(this)).replaceWith(quantitiesArray[index]);            
            index++;
        }
        jQuery('input, .hide', jQuery(this)).replaceWith('');
        jQuery('span', jQuery(this)).show();        
    });

    content.append(table);
    var summaryDiv = jQuery('.summaryDiv').parent().clone();
    content.append(jQuery(summaryDiv ).css('float','none').html());
    if (jQuery(txtSufix).val().trim() != '') {
        content.append(format('<div class="offerWindowLine5">{0}</div>', jQuery(txtSufix).val()));
    }
    writer.html(content);

    // create ne window for print content
    var w = window.open('', '', 'width=700,height=800,menubar=no,status=no,titlebar=no,toolbar=no,scrollbars=yes');
    w.document.write("<html><head><link href='/Portals/0/style.css' rel='stylesheet' type='text/css' /><link href='/Portals/0/print_offer.css' rel='stylesheet' type='text/css' /></head><body>");
    // set print content to new window    
    w.document.write(writer.html());
    w.document.write("</body></html>")
    // set focus to new window
    w.focus();
    // move to 0,0;
    w.moveTo(0, 0);  
    
    return false;
}

function format(str)
{
  for(i = 1; i < arguments.length; i++)
  {
      str = str.replace('{' + (i - 1) + '}', arguments[i]);
  }
  return str;
}

/* OfferCreator [END] */

/* List [START] */
var ajaxurl = "/API/ProductListApi.asmx/";
function AjaxFailed(result) {
    alert(result.status + ' ' + result.statusText);
}
jQuery(document).ready(function() {
    jQuery('span.price_show').click(function() {
        var span = jQuery(this).get(0);
        var hid = jQuery('input:hidden', jQuery(span).parent()).val();

        var pid = hid.split('|')[0];
        var erp = hid.split('|')[1];
        var cur = hid.split('|')[2];

        jQuery.ajax({
            type: "POST",
            url: ajaxurl + "GetProductPrice",
            cache: false,
            data: "{'pid': '" + pid + "', erp: '" + erp + "', cur: '" + cur + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(result) {
                var pfp = jQuery('.pfp', jQuery(span).parent().parent());
                var peu = jQuery('.peu', jQuery(span).parent().parent());
                pfp.html(result.d[0]);
                peu.html(result.d[1]);
            },
            error: AjaxFailed
        });
    });
    jQuery('span.price_show_all').click(function() {
        var erp = '';
        var cur = '';
        var pids = "[";
        var rows = jQuery('table.wc_productsList tr');
        jQuery(rows).each(function() {
            if (jQuery(this).hasClass('wc_head')) return;
            var hid = jQuery('input:hidden:first', jQuery(this)).val();

            var pid = hid.split('|')[0];
            erp = hid.split('|')[1];
            cur = hid.split('|')[2];

            if (pid == undefined) return;
            pids += "'" + pid + "',";
        });
        pids += "'']";
        //var span = jQuery(this).get(0);

        jQuery.ajax({
            type: "POST",
            url: ajaxurl + "GetProductsPrices",
            cache: false,
            data: "{'pids': " + pids + ", erp: '" + erp + "', cur: '" + cur + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(result) {
                jQuery(rows).each(function() {
                    if (jQuery(this).hasClass('wc_head')) return;

                    var h = jQuery('input:hidden:first', jQuery(this));                                        
                    var pid = h.val().split('|')[0];
                    if (pid == undefined) return;
                    for (i = 0; i < result.d.length; i++) {
                        if (result.d[i][0].toString() == pid.toString()) {
                            var pfp = jQuery('.pfp', jQuery(h).parent().parent());
                            var peu = jQuery('.peu', jQuery(h).parent().parent());
                            pfp.html(result.d[i][1]);
                            peu.html(result.d[i][2]);
                            break;
                        }
                    }
                });
            },
            error: AjaxFailed
        });
    });
});
function GetProductsPrices(ctrl) {
    jQuery.ajax({
        type: "POST",
        url: ajaxurl + "GetProductsPrices",
        cache: false,
        data: "{'pids': ['1','2']}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(result) {
            alert(result.d);
        },
        error: AjaxFailed
    });
}
  

/* List [END] */
