var imagencoche="coches/banner_coche_01.jpg";
var modelocoche="modelo1";
var grupo ="A";
var importe = 0;
var campo = '';

function getContent(sURL) {
	var xmlhttp;
	if(window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
		xmlhttp.open("GET", sURL, false);
		xmlhttp.send(null);
	} else if (window.ActiveXObject) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		if(xmlhttp) {
			xmlhttp.open("POST", sURL, false);
			xmlhttp.send();
		}
	}
	return xmlhttp.responseText;
}

function actualizaresultado(campo){
	var recogida=document.getElementById('select').value;
	
	if (recogida == '00') { return; }
	if (campo == 'select') { document.getElementById('select2').value = recogida;}
	
	var devolucion=document.getElementById('select2').value;
	var fechainicio=(document.getElementById("datBegin").value.substr(6,4)+'-'+document.getElementById("datBegin").value.substr(3,2)+'-'+document.getElementById("datBegin").value.substr(0,2));
	var fechafin=(document.getElementById("datEnd").value.substr(6,4)+'-'+document.getElementById("datEnd").value.substr(3,2)+'-'+document.getElementById("datEnd").value.substr(0,2));
	var horainicio=document.getElementById('horainicio').value;
	var horafin=document.getElementById('horafin').value;
	var booster=document.getElementById('booster').value;
	var sillita=document.getElementById('sillita').value;
	var tipo=document.getElementById('tipo').value;
	//var seleccionado=document.getElementById('seleccionado').value
	
	var devuelvecontenido=getContent('../../Scripts/search2.php?recogida='+recogida+'&devolucion='+devolucion+'&fechainicio='+fechainicio+'&fechafin='+fechafin+'&horainicio='+horainicio+'&horafin='+horafin+'&booster='+booster+'&sillita='+sillita+'&tipo='+tipo);
	
	document.getElementById('listado').innerHTML=devuelvecontenido;
	
	if (tipo == 'F') {	
		grupo = 'N'; imagencoche = 'coches/banner_coche_18.jpg';
		if (document.getElementById('datBegin').value != '') {
			var dday   = (document.getElementById('datBegin').value).substr(0,2);
			var dmonth = (document.getElementById('datBegin').value).substr(3,2) - 1;
			var dyear  = (document.getElementById('datBegin').value).substr(6,4);
			var desde  = new Date(dyear,dmonth,dday);
			var ss = new Date(2009,05,28); // Ojo, el mes - 1
				
			if (desde<=ss) {grupo = 'N'; imagencoche = 'coches/banner_coche_18.jpg';}
		}
	}
	else if (tipo == 'M') {
			if (recogida == '61') { grupo = '2'; imagencoche = 'coches/banner_coche_15.jpg'; }
			else {grupo = '1'; imagencoche = 'coches/banner_coche_14.jpg';}
	}
	else {
		if (document.getElementById('datBegin').value != '') {
			grupo = 'A'; imagencoche = 'coches/banner_coche_01.jpg'; 
			var dday   = (document.getElementById('datBegin').value).substr(0,2);
			var dmonth = (document.getElementById('datBegin').value).substr(3,2) - 1;
			var dyear  = (document.getElementById('datBegin').value).substr(6,4);
			var desde  = new Date(dyear,dmonth,dday);
			
			
			var ssanta1 = new Date(2010,05,06); // Ojo el mes -1 
			
			var ssF2 = new Date(2010,04,30); // Ojo el mes -1 
			
			
			if (recogida == '70') {grupo = 'A'; imagencoche = 'coches/banner_coche_26.jpg'; }
			else 
			if (recogida != '61') {
				if (desde < ssF2) {grupo = 'D'; imagencoche = 'coches/banner_coche_04.jpg'; }
				if ((desde < ssanta1) && (recogida == '80')) { 
				grupo = 'D'; imagencoche = 'coches/banner_coche_04.jpg';
				
				}
			} else if (recogida == '61') { 
			
			}
		}	
		//
		else {grupo = 'A'; imagencoche = 'coches/banner_coche_01.jpg'; }
	}
	cambiofoto(imagencoche,modelocoche,grupo,document.getElementById('hprecio').value);
}

function cambiofoto(valor,cambioid,grupo,importe){
	document.getElementById('imagencoche').innerHTML="<img src='../../images_nuevo/"+valor+"' alt='Selected car group' />";
	
	var totalids=parseInt(document.getElementById("totalmodelos").value);
	
	for(i=0;i<totalids;i++){
		contadorids="modelo"+(i+1);
		document.getElementById(contadorids).innerHTML="<img src='../../images_nuevo/_blank.gif' width='11' height='10' border='0' alt='' />";
	}
	
	document.getElementById(cambioid).innerHTML="<img src='../../images_nuevo/botonverde.jpg' alt=''  width='11' height='10' border='0' />";
	document.getElementById('hprecio').value = importe;
	document.getElementById('hgrupo').value = grupo;
	//Display Resumen, faltan días y grupo.
	var recogida=document.getElementById('hrecogida').value;
	var devolucion=document.getElementById('hdevolucion').value;
	var fechainicio=document.getElementById('datBegin').value;
	var fechafin=document.getElementById('datEnd').value;
	var horainicio=document.getElementById('horainicio').value;
	var horafin=document.getElementById('horafin').value;
	var dias=document.getElementById('hdias').value;
	
	document.getElementById('resumen').innerHTML='<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td align="left"><span class="letramedia">D&iacute;as:</span> <span class="letramediaverde">'+dias+'</span></td><td align="left"><span class="letramedia">Grupo:</span> <span class="letramediaverde">'+grupo+'</span></td></tr><tr><td align="left" class="letranormalnegrita">Recogida:</td><td align="left" class="letranormalnegrita">Devoluci&oacute;n:</td></tr><tr><td align="left" class="letranormal">Lugar:</td><td align="left" class="letranormal">Lugar:</td></tr><tr><td align="left" class="letranormalverde">'+recogida+'</td><td align="left" class="letranormalverde">'+devolucion+'</td></tr><tr><td align="left"><span class="letranormal">Fecha: </span><span class="letranormalverde">'+fechainicio+'</span></td><td align="left"><span class="letranormal">Fecha:</span> <span class="letranormalverde">'+fechafin+'</span></td></tr><tr><td align="left"><span class="letranormal">Hora:</span> <span class="letranormalverde">'+horainicio+'h</span></td><td align="left"><span class="letranormal">Hora:</span><span class="letranormalverde">'+horafin+'h</span></td></tr><tr><td colspan="2" align="left"><span class="letragrande">Total:</span> <span class="letragrandeverde">'+importe+'</span> <span class="letranormalverde">I.V.A. Incluido</span></td></tr></table>';
}
