/*
 * @autor: Raul Yahtnel
 * company: PanamaCOM
 * Date: 7/7/2009
 */
 

//FUNCION PARA COLOCAR FOCO A LOS CAMPOS
function ShowFocus(elemento){
	elemento.style.border = "1px solid #000000";
}

//FUNCION PARA QUITAR FOCO A LOS CAMPOS
function notFocus(elemento){
	elemento.style.border = "1px solid #A5ACB2";
}

//MUESTRA ELEMENTOS DEL DOM DE HTML QUE GUERON OCULTADOS
function ShowElement(id){
	$("#"+id).show('slow');
}

//OCULTA ELEMENTOS DEL DOM DE HTML
function HiddenElement(id){
	$("#"+id).hide('slow');
}
function cleanList(ident){
	$(ident).removeOption(/./);
}
function getListDestinations(msjload, msj, de)
{
	/*Inicializa la lista de subcategoria*/
	cleanList('#hacia');
	$('#hacia').attr("disabled","disabled");
	$.ajax({
				beforeSend: function(){
					$('#hacia').attr("disabled","");
					$("#hacia").addOption("0",msjload);
				},
				async: true,
				type: "POST",
				contentType: "application/x-www-form-urlencoded",
				url: "rutas/ctrlRutas.php",
				data: "opt=1&origen="+de,
				dataType: ($.browser.msie) ? "text" : "xml",
				cache: false,
				success: function(data){
					var xml;
					  if (typeof data == 'string') {
						xml = new ActiveXObject("Microsoft.XMLDOM");
						xml.async = false;
						xml.loadXML(data);
					  } else {
						xml = data;
					  }
					cleanList("#hacia");
					flag=true;
					$('item',xml).each(function(){
						   var id = $(this).find('codigo').text();
						   var nombre = $(this).find('nombre').text();
						   $("#hacia").addOption(id,nombre,false);
						   if(id=="DAVID")
						   {
							   $("#hacia").selectOptions(id);
							   flag=false;
							   getIntinerary(id,de,'',msjload);
							   getIntineraryReturn(id,de,'',msjload);
							   $("#diaf").attr("disabled","disabled"); 
						   }
						   if(flag)
						   {
							   $("#hacia").selectOptions(id);
							   flag=false;
							   getIntinerary(id,de,'',msjload);
							   getIntineraryReturn(id,de,'',msjload);
							   $("#diaf").attr("disabled","disabled"); 
						   }
						 }); 
				},
			   error:function(objeto, quepaso, otroobj){
		            alert("Estas viendo esto por que fallé");
		            alert("Pasó lo siguiente: "+quepaso + objeto);
		        },
		        global: true,
		        ifModified: false,
		        processData:true
			});
}

function getListOrigin(msjload, msj)
{
	var de= $("#de").val();
	/*Inicializa la lista de subcategoria*/
	cleanList('#de');
	//$('#de').addOption("0", msj);
	$('#de').attr("disabled","disabled");
	/*Fin*/
	$.ajax({
				beforeSend: function(){
					$('#de').attr("disabled","");
					$("#de").addOption("0",msjload);
				},
				async: true,
				type: "POST",
				contentType: "application/x-www-form-urlencoded",
				url: "rutas/ctrlRutas.php",
				data: "opt=3",
				dataType: ($.browser.msie) ? "text" : "xml",
				cache: false,
				success: function(data){
					var xml;
					  if (typeof data == 'string') {
						xml = new ActiveXObject("Microsoft.XMLDOM");
						xml.async = false;
						xml.loadXML(data);
					  } else {
						xml = data;
					  }
					cleanList("#de");
					$('item',xml).each(function(){
						   var id = $(this).find('codigo').text();
						   var nombre = $(this).find('nombre').text();
						   $("#de").addOption(id,nombre,false);
						   if(id=="PANAMA-Albrook")
						   {
							   $("#de").selectOptions(id);
						   }
						 }); 
				},
			   error:function(objeto, quepaso, otroobj){
		            alert("Estas viendo esto por que fallé");
		            alert("Pasó lo siguiente: "+quepaso + objeto);
		        },
		        global: true,
		        ifModified: false,
		        processData:true
			});
}

function getIntinerary(hacia,desde,mes,msjload)
{
	$('#diai').attr("disabled","disabled");
	cleanList("#diai");
	$("#diai").addOption("0",msjload);
	$.ajax({
		beforeSend: function(){
			$('#diai').attr("disabled","");
			$("#diai").addOption("0",msjload);
		},
		async: true,
		type: "POST",
		contentType: "application/x-www-form-urlencoded",
		url: "rutas/ctrlRutas.php",
		data: "opt=2&destino="+hacia+"&origen=" + desde + "&mes="+mes,
		dataType: ($.browser.msie) ? "text" : "xml",
		cache: false,
		success: function(data){
			var xml;
			  if (typeof data == 'string') {
				xml = new ActiveXObject("Microsoft.XMLDOM");
				xml.async = false;
				xml.loadXML(data);
			  } else {
				xml = data;
			  }
			cleanList("#diai");
			$('item',xml).each(function(){
				   var id = $(this).find('codigo').text();
				   var nombre = $(this).find('nombre').text();
				   $("#diai").addOption(id,nombre,false);
				 }); 
		},
	   error:function(objeto, quepaso, otroobj){
            alert("Estas viendo esto por que fallé");
            alert("Pasó lo siguiente: "+quepaso + objeto);
        }
	});
}
function getIntineraryReturn(hacia,desde,mes,msjload)
{
	$('#diaf').attr("disabled","disabled");
	cleanList("#diaf");
	$("#diaf").addOption("0",msjload);
	$.ajax({
		beforeSend: function(){
			$('#diaf').attr("disabled","");
			$("#diaf").addOption("0",msjload);
		},
		async: true,
		type: "POST",
		contentType: "application/x-www-form-urlencoded",
		url: "rutas/ctrlRutas.php",
		data: "opt=2&destino="+hacia+"&origen=" + desde + "&mes="+mes,
		dataType: ($.browser.msie) ? "text" : "xml",
		cache: false,
		success: function(data){
			var xml;
			  if (typeof data == 'string') {
				xml = new ActiveXObject("Microsoft.XMLDOM");
				xml.async = false;
				xml.loadXML(data);
			  } else {
				xml = data;
			  }
			cleanList("#diaf");
			$('item',xml).each(function(){
				   var id = $(this).find('codigo').text();
				   var nombre = $(this).find('nombre').text();
				   $("#diaf").addOption(id,nombre,false);
				 }); 
		},
	   error:function(objeto, quepaso, otroobj){
            alert("Estas viendo esto por que fallé");
            alert("Pasó lo siguiente: "+quepaso + objeto);
        }
	});
}