/**
*
*  AJAX IFRAME METHOD (AIM)
*  http://www.webtoolkit.info/
*
**/

AIM = {

	frame : function(c) {

		var n = 'f' + Math.floor(Math.random() * 99999);
		var d = document.createElement('DIV');
		d.innerHTML = '<iframe style="display:none" src="about:blank" id="'+n+'" name="'+n+'" onload="AIM.loaded(\''+n+'\')"></iframe>';
		document.body.appendChild(d);

		var i = document.getElementById(n);
		if (c && typeof(c.onComplete) == 'function') {
			i.onComplete = c.onComplete;
		}

		return n;
	},

	form : function(f, name) {
		f.setAttribute('target', name);
	},

	submit : function(f, c) {
		AIM.form(f, AIM.frame(c));
		if (c && typeof(c.onStart) == 'function') {
			return c.onStart();
		} else {
			return true;
		}
	},

	loaded : function(id) {
		var i = document.getElementById(id);
		if (i.contentDocument) {
			var d = i.contentDocument;
		} else if (i.contentWindow) {
			var d = i.contentWindow.document;
		} else {
			var d = window.frames[id].document;
		}
		if (d.location.href == "about:blank") {
			return;
		}

		if (typeof(i.onComplete) == 'function') {
			i.onComplete(d.body.innerHTML);
		}
	}

}

function checkForm(id) {
        var error = false;
        var nodes;
        nodes = $A(document.getElementsByClassName("required",id));
        nodes.each(function(node){
		        if (node.value == "") {
            	    error = true;
            	     Element.update(node.id+'-error','Requerido');
            	     Element.show(node.id+'-error');
            	}
            	else {
	           	     Element.hide(node.id+'-error');
				}
			});

        nodes = $A(document.getElementsByClassName("required-mail",id));
		nodes.each(function(node){
		        if ((node.value.indexOf(".") > 2) && (node.value.indexOf("@") > 0)) {
		             error = true;
            	     Element.update(node.id+'-error','No es Un correo Valido');
            	     Element.show(node.id+'-error');
            	}
            	else {
	           	     Element.hide(node.id+'-error');
				}
			});

        nodes = $A(document.getElementsByClassName("required-numeric",id));
		nodes.each(function(node){
	            var strChars = "0123456789.-,";
	            for (i = 0; i < node.value.length; i++) {
                strChar = node.value.charAt(i);
	                if (strChars.indexOf(strChar) == -1) {
						mal=true;
	            	}
				}

				if (mal == true){
		             error = true;
            	     Element.update(node.id+'-error','Introduzca un valor númerico [0-9][.,-]');
            	     Element.show(node.id+'-error');
				}
            	else {
	           	     Element.hide(node.id+'-error');
				}
			});
        if (error == false) {
		return true;
		}
		else {
		return false;
		}
   }
