function metertextoempw(tabla,campo,idiom,id,texto,empw) {

xmlHttp=GetXmlHttpObject()

if (xmlHttp==null || texto==null || texto=='')  {
//alert ("Browser does not support HTTP Request")
return
} 

var url = "/cms/markets/meterTexto.asp";
url=url+"?tabla="+tabla;
url=url+"&campo="+campo;
url=url+"&idiom="+idiom
url=url+"&id="+id;
url=url+"&texto="+texto;
url=url+"&empw="+empw;
url=url+"&sid="+Math.random()

//alert(url)

xmlHttp.onreadystatechange=function () { };
xmlHttp.open("GET",url,true)
xmlHttp.send(null)


}


function borrarLinea(linea,idpedido,empr,emp0) {
urlborrar='/cms/markets/baz_order_delete_item.asp?linea='+linea+'&idpedido='+idpedido+'&empresa='+empr+'&empresa0='+emp0;
//alert(urlborrar)
showURL2(urlborrar,'pedido');
//recalCular()
}



function borrarFotoPedido(linea,idpedido,arx) {
urlborrar='/borrarFoto.asp?linea='+linea+'&idpedido='+idpedido+'&arx='+arx;
showHint(urlborrar,'fotosVerPedido');
//recalCular()
}

function duplicarLinea(linea,idpedido,empr) {
urlduplicar='baz_order_duplic_item.asp?linea='+linea+'&idpedido='+idpedido+'&empresa='+empr;
window.location=(urlduplicar)
}



function showHint(url,capa) {

if (url.length==0)
{ 
document.getElementById(capa).innerHTML=""
return
}
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
} 
var url=url+"&sid="+Math.random()
//alert(url)
xmlHttp.onreadystatechange=function()  { 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
document.getElementById(capa).innerHTML=xmlHttp.responseText 
} 
} 

xmlHttp.open("GET",url,false)
xmlHttp.send(null)
}


function handleEnter (field, event) { 
        var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode; 
        if (keyCode == 13) { 
field.blur();
return false;
        } 
        else 
        return true; 
    }    



				
function isEmpty(s) {
	return ((s == null) || (s.length == 0));
}

function isDigit(c)
{
	return ((c >=0) && (c <=9));
}

function isInteger (s)
{
	if (isEmpty(s.value)) return false;
	for (var i = 0; i < s.value.length; i++)
		if (!isDigit(s.value.charAt(i))) return false;
	return true;
}

function isFloat(s)
{
	if (isEmpty(s.value))return false;
	if (isNaN(parseFloat(s.value))) return false;
	return true;
}

		
function isDecimalComa(s)
{
	for (i = 0; i < s.length; i++)
	{
		var c = s.charAt(i);
		if (c==".") return false;
	}
	data = s.split(",");
	if (data.length > 2) return false;
	parteEntera = data[0];
	if (isEmpty(parteEntera)) return false;
	for (i = 0; i < parteEntera.length; i++)
	{
		var c = parteEntera.charAt(i);
		if (!isDigit(c)) return false;
	}
	if (data.length > 1)
	{
		parteDecimal = data[1];
		if(parteDecimal.length > 2) //numero de decimales
			return false;
		if (isEmpty(parteDecimal)) return false;
		for (i = 0; i < parteDecimal.length; i++)
		{
			var c = parteDecimal.charAt(i);
			if (!isDigit(c)) return false;
		}
	}
	return true;
}

function anyCheck() {
var total = 0;
var max = document.delForm.p_dely.length;
if (eval("document.delForm.p_dely.checked") == true) {
    total += 1;
   }
for (var idx=0; idx < max; idx++) {
if (eval("document.delForm.p_dely[" + idx + "].checked") == true) {
    total += 1;
   }
}
if (total < 1) {
alert("No se ha seleccionado ninguna linea.");
return false;
}
else {
if (confirm("Está seguro de borrar las líneas seleccionadas")) {
return true;
}
else {
return false;
}
}
}

var checkflag = "false";
function check(field) {
if (checkflag == "false") {
document.delForm.p_dely.checked = true;
for (i = 0; i < field.length; i++) {
field[i].checked = true;}
checkflag = "true";
return "Uncheck All"; }
else {
document.delForm.p_dely.checked = false; 
for (i = 0; i < field.length; i++) {
field[i].checked = false; }
checkflag = "false";
return "Check All"; }
}





function valForm() {
if (document.calData.nombre.value =='' ) {
alert ("El campo Nombre no puede quedar en blanco");
document.calData.nombre.focus();
return false;
}

else if (document.calData.tel.value =='' ) {
alert ("El campo Tel\u00E9fono de contacto no puede quedar en blanco");
document.calData.tel.focus();
return false;
}
else if (document.calData.dire.value =='' ) {
alert ("El campo Direcci\u00f3n no puede quedar en blanco");
document.calData.dire.focus();
return false;
}
else if (document.calData.cp.value =='' ) {
alert ("El campo C\u00f3digo Postal no puede quedar en blanco");
document.calData.cp.focus();
return false;
}
else if (document.calData.pobIDsel.value =='' ) {
alert ("El campo Poblaci\u00f3n no puede quedar en blanco");
document.calData.tel.focus();
return false;
}
else if (document.calData.email.value =='' ) {
alert ("El campo E-mail no puede quedar en blanco");
document.calData.email.focus();
return false;
}
else if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.calData.email.value)==false) {
alert("El E-mail introducido no es v‡lido")
document.calData.email.focus();
return (false)
}
else if (document.calData.password.value =='' ) {
alert ("El campo Clave de acceso no puede quedar en blanco");
document.calData.password.focus();
return false;
}
else if (document.calData.password.value != document.calData.password2.value ) {
alert ("No coincide la confirmaci\u00f3n de la clave de acceso");
document.calData.password.focus();
return false;
}
else if (document.calData.dni.value =='' ) {
alert ("El campo DNI/NIF no puede quedar en blanco");
document.calData.dni.focus();
return false;
}
else if (eval("document.calData.condiciones.checked") == false) {
alert ("Debe aceptar las condiciones generales de venta.");
document.calData.condiciones.focus();
return false;
}
else {
document.calData.submit();
}
}


	

function sumarPedir(x,linea,uMinima,stock) { 
if (!uMinima) {uMinima=1;}
x=(x*1)+(uMinima);
if (x > stock) { 
x=stock
alert("No existen en stock m\u00E1s de "+stock+" unidades");
}
$("#quant"+linea).val(x)
} 

function comprobarStock(x,linea, uMinima,refVar) { 
stockCur=$("#quantTotalCur"+linea).val()
if (x*1 > stockCur*1) { 
x=stockCur;
alert("No existen m\u00E1s de "+stockCur+" unidades de este producto");
$("#quant"+linea).val(0)
$('#myModal'+refVar).html("No existen m\u00E1s de "+stockCur+" unidades de este producto")
} 
	return true;
}


function restarPedir(x, linea,uMinima,cantMinima) { 
if (!uMinima) {uMinima=1;}
x=(x*1)-(uMinima);
if (x<cantMinima) {x=cantMinima}
$("#quant"+linea).val(x)
} 

function validarPedido() {
    var unidades = parseInt(document.getElementById("unidades").value);
    var totalPedido = unidades * precioPorUnidad;
    if (totalPedido < 30) {
        alert("El pedido mínimo es de 30 euros.");
        // Ajustar las unidades para alcanzar el pedido mínimo
        var unidadesMinimas = Math.ceil(30 / precioPorUnidad);
        document.getElementById("unidades").value = unidadesMinimas;
    }
}





function sumar(x, um,stock,pedido,linea,ref,precioU) { 

precioTotal=$("#listatotal").val();
x=(x*1)+(um*1);
if (x > stock) { 
x=stock
}
$("#quant"+linea).val(x)
$("#totalLinea"+linea).html((precioU*x).toFixed(2))
$("#listatotalW").html((precioTotal*1+precioU).toFixed(2))
$("#listatotal").val(precioTotal*1+precioU)
//
actualizaPedido(pedido,linea,x,ref)
} 


function restar(x, um,stock,pedido,linea,ref,precioU,minimo) { 
precioTotal=$("#listatotal").val();
if (x > um) { 
x=x-um; 
if (x < minimo) { 
x=minimo;
} 
$("#quant"+linea).val(x)
$("#totalLinea"+linea).html((precioU*x).toFixed(2))
$("#listatotalW").html((precioTotal*1-precioU).toFixed(2))
$("#listatotal").val(precioTotal*1-precioU)
//
actualizaPedido(pedido,linea,x,ref)
} 
} 

function actualizaPedido1(x, um,stock,pedido,linea,ref,precioU) { 
precioTotal=$("#listatotal").val();
x=(x*1)+(um*1);
if (x > stock) { 
x=stock
}
if (x > um) { 
x=x-um; 

$("#quant"+linea).val(x)
$("#totalLinea"+linea).html((precioU*x).toFixed(2))
$("#listatotalW").html((precioU*x).toFixed(2))
$("#listatotal").val(precioU*x)
//
actualizaPedido(pedido,linea,x,ref)
} 
} 


function restarMK(x,stock,pedido,linea,ref,precioU,minimo,cantMinima,empweb,empweb0,precioMinimoPedido,idFab) {
precioTotal=$("#listatotal").val();
	
if (x > 0) { 
x=(x*1)-minimo; 
if (x < cantMinima) { 
//	alert(cantMinima+' UNIDADES');
x=cantMinima;
	//alert("pedido minimo");
} 
$("#quant"+linea).val(x)
$("#totalLinea"+linea).html((precioU*x).toFixed(2))
$("#listatotalW").html((precioTotal*1-precioU).toFixed(2))
$("#listatotal").val(precioTotal*1-precioU)
//
actualizaPedidoMK(pedido,linea,precioU,x,ref,stock,empweb,empweb0,0,idFab,precioMinimoPedido)

} 
}


function sumarMK(x, um, stock, pedido, linea, ref, precioU,empweb,empweb0,idFab,precioMinimoPedido) { 
//alert(x);
precioTotal=$("#listatotal").val();
x=(x*1)+(um*1);
if (x > stock ) { 
x=stock
alert("No existen en stock m\u00E1s de "+stock+" unidades");
} else {
$("#quant"+linea).val(x)
$("#totalLinea"+linea).html((precioU*x).toFixed(2))
$("#listatotalW").html((precioTotal*1+precioU).toFixed(2))
$("#listatotal").val(precioTotal*1+precioU)
//
actualizaPedidoMK(pedido,linea,precioU,x,ref,stock,empweb,empweb0,1,idFab,precioMinimoPedido);
} 
} 



function actualizaPedidoMK(pedido,linea,precio,q,ref,stock,empweb,empweb0,actStock,idFab,precioMinimoPedido) {
if (q > stock) { 
q=stock
alert("No existen en stock m\u00E1s de "+stock+" unidades");
$("#quant"+linea).val(q)
$("#quant"+ref).val(q)
}
urlactualiza='/cms/markets/cambiaEstadoLineaPedido.asp?precioLinea='+precio+'&idFab='+idFab+'&pmv='+precioMinimoPedido+'&ref='+ref+'&id_pedido='+pedido+'&linea='+linea+'&q='+q+'&empweb='+empweb+'&empweb0='+empweb0+'&actStock='+actStock;
//alert(urlactualiza);
HintMARKETS(urlactualiza,'pedidoTicket',linea,pedido,empweb,empweb0,precioMinimoPedido);

}



function cambiarIVA(id,IVA){
urlactualiza='/cms/cambiaIVA.asp?idProd='+id+'&IVA='+IVA;
//alert(urlactualiza);
showHint(urlactualiza);
}

function cambiaDTO(id,dto){
urlactualiza='/cms/cambiadto.asp?idProd='+id+'&dto='+dto;
//alert(urlactualiza);
showHint(urlactualiza);
}


function cambiarStock(id,stock){
urlactualiza='/cms/cambiaStock.asp?idProd='+id+'&stock='+stock;
//alert(urlactualiza);
showHint(urlactualiza);
}


function cambiarGrupoFamilia(idFamilia,grupo){
urlactualiza='/cms/cambiagrupofamilia.asp?idFamilia='+idFamilia+'&grupo='+grupo;
//alert(urlactualiza);
Hint(urlactualiza);
}


function regeneraMuestras(){
urlactualiza='/cms/markets/makebannersRistras.asp'
//alert(urlactualiza);
Hint(urlactualiza);
}



function actualizaPedido(pedido,linea,q,ref) {
urlactualiza='/cms/markets/cambiaEstadoLineaPedido.asp?ref='+ref+'&id_pedido='+pedido+'&linea='+linea+'&q='+q;
Hint(urlactualiza,'pedido');
}







function quitarMK(pedido,linea,q,ref,stock,empweb,empweb0,actStock,idFab,precioMinimoPedido,precio) {

$("#quant"+linea).val(q)
$("#quant"+ref).val(q)

urlactualiza='/cms/markets/cambiaEstadoLineaPedido.asp?precioLinea='+precio+'&idFab='+idFab+'&pmv='+precioMinimoPedido+'&ref='+ref+'&id_pedido='+pedido+'&linea='+linea+'&q='+q+'&empweb='+empweb+'&empweb0='+empweb0+'&actStock='+actStock;
//alert(urlactualiza);
HintMARKETS(urlactualiza,'pedidoTicket',linea,pedido,empweb,empweb0,precioMinimoPedido);

}



function actualizaCantidadesMARKETS(linea,q,ref,stock) {
if (q > stock) { 
q=stock
alert("No existen en stock m\u00E1s de "+stock+" unidades");
$("#quant"+linea).val(q)
$("#quant"+ref).val(q)
}

}




	function mostrarAlerta(msg) {
  // Crear el cuadro de diálogo

                    var alertaHTML = `
                        <div id="alerta" style="background-color: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; padding: 10px; margin: 20px;">
                            <strong>Alerta!</strong> ${msg}
                            <button id="botonAceptar">Aceptar</button>
                            <button id="botonVerProductos">Ver otros productos del vendedor</button>
                        </div>`;
                    $("#pedidoTicket").html(alertaHTML);

                    $('#botonAceptar').on('click', function() {
                        cerrarAlerta();
                        resolve('Aceptar');
                    });

                    $('#botonVerProductos').on('click', function() {
                        otroBoton();
                        resolve('VerProductos');
                    });
         
}

function cerrarAlerta() {
  // Eliminar el cuadro de diálogo al hacer clic en "Aceptar"
  document.body.removeChild(document.querySelector('#alerta'));
}

function otroBoton() {
window.location=('marketplace.asp?id_fab=267')
}
	

function HintMARKETS(url, capa1, linea, pedido, empweb, empweb0, pedidoMinimo) {
	
    $.ajax({
        type: "GET",
        url: url,
        success: function(response) {
            var idFab = response.idFab;
            var mensaje = response.mensaje;
			
            
            if (mensaje.trim() !== '--') {
                abrirModal(mensaje, idFab);
				console.log(mensaje);
            } else {
                // Manejar el caso en que el mensaje sea '--', si es necesario
                console.log("El mensaje es '--', no se mostrará en el modal.");
            }
            
            showTicketDiscount(pedido, empweb, empweb0, pedidoMinimo, mensaje, idFab);
        },
        beforeSend: function() {
            $("#pedidoTicket").busyLoad("show", {
                spinner: "accordion",
            });
        },
        complete: function() {
            $("#pedidoTicket").busyLoad("hide", {
                animation: "fade"
            });
        }
    });
}



function showTicketDiscount(p_order_id, empweb, empweb0, pedidoMinimo, mensaje, idFab) {

	msg1=mensaje
    var cupon = $("#cupon").val();
    var capa = "pedidoTicket";

    url = "/cms/markets/cambiaTicket.asp?empweb=" + empweb + "&empweb0=" + empweb0 + "&idPedido=" + p_order_id + "&cupon=" + cupon;

    $.busyLoadSetup({ animation: "fade", background: "rgba(51, 153, 0, 0.61)" });

    $.ajax({
        type: "GET",
        url: url,
        success: function(msg) {
            $("#" + capa).html(msg);
            if ($("#Ds_Merchant_Amount").val() < pedidoMinimo * 100) {
                $("#bloquePagar").css("display", "none");
            } else {
                $("#bloquePagar").css("display", "block");
            }

            if ($("#Ds_Merchant_Amount").val() > 0) {
                $("#optionFree").css("display", "none");
                $("#bloqueOpcionesPago").css("display", "block");
            } else {
                $("#bloqueOpcionesPago").css("display", "none");
                $("#optionFree").css("display", "block");
            }
             
  
        },
        beforeSend: function() {
            $("#pedidoTicket").busyLoad("show", {
                spinner: "accordion",
            });
        },
        complete: function() {
            $("#pedidoTicket").busyLoad("hide", {
                animation: "fade"
            });

            $("#pedidoTicket").css("background-color", "transparent");
            $(".loading-Ticket").css("display", "none");

            $("#Ds_Merchant_Amount").val($("#Ds_Merchant_AmountT").val());
            $("#DTOE").val($("#DTOET").val());
            $("#DTOESP").val($("#DTOESPT").val());
            $("#ivabase").val($("#ivabaseT").val());
            $("#ivagastos").val($("#ivagastosT").val());
            $("#IVApvp").val($("#IVApvpT").val());
            $("#base").val($("#baseT").val());
            $("#gastos").val($("#gastosT").val());
            $("#pvp").val($("#pvpT").val());
            $("#IVApvp").val($("#IVApvpT").val());
        }
    });
}

function abrirModal(mensaje,idFab) {
    // Aquí puedes abrir el modal con el mensaje recibido
    // Por ejemplo:
    $('#modalAlerta').modal('show');
    $('#modalMensaje').html(mensaje);
	    
    // Agregar el idFab al atributo href del enlace
    $('#enlaceProductos').attr('href', '/marketplace.asp?id_fab=' + idFab);
}



function showTicketDiscountPubli(p_order_id,pedidoMinimo,empweb,empweb0,idCliente,idProd) {


var cupon=$("#cupon").val();
var capa="pedidoTicket";


url="/cms/markets/cambiaTicketPubli.asp?empweb="+ empweb +"&empweb0="+ empweb0 +"&idFab="+ idCliente +"&idPedido="+ p_order_id +"&cupon="+cupon+"&idProd="+idProd+"&idCliente="+idCliente;
//alert(url)
$("#loadingTicket").css("display","block");

$.ajax({
type: "GET",
url: url,
success: function(msg){					
//$("#"+capa).fadeIn("fast"); 
$("#bloqueTicket").html(msg);

},
beforeSend: function(){
//$("#pedidoTicket").css("background-color","white");
//$(".loading-Ticket").css("display","block");
},
complete: function(){
$("#pedidoTicket").css("background-color","transparent");
$(".loading-Ticket").css("display","none");

	$("#Amount").val($("#pvpT").val());
	$("#precioMostrar").html($("#pvpT").val());
$("#DTOE").val($("#DTOET").val());
$("#DTOESP").val($("#DTOESPT").val());
	$("#ivabase").val($("#ivabaseT").val());
	$("#ivagastos").val($("#ivagastosT").val());
	$("#IVApvp").val($("#IVApvpT").val());
	$("#base").val($("#baseT").val());
	$("#gastos").val($("#gastosT").val());
	$("#pvp").val($("#pvpT").val());
	$("#IVApvp").val($("#IVApvpT").val());

if ( $("#pvpT").val() == '0,00') {
$("#formaPago").html("<a class=boton1 href='/cms/markets/forzarPagoPubli.asp?idPedido="+ p_order_id +"'>Confirmar el pedido</a>");
}

}
});  

}

////////////////////
function anularPedido(pedido) {
if (confirm("Deseas anular todo y empezar de nuevo")) {
window.location=('/anularpedido.asp');
}  
}



function closeReveal()
{
$('.close-reveal-modal').click();
  };



function cambiaValor2(campo,linea,valor) {

urlactualiza='/CambiaValor.asp?campo='+campo+'&linea='+linea+'&valor='+valor;
Hint(urlactualiza,'pedido');
showURL2("/pedido.asp",'pedidoWindow');

}



function cambiaValor2b(campo,linea,valor) {
var valor1=valor.split("|");
urlactualiza='/CambiaValor.asp?campo='+campo+'&linea='+linea+'&valor='+valor1[1];
Hint(urlactualiza,'pedido');
}



function gastos() {
vol=1;
cp=document.addlista.cp1.value;
pedidox=document.addlista.idPedido.value;
var url="/visualweb/foto/buscagastos.asp?cp="+cp
url+="&idPedido="+pedidox
url+="&volumen="+vol
url+='&sid='+Math.random()
Hint(url,'pedido');
}




function Hint(url,capa1) {

if (url.indexOf("?")>=0) {
var url=url+'&sid='+Math.random()
} else {
var url=url+'?sid='+Math.random()
}

$.ajax({
        type: "GET",
        url: url});  

} 



function showAjaxFoto(url,capa) {

    $.ajax({
        type: "GET",
        url: url,
            success: function(msg){
                	$("#"+capa).html(msg);		
                	     
            },
            beforeSend: function(){
      
        },
            complete: function(){

             
            }
        });  
 	
}




function showURL2(url,capa) {

if (url.indexOf("?")>=0) {
var url=url+'&sid='+Math.random()
} else {
var url=url+'?sid='+Math.random()
}


$("#loading").css("display","block");
    $.ajax({
        type: "GET",
        url: url,
            success: function(msg){
					
                	$("#"+capa).html(msg);		
                	$("#loading").css("display","none");     
            },
            beforeSend: function(){        	
			$("#loading").css("display","block");
        },
            complete: function(){
			$("#loading").css("display","none");
             
            }
        });  
 	
}


function GetXmlHttpObject(){ 
var objXMLHttp=null
if (window.XMLHttpRequest){
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject){
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
} 



function handleEnterMarkets (field, event) { 
        var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode; 
        if (keyCode == 13) { 
field.blur();
return false;
        } 
        else 
        return true; 
    }   
    
    
    function handleEnterTextoBuscar() { 

        buscarTextoMarkets();

        return false; 

        
    }   
    
    
function buscarTextoMarkets() {

tema	=document.buscar.tema.value;
emp		=document.buscar.emp0.value;
texto	=document.buscar.texto.value;


var url = "/cms/markets/buscaTextoProds.asp";
url=url+"?empweb0="+emp;
url=url+"&texto="+texto;
url=url+"&tema="+tema
url=url+"&sid="+Math.random()

//alert(url)
	
window.location=(url);

}

function cambiaFavorito(clienteCookie,idProd) {	
estado=$("#corEst-"+idProd).val()
if (estado==0) {
            $("#cor-"+idProd).attr("src", "/images/ico-cor-red.png");
            est=1
            estado=$("#corEst-"+idProd).val(1)
} else {
            $("#cor-"+idProd).attr("src", "/images/ico-cor.png");
            est=0
            estado=$("#corEst-"+idProd).val(0)
}

urlactualiza='/cms/markets/CambiaFavorita.asp?prod='+idProd+'&clienteCookie='+clienteCookie+'&valor='+est;
//alert(urlactualiza)
Hint(urlactualiza);
}


function openTab(evt, tabName) {
  // Declare all variables
  var i, tabcontent, tablinks;

  // Get all elements with class="tabcontent" and hide them
  tabcontent = document.getElementsByClassName("tabcontent");
  for (i = 0; i < tabcontent.length; i++) {
    tabcontent[i].style.display = "none";
  }

  // Get all elements with class="tablinks" and remove the class "active"
  tablinks = document.getElementsByClassName("tablinks");
  for (i = 0; i < tablinks.length; i++) {
    tablinks[i].className = tablinks[i].className.replace(" active", "");
  }

  // Show the current tab, and add an "active" class to the button that opened the tab
  document.getElementById(tabName).style.display = "block";
  evt.currentTarget.className += " active";
}



function countClics(bannerID) {
urlactualiza='/cms/markets/sumaClicsBanners.asp?bannerID='+bannerID;
//alert(urlactualiza)
Hint(urlactualiza);
return true
	
}


;(function ( $, window, document, undefined ) {
  var pluginName = 'svgInject';
  // The actual plugin constructor
  function Plugin(element, options) {
    this.element = element;
    this._name = pluginName;
    this.init();
  }
  Plugin.prototype = {
    init: function () {
      $(this.element).css('visibility', 'hidden');
      this.swapSVG(this.element);
    },
    swapSVG: function (el) {
      // This technique is based in part on:
      // http://www.snippetlib.com/jquery/replace_all_svg_images_with_inline_svg
      var imgURL = $(el).attr('src');
      var imgID = $(el).attr('id');
      var imgClass = $(el).attr('class');
      var imgData = $(el).clone(true).data();
      var dimensions = {
        w: $(el).attr('width'),
        h: $(el).attr('height')
      };
      $.get(imgURL, function (data) {
        var svg = $(data).find('svg');
        if (typeof imgID !== undefined) {
          svg = svg.attr('id', imgID);
        }
        if (typeof imgClass !== undefined) {
          var cls = (svg.attr('class') !== undefined) ? svg.attr('class') : '';
          svg = svg.attr('class', imgClass + ' ' + cls + ' replaced-svg');
        }
        // copy all the data elements from the img to the svg
        $.each(imgData, function (name, value) {
          //svg.data(name, value);
          //jQuery.data(svg, name, value);
          //svg[0].dataset[name] = value;
          svg[0].setAttribute('data-' + name, value);
        });
        svg = svg.removeAttr('xmlns:a');
        //Get original dimensions of SVG file to use as foundation for scaling based on img tag dimensions
        var ow = parseFloat(svg.attr('width'));
        var oh = parseFloat(svg.attr('height'));
        //Scale absolutely if both width and height attributes exist
        if (dimensions.w && dimensions.h) {
          $(svg).attr('width', dimensions.w);
          $(svg).attr('height', dimensions.h);
        }
        //Scale proportionally based on width
        else if (dimensions.w) {
          $(svg).attr('width', dimensions.w);
          $(svg).attr('height', (oh / ow) * dimensions.w);
        }
        //Scale proportionally based on height
        else if (dimensions.h) {
          $(svg).attr('height', dimensions.h);
          $(svg).attr('width', (ow / oh) * dimensions.h);
        }
        $(el).replaceWith(svg);
        //Wrap all SVG-associated JS within a function and run it - this will need some more work
        var js = new Function(svg.find('script').text());
        js();
      });
    }
  };
  $.fn[pluginName] = function (options) {
    return this.each(function () {
      if (!$.data(this, 'plugin_' + pluginName)) {
        $.data(this, 'plugin_' + pluginName, new Plugin(this, options));
      }
    });
  };
})(jQuery, window, document);
$('.svg-inject').svgInject();





function desglosarPedidos(e,gasto,proveedor) {
	
var pedidos = e.split(',');
var pedido	="";
var x	=0;
	if (proveedor==0 || !proveedor ) {proveedor=$("#idProveedor").val();}

var totalPedidos=0
$.each(pedidos, function(index, value){
	pedidoArr=value.split('-');
 pedido+=pedidoArr[pedidoArr.length - 1]*1 + "|"
	x+=1
	
	

});
	

	url="/cms/edit_markets_gastos_recPedidos.asp?idGasto="+gasto+"&idProveedor="+proveedor+"&numpedidos="+x+"&pedidos="+pedido;

	
	$.ajax({
        type: "GET",
        url: url,
            success: function(msg){					
  
												$("#desglosePedidos").html(msg);
													
												}
	});
	
	
}


