//Function to count the number of characters in the description text box
//document.write ("<title>.: Portal da Póvoa de Varzim :.</title>");
window.status=".: A Póvoa de Varzim mais perto de si - www.povoadevarzim.com.pt :.";

function open_window(votre_page)
{
	var hauteur_popup=400;
	var H = (screen.height - hauteur_popup) / 2;
	var largeur_popup=600;
	var L = (screen.width - largeur_popup) / 2;
	pop_up = window.open(votre_page,"Popup","status=no,scrollbars=no,resizable=no,height="+hauteur_popup+",width="+largeur_popup+",top="+H+",left="+L);

}

<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//-->


function open_window1(theURL,winName,features,largura,altura)
{
	var H = (screen.height - altura) / 2;
	var L = (screen.width - largura) / 2;
	pop_up = window.open(theURL,"winName","status=no,scrollbars=no,resizable=no,height="+altura+",width="+largura+",top="+H+",left="+L);

}
//-->


function ContarDesc() {
	document.orderform.conta.value = document.orderform.descricao1.value.length;
}

//Function to check form is filled in correctly before submitting
function CheckForm () {

	//Intialise variables
	var errorMsg = "";
	var errorMsgLong = "";
	var erro="";
	
	
	if(document.orderform.subcat.value==0)
	{
	erro+="\n Sub-categoria não preenchida";
	}

	if (document.orderform.nome.value.length < 1){
		erro+="\n O nome não está preenchido!";
	}
	
	//VALIDAR FAX       --------- FALTA MELHORAR COM EXPRESSOES REGULARES
	if (document.orderform.fax.value.length!=0)
	{
		if (document.orderform.fax.value.length < 6)
			erro+="\n O fax não está preenchido correctamente!";
	}
	

	if (document.orderform.localidade.value.length < 1)
			erro+="\n A localidade não está preenchida!";
	else if (document.orderform.localidade.value.length < 5)
			erro+="\n A Localidade não é válida!";

	if (document.orderform.morada.value.length < 1){
		erro+="\n A morada não está preenchida!";
	}
	else if (document.orderform.morada.value.length < 10)
	     {
		     erro+="\n A morada não está preenchida correctamente!";
     	}

	//VALIDAR CPOSTAL       --------- FALTA MELHORAR COM EXPRESSOES REGULARES
	var cp=/[0-9][0-9][0-9]/;
	if(document.orderform.codigo_postal.value!=0)
	{
	if (document.orderform.codigo_postal.value.length<3)
	{
	   erro+="\n O código postal não é válido!";
	 }
	 }
/*	else if (document.orderform.codigo_postal.value!=cp)
		{
		 	erro="\n O código postal não é válido!";
		}
	}*/

	//VALIDAR TELEFONE       --------- FALTA MELHORAR COM EXPRESSOES REGULARES
	if (document.orderform.telef.value.length < 1)
	{
		erro+="\n O telefone não está preenchido!";
	}
	else if (document.orderform.telef.value.length < 6)
	{
		erro+="\n O telefone não é válido!";
	}
	
	//VALIDAR TELEMOVEL		--------- FALTA MELHORAR COM EXPRESSOES REGULARES
	if (document.orderform.telemovel.value.length > 0)
	{
	  if (document.orderform.telemovel.value.length < 6)
	 		erro+="\n O telemovel não é válido!";
	}
	
	//VALIDAR PASSWORD
	if (document.orderform.passw.value.length < 1)
	{
	 		erro+="\n A password não está preenchida!";
	}
	//VALIDAR PASSWORD
	if (document.orderform.passw.value.length < 5 )
	{
	 		erro+="\n A password tem que ter no mínimo 5 caracteres!";
	}
	

	//Verifica se o comprimento da descrição está correcto
	if (document.orderform.descricao1.value.length > 200){
		errorMsgLong += "\n- A sua descricação tem " + document.orderform.descricao1.value.length + " caracteres, tem que colocar menos que 200.";
	}

	
	
	//Verifica o comprimento das palavras na descrição
	palavras = document.orderform.descricao1.value.split(' ');
	for (var loop = 0; loop <= palavras.length - 1; ++loop){
		if (palavras[loop].length > 30){
		errorMsgLong += "\n- Uma palavra na sua descrição contém " + palavras[loop].length + " caracteres. Corrija o problema.";
		}	
	}	
	
	//If there is aproblem with the form then display an error
	if ((errorMsg != "")||(errorMsgLong != "")){
		msg = "________________________________________________________\n\n";
		msg += "\tOcorreram o seguintes erros no seu formulário:         \n\n";
		msg += "A Descrição que inseriu não pode ser adicionada pois não é válida.\n";
		msg += "Por favor corrija o problema.\n";
		msg += "_______________________________________________________________\n";
				
		errorMsg += alert(msg + errorMsg + errorMsgLong);
		return false;
	}
	if(erro!="")
	{
		alert(erro);
		return false;
	}
	
	return true;
}
// -->

 function ativo(src) {
 if (!src.contains(event.fromElement))
  {
     src.bgColor = '#318ACE';
  }
 }
 function inativo(src,corinativa) {
 if (!src.contains(event.toElement))
  {
   src.bgColor = '#318ACE';
  }
 }

<!--//função que verifica se o formulário de pesquisa foi preenchido antes de ser submetido-->
function verificar_pesquisa() {
var themessage = "Para fazer a pesquisa precisa de preencher o campo de: ";
if (document.form.q.value==""){
themessage = themessage + " Pesquisa";
alert(themessage);
return false;}

else {

return true;
   }
}

function verificar_pesquisa1() {
var themessage = "Necessita de inserir algo a procurar ";
if (document.form_pesq.q.value==""){
alert(themessage);
return false;}


else {

return true;
   }
}


function Contar2() {
	document.form1.conta2.value = document.form1.descricao2.value.length;
}

//Function to check form is filled in correctly before submitting
function valida1 () {

	//Intialise variables
	var errorMsg = "";
	var errorMsgLong = "";
	var erro="";
	//Verifica se o comprimento da descrição está correcto
	if (document.form1.descricao1.value.length > 200){
		errorMsgLong += "\n- A descricação dos principais pratos tem " + document.form1.descricao1.value.length + " caracteres, tem que colocar menos que 200.";
	}
	if (document.form1.descricao2.value.length > 200){
		errorMsgLong += "\n- A descricação das especialidades tem" + document.form1.descricao2.value.length + " caracteres, tem que colocar menos que 200.";
	}
	

	
	//Verifica o comprimento das palavras na descrição
	palavras = document.form1.descricao1.value.split(' ');
	for (var loop = 0; loop <= palavras.length - 1; ++loop){
		if (palavras[loop].length > 30){
		errorMsgLong += "\n- Uma palavra na sua descrição contém " + palavras[loop].length + " caracteres. Corrija o problema.";
		}	
	}	

	//If there is aproblem with the form then display an error
	if ((errorMsg != "")||(errorMsgLong != "")){
		msg = "________________________________________________________\n\n";
		msg += "\tOcorreram o seguintes erros no seu formulário:         \n\n";
		msg += "-A Descrição que inseriu não pode ser adicionada pois não é válida.\n";
		msg += "Por favor corrija o problema.\n";
		msg += "_______________________________________________________________\n";
				
		errorMsg += alert(msg + errorMsg + errorMsgLong);
		return false;
	}
	if(erro!="")
	{
		alert(erro);
		return false;
	}
	
	return true;
}



function CheckForm2 () {

	//Intialise variables
	var errorMsg = "";
	var erros = "";
	var erro="";
	

	if (document.form1.nome.value.length < 1){
		erro+="\n O nome não está preenchido!\n";
	}
	
	if (document.form1.morada.value.length < 1){
		erro+="\n A morada não está preenchida!\n";
	}
	else if (document.form1.morada.value.length < 10)
	     {
		     erro+="\n A morada não está preenchida correctamente!\n";
     	}
	
	if (document.form1.localidade.value.length < 1){
		erro+="\n A Localidade não está preenchida!\n";
	}

	if (document.form1.telef.value.length < 1){
		erro+="\n O telefone não está preenchido!\n";
	}

	if (document.form1.descricao1.value.length < 1){
		erro+="\n A descrição dos pratos não está preenchida!\n";
	}

	if (document.form1.descricao1.value.length > 200){
		erro += "\n- A descricação dos pratos tem " + document.form1.descricao2.value.length + " caracteres, tem que colocar menos que 200.\n";
	}
	

	if (document.form1.descricao2.value.length < 1){
		erro+="\n A descrição das especialidades não está preenchida!\n";
	}

	if (document.form1.descricao2.value.length > 200){
		erro+= "\n- A descricação das especialidades tem " + document.form1.descricao2.value.length + " caracteres, tem que colocar menos que 200.\n";
	}


	if(erro!="")
	{
		alert(erro);
		return false;
	}
	
	return true;

}






