function openWindow(theURL, winName, features)
{
	window.open(theURL, winName, features);
	return true;
}

function center_window(url, hwindow, winwidth, winheight, stitle)
{
	var top, left, nhw;
	//top = 0; left = 0;
	var LeftPosition, TopPosition, w = winwidth, h = winheight;
	if (top != null && top != '')
		TopPosition = top;
	else
		TopPosition = (screen.availHeight) ? (screen.availHeight-h)/2 : 0;
	if (left != null && left != '')
		LeftPosition = left;
	else	
		LeftPosition = (screen.availWidth) ? (screen.availWidth-w)/2 : 0;
	var settings='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',fullscreen=no,directories=no,resizable=no,scrollbars=no,titlebar=no,status=no,toolbar=no,menubar=no,location=no,channelmode=no';
	nhw = window.open(url,hwindow,settings);
	if (nhw)
	{
		//if (stitle != null && stitle != '')
		//	nhw.document.title = stitle;
		nhw.focus();
	}	
}
//---------------------------------------------------------//
// Funcao	  : textCounter
// Descricao  : Limita a introdução de uma cadeia de caracteres a um número pré-definido
// Data		  : 20/09/2003 
// Copyright  : (c) GNR - (4)
// Parametros : descricao - identifica a Tag;  countfield - ; maxlimit - define-se o limite de caracteres
// OBS        : Vide Exemplo de Utilização na Área de Links
//-------------------------------------------------------- //

function textCounter(descricao, countfield, maxlimit)
{
if (descricao.value.length > maxlimit) 
	descricao.value = descricao.value.substring(0, maxlimit);
else 
	countfield.value = maxlimit - descricao.value.length;
}

//---------------------------------------------------------//
// Funcao	  : sobreOpcao
// Descricao  : Efeito de rollOver sobre células de uma tabela
// Data		  : 1/10/2003 
// Copyright  : (c) GNR - (0)
// Parametros : obj - identifica a Tag; opcao - aplica a css pretendida
// OBS        : Para funcionar deve nomear de forma diferente as Tags
//				Vide Exemplo de Utilização na Homepage - menudireita.asp
//-------------------------------------------------------- //
function sobreOpcao(obj,opcao) 
{
	if (opcao==1)
	{obj.className='sobre';}
	if (opcao==2) {obj.className='normal';}
}


//---------------------------------------------------------//
// Funcao	  : verificar
// Descricao  : Faz a verificação dos campos obrigatórios no form
// Data		  : 12/12/2003 
// Copyright  : (c) GNR - (0)
// Parametros : descricao - identifica a Tag;
// OBS        : Vide Exemplo de Utilização na Área do Sepna
//-------------------------------------------------------- //
function verificar()			
			
		    { 
		
			var mensagem = "Campos Obrigatórios:\n\n "; 	  
			
			if (document.form_sepna.nome.value=="") { 
			mensagem = mensagem + "\nNome, ";
			}
			
			if (document.form_sepna.distritos.value == ""){
				mensagem = mensagem + "\nDistrito, "; 			
			 }
			
			if (document.form_sepna.concelhos.value== "") {
				mensagem = mensagem + "\nConcelho, "; 
			 }
           if (document.form_sepna.email.value== "") {
				mensagem = mensagem + "\nemail, "; 
			 }
						 
			
			if (document.form_sepna.freguesia.value=="") { 
			mensagem = mensagem + "\nFreguesia, "; 
			}
				
			if (document.form_sepna.cpostal.value.length == 4)
				{
					true;
				}
			else	
				{
				mensagem = mensagem + "\nCódigo Postal(4), "; 
				}
				
			if (document.form_sepna.cpostal1.value.length == 3)
				{
					true;
				}
			else	
				{
				mensagem = mensagem + "\nCódigo Postal(3), "; 
				}
			
			if (document.form_sepna.telefone.value.length == 9)
				{
					true;
				}
			else	
				{
				mensagem = mensagem + "\nTelefone, "; 
				}
		
			if (document.form_sepna.area.value=="Escolha") { 
			mensagem = mensagem + "\nÁrea, "; 
			}
			
			if (document.form_sepna.firstinput.value=="") { 
			mensagem = mensagem + "\nData, "; 
			}
			
			
		 
		 	if (document.form_sepna.hora.value=="Hora") { 
			mensagem = mensagem + "\nHora, "; 
			}
			if (document.form_sepna.minutos.value=="Minutos") { 
			mensagem = mensagem + "\nMinutos, "; 
			}
			if (document.form_sepna.zona.value=="") { 
			mensagem = mensagem + "\nLocal Ocorrência"; 
			}
			if (document.form_sepna.descricao.value=="") { 
			mensagem = mensagem + "\nDescrição."; 
			} 
			if (mensagem == "Campos Obrigatórios:\n\n ") { 
			
			document.form_sepna.action='/portal/internet/sepna/12.denuncias/dataForm_sepna.asp';
			document.form_sepna.method='post';
			document.form_sepna.submit();
			
			
			}
			
			else { 
			alert(mensagem); 
			return ;
			}
				}



			
//---------------------------------------------------------//
// Funcao	  : validate_nome
// Descricao  : Faz a validação do campo "nome"
// Data		  : 12/12/2003 
// Copyright  : (c) GNR - (0)
// Parametros : descricao - identifica a Tag;
// OBS        : Vide Exemplo de Utilização na Área do Sepna
//-------------------------------------------------------- //
			
function validate_nome(field) {
					var valid = "ãâaàbcçdeéfghijklmnoóôpqrstuvwxyz ÃÂAÀBCÇDEÉFGHIJKLMNOÓÔPQRSTUVWXVYZ-."
					var ok = "yes";
					var temp;
						for (var i=0; i<55; i++)
						   {
							temp = "" + field.value.substring(i, i+1);
							if (valid.indexOf(temp) == "-1") ok = "no";
							}
							if (ok == "no") 
							{
							alert("Caracteres inválidos!");
							field.focus();
							field.select();
							 }
							}
//---------------------------------------------------------//
// Funcao	  : validate_endereco
// Descricao  : Faz a validação do campo "Endereços vs Morada"
// Data		  : 12/12/2003 
// Copyright  : (c) GNR - (0)
// Parametros : 
// OBS        : Vide Exemplo de Utilização na Área do Sepna
//-------------------------------------------------------- //

function validate_endereco(field) {
					var valid = "ãâabcçdeéfghijklmnoóôpqrstuvwxyz ÃÂABCÇDEÉFGHIJKLMNOÓÔPQRSTUVWXVYZ0123456789.,-/ºª"
					var ok = "yes";
					var temp;
						for (var i=0; i<55; i++)
						   {
							temp = "" + field.value.substring(i, i+1);
							if (valid.indexOf(temp) == "-1") ok = "no";
							}
							if (ok == "no") 
							{
							alert("Caracteres inválidos!");
							field.focus();
							field.select();
							 }
							}
			
			
//---------------------------------------------------------//
// Funcao	  : validate_telefone
// Descricao  : Faz a validação do campo "telefone"
// Data		  : 12/12/2003 
// Copyright  : (c) GNR - (0)
// Parametros : 
// OBS        : Vide Exemplo de Utilização na Área do Sepna
//-------------------------------------------------------- //


function validate_telefone()
				 {
					var num = "0123456789()- +.";
					for (var intLoop = 0; intLoop <form_sepna.telefone.value.length; intLoop++) {
					if (-1 == num.indexOf(form_sepna.telefone.value.charAt(intLoop))) {
					alert ("Caracteres Inválidos!!!!!\n\n   Caracteres Válidos - 0 a 9 ");
					form_sepna.telefone.focus();
					return false;
					}
					} 
				 }		

//---------------------------------------------------------//
// Funcao	  : validate_cpostal
// Descricao  : Faz a validação do campo "Codigo Postal"
// Data		  : 01/03/2005 
// Copyright  : (c) GNR - (0)
// Parametros : 
// OBS        : Vide Exemplo de Utilização na Área do Sepna
//-------------------------------------------------------- //


function validate_cpostal()
				 {
					var num = "0123456789()- +.";
					for (var intLoop = 0; intLoop <form_sepna.cpostal.value.length; intLoop++) {
					if (-1 == num.indexOf(form_sepna.cpostal.value.charAt(intLoop))) {
					alert ("Caracteres Inválidos!!!!!\n\n   Caracteres Válidos - 0 a 9 ");
					form_sepna.cpostal.focus();
					return false;
					}
					} 
				 }						 	
									
//---------------------------------------------------------//
// Funcao	  : validate_cpostal
// Descricao  : Faz a validação do campo "Codigo Postal1"
// Data		  : 01/03/2005 
// Copyright  : (c) GNR - (0)
// Parametros : 
// OBS        : Vide Exemplo de Utilização na Área do Sepna
//-------------------------------------------------------- //


function validate_cpostal1()
				 {
					var num = "0123456789()- +.";
					for (var intLoop = 0; intLoop <form_sepna.cpostal1.value.length; intLoop++) {
					if (-1 == num.indexOf(form_sepna.cpostal1.value.charAt(intLoop))) {
					alert ("Caracteres Inválidos!!!!!\n\n   Caracteres Válidos - 0 a 9 ");
					form_sepna.cpostal1.focus();
					return false;
					}
					} 
				 }						
			
			
//---------------------------------------------------------//
// Funcao	  : validar_email
// Descricao  : Faz a validação do campo "e-mail"
// Data		  : 12/12/2003 
// Copyright  : (c) GNR - (0)
// Parametros : 
// OBS        : Vide Exemplo de Utilização na Área do Sepna
//-------------------------------------------------------- //
	

function validar_email() 
				{

					if (form_sepna.email.value.indexOf('@', 0) == -1){
					alert("O E-mail é Inválido !!!");
					form_sepna.email.focus();
					return (false);
					}
				}
			
						

			
//---------------------------------------------------------//
// Funcao	  : allDigits/validDate
// Descricao  : Faz a validação do campo "data"
// Data		  : 12/12/2003 
// Copyright  : (c) GNR - (0)
// Parametros : 
// OBS        : Vide Exemplo de Utilização na Área do Sepna
//-------------------------------------------------------- //

function allDigits(str){
   return inValidCharSet(str,"0123456789-");
}

function inValidCharSet(str,charset){
	var result = true;
	for (var i=0;i<str.length;i++)
		if (charset.indexOf(str.substr(i,1))<0) {
			result = false;
			break;
		}
	
	return result;
}



//--------------------------
function validDate(formField,fieldLabel,required){
	var result = true;
	//if (required && !validRequired(formField,fieldLabel)) result = false;
	
 	if (result){
 		var elems = formField.value.split("-");
 		//alert(formField.value);
 		result = (elems.length == 3); // should be three components
 		if (result)	{
// 			var day = parseInt(elems[0]);
//  		var month = parseInt(elems[1]);
// 			var year = parseInt(elems[2]);

 			var day = (elems[0]);
  			var month = (elems[1]);
 			var year = (elems[2]);

 	
			result =  allDigits(elems[1]) && (day > 0) && (day < 32) &&
					 allDigits(elems[0]) && (month > 0) && (month < 13) &&					
					 allDigits(elems[2]) && ((elems[2].length == 2) || (elems[2].length == 4));
				//	 alert(result);
 		}
  		if (!result){
 			alert('Digite manualmente uma data válida no formato DD-MM-YYYY para o campo "' + fieldLabel +'".');
			formField.focus();		
		}	
	} 	
	return result;
}
// - - - -- - - - -- - - - -Fim Função para validar Datas - calendário




//---------------------------------------------------------//
// Funcao	  : Estilos para os Botões
// Descricao  : Faz os Estilos para os Botões
// Data		  : 10/12/20043 
// Copyright  : (c) GNR - (0)
// Parametros : 
// OBS        : Operações - PopUP - Conselhos
//-------------------------------------------------------- //

function perdeFocus(obj)
		{
		  obj.style.backgroundColor = '#CCCCCC';
		  obj.style.color = 'black';
		  obj.style.border = '1px solid #999999'; 
		}
		
function sobre(obj)
		{
		  obj.style.backgroundColor = '#c4d7ff';
		  
		  obj.style.color = 'black';
		  obj.style.border = '1px solid #006699'; 
		}


function GetFieldValueByName(form,name)
{
	var i;
	
	for (i=0;i<form.elements.length;i++)
	{
		if(form.elements[i].name == name)
			return (form.elements[i].value);
	}
	return null;
}




