  var daysVuelta = 7;
  var salidaDate;
  var regresoDate ;
  var currentDate = new Date();
  salidaDate=new Date();
  salidaDate=currentDate;
  regresoDate=new Date(salidaDate.getFullYear(),salidaDate.getMonth(),salidaDate.getDate()+daysVuelta)
//  window.document.getElementById('salida').value = (salidaDate.getDate()) + '/' + (salidaDate.getMonth()+1).toString() + '/' + salidaDate.getFullYear();
//  window.document.getElementById('regreso').value=(regresoDate.getDate()) + '/' + (regresoDate.getMonth()+1).toString() + '/' + regresoDate.getFullYear();


function ocultar_mostrar_combos()
{
    if(document.getElementById('checkintrodestino').checked == true)
    {//mostrar autocomplete, ocultar combos
        document.getElementById('bloque-destino').style.display='none';
        document.getElementById('bloquedestinofertas2').style.display='none';
        document.getElementById('bloquedestinofertasauto').style.display='inline';
    }
    else
    {//ocultar autocomplete, mostrar combos
        document.getElementById('bloque-destino').style.display='inline';
        document.getElementById('bloquedestinofertas2').style.display='inline';
        document.getElementById('bloquedestinofertasauto').style.display='none';
    }
}


function carga_ajax_inicio(url,cap){ 
	if (window.XMLHttpRequest) //Non-IE Browsers
		GlobalAjaxObject = new XMLHttpRequest(); //Global Variable
	else if(window.ActiveXObject) //IE Browsers
		GlobalAjaxObject = new ActiveXObject("Msxml2.XMLHTTP");  //Global Variable
	else { //Your browsers is not compatible with AJAX
		alert('Your browser is not supported.')
		return; //exit
	}
	//Initialized the Ajax object to access the URL
	capa = cap;
	GlobalAjaxObject.open("GET", url ); 
	//Sets the function that is run many times.
	GlobalAjaxObject.onreadystatechange = keepChecking_inicio; 
	//Executes the request
	GlobalAjaxObject.send(null);
}

//This function keeps checking for a successful connection
function keepChecking_inicio() {
	var element =  'document.getElementById("' + capa + '")';
	//eval(element).innerHTML = 'Cargando Datos, espere por favor...';
	//eval(element).innerHTML='inicio';
	//mostrar();
	if(GlobalAjaxObject.readyState == 4){
		if(GlobalAjaxObject.status == 200){ //200 = success
			text = GlobalAjaxObject.responseText;
			eval(element).innerHTML=text;
				
			//ocultar();		
			//document.getElementById("seleccion").innerHTML=document.getElementById("se_cli").value
			//document.getElementById("pre_min_sel").innerHTML=document.getElementById("min_cli").value
		}
	}
}

function carga_paises(){
var zona_select=document.getElementById('destinozona').value
var cadena='';
if (zona_select!="-1" && zona_select!=ZONA_SPAIN)
{
    cadena='/carga_paises.aspx?id_zona=' + zona_select + '&id_pais=';
    carga_ajax_inicio(cadena,'bloquedestinofertas2');
    document.getElementById('bloquedestinofertas2').style.display='block';
}
else
{
    
}
return false;
}

function seleccionar_tipo_destino(tipo)
{
    if (tipo==1)
    {
        document.getElementById('checkintrodestino').checked=true;
        ocultar_mostrar_combos();   
    }
    else
    {
        document.getElementById('checkintrodestino').checked=false;
        ocultar_mostrar_combos();   
    }
}

function comprobar_validacion_ofertas() 
{
	if(GlobalAjaxObjectVal.readyState == 4)
	{
		if(GlobalAjaxObjectVal.status == 200)
		{ //200 = success
			text = GlobalAjaxObjectVal.responseText;
			var element = document.getElementById('validacionesofertas');
			element.innerHTML=text;
			//mostramos los mensajes de error
			
			var error = 0;
			
			if (document.formulariofertas.horigenofertas.value == 0)
            {
                error=1;
                document.getElementById('avisoorigenofertas').style.display='block';
            }
            else
            {
                document.getElementById('avisoorigenofertas').style.display='none';
                document.formulariofertas.origenofertas.value = document.formulariofertas.horigenofertasvalue.value;
            }
            
            document.getElementById('avisodestinofertas').style.display='none';
            
            if (document.formulariofertas.hdestinofertas.value == 0)
            {
                error=1;
                document.getElementById('destinofertasLabel').innerText='Destino no encontrado!!';
                document.getElementById('avisodestinofertas').style.display='block';
            }
            else
            {
                if(document.formulariofertas.hdestinofertasvalue)
                    document.formulariofertas.destinofertas.value = document.formulariofertas.hdestinofertasvalue.value;
            }

	        if (document.getElementById('hdistintosofertas').value == 0)
	        {
	            error=1;
	            document.getElementById('destinofertasLabel').innerText='Origen igual a destino!!';           
	            document.getElementById('avisodestinofertas').style.display='block';
	        }

	        if (document.getElementById('hsalida').value == 0)
	        {
	            error=1;
	            document.getElementById('avisofechasfertas').style.display='block';
	        }
	        if (document.getElementById('hregreso').value == 0)
	        {
	            error=1;
	            document.getElementById('avisofechasfertas').style.display='block';
	        }

            if (document.formulariofertas.hpreciomax.value == 0)
            {
                error=1;
                document.getElementById('avisopreciomax').style.display='block';
            }
            else
            {
                var precio=document.formulariofertas.preciofertas.value.toString();
                if (precio.indexOf(".") != -1)
                    document.formulariofertas.preciofertas.value=precio.substring(0,precio.indexOf("."));
                precio=document.formulariofertas.preciofertas.value.toString();                 
                if (precio.indexOf(",") != -1)
                    document.formulariofertas.preciofertas.value=precio.substring(0,precio.indexOf(","));     
                document.getElementById('avisopreciomax').style.display='none';
                
            }
            if (error==0 )
            {
                document.getElementById('btnBuscar').src='/images/ES/botones/btn-buscando.png';
                document.formulariofertas.submit();
            }
		}
	}
}


function validar_campos()
{
	if (window.XMLHttpRequest) //Non-IE Browsers
		GlobalAjaxObjectVal = new XMLHttpRequest(); //Global Variable
	else if(window.ActiveXObject) //IE Browsers
		GlobalAjaxObjectVal = new ActiveXObject("Msxml2.XMLHTTP");  //Global Variable
	else 
	{ //Your browsers is not compatible with AJAX
		alert('Your browser is not supported.')
		return; //exit
	}
	//Initialized the Ajax object to access the URL
	url="";

    if(document.getElementById('checkintrodestino').checked == true)
    {
        url="/validaciones.aspx?origenofertas=" + document.formulariofertas.origenofertas.value.toString() + "&destinofertas=" + document.formulariofertas.destinofertas.value.toString() + "&preciomax=" + document.formulariofertas.preciofertas.value.toString() + "&ofertas=1" + "&salida=" + document.getElementById("salida").value + "&regreso=" + document.getElementById("regreso").value;
    }
    else
    {
        url="/validaciones.aspx?origenofertas=" + document.formulariofertas.origenofertas.value.toString() + "&preciomax=" + document.formulariofertas.preciofertas.value.toString() + "&ofertas=1" + "&salida=" + document.getElementById("salida").value + "&regreso=" + document.getElementById("regreso").value;            
    }

	var url_encode= encodeURI(url);
	
	GlobalAjaxObjectVal.open("GET", url_encode );
	//GlobalAjaxObject.open("POST", document.formulariohome);
	//Sets the function that is run many times.

    GlobalAjaxObjectVal.onreadystatechange = comprobar_validacion_ofertas; 
	
	//Executes the request
	GlobalAjaxObjectVal.send(null);
}

function MiCuenta()
    {
        window.open('/UserLogin.aspx');
    }

/************ MANEJO DE LISTADO DE AEROPUERTOS *************/

function elegir_aeropuerto(control)
{
    document.getElementById('hcontrol').value=control;
    document.getElementById('listado-aeropuertos').style.display='block';
    if(control=='origenofertas')
    {
    	if(window.ActiveXObject)
		    document.getElementById('listado-aeropuertos').style.left='400px';
	    else 
            document.getElementById('listado-aeropuertos').style.left='-100px';
    }
    else
    {
        if(control=='destinofertas')
        {
    	    if(window.ActiveXObject)
		        document.getElementById('listado-aeropuertos').style.left='700px';
	        else
                document.getElementById('listado-aeropuertos').style.left='200px';
        }
    }
}

function cerrar_session()
    {
        window.open('/UserLogin.aspx?mode=cerrar');
    }
function Recargar_alertas(cerrar)
{
    if (cerrar==1)
        window.location.href=window.location.href;
    else
        window.location.href="Alertas.aspx?mode=insert";
}        

function stringToDate(strdate)
{
    var arr=strdate.split("/");
    var date=new Date();
    if (arr.length=3)
    {
        /*var mes =parseInt(arr[1]);
        date.setFullYear(arr[2]);
        date.setMonth(mes-1);
        date.setDate(arr[0]);*/
        date.setTime( Date.parse(arr[1]+"/"+arr[0]+"/"+arr[2]) );
        return date;
    }
    else
        return currentDate;
}
