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 showVuelo() {
	document.getElementById("vuelo").style.visibility='visible';
  	document.form1.txt_vuelo.style.visibility = 'visible';
}

function hideVuelo() {
 	document.getElementById("vuelo").style.visibility='hidden'; 	
  	document.form1.txt_vuelo.style.visibility = "hidden";
}
function actualizaresultado(campo){
	var recogida=document.getElementById('select').value;
	
	if (recogida == '00') { return; }
	if (campo == 'select') { 
		document.getElementById('select2').value = recogida;
		// Si es aeropuerto, activar campo vuelo							
		switch (document.getElementById('select').value) {
    		case '31':  
    		case '80':
    		case '70':
      			showVuelo(); 
      			break
    		default:
				hideVuelo();
		} 				
	}
	
	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/search5.php?recogida='+recogida+'&devolucion='+devolucion+'&fechainicio='+fechainicio+'&fechafin='+fechafin+'&horainicio='+horainicio+'&horafin='+horafin+'&booster='+booster+'&sillita='+sillita+'&tipo='+tipo);
	
	document.getElementById('listado').innerHTML=devuelvecontenido;
	
	// Buscar grupo e imagen del primer grupo disponible
	if (tipo == 'F') {	
		grupo = 'H'; imagencoche = 'coches/banner_coche_10.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') { grupo = '1'; imagencoche = 'coches/banner_coche_14.jpg';}
	else {
		if (document.getElementById('datBegin').value != '') {
			grupo = document.getElementById('hgrupo').value; 
			imagencoche = document.getElementById('himagencoche').value; 
		}	
	
		else {grupo = 'A'; if (recogida == '70') {imagencoche = 'coches/banner_coche_26.jpg';} else {imagencoche = 'coches/banner_coche_46.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">Days:</span> <span class="letramediaverde">'+dias+'</span></td><td align="left"><span class="letramedia">Group:</span> <span class="letramediaverde">'+grupo+'</span></td></tr><tr><td align="left" class="letranormalnegrita">Pick up:</td><td align="left" class="letranormalnegrita">Drop off:</td></tr><tr><td align="left" class="letranormal">Location:</td><td align="left" class="letranormal">Location:</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">Date: </span><span class="letranormalverde">'+fechainicio+'</span></td><td align="left"><span class="letranormal">Date:</span> <span class="letranormalverde">'+fechafin+'</span></td></tr><tr><td align="left"><span class="letranormal">Time:</span> <span class="letranormalverde">'+horainicio+'h</span></td><td align="left"><span class="letranormal">Time:</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">V.A.T. Included</span></td></tr></table>';
}
