


function post(url, params) 
{
	var temp=document.createElement("form");
	temp.action=url;
	temp.method="POST";
	temp.style.display="none";
	for(var x in params) {
		var opt=document.createElement("textarea");
		opt.name=x;
		opt.value=params[x];
		temp.appendChild(opt);
	}
	document.body.appendChild(temp);
	temp.submit();
	return temp;
}



//create and show
function openLightbox(requestUri, width, preLoadContent, isBooking, innerWrap)
{

  //undefined paramss
  if ('undefined' == typeof(preLoadContent)) preLoadContent = '';    
  if ('undefined' == typeof(isBooking)) isBooking = false;    
  if ('undefined' == typeof(innerWrap)) innerWrap = '.lb';

  //remove previous
  if (!isBooking) {
    $('.lbw,.lbo').remove();
  }  
  
  //create lightobx
  if (0 == $('.lbw').length) 
  {
    var lbc = $('<div class="lbw"><div class="lb">'+preLoadContent+'</div></div><div class="lbo"></div>');
    $('body').append(lbc);  	
  }

  var lbw = $('.lbw');
  var lbo = $('.lbo');  
   
  //hide scroll
  if (!isBooking)
    $('html').css('overflow','hidden');  
  
  var arrPageSizes = ___getPageSize();	
  
  // Style overlay and show it
	lbo.css({width:arrPageSizes[0], height: arrPageSizes[1]});  
  if ($.browser.msie)
    lbo.show();    
  else
    lbo.fadeIn('fast');        
    
  if ('undefined' != typeof(width))
    lbw.find('.lb').css('width', width+'px');    
    
  // Calculate top and left offset for the jquery-lightbox div object and show it
  var arrPageScroll = ___getPageScroll();
	//lbw.css({ top:	arrPageScroll[1] + (arrPageSizes[3] / 10), left:	arrPageScroll[0] }).show();
	lbw.css({ top:	50, left:	arrPageScroll[0] }).show();
  
  //load uri or div content
  if ( -1 == requestUri.indexOf('/') && $('#'+requestUri).length>0 )
    lbw.find('.lb').html ( $('#'+requestUri).html() );
  else if (isBooking)
    lbw.find('#book_process').load(requestUri);
  else
    lbw.find(innerWrap).load(requestUri);

  //style lightbox scroll
  $('.lb-scroll').animate({height: arrPageSizes[3]*(0.75)+'px'});

  //go top 
  $('html, body').animate({ scrollTop: 0 }, 100);
    
}




//show html-defined lightbox
function showLightbox(width)
{

  var lbw = $('.lbw');
  var lbo = $('.lbo');
  
  
  var arrPageSizes = ___getPageSize();	
  
  // Style overlay and show it
	lbo.css({width:arrPageSizes[0], height: arrPageSizes[1]});  
  if ($.browser.msie)
    lbo.show();    
  else
    lbo.fadeIn('fast');    
    

  if ('undefined' != typeof(width))
    lbw.find('.lb').css('width', width+'px');
    
  // Calculate top and left offset for the jquery-lightbox div object and show it
  var arrPageScroll = ___getPageScroll();
	lbw.css({ top:	arrPageScroll[1] + (arrPageSizes[3] / 10), left:	arrPageScroll[0] }).show();
    
}


//expand overlay to fit page
function expandLBOverlay() 
{  
  var arrPageSizes = ___getPageSize();	    
	$('.lbo').css({width:arrPageSizes[0], height: arrPageSizes[1]});  
}



function closeLightbox() 
{
  //alert('close');
  /*
  $('.lbw').hide();
  $('.lbo').hide();
  */
  $('html').css('overflow','');
  $('.lbw').remove();
  $('.lbo').remove();
}



/** abrir páginas como términos, política, aviso legal... **/
function openLBPage(url)
{
  openLightbox(url, 800, 
    '<div class="lb-close"></div> \
     <div class="lb-scroll">'+$('#update_loading').html()+'</div> \
     <div class="clear"></div>', false, '.lb-scroll');
}



function showFormTooltip(inputId, title, content)
{
  
  var tooltip = $('#f_tooltip');
  var input = $('#'+inputId);
  
  //create tooltip
  if (0 == tooltip.length) 
  {
    var tooltip = $('<div id="f_tooltip"><span class="peak ie6fix"></span><div class="content"><div class="title"><strong>'+title+'</strong></div><p>'+content+'</p></div></div>');
    $('body').append(tooltip);  	
  }
  
  //insert content
  /*
  tooltip.find('.title strong').html(title);    
  tooltip.find('p').html(content);      
  */
  var content = $('.tooltip_content[rel='+inputId+']').html();
  tooltip.find('.content').html( content );
  
  //show tooltip
  var offset = input.offset();
  var ox = offset.left + 245;
  var oy = offset.top - 23;        
  tooltip.attr('rel',inputId).css({'left':ox+'px', 'top':oy+'px'}).show();    
  
}



function showTooltip(selector, content, w, h)
{
  var tooltip = $('#tooltip');
  
  if (typeof(selector)!='object')
    var input = $(selector);
  else
    input = selector;
  
  //alert('tooltip2:'+content);    
    
  //create tooltip
  if (0 == tooltip.length) 
  {
    var tooltip = $('<div id="tooltip" class="br5"><span class="peak"></span><div class="content"><p>'+content+'</p></div></div>');
    $('body').append(tooltip);  	
  }
  
  //var content = $('.tooltip_content[rel='+inputId+']').html();
  tooltip.find('.content').html( content );
  
  //show tooltip
  var offset = input.offset();
  var ox = offset.left;
  var oy = offset.top - 50;  
  
  //alert(ox+'-'+oy);  
  //alert(w+'-'+h);
  
  tooltip.css({'left':ox+'px', 'top':oy+'px'});
  
  //alert( 'type w:' + typeof(w) );
  
  if ('undefined' != typeof(w)) 
    tooltip.css({'width':w+'px'});
    
  if ('undefined' != typeof(h)) 
    tooltip.css({'height':h+'px'});
  
  tooltip.show();    
  input.addClass('active');
  
}


function hideTooltip(wrap) 
{
  wrap.removeClass('active');  
  $('#tooltip').remove();  
}


/*
function scrollToDiv(divId)
{

  var theDiv = $(divId);
  var offset = theDiv.offset();
  
  window.scrollTo(offset.left, offset.top-20);

}
*/


function stupidIE() 
{
  var msie = jQuery.browser.msie;
  var version = jQuery.browser.version;

  if (true == msie && version < '7.0')
    return true;
  
  return false;
}





function setCharAt(str, index, chr) 
{
  if (index > str.length-1) 
    return str;
  return str.substr(0,index) + chr + str.substr(index+1);
}

/*
function getViewport() 
{

  var result = new Array();
  
  var msie = jQuery.browser.msie;

  if (msie) {
    result['left'] = document.body.scrollLeft;
    result['top'] = document.body.scrollTop;
  }
  else {
    result['left'] = window.pageXOffset;
    result['top'] = window.pageYOffset;
  }
  
  return result;  

}
*/


/**
 * getPageSize() by quirksmode.com
 *
 * @return Array Return an array with page width, height and window width, height
 */
function ___getPageSize() 
{
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
};


/**
 * getPageScroll() by quirksmode.com
 *
 * @return Array Return an array with x,y page scroll values.
 */
function ___getPageScroll() 
{
	var xScroll, yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}
	arrayPageScroll = new Array(xScroll,yScroll);
	return arrayPageScroll;
};



function objToString(obj) 
{
  var str = ''; 
  for(prop in obj)
    str += prop + ':'+ obj[prop]+'\n';
    
  return(str); 
}



