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_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_findObj(n, d) { //v3.0
  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); 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];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  top.window.name="NetViagens";
  features += ",resizable";
  window.open(theURL,winName,features);
}
function MM_openBrWindow2(theURL,winName,features) { //v2.0
  top.window.name="NetViagens";
  window.open(theURL,winName,features);
}

function MM_openBrWindowRedirect(theURL,theRedirectURL, winName,features) { //v2.0
  top.window.name="NetViagens";
  features += ",resizable";
  window.open(theURL,winName,features);
  window.location=theRedirectURL;
}

function tagsOver(strTop,strBg,strInfo,strBottom,iVar){
	srcTop[iVar].src = "_images/homepage/"+strTop;
	srcBg[iVar].background = "_images/homepage/"+strBg;
	srcLabel[iVar].src = "_images/homepage/"+strInfo;
	srcBottom[iVar].src = "_images/homepage/"+strBottom;	
}

			
function desejoPesquisar(num){
	document.frmPesquisa.pesquisa[num].checked = true;
	if(num == 0){
		document.getElementsByName('ifrMotor')[0].src = "Engines/motor_aviao_hotel.aspx";
		document.getElementsByName('op0')[0].className = "opcao_selected";
		document.getElementsByName('op1')[0].className = "opcao";
		document.getElementsByName('op2')[0].className = "opcao";
		document.getElementsByName('op3')[0].className = "opcao";
		document.getElementsByName('op4')[0].className = "opcao";
		changeImage(1);
	}
	if(num == 1){
		document.getElementsByName('ifrMotor')[0].src = "Engines/motor_aviacao.aspx";	
		document.getElementsByName('op0')[0].className = "opcao";
		document.getElementsByName('op1')[0].className = "opcao_selected";
		document.getElementsByName('op2')[0].className = "opcao";
		document.getElementsByName('op3')[0].className = "opcao";
		document.getElementsByName('op4')[0].className = "opcao";
		changeImage(2);
	}
	if(num == 2){
		document.getElementsByName('ifrMotor')[0].src = "Engines/motor_hotelaria.aspx";
		document.getElementsByName('op0')[0].className = "opcao";
		document.getElementsByName('op1')[0].className = "opcao";
		document.getElementsByName('op2')[0].className = "opcao_selected";
		document.getElementsByName('op3')[0].className = "opcao";
		document.getElementsByName('op4')[0].className = "opcao";
		changeImage(3);
	}
	if(num == 3){
		document.getElementsByName('ifrMotor')[0].src = "Engines/motor_ferias.aspx";
		document.getElementsByName('op0')[0].className = "opcao";
		document.getElementsByName('op1')[0].className = "opcao";
		document.getElementsByName('op2')[0].className = "opcao";
		document.getElementsByName('op3')[0].className = "opcao_selected";
		document.getElementsByName('op4')[0].className = "opcao";
		changeImage(4);
	}
	if(num == 4){
		document.getElementsByName('ifrMotor')[0].src = "Engines/motor_escapadelas.aspx";
		document.getElementsByName('op0')[0].className = "opcao";
		document.getElementsByName('op1')[0].className = "opcao";
		document.getElementsByName('op2')[0].className = "opcao";
		document.getElementsByName('op3')[0].className = "opcao";
		document.getElementsByName('op4')[0].className = "opcao_selected";	
		changeImage(5);
	}
}

function changeImage(val) {
	for (i=1;i <= 5; i++){
		if (i == val){
			document.images('img' + i).src = myimages[i+5].src;
		}else{
			document.images('img' + i).src = myimages[i].src;
		}
		
	}
}

function MM_openBrWindow(theURL,winName,features,onMousePos)  //v2.0
{
	if (window.event)
	{           
		x=window.event.screenX;
		y=window.event.screenY;
		if (String(onMousePos)=="undefined" || String(onMousePos)=="1") 
	    features="top="+y+",left="+x+","+features;
		else 
		  features="top=5,left=5,"+features;
	}                       
	window.name="rbottom";
  window.open(theURL,winName,features,false);
}


function validateEmail(emailFieldName){

  emailObj = document.getElementsByName(String(emailFieldName))[0];
  if(emailObj != null)
  {
		var reg = /^(\w+((\.|\-)\w+)*)@((\w+((\.|\-)\w+)*\.)+)([a-z\d]{2,3})$/i;
    control = reg.test(emailObj.value);
    if(!control) 
      return false;
      
    return true;
  }
  return false;
}

function displayRooms(val)
{	
	for(i=1;i<=3;i++)
	{
		obj = document.getElementById("tbl_rooms" + i);
		if (obj != null)
		{
			if (i <= val)
				obj.style.display = 'block';
			else
				obj.style.display = 'none';
		}
	}
}

function ValidateEmail(email)
{
	var reg = /^(\w+(?:(\.|\-)\w+)*)@((?:\w+(?:(\.|\-)\w+)*\.)+)([a-z\d]{2,})$/i;			  
	return reg.test(email);
}

function ValidatePassword(pass, minLength)
{
	return String(pass).length >= minLength;
}

function ValidationSimpleLogin()
{			
	var minPassLength = 1;
	var emailObj = document.getElementById("fldEmail");
	var passObj = document.getElementById("fldPassword");
			
	if (!ValidateEmail(emailObj.value))
	{
		emailObj.focus();
		alert(unescape("O%20E-mail%20n%E3o%20corresponde%20a%20um%20formato%20v%E1lido."));
		return false;
	}
	
	if (!ValidatePassword(passObj.value, minPassLength))
	{
		passObj.focus();
		alert(unescape("A%20password%20deve%20ter%2C%20no%20m%EDnimo%2C%20") + minPassLength + " caracteres.");
		return false;
	}
		
	return true;
}


//Header Form Functions
function IsEnter(e)
{
	
	if(!e) window.event;
	
	var key = e.keyCode;
	
	if(key == 13)
	{
		ValidateTopSearchForm();
	}
}
function ReEnterText(aObject)
{
	if(aObject.value == "pesquise aqui" || aObject.value == "")
		aObject.value = "pesquise aqui";		
}

function ClearText(aObject)
{
	if(aObject.value == "pesquise aqui")
		aObject.value = "";
}

function ValidateTopSearchForm()
{
	var aForm = document.getElementById("topSearchForm");
	var displayedValue = document.getElementById("searchDisplay");
	
	if(aForm == null || displayedValue == null)
		return;
	
	aForm.search.value = displayedValue.value;
		
	if(aForm.search.value == "" || aForm.search.value == "pesquise aqui")
	{
		alert("Tem de introduzir um texto de pesquisa valido");
		return;
	}
	
	aForm.submit();
}

function ValidateHomepageRegister(aForm)
{
	var alertDiv = document.getElementById("message");
	
	if(aForm.emailFromHome.value == "")
	{
		alertDiv.innerHTML =  "Tem de introduzir um endereco de email";
		return false;
	}
	
	if(!ValidateEmail(aForm.emailFromHome.value))
	{
		alertDiv.innerHTML = "Tem de introduzir um endereco de email valido";
		return false;
	}
	
	aForm.submit();
}