
	var xmlhttp,alerted
		/*@cc_on @*/
		/*@if (@_jscript_version >= 5)
			// JScript gives us Conditional compilation, we can cope with old IE versions.
			try {
				xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
			} catch (e) {
				try {
					xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
				} catch (E) {
					alert("You must have Microsofts XML parsers available")
				}
			}
		@else
			//alert("You must have JScript version 5 or above.")
			xmlhttp=false
			alerted=false
		@end @*/	
	if (!xmlhttp && !alerted) {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false
			alerted=false
			alert("You need a browser which supports an XMLHttpRequest Object.\nMozilla build 0.9.5 has this Object and IE5 and above, others may do, I don't know, any info david@iquadrat.com")
		}
	}
	
	

	
	function loginear() { 	
		var d = new Date();
		txtlogin = document.getElementById('email_login').value;
		txtpassword = document.getElementById('password_login').value;

		if(txtlogin!='' || txtpassword!=''){
			xmlhttp.open("GET", "core_login.php?tipo=loguinear&user="+txtlogin+"&password="+txtpassword+"&lah="+d.getTime() );
			xmlhttp.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");
			xmlhttp.onreadystatechange=actualizacontenido
			xmlhttp.send(null)
		}else{
			document.getElementById('respuesta_login').innerHTML="E-mail y Password son obligatorios.";
		}
	}
	
	function actualizacontenido() {
		if (xmlhttp.readyState==4) {
			if (xmlhttp.responseText.length>0) {

				respuesta = xmlhttp.responseText;
				//alert(respuesta)
				
				//alert('AC')
				switch (respuesta) {
					case "OK": 
					document.location='zonaclientes.php';
					break;
					case "KO":
					document.getElementById('respuesta_login').innerHTML=" Login y/o password incorrectos";
					break;
					case "DES":
					document.location = 'zonaclientes.php';
					break;
					case "OKEMAIL":
					document.getElementById('respuesta_login_recordar').innerHTML="Su contraseña ha sido enviada.";
					break;
					case "KOEMAIL":
					document.getElementById('respuesta_login_recordar').innerHTML="Su email no es válido.";	
					break;
				}
			}
		}	
	} 
	
	function recordar(txtemail) {	
		txtemail = document.getElementById('email_recordar').value;
		
		if(txtemail!=""){
			document.getElementById('respuesta_login_recordar').innerHTML="enviando..."
	
			xmlhttp.open("GET", "core_login.php?tipo=recordar&email="+txtemail);
			xmlhttp.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");
			xmlhttp.onreadystatechange=actualizacontenido
			xmlhttp.send(null)
		}else{
			document.getElementById('respuesta_login_recordar').innerHTML="E-mail es obligatorio."
		}
	}


	function desloginear() {
		var d = new Date();

		xmlhttp.open("GET", "core_login.php?tipo=desloguinear&lah="+d.getTime());
		xmlhttp.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");
		xmlhttp.onreadystatechange=actualizacontenido
		xmlhttp.send(null)
	}
	
	
	function registrar_usuario(email,password,password_rep,pais,empresa,nombre,apellidos,dni,direccion,codigopostal,poblacion,telefono,fax) {
		var today=new Date();
		
		//if(password==password_rep){	
			
		//}
			xmlhttp.open("GET", "core_catalogo.php?tipo=registrar_usuario&email="+email+"&password="+password+"&password_rep="+password_rep+"&pais="+pais+"&empresa="+empresa+"&nombre="+nombre+"&apellidos="+apellidos+"&dni="+dni+"&direccion="+direccion+"&codigopostal="+codigopostal+"&poblacion="+poblacion+"&telefono="+telefono+"&fax="+fax+"&pp="+today);
			xmlhttp.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");
			xmlhttp.onreadystatechange=rcv_registrar_usuario
			xmlhttp.send(null)
		//}
	}
	
	function rcv_registrar_usuario() {
		if (xmlhttp.readyState==4) {
			if (xmlhttp.responseText.length>0) {
				respuesta = xmlhttp.responseText;
				//Escribimos en el estado 
				//alert(respuesta)
				num = String(respuesta).substring(0,1);
				texto = String(respuesta).substring(String(respuesta).length, 1);

				if(num=="1"){
					document.getElementById('form_reg').innerHTML = texto;
					document.getElementById('form_recordar').innerHTML = "";
					document.getElementById('form_login').innerHTML = "";
				}else{
					document.getElementById('msg_zona').innerHTML = texto;
				}
				
			} else { 
				//document.getElementById('titulo_familia').innerHTML = "<i>No hay articulos</i>";
			}
		}
	}
	
	function contactar(email,mensaje) {
		var today=new Date();
		
		document.getElementById('enviar_bt').innerHTML = 'Enviando Mensaje...';
		
		xmlhttp.open("GET", "core_catalogo.php?tipo=contactar&email="+email+"&mensaje="+mensaje+"&pp="+today);
		xmlhttp.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");
		xmlhttp.onreadystatechange=rcv_contactar
		xmlhttp.send(null)

	}
	
	function rcv_contactar() {
		if (xmlhttp.readyState==4) {
			if (xmlhttp.responseText.length>0) {
				respuesta = xmlhttp.responseText;
				//Escribimos en el estado 
				//alert(respuesta)
				document.getElementById('introduzca_contacto').innerHTML = 'Su mensaje ha sido enviado, en breve nos pondremos en contacto con usted.';
				document.getElementById('enviar_bt').innerHTML = 'Mensaje Enviado';
				document.getElementById('form_reg').innerHTML = '<br><br><br><br><br><br><br><br><br><br><br>';
			} else { 
				//document.getElementById('titulo_familia').innerHTML = "<i>No hay articulos</i>";
			}
		}
	}
	
	function devolucion(url) {
		var today=new Date();
		
		document.getElementById('enviar_bt').innerHTML = 'Enviando Mensaje...';
		
		xmlhttp.open("GET", url+"&pp="+today);
		xmlhttp.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");
		xmlhttp.onreadystatechange=rcv_devolucion
		xmlhttp.send(null)

	}
	
	function rcv_devolucion() {
		if (xmlhttp.readyState==4) {
			if (xmlhttp.responseText.length>0) {
				respuesta = xmlhttp.responseText;
				//Escribimos en el estado 
				//alert(respuesta)
				document.getElementById('introduzca_contacto').innerHTML = 'Su mensaje ha sido enviado, en breve nos pondremos en contacto con usted.';
				document.getElementById('enviar_bt').innerHTML = 'Mensaje Enviado';
				document.getElementById('form_reg').innerHTML = '<br><br><br><br><br><br><br><br><br><br><br>';
			} else { 
				//document.getElementById('titulo_familia').innerHTML = "<i>No hay articulos</i>";
			}
		}
	}
	
	function recibirBoletin(valor) {
		var today=new Date();
				
		xmlhttp.open("GET", "core_catalogo.php?tipo=recibir_boletin&valor="+valor+"&pp="+today);
		xmlhttp.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");
		xmlhttp.onreadystatechange=rcv_recibirBoletin
		xmlhttp.send(null)

	}
	
	function rcv_recibirBoletin() {
		if (xmlhttp.readyState==4) {
			if (xmlhttp.responseText.length>0) {
				respuesta = xmlhttp.responseText;
				
				alert(respuesta);
			} else { 
				//document.getElementById('titulo_familia').innerHTML = "<i>No hay articulos</i>";
			}
		}
	}
	
	// PEDIDO ONLINE *************************************************************************************************
	
	var g_fam = 0;
	var g_subfam = 0;
	var g_subsubfam = 0;
	
	var g_busqueda = "";
	var g_outlet = "";
	
	var g_countbusqueda = 0;
	
	campos_ordenes = Array(Array("id_articulo","ASC"),Array("id_categoria","ASC"),Array("articulo","DESC"),Array("modelo","ASC"),Array("clase","ASC"),Array("descripcion","ASC"),Array("pvp","ASC"),Array("pvpoutlet","ASC"));
	
	function actualizarFamilias(fam,subfam,subsubfam) {

		if(fam==undefined){fam=""};
		if(subfam==undefined){subfam=""};
		if(subsubfam==undefined){subsubfam=""};
			
		g_fam = fam;
		g_subfam = subfam;
		g_subsubfam = subsubfam;
				
		//if(g_subsubfam==""){g_subsubfam = g_subfam;}
				
		g_busqueda = "";
		
		var today=new Date();
		xmlhttp.open("GET", "core_catalogo.php?tipo=actualizar_familias&fam="+fam+"&subfam="+subfam+"&subsubfam="+subsubfam+"&pp="+today);
		xmlhttp.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");
		xmlhttp.onreadystatechange=rcv_actualizarFamilias
		xmlhttp.send(null)
	}

	function rcv_actualizarFamilias() { 
		if (xmlhttp.readyState==4) {
			//alert('AF')
			if (xmlhttp.responseText.length>0) {
				respuesta = xmlhttp.responseText;
//				alert(respuesta)
				if(document.getElementById('menuFamilias')!=null){
					document.getElementById('menuFamilias').innerHTML = respuesta;
				}
					
				//if(g_subsubfam!=""){
					actualizarArticulos(g_fam,g_subfam,g_subsubfam,null,null,null,g_outlet);
				//}else{
				//	actualizarArticulos(g_subfam);
				//}

				//initBusqueda();
				
				
				//actualizarTituloFamilia(g_fam,g_subfam,g_subsubfam);
			}
		}	
	}
	
	function devolverContadorRegistros() {
	
		var today=new Date();
		xmlhttp.open("GET", "core_catalogo.php?tipo=contar_registros&busqueda="+ urlencode(g_busqueda) +"&pp="+today);
		xmlhttp.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");
		xmlhttp.onreadystatechange=rcv_devolverContadorRegistros
		xmlhttp.send(null)
	}

	function rcv_devolverContadorRegistros() { 
		if (xmlhttp.readyState==4) {
			if (xmlhttp.responseText.length>0) {
				respuesta = xmlhttp.responseText;
				document.getElementById('titulo_familia').innerHTML = respuesta;
			}
		}	
	}
	
	function plegarMenuFamilias() {
		//alert('plegarMenuFamilias')
		
		var today=new Date();
		xmlhttp.open("GET", "core_catalogo.php?tipo=actualizar_familias&fam=&subfam=&subsubfam=&pp="+today);
		xmlhttp.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");
		xmlhttp.onreadystatechange=rcv_plegarMenuFamilias
		xmlhttp.send(null)
	}
	
	function rcv_plegarMenuFamilias() { 
		if (xmlhttp.readyState==4) {
			if (xmlhttp.responseText.length>0) {
				respuesta = xmlhttp.responseText;
				
				if(document.getElementById('menuFamilias')!=null){
					document.getElementById('menuFamilias').innerHTML = respuesta;
				}
				
				actualizarArticulos(g_fam,g_subfam,g_subsubfam,'','',g_busqueda,g_outlet);
			}
		}	
	}
	
	function buscarArticulos(busqueda){
		if((busqueda!=0) && (busqueda!="") && (document.getElementById('estadobusqueda').innerHTML == '')){
			document.getElementById('estadobusqueda').innerHTML = 'Buscando...';
			document.getElementById('lista_articulos').innerHTML = '';
			//busqueda = document.getElementById('campobusqueda').value;
			//if(g_subsubfam==''){
			//	actualizarArticulos(g_subfam,'','',busqueda);
			//}else{
				plegarMenuFamilias();
				//actualizarArticulos(g_subsubfam,'','',busqueda);
			//}
			
			g_busqueda = busqueda;
		}
	}
	
function urlencode (str) {
    var hexStr = function (dec) {
        return '%' + (dec < 16 ? '0' : '') + dec.toString(16).toUpperCase();
    };

    var ret = '',
            unreserved = /[\w.-]/; // A-Za-z0-9_.- // Tilde is not here for historical reasons; to preserve it, use rawurlencode instead
    str = (str+'').toString();

    for (var i = 0, dl = str.length; i < dl; i++) {
        var ch = str.charAt(i);
        if (unreserved.test(ch)) {
            ret += ch;
        }
        else {
            var code = str.charCodeAt(i);
            if (0xD800 <= code && code <= 0xDBFF) { // High surrogate (could change last hex to 0xDB7F to treat high private surrogates as single characters); https://developer.mozilla.org/index.php?title=en/Core_JavaScript_1.5_Reference/Global_Objects/String/charCodeAt
                ret += ((code - 0xD800) * 0x400) + (str.charCodeAt(i+1) - 0xDC00) + 0x10000;
                i++; // skip the next one as we just retrieved it as a low surrogate
            }
            // We never come across a low surrogate because we skip them, unless invalid
            // Reserved assumed to be in UTF-8, as in PHP
            else if (code === 32) {
                ret += '+'; // %20 in rawurlencode
            }
            else if (code < 128) { // 1 byte
                ret += hexStr(code);
            }
            else if (code >= 128 && code < 2048) { // 2 bytes
                ret += hexStr((code >> 6) | 0xC0);
                ret += hexStr((code & 0x3F) | 0x80);
            }
            else if (code >= 2048) { // 3 bytes (code < 65536)
                ret += hexStr((code >> 12) | 0xE0);
                ret += hexStr(((code >> 6) & 0x3F) | 0x80);
                ret += hexStr((code & 0x3F) | 0x80);
            }
        }
    }
    return ret;
}


	function actualizarArticulos(fam,subfam,subsubfam,orden,sentido,busqueda,outlet) {
		var today=new Date();
						
		old_articulo = "";
		CerrarFicha('');
								
		if(fam==undefined){fam=""};
		if(subfam==undefined){subfam=""};
		if(subsubfam==undefined){subsubfam=""};
		if(orden==undefined){orden=""};
		if(sentido==undefined){sentido=""};
		if(busqueda==undefined){busqueda=""};
		if(outlet==undefined){outlet="false"};
		
		busqueda = busqueda.toUpperCase();
		
		xmlhttp.open("GET", "core_catalogo.php?tipo=actualizar_articulos&fam="+fam+"&subfam="+subfam+"&subsubfam="+subsubfam+"&orden="+orden+"&sentido="+sentido+"&busqueda="+urlencode(busqueda)+"&outlet="+outlet+"&pp="+today);
		xmlhttp.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");
		xmlhttp.onreadystatechange=rcv_actualizarArticulos;
		xmlhttp.send(null);
	}
	
	function rcv_actualizarArticulos() {
		//alert(xmlhttp.readyState);
		if (xmlhttp.readyState==4) {
			//alert('AA')
			document.getElementById('estadobusqueda').innerHTML = '';

			//alert(xmlhttp.responseText)
	
			if (xmlhttp.responseText.length>0) {
				respuesta = xmlhttp.responseText;
				
				if(g_busqueda!="" || g_outlet){
					document.getElementById('col_cat').style.display = 'block';
					document.getElementById('col_desc').style.width = '222px';
					
				}else{
					document.getElementById('col_cat').style.display = 'none';
					document.getElementById('col_desc').style.width = '398px';
				}
				
				
				document.getElementById('lista_articulos').innerHTML = respuesta;
				
				/*
				if(g_busqueda==''){
					actualizarTituloFamilia(g_fam,g_subfam,g_subsubfam);			
				}else{
					document.getElementById('titulo_familia').innerHTML = 'Busqueda';
				}
				*/
			} else { 
			
				document.getElementById('lista_articulos').innerHTML = "<i>No hay articulos</i>";
				/*
				if(g_busqueda==''){
					actualizarTituloFamilia(g_fam,g_subfam,g_subsubfam);		
				}else{
					document.getElementById('titulo_familia').innerHTML = 'Busqueda';
				}
				*/
			}
			
			if(g_busqueda==''){
				if(g_outlet==false) actualizarTituloFamilia(g_fam,g_subfam,g_subsubfam);
			}else{
				//document.getElementById('titulo_familia').innerHTML = 'Busqueda de "'+ g_busqueda +"' obtuvo ("+ 5 +") resultados.";
				devolverContadorRegistros();
			}
			
		}	
		else
		{
		//alert("No entramos");
		}
	}
	
	function eliminarProducto(idarticulo){
		comprarProducto(idarticulo,0);
	}
	
	function actualizarPedido() {	
		var today=new Date();

		//CerrarFicha('');

		xmlhttp.open("GET", "core_catalogo.php?tipo=actualizar_pedido&pp="+today);
		xmlhttp.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");
		xmlhttp.onreadystatechange=rcv_actualizarPedido
		xmlhttp.send(null)
	}
	
	function rcv_actualizarPedido() {
		//alert(xmlhttp.readyState);
		if (xmlhttp.readyState==4) {
			document.getElementById('estadobusqueda').innerHTML = '';
			if (xmlhttp.responseText.length>0) {
				respuesta = xmlhttp.responseText;
				document.getElementById('lista_articulos').innerHTML = respuesta;


				if(g_articulo!=0){
					//marcarArticuloLista(g_articulo);
				}
				actualizarEstado();
								
				//mostrarFichaPedido();
			} else { 
			
				document.getElementById('lista_articulos').innerHTML = "<i>No hay articulos</i>";
				actualizarEstado();
			}
						
		}	
		else
		{
		//alert("No entramos");
		}
	}
	
	function actualizarEstado() {	
		var today=new Date();

		//CerrarFicha('');
		
		xmlhttp.open("GET", "core_catalogo.php?tipo=actualizar_estado&pp="+today);
		xmlhttp.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");
		xmlhttp.onreadystatechange=rcv_actualizarEstado
		xmlhttp.send(null)
	}
	
	function rcv_actualizarEstado() {
		//alert(xmlhttp.readyState);
		if (xmlhttp.readyState==4) {
			if (xmlhttp.responseText.length>0) {
				respuesta = xmlhttp.responseText;

				document.getElementById('pos_verpedido').innerHTML = respuesta;
			}
		}
	}
	
	function efectuarPedido(observaciones) {
		//g_idusuario = idusuario;
		
		//actualizarEstado();
		//alert(observaciones)
		observaciones = observaciones.replace(/\n/g, "<br />");
		//alert(observaciones)
		//alert(observaciones)
		
		mostrarMensaje("Efectuando pedido... &nbsp;<span style='color:#545454;'>Espere confirmación</span>",3000)
		
		var today=new Date();
		xmlhttp.open("GET", "core_catalogo.php?tipo=efectuar_pedido&observaciones="+observaciones+"&pp="+today);
		xmlhttp.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");
		xmlhttp.onreadystatechange=rcv_efectuarPedido
		xmlhttp.send(null)
		
	}

	function rcv_efectuarPedido() {
		if (xmlhttp.readyState==4) {
			if (xmlhttp.responseText.length>0) {
				respuesta = xmlhttp.responseText;
				
				if(respuesta=="OK"){
					mostrarMensaje("Pedido realizado con éxito",2000)
					setTimeout("location.reload(true)",1500);

				}else{alert(respuesta)}
			}
		}else{
			mostrarMensaje("Efectuando pedido... &nbsp;<span style='color:#545454;'>Espere confirmación</span>",2000)
			//mostrarProgreso("Efectuando pedido... &nbsp;<span style='color:#545454;'>Espere confirmación</span>")
		}
	}
	
	function actualizarTituloFamilia(fam,subfam,subsubfam) {
		var today=new Date();
		
		if(fam==undefined){fam=""};
		if(subfam==undefined){subfam=""};
		if(subsubfam==undefined){subsubfam=""};
		
		//if(subfam==subsubfam){subsubfam=""}
		
		xmlhttp.open("GET", "core_catalogo.php?tipo=actualizar_titulofamilia&fam="+fam+"&subfam="+subfam+"&subsubfam="+subsubfam+"&pp="+today);
		xmlhttp.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");
		xmlhttp.onreadystatechange=rcv_actualizarTituloFamilia
		xmlhttp.send(null)
	}
	
	function rcv_actualizarTituloFamilia() {
		//alert(xmlhttp.readyState);
		if (xmlhttp.readyState==4) {
			//alert('AT')
			if (xmlhttp.responseText.length>0) {
				respuesta = xmlhttp.responseText;
				//Escribimos en el estado 
				initArticulo();
				document.getElementById('titulo_familia').innerHTML = respuesta;
			} else { 
				//document.getElementById('titulo_familia').innerHTML = "<i>No hay articulos</i>";
			}
		}
	}
	
	function ordenarArticulos(indice) {

		//if(g_subsubfam!=0){
			campo = campos_ordenes[indice][0]
			sentido = campos_ordenes[indice][1]
			
			actualizarArticulos(g_fam, g_subfam, g_subsubfam, campo, sentido, g_busqueda, g_outlet);
			
			if(campos_ordenes[indice][1]=="ASC"){campos_ordenes[indice][1]="DESC"}else{campos_ordenes[indice][1]="ASC"};
		//}
	}
	
	var old_articulo = '';
	var g_articulo = 0;
	
	function mostrarFicha(articulo) {	
		var today=new Date();
					
		if(articulo==undefined){articulo=""};	

		g_articulo = articulo;
		
		xmlhttp.open("GET", "core_catalogo.php?tipo=mostrar_ficha&articulo="+articulo+"&outlet="+g_outlet+"&pp="+today);
		xmlhttp.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");
		xmlhttp.onreadystatechange=rcv_mostrarFicha
		xmlhttp.send(null)
	}
	
	function mostrarFichaPedido(articulo) {	
		var today=new Date();
					
		if(articulo==undefined){articulo=""};	
		
		g_articulo = articulo;
		
		xmlhttp.open("GET", "core_catalogo.php?tipo=mostrar_fichapedido&articulo="+articulo+"&pp="+today);
		xmlhttp.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");
		xmlhttp.onreadystatechange=rcv_mostrarFicha
		xmlhttp.send(null)
	}
	
	function rcv_mostrarFicha() {
		//alert(xmlhttp.readyState);
		if (xmlhttp.readyState==4) {
			//alert('MF')
			if (xmlhttp.responseText.length>0) {
				respuesta = xmlhttp.responseText;
				//Escribimos en el estado 
												
				scrOfY = getScrollTop() + getOffsetLayer();
				
				document.getElementById('ficha_catalogo').style.top = scrOfY + 'px';
				document.getElementById('ficha_catalogo').innerHTML = respuesta;	
				document.getElementById('ficha_catalogo').style.display = "block";	
				
				desmarcarArticuloLista(old_articulo)
				marcarArticuloLista(g_articulo);
				
				//document.getElementById('carrito_unidades').focus();
				
				old_articulo = g_articulo;
			}
			//alert("No entramos");
		}
	}

	function comprobarDatosPedido(idusuario,totalpvp,totalnum) {
		var direccion = document.getElementById('direccion');
		var provincia = document.getElementById('provincia');
		var poblacion = document.getElementById('poblacion');
		var cp = document.getElementById('cp');
		var atencionde = document.getElementById('atencionde');
		var telefono = document.getElementById('telefono');
		var email = document.getElementById('email');

		var confir = document.getElementById('confir');
		var acepto = document.getElementById('aceptoCondiciones');
		
		msg=''
		if(direccion.value==''){msg+='El campo "Dirección" es obligatorio\n'}
		if(provincia.value==''){msg+='El campo "Provincia" es obligatorio\n'}
		if(poblacion.value==''){msg+='El campo "Población" es obligatorio\n'}
		if(cp.value==''){msg+='El campo Código "Postal" es obligatorio\n'}
		if(atencionde.value==''){msg+='El campo "Atención de" es obligatorio\n'}
		if(telefono.value==''){msg+='El campo "Teléfono" es obligatorio\n'}
		if(email.value==''){msg+='El campo "Email" es obligatorio\n'}
		if(acepto.checked==false){msg+='Necesitas aceptar las Condiciones'}
		
		if(msg==''){
			if(confir.checked==false){mostrarGlobo()}
			else{
				efectuarPedido(idusuario,totalpvp,totalnum,'&direccion='+direccion.value+'&provincia='+provincia.value+'&poblacion='+poblacion.value+'&cp='+cp.value+'&atencionde='+atencionde.value+'&telefono='+telefono.value+'&email='+email.value)
			}
		}else{
			alert(msg)
		}

	}
	
	function comprarProducto(idarticulo,unidades) {
		g_articulo = idarticulo;
		g_unidades = unidades;
				
		//g_unidelete = document.getElementById('hid_cantidad_'+idarticulo).value;
		
		//if((unidades<1) && (g_unidelete<=1)){
		if(unidades<1){
			if(!confirm('Esta acción eliminara el producto de su pedido, está seguro que quiere continuar?',2)){
				pararcompra = true;
				
			}else{
				pararcompra = false;
				CerrarFicha("");
			}
		}else{
			pararcompra = false;	
		}
		
		if(pararcompra==false){
			var today=new Date();
			xmlhttp.open("GET", "core_catalogo.php?tipo=comprar_producto&idarticulo="+idarticulo+"&unidades="+unidades+"&pp="+today);
			xmlhttp.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");
			xmlhttp.onreadystatechange=rcv_comprarProducto
			xmlhttp.send(null)
		}
	}
	
	function rcv_comprarProducto() {
		if (xmlhttp.readyState==4) {
			if (xmlhttp.responseText.length>0) {
				respuesta = xmlhttp.responseText;

				actualizarPedido();
				
				CerrarFicha(g_articulo);
				
				mostrarMensaje("Articulo actualizado",1000);

				/*
				if(g_unidades<0){
					decrementarCarrito();
				}else{
					incrementarCarrito();
				}
				*/

			} 
		}	
	}
	
	
	var g_articulo = 0;
	var g_unidades = 0;
	
	function comprarProductoCarrito(idarticulo,unidades) {
		g_articulo = idarticulo;
		g_unidades = unidades;
		
		if(unidades>0){
			var today=new Date();
			xmlhttp.open("GET", "core_catalogo.php?tipo=comprar_producto&idarticulo="+idarticulo+"&unidades="+unidades+"&outlet="+g_outlet+"&pp="+today);
			xmlhttp.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");
			xmlhttp.onreadystatechange=rcv_comprarProductoCarrito
			xmlhttp.send(null)			
		}
	}
	
	function rcv_comprarProductoCarrito() {
		if (xmlhttp.readyState==4) {
			if (xmlhttp.responseText.length>0) {
				respuesta = xmlhttp.responseText;
				if(respuesta!="LOG"){
					actualizarEstado();

					CerrarFicha(g_articulo);
					
					mostrarMensaje("Articulo actualizado",1000);
				/*
					if(g_unidades<0){
						decrementarCarrito();
					}else{
						incrementarCarrito();
					}
				*/

				}else{
					if(confirm("Para añadir un articulo a la cesta, tiene que estar registrado.\n¿Desea registrarse?")){
						document.location = "zonaclientes.php"	
					}
				}
			}
		}	
	}
	
	function crearPDF() {
		//alert('plegarMenuFamilias')
		origen = '';
		destino = '';
		
		document.getElementById('estado_pdf').innerHTML = 'Generando PDF...';
		
		var today=new Date();
		xmlhttp.open("GET", "core_pdf.php?tipo=crear_pdf&origen="+ origen +"&destino="+ destino +"&pp="+today);
		xmlhttp.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");
		xmlhttp.onreadystatechange=rcv_crearPDF
		xmlhttp.send(null)
	}
	
	function rcv_crearPDF() { 
		if (xmlhttp.readyState==4) {
			if (xmlhttp.responseText.length>0) {
				respuesta = xmlhttp.responseText;
//				alert(respuesta)
				document.getElementById('estado_pdf').innerHTML = "PDF Generado";
				//window.open('pdf/Op3r4Op3rt4__!.pdf','_blank');
			}
		}	
	}

	

	//FIN PEDIDO ONLINE **********************************************************************************************

