// JavaScript Document

// precargar la barra de progreso

var progress_bar = new Image();

		progress_bar.src = 'images/4.gif';



// ######################################################################
// funcion para desplegar u ocultar objetos al momento de hacerle click
// ######################################################################

	function display(obj) {

		obj = document.getElementById(obj);

		if (obj.style.display == "none") {

			obj.style.display = "block";

		} else {

			obj.style.display = "none";

		}

	}





//////////////////////////////////////////////////////////////////////////////////////////

// funcion para generar las peliculas flash en Internet Explorer

//////////////////////////////////////////////////////////////////////////////////////////



function flash(pelicula, ancho, alto)

{

    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+ancho+'" height="'+alto+'">\n');
	document.write('<param name="movie" value="'+pelicula+'"/>\n');
	document.write('<param name="quality" value="high"/>\n');
	document.write('<param name="wmode" value="transparent"/>\n');
	document.write('<embed src="'+pelicula+'" quality="high" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+ancho+'" height="'+alto+'"></embed>\n');
    document.write('</object>\n');
}



//////////////////////////////////////////////////////////////////////////////////////////
// funcion para el jump menu
//////////////////////////////////////////////////////////////////////////////////////////

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

//////////////////////////////////////////////////////////////////////////////////////////
// funcion para verificar la validacion del correo electronico
//////////////////////////////////////////////////////////////////////////////////////////



function emailvalidation(entered, alertbox)
{
with (entered)
{
apos=value.indexOf("@"); 
dotpos=value.lastIndexOf(".");
lastpos=value.length-1;

if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) 

{if (alertbox) {alert(alertbox);} return false;}

else {return true;}

}

} 



//////////////////////////////////////////////////////////////////////////////////////////

// funcion para abrir pop up

//////////////////////////////////////////////////////////////////////////////////////////



function openWindow(url) {

  window.open( url, 'remote', 'resizable,dependent,width=700,height=480,left=50,top=150, scrollbars=yes')

}



//////////////////////////////////////////////////////////////////////////////////////////
// funcion para cargar links en la ventana padre
//////////////////////////////////////////////////////////////////////////////////////////



function loadinparent(url, closeSelf){
	self.opener.location = url;
	if(closeSelf) self.close();
	}

//////////////////////////////////////////////////////////////////////////////////////////
// funcion para validar los campos requeridos
//////////////////////////////////////////////////////////////////////////////////////////



function validar_forma(f) {

		if (f.name.value == "") {

			alert("Nombre completo, por favor.");

			f.nombre.focus();

			return false;

		}

		

		if (f.phone.value == "") {

			alert("Tel&eacute;fono, por favor.");

			f.phone.focus();

			return false;

		}

		

		if (f.arrival.value == "") {

			alert("Celular, por favor.");

			f.arrival.focus();

			return false;

		}

		

		if (f.rooms.value == "") {

			alert("Cantidad cuartos, por favor.");

			f.rooms.focus();

			return false;

		}

		

	}

//////////////////////////////////////////////////////////////////////////////////////////
// funcion para validar los campos requeridos
//////////////////////////////////////////////////////////////////////////////////////////



function checkrequired(which){
var pass=true
if (document.images){
for (i=0;i<which.length;i++){
var tempobj=which.elements[i]
if (tempobj.name.substring(0,8)=="required"){
if (((tempobj.type=="text"||tempobj.type=="textarea")&&tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==-1)){
pass=false
break
}
}
}
}

if (!pass){
alert("Uno o m&aacute;s de los elementos requeridos no est&aacute;n completos.  Por favor, complete los campos faltantes.")
return false
} else
return true
}





// #########################################################################	 	

/************************   AJAX del suggest *************************************/

// #########################################################################	 

function createRequestObject() { 



   var req; 



   if(window.XMLHttpRequest){ 

      // Firefox, Safari, Opera... 

      req = new XMLHttpRequest(); 

   } else if(window.ActiveXObject) { 

      // Internet Explorer 5+ 

      req = new ActiveXObject("Microsoft.XMLHTTP"); 

   } else { 

      // There is an error creating the object, 

      // just as an old browser is being used. 

      alert('Problem creating the XMLHttpRequest object'); 

   } 



   return req; 



} 



// Make the XMLHttpRequest object 

   var http = createRequestObject();

   

function sendRequest(q) { 

		

       // Open PHP script for requests  

      http.open('get', 'retrieve.php?id='+q);  

       http.onreadystatechange = handleResponse;  

       http.send(null); 



} 



// handles the response returned FROM the PHP script. Anything echoed or printed

// in that script is stored in a variable as part of the http object which we can work with later.



function handleResponse() { 



   if(http.readyState == 4 && http.status == 200){ 



      // Text returned FROM the PHP script 

      var response = http.responseText; 



      if(response) { 

         // UPDATE ajaxTest content 

		 show_progressbar('searchResults');

        document.getElementById("searchResults").innerHTML = response; 

      	//display('searchResults');

	  } 



   } 



} 	


/****************************************************************************************
* Esto es para el AJAX del select del pais y los estados
*****************************************************************************************/



var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)

var loadedobjects=""

var rootdomain="http://"+window.location.hostname

var bustcacheparameter=""



function ajaxpage(url, containerid){

var page_request = false

if (window.XMLHttpRequest) // if Mozilla, Safari etc

page_request = new XMLHttpRequest()

else if (window.ActiveXObject){ // if IE

try {

page_request = new ActiveXObject("Msxml2.XMLHTTP")

} 

catch (e){

try{

page_request = new ActiveXObject("Microsoft.XMLHTTP")

}

catch (e){}

}

}

else

return false

page_request.onreadystatechange=function(){

loadpage(page_request, containerid)

}

if (bustcachevar) //if bust caching of external page

bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()

page_request.open('GET', url+bustcacheparameter, true)

page_request.send(null)

}



function loadpage(page_request, containerid){

show_progressbar(containerid);

if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))

document.getElementById(containerid).innerHTML=page_request.responseText

}



function loadobjs(){

if (!document.getElementById)

return

for (i=0; i<arguments.length; i++){

var file=arguments[i]

var fileref=""

if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding

if (file.indexOf(".js")!=-1){ //If object is a js file

fileref=document.createElement('script')

fileref.setAttribute("type","text/javascript");

fileref.setAttribute("src", file);

}

else if (file.indexOf(".css")!=-1){ //If object is a css file

fileref=document.createElement("link")

fileref.setAttribute("rel", "stylesheet");

fileref.setAttribute("type", "text/css");

fileref.setAttribute("href", file);

}

}

if (fileref!=""){

document.getElementsByTagName("head").item(0).appendChild(fileref)

loadedobjects+=file+" " //Remember this object as being already added to page

}

}

}



/****************************************************************************************

* Esta funcion trabaja con el superior

*****************************************************************************************/



function ajaxcombo(obj, loadarea){
if (obj) {

	//alert(obj.value);
		var val = obj.value.toLowerCase();		//convertir texto a minusculas
		val = val.replace(new RegExp('\\ ', 'g'),'_');	//eliminamos los espacios en blancos y los reemplazamos con _
		//val = val.replace(/ /gi, '_');
		//alert(val);
		switch(val) {	
			case 'panama':
				ajaxpage('statefield.html', loadarea);
				break;
			case 'united_states_of_america':
				ajaxpage('statedropdown.html', loadarea);
				break;
			default:
				ajaxpage('statefield.html', loadarea);
			break;
		}
}


}

/****************************************************************************************
* Funcion para habilitar el boton del cart
*****************************************************************************************/


function btnchecker(obj) {
if (obj) {
if (obj.value == 'yes') {	
cred.place.disabled = false;
} else {
cred.place.disabled = true;	
}
}
}

/****************************************************************************************
* Funcion para reemplazar el html de un div determinado
*****************************************************************************************/

function replace_html(id, content) {
		document.getElementById(id).innerHTML = content;
		}

/****************************************************************************************
* Funcion para mostrar la barra de carga de progreso
*****************************************************************************************/

function show_progressbar(id) {
			replace_html(id, '<img src="images/4.gif" border="0" alt="Loading, please wait..." style="margin-top: 200px;" />');
		}

/****************************************************************************************
* slideshow de pagina de inicio
*****************************************************************************************/	

function slideShow(speed) {

	//append a LI item to the UL list for displaying caption
	$('ul.slideshow').append('<li id="slideshow-caption" class="caption"><div class="slideshow-caption-container"><h3></h3><p></p></div></li>');

	//Set the opacity of all images to 0
	$('ul.slideshow li').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('ul.slideshow li:first').css({opacity: 1.0});
	
	//Get the caption of the first image from REL attribute and display it
	$('#slideshow-caption h3').html($('ul.slideshow a:first').find('img').attr('title'));
	$('#slideshow-caption p').html($('ul.slideshow a:first').find('img').attr('alt'));
		
	//Display the caption
	$('#slideshow-caption').css({opacity: 0.7, bottom:0});
	
	//Call the gallery function to run the slideshow	
	var timer = setInterval('gallery()',5000);
	
	//pause the slideshow on mouse over
	$('ul.slideshow').hover(
		function () {
			clearInterval(timer);	
		}, 	
		function () {
			timer = setInterval('gallery()',speed);			
		}
	);
	
}

function gallery() {


	//if no IMGs have the show class, grab the first image
	var current = ($('ul.slideshow li.show')?  $('ul.slideshow li.show') : $('#ul.slideshow li:first'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().attr('id') == 'slideshow-caption')? $('ul.slideshow li:first') :current.next()) : $('ul.slideshow li:first'));
		
	//Get next image caption
	var title = next.find('img').attr('title');	
	var desc = next.find('img').attr('alt');	

	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);
	
	//Hide the caption first, and then set and display the caption
	$('#slideshow-caption').animate({bottom:-70}, 300, function () {
			//Display the content
			$('#slideshow-caption h3').html(title);
			$('#slideshow-caption p').html(desc);				
			$('#slideshow-caption').animate({bottom:0}, 500);	
	});		

	//Hide the current image
	current.animate({opacity: 0.0}, 1000).removeClass('show');

}

/* ------------------------------------------------------------------------
	s3Slider
	
	Developped By: Boban Kariik -> http://www.serie3.info/
        CSS Help: Mészáros Róbert -> http://www.perspectived.com/
	Version: 1.0
	
	Copyright: Feel free to redistribute the script/modify it, as
			   long as you leave my infos at the top.
------------------------------------------------------------------------- */


(function($){  

    $.fn.s3Slider = function(vars) {       
        
        var element     = this;
        var timeOut     = (vars.timeOut != undefined) ? vars.timeOut : 4000;
        var current     = null;
        var timeOutFn   = null;
        var faderStat   = true;
        var mOver       = false;
        var items       = $("#" + element[0].id + "Content ." + element[0].id + "Image");
        var itemsSpan   = $("#" + element[0].id + "Content ." + element[0].id + "Image span");
            
        items.each(function(i) {
    
            $(items[i]).mouseover(function() {
               mOver = true;
            });
            
            $(items[i]).mouseout(function() {
                mOver   = false;
                fadeElement(true);
            });
            
        });
        
        var fadeElement = function(isMouseOut) {
            var thisTimeOut = (isMouseOut) ? (timeOut/2) : timeOut;
            thisTimeOut = (faderStat) ? 10 : thisTimeOut;
            if(items.length > 0) {
                timeOutFn = setTimeout(makeSlider, thisTimeOut);
            } else {
                console.log("Poof..");
            }
        }
        
        var makeSlider = function() {
            current = (current != null) ? current : items[(items.length-1)];
            var currNo      = jQuery.inArray(current, items) + 1
            currNo = (currNo == items.length) ? 0 : (currNo - 1);
            var newMargin   = $(element).width() * currNo;
            if(faderStat == true) {
                if(!mOver) {
                    $(items[currNo]).fadeIn((timeOut/6), function() {
                        if($(itemsSpan[currNo]).css('bottom') == 0) {
                            $(itemsSpan[currNo]).slideUp((timeOut/6), function() {
                                faderStat = false;
                                current = items[currNo];
                                if(!mOver) {
                                    fadeElement(false);
                                }
                            });
                        } else {
                            $(itemsSpan[currNo]).slideDown((timeOut/6), function() {
                                faderStat = false;
                                current = items[currNo];
                                if(!mOver) {
                                    fadeElement(false);
                                }
                            });
                        }
                    });
                }
            } else {
                if(!mOver) {
                    if($(itemsSpan[currNo]).css('bottom') == 0) {
                        $(itemsSpan[currNo]).slideDown((timeOut/6), function() {
                            $(items[currNo]).fadeOut((timeOut/6), function() {
                                faderStat = true;
                                current = items[(currNo+1)];
                                if(!mOver) {
                                    fadeElement(false);
                                }
                            });
                        });
                    } else {
                        $(itemsSpan[currNo]).slideUp((timeOut/6), function() {
                        $(items[currNo]).fadeOut((timeOut/6), function() {
                                faderStat = true;
                                current = items[(currNo+1)];
                                if(!mOver) {
                                    fadeElement(false);
                                }
                            });
                        });
                    }
                }
            }
        }
        
        makeSlider();

    };  

})(jQuery);  
