/* FORUM */
function form_message_submit() {
	nome = document.form1.nome.value;
	email = document.form1.email.value;
	titulo = document.form1.titulo.value;
	mensagem = document.form1.mensagem.value;

	if (nome=="" || email=="" || titulo=="" || mensagem=="") {
		alert("Todos os campos são de preenchimento obrigatório.");
	    return;
	} else
		document.form1.submit();
} 

// --- Pesquisa
function pesquisa() {
	texto = document.pesquisa.texto.value;
	if (texto.length < 3) {
	    alert("Para efectuar uma pesquisa necessita de inserir pelo menos uma palavra de 3 caracteres.");
	} else {
	   document.forms["pesquisa"].submit();
	}
}

// ---- ImageOver wrap
function hsrc_init() {
  if (!document.getElementById) return
  var imgOriginSrc;
  var imgTemp = new Array();
  var imgarr = document.getElementsByTagName('img');
  for (var i = 0; i < imgarr.length; i++) {
    if (imgarr[i].getAttribute('hsrc')) {
        imgTemp[i] = new Image();
        imgTemp[i].src = imgarr[i].getAttribute('hsrc');
        imgarr[i].onmouseover = function() {
            imgOriginSrc = this.getAttribute('src');
            this.setAttribute('src',this.getAttribute('hsrc'))
        }
        imgarr[i].onmouseout = function() {
            this.setAttribute('src',imgOriginSrc)
        }
    }
  }
}

// -- Socio registo
function socio_validar() {
	tf = document.forms["form1"];
	tf.submit();

	if ( tf.comercial.value  == ""  ) {
		alert("Nome comercial é campo obrigatorio.");
		return;
	}
	if ( tf.firma.value  == ""  ) {
		alert("Nome da Firma é campo obrigatorio.");
		return;
	}
	if ( tf.responsavel.value  == ""  ) {
		alert("Nome do responsavel é campo obrigatorio.");
		return;
	}
	if ( tf.morada.value  == ""  ) {
		alert("Morada é campo obrigatorio.");
		return;
	}
	if ( tf.codigo_postal.value  == ""  ) {
		alert("Codigo Postal é campo obrigatorio.");
		return;
	}
	if ( tf.telefone.value  == ""  ) {
		alert("Telefone é campo obrigatorio.");
		return;
	}
	if ( tf.fax.value  == ""  ) {
		alert("Fax é campo obrigatorio.");
		return;
	}
	if ( tf.email.value  == ""  ) {
		alert("E-mail é campo obrigatorio.");
		return;
	}
	if ( tf.contribuinte.value  == ""  ) {
		alert("Contribuinte é campo obrigatorio.");
		return;
	}
	if ( tf.capital_social.value  == ""  ) {
		alert("Capital Social é campo obrigatorio.");
		return;
	}
	if ( tf.alvara.value  == ""  ) {
		alert("Alvara é campo obrigatorio.");
		return;
	}

	tf.submit();
}

// ------------------ Download da imagem no tamanho maximo
function get_image( imagem ) {
	var winl = screen.width;
	var wint =screen.height;

	win=window.open("image.php?fx="+imagem, 'janela', "top=0,left=0,scrollbars=0,width="+wint+",height="+winl);	
	if ( typeof(window.focus) != "undefined" ) {
	    win.focus();
	}
}

function resize_window(obj) {
	comp	= obj.width < 400 ? 400 : obj.width;
	altura	= obj.height < 400 ? 400 : obj.height;
	
	window.resizeTo(comp, altura);
}

// _--------------------- chat
function open_chat_old( ) {
	var winl = ( screen.width - 700 ) / 2;
	var wint =( screen.height - 500 ) / 2;

	win=window.open("chat/index.php", 'janelachat', "width=700,height=500,scrollbars=0,top="+wint+",left="+winl);	
	if ( typeof(window.focus) != "undefined" ) {
	    win.focus();
	}
}



function imgset( nome, valor) {
	temp = new Image();
	temp.src = valor;
	actual = document.images[ nome ];
	oldImage = actual.src;
	actual.onmouseout = function() {
		actual.src = oldImage;
	}
	actual.src = temp.src;
}

// ----------
function getoffsettop(element, deep) {
	return getoffsetproperty(element, 'Top', deep);
}

function getoffsetleft(element, deep) {
	return getoffsetproperty(element, 'Left', deep);
}

function getoffsetproperty(element, property, deep) {
   var offsetValue = 0;
   offsetProperty = 'offset' + property;
   
   do {
      offsetValue += element[offsetProperty];
      element = element.offsetParent;
   } while (deep == true && element != document.body && element != null);
   return offsetValue;
}
function overtd(td,color) { td.style.cursor='hand';td.bgColor=color; }
function outtd(td,color){ td.style.cursor='default';td.bgColor=color; }