var namesDay = ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa'];
var namesMonth = ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'];


/* FUNCTIONS */	


if(!window.console){window.console={log:function(){},error:function(){},warn:function(){}};}
							function galleryTitle(title, currentArray, currentIndex, currentOpts){ return '<div id="fancybox-title-over" style="padding: 10px 10px 20px 10px;">' + '<div class="fl">' + (title && title.length ? '<b>' + title + '</b>' : '&nbsp;' ) + '</div>' + '<div class="fr">' + (currentIndex + 1) + ' / ' + currentArray.length + '</div>' + '</div>'; } 
							function createChildAgeSelect() { var select = $('<select  name="children_age[]" />').addClass('select').addClass('minorage'); jQuery.each(['0','1','2','3','4','5','6','7','8','9','10','11','12'], function(index, value){$(select).append($('<option />').clone().attr('label', index).val(value).html(value));});return select;}
							function setMap(id, lat, lng, zom, title, info, zcontrol){
								var latlng = new google.maps.LatLng(lat, lng);
								var options = {
										zoom: zom,
										center: latlng,
										draggable: true,
									    zoomControl: zcontrol,
									    zoomControlOptions: {
									        style: google.maps.ZoomControlStyle.LARGE
									    },
									    mapTypeControl: true,
									    mapTypeControlOptions: {
											style: google.maps.MapTypeControlStyle.DROPDOWN_MENU,
											mapTypeIds: [ google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.SATELLITE, google.maps.MapTypeId.TERRAIN, google.maps.MapTypeId.HYBRID ],
											position: google.maps.ControlPosition.TOP_LEFT
										},
									    mapTypeId: google.maps.MapTypeId.TERRAIN,
										panControl: false,
									    scaleControl: false,
									    streetViewControl: false,
									    overviewMapControl: false
									};
								var map = new google.maps.Map(document.getElementById(id), options);
								var marker = new google.maps.Marker({ position: latlng, map: map, draggable:false, animation: google.maps.Animation.DROP, title: title });
								var info = new google.maps.InfoWindow({ position: latlng, content: info, maxWidth: 285 });
								info.open(map);
							}
							function autocompleteOnComplete(responseText){
								var find = 'origin';
								var selector = '#' +find;
								var currentLang = getLang();
							 	err2 = responseText;
								var objs = responseText;
								$(selector).autocomplete(objs, {
									width:280,
									//mustMatch:true,
									max: 10, highlight:false,
									//autoFill:true,
									multiple: false,minChars: 1,
										scroll: true,scrollHeight: 300,
									matchContains:true,formatItem: function(item){
 										var airportName = item.AirportName!=""?" ("+item.AirportName+")":"";
										item.CountryCode = "Mexico";
										var result = item.CityName + airportName + ", "+ item.CountryCode+" ("+item.AirportCode+")";
									
 										return result;
									},formatMatch: function(item) {
										
								 			return item.AirportCode +","+
								 				   item.CityName +","+
								 				   item.CityCode +","+
								 				   item.State +","+
								 				   item.AirportName ; 
									},formatResult: function(item){
 										//return item.AirportCode;
										var airportName = item.AirportName!=""?" ("+item.AirportName+")":"";
										item.CountryCode = "Mexico";
										var result = item.CityName + airportName + ", "+ item.CountryCode+" ("+item.AirportCode+")";
										return result;
									},formatItem: function(item, i, max,term,word){
										var airportName = item.AirportName!=""?" ("+item.AirportName+")":"";
										item.CountryCode = "Mexico";
										var result = item.CityName + airportName + ", "+ item.CountryCode+" ("+item.AirportCode+")";
										
										var x = result.replace(new RegExp("(" + word + ")", "gi"), "<strong>$1</strong>");
										return x;
									}
								}).blur(function(){
									$(this).search();
								}).result(function(a,b,c){
									var val = $(this).val();
									var exists = false;
									var defaultValue = "";
									$(objs).each(function(index,item){
										var airportName = item.AirportName!=""?" ("+item.AirportName+")":"";
										item.CountryCode = "Mexico";
										var result = item.CityName + airportName + ", "+ item.CountryCode+" ("+item.AirportCode+")";
 										if(item.AirportCode == "MEX") defaultValue = result;
 										
										if(val == result) exists = true;
									});
									
									if(!exists)	$(this).val(defaultValue);
									
									
								});
							}
							function initAutocompleterOrigin(selector){
								if($(selector).length == 0) return;
								var script = document.createElement("script");
								script.type = "text/javascript";
								script.src = "/"+getLang()+"/flight/find/country/mx/callback/autocompleteOnComplete";
							 	document.body.appendChild(script);
							};
							

/* ON PAGE LOAD */
$(document).ready(function(){
	/*var x = new Date();
	if((x.getDay() == 6 && x.getHours() >= 15)
			|| x.getDay() == 0){
		if($("input[name=traveloptions]").length>0){
			$("input[name=traveloptions]")[0].click();$("input[name=traveloptions]").parents("tr").hide();
		}
	}*/
	
	
	$("a#inlinecontactwindow").fancybox({
		'hideOnContentClick': false
	});
	
	$("a#inlinecontactwindow2").fancybox({
		'hideOnContentClick': false
	});
	
	
	/* $('img').lazyload({effect:'fadeIn',threshold:100}); */
	initAutocompleterOrigin('#origin')
	$('#adultos, #ninos, #cuartos').selectmenu({width:44,style:'dropdown'});
	$('#resort_id, #meetingroom, #event').selectmenu({width:170,style:'dropdown'});
	$('#currency_code,#flight_option').selectmenu({width:123,style:'dropdown'});
	
	
	$('select#country').selectmenu({
		style:'dropdown',
		width:170,
		maxHeight: 300
	});

	$('#country_id').selectmenu({
		style:'dropdown',
		width:170,
	    speed: 400,
	    maxHeight: 200,
	    direction: "auto"
	});
	
	
	$('div.acc-container #title').selectmenu({width:170,style:'dropdown'});
	$('div.acc-container #bday_day').selectmenu({width:64,style:'dropdown',maxHeight:180});
	$('div.acc-container #bday_month').selectmenu({width:170,style:'dropdown'});
	$('div.acc-container #bday_year').selectmenu({width:44,style:'dropdown',maxHeight:180});
	$('div.acc-container select#gender').selectmenu({width:170,style:'dropdown'});
	$('div.acc-container #sel_meal').selectmenu({width:170,style:'dropdown'});
	$('div.acc-container #sel_wheelchair').selectmenu({width:402,style:'dropdown'});
	$('div.acc-container #phoneUseType').selectmenu({width:170,style:'dropdown'});
	
	
	$('div#creditcard-payment  #choose_cc').selectmenu({width:170,style:'dropdown'});
	$('div#creditcard-payment  #cc_exp_m').selectmenu({width:64,style:'dropdown', maxHeight:100});
	$('div#creditcard-payment  #cc_exp_y').selectmenu({width:64,style:'dropdown', maxHeight:100});
	
	
	
	
	//$('select#resort_id, select#country').easySelectBox({speed:100});

	$("#tag").css("background-image", "url("+$("#tagimg1").attr("src")+")");

	$('#slideshow').craftyslide({'eachSlideEvent':function(s){
		$("#tag").attr('style','background-image:url('+$("#tagimg1").attr("src")+')');
		//$("#tag").css("background-image", "url("+$("#tagimg1").attr("src")+")");
		
		setTagBillboard(s);
	}});
	
	var dates = $( "#checkin, #checkout" ).datepicker({
		dayNamesMin:namesDay,
		monthNames:namesMonth,
		minDate:+1,
		//defaultDate:'+1w',
		numberOfMonths: 2,
		showOn:'both',
		buttonImage:'http://prassets.clubparkroyal.com/hotels/calendario-reservacion.png',
		buttonImageOnly:true,
		dateFormat:'yy-mm-dd',
		firstDay:1,
		onSelect: function( selectedDate ) {
			var option = this.id == 'checkin' ? 'minDate' : 'maxDate',
				instance = $( this ).data( 'datepicker' ),
				date = $.datepicker.parseDate(
					instance.settings.dateFormat ||
					$.datepicker._defaults.dateFormat,
					selectedDate, instance.settings );
			dates.not( this ).datepicker( 'option', option, date );
		}
	});
	$('#events #eventdate').datepicker({
		dayNamesMin:namesDay,
		monthNames:namesMonth,
		minDate:+1,
		numberOfMonths: 2,
		buttonImageOnly:true,
		buttonImage:'http://prassets.clubparkroyal.com/hotels/calendario-reservacion.png',
		dateFormat:'yy-mm-dd',
		firstDay:1
	});
	
	$('ul.amenities li').amenities();
	$('ul.hotel-services li a[title]').qtip({position:{corner:{target:'topMiddle',tooltip: 'bottomMiddle'}},style:{tip: 'bottomMiddle',name:'light',background:'#d9d9d9', color: '#3c3c3c',border:{radius: 7, color: '#3c3c3c'}}});
	if ($('ul.hotel-tabs').length) $('ul.hotel-tabs').tabs({load:true,scrollTo:$('#services').position().top, speed:200, easing:'swing'});
	$('ul.places-tabs').tabs({contentClassName:'tc',selectedClassName:'a',previousClassName:'p', speed:200, easing:'swing'});
	$('a.up-arrow').click(function(){$('html, body').animate({scrollTop:$('#services').position().top},700);return false;});
	$('.map').fancybox({overlayColor:'#000',overlayOpacity:'0.8',scrolling:'no',autoDimensions:true,autoScale:true,titleShow:false,type:'inline'});
	$('.gallery').fancybox({cyclic:true,overlayColor:"#000",overlayOpacity:"0.8",titlePosition:'over','titleFormat':galleryTitle,autoScale:true});
	$('.shop').fancybox({type:'inline',titleShow:false,width:700,height:300,autoDimensions:false,transitionIn:'none',transitionOut:'none'});
	$('.blueprints').fancybox({overlayColor:"#f5f6f8",overlayOpacity:"0.8",margin:0,padding:0,width:1048,height:800,titleShow:false,autoScale:true,onStart:function(){$('.fancybox-bg').css('display','none');$('#fancybox-close').css('top','5px').css('right','5px');}, onCleanup:function(){ $('#fancybox-close').css('top','-15px').css('right','-15px'); }});
	$('#playVideo').fancybox({overlayColor:'#000',overlayOpacity:'0.8',scrolling:'no',titleShow:false,autoDimensions:false,width:640,height:360});
	//if (!$.browser.msie) {
		//if ($.flash.available) {
		if($("#mediaSpace").length > 0 ){
			jwplayer('mediaSpace').setup({
		        flashplayer:'/swf/player.swf',
				file:$('#playVideo').attr('src'),
				width:640,
				height:360,
				bufferlength:3,
				autostart:true
			});
		}
		//}
	//}
	$('#sites').sites({width:320});
	$("select#ninos").change(function(){
		//console.log($(this).attr('value'));
		var label = $("#minor-translation").text();
		var ninos = $(this).attr('value');
		if (ninos > 0) {
			var select = createChildAgeSelect();
			$('td.minor-age').html( $('<p />').html( $('<label />') ) );	
			$('td.minor-age p label').html( $('#minor-age-title').text() );
			for (i = 1; i <= ninos; i++) { 
				var id = 'ninos-' + i;
				$('td.minor-age').append(
					$('<div />').append(
						$('<div />').addClass('age-container').append(
							$('<label />').html(label + ' ' + i)	
						).append(
						    $('<br />')
						).append(				
							$(select).clone().attr('id', id)
						)
					).html()
				);
				$('#' + id).selectmenu({width:48,style:'dropdown'});
			}
		} else {
			$('td.minor-age *').not('p').empty();
			$('td.minor-age p label').html('');		
		}
	});
	
	$('form#reservas').submit(function() {
		var rgxp = new RegExp(/\b\d{4}[\/-]\d{1,2}[\/-]\d{1,2}\b/);
		if (!rgxp.test($('#checkin').val())) {
			$('#checkin').val('Seleccione una fecha.');
			$('#checkin').siblings().click();
			return false;
		}
		if (!rgxp.test($('#checkout').val())) {
			$('#checkout').val('Seleccione una fecha.');
			$('#checkout').siblings().click();
			return false;
		}
		return true;
	});
	
	
	jQuery.fn.reset = function () {
	  $(this).each (function() { this.reset(); });
	}
	
	$('#events #name').keyup(function() {
		quitaNumeros($(this));
	});
	$('#events #telephone').keyup(function() {
		//soloTelefono($(this));
	});
	$('#events #people').keyup(function() {
		soloNumeros($(this));
	});
	
	
	$('form#events').submit(function() {
		$('#events-contact-form-messages').html('');
		
		quitaNumeros($('#name'));
		soloTelefono($('#telephone'));
		soloNumeros($('#people'));
		
		var tmpTel = $('#telephone').val();
		tmpTel = cadSoloNumeros(tmpTel);
		
		$('form#events label').css({color:'#333'});
		
		
		if (!$('#name').val()) {
			$('[for=name]').css({color:'#f00'});
			return false;
		}
		
		if (!$('#telephone').val() || tmpTel.length<10)
		{
			$('[for=telephone]').css({color:'#f00'});
			return false;
		}
		
		var emailRegex = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/;
		if (!emailRegex.test($('#email').val())) {
			$('[for=email]').css({color:'#f00'});
			return false;
		}		
		
		if(!$('#events #country').val())
		{
			$('[for=country-button]').css({color:'#f00'});
			return false;
		}
		
		
		var formdata = {
			name:$('#name').val(),
			company:$('#company').val(),
			telephone:$('#telephone').val(),
			email:$('#email').val(),
			people:$('#people').val(),
			meetingroom:$('#meetingroom').val(),
			event:$('#event').val(),
			catering:$('[name=catering]:checked').val(),
			date:$('#eventdate').val(),
			resort:$('#resort').val(),
			//country:$('#country option:selected').html(),
			country:$('#country option:selected').val(),
			comments:$('#comments').val()
		}
		$('#events-contact-form-espera').show('slow');
		$('#events-contact-form-espera').addClass('posrel').html(
			$('<img />').attr('src', 'http://prassets.clubparkroyal.com/hotels/ajax-loader.gif').addClass('posabs').css({top:'230px', left: '185px'})
		);		
		$('#events-contact-form-content').hide('slow');
		
		$.ajax({
			type: "POST",
			url: $(this).attr('action'),
			data: formdata,
			success: function(html) {
				var arr=html.split(':-');
				if(arr[0]=='1')
				{
					$('form#events').each (function(){
						this.reset();
					});
					$('#events #country').selectmenu('value','0');
					$('#events #meetingroom').selectmenu('value','0');
					$('#events #event').selectmenu('value','0');
				}
				$('#events-contact-form-messages').html(arr[1]);
				$('#events-contact-form-content').show('slow');
				$('#events-contact-form-espera').hide();
				
			}
		});
		
		return false;
	});
	
	$("select#adultos").change(function(){
		console.log($(this).attr('value'));
		
		var  ad=$(this).attr('value');
		var less=(8-ad);
		
		console.log(less);
		$("select#ninos option[value='0']").attr("selected", true);
		$("a#ninos-button  span.ui-selectmenu-status").text("-");
		$("td.minor-age").html("");
		if(less > 0){
			//$("select#ninos option").each(function(){
			$("ul#ninos-menu li a").each(function(){
				var optvalue=$(this).text();
				if(optvalue > less){
					$(this).css("display","none");
				} else {
					$(this).css("display","block");
				}
			});
		} else {
			 $("ul#ninos-menu li a").each(function(){
				var optvalue=$(this).text();
				if(optvalue != '-'){
					$(this).css("display","none");
				} else {
					$(this).css("display","block");
				}
			});
		}
		//$('select#ninos').selectmenu({width:48,style:'dropdown'});
	});
	$('#map-trigger').click(function() {
		setMap(
			$('#mapa-hotel').attr('id'), 
			$('#mapa-hotel').attr('lat'), 
			$('#mapa-hotel').attr('lng'), 
			parseInt($('#mapa-hotel').attr('zom')), 
			$('#mapa-hotel').attr('title'), 
			$('#hotel-address').html(),
			true
		);
	});
	$('#tab-cancun a, #tab-cozumel a, #tab-acapulco a, #tab-ixtapa a, #tab-huatulco a').click(function() { 
		setMap(
			$('#mapa-destino').attr('id'), 
			$('#mapa-destino').attr('lat'), 
			$('#mapa-destino').attr('lng'), 
			parseInt($('#mapa-destino').attr('zom')), 
			$('#mapa-destino').attr('title'), 
			$('#hotel-address').html(),
			false
		);
	});	
	
	$('input[name=traveloptions]').click(function(){
		
	
		if($('input[name=traveloptions]:checked').val()=='2'){
			$('#origin_row').show();
			$('#flighttype_row').show();
			//$('#origin_row').css('display','table-row');
			$("#checkin").datepicker("option", "minDate",+3)
		}else{
			$('#origin_row').hide();
			$('#flighttype_row').hide();
			//$('#origin_row').css('display','none');
			$("#checkin").datepicker("option", "minDate",+1)
		}	
	});
	
	if($('input[name=traveloptions]:checked').val()=='2'){
		console.log('click 2');
//		$('#origin_row').css("display","table-row"); se cambia por .show() para ser mostrado en  ie7
		$('#origin_row').show();
		$("#checkin").datepicker("option", "minDate",+3)
	}
	
	
	/****************************/
	/** Mostrar imagenes **/
	
	$("li#tab-all-inclusive, li#tab-all-inclusive > div > a > img, li#tab-all-inclusive > div > a > p,li#tab-all-inclusive > div > a > h2").click(function(){
		//alert(":)");
	});
	
	$("li#tab-habitaciones, li#tab-habitaciones > div > a > img, li#tab-habitaciones > div > a > p, li#tab-habitaciones > div > a > h2").click(function(){
		$.each($("div.bgloading"), function(){
			if($(this).html("")){
				$(this).append("<img  src=" + $(this).attr("id") + "  />");
			}
		});
	});
	
	/****************************/
	
});

//Se agregan las validaciones para el formulario de eventos y contacto
function cadSoloNumeros(cadena)
{
	for (var i=0, regreso='', validos="0123456789"; i<cadena.length; i++)
	{
		if (validos.indexOf(cadena.charAt(i)) != -1)
	    {
			regreso += cadena.charAt(i);
	    }
	}
	return regreso;
}

function quitaNumeros(objeto)
{
	var cadena = objeto.val();
	
	for (var i=0, regreso='', noValidos="0123456789"; i<cadena.length; i++)
	{
		if (noValidos.indexOf(cadena.charAt(i)) == -1)
	    {
			regreso += cadena.charAt(i);
	    }
	}
	objeto.val(regreso);		
}
function soloTelefono(objeto)
{
	var cadena = objeto.val();
	
	for (var i=0, regreso='', validos="0123456789 -()"; i<cadena.length; i++)
	{
		if (validos.indexOf(cadena.charAt(i)) != -1)
	    {
			regreso += cadena.charAt(i);
	    }
	}
	objeto.val(regreso);
}
function soloNumeros(objeto)
{
	var cadena = objeto.val();
	objeto.val(cadSoloNumeros(cadena));
}

function is_validemail(email) {
	return /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(email);
}



function validContactform(contactFormId){
	var valid = false;
	var counting=0;
	
	quitaNumeros($('#'+contactFormId+' #name'));
	soloTelefono($('#'+contactFormId+' #telephone'));
	
	var tmpTel = $('#'+contactFormId+' #telephone').val();
	tmpTel = cadSoloNumeros(tmpTel);
	
	console.log(contactFormId);
	
	if($("#" + contactFormId).find("input#name").attr('value') == "")
	{
		$("#" + contactFormId).find("span.name").show();
		//$('[for=name]').css({color:'#ff0000'});
	}
	else
	{
		$("#" + contactFormId).find("span.name").hide();
		//$('[for=name]').css({color:'#626262'});
		counting= counting + 1;
	}
	
	if($("#" + contactFormId).find("select#country").attr('value') == "")
	{
		$("#" + contactFormId).find("span.country").show();
		//$('[for=country]').css({color:'#ff0000'});
		//error
	}
	else
	{
		counting=counting + 1;
		$("#" + contactFormId).find("span.country").hide();
		//$('[for=country]').css({color:'#626262'});
	}
	
	if(is_validemail($("#" + contactFormId).find("input#email").attr('value')))
	{
		$("#" + contactFormId).find("span.mail").hide();
		//$('[for=email]').css({color:'#626262'});
		counting= counting + 1;
	}
	else
	{
		$("#" + contactFormId).find("span.mail").show();
		//$('[for=email]').css({color:'#ff0000'});
		
	}
	
	if($("#" + contactFormId).find("input#telephone").attr('value') != "" && tmpTel.length<10)
	{
		$("#" + contactFormId).find("span.tel").show();
		//$('[for=telephone]').css({color:'#ff0000'});
		
	}
	else
	{
		$("#" + contactFormId).find("span.tel").hide();
		//$('[for=telephone]').css({color:'#626262'});
		counting= counting + 1;
	}
	
	if($("#" + contactFormId).find("textarea#comments").attr('value') == "")
	{
		$("#" + contactFormId).find("span.comments").show();
		//$('[for=comments]').css({color:'#ff0000'});
		//error
	}
	else
	{
		$("#" + contactFormId).find("span.comments").hide();
		//$('[for=comments]').css({color:'#626262'});
		counting=counting + 1;
	}
	
	
	console.log("counting" + counting);
	if(counting == 5){
		return true;
	} else {
		return false;
	}
}
$(document).on('keyup','#contactform_id #name', function() {
	quitaNumeros($(this));
});


$("a#inlinecontactwindow").live("click",function(){
	/*setTimeout(function(){
		$('div.contact-window select#country').selectmenu({
			style:'dropdown',
			width:170,
			maxHeight: 300
		});
	
	},2000);*/
});
/*
$(document).on('focus','#contactform_id #country', function() {
	$(this).selectmenu({
		style:'popup',
		width:170,
		maxHeight: 300
	});
});
*/
function sendDataForm(){
 	var contactFormId = "contactform_id";
	if(validContactform(contactFormId))
	{
		console.log("id " + contactFormId);
		
		var dataForm = $("#" + contactFormId).serialize();
		console.log(dataForm);
		dataForm = dataForm.replace(/&/g, "/");
		dataForm = dataForm.replace(/=/g, "/");
		var  docurl= document.URL;	
		console.log(docurl);
		var datForm2 = 
		{
				resort:'1',
				name:$('#'+contactFormId+' #name').val(),
				address:$('#'+contactFormId+' #address').val(),
				state:$('#'+contactFormId+' #state').val(),
				city:$('#'+contactFormId+' #city').val(),
				zipcode:$('#'+contactFormId+' #zipcode').val(),
				country:$('#'+contactFormId+' select#country option:selected').val(),
				email:$('#'+contactFormId+' #email').val(),
				telephone:$('#'+contactFormId+' #telephone').val(),
				comments:$('#'+contactFormId+' #comments').val(),
				url:docurl
		}
		//console.log('/en/hotel-contact/contactmail/'+dataForm);
		$.ajax({
			type: "POST",
			url: '/'+getLang()+'/contactmail/',
			dataType: "html",
			data:datForm2,
			cache: false,
			success: function(responseHtml){
				console.log('['+responseHtml+']');
				if(responseHtml == "true")
				{ 
					//console.log('fue todo ok');
					$("#" + contactFormId). hide();
					$("#notification_false").hide();
					$("#notification_true").show();
				}
				else
				{
					$("#notification_true").hide();
					$("#notification_false").show();
				}
			}
		});
		setTimeout(function(){$.fancybox.close();},5000);
		
		
	}
}




function setTagBillboard(s){
	
	$(s).each(function(index,object){
		elementActive = object;
		
		slideActive = elementActive.getAttribute('href');
		
		var strReplace = new Array(16);
		
		strReplace[0]= 'http://';
		strReplace[1]= location.host;
		strReplace[2]= "/";
		strReplace[3]= "es";
		strReplace[4]= "en";
		strReplace[5]= "/";
		strReplace[6]= "park";
		strReplace[7]= "-";
		strReplace[8]= "royal";
		strReplace[9]= "-";
		strReplace[10]= "grand";
		strReplace[11]= "inn";
		strReplace[12]= "/";
		strReplace[13]= "huatulco";
		strReplace[14]= "cancun";
		strReplace[15]= "cozumel";
		strReplace[16]= "acapulco";
		strReplace[17]= "ixtapa";
		strReplace[18]= "/";
		strReplace[19]= "#slide";
		
		for(var i=0; i < strReplace.length; i++) {
			slideActive = slideActive.replace(strReplace[i],'');
		}
		imgTag = $("#tagimg"+slideActive).attr("src");
		
		$("#tag").css("background-image", "url("+imgTag+")");
	});
	
}




