function OpenWindow(URL,nome,w,h,scroll) {

var sw = 800, sh = 600;

if (document.all || document.layers) {
   sw = screen.availWidth;
   sh = screen.availHeight;
}

var leftPos = (sw-w)/2, topPos = (sh-h)/2;

 window.open(URL,nome,"width="+w+",height="+h+",toolbar=no,scrollbars="+scroll+",resizable=no,status=no,directories=no,menubar=no,location=no,top=" + topPos + ",left=" + leftPos, true);
}

function validarNumerico (objEvent) {
	var iKeyCode;
	if (navigator.appName == "Netscape") { iKeyCode = objEvent.which; } else { iKeyCode = objEvent.keyCode; }
	if (iKeyCode >= 48 && iKeyCode <= 57 || iKeyCode == 14) {return true}
	else {return false}
}

function validarFloat (objEvent) { // aceita ponto e virgula //
	var iKeyCode;
	if (navigator.appName == "Netscape") { iKeyCode = objEvent.which; } else { iKeyCode = objEvent.keyCode; }
	if (iKeyCode >= 48 && iKeyCode <= 57 || iKeyCode == 0 || iKeyCode == 8 || iKeyCode == 46 || iKeyCode == 14) {return true}
	else {return false}
}

function validar_reg()
{
        str1 = document.reg.new_email.value;
        str2 = document.reg.new_pass.value;
        str3 = document.reg.new_nome.value;
        str4 = document.reg.new_morada.value;
        str5 = document.reg.new_cp.value;
        str6 = document.reg.new_telef.value;
        str7 = document.reg.new_telem.value;


                if (str1 == "")
                {
                        alert("ERROR:\n\nYou have to fill the \"New Email (login)\" blank.\nThis email will be your login in the future.");
                        document.reg.new_email.focus();
                        return false;
                }
                else if (str1.length <= 7)
                {
                        alert("ERROR:\n\nThe email is too short.\nThis email will be your login in the future.");
                        document.reg.new_email.focus();
                        return false;
                }
                else if (document.reg.new_email.value.indexOf("@") == -1 || document.reg.new_email.value.indexOf(".") == -1){
                        alert("ERROR:\n\nYou have to enter a valid email!\nThis email will be your login in the future.");
                        document.reg.new_email.focus();
                        return false;
                }
                else if (str2 == "")
                {
                        alert("ERROR:\n\nYou have to fill the \"New Password\" blank.");
                        document.reg.new_pass.focus();
                        return false;
                }
                else if (str2.length <= 5)
                {
                        alert("ERROR:\n\nThe password should have at least 5 characterses.");
                        document.reg.new_pass.focus();
                        return false;
                }
                else if (str3 == "")
                {
                        alert("ERROR:\n\nYou have to fill the \"Complete name\" blank.");
                        document.reg.new_nome.focus();
                        return false;
                }
                else if (str3.length <= 7)
                {
                        alert("ERROR:\n\nThe \"Complete name\" is too short.");
                        document.reg.new_nome.focus();
                        return false;
                }
                else if (str4 == "")
                {
                        alert("ERROR:\n\nYou have to fill the \"Address\" blank.");
                        document.reg.new_morada.focus();
                        return false;
                }
                else if (str4.length <= 10)
                {
                        alert("ERROR:\n\nThe \"Address\" is too short.");
                        document.reg.new_morada.focus();
                        return false;
                }
                else if (str5 == "")
                {
                        alert("ERROR:\n\nYou have to fill the \"Zip Code\" blank.");
                        document.reg.new_cp.focus();
                        return false;
                }
                else if (str5.length <= 4)
                {
                        alert("ERROR:\n\nThe \"Zip code\" is too short.");
                        document.reg.new_cp.focus();
                        return false;
                }
                else if (str6 == "")
                {
                        alert("ERROR:\n\nYou have to fill the \"Phone number\" blank.");
                        document.reg.new_telef.focus();
                        return false;
                }
                else if (str6.length <= 8)
                {
                        alert("ERROR:\n\nThe telephone number has to have at least 9 digits.");
                        document.reg.new_telef.focus();
                        return false;
                }
                else if (str7 == "")
                {
                        alert("ERROR:\n\nYou have to fill the \"Mobil Phone\" blank.");
                        document.reg.new_telem.focus();
                        return false;
                }
                else if (str7.length <= 8)
                {
                        alert("ERROR:\n\nThe mobil phone number has to have at least 9 digits.");
                        document.reg.new_telem.focus();
                        return false;
                }

                  else {
                        return true;
                }
}

function validar_tech()
{
        str1 = document.tech.same.checked;
        str3 = document.tech.newt_nome.value;
        str4 = document.tech.newt_morada.value;
        str5 = document.tech.newt_cp.value;
        str6 = document.tech.newt_telef.value;

        if (str1 == true)
        {
                return true;
        }
        else
        {
                if (str3 == "")
                {
                        alert("ERRO:\n\nTem de preencher o campo \"Nome e Apelido\".\nSe o Contacto Técnico for o mesmo que o Contacto Administrativo tem de seleccionar a checkbox do topo");
                        document.tech.newt_nome.focus();
                        return false;
                }
                else if (str3.length <= 7)
                {
                        alert("ERRO:\n\nO campo \"Nome e Apelido\" está demasiado curto.");
                        document.tech.newt_nome.focus();
                        return false;
                }
                else if (str4 == "")
                {
                        alert("ERRO:\n\nTem de preencher o campo \"Morada\".");
                        document.tech.newt_morada.focus()
                        return false;
                }
                else if (str4.length <= 10)
                {
                        alert("ERRO:\n\nMorada demasiado curta.");
                        document.tech.newt_morada.focus();
                        return false;
                }
                else if (str5 == "")
                {
                        alert("ERRO:\n\nTem de preencher o campo \"Código Postal\".");
                        document.tech.newt_cp.focus();
                        return false;
                }
                else if (str5.length <= 4)
                {
                        alert("ERRO:\n\nCódigo Postal demasiado curto.");
                        document.tech.newt_cp.focus();
                        return false;
                }
                else if (str6 == "")
                {
                        alert("ERRO:\n\nTem de preencher o campo \"Telefone\".");
                        document.tech.newt_telef.focus();
                        return false;
                }
                else if (str6.length <= 8)
                {
                        alert("ERRO:\n\nO telefone tem de ter pelo menos 9 digitos.");
                        document.tech.newt_telef.focus();
                        return false;
                }
                else {
                        return true;
                }
        }
}

function verEmail(email) {
  var result = false
  var varEmail = new String(email)
  var varIndice = varEmail.indexOf("@");
  if (varIndice > 0) {
    var pindex = varEmail.indexOf(".",varIndice);
    if ((pindex > varIndice+1) && (varEmail.length > pindex+1))
        result = true;
  }
  return result;
}

function verNomeDom(nome)
        {
                var canSubmit = false;
                var searchValue;
                if (nome.domainToCheck)
                {
                        searchValue = nome.domainToCheck.value;
                        if (searchValue != '')
                        {
                                var regExInvalidChars = /[^a-zA-Z0-9-\s.]+/;
                                if (regExInvalidChars.test(searchValue))
                                {
                                        alert('Invalid character in domain.\n\nOnly letters, numbers or hyphens are allowed.')
                                }
                                else
                                {
                                canSubmit = true;
                                }
                        }
                        if (searchValue.length == 0)
                        {
                                alert('Please enter a domain name.')
                        }
                }
                if (canSubmit)
                {
                        return true;
                }
                else
                {
                        return false;
                }
        }


