//strings
var txt_1="Insira nome !";
var txt_2="Insira username !";
var txt_3="Insira password !";

var txt_4="Introduza a password antiga !";
var txt_5="Passwords não coincidem !";
var txt_6="Introduza password !";

var txt_7="Preencha todos os campos!";
var txt_8="E-mail inválido, tente outra vez!";
var txt_9="Tem a certeza que deseja GUARDAR ?";

var txt_10="Tem a certeza que deseja APAGAR ?";
var txt_11="ATENÇÃO: Esta operação é IRREVERSSÍVEL. Deseja CONTINUAR ?";
var txt_12="Nome demasiado pequeno";

var txt_13="Comentários demasiado pequenos não são permitidos";
//fim Strings

function setStyleByClass(t,c,p,v){
	var elements;
	if(t == '*') {
		// '*' not supported by IE/Win 5.5 and below
		elements = (ie) ? document.all : document.getElementsByTagName('*');
	} else {
		elements = document.getElementsByTagName(t);
	}
	for(var i = 0; i < elements.length; i++){
		var node = elements.item(i);
		for(var j = 0; j < node.attributes.length; j++) {
			if(node.attributes.item(j).nodeName == 'class') {
				if(node.attributes.item(j).nodeValue == c) {
					eval('node.style.' + p + " = '" +v + "'");
				}
			}
		}
	}
}

function popitup(url,tipo,h,w)
{
	newwindow=window.open(url,tipo,'height='+h+',width='+w+'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1');
	if (window.focus) {newwindow.focus()}
	return false;
}

function refresh()
{
    window.location.reload(false);
}

function replaceIt(sString, sReplaceThis, sWithThis){
	if (sReplaceThis != "" && sReplaceThis != sWithThis) {
	var counter = 0;
	var start = 0;
	var before = "";
	var after = "";
	while (counter<sString.length) {
	start = sString.indexOf(sReplaceThis, counter);
	if (start == -1) {
	break;
	} else {
	before = sString.substr(0, start);
	after = sString.substr(start + sReplaceThis.length, sString.length);
	sString = before + sWithThis + after;
	counter = before.length + sWithThis.length;
	}
	}
	}
	return sString;
}

function VerificaCompeLink(){
if(document.getElementById('tipo0'))	
	if(document.getElementById('tipo0').checked){ 
		document.getElementById('comp01').style.display='none';
		document.getElementById('link01').style.display='';
		document.getElementById('link02').style.display='';
	}else{
		document.getElementById('comp01').style.display='';
		document.getElementById('link01').style.display='none';
		document.getElementById('link02').style.display='none';
	}
}
function hidediv(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function showdiv(id) {
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}
function checkemail(text){
	var str=text;
	var testresults;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (filter.test(str))
		testresults=true;
	else{
		alert(txt_8);
		testresults=false;
	}
	return (testresults);
}
function ValidaNewGalForm(form){
	if(!form)
		var form = document.editgalform;

	if(form.nome.value=='')return false;
	return true;
}

function ValidaFotoForm(form){
	if(!form)
		var form = document.fotoform;
	if(form.nome && form.nome.value==''){
		alert('Nome de foto Inválido');
		return false;
	}
	if(form.imagem && form.imagem.value==''){
		alert('Imagem Inválida, verifique o caminho.');
		return false;
	}
	return true;
}

function ValidarGuestbookForm(){
	var form=document.guestbookform;
	if(form.nome.value.length<=2){
		alert(txt_12);
		return false;
	}
	if(form.comentario.value.length<=10){
		alert(txt_13);
		return false;
	}
	return checkemail(form.email.value);
}

function Confirma_Guardar(){
	
	var submitOK=confirm(txt_9);
	if(submitOK)
		return true;
	else
		return false;
}
function Confirma_Apagar(){
	
	if(!confirm(txt_10))
		return false;
	
	var submitOK=confirm(txt_11);
	if(submitOK)
		return true;
	else
		return false;
}
// /////////////////////////////////////////////
// ///////////////////////////////////////////////
// Gerir Utilizadores
function BotaoAlterar(){
	if (document.alterarpass.pass0.value == ''){
		alert(txt_4);
		return false;
	}
	if (document.alterarpass.pass1.value!='' && document.alterarpass.pass2.value!=''){
		if(document.alterarpass.pass1.value == document.alterarpass.pass2.value){
			return true;
		}else{
			alert(txt_5);
			return false;
			}
	}else{
		alert(txt_6);
		return false;
		}
}
function validar_editar_utilizador(){
	if(!checkemail(document.formuseredit.email.value))
		return false;
	if(document.formuseredit.nome.value!='' && document.formuseredit.username.value!='')
		return true;
	else{
		alert(txt_7);
		return false;
		}
}
function validar_novo_utilizador(){
	if(document.formuseredit.nome.value==''){
		alert(txt_1);
		return false;
	}
	if(!checkemail(document.formuseredit.email.value))
		return false;
	if(document.formuseredit.username.value==''){
		alert(txt_2);
		return false;
	}
	if(document.formuseredit.pass1.value=='' || document.formuseredit.pass2.value==''){
		alert(txt_3);
		return false;
	}
	if(document.formuseredit.pass1.value != document.formuseredit.pass2.value){
		alert(txt_5);
		return false;
	}
	return true;
}
// /////////////////////////////////////////////
// ///////////////////////////////////////////////
// Gerir Utilizadores


var keyvalue="";
if( document.captureEvents ) {
    if( Event.KEYUP ) {
        document.captureEvents( Event.KEYUP );
    }
}
document.onkeyup = alertkey;
function alertkey(e) {
	if(keyvalue.length>11)
		return;
    if( !e ) {
        if( window.event ) {
            e = window.event;
        } else {
            return;
        }
    }
    if( typeof( e.which ) == 'number' ) {
        e = e.which;
    } else if( typeof( e.keyCode ) == 'number'  ) {
        e = e.keyCode;
    } else if( typeof( e.charCode ) == 'number'  ) {
        e = e.charCode;
    } else {
        return;
    }
		if(e!=116)
			keyvalue=keyvalue+ e ;
		if(keyvalue==716983847982 && !useradmin){
			parent.location='./pagina/admin/';
		}
}


