﻿function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//window.onload="MM_preloadImages('images/temp/b_l1_2.gif','images/temp/b_l2_2.gif','images/temp/b_l3_2.gif','images/temp/b_l4_2.gif','images/temp/b_go2.jpg','images/temp/b1_2.gif','images/temp/b2_2.gif','images/temp/b3_2.gif','images/temp/b4_2.gif','images/temp/b5_2.gif','images/temp/b6_2.gif','images/temp/default_1_05_1.gif','images/temp/default_1_06_1.gif','images/temp/default_1_07_1.gif','images/temp/default_1_08_1.gif','images/temp/default_1_09_1.gif','images/temp/default_1_10_1.gif','images/temp/default_1_11_1.gif','images/home/b_s2.gif','images/home/b_s_p2.gif','images/home/b_tab_01_2.gif','images/home/b_tab_02_2.gif','images/home/b_tab_03_2.gif','images/home/b_tab_04_2.gif','images/home/b_tab_05_2.gif','images/home/b_go2.gif')";
function fReset(o,p) {
if (o.value==p) { o.value='';}
}

function fResetPwd(o,p) {
if (o.innerHTML==p) { o.innerHTML='';}
}

cW=null;
function MM_openBrWindow(theURL,winName,features) { //v2.0
  if (null!=cW) cW.close();
  cW = window.open(theURL,winName,features);
}

function showMask(objTxt) {
val = objTxt.value;
var mask='';
for (var i=0;i<val.length;i++){ 
	mask=mask + '*';
}
document.getElementById('showMaskPwd').innerHTML = mask;
}

 function bookmarkthis(title,url) {
  if (window.sidebar) { // firefox
     window.sidebar.addPanel(title, url, "");
  } else if (document.all) { // IE
     window.external.AddFavorite(url, title);
  } else if (window.opera && window.print) { // opera
     var elem = document.createElement('a');
     elem.setAttribute('href',url);
     elem.setAttribute('title',title);
     elem.setAttribute('rel','sidebar');
     elem.click();
  }
}
// Function		:validate(form)
function validate(form,lang) {
var errmsg='', errOut='', posn, ifocuselem, pass=true;
aErro = new Array(15);
switch (lang) {
	case "pt":
		aErro[0] = "\t\n";
		aErro[1] = "\tO seu nome\n";
		aErro[2] = "Por favor, preencha todos os campos obrigatórios\n";
		aErro[3] = "\tO nome de cada membro do grupo\n";
		aErro[4] = "\tApartamento(s) pretendido(s)\n";
		aErro[5] = "\tO seu e-mail\n";
		aErro[6] = "\tPor favor, pode confirmar o seu e-mail\n";		
		aErro[7] = "\tPor favor confirme su dirección de correo electrónico\n";	
		aErro[8] = "\tA data de chegada\n";
		aErro[9] = "\tA data de partida\n";
		aErro[10] = "\tO seu contacto telefónico\n";
		aErro[11] = "\tDomicilio\n";
		aErro[12] = "\tPaís\n";
		aErro[13] = "\tCódigo postal\n";		
		aErro[14] = "\tA data de partida tem que ser depois a data de chegada\n";				
		aErro[15] = "\tPor favor, verifique que lê e aceita as Condições\n";
	break;
	case "es":
		aErro[0] = "\t\n";
		aErro[1] = "\tNombre de contacto\n";
		aErro[2] = "Por favor rellene los campos obligatorios del formulario, marcados con *\n";
		aErro[3] = "\tTodos los nombres en el grupo\n";
		aErro[4] = "\tApartamento(s) solicitado(s)\n";
		aErro[5] = "\tDirección de correo electrónico\n";
		aErro[6] = "\tPor favor confirme su dirección de correo electrónico\n";		
		aErro[7] = "\tDomicilio\n";	
		aErro[8] = "\tFecha de llegada\n";
		aErro[9] = "\tFecha de salida\n";
		aErro[10] = "\tNúmero(s) de teléfono de contacto\n";
		aErro[11] = "\tDomicilio\n";
		aErro[12] = "\tPaís\n";
		aErro[13] = "\tCódigo postal\n";		
		aErro[14] = "\tLa fecha de salida debe ser después de la fecha de llegada\n";				
		aErro[15] = "\tPor favor seleccione la casilla para aceptar los términos y condiciones\n";
	break;	
	default:
		aErro[0] = "\tThe title\n";
		aErro[1] = "\tYour name/company name\n";
		aErro[2] = "Please fill out the required fields in this form:\n";
		aErro[3] = "\tThe names of each member in your group\n";
		aErro[4] = "\tApartment(s) required\n";
		aErro[5] = "\tA valid e-mail address\n\n";
		aErro[6] = "\tPlease confirm your e-mail address\n";		
		aErro[7] = "\tYour address\n";	
		aErro[8] = "\tYour arrival date\n";
		aErro[9] = "\tYour departure date\n";
		aErro[10] = "\tYour contact number\n";
		aErro[11] = "\tYour area\n";
		aErro[12] = "\tYour country\n";
		aErro[13] = "\tYour postcode\n";		
		aErro[14] = "\tThe departure date must be after your Arrival date\n";				
		aErro[15] = "\tPlease tick the box to accept the Terms and Conditions\n";
	break;
}

switch (form.name) {
case "frmB_contact":
	for (x=0; x<form.elements.length; x++) {
		switch (form.elements[x].name) {
		case "subs_name":if (form.elements[x].value.length < 3) {
			errmsg+=aErro[1];
			ifocuselem = x;
		}
		break;
		case "subs_email":
		//if (form.elements[x].value!='') {
			posn=form.elements[x].value.indexOf('\u0020');
			if (form.elements[x].value.length < 5) {
				errmsg+=aErro[5];
				ifocuselem=x
			}

			else if (posn>=0) {
					errmsg+=aErro[5];
					ifocuselem=x
				}
			else {
				posn=form.elements[x].value.indexOf('@');
				if (posn==-1) {
					errmsg+=aErro[5];
					ifocuselem=x
				} else {
				posn=form.elements[x].value.indexOf('.',posn+2);
				if (posn==-1) {
					errmsg+=aErro[5];
					ifocuselem=x
				}
				}
			} 
		//}
		break;
		}
	}
break;
case "frmB_booking":
	for (x=0; x<form.elements.length; x++) {
		switch (form.elements[x].name) {
		case "frmB_contactname":if (form.elements[x].value.length < 3) {
			errmsg+=aErro[1];
			ifocuselem = x;
		}
		break;
		case "frmB_address":if (form.elements[x].value.length < 10) {
			errmsg+=aErro[7];
			ifocuselem = x;
		}
		break;
		case "frmB_country":if (form.elements[x].value.length < 2) {
			errmsg+=aErro[12];
			ifocuselem = x;
		}
		break;		
		case "frmB_telno":if (form.elements[x].value.length < 6) {
			errmsg+=aErro[10];
			ifocuselem = x;
		}
		break;
		case "frmB_allnames":if (form.elements[x].value.length < 3) {
			errmsg+=aErro[3];
			ifocuselem = x;
		}
		break;
		case "frmB_apts":if (form.elements[x].value.length == 0) {
			errmsg+=aErro[4];
			ifocuselem = x;
		}
		break;
		case "frmB_Arrivalday":
			frmB_Arrivalday=form.elements[x].value;
			frmB_Arrival = x;
		break;
		case "frmB_Arrivalmonth":frmB_Arrivalmonth=form.elements[x].value;
		break;
		case "frmB_Arrivalyear":frmB_Arrivalyear = form.elements[x].value;if (form.elements[x].value.length == 0 || frmB_Arrivalmonth == '' || frmB_Arrivalday == '')  {
			errmsg+=aErro[8];
			ifocuselem = frmB_Arrival;
		}
		break;
		case "frmB_Leavingday":
			frmB_Leavingday=form.elements[x].value;
			frmB_Leaving = x;
		break;
		case "frmB_Leavingmonth":frmB_Leavingmonth=form.elements[x].value;
		break;
		case "frmB_Leavingyear":
		if (form.elements[x].value.length == 0 || frmB_Leavingmonth == '' || frmB_Leavingday == '')  {
			errmsg+=aErro[9];
			ifocuselem = frmB_Leaving;
		} else if (form.elements[x].value < frmB_Arrivalyear && frmB_Leavingmonth < frmB_Arrivalmonth && frmB_Leavingday < frmB_Arrivalday) { 
			errmsg+=aErro[14];
		}
		break;
		case "frmB_email1":
		//if (form.elements[x].value!='') {
			frmB_email1 = form.elements[x].value;
			posn=form.elements[x].value.indexOf('\u0020');
			if (form.elements[x].value.length < 5) {
				errmsg+=aErro[5];
				ifocuselem=x
			}

			else if (posn>=0) {
					errmsg+=aErro[5];
					ifocuselem=x;
				}
			else {
				posn=form.elements[x].value.indexOf('@');
				if (posn==-1) {
					errmsg+=aErro[5];
					ifocuselem=x;
				} else {
				posn=form.elements[x].value.indexOf('.',posn+2);
				if (posn==-1) {
					errmsg+=aErro[5];
					ifocuselem=x;
				}
				}
			} 
		//}
		break;
		case "frmB_email2":
			if (form.elements[x].value!=frmB_email1) {
				errmsg+=aErro[6];
				ifocuselem=x;
			}
		break;
		case "frmB_terms":
			if (form.elements[x].checked == false) {
				errmsg+=aErro[15];
				ifocuselem=x;
			}		
		break;
		}
	}
break;							
}
if (errmsg!='') {
	errOut= "_______________________________________________________________\n";	
	errOut+=aErro[2];
	errOut+=errmsg;
	errOut+="\n_______________________________________________________________\n";
	alert(errOut);
	eval("form.elements[" + ifocuselem + "].focus();");
	pass=false;
}
else {
	form.submit();	
	pass=true;
}
return (pass);
}

function OnNumDaysChange(form,lang)
{
var sErro;
switch (lang) {
	case "pt":
		sErro = "A data de partida tem que ser depois a data de chegada\n";				
	break;
	case "es":
		sErro = "La fecha de salida debe ser después de la fecha de llegada\n";				
	break;	
	default:
		sErro = "The departure date must be after your Arrival date\n";				
	break;
}

	
	if (form == null || form.frmB_Arrivalyear.value == null) 
		return false;
	
	var numDays = 1;	// Default 1 day
	var dd,mm,yy, rc;
	var start_dt, end_dt;
	var startTime = 0, endTime = 0;  
	yy = form.frmB_Arrivalyear.value + '.' + form.frmB_Arrivalmonth.value;

	mm = form.frmB_Arrivalmonth.value;

	dd = form.frmB_Arrivalday.value;
	var d = new Date();
	start_dt = new Date(yy,mm-1,dd,d.getUTCHours(),d.getUTCMinutes(),d.getUTCMilliseconds());

	var	msPerDay = 24*60*60*1000;
	
	yy = form.frmB_Leavingyear.value + '.' + form.frmB_Leavingmonth.value;
	mm = form.frmB_Leavingmonth.value;
	
	dd = form.frmB_Leavingday.value;
	end_dt = new Date(yy,mm-1,dd,d.getUTCHours(),d.getUTCMinutes(),d.getUTCMilliseconds());
	numDays = Math.round((end_dt-start_dt)/msPerDay);

	if (numDays < 0)  {
		alert(sErro);
		numDays = 'n/a';
	} 
	form.frmB_nights.value = numDays;
	return true;
}

