//jq
$(document).ready(function(){

// Insertamos la imagen
  $('body').append(
    $('<div>').attr('id', 'loading').append(
        $('<img>').attr({src:'http://www.aginformatica.es/imagenes/spinner.gif', alt:'Cargando...', width:'16', height:'16'})
      ).css({
        position: 'absolute',
        display: 'none'
      })
    );

  // Reposicionado de la imagen
  $(document).mousemove(function(e){
    $('#loading').css({left: e.pageX + 10, top: e.pageY + 15});
  });
  
  // Eventos globales
	$('#loading').bind('ajaxStart', function(){
		//$(this).show();
	  }).bind('ajaxStop', function(){
		//$(this).hide();
	  });
	
	

	$(".comprar").click(agregarCesta);
	
	function agregarCesta()//agregar un producto a la cesta
	{
		if($(this).attr('href') != "")
		{
			$.ajax({
				url: $(this).attr('href'),
				cache: false,
				beforeSend: function(){
					$('#mainContent').after($('<div>').attr('id', 'mascara').addClass("mascara"));
					$('#msg-fijo').css({opacity: '0.75', filter:'Alpha(Opacity=75)'}).fadeIn();
					$('#loading').show();
				},
				success: function(){
					$('#inc_carrito').fadeTo("slow",0.1, function() {
    				    var Rcarrito = "http://www.aginformatica.es/includes/include_carrito.asp?noCache=" + new Date().getTime();
						var Rlineas = "http://www.aginformatica.es/mi-cesta/inc_mi_cesta.asp?noCache=" + new Date().getTime();
						var Vtienda_01 = "http://www.aginformatica.es/pasar-por-caja/inc_pasar_por_caja.asp?noCache=" + new Date().getTime();
						$('#inc_carrito').load(Rcarrito).fadeTo("slow",1);
						$('#inc_su_cesta').load(Rlineas).fadeTo("slow",1);
						$('#inc_tienda_01').load(Vtienda_01).fadeTo("slow",1);
						$(this).attr('href', "");
						$('#mascara').remove();
						$('#msg-fijo').css({opacity: '0', filter:'Alpha(Opacity=0)'}).hide();
						$('#loading').hide();
				    });
				}
			});
		}
		return false;
	}

});
//fin jq


//Para levantar popups y redireccionar

function verURL(miURL, redir){ 
	var winl = (screen.width - 650) / 2;
	var wint = (screen.height - 450) / 2; 
	winprops = 'height=450,width=650,top='+wint+',left='+winl+',scrollbars=yes,resizable=no'
	miPopup = window.open(miURL,"miwin",winprops) 
	miPopup.focus()
	window.location.href=redir;
	}

//Pasa presupuesto a cesta o lo guarda

function ir(accion)
{
	if (accion == "Pasar a cesta")
	{
	document.form1.method = "Post"
	document.form1.action = "http://www.aginformatica.es/configurar-pc/pasar-presupuesto-a-cesta/"
	document.form1.submit()
	}
	else
	{
	  if ((document.form1.id.value.indexOf ('@', 0) == -1)||(document.form1.id.value.length < 5)) { 
		alert("Escriba una dirección de correo válida en el campo \"Dirección de correo\" destinatino."); 
		return (false); 
	  }
	document.form1.method = "Post"
	document.form1.action = "../../guardar-presupuesto/"
	document.form1.submit()
	}
}

//Nueva ventana popup

function NewWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=no'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion)>= 4) { win.window.focus(); }
}

//Muestra popup de producto

var Popup 
function abreProducto(codigo){ 
   var winl = (screen.width - 650) / 2;
   var wint = (screen.height - 450) / 2; 
   winprops = 'height=450,width=650,top='+wint+',left='+winl+',scrollbars=yes,resizable=no'
   Popup = window.open("http://www.aginformatica.es/configurar-pc/ver-producto/?codigo="+codigo,"miwin",winprops) 
   Popup.focus() 
} 


//Lista de precios

function abreListaprecios(){ 
   var winl = (screen.width - 650) / 2;
   var wint = (screen.height - 450) / 2; 
   winprops = 'height=450,width=650,top='+wint+',left='+winl+',scrollbars=yes,resizable=no'
   Popup = window.open("http://www.aginformatica.es/listado-de-precios/","miwin",winprops) 
   Popup.focus() 
} 


//Imprimir pop up

function imprimirPagina() {
  if (window.print)
    window.print();
  else
    alert("Lo siento, pero a tu navegador no se le puede ordenar imprimir" +
      " desde la web. Actualizate o hazlo desde los menús");
}


//Abre listado productos configuraciones

var Popup 
function abreListado(url){ 
   var winl = (screen.width - 650) / 2;
   var wint = (screen.height - 450) / 2; 
   winprops = 'height=450,width=650,top='+wint+',left='+winl+',scrollbars=yes,resizable=no'
   Popup = window.open("http://www.aginformatica.es/configurar-pc/listado-categoria/?categoria="+url,"miwin",winprops) 
   Popup.focus() 
} 


//Abre presupuesto cofiguracion "a"

function abrePresupuestoa(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20,a21,a22,a23,dtoa,configa){ 
   var winl = (screen.width - 650) / 2;
   var wint = (screen.height - 450) / 2; 
   winprops = 'height=450,width=650,top='+wint+',left='+winl+',scrollbars=yes,resizable=no'
   miPopup = window.open("presupuesto/?a1="+a1+"&a2="+a2+"&a3="+a3+"&a4="+a4+"&a5="+a5+"&a6="+a6+"&a7="+a7+"&a8="+a8+"&a9="+a9+"&a10="+a10+"&a11="+a11+"&a12="+a12+"&a13="+a13+"&a14="+a14+"&a15="+a15+"&a16="+a16+"&a17="+a17+"&a18="+a18+"&a19="+a19+"&a20="+a20+"&a21="+a21+"&a22="+a22+"&a23="+a23+"&dtoa="+dtoa+"&configa="+configa,"miwin",winprops) 
   miPopup.focus() 
} 


//Abre presupuesto cofiguracion "b"

function abrePresupuestob(b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18,b19,b20,b21,b22,b23,dtob,configb){ 
   var winl = (screen.width - 650) / 2;
   var wint = (screen.height - 450) / 2; 
   winprops = 'height=450,width=650,top='+wint+',left='+winl+',scrollbars=yes,resizable=no'
   miPopup = window.open("presupuesto/?b1="+b1+"&b2="+b2+"&b3="+b3+"&b4="+b4+"&b5="+b5+"&b6="+b6+"&b7="+b7+"&b8="+b8+"&b9="+b9+"&b10="+b10+"&b11="+b11+"&b12="+b12+"&b13="+b13+"&b14="+b14+"&b15="+b15+"&b16="+b16+"&b17="+b17+"&b18="+b18+"&b19="+b19+"&b20="+b20+"&b21="+b21+"&b22="+b22+"&b23="+b23+"&dtob="+dtob+"&configb="+configb,"miwin",winprops) 
   miPopup.focus() 
} 


//Abre presupuesto cofiguracion "c"

function abrePresupuestoc(c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16,c17,c18,c19,c20,c21,c22,c23,dtoc,configc){ 
   var winl = (screen.width - 650) / 2;
   var wint = (screen.height - 450) / 2; 
   winprops = 'height=450,width=650,top='+wint+',left='+winl+',scrollbars=yes,resizable=no'
   miPopup = window.open("presupuesto/?c1="+c1+"&c2="+c2+"&c3="+c3+"&c4="+c4+"&c5="+c5+"&c6="+c6+"&c7="+c7+"&c8="+c8+"&c9="+c9+"&c10="+c10+"&c11="+c11+"&c12="+c12+"&c13="+c13+"&c14="+c14+"&c15="+c15+"&c16="+c16+"&c17="+c17+"&c18="+c18+"&c19="+c19+"&c20="+c20+"&c21="+c21+"&c22="+c22+"&c23="+c23+"&dtoc="+dtoc+"&configc="+configc,"miwin",winprops) 
   miPopup.focus() 
} 


//Abre presupuesto cofiguracion "d"

function abrePresupuestod(d1,d2,d3,d4,d5,d6,d7,d8,d9,d10,d11,d12,d13,d14,d15,d16,d17,d18,d19,d20,d21,d22,d23,dtod,configd){ 
   var winl = (screen.width - 650) / 2;
   var wint = (screen.height - 450) / 2; 
   winprops = 'height=450,width=650,top='+wint+',left='+winl+',scrollbars=yes,resizable=no'
   miPopup = window.open("presupuesto/?d1="+d1+"&d2="+d2+"&d3="+d3+"&d4="+d4+"&d5="+d5+"&d6="+d6+"&d7="+d7+"&d8="+d8+"&d9="+d9+"&d10="+d10+"&d11="+d11+"&d12="+d12+"&d13="+d13+"&d14="+d14+"&d15="+d15+"&d16="+d16+"&d17="+d17+"&d18="+d18+"&d19="+d19+"&d20="+d20+"&d21="+d21+"&d22="+d22+"&d23="+d23+"&dtod="+dtod+"&configd="+configd,"miwin",winprops) 
   miPopup.focus() 
} 


//Abre modificacion de presupuesto de la cofiguracion "a"

function modiPresupuestoa(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20,a21,a22,a23,dtoa,configa,ide,codigo){ 
   var winl = (screen.width - 650) / 2;
   var wint = (screen.height - 450) / 2; 
   winprops = 'height=450,width=650,top='+wint+',left='+winl+',scrollbars=yes,resizable=no'
   miPopup = window.open("../presupuesto/editar/?a1="+a1+"&a2="+a2+"&a3="+a3+"&a4="+a4+"&a5="+a5+"&a6="+a6+"&a7="+a7+"&a8="+a8+"&a9="+a9+"&a10="+a10+"&a11="+a11+"&a12="+a12+"&a13="+a13+"&a14="+a14+"&a15="+a15+"&a16="+a16+"&a17="+a17+"&a18="+a18+"&a19="+a19+"&a20="+a20+"&a21="+a21+"&a22="+a22+"&a23="+a23+"&dtoa="+dtoa+"&configa="+configa+"&ide="+ide+"&codigo="+codigo,"miwin",winprops) 
   miPopup.focus() 
} 


//Abre modificacion de presupuesto de la cofiguracion "b"

function modiPresupuestob(b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18,b19,b20,b21,b22,b23,dtob,configb,ide,codigo){ 
   var winl = (screen.width - 650) / 2;
   var wint = (screen.height - 450) / 2; 
   winprops = 'height=450,width=650,top='+wint+',left='+winl+',scrollbars=yes,resizable=no'
   miPopup = window.open("../presupuesto/editar/?b1="+b1+"&b2="+b2+"&b3="+b3+"&b4="+b4+"&b5="+b5+"&b6="+b6+"&b7="+b7+"&b8="+b8+"&b9="+b9+"&b10="+b10+"&b11="+b11+"&b12="+b12+"&b13="+b13+"&b14="+b14+"&b15="+b15+"&b16="+b16+"&b17="+b17+"&b18="+b18+"&b19="+b19+"&b20="+b20+"&b21="+b21+"&b22="+b22+"&b23="+b23+"&dtob="+dtob+"&configb="+configb+"&ide="+ide+"&codigo="+codigo,"miwin",winprops) 
   miPopup.focus() 
} 


//Abre modificacion de presupuesto de la cofiguracion "c"

function modiPresupuestoc(c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16,c17,c18,c19,c20,c21,c22,c23,dtoc,configc,ide,codigo){ 
   var winl = (screen.width - 650) / 2;
   var wint = (screen.height - 450) / 2; 
   winprops = 'height=450,width=650,top='+wint+',left='+winl+',scrollbars=yes,resizable=no'
   miPopup = window.open("../presupuesto/editar/?c1="+c1+"&c2="+c2+"&c3="+c3+"&c4="+c4+"&c5="+c5+"&c6="+c6+"&c7="+c7+"&c8="+c8+"&c9="+c9+"&c10="+c10+"&c11="+c11+"&c12="+c12+"&c13="+c13+"&c14="+c14+"&c15="+c15+"&c16="+c16+"&c17="+c17+"&c18="+c18+"&c19="+c19+"&c20="+c20+"&c21="+c21+"&c22="+c22+"&c23="+c23+"&dtoc="+dtoc+"&configc="+configc+"&ide="+ide+"&codigo="+codigo,"miwin",winprops) 
   miPopup.focus() 
} 


//Abre modificacion de presupuesto de la cofiguracion "d"

function modiPresupuestod(d1,d2,d3,d4,d5,d6,d7,d8,d9,d10,d11,d12,d13,d14,d15,d16,d17,d18,d19,d20,d21,d22,d23,dtod,configd,ide,codigo){ 
   var winl = (screen.width - 650) / 2;
   var wint = (screen.height - 450) / 2; 
   winprops = 'height=450,width=650,top='+wint+',left='+winl+',scrollbars=yes,resizable=no'
   miPopup = window.open("../presupuesto/editar/?d1="+d1+"&d2="+d2+"&d3="+d3+"&d4="+d4+"&d5="+d5+"&d6="+d6+"&d7="+d7+"&d8="+d8+"&d9="+d9+"&d10="+d10+"&d11="+d11+"&d12="+d12+"&d13="+d13+"&d14="+d14+"&d15="+d15+"&d16="+d16+"&d17="+d17+"&d18="+d18+"&d19="+d19+"&d20="+d20+"&d21="+d21+"&d22="+d22+"&d23="+d23+"&dtod="+dtod+"&configd="+configd+"&ide="+ide+"&codigo="+codigo,"miwin",winprops) 
   miPopup.focus() 
} 


//Habilita campos si no es comprador / destinatario

function habilita(form)
{ 
	form.nombred.value = ""
	form.nombred.disabled = false;
	form.apellidosd.value = ""
	form.apellidosd.disabled = false;
	form.empresad.value = ""
	form.empresad.disabled = false;
	form.direcciond.value = ""
	form.direcciond.disabled = false;
	form.poblaciond.value = ""
	form.poblaciond.disabled = false;
	form.cpd.value = ""
	form.cpd.disabled = false;
	form.provinciad.value = ""
	form.provinciad.disabled = false;
	form.paisd.value = ""
	form.paisd.disabled = false;
	form.ap_correod.value = ""
	form.ap_correod.disabled = false;
}


//Deshabilita campos si no es comprador / destinatario

function deshabilita(form)
{ 
	form.nombred.value = form.nombre.value
	form.nombred.disabled = true;
	form.apellidosd.value = form.apellidos.value
	form.apellidosd.disabled = true;
	form.empresad.value = form.empresa.value
	form.empresad.disabled = true;
	form.direcciond.value = form.direccion.value
	form.direcciond.disabled = true;
	form.poblaciond.value = form.poblacion.value
	form.poblaciond.disabled = true;
	form.cpd.value = form.cp.value
	form.cpd.disabled = true;
	form.provinciad.value = form.provincia.value
	form.provinciad.disabled = true;
	form.paisd.value = form.pais.value
	form.paisd.disabled = true;
	form.ap_correod.value = form.ap_correo.value
	form.ap_correod.disabled = true;
}
