/*---------------------------------------------------------------------

Template Name: 	Online Booking
Version:	 	1.0
Release Date: 	August 08, 2010

File:       	custom.js
Updated:    	2010-08-08

Copyright (c) 2010 Zoran Juric - http://themeforest.net/user/zoranjuric

-----------------------------------------------------------------------

WARNING! DO NOT EDIT THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!

---------------------------------------------------------------------*/

// Preload images
imageObj = new Image();
imgs = ["/img/loader.gif", "/img/loading.gif"];
for (i = 0; i < imgs.length; i++) imageObj.src = imgs[i];
var undefined;
var $adHideMe = null; //Change the CSS ID selector to whatever you want to check
var infowindow;
var hotel_index = 0;
var hotel_name="";
var map = [];
var mapDrawn = [];

var hotels = [];
var list_hotels = [];
var markers = [];

var hidden_class = 'disabled'; //what class you want to add to the element when it's hidden
var width_to_hide = 1200;//What size to check for. DO NOT ADD "px"
var banner_ad_sky_visible = true;
// Site object setup
var Site = {};

Site.activeAd  = "";
Site.initAd = function(){
	
	var rndImg = Math.ceil(Math.random() * adBanners.length);
	if(rndImg<0) rndImg=0;
	var img = adBanners[rndImg-1];
	Site.activeAd = img;

	$adHideMe.empty().html("<a href='"+ img.url + "' ><img src='" + img.img + "' width='140' height='600' /></a>");

	//track click on banner ad skycrapper
	$("a",$adHideMe).click(function(){		
		_gaq.push(['_trackEvent', 'banner-ads', 'click', 'skycrapper-' + Site.activeAd.trackName]);
	});
}

Site.scrollAd = function(j,window,document, obj){

	function init(){
		var F = obj;
		var $adHideMe = j("#floatingbanner");

		$adHideMe.css({
			position: "absolute"
		});
		
		var y = j(document).height() - $adHideMe.height();

		F.timerAd = setInterval(function () {
			var i = Math.min($(window).scrollTop() , y);				
			if (i !== F.lastTop) {
				F.lastTop = i;
				$adHideMe.clearQueue().animate({
					top: i
				}, 1000, "easeOutCubic")
			}else{ 
				clearInterval(F.timerAd);
				return true;
			};
				
		}, 200)
	};

	init();


}

// scrollToTop() - scroll window to the top
Site.scrollToTop = function (e) {
    $(e).hide().removeAttr("href");
    if ($(window).scrollTop() != "0") {
        $(e).fadeIn("slow")
    }
    var scrollDiv = $(e);
    $(window).scroll(function () {
        if ($(window).scrollTop() == "0") {
            $(scrollDiv).fadeOut("slow")
        } else {
            $(scrollDiv).fadeIn("slow")
        }

		if(banner_ad_sky_visible && $adHideMe.length && jQuery.easing){ Site.scrollAd(jQuery,window,document,this); }

    });
    $(e).click(function () {
        $("html, body").animate({
            scrollTop: 0
        }, "slow")
    })

	$(window).scroll();
}

// scroll_to_hash() - scroll window to the tag with #hash id 
Site.scroll_to_hash = function(hash) {
	var ot = $(hash).offset();
	jQuery("html, body").animate({ 
		scrollTop: ot.top 
	}, "slow");
}

// setup() - Site init and setup
Site.setup = function () {
	
	$adHideMe = $('#floatingbanner');
	$adHideMe.lastTop = 0;

    // Open an external link in a new window
    $('a[href^="http://"]').filter(function () {
        return this.hostname && this.hostname !== location.hostname;
    }).attr('target', '_blank');

    // scroll to top on request
    if ($("a#totop").length) Site.scrollToTop("a#totop");
	
	// setup content boxes (Search Filters)
	if ($(".content-box").length) {
		$(".content-box .header").css({
			"cursor": "s-resize"
		});
		// Give the header in content-box a different cursor	
		$(".content-box .header").click(
		function () {
			$(this).parent().find('.section').toggle(); // Toggle the content
			$(this).parent().toggleClass("content-box-closed"); // Toggle the class "content-box-closed" on the content
		});
	}
	
	// preview image setup
	if ($("a.previewimg").length) {
		$('.infopanel a.previewimg').imgPreview({
			containerID: 'imgPreviewWithStyles',
			imgCSS: { height: 200 }
		});	
	}
	
	// popup windows
	$.nyroModalSettings({
		debug: false
	});
	
	// dropdown menu
	var $menu = $('#nav');		
	$menu.children('li').each(function(){
		var $this = $(this);

		var submenu = $this.find('.dropdown_submenu');
		if (submenu.length) {
			submenu.parents('ul, div').css('z-index', 2000); // z-index hack for IE7
			$this.bind('mouseenter',function(){
				submenu.slideDown().css('z-index', 1000); // z-index hack for IE7
			}).bind('mouseleave',function(){
				submenu.fadeOut('fast');
			});
		}		
	});
	
	// find closeable boxes and add a "close" action
	$('.closeable').each(function(index){
		$(this).prepend( 
			$('<a></a>')
				.attr({href: '#', title: 'Close'})
				.addClass('close')
				.text('x')
				.click(function() {
					$(this).parent().fadeOut();
					return false;
				})
		);
	});


	Site.initAd();

	$(window).resize(function(){//When the browser resizes
		Site.onResize(this);
	});

	$(window).resize();

	/*if($adHideMe.length>0 && adBanners.length>0){
		var rndImg = Math.ceil(Math.random() * adBanners.length);
		if(rndImg<0) rndImg=0;
		var img = adBanners[rndImg-1];
		$adHideMe.empty().html("<a href='"+ img.url + "' ><img src='" + img.img + "' width='140' height='600' /></a>");

		//track click on banner ad skycrapper
		$("a",$adHideMe).click(function(){
			_gaq.push(['_trackEvent', 'banner-ads', 'click', 'skycrapper']);
		});

		
		$(window).resize(function(){//When the browser resizes
			Site.onResize(this);		
			
		});

		$(window).resize();
	}*/

}





// gmapInit() - Init and draw a Google Map
// centerX		: Map center X
// centerY		: Map center Y
// zoom			: Zoom level
// clustering	: Clustering Enable/Disable
// panoramaID	: ID of the Street View panorama holder
Site.gmapInit = function(centerX, centerY, zoom, clustering, panoramaID, mapId, list) {
	// Already initialized?
	if (mapDrawn[mapId]) return false;

	// Default values
	var centerX 	= (centerX == null) ? 27.9944 : centerX;
	var centerY 	= (centerY == null) ? -9.8437 : centerY;
	var zoom 		= (zoom == null) ? 2 : zoom;
	var clustering 	= (clustering == null) ? false : clustering;
	var panoramaID 	= (panoramaID == null) ? "" : panoramaID
	var streetView	= (panoramaID != "");

	if(typeof(mapId)=="undefined")
		mapId = "map_canvas";

	if(typeof(list)=="undefined")
		list = hotels;

	(function () {

		google.maps.Map.prototype.markers = new Array();

		google.maps.Map.prototype.addMarker = function(marker) {
			this.markers[this.markers.length] = marker;
		};
		
	})();
	
	var hotelIcon = new google.maps.MarkerImage(
		'/img/markers/bed.png', 
		new google.maps.Size(26, 27), 
		new google.maps.Point(0, 0), 
		new google.maps.Point(11, 35)
	);	
	
	var hotelActiveIcon = new google.maps.MarkerImage(
		'/img/markers/blue_bed.png', 
		new google.maps.Size(26, 27), 
		new google.maps.Point(0, 0), 
		new google.maps.Point(11, 35)
	);

	

	var iconShape = { 
		coord: [14,0,16,1,17,2,18,3,19,4,19,5,20,6,20,7,20,8,20,9,20,10,20,11,20,12,20,13,20,14,19,15,19,16,18,17,18,18,18,19,17,20,17,21,16,22,16,23,15,24,15,25,14,26,14,27,13,28,13,29,12,30,12,31,11,32,11,33,11,34,9,34,9,33,9,32,8,31,8,30,7,29,7,28,6,27,6,26,5,25,5,24,4,23,4,22,3,21,3,20,3,19,2,18,2,17,1,16,1,15,0,14,0,13,0,12,0,11,0,10,0,9,0,8,0,7,0,6,1,5,1,4,2,3,3,2,4,1,6,0], 
		type: 'poly' 
	};

	var hotelIconShadow=null;
	/*var hotelIconShadow = new google.maps.MarkerImage(
		'/img/markers/orange-shadow.png',
		new google.maps.Size(39, 35),
		new google.maps.Point(0, 0),
		new google.maps.Point(11, 35)
	);*/
	
	var latlng = new google.maps.LatLng(centerX, centerY);
	var mapOptions = {
		zoom: zoom,
		center: latlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP,
		streetViewControl: streetView
	};
	map[mapId] = new google.maps.Map(document.getElementById(mapId), mapOptions);
	
	// Initialize Fluster and give it an existing map
	if (clustering)
		var fluster = new Fluster2(map[mapId]); 

	// Initialize markers for hotels
	for (var i = 0; i < list.length; i++) {
		var hotel = list[i];
		if (hotel[2] != '') {
			var myLatLng = new google.maps.LatLng(hotel[0], hotel[1]);
			// Add the marker to the Fluster
			if (clustering) {
				fluster.addMarker(createMarker(hotel, myLatLng)); 
			} else {
				map[mapId].addMarker(createMarker(hotel, myLatLng));
			}
		}
	}
	function createMarker(hotel, latlng) {
		var theIcon = hotelIcon;
		var infoExtended = false;
		if(hotel.length>4){
			infoExtended = true;
			if(hotel[4].status==1)
				theIcon = hotelActiveIcon;
		}
		var marker = new google.maps.Marker({
			position: latlng,
			map: map[mapId],
			shadow: hotelIconShadow,
			icon: theIcon,
			shape: iconShape,
			title: hotel[2],
			zIndex: 1
		});
		google.maps.event.addListener(marker, "click", function() {
			if (infowindow) infowindow.close();
			if(infoExtended){
				stars_img = ("<img height=\"16\" width=\"16\" src=\"/img/star.png\">").repeat(hotel[4].stars);
				var cextend =  "<div class=\"infopanel padded\"> <p><a href=\""+ hotel[3] +"\"><b>"+ hotel[2] +"</b></a><br/>" + stars_img + "</p><a title=\""+hotel[2]+"\" href=\""+hotel[3]+"\" class=\"fl\"><img class=\"small\" alt=\""+hotel[2]+"\" src=\""+ hotel[4].img +"\" width=\"50\" height=\"50\"></a><p class=\"small_8\">" + (hotel[4].desc).substr(0,70) + "...</p><div class=\"clear\">&nbsp;</div><div class=\"tr\"><a href=\"" + hotel[3] + "\"><b>Reservar</b></a></div></div>";
				infowindow = new google.maps.InfoWindow({content: cextend});
			}else{
				infowindow = new google.maps.InfoWindow({content: '<h5>' + hotel[2] + '</h5><a href="' + hotel[3] + '">Reserve Ahora</a>'});
			}
			infowindow.open(map[mapId], marker);
		});
		return marker;
	}
	
	if (clustering) {
		// Set fluster styles for more than 0, 10, 20 and 40 markers
		fluster.styles = {
			0: {
				//image: 'http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/images/m1.png',
				image: '/img/markers/fluster0.png',
				textColor: '#FFFFFF',
				width: 54,
				height: 54
			},
			10: {
				//image: 'http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/images/m2.png',
				image: '/img/markers/fluster1.png',
				textColor: '#FFFFFF',
				width: 58,
				height: 58
			},
			20: {
				//image: 'http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/images/m3.png',
				image: '/img/markers/fluster2.png',
				textColor: '#FFFFFF',
				width: 66,
				height: 66
			},
			40: {
				//image: 'http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/images/m4.png',
				image: '/img/markers/fluster3.png',
				textColor: '#FFFFFF',
				width: 80,
				height: 80
			}
		};

		// Initialize Fluster
		// This will set event handlers on the map and calculate clusters the first time.
		fluster.initialize(); 
	}
	
	// Do we need street view?
	if (panoramaID != '') {
		var panoramaOptions = {
			position: latlng,
			pov: {
				heading: 34,
				pitch: 10,
				zoom: 1
			}
		};
		var panoramaView = new google.maps.StreetViewPanorama(document.getElementById(panoramaID), panoramaOptions);
		map[mapId].setStreetView(panoramaView);
	}
	
	mapDrawn[mapId] = true;

}

// mapSetCenter() - Relocate/center a Google map
Site.mapSetCenter = function(lat, lng, zoom, mapId) {
	if(typeof(mapId)=="undefined")
		mapId = "map_canvas";

	map[mapId].setCenter(new google.maps.LatLng(lat, lng));
	if (zoom > 0) map[mapId].setZoom(zoom);
} 


Site.gmapwinhtml = function(hotel,i){
	
	return "<tr><td class=\"w34\"><a href=\""+hotel[3]+"\" onmouseover=\"showInMap("+i+")\">"+hotel[2]+"</a></td><td class=\"w14 tr\">"+("<img height=\"10\" width=\"10\" src=\"/img/star.png\">").repeat(hotel[4].stars)+"</td></tr>";

}



Site.onResize = function(obj){
	if($adHideMe!=null && $adHideMe.length>0){
		var w = $(obj).width();
		if(w < width_to_hide){ //If the browser width is LESS THAN width_to_hide
			$adHideMe.css('display','none').addClass(hidden_class); //Makes the ad banner display none
			banner_ad_sky_visible = false;
		}
		//If the window is equal or MORE THAN width_to_hide AND has a class "hidden":
		if(w >= width_to_hide && $adHideMe.hasClass(hidden_class)){
			$adHideMe.css('display','block').removeClass(hidden_class); //Make it appear again.
			banner_ad_sky_visible = true;
		}


		if(banner_ad_sky_visible){
			$adHideMe.css("left", ((w - 960)/2)-($adHideMe.width()+10));
		}
	}

}

Site.showFormBooking = function() {

	tabs.tabs('select', 0); 
	$('#frmbooking').show(); 
	$("#frmbooking h1").html("Hotel: " + hotels[0][2]);
	Site.scroll_to_hash('#frmbooking'); 
	
}


Site.Tarjeta = function(frm) {

	var ofrm = $('#'+frm); 
	/*
	name
	email
	dir
	phone
	dni
	reservar
	hora
	titular
	Nombre_tarjeta
	notarjeta
	Mes
	Ano
	codtarjeta
	comments
	*/

	//validar los datos iniciales.
	var l_nombre = $("#name");
	var l_email = $("#email");	
	var l_dir = $("#dir");
	var l_phone = $("#phone");
	var l_dni = $("#dni");
	var l_reservar = $("#reservar");
	//var l_hora = $("#hora");
	var l_titular = $("#titular");
	var l_Nombre_tarjeta = $("#Nombre_tarjeta");
	var l_notarjeta = $("#notarjeta");
	var l_Mes = $("#Mes");
	var l_Ano = $("#Ano");
	var l_codtarjeta = $("#codtarjeta");
	var l_comments = $("#comments");


	if(l_nombre.val()==""){
		$(".btf").html("<div class=\"alert\">Debe indicar su nombre</div>");
		return false;
	}

	v = l_email.val();
	var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
	if(!filter.test(v)){ //mail error
		$(".btf").html("<div class=\"alert\">La dirección de mail no es válida</div>");
		return false;
	}

	if(l_dir.val()==""){
		$(".btf").html("<div class=\"alert\">Debe indicar su dirección</div>");
		return false;
	}

	if(l_phone.val()==""){
		$(".btf").html("<div class=\"alert\">Debe indicar un teléfono de contacto</div>");
		return false;
	}

	if(l_dni.val()==""){
		$(".btf").html("<div class=\"alert\">Debe indicar DNI, Cédula de Identidad o Pasaporte</div>");
		return false;
	}

	if(l_reservar.val()==""){
		$(".btf").html("<div class=\"alert\">Debe indicar Hotel o Auto a reservar</div>");
		return false;
	}


	if(l_titular.val()==""){
		$(".btf").html("<div class=\"alert\">Debe indicar Nombre titular de la tarjeta</div>");
		return false;
	}

	if(l_Nombre_tarjeta.val()==""){
		$(".btf").html("<div class=\"alert\">Debe indicar Tarjeta de crédito</div>");
		return false;
	}

	
	if(l_notarjeta.val()==""){
		$(".btf").html("<div class=\"alert\">Debe indicar N° de Tarjeta de Crédito</div>");
		return false;
	}


	if(l_codtarjeta.val()==""){
		$(".btf").html("<div class=\"alert\">Debe indicar Código de seguridad Tarjeta de Crédito</div>");
		return false;
	}

	$(".btf").html("<img src='/img/loading_trans.gif' width='16' height='16' /> Procesando..");
	$.ajax({
	   type: "POST",
	   url: "/Includes/fnTarjetaProcesar.php",
	   data: $(ofrm).serialize(),
	   success: function(msg){
		 $(".btf").html(msg);
		 if(msg.indexOf("\"success\"")!=-1){
			$(ofrm).clearForm();
		 }
	   }
	});

}


Site.RentCar = function(frm) {

	var ofrm = $('#'+frm); 

	//validar los datos iniciales.
	var l_nombre = $("#txtname");
	var l_email = $("#email");
	var l_dir = $("#txtdir");
	var l_phone = $("#txtphone");
	var l_pais = $("#cbopais");
	var l_city = $("#txtcity");
	var l_llegada = $("#startdate_change");
	var l_partida = $("#enddate_change");

	if(l_nombre.val()==""){
		$(".btf").html("<div class=\"alert\">Debe indicar su nombre</div>");
		return false;
	}

	v = l_email.val();
	var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
	if(!filter.test(v)){ //mail error
		$(".btf").html("<div class=\"alert\">La dirección de mail no es válida</div>");
		return false;
	}

	/*if(l_dir.val()==""){
		$(".btf").html("<div class=\"alert\">Debe indicar su dirección</div>");
		return false;
	}*/

	/*if(l_phone.val()==""){
		$(".btf").html("<div class=\"alert\">Debe indicar un teléfono de contacto</div>");
		return false;
	}*/


	v = l_pais.val();
	if(v==""){
		$(".btf").html("<div class=\"alert\">Debe indicar su país de residencia</div>");
		return false;
	}


	/*v = l_city.val();
	if(v==""){
		$(".btf").html("<div class=\"alert\">Debe indicar su país de residencia</div>");
		return false;
	}*/

	
	if(l_llegada.val()==""){
		$(".btf").html("<div class=\"alert\">Debe indicar fecha en que retira el vehículo</div>");
		return false;
	}

	if(l_partida.val()==""){
		$(".btf").html("<div class=\"alert\">Debe indicar una fecha en que devuelve el vehículo</div>");
		return false;
	}


	$(".btf").html("<img src='/img/loading_trans.gif' width='16' height='16' /> Procesando..");
	$.ajax({
	   type: "POST",
	   url: "/Includes/fnRentCar.php",
	   data: $(ofrm).serialize() + "&pais=" + $("#cbopais option:selected").text(),
	   success: function(msg){
		 $(".btf").html(msg);
		 if(msg.indexOf("\"success\"")!=-1){
			$(ofrm).clearForm();
		 }
	   }
	});

}


Site.AddBooking = function(frm) {

	var ofrm = $('#'+frm); 

	//validar los datos iniciales.
	var l_llegada = $("#startdate_change");
	var l_partida = $("#enddate_change");
	var l_nombre = $("#txtname");
	var l_apellido = $("#txtape");
	var l_email = $("#email");
	var l_emailconf = $("#emailconf");
	var l_pais = $("#cbopais");

	
	if(l_llegada.val()==""){
		$(".btf").html("<div class=\"alert\">Debe indicar una fecha de llegada</div>");
		return false;
	}

	if(l_partida.val()==""){
		$(".btf").html("<div class=\"alert\">Debe indicar una fecha de partida</div>");
		return false;
	}

	if(l_nombre.val()==""){
		$(".btf").html("<div class=\"alert\">Debe indicar su nombre</div>");
		return false;
	}

	if(l_apellido.val()==""){
		$(".btf").html("<div class=\"alert\">Debe indicar su apellido</div>");
		return false;
	}

	v = l_email.val();
	if(v!=l_emailconf.val()){
		$(".btf").html("<div class=\"alert\">La dirección de mail y su confirmación deben ser iguales</div>");
		return false;
	}	
	
	var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
	if(!filter.test(v)){ //mail error
		$(".btf").html("<div class=\"alert\">La dirección de mail no es válida</div>");
		return false;
	}


	v = l_pais.val();
	if(v==""){
		$(".btf").html("<div class=\"alert\">Debe indicar su país de residencia</div>");
		return false;
	}
	
	

	$(".btf").html("<img src='/img/loading_trans.gif' width='16' height='16' /> Procesando..");
	$.ajax({
	   type: "POST",
	   url: "/Includes/fnAddBooking.php",
	   data: $(ofrm).serialize() + "&h=" + escape(hotels[0][2]),
	   success: function(msg){
		 $(".btf").html(msg);
		 if(msg.indexOf("\"success\"")!=-1){
			$(ofrm).clearForm();
			$("#thw_rooms").trigger("change.basicInput");
			$("#list_child_ages_0_0").attr("selectedIndex",0).hide();
		 }
	   }
	});
	
}


Site.AddHotel = function(frm) {

	var ofrm = $('#'+frm); 

	//validar los datos iniciales.
	var l_name = $("#txtname");
	var l_hotel = $("#txthotel");
	var l_tipo = $("#cbotipo");
	var l_provincia = $("#cboprovincia");
	var l_dir = $("#txtdir");
	//var l_categoria = $("#cbocategoria");
	//var l_localidad = $("#txtlocalidad");
	var l_tel = $("#txtphone");
	//var l_fax = $("#txtfax");
	var l_mail = $("#txtmail");
	var l_mail_res = $("#email");
	//var l_web = $("#txtWeb");
	
	if(l_hotel.val()==""){
		$(".btf").html("<div class=\"alert\">Debe indicar el nombre del hotel</div>");
		return false;
	}


	if(l_name.val()==""){
		$(".btf").html("<div class=\"alert\">Debe indicar su nombre y apellido</div>");
		return false;
	}


	v = l_mail.val();
	var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
	if(!filter.test(v)){ //mail error
		$(".btf").html("<div class=\"alert\">La dirección de mail no es válida</div>");
		return false;
	}

	if(l_tipo.val()==""){
		$(".btf").html("<div class=\"alert\">Debe indicar el tipo de hotel a agregar</div>");
		return false;
	}

	if(l_dir.val()==""){
		$(".btf").html("<div class=\"alert\">Debe indicar dirección del hotel</div>");
		return false;
	}
	
	if(l_provincia.val()==""){
		$(".btf").html("<div class=\"alert\">Debe indicar provincia</div>");
		return false;
	}

	v = l_tel.val();
	if(v==""){
		$(".btf").html("<div class=\"alert\">Debe indicar un número de teléfono</div>");
		return false;
	}
	
	

	v = l_mail_res.val();
	var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
	if(!filter.test(v)){ //mail error
		$(".btf").html("<div class=\"alert\">La dirección de mail para reservas no es válida</div>");
		return false;
	}


	$(".btf").html("<img src='/img/loading_trans.gif' width='16' height='16' /> Procesando..");
	$.ajax({
	   type: "POST",
	   url: "/Includes/fnAddHotel.php",
	   data: $(ofrm).serialize(),
	   success: function(msg){
		 $(".btf").html(msg);
		 if(msg.indexOf("\"success\"")!=-1){
			$(ofrm).clearForm();
		 }
	   }
	});
	
}



Site.Contacto = function(frm) {

	var ofrm = $('#'+frm); 

	//validar los datos iniciales.
	var l_name = $("#name");
	var l_tema = $("#subject");
	var l_obs = $("#comments");
	//var l_tel = $("#phone");
	var l_mail = $("#contactemail");

	if(l_tema.val()==""){
		$(".btf").html("<div class=\"alert\">Debe indicar el tema de su consulta/sugerencia</div>");
		return false;
	}
	
	if(l_name.val()==""){
		$(".btf").html("<div class=\"alert\">Debe indicar su nombre y apellido</div>");
		return false;
	}

	v = l_mail.val();
	var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
	if(!filter.test(v)){ //mail error
		$(".btf").html("<div class=\"alert\">La dirección de mail no es válida</div>");
		return false;
	}

	if(l_obs.val()==""){
		$(".btf").html("<div class=\"alert\">Escribe tu comentario, sugerencia o queja para que podamos responderte</div>");
		return false;
	}
	
	
	


	$(".btf").html("<img src='/img/loading_trans.gif' width='16' height='16' /> Procesando..");
	$.ajax({
	   type: "POST",
	   url: "/Includes/fnContacto.php",
	   data: $(ofrm).serialize(),
	   success: function(msg){
		 $(".btf").html(msg);
		 if(msg.indexOf("\"success\"")!=-1){
			$(ofrm).clearForm();
		 }
	   },
	   error: function(msg){$(".btf").html("<div class='alert'>Ups, parece que algo no funcionó bien.<br/>Vuelve a intentarlo más tarde.</div>");}
	});
	
}


Site.Opinar = function(frm) {

	var ofrm = $('#'+frm); 

	//validar los datos iniciales.
	var l_name = $("#name");
	var l_name2 = $("#lastname");	
	var l_obs = $("#comments");
	var l_mail = $("#contactemail");
	
	/*if(l_name.val()==""){
		$(".btf").html("<div class=\"alert\">Debe indicar su nombre</div>");
		return false;
	}*/

	/*if(l_name2.val()==""){
		$(".btf").html("<div class=\"alert\">Debe indicar su apellido</div>");
		return false;
	}*/

	/*v = l_mail.val();
	var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
	if(!filter.test(v)){ //mail error
		$(".btf").html("<div class=\"alert\">La dirección de mail no es válida</div>");
		return false;
	}*/

	/*if(l_obs.val()==""){
		$(".btf").html("<div class=\"alert\">Escribe tu comentario, sugerencia o queja para que podamos responderte</div>");
		return false;
	}*/

	$(".btf").html("<img src='/img/loading_trans.gif' width='16' height='16' /> Procesando..");
	$.ajax({
	   type: "POST",
	   url: "/Includes/fnOpinar.php",
	   data: $(ofrm).serialize(),
	   success: function(msg){
		 $(".btf").html(msg);
		 if(msg.indexOf("\"success\"")!=-1){
			$(ofrm).clearForm();
		 }
	   },
	   error: function(msg){$(".btf").html("<div class='alert'>Ups, en este momento no podemos procesar tu opinion<br/>Vuelve a intentarlo más tarde.</div>");}
	});
	
}


Site.serialize_people = function () {
	var rooms = [],
		childNumOfRoom,
		childIdPrefix,
		ages,
		i, j;
	var thw_rNum = parseInt($("#thw_rooms").val(),10);

	if (thw_rNum) {
		for (i = 0; i < thw_rNum; i++) {
			childNumOfRoom = parseInt($("#thw_children_" + i).val(), 10);
			ages = [];
			childIdPrefix = "#thw_ca_" + i + "_";
			for (j = 0; j < childNumOfRoom; j++) {
				ages.push($(childIdPrefix + j).val());
			}
			rooms.push(ages);
		}
	}
	return rooms;
}


$.fn.clearForm = function() {
  return this.each(function() {
    var type = this.type, tag = this.tagName.toLowerCase();
    if (tag == 'form')
      return $(':input',this).clearForm();
    if (type == 'text' || type == 'password' || tag == 'textarea')
      this.value = '';
    else if (type == 'checkbox' || type == 'radio')
      this.checked = false;
    else if (tag == 'select' && this.multiple)
       this.selectedIndex = -1;
    else if (tag == 'select'){
       this.selectedIndex = -1;
       this.selectedIndex = 0;
	}
  });
};



String.prototype.repeat= function(n){
	n= n || 1;     
	return Array(n+1).join(this); 
} 



