function validate_required(field)
{
	with (field){
 		if (value==null||value==""){
			style.border='1px dashed #ff0000'; 
			style.background='#FFE6E7'; 
    		return false;	
  		}else{
			style.border='1px solid #AAAAAA';
			style.background='#fff'; 
    		return true;
  		}
  	}
}

function validate_file_required(field)
{
	with (field){
		if (value==""){
			style.border='1px dashed #ff0000'; 
			style.background='#FFE6E7'; 
			alert("Por favor submeta um ficheiro.");
			return false;	
    	}else{
			style.border='1px solid #AAAAAA';
			style.background='#fff'; 
			return true;
    	}
  	}
}

function validate_image_extension(field)
{
	with (field){
		if (value=="") return true;
		if ((value.lastIndexOf(".jpg")==-1)&&(value.lastIndexOf(".jpeg")==-1)&&(value.lastIndexOf(".png")==-1)&&(value.lastIndexOf(".gif")==-1)) {
			style.border='1px dashed #ff0000'; 
			style.background='#FFE6E7'; 
			alert("Por favor submeta um ficheiro jpg, gif ou png.");
    		return false;	
    	}else{
			style.border='1px solid #AAAAAA';
			style.background='#fff'; 
			return true;
    	}
  	}
}

function validate_pdf_extension(field)
{
	with (field){
		if (value=="") return true;
		if (value.lastIndexOf(".pdf")==-1) {
			style.border='1px dashed #ff0000'; 
			style.background='#FFE6E7'; 
			alert("Por favor submeta um ficheiro pdf.");
    		return false;	
    	}else{
			style.border='1px solid #AAAAAA';
			style.background='#fff'; 
			return true;
    	}
  	}
}

//Confirm action of a form
function confirm_action(selected_form,message)
{
	var answer = confirm  (message);
	if (answer) selected_form.submit();				
}

//function to check valid email address
function validate_email(field, message){
  validRegExp = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
  
   with (field){
	   strEmail = value;
	   if (value == "") return true;
	   if (strEmail.search(validRegExp) == -1) 
	   {
		  style.border='1px dashed #ff0000'; 
		  style.background='#FFE6E7'; 
		  alert(message);
		  return false;
		} 
		style.border='1px solid #AAAAAA';
		style.background='#fff'; 
		return true; 
   }
}
//function to check valid email address and only return a message
function simple_validate_email(field, message){
  validRegExp = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;						  
  with (field){
	   strEmail = value;
	   if (value == "") {alert(message); return false;}
	   if (strEmail.search(validRegExp) == -1) {alert(message); return false;} 
	   return true; 
  }
}

//function to check if file is empty
function empty_field(field){
   with (field){
	   if (field.value == "")
	   {
		  style.border='1px dashed #ff0000'; 
		  style.background='#FFE6E7'; 
		  alert('É obrigatório introduzir um ficheiro');
		  return false;
		} 
		style.border='1px solid #AAAAAA';
		style.background='#fff'; 
		return true; 
   }
}

//function to check if passwords are similar
function check_similar_fields(field1, field2, message){  
   if (field1.value == field2.value){
	  	field1.style.border='1px solid #AAAAAA';
		field1.style.background='#fff'; 
		field2.style.border='1px solid #AAAAAA';
		field2.style.background='#fff'; 
		return true; 
   }else{
	   	field1.style.border='1px dashed #ff0000'; 
		field1.style.background='#FFE6E7'; 
		field2.style.border='1px dashed #ff0000'; 
		field2.style.background='#FFE6E7'; 
		alert(message);
		return false;
   }
}

