var ns6=document.getElementById&&!document.all;
//Recogemos el elemento que
//anteriormente produjo error y el actual
var previous = '';
var elemento = '';
/*
 * mapa = 0 Oficina
 * mapa = 1 Apartamento
 */
var map = 0;
/*
 * Para controlar las imagenes que se muestran
 * en dotacion cuando nos situamos sobre la lupa
 */
function show_picture(num)
{
	var imag = document.getElementById("cama"+num);
	imag.style.display="block";
}

function noshow_picture(num)
{
    var imag = document.getElementById("cama"+num);
    imag.style.display="none";
}
/*
 * 
 */

/*
 * Para verificar formularios...
 */
function setColorPrevious(input){
	if (input != document.forms['reserve'].departure || input != document.forms['reserve'].arrive)
		input.style.backgroundColor="white";
	else
		input.style.backgroundColor="lightgrey";
}
function setColorPrevious2(input){
	input.style.backgroundColor="white";
}
function highlight(input){
	input.style.backgroundColor="yellow";
}
function verify(){
	if (document.forms['reserve'].arrive.value == 'Pinche el calendario'
		||document.forms['reserve'].arrive.value == 'Click on the calendar'
		|| document.forms['reserve'].arrive.value == 'Klik op de kalender')
	{
		elemento = document.forms['reserve'].arrive;
		if (previous!=elemento && previous!='')
			setColorPrevious(previous);
		previous = elemento;
		document.forms['reserve'].arrive.focus();
		highlight(document.forms['reserve'].arrive);
		return false;
	}
	if (document.forms['reserve'].departure.value == 'Pinche el calendario'
		||document.forms['reserve'].departure.value == 'Click on the calendar'
			|| document.forms['reserve'].departure.value == 'Klik op de kalender')
	{
		elemento = document.forms['reserve'].departure;
		if (previous!=elemento && previous!='')
			setColorPrevious(previous);
		previous = elemento;
		document.forms['reserve'].departure.focus();
		highlight(document.forms['reserve'].departure);
		return false;
	}
	if (document.forms['reserve'].personas.value == ''){
		elemento = document.forms['reserve'].personas;
		if (previous!=elemento && previous!='')
			setColorPrevious(previous);
		previous = elemento;
		document.forms['reserve'].personas.focus();
		highlight(document.forms['reserve'].personas);
		return false;
	}
	
	if (document.forms['reserve'].name.value == '')
	{
		elemento = document.forms['reserve'].name;
		if (previous!=elemento && previous!='')
			setColorPrevious(previous);
		previous = elemento;
		document.forms['reserve'].name.focus();
		highlight(document.forms['reserve'].name);
		return false;
	}
	if (document.forms['reserve'].scndname.value == '')
	{
		elemento = document.forms['reserve'].scndname;
		if (previous!=elemento && previous!='')
			setColorPrevious(previous);
		previous = elemento;
		document.forms['reserve'].scndname.focus();
		highlight(document.forms['reserve'].scndname);
		return false;
	}
	if (document.forms['reserve'].tlfn.value == '')
	{
		elemento = document.forms['reserve'].tlfn; 
		if (previous!=elemento && previous!='')
			setColorPrevious(previous);
		previous = elemento;
		document.forms['reserve'].tlfn.focus();
		highlight(document.forms['reserve'].tlfn);
		return false;
	}
	if (document.forms['reserve'].mail.value == '')
	{
		elemento = document.forms['reserve'].mail;
		if (previous!=elemento && previous!='')
			setColorPrevious(previous);
		previous = elemento;
		document.forms['reserve'].mail.focus();
		highlight(document.forms['reserve'].mail);
		return false;
	}
	return true;
}
function verify2(){
	if (document.forms['contacto'].name.value=='')
	{
		elemento = document.forms['contacto'].name;
		if (previous!=elemento && previous!='')
			setColorPrevious2(previous);
		previous = elemento;
		document.forms['contacto'].name.focus();
		highlight(document.forms['contacto'].name);
		return false;
	}
	if (document.forms['contacto'].scnd.value=='')
	{
		elemento = document.forms['contacto'].scnd;
		if (previous!=elemento && previous!='')
			setColorPrevious2(previous);
		previous = elemento;
		document.forms['contacto'].scnd.focus();
		highlight(document.forms['contacto'].scnd);
		return false;
	}
	if (document.forms['contacto'].mail.value=='')
	{
		elemento = document.forms['contacto'].mail;
		if (previous!=elemento && previous!='')
			setColorPrevious2(previous);
		previous = elemento;
		document.forms['contacto'].mail.focus();
		highlight(document.forms['contacto'].mail);
		return false;
	}
	if (document.forms['contacto'].data.value=='')
	{
		elemento = document.forms['contacto'].data;
		if (previous!=elemento && previous!='')
			setColorPrevious2(previous);
		previous = elemento;
		document.forms['contacto'].data.focus();
		highlight(document.forms['contacto'].data);
		return false;
	}
	return true;
}

/*
 * Controlar las entradas en el formulario
 */
function onlynumbers(e){
	var key = ns6 ? e.charCode : window.event.keyCode;
	return ((key > 48 && key < 59) || key == 8 || key == 0);
}

function enterpressed(e){
	var key = ns6 ? e.charCode : window.event.keyCode;
	if (key==13){
		if (verify())
			document.forms['reserve'].submit();
	};
}

function enterpressed2(e){
	var key = ns6 ? e.charCode : window.event.keyCode;
	if (key==13){
		if (verify())
			document.forms['contacto'].submit();
	};
}
/*
 *
 */
/*
 *Nueva ventana para ver el plano
 */
function newWindow(mypage, myname, w, h, scroll, pos){
	if(pos=="center"){
		LeftPosition=(screen.width)?(screen.width-w)/2:100;
		TopPosition=(screen.height)?(screen.height-h)/2:100;
	}
	var settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	window.open(mypage, '_blank', settings);
}
/*
 *
 */
/*
 * Nueva ventana para galería fotos
 */
function photoGallery(mypage){
	LeftPosition=(screen.width)?(screen.width-552)/2:100;
	TopPosition=(screen.height)?(screen.height-475)/2:100;
	var settings='width=630,height=530,top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	window.open(mypage, '_blank', settings);
}
/*
 * 
 */
/*
 * Para controlar los eventos del mapa en la sección de contacto
 */
function select_map(num, root, lang){
	var elem;
	switch (num){
	case 0:
		map = 0;
		elem = document.getElementById('office_up-'+lang);
		elem.style.backgroundImage="url("+root+"/themes/albirholiday/graphics/oficina_on_up-"+lang+".jpg)";
		elem = document.getElementById('office_down-'+lang);
		elem.style.backgroundImage="url("+root+"/themes/albirholiday/graphics/oficina_on_down-"+lang+".jpg)";
		elem = document.getElementById('apartment_up-'+lang);
		elem.style.backgroundImage="url("+root+"/themes/albirholiday/graphics/apartamento_off_up-"+lang+".jpg)";
		elem = document.getElementById('apartment_down-'+lang);
		elem.style.backgroundImage="url("+root+"/themes/albirholiday/graphics/apartamento_off_down-"+lang+".jpg)";
		elem = document.getElementById('map_apartment');
		elem.style.display = "none";
		elem = document.getElementById('map_office');
		elem.style.display = "block";
		break;
	case 1:
		map = 1;
		elem = document.getElementById('apartment_up-'+lang);
		elem.style.backgroundImage="url("+root+"/themes/albirholiday/graphics/apartamento_on_up-"+lang+".jpg)";
		elem = document.getElementById('apartment_down-'+lang);
		elem.style.backgroundImage="url("+root+"/themes/albirholiday/graphics/apartamento_on_down-"+lang+".jpg)";
		elem = document.getElementById('office_up-'+lang);
		elem.style.backgroundImage="url("+root+"/themes/albirholiday/graphics/oficina_off_up-"+lang+".jpg)";
		elem = document.getElementById('office_down-'+lang);
		elem.style.backgroundImage="url("+root+"/themes/albirholiday/graphics/oficina_off_down-"+lang+".jpg)";
		elem = document.getElementById('map_office');
		elem.style.display = "none";
		elem = document.getElementById('map_apartment');
		elem.style.display = "block";
		break;
	}
}

function preselect_map(num, root, lang){
	//Si el mapa seleccionado es distinto del elemento en el que nos hemos posicionado ...
	if (map != num){
		var elem;
		switch (num){
			case 0:
				elem = document.getElementById('office_up-'+lang);
				elem.style.backgroundImage="url("+root+"/themes/albirholiday/graphics/oficina_on_up-"+lang+".jpg)";
				elem = document.getElementById('office_down-'+lang);
				elem.style.backgroundImage="url("+root+"/themes/albirholiday/graphics/oficina_on_down-"+lang+".jpg)";
				break;
			case 1:
				elem = document.getElementById('apartment_up-'+lang);
				elem.style.backgroundImage="url("+root+"/themes/albirholiday/graphics/apartamento_on_up-"+lang+".jpg)";
				elem = document.getElementById('apartment_down-'+lang);
				elem.style.backgroundImage="url("+root+"/themes/albirholiday/graphics/apartamento_on_down-"+lang+".jpg)";
				break;
			}
	}
}

function unpreselect_map(num, root, lang){
	//Si el mapa seleccionado es distinto del elemento en el que nos hemos posicionado ...
	if (map != num){
		var elem;
		switch (num){
			case 0:
				elem = document.getElementById('office_up-'+lang);
				elem.style.backgroundImage="url("+root+"/themes/albirholiday/graphics/oficina_off_up-"+lang+".jpg)";
				elem = document.getElementById('office_down-'+lang);
				elem.style.backgroundImage="url("+root+"/themes/albirholiday/graphics/oficina_off_down-"+lang+".jpg)";
				break;
			case 1:
				elem = document.getElementById('apartment_up-'+lang);
				elem.style.backgroundImage="url("+root+"/themes/albirholiday/graphics/apartamento_off_up-"+lang+".jpg)";
				elem = document.getElementById('apartment_down-'+lang);
				elem.style.backgroundImage="url("+root+"/themes/albirholiday/graphics/apartamento_off_down-"+lang+".jpg)";
				break;
			}
	}
}
/*
 *
 */
