﻿oEmail = {
    handler : "Handlers/correo.aspx",
    accion : "",
    to : "",
    cc : "",
    bcc : "",
    from : "",
    nombre : "",
    msg : "",
    asunto : "",
    canal : "",
    ishtml : false,
    estado : "",
    onfinish : function(){},
    send : function(){
        var me = this;
        me.to = me.to.replace(/;/gi,",");
        me.bcc = me.to.replace(/;/gi,",");
        me.cc = me.to.replace(/;/gi,",");
        me.to = me.to.replace(/[\n\r]/gi,"");
        me.bcc = me.to.replace(/[\n\r]/gi,",");
        me.cc = me.to.replace(/[\n\r]/gi,",");
        
        if(me.to.indexOf(",")>-1 && !me.to.match(/^([a-zA-Z0-9\.\-_]+@[a-zA-Z0-9\.\-_]+\.[a-zA-Z0-9\.\-_]{2,}\s*,?\s*)+[^,]\s*$/i) ){
            alert("Favor de verificar que los correos sean válidos");
            return false;
        }else if(me.to.indexOf(",")==-1 && !me.to.match(/^([a-zA-Z0-9\.\-_]+@[a-zA-Z0-9\.\-_]+\.[a-zA-Z0-9\.\-_]{2,}\s*)$/i)){
            alert("Favor de verificar la dirección de correo");
            return false;
        }
        if(me.nombre.length < 3){
            alert("Favor de escribir el nombre completo");
            return false;
        }
        //
        var peticion = Service.HTTP._create();
	    peticion.url = me.handler;
	    peticion._add("pg","sendmail");
	    peticion._add("canal",me.canal);
	    peticion._add("to",me.to);
	    peticion._add("from",me.from);
	    peticion._add("cc",me.cc);
	    peticion._add("bcc",me.bcc);
	    peticion._add("asunto",me.asunto);
	    peticion._add("accion",me.accion);
	    peticion._add("msg",me.msg);
	    peticion._add("ishtml",me.ishtml);
	    peticion._add("nombre",me.nombre);
	    peticion.onStatus = function(estatus){
	        //alert(estatus);
	    }
        peticion.onFinish = function(){
            me.estado = peticion.response;
            me.onfinish();
        }
        peticion._post();
        return true;
    }
}
