 var ControlForm = Class.create()

ControlForm.prototype = {                       
    idForm : "formulariValidar",
    validador : null,
    win : null,
    
   initialize : function() {
		if ($('framePostUpload')) {
			if ($('submitForm') != undefined){
				Event.observe($('submitForm'), "click", this.validarFormUpload.bind(this));
				this.validador = new Validation(this.idForm);   
			}
		}
		else {
			if ($('submitForm') != undefined){
				Event.observe($('submitForm'), "click", this.validarForm.bind(this));
				this.validador = new Validation(this.idForm);   
			}
        }
        Object.extend(window,this);
    },
    
    validarForm : function (evt){
        if (this.validador.validate()){
            this.win = new Window('modal_window', {
                className: "dialog", 
                title: "",
                width:150, 
                height:80, 
                zIndex:150, 
                opacity:1, 
                minimizable: false, 
                maximizable: false,
                destroyOnClose: true, 
                recenterAuto:true,
                resizable: false}
            )
		    this.win.setDestroyOnClose();
            var params = Form.serialize(this.idForm);
		    url = "services/genericMailForm.aspx";		
		    this.win.setAjaxContent(url, {parameters:params, asynchronous:true, evalScripts: true}, true, true);
	    }
	    return false;    
    },


    validarFormUpload : function (evt){
        if (this.validador.validate()){
		    url = "services/genericMailForm.aspx?noAjax=true";		
            $(this.idForm).target = 'framePostUpload';
            $(this.idForm).action = url;
            $(this.idForm).submit();
//		    this.win.setAjaxContent(url, {parameters:params, asynchronous:true, evalScripts: true}, true, true);
	    }
	    return false;    
    },

	loadNoAjax: function(text) {
        var win = new Window('modal_window2', {
            className: "dialog", 
            title: "",
            width:150, 
            height:80, 
            zIndex:150, 
            opacity:1, 
            minimizable: false, 
            maximizable: false,
            destroyOnClose: true, 
            recenterAuto:true,
            resizable: false}
        )
		win.setDestroyOnClose();	
		win.setHTMLContent(text);
		win.showCenter();
	},
    
    finalMail: function(transport){
        		
    }    
    
}

Event.observe(window,"load",function(){ new ControlForm(); });

