// JavaScript Document

//validar formulario de contacto
function validar(){
	if(document.contacto.nombreco.value.length==0 || document.contacto.tlf.value.length==0 || document.contacto.email.value.length==0 || document.contacto.comentario.value.length==0){
		alert('Todos los campos son obligatorios, por favor, revise y rellene correctamente el formulario. Gracias.');	
	}else{
		
		//validar mail
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.contacto.email.value)){
			document.contacto.submit(); 
		}else{
			alert('El email introducido no es correcto, por favor, verifique el email.');
		}
		
	}
}

//popup radio
function reservas(a_str_windowURL, a_str_windowName, a_int_windowWidth, a_int_windowHeight, a_bool_scrollbars, a_bool_resizable, a_bool_menubar, a_bool_toolbar, a_bool_addressbar, a_bool_statusbar, a_bool_fullscreen){
	var int_windowLeft = (screen.width - a_int_windowWidth) / 2;
	var int_windowTop = (screen.height - a_int_windowHeight) / 2;
	var str_windowProperties = 'height=' + a_int_windowHeight + ',width=' + a_int_windowWidth + ',top=' + int_windowTop + ',left=' + int_windowLeft + ',scrollbars=' + a_bool_scrollbars + ',resizable=' + a_bool_resizable + ',menubar=' + a_bool_menubar + ',toolbar=' + a_bool_toolbar + ',location=' + a_bool_addressbar + ',statusbar=' + a_bool_statusbar + ',fullscreen=' + a_bool_fullscreen + '';
	var obj_window = window.open(a_str_windowURL, a_str_windowName, str_windowProperties)
	if (parseInt(navigator.appVersion) >= 4) {
		obj_window.window.focus();
	}
}


//validar formulario reserva online.
function validar_reserva(){
	if(document.chooseDateForm.personas.value.length == 0){
		alert('Error: No ha especificado el numero de personas, porfavor, rellene el campo personas.');
	}else{
		if(document.chooseDateForm.nombre.value.length == 0){
			alert('Error: No ha especificado su nombre, porfavor, rellene el campo nombre.');
		}else{
			if(document.chooseDateForm.email.value.length == 0){
				alert('Error: No ha especificado su e-mail, porfavor, rellene el campo e-mail.');
			}else{
				if(document.chooseDateForm.email.value != document.chooseDateForm.email2.value){
					alert('Error: Ha especificados dos e-mails distintos, porfavor, escriba el mismo e-mail en el campo e-mail y confirmacion de e-mail.');
				}else{
					if(document.chooseDateForm.tlf.value.length == 0){
						alert('Error: No ha especificado su telefono, porfavor, rellene el campo telefono.');
					}else{
						document.chooseDateForm.submit();
					}
				}
			}
		}
	}
}

// SCROLL

scrollList=new Array();

function registraScroll(idAbajo, idArriba, div, velAbajo, velArriba)
{
  if(scrollList[idAbajo]==null) scrollList[idAbajo]=new Array();
  if(scrollList[idArriba]==null) scrollList[idArriba]=new Array();
  scrollList[idAbajo].push(new Array(div, velAbajo));
  scrollList[idArriba].push(new Array(div, velArriba));
}

window.onload=inicializar;

function getEl(elementId)
{
  return document.getElementById(elementId);
}

function inicializar()
{
  for(key in scrollList)
  {
	  var elemento=getEl(key);
	  elemento.onmouseover=iniciaScroll;
	  elemento.onmouseout=detieneScroll;
  }
}

function iniciaScroll()
{
  scrollDivs=new Array();
  velDivs=new Array();
  for(key in scrollList[this.id])
  {
	  scrollDivs.push(getEl(scrollList[this.id][key][0]));
	  velDivs.push(scrollList[this.id][key][1]);
  }
  identificador=setInterval('scrollNow()', 50);
}

function detieneScroll()
{
  clearInterval(identificador);
}

function scrollNow()
{
  for(key in scrollDivs)
  {
  var desplazamientoActual=scrollDivs[key].scrollTop;
  var nuevoDesplazamiento=desplazamientoActual+velDivs[key];
  scrollDivs[key].scrollTop=nuevoDesplazamiento;
  }
}
