// JavaScript Document
newsletter = function(campo)
{
	document.getElementById(campo).value = "";
	document.getElementById(campo).focus();
}

verifica_newsletter = function(campo_email)
{
	if (document.frm_newsletter.txt_newsletter.value.length == 0) 
	{
		alert('Indique o E-mail!');
		document.frm_newsletter.txt_newsletter.focus();
	}else if(document.frm_newsletter.txt_newsletter.value.length > 0 && !(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/.test(document.frm_newsletter.txt_newsletter.value))) {
		alert("Preencha corretamente o e-mail!");
		document.frm_newsletter.txt_newsletter.focus();
	} else 
	{
		document.frm_newsletter.submit();
	}
}

verifica_frm_contacto = function ()
{
	
	nome = document.getElementById("txt_nome");
	mail = document.getElementById("txt_mail");
	assunto = document.getElementById("txt_assunto");
 	msg = document.getElementById("txt_msg");
	
	if (nome.value.length == 0 || nome.value == "Nome")
	{
		alert("O campo nome é de preenchimento obrigatório");
		nome.select();
		nome.focus();
	} 
	else if (mail.value.length == 0 || mail.value == "Email")
		{
			alert("O campo email é de preenchimento obrigatório");
			mail.select();
			mail.focus();
		}
		else if (mail.value.length > 0 && !(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/.test(mail.value)))
			{
				alert("Verifique se o campo de Email está preenchido correctament!");
				mail.focus();
			}else if (msg.value.length == 0 || msg.value == "Mensagem")
				{
					alert("A area de texto da mensagem é de preenchimento obrigatório");
					msg.focus();
				}
				else
				{
					document.frm_contacto.submit();
				}
}


selectcampos = function(id_campo)
{
	document.getElementById(id_campo).select();
}

resultado = function(id)
{
	alert (id);
	if (document.getElementById(id).className == 'result_closed')
	{
		document.getElementById(id).className = 'result_open';
	}
}

verifica_qt = function(id_qt)
{
	if (document.getElementById(id_qt).value == '')
	{
		document.getElementById(id_qt).value = '1';
	}
}

verifica_campos = function()
{
	var erro_n,erro_cont ,erro_m, erro_l, erro_cod, erro_pre, erro_local, erro_contact, erro_mail;
	
	erro_n = '0';
	erro_cont = '0';
	erro_m = '0';
	erro_l = '0';
	erro_cod = '0';
	erro_pre = '0';
	erro_local = '0';
	erro_contact = '0';
	erro_mail = '0';
	err = "";
	
	nome = document.getElementById("txt_nome");
	//err = document.getElementById("err_nome");
	//empresa = document.getElementById("txt_empresa");
	cont = document.getElementById("txt_cont");
	
	morada = document.getElementById("txt_morada");
	localidade = document.getElementById("txt_localidade");
	codigo = document.getElementById("txt_codigo");
	prefixo = document.getElementById("txt_prefixo");
	local = document.getElementById("txt_local");
	
	telef = document.getElementById("txt_telef");
	movel = document.getElementById("txt_movel");
	fax = document.getElementById("txt_fax");
	email = document.getElementById("txt_email");
	
	
	if (nome.value.length == 0)
	{
		erro_n = '1';
		err = "Verifique o campo Nome! <br />"
	}
	if (isNaN(cont.value))
	{
	 	erro_cont = '1';
		err = err + "Verifique o conteudo do campo Contribuinte! <br />"
	}
	if (morada.value.length == 0)
	{
		erro_m = '1';
		err = err + "Verifique o campo morada! <br />" 
	} 
	if (localidade.value.length == 0)
	{
		erro_l = '1';	
		err = err + "Verifique o campo da localidade! <br />"
	}
	if (codigo.value.length == 0)
	{
		erro_cod = '1';
		err = err + "Verifique o campo Codigo Postal! <br />"
	}else if (codigo.value.length > 0 && isNaN(codigo.value))
	{
		erro_cod = '1';	
		err = err + "Verifique o conteúdo da codigo postal! <br />"
	}
	
	if (prefixo.value.length == 0)
	{
		erro_pre = '1';
		err = err + "Verifique o sufixo do seu codigo postal! <br />"
	} else 	if (prefixo.value.length > 0 && isNaN(prefixo.value))
	{
		erro_pre = '1';
		err = err + "Verifique o conteúdo no sufixo do seu codigo postal! <br />"
	}
	
	if (local.value.length == 0)
	{
		erro_local = '1';	
		err = err + "Verifique o campo da localidade! <br />"
	}
	if (telef.value.length == 0 && movel.value.length == 0)
	{
		erro_contact = '1';
		err = err + "Uns dos campos, Contacto Telefónico ou Contacto Móvel, é de preenchimento obrigatório!<br />"
	}
	if (isNaN(telef.value) || isNaN(movel.value))
	{
		erro_contact = '1';
		err = err + "Verifique o conteudo dos contactos!<br />"
	}
	if (email.value.length == 0)
	{
		erro_mail = '1';
		err = err + "Verifique o campo Email! <br />" 
	} 
	else if (email.value.length > 0 &&  !(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/.test(email.value)))
	{
		erro_mail = '1';
		err = err + "Verifique a sintaxe do email! <br />" 
	}
	
	if (erro_n=='1' || erro_cont=='1' || erro_m=='1' || erro_l=='1' || erro_cod=='1' || erro_pre=='1' || erro_local=='1' || erro_contact=='1' || erro_mail=='1')
	{
		if (erro_n=='1')
		{
			nome.focus();
		}else
		if (erro_cont=='1')
		{
			cont.focus();	
		}else
		if (erro_m=='1')
		{
			morada.focus();
		}else
		if (erro_l=='1')
		{
			localidade.focus();	
		}else
		if (erro_cod=='1')
		{
			codigo.focus();	
		}else
		if (erro_pre=='1')
		{
			prefixo.focus();	
		}else
		if (erro_local =='1')
		{
			local.focus();	
		}else
		if (erro_contact == '1')
		{
			movel.focus();	
		}else
		if (erro_mail =='1')
		{
			email.focus();
		}
		document.getElementById('div_err').innerHTML = err;
		document.getElementById("erros").style.display = 'block';

	}
	else
	{
		document.getElementById('erros').style.display = 'none';
		document.frm_dados_reg.submit();
	}
}

muda_campo = function()
{
	codigo = document.getElementById("txt_codigo");
	prefixo = document.getElementById("txt_prefixo");
	local = document.getElementById("txt_local");	
	
	if (codigo.value.length == 4)
	{
		prefixo.focus();
	}
	
	if (prefixo.value.length == 3)
	{
		local.focus();	
	}	
}


procura = function(id1,id2)
{
	//alert ("Valor: " + id1 + " Valor 2: " + id2);
	
	if (document.getElementById(id1).className == 'acessorios_closed')
	{
		document.getElementById(id1).className = 'acessorios_open'
		document.getElementById(id2).className = 'acessorios_closed'
	}
	else
	{
		document.getElementById(id1).className = 'acessorios_closed'
		document.getElementById(id2).className = 'acessorios_open'
	}
}