// JavaScript Document
$(document).ready(function(){
				
	// thickbox code!!!
	tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
	imgLoader = new Image();// preload image
	imgLoader.src = tb_pathToImage;
	
    $('.officeItemList').combobox(
   {
     comboboxContainerClass: "comboboxContainer",
     comboboxValueContainerClass: "comboboxValueContainer",
     comboboxValueContentClass: "comboboxValueContent",
     comboboxDropDownClass: "comboboxDropDownContainer",
     comboboxDropDownButtonClass: "comboboxDropDownButton",
     comboboxDropDownItemClass: "comboboxItem",
     comboboxDropDownItemHoverClass: "comboboxItemHover",
     comboboxDropDownGroupItemHeaderClass: "comboboxGroupItemHeader",
     comboboxDropDownGroupItemContainerClass: "comboboxGroupItemContainer",
     animationType: "fade",
	 width: "220px"
   });
    $('.officeItemList2').combobox(
    {
     comboboxContainerClass: "comboboxContainer2",
     comboboxValueContainerClass: "comboboxValueContainer2",
     comboboxValueContentClass: "comboboxValueContent2",
     comboboxDropDownClass: "comboboxDropDownContainer2",
     comboboxDropDownButtonClass: "comboboxDropDownButton2",
     comboboxDropDownItemClass: "comboboxItem2",
     comboboxDropDownItemHoverClass: "comboboxItemHover2",
     comboboxDropDownGroupItemHeaderClass: "comboboxGroupItemHeader2",
     comboboxDropDownGroupItemContainerClass: "comboboxGroupItemContainer2",
     animationType: "fade",
	 width: "460px"
   });   	
	$('#nome').blur(function(){
		if ($(this).attr('value') == null) {
			$(this).attr('value','Nome');
		}
	});
	$('#entidade').blur(function(){
		if ($(this).attr('value') == null) {
			$(this).attr('value','Entidade');
		}
	});
	$('#nif').blur(function(){
		if ($(this).attr('value') == null) {
			$(this).attr('value','NIF');
		}
	});
	$('#telefone').blur(function(){
		if ($(this).attr('value') == null) {
			$(this).attr('value','Telefone');
		}
	});
	$('#fax').blur(function(){
		if ($(this).attr('value') == null) {
			$(this).attr('value','Telemóvel');
		}
	});		
	$('#email').blur(function(){
		if ($(this).attr('value') == null) {
			$(this).attr('value','Email');
		}
	});	
	$('#endereco').blur(function(){
		if ($(this).attr('value') == null) {
			$(this).attr('value','Endereço');
		}
	});		
	$('#localidade').blur(function(){

		if ($(this).attr('value') == null) {
			$(this).attr('value','Localidade');
		}
	});
	$('#cp1').blur(function(){

		if ($(this).attr('value') == null) {
			$(this).attr('value','Código Postal');
		}
	});	
	$('#area_c').blur(function(){
		if ($(this).attr('value') == null) {
			$(this).attr('value','Observações');
		}
	});	
	
	$('#nome').blur(function(){
		if ($(this).attr('value') == null) {
			$(this).attr('value','Nome');
		}
	});
	$('#password').blur(function(){
		if ($(this).attr('value') == null) {
			$(this).attr('value','Palavra senha');
		}
	});
	$('#nomeAmigo').blur(function(){
		if ($(this).attr('value') == null) {
			$(this).attr('value','Nome do amigo');
		}
	});	
	$('#emailAmigo').blur(function(){
		if ($(this).attr('value') == null) {
			$(this).attr('value','Email do amigo');
		}
	});		
	$('.field_c').click(function(){
		$(this).attr('value', '');
	});
	$('.field_c2').click(function(){
		$(this).attr('value', '');
	});
	$('.field_c3').click(function(){
		$(this).attr('value', '');
	});				
	$('.box').click(function(){
		$(this).attr('value', '');
	});	
	$('.observacoes').click(function(){
		$(this).attr('value', '');
	});		
	
	$('#submeterIMG').mousedown(function(){
		$(this).attr('src','../images/img42C.gif');
	});
	$('#submeterIMG').mouseout(function(){
		$(this).attr('src','../images/img42A.gif');
	});
	$('#submeterIMG').mouseup(function(){
		$(this).attr('src','../images/img42A.gif');
	});
	$('#submeterIMG').click(function(){
		$('#inscricaoform').submit();
	});
	
	$('#submeterIMG2').mousedown(function(){
		$(this).attr('src','../images/img42C.gif');
	});
	$('#submeterIMG2').mouseout(function(){
		$(this).attr('src','../images/img42A.gif');
	});
	$('#submeterIMG2').mouseup(function(){
		$(this).attr('src','../images/img42A.gif');
	});
	$('#submeterIMG2').click(function(){
		$('#enviarAmigoForm').submit();
	});	
	
	
	$('#submeterIMG_newsletter').mousedown(function(){
		$(this).attr('src','../images/img42C.gif');
	});
	$('#submeterIMG_newsletter').mouseout(function(){
		$(this).attr('src','../images/img42A.gif');
	});
	$('#submeterIMG_newsletter').mouseup(function(){
		$(this).attr('src','../images/img42A.gif');
	});
	$('#submeterIMG_newsletter').click(function(){
		$('#inscricaoform_newsletter').submit();
	});
	
	$('#inscricaoform').submit(function(){
		/* obtem os valores */
		nome = $(this).find("#nome").attr('value');
		entidade = $(this).find("#entidade").attr('value');
		nif = $(this).find("#nif").attr('value');
		telefone = $(this).find("#telefone").attr('value');
		fax = $(this).find("#fax").attr('value');
		email = $(this).find("#email").attr('value');
		endereco = $(this).find("#endereco").attr('value');
		localidade = $(this).find("#localidade").attr('value');
		cp1 = $(this).find("#cp1").attr('value');
		cp2 = $(this).find("#cp2").attr('value');
		obs = $(this).find("#area_c").attr('value');
		
		var camposErrados="";
		if (nome == "Nome") {
			camposErrados=camposErrados+"Nome|"
		}
		if (nif == "NIF") {
			camposErrados=camposErrados+"NIF|"
		}
		if (telefone == "Telefone") {
			camposErrados=camposErrados+"Telefone|"
		}
		if (email == "Email") {
			camposErrados=camposErrados+"Email|"
		}
		if (endereco == "Endereço") {
			camposErrados=camposErrados+"Endereço Postal|"
		}
		if (localidade == "Localidade") {
			camposErrados=camposErrados+"Localidade|"
		}
		if (cp1 == "Código Postal") {
			camposErrados=camposErrados+"Código Postal|"
		}
		if (cp2 == null) {
			camposErrados=camposErrados+"Código Postal - Extensão|"
		}

		if (obs == "Observações") {
			$(this).find("#area_c").attr('value','');
		}
		
		// se existirem campos com erro apresenta mensagem
		if (camposErrados != "") {
			msg = "Existem campos com valores errados:\n"
			campos = camposErrados.split("|")
			for (f=0; f < campos.length - 1; f++) {
				msg = msg + "    -  " + campos[f] + "\n";
			}
			alert(msg);		
			return (false);
		}
		else
		{
			return (true);
		}

	});
	$('#inscricaoform_newsletter').submit(function(){
		/* obtem os valores */
		nome = $(this).find("#nome").attr('value');
		entidade = $(this).find("#entidade").attr('value');
		nif = $(this).find("#nif").attr('value');
		telefone = $(this).find("#telefone").attr('value');
		fax = $(this).find("#fax").attr('value');
		email = $(this).find("#email").attr('value');
		endereco = $(this).find("#endereco").attr('value');
		localidade = $(this).find("#localidade").attr('value');
		cp1 = $(this).find("#cp1").attr('value');
		cp2 = $(this).find("#cp2").attr('value');
		obs = $(this).find("#area_c").attr('value');
		
		var camposErrados="";
		if ((nome == "Nome") || (nome == null)) {
			camposErrados=camposErrados+"Nome|"
		}
		if ((email == "Email") || (email == null)) {
			camposErrados=camposErrados+"Email|"
		}
		
		// se existirem campos com erro apresenta mensagem
		if (camposErrados != "") {
			msg = "Existem campos com valores errados:\n"
			campos = camposErrados.split("|")
			for (f=0; f < campos.length - 1; f++) {
				msg = msg + "    -  " + campos[f] + "\n";
			}
			alert(msg);		
			return (false);
		}
		else
		{
			return (true);
		}

	});

	$('#linkEnviarAmigo').click(function(){
		$('#moduloEnviaAmigos').css('display','block');						
	});

});