// JavaScript Document
/*function cargaPagina(url,div,parametros)
{
	new Request(
	{
		method: 'post',
		url: url,
		onSuccess: function(texto){
		$(div).innerHTML = texto;}
	}).send(parametros);
}*/
function cargaPagina(url,div,parametros)
{
	new Ajax(url,{method: 'post', postBody:parametros, update:div}).request();
}
function escribeflash(url,anchoswf,altoswf){
document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="https://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+anchoswf+'" height="'+altoswf+'"  align="middle">');
document.write('<param name="allowScriptAccess" value="sameDomain" />');
document.write('<param name="movie" value="'+url+'" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><embed wmode="transparent" src="'+url+'" quality="high" width="'+anchoswf+'" height="'+altoswf+'"  align="middle"  type="application/x-shockwave-flash" pluginspage="https://www.macromedia.com/go/getflashplayer" />');
document.write('</object>');}

var tempX=0;
var tempY=0;
var IE=document.all?true:false;
if(IE)
{
	var AltoPantalla = screen.Height / 2;
	var AnchoPantalla = screen.Width / 2;
}
else
{
	var AltoPantalla=screen.height / 2;	
	var AnchoPantalla=screen.width / 2;
}

function getMouseXY(e)
{
	if(IE)
	{
		tempX=event.clientX - 530;
		tempY=event.clientY;
		altura=document.body.clientHeight
	}
	else
	{
		tempX=parseInt(e.pageX-530)+"px";
		tempY=parseInt(e.pageY+16)+"px";
		altura=window.innerHeight
	}
	
	if(tempX<0)
		tempX=0;
		
	if(tempY<0)
		tempY=0;
	
	if(document.getElementById('cuadro').offsetHeight+parseInt(tempY)>altura)
	{
		document.getElementById('cuadro').style.top=(parseInt(parseInt(tempY)-document.getElementById('cuadro').offsetHeight)-18)+"px";
		
		if(parseInt(document.getElementById('cuadro').style.top)<0)
		{
			document.getElementById('cuadro').style.top=10+"px"
		}
	}
	else
	{
		document.getElementById('cuadro').style.top=tempY
	}
	
	document.getElementById('cuadro').style.left=tempX;
	return true;
}

function mueve()
{
	if(document.direccion.forma_entrega[0].checked)
		var reparto = 0;
	else
		var reparto = 1;
	var cp = $('direcciones-habituales').value
	cargaPagina('/desglose-compra.php', 'cuadro', 'reparto_tienda=' + reparto + "&cp=" + cp);
	
	if(!IE) document.captureEvents(Event.MOUSEMOVE);
	
	document.onmousemove=getMouseXY;
	//document.getElementById('cuadro').innerHTML="<img src='"+a+"' align='top'/><div style='padding:5px;'>"+b+"</div>";
	document.getElementById('cuadro').style.display="block";
	document.getElementById('cuadro').style.visibility="visible";
}

function oculta(){document.onmousemove="";document.getElementById('cuadro').style.display="none";document.getElementById('cuadro').style.visibility="hidden";document.getElementById('cuadro').style.left=-400+"px";document.getElementById('cuadro').style.top=-400+"px"}

function revisarDatosUsuario()
{
	var error = "";
		
	if($('nombre').value == "" && error == "")
	{
		alert("Por favor, debe rellenar el nombre de registro.");
		error = "nombre";
	}
	if($('apellidos').value == "" && error == "")
	{
		alert("Por favor, debe rellenar los apellidos de registro.");
		error = "apellidos";
	}
	if($('telefono').value == "" && error == "")
	{
		alert("Por favor, debe rellenar el teléfono de registro.");
		error = "telefono";
	}
	if(!telefono_valido($('telefono').value) && error == "")
	{
		alert("Por favor, el teléfono de registro de ser un número de 9 dígitos.\n\nFormato: 9xxxxxxxx - 6xxxxxxxx");
		error = "telefono";
	}
	if($('direccion').value == "" && error == "")
	{
		alert("Por favor, debe rellenar la dirección de registro.");
		error = "direccion";
	}
	if($('cp').value == "" && error == "")
	{
		alert("Por favor, debe rellenar el código postal de registro.");
		error = "cp";
	}
	if(!validaCodigoPostal($('cp').value) && error == "")
	{
		alert("Por favor, el código postal de registro de ser un número de 5 dígitos.");
		error = "cp";

	}
	if($('localidad').value == "" && error == "")
	{
		alert("Por favor, debe rellenar la localidad de registro.");
		error = "localidad";
	}
	
	if($('email').value == "" && error == "")
	{
		alert("Por favor, debe rellenar el email de registro.");
		error = "email";
	}
	if(!validarMail($('email').value) && error == "")
	{
		alert("Por favor, el email de registro no es correcto.");
		error = "email";
	}
	if($('usuario').value == "" && error == "")
	{
		alert("Por favor, debe rellenar usuaro de acceso a la web.");
		error = "usuario";
	}
	if($('password').value == "" && error == "")
	{
		alert("Por favor, debe rellenar la contraseña de acceso a la web.");
		error = "password";
	}
	if($('password').value != $('password_2').value && error == "")
	{
		alert("Las contraseñas de acceso a la web no coinciden.");
		error = "password";
	}
	if(!$('politica').checked && error == "")
	{
		alert("Por favor, para completar el registro debe aceptar la política de privacidad y aviso legal.");
		error = "politica";
	}
	
	if(error != "")
		$(error).focus();
	else if(confirm("¿Son correctos todos los datos?"))
		document.registro.submit();
}

function revisarDatosCoche()
{
	var error = "";
	var fecha = new Date();
	$('codigosEquipamiento').value = "";
	var modelos = $('todos_versiones');
	var cadElim = "";
	var cont = 0;
	
	for(i=0;i <= modelos.length	- 1; i++)
	{
		if(modelos[i].selected)
			cont++;
	}
		
	if(cont == 0 && error == "")
	{
		alert("Por favor, debe seleccionar una versión de coche.");
		error = "todos_versiones";
	}
	if(cont > 1 && error == "")
	{
		alert("Por favor, tan solo debe seleccionar una versión de coche.");
		error = "todos_versiones";
	}		
	
	if($('total_serie').value)
	{
		for(i=0; i<= $('total_serie').value; i++)
		{
			if($('serie_' + i).checked)
				$('codigosEquipamiento').value += $('serie_' + i).value + "#";
		}
	}
	
	if($('codigosEquipamiento').value == "" && $('total_serie').value > 0 && error == "")
	{
		alert("Por favor, debe seleccionar al menos un equipamiento de serie.");
		error = "serie_0";
	}
	
	if($('total_extra').value)
	{
		for(i=0; i<= $('total_extra').value; i++)
		{
			if($('extra_' + i).checked)
				$('codigosEquipamiento').value += $('extra_' + i).value + "#";
		}
	}
	if($('tipoPrecio').value != 1)
	{
		if($('precio').value == "" && error == "")
		{
			alert("Por favor, debe rellenar el precio del coche.");
			error = "precio";
		}
		if(isNaN($('precio').value) && error == "")
		{
			alert("El precio del coche debe ser un número.");
			error = "precio";
		}
		if($('precio').value <= 0 && error == "")
		{
			alert("El precio del coche debe ser mayor a 0 €.");
			error = "precio";
		}
	}
	/*if($('km').value == "" && error == "")
	{
		alert("Por favor, debe rellenar los kilómetros del coche.");
		error = "km";
	}*/
	if($('km').value != "" && error == "")
	{
		if(isNaN($('km').value) && error == "")
		{
			alert("Los kilómetros del coche debe ser un número.");
			error = "precio";
		}
		if($('km').value <= 0 && error == "")
		{
			alert("Los kilómetros del coche debe ser mayor a 0.");
			error = "precio";
		}
	}
	/*if($('ano_matriculacion').value == "" && error == "")
	{
		alert("Por favor, debe rellenar el año de matriculación del coche.");
		error = "ano_matriculacion";
	}*/
	if($('ano_matriculacion').value != "" && error == "")
	{
		if(isNaN($('ano_matriculacion').value) && error == "")
		{
			alert("El año de matriculación del coche debe ser un número.");
			error = "ano_matriculacion";
		}
		if(($('ano_matriculacion').value <= 1950 || $('ano_matriculacion').value > fecha.getFullYear()) && error == "")
		{
			alert("El año de matriculación del coche debe ser mayor a 1950 y menos o igual a " + fecha.getFullYear() + ".");
			error = "ano_matriculacion";
		}
	}
	for(i=1; i<= 6; i++)
	{
		if($('img_' + i).value != "")
		{
			if(!validateFotoExt($('img_'+i).value) && error == "")
			{
				alert("La extensión de las imagenes debe ser GIF - JPG - PNG.");
				error = "img_"+i;
			}	
			if($('accion').value == 2 && error == "")
			{
				cadElim += $('codImg' + i).value + "#";
			}
		}
	}
	if(!$('politica').checked && error == "")
	{
		alert("Por favor, para completar el registro del coche debe aceptar la política de privacidad y aviso legal.");
		error = "politica";
	}
	
	if(error != "")
		$(error).focus();
	else if(confirm("El proceso se puede alargar, dependiendo del tamaño de las imagenes.\n\n¿Son correctos todos los datos?"))	
	{
		if($('accion').value == 2) $('fotoAeliminar').value += cadElim;
		$('cargando').style.display = "inline";
		document.coche.submit();
	}
}

function validarMail(sEmail) {
  	var emailFilter = /^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
	if (sEmail != '' && emailFilter.test(sEmail)) {return true;}
	return false;
}

function validaCIF(CIF)
{
	var pares = 0;
	var impares = 0;
	var suma, ultima, numero;
	var letra = new Array("J", "A", "B", "C", "D", "E", "F", "G", "H", "I");
	var cad;
	
	CIF = CIF.toUpperCase();
	
	var regular = new RegExp(/^[ABCDEFGHKLMNPQS]\d\d\d\d\d\d\d[0-9,A-J]$/g);
	if (!regular.exec(CIF)) return false;
		 
	ultima = CIF.substr(8,1);
	
	for (var cont = 1 ; cont < 7 ; cont ++){
		cad = (2 * parseInt(CIF.substr(cont++,1))).toString() + "0";
		impares += parseInt(cad.substr(0,1)) + parseInt(cad.substr(1,1));
		pares += parseInt(CIF.substr(cont,1));
	}
	cad = (2 * parseInt(CIF.substr(cont,1))).toString() + "0";
	impares += parseInt(cad.substr(0,1)) + parseInt(cad.substr(1,1));
	
	suma = (pares + impares).toString();
	numero = parseInt(suma.substr(suma.length - 1, 1));
	numero = (10 - numero).toString();
	if(numero == 10) numero = 0;
	
	if ((ultima == numero) || (ultima == letra[numero]))
		return true;
	return false; 
}

function isValidNif(abc)
{
	dni=abc.substring(0,abc.length-1);
	let=abc.charAt(abc.length-1);
	if (!isNaN(let)) {
		return false;
	}else{
		cadena = "TRWAGMYFPDXBNJZSQVHLCKET";
		posicion = dni % 23;
		letra = cadena.substring(posicion,posicion+1);
		if (letra!=let.toUpperCase()){
			return false;
		}
	}
	return true;
}

function telefono_valido(numero)
{
	var tfno= parseInt(numero);
	var error = "";
	if ( isNaN(tfno) )
		return false;
	else
	{
		if ( !( (tfno >= 900000000) && (tfno < 1000000000) || (tfno >= 600000000) && (tfno < 700000000) ) )  
			return false;
	}
	return true;
}
function validaCodigoPostal(CP)
{
	if(CP == "" || isNaN(CP) || CP < 1000 || CP > 52999)
		return false;
	return true;
}
function comprueba_fecha(dia,mes,anio)
{
	var elMes = parseInt(mes);		
	if(elMes == 2)
	{
		if(esBisiesto(anio))
		{
			if(parseInt(dia) > 29)
				return false;
			else
				return true;
		}
		else
		{
			if(parseInt(dia) > 28)
				return false;
			else
				return true;
		}
	}

	if(elMes== 4 || elMes==6 || elMes==9 || elMes==11)
	{
		if(parseInt(dia) > 30)
			return false;
	
	}
	
	var hoy = new Date();
	
	edad=hoy.getFullYear()- anio;			
	
    if (hoy.getMonth() + 1 - elMes > 0)
       edad = edad + 1;
    else if(hoy.getMonth() + 1 - elMes == 0) 
	{	
		if (hoy.getUTCDate() - dia >= 0)
		   edad = edad +1;
	}

	if(edad < 18)
	    return false;
		
	return true;
}
function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
		cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+'.'+
	num.substring(num.length-(4*i+3));
	return (num + ',' + cents);
}

/*
window.addEvent('load', function() {
 
	ReMooz.assign('#demo-photos a', {
		'origin': 'img',
		'shadow': 'onOpenEnd', // fx is faster because shadow appears after resize animation
		'resizeFactor': 0.8, // resize to maximum 80% of screen size
		'cutOut': false, // don't hide the original
		'opacityResize': 0.4, // opaque resize
		'dragging': false, // disable dragging
		'centered': true // resize to center of the screen, not relative to the source element
	});
 
	/**
	 * Note on "shadow": value can be true, onOpenEnd (appear after resize) and false, to disable shadow
	 * WebKit (Safari 3) uses (great looking) CSS shadows, so it ignores this option.
	 */
 
//});

function validaNuevaDireccion()
{
	if($('direccion-nueva').value != '' && validaCodigoPostal($('cp-nueva').value))
	{
		if($('cp-nueva').value.length == 4)
			var pro = $('cp-nueva').value.substr(0,1);
		else
			var pro = $('cp-nueva').value.substr(0,2);
			
		if(pro == "7" || pro == "07" || pro == "35" || pro == "38" || pro == "51" || pro == "52")
			alert("Por cuestiones de reparto tan solo se permite el\nregistro a provincias de EspaÃ±a peninsular.");
		else
			document.direccion.submit();
	}
	else
		alert('Debe rellenar correctamente todos los datos.');
}
function cargaMapa()
{
		var map = new google.maps.Map2(document.getElementById("map"));
		var geocoder = new GClientGeocoder();
		var address = $('direccion').value;			
		
		var texto = "<div style='font-family:arial; font-size: 11px;'>" + address + "<br />";
		texto += $('cp').value + " " + $('poblacion').value + " (" + $('provincia').value + ")<br />";
		texto += $('tlf').value + "<br />";
		texto += $('email').value + "</div>";
		if($('lat').value != "" && $('lon').value != "")
		{
			var LatLng = new GLatLng($('lat').value, $('lon').value);
			map.setCenter(LatLng, 16);
			marker = new GMarker(LatLng);
			marker.openInfoWindowHtml(texto);
			map.addOverlay(marker);					
		}
		else
		{
			var LatLng = new GLatLng(geocoder.getLatLng(address, function(point) {
					map.setCenter(point, 16);
					var marker = new GMarker(point);
					marker.openInfoWindowHtml(texto);
					map.addOverlay(marker);
				}
				)
			);
		}
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		map.setMapType(G_HYBRID_MAP)
}
function validaCP()
{
	var cp = parseFloat($('cp').value);
	if(!validaCodigoPostal(cp))
	{
		alert("Por favor, el cÃ³digo postal de registro de ser un nÃºmero de 5 dÃ­gitos.");
		$('cp').focus();
		return false;
	}
	if(cp < 10000)
		cp = "0" + cp.toString();
	$('cp').value = cp;	
	cargaPagina('resultados-busqueda-tiendas.php', 'resultados_busqueda', 'cp=' + cp);
}
function validateFotoExt(foto) 
{	
	if(foto != "")
	{
		var corte = foto.split(".");
		var extension = corte[corte.length - 1];
		if(extension.toUpperCase() == "JPG" || extension.toUpperCase() == "GIF" || extension.toUpperCase() == "PNG")
			return true;
		else
			return false;
	}
	else
		return false;
}
function  marcarSerie(tipo)
{
	if($('total_serie').value)
	{
		for(i=0; i<= $('total_serie').value; i++)
		{
			if(tipo == 1)
				$('serie_' + i).checked = true;
			else
				$('serie_' + i).checked = false;
		}
	}
	else
		alert("Debe seleccionar una versión")
}
function  marcarExtra(tipo)
{
	if($('total_extra').value)
	{
		for(i=0; i<= $('total_extra').value; i++)
		{
			if(tipo == 1)
				$('extra_' + i).checked = true;
			else
				$('extra_' + i).checked = false;
		}
	}
	else
		alert("Debe seleccionar una versión")
}

var actuTam;
function actualizatamanos()
{
	if($('div_colum2'))
	{
		clearTimeout(actuTam);
		while(document.getElementById('div_colum1').offsetHeight != (document.getElementById('div_colum2').offsetHeight + 31))
		{
			var tamano1 = document.getElementById('div_colum1').offsetHeight;
			var tamano2 = document.getElementById('div_colum2').offsetHeight;
			
			if(tamano1 > tamano2)
				$('div_colum2').style.height = (tamano1 - 33) + "px";
			else
				$('div_colum1').style.height = (tamano2 + 33) + "px";
				
		}
	}
	else
		actuTam = setTimeout("actualizatamanos();", 500);
}

function revisarContacto()
{
	var error = "";
	/*if($('nombre_contacto').value == "" && error == "")
	{
		alert("Debe rellenar el nombre.").
		error = "nombre_contacto";
	}*/
	if($('email_contacto').value == "" && error == "")
	{
		alert("Debe rellenar el e-mail.").
		error = "email_contacto";
	}
	if(!validarMail($('email_contacto').value) && error == "")
	{
		alert("El e-mail es incorrecto.").
		error = "email_contacto";
	}
	if($('tlf_contacto').value == "" && error == "")
	{
		alert("Debe rellenar el teléfono.").
		error = "tlf_contacto";
	}
	if($('tlf_contacto').value != "" && error == "")
	{
		if(!telefono_valido($('tlf_contacto').value) && error == "")
		{
			alert("El teléfono es incorrecto.").
			error = "tlf_contacto";
		}
	}
	if($('comentarios_contacto').value == "" && error == "")
	{
		alert("Debe rellenar los comentarios.").
		error = "comentarios_contacto";
	}
	
	if(error != "")
		$(error).focus()
	else if(confirm("¿Estan correctos los datos?"))
	{
		cargaPagina('guarda-click.php', 'div_oculto', 'tipo=4&cliente='+$('cliente').value+'&coche=' + $('coche').value);
		if($('color'))
			extra = '&color=' + $('color').value;
		else
			extra = '';
		cargaPagina('envia_contacto.php', 'envio_contacto', 'coche=' + $('coche').value + '&nombre=' + $('nombre_contacto').value + '&email=' + $('email_contacto').value + '&telefono=' + $('tlf_contacto').value + '&comentarios=' + $('comentarios_contacto').value + "&tipo=" + $('tipo_contacto').value + extra)
	}
	
}
function revisarContacto2(tipo, pos)
{
	if(tipo == 1)
		div = "div_amp_inf_"+pos;
	else if(tipo == 2)
		div = "div_finan_"+pos;
	else
		div = "div_contacta_"+pos;
	
	var error = "";
	/*if($('nombre_contacto').value == "" && error == "")
	{
		alert("Debe rellenar el nombre.").
		error = "nombre_contacto";
	}*/
	if($('email_contacto' + pos).value == "" && error == "")
	{
		alert("Debe rellenar el e-mail.").
		error = "email_contacto" + pos;
	}
	if(!validarMail($('email_contacto' + pos).value) && error == "")
	{
		alert("El e-mail es incorrecto.").
		error = "email_contacto" + pos;
	}
	if($('tlf_contacto').value == "" && error == "")
	{
		alert("Debe rellenar el teléfono.").
		error = "tlf_contacto";
	}
	if($('tlf_contacto' + pos).value != "" && error == "")
	{
		if(!telefono_valido($('tlf_contacto' + pos).value) && error == "")
		{
			alert("El teléfono es incorrecto.").
			error = "tlf_contacto" + pos;
		}
	}
	if($('comentarios_contacto' + pos).value == "" && error == "")
	{
		alert("Debe rellenar los comentarios.").
		error = "comentarios_contacto" + pos;
	}
	
	if(error != "")
		$(error).focus()
	else if(confirm("¿Estan correctos los datos?"))
	{
		cargaPagina('guarda-click.php', 'div_oculto', 'tipo=4&cliente='+$('cliente' + pos).value+'&coche=' + $('coche' + pos).value);
		if(document.getElementById('color'))
			extra = '&color=' + $('color').value;
		else
			extra = '';
		cargaPagina('envia_contacto2.php', div, 'coche=' + $('coche' + pos).value + '&nombre=' + $('nombre_contacto' + pos).value + '&email=' + $('email_contacto' + pos).value + '&telefono=' + $('tlf_contacto' + pos).value + '&comentarios=' + $('comentarios_contacto' + pos).value + "&tipo=" + $('tipo_contacto' + pos).value+"&pos="+pos + extra)
	}
	
}
function buscaCoche()
{
	if($('marca').value == 0 && $('modelo').value == 0)
	{
		alert("Seleccione marca y modelo")
		return false;
	}
	else if(($('mes').value != '' && $('mes').value != 0) && $('ano').value == 0)	
	{
		alert('Indique el año');
		$('mes').focus();
		return false;
	}
	else
		document.registro.submit();
}

function compruebaSubmit()
{
	if($('ano') && $('combustible') && $('cambio') && $('potencia') && $('puertas'))
		document.registro.submit();
	else
		setTimeout("compruebaSubmit();", 500);
}

function abreFormulario(pos,tipo,coche,cliente, total)
{
	if(tipo == 1)
		div = "div_amp_inf_";
	else if(tipo == 2)
		div = "div_finan_";
	else
		div = "div_contacta_";
		
	if(document.getElementById('color'))
		extra = '&color=' + $('color').value;
	else
		extra = '';
		
	cargaPagina('/carga_formulario_contacto.php', div + pos, 'pos='+pos+'&tipo='+tipo+'&coche='+coche+'&id_cliente='+cliente + extra);
	
	for(i=parseInt($('numInicio').value);i<= parseInt($('numFinal').value); i++)
	{
		if($('div_contacta_'+i))
		{
			if($('div_amp_inf_'+i)) $('div_amp_inf_'+i).style.display='none';
			if($('div_finan_'+i)) $('div_finan_'+i).style.display='none';
			if($('div_contacta_'+i)) $('div_contacta_'+i).style.display='none';
			if(i == pos)
			{				
				if(tipo == 1)
					$("div_amp_inf_"+i).style.display = 'inline';
				else if(tipo == 2)
					$("div_finan_"+i).style.display = 'inline';
				else
					$("div_contacta_"+i).style.display = 'inline';
			}
		}
	}
	if($('div_amp_inf_0'))
	{
		$('div_amp_inf_0').style.display='none';
		$('div_finan_0').style.display='none';
		$('div_contacta_0').style.display='none';
		if(pos == 0)
		{
			if(tipo == 1)
				$("div_amp_inf_0").style.display = 'inline';
			else if(tipo == 2)
				$("div_finan_0").style.display = 'inline';
			else
				$("div_contacta_0").style.display = 'inline';
		}
	}
}

function cierraIframe (num, tipo)
{
	if(tipo == 1)
	{
		document.getElementById('div_amp_inf_'+num).style.display='none';
		document.getElementById('sAmp_'+num).style.visibility='hidden';
	}
	else if(tipo == 2)
	{
		document.getElementById('div_finan_'+num).style.display='none';
		document.getElementById('sFin_'+num).style.visibility='hidden';
	}
	else
	{
		document.getElementById('div_contacta_'+num).style.display='none';
		document.getElementById('sCon_'+num).style.visibility='hidden';
	}
}

function abreFormularioMicrosite(pos,tipo,coche,cliente,dominio)
{
	if(tipo == 1)
		div = "div_amp_inf_";
	else if(tipo == 2)
		div = "div_finan_";
	else if(tipo == 3)
		div = "div_contacta_";
		
	if(document.getElementById('color'))
		extra = '&color=' + $('color').value;
	else
		extra = '';
	
	if(tipo == 1)
		document.getElementById('sAmp_'+pos).style.visibility='visible';
	else if(tipo == 2)
		document.getElementById('sFin_'+pos).style.visibility='visible';
	else if(tipo == 3)
		document.getElementById('sCon_'+pos).style.visibility='visible';
	
				
	$(div+pos).innerHTML = '<iframe src="http://www.cochessegundamanogalicia.com/carga_formulario_contacto.php?dominio='+dominio+'&pos='+pos+'&mini=1&microsite=1&tipo='+tipo+'&coche='+coche+'&id_cliente='+cliente+ extra+'" frameborder="0" style="width:341px;height:217px;"></iframe>';
	//alert($(div+pos).innerHTML);
	//cargaPagina('/carga_formulario_contacto.php', div + pos, 'pos='+pos+'&tipo='+tipo+'&coche='+coche+'&id_cliente='+cliente + extra);
	
	for(i=parseInt($('numInicio').value);i<= parseInt($('numFinal').value); i++)
	{
		
		
		
		if($('div_contacta_'+i))
		{
			if($('div_amp_inf_'+i))
			{
				$('div_amp_inf_'+i).style.display='none';
				document.getElementById('sAmp_'+i).style.visibility='hidden';
			}
			if($('div_finan_'+i))
			{
				$('div_finan_'+i).style.display='none';
				document.getElementById('sFin_'+i).style.visibility='hidden';
			}
			if($('div_contacta_'+i))
			{
				$('div_contacta_'+i).style.display='none';			
				document.getElementById('sCon_'+i).style.visibility='hidden';
			}
			
			if(i == pos)
			{				
				if(tipo == 1)
				{
					$("div_amp_inf_"+i).style.display = 'inline';
					document.getElementById('sAmp_'+pos).style.visibility='visible';
				}
				else if(tipo == 2)
				{
					$("div_finan_"+i).style.display = 'inline';
					document.getElementById('sFin_'+pos).style.visibility='visible';
				}
				else
				{
					$("div_contacta_"+i).style.display = 'inline';
					document.getElementById('sCon_'+pos).style.visibility='visible';
				}
			}
			else
			{
				if($('div_amp_inf_'+i)) $('div_amp_inf_'+i).innerHTML='';
				if($('div_finan_'+i)) $('div_finan_'+i).innerHTML='';
				if($('div_contacta_'+i)) $('div_contacta_'+i).innerHTML='';
			}
		}
	}
	if($('div_amp_inf_0'))
	{
		$('div_amp_inf_0').style.display='none';
		$('div_finan_0').style.display='none';
		$('div_contacta_0').style.display='none';
		if(pos == 0)
		{
			if(tipo == 1)
				$("div_amp_inf_0").style.display = 'inline';
			else if(tipo == 2)
				$("div_finan_0").style.display = 'inline';
			else
				$("div_contacta_0").style.display = 'inline';
		}
	}
}

function cierraIframeAcc (num, tipo)
{
	if(tipo == 1)
	{
		document.getElementById('div_amp_inf_'+num).style.display='none';
		document.getElementById('sAmp_'+num).style.visibility='hidden';
	}
	else if(tipo == 2)
	{
		document.getElementById('div_finan_'+num).style.display='none';
		document.getElementById('sFin_'+num).style.visibility='hidden';
	}
	else
	{
		document.getElementById('div_contacta_'+num).style.display='none';
		document.getElementById('sCon_'+num).style.visibility='hidden';
	}
}

function abreFormularioAcc(pos,tipo,accesorio,cliente, total)
{
	if(tipo == 1)
		div = "div_amp_inf_";
	else
		div = "div_contacta_";
		
	if(document.getElementById('color'))
		extra = '&color=' + $('color').value;
	else
		extra = '';
		/*
	if(tipo == 1)
		document.getElementById('sAmp_'+pos).style.visibility='visible';
	else if(tipo == 2)
		document.getElementById('sFin_'+pos).style.visibility='visible';
	else if(tipo == 3)
		document.getElementById('sCon_'+pos).style.visibility='visible';
		*/
	//$(div+pos).innerHTML = '<iframe src="http://www.cochessegundamanogalicia.com/carga_formulario_contacto_accesorios.php?dominio='+dominio+'&pos='+pos+'&microsite=1&tipo='+tipo+'&accesorio='+accesorio+'&id_cliente='+cliente+ extra+'" frameborder="0" style="width:341px;height:217px;"></iframe>';
		
	cargaPagina('/carga_formulario_contacto_accesorios.php', div + pos, 'pos='+pos+'&tipo='+tipo+'&accesorio='+accesorio+'&id_cliente='+cliente + extra);
	
	for(i=parseInt($('numInicio').value);i<= parseInt($('numFinal').value); i++)
	{
		if($('div_contacta_'+i))
		{
			if($('div_amp_inf_'+i)) $('div_amp_inf_'+i).style.display='none';
			if($('div_contacta_'+i)) $('div_contacta_'+i).style.display='none';
			if($('div_amp_inf_'+i)) $('div_amp_inf_'+i).innerHTML='';
			if($('div_contacta_'+i)) $('div_contacta_'+i).innerHTML='';
			
			if(i == pos)
			{				
				if(tipo == 1)
					$("div_amp_inf_"+i).style.display = 'inline';
				else
					$("div_contacta_"+i).style.display = 'inline';
			}
		}
	}
	if($('div_amp_inf_0'))
	{
		$('div_amp_inf_0').style.display='none';
		$('div_contacta_0').style.display='none';
		if(pos == 0)
		{
			if(tipo == 1)
				$("div_amp_inf_0").style.display = 'inline';
			else
				$("div_contacta_0").style.display = 'inline';
		}
	}
}


