var notificar = {
    email : 'null',
    codprod : '',
    img   : 'null',
    prod : function(codprod){
        if(isNaN(parseInt(codprod,10))) return;
        this.codprod = codprod;
        this.email = new String(prompt('Digite o email para o qual devemos enviar a notificação quando o produto estiver disponível',''));
        if(this.email == 'null') return;
        if(!this.check_email(this.email)){
             alert('Email inválido');
             return;
        }
        this.img = new Image();
        this.img.src = '../notificar/reg_notificar.php?codprod='+this.codprod+'&email='+this.email;
        this.ciclo();
        return;
    },
    ciclo : function(){
        if(this.img.complete){
            this.img = 'null';
            alert('O email '+this.email+' foi cadastrado para receber a notificação de disponibilidade.');
        }else{
            setTimeout('notificar.ciclo()',200);
        }
        return;
    },
    check_email: function(email){
        return(this.email.match(/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$/i) && this.email.length <= 256);
    }
};
var indicar = {
    email : 'null',
    codprod : '',
    img   : 'null',
    prod : function(codprod){
        if(isNaN(parseInt(codprod,10))) return;
        this.codprod = codprod;
        this.email = new String(prompt('Digite o email para quem você quer recomendar este produto',''));
        if(this.email == 'null') return;
        if(!this.check_email(this.email)){
             alert('Email inválido');
             return;
        }
        var informante = prompt('Informe seu nome','');
        if(!informante || !informante.replace(/(^\s*)|(\s*$)/,'').length) return;

        this.img = new Image();
        this.img.src = '../_produtos/indique.php?email='+this.email+'&informante='+informante;
        this.ciclo();
        return;
    },
    ciclo : function(){
        if(this.img.complete){
            this.img = 'null';
            alert('Um email de indicação foi enviado a '+this.email);
        }else{
            setTimeout('indicar.ciclo()',200);
        }
        return;
    },
    check_email: function(email){
        return(this.email.match(/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$/i) && this.email.length <= 256);
    }
};
