<!--
//-----------------------------------------------
// Popup
//-----------------------------------------------

function popup(theURL,winName,features) {
window.open(theURL,winName,features);
}

//-----------------------------------------------
// Validação caracteres
//-----------------------------------------------

function checkchar(input,simbol) {
  var ok = true;
  for (var i = 0; i < input.length; i++) {
    var chr = input.charAt(i);
    var found = false;
    for (var j = 0; j < simbol.length; j++) {
  
      if (chr == simbol[j]){
        found = true;
        break;
       }
    }
    if (!found) ok = false;
  }
  return ok;
}

//-----------------------------------------------
// Validação Numerica
//-----------------------------------------------

function isNumeric(str) 
{
	for (var count = 0; count < str.length; count++)
	{
		ch = str.substring(count, count + 1);
		if (!(ch >= '0' && ch <= '9'))
			return false;
	}
	return true;
}
//-----------------------------------------------
// Validação Número de Telefone
//-----------------------------------------------

function isPhoneNumber(str) 
{
	for (var count = 0; count < str.length; count++)
	{
		ch = str.substring(count, count + 1);
		if (!(ch >= '0' && ch <= '9') && (ch != '-') && (ch != '+') && (ch != ' ') && (ch != '(') && (ch != ')'))
			return false;
	}
	return true;
}
//-----------------------------------------------
// Validação E-mail
//-----------------------------------------------

//-----------------------------------------------
// Validação Form Login
//-----------------------------------------------

function check_formlogin(){

var errorMsg = "";
var email = document.getElementById('email_login').value;
var pass = document.getElementById('pass_login').value;

	if (email ==""){
		errorMsg += "E-mail\n";
		errorMsg += "-------------------\n";
	}
	if (pass ==""){
		errorMsg += "Password\n";
		errorMsg += "-------------------\n";
	}
    	if (errorMsg != ""){
		msg = "Preencha o(s) campo(s) apresentado(s) em baixo!\n\n";
		errorMsg += alert(msg + errorMsg);
		return false;
	}
	if (email == ""){
	return true;
	}
	else
	if (email.indexOf('@', 0) == -1 || email.indexOf('.', 0) == -1){ 
	alert("Insira um e-mail válido!");
	document.getElementById('email_login').focus();
	return false;
	
	}
return true;
}

//-----------------------------------------------
// Validação Quantidade de Produtos
//-----------------------------------------------

function check_quantidade() {
var sdsimbol = new Array("1", "2", "3", "4", "5", "6", "7", "8", "9", "0");
var text = document.getElementById('qtd').value;
if (text == ""){
alert("Insira Quantidade!");
text = 1;
document.getElementById('qtd').focus();
return false;
}
  if (!(text.value == "")) {
		strCheck=text;
		if (!checkchar(strCheck,sdsimbol)) {
			document.getElementById('qtd').select();
			document.getElementById('qtd').focus(); 
			alert("Só valores númericos entre 1 e 999.");
			return false;
			    
		}
   else {
		if (text < 1 || text > 999 || text == "") {
			document.getElementById('qtd').select();
			document.getElementById('qtd').focus();
			alert("Só valores númericos entre 1 e 999."); 
			
			return false;
		}		
    }
  }
return true;

}

//-----------------------------------------------
// Validação da Cor dos Óculos
//-----------------------------------------------

function check_cor(){
var cor = document.getElementById('cor').value;

    
if (cor == "") {
	alert("Não foi especificada a cor dos óculos.");
	return false;
}	

	if (check_quantidade()){
	return true;
	}
	else{
	return false;
	}

}

//-----------------------------------------------
// Validação Lentes Contacto Simples
//-----------------------------------------------


function check_lentessimples(){

var diametro = document.formmaisinfo.diametro.value;
var curvatura = document.formmaisinfo.curvatura.value;
var potenciaesf = document.formmaisinfo.potenciaesf.value;
var radio = -1;

for (i=formmaisinfo.olho.length-1; i > -1; i--) {
	if (formmaisinfo.olho[i].checked) {
	radio = i;
	}
}

if (radio == -1) {
alert("Não foi especificado o Olho.");
return (false);
}
  
if (diametro == "") {
	alert("Não foi especificado o diametro.");
	return false;
}
if (curvatura == "") {
	alert("Não foi especificada a curvatura.");
	return false;
}
if (potenciaesf == "") {
	alert("Não foi especificada a potência esférica.");
	return false;
}

	if (check_quantidade()){
	return true;
	}
	else{
	return false;
	}
 			
return true;
}

//-----------------------------------------------
// Validação Lentes Contacto Complexas
//-----------------------------------------------

function check_lentescomplexas(){

var diametro = document.getElementById("diametro").value;
var curvatura = document.getElementById("curvatura").value;
var potenciaesf = document.getElementById("potenciaesf").value;
var potenciacil = document.getElementById("potenciacil").value;
var eixo = document.getElementById("eixo").value;
var radio = -1;

for (i=formmaisinfo.olho.length-1; i > -1; i--) {
	if (formmaisinfo.olho[i].checked) {
	radio = i;
	}
}

if (radio == -1) {
alert("Não foi especificado o Olho.");
return (false);
}
    
if (diametro == "") {
	alert("Não foi especificado o diametro.");
	return false;
}
if (curvatura == "") {
	alert("Não foi especificada a curvatura.");
	return false;
}
if (potenciaesf == "") {
	alert("Não foi especificada a potência esférica.");
	return false;
}
if (potenciacil == "") {
	alert("Não foi especificada a potência cilindrica.");
	return false;
}
if (eixo == "") {
	alert("Não foi especificado o eixo.");
	return false;
}

	if (check_quantidade()){
	return true;
	}
	else{
	return false;
	}
 			
return true;
}

//-----------------------------------------------
// Validação Lentes Contacto Cor
//-----------------------------------------------

function check_lentescor(){

var diametro = document.getElementById("diametro").value;
var curvatura = document.getElementById("curvatura").value;
var potenciaesf = document.getElementById("potenciaesf").value;
var corlentes = document.getElementById("corlentes").value;
var radio = -1;

for (i=formmaisinfo.olho.length-1; i > -1; i--) {
	if (formmaisinfo.olho[i].checked) {
	radio = i;
	}
}

if (radio == -1) {
alert("Não foi especificado o Olho.");
return (false);
}

  
if (diametro == "") {
	alert("Não foi especificado o diametro.");
	return false;
		}
if (curvatura == "") {
		alert("Não foi especificada a curvatura.");
	return false;
		}
if (potenciaesf == "") {
		alert("Não foi especificada a potência esférica.");
	return false;
		}
if (corlentes == "") {
		alert("Não foi especificada a cor.");
	return false;
		}

	if (check_quantidade()){
	return true;
	}
	else{
	return false;
	}
 			
return true;
}

//-----------------------------------------------
// Validação Form Registo
//-----------------------------------------------


function check_registo() {

var nome = document.getElementById("nome").value;
var morada = document.getElementById("morada").value;
var localidade = document.getElementById("localidade").value;
var cod_post = document.getElementById("cod_post").value;
var cod_post_det = document.getElementById("cod_post_det").value;
var telefone = document.getElementById("telefone").value;
var email = document.getElementById("email").value;
var nif = document.getElementById("nif").value;
var pass = document.getElementById("pass").value;
var conf_pass = document.getElementById("conf_pass").value;
var codseg = document.getElementById("codseg").value;

	var name = 'axdfvgbhn';
	var codsegc
  	var dc = document.cookie;
  	var prefix = name + "=";
  	var begin = dc.indexOf("; " + prefix);
  	if (begin == -1) {
    	begin = dc.indexOf(prefix);
    	if (begin != 0) return null;
  	} else
    	begin += 2;
  	var end = document.cookie.indexOf(";", begin);
  	if (end == -1)
    	end = dc.length;
  	codsegc = unescape(dc.substring(begin + prefix.length, end))


		if (nome == "") {
			alert("Não foi especificado o nome do Cliente.");
		document.getElementById("nome").focus();
			return false;
		}	
		if (morada == "") {
			alert("Não foi especificada a morada do Cliente.");
		document.getElementById("morada").focus();
			return false;
		}	
		if (localidade == "") {
			alert("Não foi especificada a localidade do Cliente.");
		document.getElementById("localidade").focus();
			return false;
		}	
	

	if (cod_post == "") {
		alert("Não foi especificado o código postal do cliente.");
		document.getElementById("cod_post").focus();	
		return false;
	}
	    	    	
	if (cod_post.length != 4 || !isNumeric(cod_post)) {
		alert("O código postal especificado é inválido.");
		document.getElementById("cod_post").focus();
    	return false;
	}		   
	//if (codigopostal_det == "") {
	//	alert("Não foi especificado o código postal do cliente.");
	//	return false;
	//} 	    	
	if (cod_post_det.length != 3 || !isNumeric(cod_post_det)) {
		alert("O código postal especificado é inválido.");
	document.getElementById("cod_post_det").focus();
    	return false;
	}
	if (telefone == "") {
		alert("Não foi especificado o telefone do Cliente.");
	document.getElementById("telefone").focus();
    	return false;
	}		    	    			
	if  
		(telefone.length != 9 || !isPhoneNumber(telefone)) {
		alert("O número de telefone especificado é inválido.");
	document.getElementById("telefone").focus();
    	return false;
	}		    


	if (email == ""){
	alert("Não foi especificado o e-mail do Cliente.");
	document.getElementById("email").focus();
    	return false;
	}
	else
	if (email.indexOf('@', 0) == -1 || email.indexOf('.', 0) == -1){ 
	alert("Insira um e-mail válido!");
	document.getElementById("email").focus();
	return false;
	}
		
	//if (nif == "") {
	//	alert("Não foi especificado o Nº de Contribuinte do Cliente");
	//document.getElementById("nif").focus();
    	//return false;
	//}

	if (nif == ""){
	}
	else
		if (nif.length != 9 || !isNumeric(nif)) {
			alert("O Nº de Contribuinte especificado é Inválido.");
		document.getElementById("nif").focus();
    		return false;
	}

	if (pass == "") {
		alert("Não foi especificada a password do Cliente.");
	document.getElementById("pass").focus();
    	return false;
	}	

	if (pass.length < 4) {
		alert("A password tem de ter no mínimo 4 e o máximo 8 caractéres.");
	document.getElementById("telefone").focus();
    	return false;
	}


	if (conf_pass == "") {
		alert("Não foi especificada a confirmação da password do Cliente.");
	document.getElementById("conf_pass").focus();
    	return false;
	}

	if (pass != conf_pass){
	alert('A confirmação não coincide com a Password escolhida.');
	document.getElementById("conf_pass").focus();
	return false;
	}

	if (codseg == ""){
	alert('Insira o código de segurança apresentado na imagem.');
	document.getElementById("codseg").focus();
	return false;
	}
	else
	if (codseg != codsegc){
	alert('O código inserido não está correcto.');
	document.getElementById("codseg").focus();
	return false;
	} 

	   			
    return true;
}
//-----------------------------------------------
// Validação Form Actualizar dados Cliente
//-----------------------------------------------


function check_actualizar() {

var nome = document.getElementById("nome").value;
var morada = document.getElementById("morada").value;
var localidade = document.getElementById("localidade").value;
var cod_post = document.getElementById("cod_post").value;
var cod_post_det = document.getElementById("cod_post_det").value;
var telefone = document.getElementById("telefone").value;
var email = document.getElementById("email").value;
var nif = document.getElementById("nif").value;
var pass = document.getElementById("pass").value;
var conf_pass = document.getElementById("conf_pass").value;


		if (nome == "") {
			alert("Não foi especificado o nome do Cliente.");
		document.getElementById("nome").focus();
			return false;
		}	
		if (morada == "") {
			alert("Não foi especificada a morada do Cliente.");
		document.getElementById("morada").focus();
			return false;
		}	
		if (localidade == "") {
			alert("Não foi especificada a localidade do Cliente.");
		document.getElementById("localidade").focus();
			return false;
		}	
	

	if (cod_post == "") {
		alert("Não foi especificado o código postal do cliente.");
		document.getElementById("cod_post").focus();	
		return false;
	}
	    	    	
	if (cod_post.length != 4 || !isNumeric(cod_post)) {
		alert("O código postal especificado é inválido.");
		document.getElementById("cod_post").focus();
    	return false;
	}		   
	//if (codigopostal_det == "") {
	//	alert("Não foi especificado o código postal do cliente.");
	//	return false;
	//} 	    	
	if (cod_post_det.length != 3 || !isNumeric(cod_post_det)) {
		alert("O código postal especificado é inválido.");
	document.getElementById("cod_post_det").focus();
    	return false;
	}
	if (telefone == "") {
		alert("Não foi especificado o telefone do Cliente.");
	document.getElementById("telefone").focus();
    	return false;
	}		    	    			
	if  
		(telefone.length != 9 || !isPhoneNumber(telefone)) {
		alert("O número de telefone especificado é inválido.");
	document.getElementById("telefone").focus();
    	return false;
	}		    


	if (email == ""){
	alert("Não foi especificado o e-mail do Cliente.");
	document.getElementById("email").focus();
    	return false;
	}
	else
	if (email.indexOf('@', 0) == -1 || email.indexOf('.', 0) == -1){ 
	alert("Insira um e-mail válido!");
	document.getElementById("email").focus();
	return false;
	}
		
	//if (nif == "") {
	//	alert("Não foi especificado o Nº de Contribuinte do Cliente");
	//document.getElementById("nif").focus();
    	//return false;
	//}

	if (nif == ""){
	}
	else
		if (nif.length != 9 || !isNumeric(nif)) {
			alert("O Nº de Contribuinte especificado é Inválido.");
		document.getElementById("nif").focus();
    		return false;
	}

	if (pass == "") {
		alert("Não foi especificada a password do Cliente.");
	document.getElementById("pass").focus();
    	return false;
	}	

	if (pass.length < 4) {
		alert("A password tem de ter no mínimo 4 e o máximo 8 caractéres.");
	document.getElementById("telefone").focus();
    	return false;
	}


	if (conf_pass == "") {
		alert("Não foi especificada a confirmação da password do Cliente.");
	document.getElementById("conf_pass").focus();
    	return false;
	}

	if (pass != conf_pass){
	alert('A confirmação não coincide com a Password escolhida.');
	document.getElementById("conf_pass").focus();
	return false;
	}
	   			
    return true;
}

//-----------------------------------------------
// Mensagens
//-----------------------------------------------

function mensagens(msg){
if (msg == 1){
alert("O seu registo foi efectuado com sucesso. Está agora na sua área de cliente!");
}
if (msg == 2) {
alert("O e-mail que inseriu já consta da nossa base de dados. por favor escolha outro!");
}
if (msg == 3) {
alert("Para aceder á ''Área de Cliente'', primeiro terá de efectuar o seu registo!\n Se já for um cliente registado, faça o login.");
}
if (msg == 4) {
alert("Registo actualizado com sucesso!");
}
if (msg == 5) {
alert("Dados de acesso errados!\nSe o problema persistir contacte a Magnivisão!");
}
if (msg == 6) {
alert("O produto foi adicionado ao seu carrinho de compras!");
}
if (msg == 7) {
alert("A encomenda foi anulada com sucesso!");
}
if (msg == 8) {
alert("O e-mail que inseriu não consta da nossa base de dados!");
}
if (msg == 9) {
alert("A password foi enviada para o seu e-mail!");
}
}
//-----------------------------------------------
// Outros dados de Entrega
//-----------------------------------------------

function useroutra (){
if (document.getElementById('entrega').checked == true) {
document.getElementById('obs_ent').style.display='block';
}
else
document.getElementById('obs_ent').style.display='none';
}

//-----------------------------------------------
// Virgulas
//-----------------------------------------------
function virgulas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? ',' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + '.' + '$2');
	}
	return x1 + x2;
}
//-----------------------------------------------
// Validar Metodo Pagamento
//-----------------------------------------------
function check_metodopag() 
{

var nome = document.getElementById("nome_ent").value;
var morada = document.getElementById("morada_ent").value;
var localidade = document.getElementById("localidade_ent").value;
var cod_post = document.getElementById("cod_post_ent").value;
var cod_post_det = document.getElementById("cod_post_det_ent").value;

    	
	if (document.getElementById('tipo_correio').value == ""){
	alert("Não foi especificado o método de envio!");
    	return false;
	}

	if (document.getElementById('zona').value == "") {
		alert("Não foi especificada a zona de Entrega!");
    	return false;
	}	

	
	if (document.getElementById('meio').value == ""){
	alert("Não foi especificado o método de pagamento!");
    	return false;
	}

	
	if (document.getElementById('entrega').checked == true) {
		
	if (nome == "") {
			alert("Não foi especificado o nome do Cliente.");
		document.getElementById("nome_ent").focus();
			return false;
	}	
	if (morada == "") {
	alert("Não foi especificada a morada do Cliente.");
	document.getElementById("morada_ent").focus();
	return false;
	}	

	if (localidade == "") {
	alert("Não foi especificada a localidade do Cliente.");
	document.getElementById("localidade_ent").focus();
	return false;
	}	
	

	if (cod_post == "") {
		alert("Não foi especificado o código postal do cliente.");
		document.getElementById("cod_post_ent").focus();	
		return false;
	}
	    	    	
	if (cod_post.length != 4 || !isNumeric(cod_post)) {
		alert("O código postal especificado é inválido.");
		document.getElementById("cod_post_ent").focus();
    	return false;
	}		   
	    	
	if (cod_post_det.length != 3 || !isNumeric(cod_post_det)) {
		alert("O código postal especificado é inválido.");
	document.getElementById("cod_post_det_ent").focus();
    	return false;
	}
	}

	return true;

}
//-----------------------------------------------
// Validar anular encomenda
//-----------------------------------------------
function anularencomenda(obj, num){
if (obj.checked == true) {
document.getElementById('anulars'+num).style.display='block';
}
else
document.getElementById('anulars'+num).style.display='none';
}

function check_anularenc(form, num) 
{
var mot
var x
mot = "form.motivo" +num+ ".value";

	if (eval(mot) == "") {
		alert("Não foi especificado o motivo.");
    	return false;
	}	
	   			
    if (confirm('Esta operação irá anular a encomenda efectuada.\nTem a certeza que pretende continuar?'))		
return true;
else
return false;
}
//-----------------------------------------------
// Rec Pass
//-----------------------------------------------
function validate_recpass() 
{
var email = document.getElementById('email_pass').value;
    
if (email == ""){
	alert("Não foi especificado o e-mail do Cliente.");
	document.getElementById("email_pass").focus();
    	return false;
	}
	else
	if (email.indexOf('@', 0) == -1 || email.indexOf('.', 0) == -1){ 
	alert("Insira um e-mail válido!");
	document.getElementById("email_pass").focus();
	return false;
	}
}
//-----------------------------------------------
// Check News
//-----------------------------------------------
function check_news(){

var email = document.getElementById('email_news').value;

        if (email=="")
        {document.getElementById('email_news').focus();
	alert("Preencha o E-mail!");
	return false;
        }
        else
        if (email.indexOf('@', 0) == -1 || email.indexOf('.', 0) == -1) 
        {document.getElementById('email_news').focus();
	alert("E-mail Inválido!");
	return false;
        } 
return true;                       
}
//-----------------------------------------------
// AVISO
//-----------------------------------------------

function aviso(){
	janaviso=dhtmlmodal.open('javiso', 'div', 'modalalertdiv', 'Condições de Venda', 'width=350px,height=300px,left=350px,top=100px,resize=0,scrolling=0');
}
//-->
