// JavaScript Document



// preload images

function preloadImages(the_images_array)



{



	for (loop=0; loop < the_images_array.length; loop++)



	{



		imageover[loop] = new Image();



		imageover[loop].src = "images/menu/" + the_images_array[loop] + "_on.jpg";



	}



}





// swap images from the upper menu

function swap(i1,i2){  



	var temp = i1.src;



//	alert(temp);



	i1.src = imageover[i2].src;



//	alert(i1.src);



	imageover[i2].src = temp;



//	alert(imageover[i2].src);



}  



// verificação dos campos do formulário



function checkfields(){

	 if ( document.form1.nome.value == "" ||

	      document.form1.email.value == "")

		  {

		   alert(" O campo Nome e Email são obrigatórios! ")

		   document.form1.action=history.go(0);

		   }

	 else{ document.form1.action="index.php"}

}


function valid_Email(email, msg){			
	email2='%'+email+'%';
	var re=/\%[a-z\-\_0-9]+(\.[a-z\-\_0-9]+)*@[a-z\-\_0-9]+(\.[a-z\-\_0-9]+)*\%/i;
	if (!email2.match(re)) {
		return false;
	}	
		
	var tam = email.length;
	var varA=0;
	var varB=0;
	for (i=0;i < tam;i++){
		caracter = email.substr(i,1);
		if(caracter == '@' && varA==0){
			varA = i;				
		}
		if(caracter == '.' && varA>0 && varB==0){
			varB = i;				
		}		
	}
	var str1 = email.substr(0,varA);
	var str2 = email.substr(varA+1,varB-(varA+1));
	var str3 = email.substr(varB+1,tam);
			
	if(str1.length < 2 || str2.length < 2 || str3.length < 2){
		return false;
	}

	return true;
	
	}
			
function valid(){					
	if (document.forms.Contacto.Nome.value.length < 3){
		alert('Introduza o seu  nome.');
		return false;				
	}
	if (!valid_Email(document.forms.Contacto.Email.value,'O Email que indicou não é válido.') || document.forms.Contacto.Email.value.length < 7) {
		alert('Introduza um e-mail válido.');
		return false;					
	}
	if (document.forms.Contacto.assunto.value.length < 5) {
		alert('Introduza a sua mensagem.');
		return false;
	}		
}














