function buscaoferta(tipo,msjError,ordenFechas)
{
	//var direccion = "http://viajes.elcorteingles.es/bofertaS/programas/buscadorofertas.asp?orden=P";

	var direccion = "listado_ofertas.asp?orden=P" + "&codwebor=" + document.all('codwebor').value;

	switch (tipo)
	{
		case 'tipoOferta':
				if (document.all('cmbTipoOferta').value != "")
				{
					direccion = direccion + "&tipo=" + document.all('cmbTipoOferta').value;
					location.href = direccion;
				}
				break;
		case 'destino':	
				if (document.all('txtDestino').value != '')
				{
					//direccion = direccion + "&tipo=" + document.all('tipo').value;
					direccion = direccion + "&destino=" + document.all('txtDestino').value;
					location.href = direccion;
				}
				else
					alert (msjError);
				break;
		case 'destinoErr':
				if (document.all('txtDestinoErr').value != "")
				{
					//direccion = direccion + "&tipo=" + document.all('tipo').value;
					direccion = direccion + "&destino=" + document.all('txtDestinoErr').value;
					location.href = direccion;
				}
				else
					alert (msjError);
				break;
		case 'fecha':
				if (document.all('txtFecha').value != '')
				{	
					//var dia = devuelvefecha (document.all('txtFecha').value);
					var dia = devuelvefecha (convierteFechaTxt(convierteFechaTrb(document.all('txtFecha').value,'1'),ordenFechas));
					//direccion = direccion + "&tipo=" + document.all('tipo').value;
					direccion = direccion + "&fechinicio=" + dia;
					location.href = direccion;
					//alert (dia);
				}
				else
					alert (msjError);
				break;
		case 'precio':
				if (parseInt(document.all('cmbPrecioMin').value) >= parseInt(document.all('cmbPrecioMax').value) && parseInt(document.all('cmbPrecioMax').value) != "")
				{
					alert(msjError);
				}else{
					//direccion += "&tipo=" + document.all('tipo').value;
					direccion += "&preciomin=" + document.all('cmbPrecioMin').value;
					direccion += "&preciomax=" + document.all('cmbPrecioMax').value;
					location.href = direccion;
				}
				break;
		case 'tipoViaje':	
				//direccion = direccion + "&tipo=" +document.all('tipo').value;
				direccion = direccion + "&destinoV=" + document.all('cmbTipoViaje').value;
				location.href = direccion;
				break;
	}
}

function buscaoferta_all(tipo)
{
	//var direccion = "http://viajes.elcorteingles.es/bofertaS/programas/buscadorofertas.asp?orden=P";

	var direccion = "listado_ofertas.asp?orden=P";
	var sinDestino = true;
	
	//TipoOferta
	if ((tipo=='tipoOferta')&&(document.all('cmbTipoOferta').value != ''))
		direccion = direccion + "&tipo=" + document.all('cmbTipoOferta').value;
	else if(document.all('cmbTipoOferta').value != '')
		direccion = direccion + "&tipo=" + iTipoOferta;
	
	//Destino
	if ((tipo=='destino')&&(document.all('txtDestino').value == '')){
		alert('Debes rellenar el campo destino.');
		return;
		}
	if ((tipo=='destino')&&(document.all('txtDestino').value != '')){
		direccion = direccion + "&destino=" + document.all('txtDestino').value;
		sinDestino=false;
		}
	if ((tipo=='tipoViaje')&&(document.all('cmbTipoViaje').value != "")){
		direccion = direccion + "&destino=" + document.all('cmbTipoViaje').value;
		sinDestino=false;
		}
	if ((tipo=='destinoErr')&&(document.all('txtDestinoErr').value == '')){
			alert('Debes rellenar el campo destino.');
			return;
			}
	if ((tipo=='destinoErr')&&(document.all('txtDestinoErr').value != '')){
		direccion = direccion + "&destino=" + document.all('txtDestinoErr').value;
		sinDestino=false;
		}
	if (sinDestino)
		direccion = direccion + "&destino=" + iDestino;
		
	//Fecha
	if ((tipo=='fecha')&&(document.all('txtFecha').value == '')){
		alert ('Debes indicar una fecha.');
		return;
		}
	if ((tipo=='fecha')&&(document.all('txtFecha').value != "")){
		var dia = devuelvefecha (document.all('txtFecha').value);
		direccion = direccion + "&fechinicio=" + dia;
		}
	else
		direccion = direccion + "&fechinicio=" + iFechInicio;
	
	//Precio
	if ((tipo=='precio')&&(document.all('cmbPrecioMin').value >= document.all('cmbPrecioMax').value)){
		alert('El precio mínimo no puede ser superior al precio máximo.');
		return;
		}
	if ((tipo=='precio')&&(document.all('cmbPrecioMax').value >= document.all('cmbPrecioMin').value)){
		direccion += "&preciomin=" + document.all('cmbPrecioMin').value;
		direccion += "&preciomax=" + document.all('cmbPrecioMax').value;
		}
	else{
		direccion += "&preciomin=" + iPrecioMin;
		direccion += "&preciomax=" + iPrecioMax;
		}			
	
	location.href = direccion;
}

function devuelvefecha (str_datetime)
{
	var re_date = /^(\d+)\/(\d+)\/(\d+)$/;
	if (!re_date.exec(str_datetime))
		return alert("Invalid Datetime format: "+ str_datetime);
	fecha = new Date (RegExp.$3, RegExp.$2-1, RegExp.$1);
	var mes = fecha.getMonth()+1;
	if (mes < 10)
		mes = "0" + mes;
	return (new String (fecha.getFullYear() + "" + mes + "" + fecha.getDate()));
}

function ControlaMaximo ()
{
	if (parseInt(document.all('cmbPrecioMax').value) <= parseInt(document.all('cmbPrecioMin').value))
		document.all('cmbPrecioMax').selectedIndex = document.all('cmbPrecioMin').selectedIndex;
}

function ControlaMinimo ()
{
	if (parseInt(document.all('cmbPrecioMin').value) >= parseInt(document.all('cmbPrecioMax').value))
		document.all('cmbPrecioMin').selectedIndex = document.all('cmbPrecioMax').selectedIndex; 
}
