function toggle(div_id) {
	var el = document.getElementById(div_id);
	if ( el.style.display == 'none' ) {	el.style.display = 'block';}
	else {el.style.display = 'none';}
}
function blanket_size(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}
	var blanket = document.getElementById('blanket');
	blanket.style.height = blanket_height + 'px';
	var popUpDiv = document.getElementById(popUpDivVar);
	popUpDiv_height=blanket_height/2-160;//160 is half popup's height
	popUpDiv.style.top = 100/*popUpDiv_height*/ + 'px';
	
}
function window_pos(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerHeight;
	} else {
		viewportwidth = document.documentElement.clientHeight;
	}
	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
		window_width = viewportwidth;
	} else {
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
			window_width = document.body.parentNode.clientWidth;
		} else {
			window_width = document.body.parentNode.scrollWidth;
		}
	}
	var popUpDiv = document.getElementById(popUpDivVar);
	window_width=window_width/2-310;//310 is half popup's width
	popUpDiv.style.right = window_width + 'px';
}
function popup(windowname) {
	$('#error_row').hide();
	$('#error').html('');
	blanket_size(windowname);
	window_pos(windowname);
	toggle('blanket');
	toggle(windowname);
	return false;		
}
function show_loading()
{
	/*$('#loading').show();
	blanket_size('loading');
	$('#blanket').show();*/
}
function hide_loading()
{
	//$('#loading').hide();
	//blanket_size('loading');
	//$('#blanket').hide();
}
function sleep(milliSeconds){
	var startTime = new Date().getTime(); // get the current time
	while (new Date().getTime() < startTime + milliSeconds); // hog cpu
}

function bloquear(number_of_rooms){
	var ok=0;
	var txt='Debe elegir tipo de alojamiento';
	/*if(document.form_blq.infhab[document.form_blq.infhab.selectedIndex].value=='-1'){
		ok=0;
		alert('Debe elegir tipo de alojamiento');
	}*/
	
	
	if (document.form_blq.infhab.length>0){
		for ( var i = 0; i < document.form_blq.infhab.length; i++ ){
			if (document.form_blq.infhab[i].checked ){
				ok=1;
			}
		}
	}else{
		if (document.form_blq.infhab.checked ){
			ok=1;
		}
	}

	if (ok<1){
		alert (txt);
		return false;
	}
	
	if (number_of_rooms == 2)
	{
		var ok=0;
		if (document.form_blq.infhab_2.length>0){
			for ( var i = 0; i < document.form_blq.infhab_2.length; i++ ){
				if (document.form_blq.infhab_2[i].checked ){
					ok=1;
				}
			}
		}else{
			if (document.form_blq.infhab_2.checked ){
				ok=1;
			}
		}
	}
	
	if (ok<1){
		alert (txt);
		return false;
	}
	show_loading();
	document.form_blq.submit();
	
}

function subscribe_email(url)
{
	var email = $('#searchbox').val();
	email = $.trim(email);
	if(email!='')
	{	
		$("#err").html('');
		$("#error_forgot_password").hide();
		var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
		if (email.search(emailRegEx) == -1)
		{
			alert('Please enter valid email address');
		}
		else
		{
			$('#searchbox').addClass( 'newsletter_loading' );
			$.post(url,{email:email},function(data,status)
			{
				$('#newsletter_response').html('Te has suscrito a nuestro bolet&iacute;n. Revisa tu correo para completar la suscripci&oacute;n.');
				
				//Thank you for subscribing to Escapadas.com
				
			});
		}
	}
	else
		alert('Please enter email address');
	
	

	
	return false;

}
