
///  setTimeout(this.getData.bind(this), this.waitAfterInput);
//// setTimeout Method
//// Evaluates an expression after a specified number of milliseconds has elapsed. 
//// setTimeout(,0);	 
//// iTimerID = window.setTimeout(vCode, iMilliSeconds [, sLanguage])


//// vCode			Required. Variant that specifies the function pointer or string that indicates the code to be executed when the specified interval has elapsed.
//// iMilliSeconds	Required. Integer that specifies the number of milliseconds.
//// sLanguage		Optional. String that specifies one of the following values:
//// 				JScript	Language is JScript.
//// 				VBScript	Language is VBScript.
//// 				JavaScript	Language is JavaScript.

var pIdioma;  //Idioma para cuando no exista el objeto
var pbCiudades;  //Zona de busqueda de Ciudades 0 = Todas
var SimbDatos = '-?-';  //Consulta No Regreso Coincidencias

function New()
	{
			
		// ------------------------------------------------------------------------------------------														
		//                              LLENA COMBO DE AEREOPUERTO
		// ------------------------------------------------------------------------------------------
		
		var CodeAirport = document.getElementById("CodeAirport");
		var Leavingfrom = document.getElementById("Leavingfrom");
		
		if (CodeAirport!= null)	{
			//CodeAirport.value="";	
			/// instanciamos la variable (x) para porder accesar a la clase AutoCompleteDataTable
			/// pasandole como paramatros nombre el input y TOP de registros.
			///AutoCompleteDataTable("input", 20  )
					
			if (Leavingfrom.tagName != "INPUT")   //Si es Combo lo saco
		        return false;	
			
			var y = new MS.Web.AutoCompleteDataTable("Leavingfrom", this.count );
					
			/// Funcion que ejecuta el Procedimeinto del lado del servidor		
			y.getData = function()
			{	
				this.ele.style.background= "url('/_Lib/Images/indicator.gif') no-repeat right";
				var Idioma = document.getElementById("Idioma");	
				if ( Idioma ==null)
					pIdioma = "ing";  //si viene en nulo le asigno un defualt
				else
					pIdioma = Idioma.value;  //Idioma del Objeto 
				AutoComplete.search_airport(this.ele.value, pIdioma, this.count, this.callback.bind(this));
			}
			
			////despliega la lista de los valores en un div para su visualizacion
			/// se llena tantos Registros encuentre	
				
			y.getDisplay = function(item,pos)
			{	
				//var Filtro = item.Clav_Pais;
				var Ruta;
				this.ele.style.background= ""; 
												
				//Cuando Realmente no hay Datos Mando "??"
				
				//Clav_Pais Valores Regreso en Consulta:   
                //				    00 =(No tiene clave de Pais)
                //			    Dif 00 =(Tiene Pais y pone su banderita)
                //				    ?? =(No hay datos (Con Mensaje Personalizado) )
               	
               	if (item != null) {                		
					if( item.Clav_Pais != "00") //Si COD. Pais 
					{
						if( item.Clav_Pais == "??") { //No coincidencias (No Resultados)
               				return (item != null ? item.Airport  : "");
               			}else {
							Ruta ="<img src='/_lib/vimages/Flags/" + item.Clav_Pais + ".gif'>&nbsp;";
							if (item.Code.length>3)
								return (item != null ? Ruta + item.CityName + " (" + item.Airport + ")" + " (" + item.Code + ") " : "");
							else
								return (item != null ? Ruta + item.CityName + " (" + item.Code + ") " + " (" + item.Airport + ")" : "");
						}	
					} else {			
						Ruta="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";					    
						return (item != null ?  Ruta + item.CityName + " (" + item.Code + ") " + " (" + item.Airport + ")" : "");
					}
				
									
				} else {
					return "";
				}
								
			}
			 
			/// obtiene los valores de los dataTable y los almacena el los input		
			y.getValue = function(item) 
			{	
				//debugger;			    
				if (item != null) {
					if (item.Status == SimbDatos) {
						CodeAirport.value = "";  //limpio la variable
						return item.Status;		//Regreso el estatus
					} else {							    
						CodeAirport.value = item.Code; //paso su codigo de aeropuerto
						//Cuando no hay ningun concidencia de Aeropuertos
						if( item.Clav_Pais == "??")
							return (item != null ?  item.Airport: ""); //Mensaje de no datos
						else 
							return (item != null ? item.CityName + " (" + item.Code + ") " + " (" + item.Airport + ")" : "");
					}
				} else {					
					if (this.ele.value != "")
						return ""; //forzo a tomar su propio valor que tenia
					else 
						return SimbDatos;     //forzo que tome Mensaje Inicial
										
				}
					
			}			
		}//if (CodeAirport!= null)	{

        	// ------------------------------------------------------------------------------------------														
		//                              LLENA COMBO DE HOTEL #1
		// ------------------------------------------------------------------------------------------
		
		var Clav_Hotel = document.getElementById("Clav_Hotel");		
		var Nombre = document.getElementById("Nombre");	//Si existe nombre 		
		
		if (Clav_Hotel!= null && Nombre !=null)	{						
		    if (Nombre.tagName != "INPUT") 
		        return false;			
			var x = new MS.Web.AutoCompleteDataTable("Nombre", this.count );
					
			/// Funcion que ejecuta el Procedimeinto del lado del servidor		
			x.getData = function()
			{
				this.ele.style.background= "url('/_Lib/Images/indicator.gif') no-repeat right";
				var Ruta_Imagen  =	document.getElementById("Ruta_Imagen");	
				var tipo_categoria = document.getElementById("tipo_categoria"); //Imagen de la categoria Estrellas o Maletas								
				var Idioma = document.getElementById("Idioma");	
				if ( Idioma ==null)
					pIdioma = "ing";  //si viene en nulo le asigno un defualt
				else
					pIdioma = Idioma.value;  //Idioma del Objeto 
				var Cuidad  =	document.getElementById("Clav_ciudad");
				
				
				if (Cuidad!=null)
					AutoComplete.search_hotel(this.ele.value, Ruta_Imagen.value, pIdioma, Cuidad.value, this.count, tipo_categoria.value, this.callback.bind(this));
				else
					AutoComplete.search_hotel(this.ele.value, Ruta_Imagen.value, pIdioma, '', this.count, tipo_categoria.value, this.callback.bind(this));
			}
			
			////despliega la lista de los valores en un div para su visualizacion
			/// se llena tantos Registros encuentre		
			x.getDisplay = function(item,pos)
			{							
				//var Filtro = item.Clav_Categoria;
				var Ruta_Imagen = document.getElementById("Ruta_Imagen");				
				var tipo_categoria; //Imagen de la categoria Estrellas o Maletas				
				var Idioma = document.getElementById("Idioma");	
				
				//debugger;
				//si no existe el hidden tomo estrellas
				if (document.getElementById("tipo_categoria") == null || document.getElementById("tipo_categoria").value == "ES")
				    tipo_categoria= "StarsSmall_";  //Categoria  de estrellas
				else
				    tipo_categoria= "CategSmall_";  //Categoria  de maletas
				 				
				if ( Idioma ==null)
					pIdioma = "ing";  //si viene en nulo le asigno un defualt
				else
					pIdioma = Idioma.value;  //Idioma del Objeto 		
				this.ele.style.background= "";
				
				if(item.Clav_Categoria!=null){
					Ruta = '';
					if (item.Clav_Categoria=='')
						return (item != null ? item.Nombre_Hotel  : "");
					else
											
						/*Ruta ='<img id="ImgEvent" src="' + Ruta_Imagen.value + '/' + tipo_categoria +  item.Clav_Categoria + '_' + pIdioma + '.gif" align="absbottom" />';
						alert(Ruta);
						var itemChild = this.div.childNodes[pos];
						var itemChildImg = document.createElement(Ruta);
												
						itemChild.appendChild(itemChildImg);						
						
						Ruta = '';
						//itemChildImg.setAttribute("id",'ImgItem');
						//itemChildImg.setAttribute("src",Ruta_Imagen.value + "/" + tipo_categoria +  item.Clav_Categoria + "_" + pIdioma + ".gif");							
						//itemChildImg.setAttribute("align",'absbottom');
						
						addEvent(itemChildImg, "mouseover", this.onmouseover.bind(this));
						addEvent(itemChildImg, "click", this.onclick.bind(this));
												
						return (item != null ? Ruta + item.Nombre_Hotel  : "");	*/											
						
						Ruta ="<img id='ImgEvent' src='" + Ruta_Imagen.value + "/" + tipo_categoria +  item.Clav_Categoria + "_" + pIdioma + ".gif' align='absbottom'>&nbsp;&nbsp;";
						return (item != null ? Ruta + item.Nombre_Hotel  : "");												
				}
				else	
					return (item != null ? item.Nombre_Hotel  : "");


			}
			 
			/// obtiene los valores de los dataTable y los almacena el los input		
			x.getValue = function(item) 
			{	
				if (item != null) {	
					if (item.Status == SimbDatos)
						return item.Status;		//Regreso el estatus (NO Datos)
					else			
						return (item != null ? item.Nombre_Hotel.toString().trimRight() : "");
				}else {
					if (this.ele.value != "")
						return "";			//forzo a tomar su propio valor que tenia
					else 
						return SimbDatos;	//forzo que tome Mensaje Inicial
				}
			}
		}	

// ------------------------------------------------------------------------------------------														
		//                              LLENA COMBO DE HOTEL  #2
		// ------------------------------------------------------------------------------------------
		
		var Clav_Hotel2 = document.getElementById("_Clav_Hotel");
		var Nombre2 = document.getElementById("_Nombre");	//Si existe nombre 
		if (Clav_Hotel2!= null && Nombre2 !=null)	{						
			if (Nombre.tagName != "INPUT") 
		        return false;			
			var x = new MS.Web.AutoCompleteDataTable("_Nombre", this.count );					
			/// Funcion que ejecuta el Procedimeinto del lado del servidor		
			x.getData = function()
			{
				this.ele.style.background= "url('/_Lib/Images/indicator.gif') no-repeat right";
				var Ruta_Imagen  =	document.getElementById("Ruta_Imagen");	
				var tipo_categoria = document.getElementById("tipo_categoria"); //Imagen de la categoria Estrellas o Maletas								
				var Idioma = document.getElementById("Idioma");	
				if ( Idioma ==null)
					pIdioma = "ing";  //si viene en nulo le asigno un defualt
				else
					pIdioma = Idioma.value;  //Idioma del Objeto 
				var Cuidad  =	document.getElementById("Clav_ciudad");
				
				
				if (Cuidad!=null)
					AutoComplete.search_hotel(this.ele.value, Ruta_Imagen.value, pIdioma, Cuidad.value, this.count, tipo_categoria.value, this.callback.bind(this));
				else
					AutoComplete.search_hotel(this.ele.value, Ruta_Imagen.value, pIdioma, '', this.count, tipo_categoria.value, this.callback.bind(this));
			}
			
			////despliega la lista de los valores en un div para su visualizacion
			/// se llena tantos Registros encuentre		
			x.getDisplay = function(item,pos)
			{							
				//var Filtro = item.Clav_Categoria;
				var Ruta_Imagen = document.getElementById("Ruta_Imagen");				
				var tipo_categoria; //Imagen de la categoria Estrellas o Maletas				
				var Idioma = document.getElementById("Idioma");	
				
				//debugger;
				//si no existe el hidden tomo estrellas
				if (document.getElementById("tipo_categoria") == null || document.getElementById("tipo_categoria").value == "ES")
				    tipo_categoria= "StarsSmall_";  //Categoria  de estrellas
				else
				    tipo_categoria= "CategSmall_";  //Categoria  de maletas
				 				
				if ( Idioma ==null)
					pIdioma = "ing";  //si viene en nulo le asigno un defualt
				else
					pIdioma = Idioma.value;  //Idioma del Objeto 		
				this.ele.style.background= "";
				if(item.Clav_Categorias !=null  ){
					Ruta ="<img src='" + Ruta_Imagen.value + "/" + tipo_categoria +  item.Clav_Categoria + "_" + pIdioma + ".gif' align='absbottom'>&nbsp;&nbsp;";
					return (item != null ? Ruta + item.Nombre_Hotel  : "");												
				}
				else	
					return (item != null ? item.Nombre_Hotel  : "");


			}
			 
			/// obtiene los valores de los dataTable y los almacena el los input		
			x.getValue = function(item) 
			{	
				if (item != null) {				
					if (item.Status == SimbDatos)
						return item.Status;  //Regreso el estatus (NO Datos)
					else
						return (item != null ? item.Nombre_Hotel.toString().trimRight() : "");
				} else {
					if (this.ele.value != "")
						return "";			//forzo a tomar su propio valor que tenia
					else 
						return SimbDatos;	//forzo que tome Mensaje Inicial
				}	
			}
		}
			
		
		// ------------------------------------------------------------------------------------------														
		//                              LLENA COMBO DE CIUDADES
		// ------------------------------------------------------------------------------------------
		
		var ciudad_list = document.getElementById("ciudades_list");		
		if (ciudad_list!= null)	
		{				
			var Clave_ciudad = document.getElementById("Clav_ciudad");		
			if (Clave_ciudad!= null)	
			
			{			
				var x = new MS.Web.AutoCompleteDataTable("ciudades", this.count);					
				/// Funcion que ejecuta el Procedimeinto del lado del servidor		
				x.getData = function()
				{
					this.ele.style.background= "url('/_Lib/Images/indicator.gif') no-repeat right";
					var Idioma = document.getElementById("Idioma");	
				    if ( Idioma ==null)
					    pIdioma = "ing";  //si viene en nulo le asigno un defualt
				    else
					    pIdioma = Idioma.value;  //Idioma del Objeto 
					//Tomara la Ciudades segun sitio    			
					var pbCiudad  =	document.getElementById("pbCiudades");
					if ( pbCiudad ==null)
					    pbCiudades = 0;  //si viene en nulo le asigno un defualt
				    else
					    pbCiudades = pbCiudad.value;  //Idioma del Objeto 
										    				    
				    var radio = $("RadioH");
					var clasif = '';									
				    if (radio != null) //Si existe
				    {	
				        var obj2 = $("TemaH");
				        if (obj2 != null) { //Si existe 				        				        				    
				            if (BuscadorSelect = 2 && radio.checked==true)
			                    clasif  = $("TemaH").value;  
			                else	 
			                    clasif  = $("TemaHF").value; 						        
				        }
				    }
				    				
					AutoComplete.search_ciudades(this.ele.value , pIdioma, pbCiudades,  this.count, clasif, this.callback.bind(this));
				}
				
				////despliega la lista de los valores en un div para su visualizacion
				/// se llena tantos Registros encuentre		
				x.getDisplay = function(item,pos)
				{								
					this.ele.style.background= "";											
					return (item != null ? item.nombre_ciudad_real  : "");	

				}
				 
				/// obtiene los valores de los dataTable y los almacena el los input		
				x.getValue = function(item) 
				{	
					//debugger;								
					if (item != null) {
						if (item.Status == SimbDatos) {
							Clave_ciudad.value = "";	//Limpio la clave de ciudad oculta
							return item.Status;			//Regreso el estatus (NO Datos)
						}else {
							Clave_ciudad.value = item.clav_iata;													
							return (item != null ? item.nombre_ciudad_real.toString().trimRight() : "");
						}	
					} else {
						if (this.ele.value != "")
							return "";			//forzo a tomar su propio valor que tenia
						else 
							return SimbDatos;	//forzo que tome Mensaje Inicial
					}	
				}
		    }
		}		
	}	

//setTimeout(New,1);		
addEvent(window, "load", New);