	
///  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='ING';  //Idioma para cuando no exista el objeto
var pbCiudades;  //Zona de busqueda de Ciudades 0 = Todas
var espacios = '&nbsp;';
var existeArrayFormHTAV = false; var existeArrayFormSAV = false;
var tipConn=0;
function ajEnabledElem(elem,idioma){ 
	idioma = fdic.lang(idioma);
	try {		
		if (elem.disabled) { elem.disabled=false; } 
		if (elem.tagName == "INPUT") {
			var desc = fdic.trad(disLoading,idioma); 		
			desc = (desc.toLowerCase()== elem.value.toLowerCase())? '': elem.value;
			elem.value = desc;
		}
	}catch(ex) { }	
	return {Idioma:idioma};	
}

function New()
	{  //debugger;
		//Valida que arrayForm exista y que tenga valores. SE LLENA EN EL COMPONENTE!!! Ej.: arrayForm[0] = nombre de formulario
		
		//Nota:  Suponemos que 
		//posicion [0] =  Hotel + Avion (Leavingfrom, Ciudades, etc.)
		//posicion [1] =  Solo Avion    por Id (bLeavingfrom, bCiudades, bXXXX, etc...)
		
		var PaqTypeHTAV = "HTAV";  //valor de defualt
		var PaqTypeSAV = "??";  //valor de defualt (No existen)		
		var valPaqType = "??";  
		var tempObj;		
		var formNameSAV = "";
		var formNameHTAV ="";
		
		
		//debugger;
		if (ajExistsObj(typeof arrayForm)==true) {
				//Solo Avion			
				if (ajExistsObj(arrayForm[0])==true) {
					PaqTypeSAV = eval("document." + arrayForm[0] + ".PackageType.value"); existeArrayFormSAV = true;
				} 
				//Hotel + Avion	
				if (ajExistsObj(arrayForm[1])==true) {
					PaqTypeHTAV = eval("document." + arrayForm[1] + ".PackageType.value"); existeArrayFormHTAV = true;			
				} 
							
		} else {					
			//Barro los todos los Inputs para Buscar 
			for (var i=0; i<=document.forms.length -1; i++){
				Elementos = document.forms[i];  //.getElementsByTagName("input");
				for (var j=0; j<=Elementos.length-1; j++){
					if (Elementos[j].tagName.toLowerCase() == 'input') {
						if (Elementos[j].name == 'PackageType'){	//Busco PackaType define si (Hotel + Avion | Solo Avion)
							//tomo su valor del elemento
							switch (Elementos[j].value.toUpperCase()) {
								case "SAV":  //solo avion
										PaqTypeSAV = Elementos[j].value; formNameSAV = document.forms[i].name;
										j = Elementos.length-1;								 
										break;
								case "HTAV": //hotel + avion
										PaqTypeHTAV = Elementos[j].value; formNameHTAV = document.forms[i].name; 
										j = Elementos.length-1;
										break;
								default: 
							}									
						}
					}	
				}
			}						
		}		
		
		// ------------------------------------------------------------------------------------------														
		//                              LLENA COMBO DE AEREOPUERTO [ HOTEL + AVION ] leavingFrom
		// ------------------------------------------------------------------------------------------
		
		var CodeAirport; var Leavingfrom; //var ajaxOnA = true;
		
		if (existeArrayFormHTAV && PaqTypeHTAV.toUpperCase() == "HTAV") {			    		    
				    
			CodeAirport = eval("document." + arrayForm[1] + ".CodeAirport");
			Leavingfrom = eval("document." + arrayForm[1] + ".Leavingfrom");
		}
		else if(formNameHTAV != "" && PaqTypeHTAV.toUpperCase() == "HTAV")  {
			CodeAirport = eval("document." + formNameHTAV + ".CodeAirport");
			Leavingfrom = eval("document." + formNameHTAV + ".Leavingfrom");
			
		}else if(PaqTypeHTAV.toUpperCase() == "HTAV"){			
			CodeAirport = document.getElementById("CodeAirport");
			Leavingfrom = document.getElementById("Leavingfrom");
		}       
		if (CodeAirport!= null &&  Leavingfrom != null)	{			
			
			/// instanciamos la variable (x) para porder accesar a la clase AutoCompleteDataTable
			/// pasandole como paramatros nombre el input y TOP de registros.
			///AutoCompleteDataTable("input", 20  )
			
			var rReturn = ajEnabledElem(Leavingfrom,null);
			var pIdioma = rReturn.Idioma;
					
			if (Leavingfrom.tagName == "INPUT"){   //Si es Combo lo saco			
		        //return false;	
		        
					//Checo si tengo que llenar con ajax  'True:  Lleno con ajax;  False: Sin ajax        
					if (Leavingfrom.alt.toLowerCase() == "ajax.off")
						return false;
		       
					var ajaxA = new MS.Web.AutoCompleteDataTable(Leavingfrom, this.count );									
	                var ajaxAFiltroPais = document.getElementById("Pais"); //Pais del Navegador
                    if (ajExistsObj(ajaxAFiltroPais)==false) {
                        ajaxAFiltroPais = document.getElementById("zLeaving");	
                    }                   
					if (ajExistsObj(ajaxAFiltroPais)==true)
						ajaxAFiltroPais = ajaxAFiltroPais.value;
					else	
						ajaxAFiltroPais = '';
						
					/// Funcion que ejecuta el Procedimeinto del lado del servidor		
					ajaxA.getData = function() {	
						this.ele.style.background= "url('/_Lib/Images/indicator.gif') no-repeat right #FFFFFF";						
						AutoComplete.search_airport(this.ele.value, pIdioma, this.count, ajaxAFiltroPais,_ajaxPrintSQL,tipConn,this.callback.bind(this));
					}
					////despliega la lista de los valores en un div para su visualizacion
					/// se llena tantos Registros encuentre
					ajaxA.getDisplay = function(item,pos){
						var textDisp='';																			
						//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)
               						textDisp = (item != null ? item.Airport  : "");
               					}else {													
									if (item.Code.length>3)
										textDisp = (item != null ? item.CityName + " (" + item.Airport + ")" + " (" + item.Code + ") " : "");
									else
										textDisp = (item != null ? item.CityName + " (" + item.Code + ") " + " (" + item.Airport + ")" : "");
								}	
							} else {							
								textDisp = (item != null ?  item.CityName + " (" + item.Code + ") " + " (" + item.Airport + ")" : "");
							}																	
						} else { textDisp = ""; }
						return 	{Text1:(espacios + textDisp),Text2:'',Principal:0};
					}
					ajaxA.getImage = function (item,pos) {
						var Ruta = '';
						//Si Clav_Pais = ??  ó 00  No hay datos o Coincidencias			
						if (item != null)
							if (item.Clav_Pais == "??" || item.Clav_Pais == "00")
								Ruta = '';
							else
								Ruta = '/_lib/vimages/Flags/' + item.Clav_Pais + '.gif';						
						return {Imagen:Ruta,Width:16,Height:11};
					}
					/// obtiene los valores de los dataTable y los almacena el los input		
					ajaxA.getValue = function(item)	{	    
						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										
						}					
					}
			  }  
		}		      
				
	}	//FIN  NEW

//setTimeout(New,1);
//addEvent(window, "load", New); // el codigo Javascript no corre hasta que se descarguen todas las imagenes
//if (typeof $$ =='function') {	
var $j = jQuery.noConflict();
$j(document).ready(function(){New();}); // Revisa el documento y espera a que este listo para manipularlo
//} else {
	//addEvent(window, "load", New); 
//}		

	
	
	
