function activar_panel(id){

	document.getElementById(id).className='imagen_colchon_dcha';
	document.getElementById("boton_"+id).className='boton_colchon_dcha';	
		
}

function desactivar_panel(id){
	
	document.getElementById(id).className='imagen_colchon';
	document.getElementById("boton_"+id).className='boton_colchon';	
	
}

function activar_banner(id){

	document.getElementById(id).className='botones_banners_dcha';
		
}

function desactivar_banner(id){
	
	document.getElementById(id).className='botones_banners';
	
}

function comprobarDestino(){

	valor = document.asistente.pareja[0].checked;
	if(valor==true)
		document.asistente.action = 'asistente_pareja.php';
	
}

var claseAnterior = "";
var idAnterior = "-1";
function marcarMedidas(alto, ancho, id){

	document.asistente_paso2.alto.value = alto;
	document.asistente_paso2.ancho.value = ancho;	

	if(idAnterior!="-1"){
		document.getElementById('cuadro_seleccionado').id = idAnterior;
	}
	idAnterior = id;

   //alert(document.getElementById(idAnterior).id);
	document.getElementById(idAnterior).id = 'cuadro_seleccionado';
	
	
	obtenerPrecio(alto,ancho);
	
}

function desMarcarMedidas(){
	if(idAnterior!='-1'){ 
//		document.getElementById('bloque_precio').className="noMostrar";	
		document.getElementById('cuadro_seleccionado').id = idAnterior;	
		idAnterior = "-1";
	}
	
}



function cambiarTextosFundas(id){


		http_request = false;

		url = "obtener_datos.php?id="+id;
		if (window.XMLHttpRequest) { // Mozilla, Safari,...
				http_request = new XMLHttpRequest();
				if (http_request.overrideMimeType) {
						http_request.overrideMimeType('text/xml');
						// Ver nota sobre esta linea al final
				}
		} else if (window.ActiveXObject) { // IE
				try {
						http_request = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e) {
						try {
								http_request = new ActiveXObject("Microsoft.XMLHTTP");
						} catch (e) {}
				}
		}

		if (!http_request) {
				alert('Falla :( No es posible crear una instancia XMLHTTP');
				return false;
		}

		http_request.onreadystatechange = alertContents;
		http_request.open('GET', url, true);
		http_request.send(null);
}


			function alertContents() {
	
					if (http_request.readyState == 4) {
							if (http_request.status == 200) {
								
								var xmldoc = http_request.responseXML;
								var tit_nucleos = xmldoc.getElementsByTagName('titulo').item(0);
								tit_nucleos = tit_nucleos.firstChild.data;
								document.getElementById('tit_nucleos').innerHTML = tit_nucleos;
								
								var tit_nucleos = xmldoc.getElementsByTagName('titulo_fundas').item(0);
								tit_nucleos = tit_nucleos.firstChild.data;
								document.getElementById('tit_fundas').innerHTML = tit_nucleos;		
								tit_funda = tit_nucleos;
								
								var tit_nucleos = xmldoc.getElementsByTagName('texto').item(0);
								tit_nucleos = tit_nucleos.firstChild.data;
								document.getElementById('texto_nucleos').innerHTML = tit_nucleos;	
								
								NLBfadeBg('texto_nucleos','#b6b7b1','#ffffff','2000');																		
								
								
								tit_funda2 = tit_funda;
								if(tit_funda=="Neo") tit_funda = "Zen";
								if(tit_funda=="Airmax") tit_funda = "Zen";

								nombreCampo = 'funda_'+tit_funda;
								
								tit_funda = tit_funda2;


								var tit_nucleos = xmldoc.getElementsByTagName('texto_fundas').item(0);
								tit_nucleos = tit_nucleos.firstChild.data;
								document.getElementById(nombreCampo).innerHTML = tit_nucleos;	

								var tit_nucleos = xmldoc.getElementsByTagName('actual').item(0);
								tit_nucleos = tit_nucleos.firstChild.data;
								actual = tit_nucleos;		
								
								/*NLBfadeBg('textos_fundas','#b6b7b1','#ffffff','2000');	*/
								/*var tit_nucleos = xmldoc.getElementsByTagName('fundas').item(0);
								tit_nucleos = tit_nucleos.firstChild.data;
								document.getElementById('fundas').innerHTML = tit_nucleos;										*/

								var tit_nucleos = xmldoc.getElementsByTagName('num_fundas').item(0);
								num_fundas = tit_nucleos.firstChild.data;
								
								var enlace = xmldoc.getElementsByTagName('enlace').item(0);
								enlace = enlace.firstChild.data;
								document.getElementById('enlace_funda').href = "img/"+enlace+".jpg";		
								
								var enlace_nucleo = xmldoc.getElementsByTagName('enlace_nucleo').item(0);
								enlace_nucleo = enlace_nucleo.firstChild.data;
								document.getElementById('enlace_nucleo').href = enlace_nucleo;										



//document.getElementById('fundas').innerHTML = "\n";
								for(var i=0;i<num_fundas;i++){								
									document.getElementById('img_'+i).src = "img/nucleos/fundas/"+xmldoc.getElementsByTagName('funda')[i].getAttribute('valor');

									if(tit_funda=="Neo"){
									  if(i==2) document.getElementById('f_'+i).setAttribute("valor","6");
									}
									else if(tit_funda=="Airmax"){
										if(i==0) document.getElementById('f_'+i).setAttribute("valor","3");
										else if(i==1) document.getElementById('f_'+i).setAttribute("valor","4");
										else if(i==2) document.getElementById('f_'+i).setAttribute("valor","5");										
									}else{
										document.getElementById('f_'+i).setAttribute("valor",i);
									}
									



									//document.getElementById('fundas').innerHTML = document.getElementById('fundas').innerHTML+"<div style='float: left; position: relative;' class='panel' id='f_"+i+"'><img src='img/nucleos/fundas/"+xmldoc.getElementsByTagName('funda')[i].getAttribute('valor')+"' /></div>\n";
								}
								

								document.getElementById('fundas').style.width = (308*parseInt(num_fundas))+"px";								
								actualizarSlide();

								
							
							} else {
									alert('Hubo problemas con la petición.');
									
							}
					}
	
			}
			
			


function cambiarTextosFundas2(id){

	
		http_request = false;
	/*	aux = id.split('_');
		id  = aux[1];*/

		url = "obtener_datos_fundas.php?id="+id;
		if (window.XMLHttpRequest) { // Mozilla, Safari,...
				http_request = new XMLHttpRequest();
				if (http_request.overrideMimeType) {
						http_request.overrideMimeType('text/xml');
						// Ver nota sobre esta linea al final
				}
		} else if (window.ActiveXObject) { // IE
				try {
						http_request = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e) {
						try {
								http_request = new ActiveXObject("Microsoft.XMLHTTP");
						} catch (e) {}
				}
		}

		if (!http_request) {
				alert('Falla :( No es posible crear una instancia XMLHTTP');
				return false;
		}

		http_request.onreadystatechange = alertContents2;
		http_request.open('GET', url, true);
		http_request.send(null);
}


			function alertContents2() {
	
					if (http_request.readyState == 4) {
							if (http_request.status == 200) {
								
								var xmldoc = http_request.responseXML;

								var tit_nucleos = xmldoc.getElementsByTagName('titulo_fundas').item(0);
								tit_nucleos = tit_nucleos.firstChild.data;
								document.getElementById('tit_fundas').innerHTML = tit_nucleos;		
								nombre_funda = tit_nucleos;

								var enlace = xmldoc.getElementsByTagName('enlace').item(0);
								enlace = enlace.firstChild.data;
								document.getElementById('enlace_funda').href = "img/"+enlace+".jpg";		

							
								var tit_nucleos = xmldoc.getElementsByTagName('texto_fundas').item(0);
								tit_nucleos = tit_nucleos.firstChild.data;
								
								if(nombre_funda=='Airmax') nombre_funda = "Modern";
								else if(nombre_funda=='Exclusive') nombre_funda = "Elegance";
								else if(nombre_funda=='Class') nombre_funda = "Zen";								
								else if(nombre_funda=='Neo') nombre_funda = "Modern";				
								
								


								document.getElementById('funda_'+nombre_funda).innerHTML = tit_nucleos;		
								
								NLBfadeBg('textos_fundas','#b6b7b1','#e6e7e1','2000');									

							
							} else {
									alert('Hubo problemas con la petición.');
							}
					}
	
			}
			
			


	function abrirPdf(archivo){
		document.location = "descarga.php?nom="+archivo+"&archivo=img/tipos/"+archivo;
//		window.open("descarga.php?nom="+archivo+"&archivo=img/tipos/"+archivo,"Detalle","width=750,height=200,scrollbars=yes, top=0, left=0");
	}
	
function obtenerPrecio(alto,ancho){

	
		http_request = false;
		
		nucleo = document.asistente_paso2.nucleo.value;
		funda  = document.asistente_paso2.funda.value;		
		
		url = "obtener_precios.php?alto="+alto+"&ancho="+ancho+"&nucleo="+nucleo+"&funda="+funda;
		
		if (window.XMLHttpRequest) { // Mozilla, Safari,...
				http_request = new XMLHttpRequest();
				if (http_request.overrideMimeType) {
						http_request.overrideMimeType('text/xml');
						// Ver nota sobre esta linea al final
				}
		} else if (window.ActiveXObject) { // IE
				try {
						http_request = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e) {
						try {
								http_request = new ActiveXObject("Microsoft.XMLHTTP");
						} catch (e) {}
				}
		}

		if (!http_request) {
				alert('Falla :( No es posible crear una instancia XMLHTTP');
				return false;
		}

		http_request.onreadystatechange = alertContents3;
		http_request.open('GET', url, true);
		http_request.send(null);
}


			function alertContents3() {
	
					if (http_request.readyState == 4) {
							if (http_request.status == 200) {
								
								var xmldoc = http_request.responseXML;

								var tit_nucleos = xmldoc.getElementsByTagName('precio').item(0);
								tit_nucleos = tit_nucleos.firstChild.data;
								document.getElementById('txt_precio').innerHTML = "<span class='tit_precio'>Precio</span> <br /><br /><span class='txt_precio'><strong>"+tit_nucleos+"</strong> </span><br /> <span class='txt_detalle'>precio referido al "+document.getElementById('tit_nucleos').innerHTML+", "+document.getElementById('tit_fundas').innerHTML+", medidas "+document.asistente_paso2.ancho.value+"x"+document.asistente_paso2.alto.value+"</span><br>&nbsp;";		
								
								var tit_nucleos = xmldoc.getElementsByTagName('disponible').item(0);
								tit_nucleos = tit_nucleos.firstChild.data;								
								document.asistente_paso2.disponible.value=tit_nucleos;
								

								NLBfadeBg('txt_precio','#b6b7b1','#ffffff','2000');										



							
							} else {
									alert('Hubo problemas con la petición.');
							}
					}
	
			}
			
				
				
	function comprobarAnyadir(){
			form = document.asistente_paso2;
			if(form.alto.value=="" || form.ancho.value=="" ){
				alert("Debes seleccionar una medida del colchón para poder realizar la compra.");					
				return false;
			}
			
			if(form.disponible.value==0){
				alert("Las medidas seleccionadas para este colchón no están disponibles en la web, para más información en info@viscoform.es");					
				return false;
			}
			
			
			nucleo = form.nucleo.value;
			funda  = form.funda.value;
			alto   = form.alto.value;
			ancho  = form.ancho.value;			
			
		
			showPopWin('anyadir_carrito.php?nucleo='+nucleo+'&funda='+funda+'&alto='+alto+'&ancho='+ancho, 700, 250, null);		
	}
	
	function confirmarBorrado(){
			valor = confirm("¿Estás seguro de querer quitar el articulo seleccionado de tu carrito de la compra?");
			if(valor==true)
				return true;
			else
				return false;
	}
	
	function vaciarCesta(){
			valor = confirm("¿Estás seguro de querer eliminar todos los articulo de tu compra?");
			if(valor==true){
					document.ficha_pedido.enviado_eliminar.value = 0;
					document.ficha_pedido.borrado_total.value    = 1;					
					document.ficha_pedido.submit();
			}
			else
				return false;
	}	
	
	
	
	function abrirFormasPago(){
		window.open("formas_pago.php","FormasPago","width=650,height=450,scrollbars=yes, top=0, left=0");
	}
	
	
	function mostrarDatosEnvio(){

		form = document.ficha_cliente;
	
		
		if(form.envio.checked==true)
			document.getElementById('datos_envio').className = '';
		else
			document.getElementById('datos_envio').className = 'noMostrar';
	}
	
	


function confirmarPago(){
		form = document.datos_pedido;
		var noMarcado = 1;

		for (i=0;i<form.modalidad.length;i++){
		 if (form.modalidad[i].checked)
			 noMarcado = 0
		} 
	
		
		if(noMarcado==1){
				alert("Debes seleccionar una modalidad de pago");
				return false;
		}else{
				if(form.modalidad[2].checked==true){
					form.action = "https://sis.sermepa.es/sis/realizarPago";
				}else if(form.modalidad[3].checked==true)
					form.action = "https://www.paypal.com/cgi-bin/webscr" ;
				else
					form.action = "realizar_pedido.php";
		}
}


function mostrarTextoExplicativo(id, total){

		for(i=0;i<=total;i++){
			 document.getElementById("texto_mod_"+i).className = "noMostrar";
		}
	
		clase = document.getElementById("texto_mod_"+id).className;
		if(clase=="noMostrar")
			document.getElementById("texto_mod_"+id).className = "";

			
}
	function ventanaInfoVisa(){
		window.open("visa.html","Info","width=500,height=500");	
	}
	

	function ventanaInfoMaster(){
		window.open("http://www.mastercardbusiness.com/mcbiz/index.jsp?template=/orphans&content=securecodepopup", "Info","width=550,height=500");	
	}	
	
	
		function comprobarCantidadBuscador(valor){
			

			var er = /^[1-9]\d*$/;
			
		
			if(valor=="")
				cantidad = 0;
			else
				cantidad 	  = parseInt(valor);			
			


			if(er.test(cantidad)==false){
				Sexy.alert("Debes indicar una cantidad númerica.");
				return false;
			}			

			if(cantidad<=0){
				alert("Cantidad númerica no válida.");					
				return false;				
			}			
		
		return true;
			
	}



	function anyadirCarritoBuscador(valor,tiene_talla){

		eval("form = document.producto_"+valor+";");
		cantidad      = form.cantidad.value;
		id_referencia = form.id_articulo.value;
		id_talla 	  = form.id_talla.value;				

		valor = comprobarCantidadBuscador(cantidad);
		if(valor==false)
			return false;
			
		if(tiene_talla==1){
			if(form.medidas.value=='-1'){
				Sexy.alert("Este artículo esta disponible en varias medidas, debes indicar una medida.");
				return false;
			}			
		}
		


		showPopWin('anyadir_carrito.php?id_referencia='+id_referencia+"&cantidad="+cantidad+'&id_talla='+id_talla, 700, 250, null);		
		
		return false;
	}
	
	
	
	function calcula_precio(medida,  posicion){
		
			aux = medida.split('#');
			
			precio = aux[1].replace('.',',');
			document.getElementById('precio_'+posicion).innerHTML = "<strong>"+precio+"</strong>";
			
			
			eval("form = document.producto_"+posicion);
			form.id_talla.value = aux[0];
			

	}
	
	    var map;
    var geocoder;
    var address;
	 var tipoMapa = 0;

	 var texto_datos;	 

    function initialize(tipo) {

      map = new GMap2(document.getElementById("mapa"));
		
    	pointAdresse = new GLatLng(lat, lng);
		
		if(tipo==0)
      	map.setCenter(pointAdresse, 16,G_HYBRID_MAP);
		else
      	map.setCenter(pointAdresse, 10,G_HYBRID_MAP);		
		
      map.setUIToDefault();
		
	   geocoder = new GClientGeocoder();
	
	//	map.addControl(new GLargeMapControl());

		tipoMapa = 1;
		
		
		var extension = "png";
   		
		icon = new GIcon();
		if(tipo==0)
			icon.image = "http://www.viscoform.es/img/mapa." + extension;
		else
			icon.image = "http://www.viscoform.es/img/mapa." + extension;
			
		icon.iconSize = new GSize(36, 44);
		icon.shadowSize = new GSize(38, 34);
		icon.iconAnchor = new GPoint(10, 34);
		icon.infoWindowAnchor = new GPoint(5, 1);

    	map.checkResize();
            
    //	addMarker(lat, lng, icon);

      geocoder = new GClientGeocoder();
            
      map.checkResize();
            
        
	}
	
	    function createMarker(latlng,img) {
	      number++;
	      var marker = new GMarker(latlng,{ icon:img });
			bounds.extend(marker.getPoint());


	      return marker;
		}
	
		function addMarker(latGM,lngGM,img) {
		    var latlng = new GLatLng(latGM, lngGM);
			 var marker =  createMarker(latlng,img);
		    map.addOverlay(marker); 

	 
			 return marker;
		}
		
		function toggleMarker(nomMarker,opt) {

			if (markers[nomMarker]){ //vérifier que le marker existe ! sinon erreur javascript
				if(opt == "hide")
					markers[nomMarker].hide();
				else if(opt == "show"){
					markers[nomMarker].show();
				}
			}
	    }



var direccion = "";
function obtenerDatos(marker,point,id,nombre){
	
	

//	marker.openInfoWindowHtml(nombre);
	document.location = 'ficha_promocion.php?id='+id;

}


	function mostrarFaqs(cont,actual){

			for(i=0;i<cont;i++){
				$(document.getElementById('respuesta_'+i)).slideUp();
				//document.getElementById('ampliar_'+i).className = "ampliar_pregunta";
			}


			if ($(document.getElementById('respuesta_'+actual)).is(":hidden")) {
			  $(document.getElementById('respuesta_'+actual)).slideDown("slow");
			  //document.getElementById('ampliar_'+actual).className = "ampliar_pregunta_despl";			  
			} else {
			  $(document.getElementById('respuesta_'+actual)).slideUp();
			}		
		
	}