var envia=0;
function findValue(li) {
	if( li == null ){
		var valor = $('#destino').val();
		var txt='Destino no encontrado, le invitamos a escribir otro destino';
		if(valor == '' || valor=='Escriba el nombre del destino' ){
			txt='Por favor escriba un destino';
		}
		alert(txt);
		return $('#destino').focus();
	}
	else{
		if( !!li.extra ){ 
			var sValue = li.extra[0];
		}
		else {
			var sValue = li.selectValue;
		}
		valores=sValue.split("-");
		destino=valores[0];
		zona=valores[1];
		document.getElementById('forma_busqueda').action="http://www.mexicohoteles.com.mx/"+destino+"/";
		document.getElementById('dest').value=zona;
		if(envia == 0){
			$('#envia_bus').focus();
		}
		else{
			$('#forma_busqueda').submit();
		}
	}
}

function selectItem(li) {
	envia=0;
	findValue(li);
}

function formatItem(row) {
	valor=row[0];
	encuentra=valor.indexOf(',');
	if (encuentra != -1){
		val=valor.split(', ');
		return '<strong>'+val[0]+'</strong>, <span>'+val[1]+'</span>';
	}
	else{
		return '<strong>'+valor+'</strong> <span class="todos">'+row[2]+'<span>';
	}
}

function lookupAjax(){
	envia=1;
	var oSuggest = $("#destino")[0].autocompleter;
	oSuggest.findValue();
	return false;
}
$(document).ready(function() {
	$("#destino").autocomplete(
		"/search_destino.php",
		{
			delay:10,
			minChars:3,
			matchSubset:1,
			width:"300px",
			matchContains:1,
			cacheLength:0,
			onItemSelect:selectItem,
			onFindValue:findValue,
			formatItem:formatItem,
			selectFirst:true
		}
	);
	$("#destino").focus(function (){
		valor = $('#destino').val();
		if(valor=='Escriba el nombre del destino'){
			$('#destino').val('');
			$("#destino").css({'font-style':'normal','color':'#333333'})
		}
	});
	$("#destino").blur(function (){
		valor = $('#destino').val();
		if(valor==''){
			$("#destino").css({'font-style':'italic','color':'#999999'})
			$('#destino').val('Escriba el nombre del destino');
		}
	});
	$('#ayuda_b').click(function (){
		if ($('#ayuda').is (':visible')){
			$('#ayuda').hide('slow');
		}
		else{
			$('#ayuda').show('slow');
		}
		
	});
	$('#ayuda .cerrar').click(function (){
		$('#ayuda').hide('slow');
	});
	$('#ayuda div').click(function (){
		$('#ayuda').hide('slow');
	});

	$('#muesta_telefonos').click( function (){
		if ($('#div_telefonos').is (':visible')){
			$('#div_telefonos').hide('slow');
		}
		else{
			$('#div_telefonos').show('slow');
		}
	});

	$('#muesta_telefonos').hover(function (){
		$('#div_telefonos').show('slow');
	},function (){});

	$('#menu_telefonos').hover(function (){},function (){
		if ($('#div_telefonos').is (':visible')){
			$('#div_telefonos').hide('slow');
		}
	});
	$('#div_telefonos').hover( function(){} ,function (){
		$('#div_telefonos').hide('slow');
	})



});

function ver_form_reserva(){
	var usuario = $('#r_usuario').val();
	var password = $('#r_pass').val();
	if(usuario == '' || password == ''){
		alert('Ingrese Usuario y Contaseņa');
		return false;
	}
	else{
		return true;
	}
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
