var tempo;

function initTempoTop() {
	tempo = setTimeout('ocultarMenuTop();', 500);
}

function resetTempoTop() {
	clearTimeout(tempo);
}

function verMenuTop (id) {
	ocultarMenuTop ();

	var trigger = $('#'+id).position();
	  var menu = $('#menu_dinamico_html');	
	  $('#div_menu_top').css("visibility","visible");
		$('#div_menu_top').show();

		
		var top = "95px";
		var left = "650px";
		
		if ( menu != null ) {
			menu.css({		
				'visibility': 'visible',
				'left': trigger.left - 25, 
				'top': trigger.top + 18,
				'display': 'block',
				'z-index': '1500'});		
		}	
	  
	}

function ocultarMenuTop () {
	$('#menu_dinamico_html').css("visibility","hidden");
	$('#div_menu_top').css("visiblity","hidden");
	$('#div_menu_top').hide();
}



function displayChat() {
	if($('#chat_izquierda')){
		if(location.pathname=="/" 
			|| location.pathname.indexOf("/index.do") >= 0
			|| location.pathname.indexOf("/menuBusquedaHoteles.do") >= 0
			|| location.pathname.indexOf("/menuBusquedaVuelos.do") >= 0
			|| location.pathname.indexOf("/index.jsp") >= 0 
			|| location.pathname.indexOf("/home.do") >= 0){
			$('#chat_izquierda').hide();
		} else {
			$('#chat_izquierda').show();
		}
	}
}

function cambiarTamanoFrames(height) {	
	$('#cuerpoCentro').height (height+'px');
}


function redirect() {

}

var mFootTempo;

function initTempoFooter() {
	mFootTempo=setTimeout('ocultarMenuFooter();', 500);
}

function resetTempoFooter() {
	clearTimeout(mFootTempo);
}


function verMenuFooter() {
	var menuFooter = $('#menu_dinamico_foot_html');
	var spanPosition = $(".final span").offset();
	
	menuFooter.css({
		'top' : spanPosition.top - menuFooter.height() - 16,
		'left' : spanPosition.left - 22,
		'display': 'block',
		'z-index': '1000'
	});
	menuFooter.show();	
			
}

function MM_preloadImages() {
	  var d=document; 
	  if(d.images){ 
	  	if(!d.MM_p) d.MM_p=new Array();
	    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; 
	    for(i=0; i<a.length; i++)
	    	if (a[i].indexOf("#")!=0){ 
	    		d.MM_p[j]=new Image; 
	    		d.MM_p[j++].src=a[i];
	    	}
	  }
}

function sendMailFromProduct(id, prod) {
	var action 	  = "../mailFromProducto/mailFromProducto_init.do";
	var params = "?method=init&idProducto=" + id + "&tipoProducto=" + prod;
	location.href = action+params;
}

var flechaUp='../img/flecha_up_azul.gif';

function openCloseAlternativa() {
	
	if($("a[name=mas_info]").length == 1) {
		var altId = '#' + $("a[name=mas_info]")[0].name + "_" + $("a[name=mas_info]")[0].id;
		var imgId = '#bullet_' + $("a[name=mas_info]")[0].name + "_" + $("a[name=mas_info]")[0].id;
		$(imgId).attr("src", flechaUp);
		$(altId).show("slow",function(){displayTrama();});
	}
}

var sBulletShow='../img/flecha_up_azul.gif';
var sBulletHide='../img/flecha_down_azul.gif';
var sBulletMasShow='../img/minimizar.gif';
var sBulletMasHide='../img/maximizar.gif';

function showHide(sId)
{
	var theDiv = window.document.getElementById(sId);
	var theBullet = window.document.getElementById('bullet_'+sId);
	var bShow = (theDiv.style.display=='none');
	if (bShow) {
		theDiv.style.display ='';
		theBullet.src = sBulletShow;
	
	}
	else{
		theDiv.style.display = 'none';
		theBullet.src = sBulletHide;
		
	}	
	displayTrama();
}

function showHideMas(sId)
{
	var theDiv = window.document.getElementById(sId);
	var theBullet = window.document.getElementById('bullet_'+sId);
	
	if( $(theDiv).css('display') == 'none' ) {
	    $(theDiv).show();
	    theBullet.src = sBulletMasShow;
	} else{
	    $(theDiv).hide();
	    theBullet.src = sBulletMasHide;
	}
	displayTrama();
}




function include  (fileSrc) {	
	if (!isIncluded (fileSrc) ) {
		//alert ("include: " + fileSrc);
		$.include (fileSrc);	
	}
}

function isIncluded (fileSrc) {
	var head = document.getElementsByTagName("head")[0].innerHTML;
	var pattern = new RegExp (fileSrc);
	return pattern.test(head);
}

function isExplorer () {
	return $.browser.msie;
}

function isMozilla () {
	return $.browser.mozilla;    
}

function isChrome () {
	return $.browser.webkit;
}
function abrirURL (URL) {
	location.href = URL;
}

function ocultarMenuFooter () {
	$("#menu_dinamico_foot_html").hide();
}
/*
function callAction(action) {
	
	if ( location.protocol.indexOf('https') > -1) {
		if(action.indexOf('?') == -1){
			action += '?usingProtocol=https';
		} else {
			action += '&usingProtocol=https';
		}
	}
	//location.href = location.protocol + "//" + location.hostname + ":" +  location.port + action;
	location.href = action;
}
 */
 function appendParamToForm(idForm, param) {
	 
	 if($('#'+idForm).attr('action').indexOf('?') == -1){
		 $('#'+idForm).attr('action', $('#'+idForm).attr('action')+'?'+param);
	 }else{
		 $('#'+idForm).attr('action', $('#'+idForm).attr('action')+'&'+param);
	 }
	 
 }
 
 
 function addParam(link, param) {
	 if( link.indexOf('?') == -1 ){
		 link+='?'+param;
	 }else{
		 link+='&'+param;
	 }
	 return link;
 }
function clickIttLinks(link) {
	
	if(link.charAt(0)=='/') {
		link = '..' + link;
	}
	if( location.protocol.indexOf('https') > -1) {
		link = addParam( link, 'usingProtocol=https')
	}
	if( $("#iFrameCentro").length > 0 ){
		link = addParam(link, 'rss=true');
	}
	
	location.href = link;
}
function checkAndSubmitForm(idForm) {
	
	var action = $('#'+idForm).attr('action');
	
	if( location.protocol.indexOf('https') > -1) {
		action=addParam( action, 'usingProtocol=https');
	}
	if( $("#iFrameCentro").length > 0 ){
		action=addParam( action, 'rss=true');
	}
	$('#'+idForm).attr('action', action);
	$('#'+idForm).submit();
	
}


function displayUser(nombreUsuario){
	var user = $('#nombreUser').text();
	$('#nombreUser').text(nombreUsuario);
	if(user != nombreUsuario){
		if(user == ''){
			$('#nombreTop').css('visibility', 'visible');
		} else {
			$('#nombreTop').css('visibility', 'hidden');
		}
	}
}


/*var userAgent = navigator.userAgent.toLowerCase();
	jQuery.browser = {
	    version: (userAgent.match( /.+(?:rv|it|ra|ie|me)[\/: ]([\d.]+)/ ) || [])[1],
	    chrome: /chrome/.test( userAgent ),
	    safari: /webkit/.test( userAgent ) && !/chrome/.test( userAgent ),
	    opera: /opera/.test( userAgent ),
	    msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
	    mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
	};
*/
	//Example
	//$.browser.mozilla returns true if mozilla
	//jQuery.browser.version.substr(0,3) returns "6.0", "7.0" or "8.0", useful for IE
	
function displayTrama(){
	
	if(location.pathname !="/" 
		&& location.pathname.indexOf("/index.do") < 0
		&& location.pathname.indexOf("/menuBusquedaHoteles.do") < 0
		&& location.pathname.indexOf("/menuBusquedaVuelos.do") < 0
		&& location.pathname.indexOf("/index.jsp") < 0
		&& location.pathname.indexOf("/home.do") < 0){
		
			var height = $('div#cuerpo').height() - ($('#cuerpoIzquierda').height());
			
			if( $('#chat_izquierda').css('visibility') == 'visible' ) {
				height -= ($('#chat_izquierda').height()+5);
			}
			
			height -= 10;
			
			if ($.browser.msie) {
				height -= 55 ;
			} else {
				height -= 5 ;
			}
			
			if( height > 2) {
				$('#trama_box').height(height);
				$('#trama_box').css('visibility', 'visible');
			} else {
				$('#trama_box').css('visibility', 'hidden');
			}
	}
	
}

function focusInOut(array){
	$.each(array, function(index, elem){
		$('#'+elem).focus(function(){
			$(this).css('border', 'orange solid 1px');
			//$(this).addClass("focus");  si utilizas (outline: orange solid 1px);
		});
		$('#'+elem).blur(function(){
			$(this).css('border', '#cfc9c8 solid 1px');
		});
	});
	$('#'+array[0]).focus();
}

function clearForm(form) {
	/*
	$('.hasDatepicker').each(function(){
		$(this).datepicker('option', 'minDate', '0');
		$(this).datepicker('setDate', '0');
	});
	*/
	$(':input', '#'+form).not(':button, :reset, :submit, .hasDatepicker').val('')
			.removeAttr('checked').removeAttr('selected');
}

function buscador_costa()
{
 width=640;
    height=620;
    var left = Math.floor( (screen.width - width) / 2);
    var top = Math.floor( (screen.height - height) / 2)-20;
    var winParms = "top=" + top + ",left=" + left + ",height=" + height + ",width=" + width+", resizable=yes, scrollbars=yes, status=no";
    //produccion
    //window.open("http://www.cruisengine.com/BookingEngine/partners/es-AR/Step1a?Key=sfSRtpaPy9J9bV%2bHkSTTTRehLvos0%2f0qYSf%2bPFOQ9Og%3d", "costa", winParms); //microcentro
    window.open("http://www.cruisengine.com/BookingEngine/partners/es-AR/Step1a?Key=R99Lb3WTdNTxMslGxxD%2fZ6FMCKskr7OvvxRtJhsHRfM%3d", "costa", winParms); //casa central
    
    //test
    //window.open("http://test.cruisengine.com/BookingEngine/partners/es-AR/Step1a?Key=R99Lb3WTdNTxMslGxxD%2fZ6FMCKskr7OvvxRtJhsHRfM%3d", "costa", winParms); //casa central
}

