// JavaScript Document
function mostrar(id){
	var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
	var dsocleft=document.all? iebody.scrollLeft : pageXOffset
	var dsoctop=document.all? iebody.scrollTop : pageYOffset
	var q = $('load'+id);
	q.style.visibility="visible";
 }
function ocultar(id){
	var q = $('load'+id);
	q.style.visibility="hidden";
 }
 
 var myGlobalHandlers = {
		onCreate: function(){
			//mostrar();
		},
		onComplete: function() {
			if(Ajax.activeRequestCount == 0){
				//setTimeout("ocultar();",1950);	
			}
		}
	};

	Ajax.Responders.register(myGlobalHandlers);
	
function executarAjax(urldesti,pars,id) {
	var url = urldesti;	
	var idload = id;
	var myAjax = new Ajax.Request(
		url, 
		{  parameters: pars,
			method: 'get', 
			onComplete: showResponse
	});
}

// VALIDACIO DE FORMULARIS
function checkForm(id) {
	var error = false;
	$$('form#'+id+' .required').each(function(node){
		if (node.value == "") {
			error = true;
			node.style.background = "#FF9900";
		} else{
			node.style.background = "#FFF";
		}
	});
	$$('form#'+id+' .email').each(function(node){
		if ((node.value.indexOf(".") < 5) || (node.value.indexOf("@") == -1)) {
			error = true;
			node.style.background = "#FF9900";
		} else{
			node.style.background = "#FFF";
		}
	});
	$$('form#'+id+' .numeric').each(function(node){
		var strChars = "0123456789.-,";
		for (i = 0; i < node.value.length; i++) {
			strChar = node.value.charAt(i);
			if (strChars.indexOf(strChar) == -1) {
				error = true;
			}
			if (error){
			node.style.background = "#FF9900";
		}else{
			node.style.background = "#FFF";
		}
		}
	});
	$$('form#'+id+' .telfs').each(function(node){
		var strChars = "0123456789.-,";
		for (i = 0; i < node.value.length; i++) {
			strChar = node.value.charAt(i);
			if (strChars.indexOf(strChar) == -1) {
				error = true;
			}
		}
		if (error){
			node.style.background = "#FF9900";
		}else{
			node.style.background = "#FFF";
		}
	});
	return error;
}

function cadenaValoresForm(idform){
	var Formulario = $(idform);
	var longitudFormulario = Formulario.elements.length;
	var cadenaFormulario = ""
	var sepCampos
	sepCampos = "&"
	for (var i=0; i <= Formulario.elements.length-1;i++) {
		if (Formulario.elements[i].type == "select-multiple") {
			var lng = Formulario.elements[i].options.length;
			cadenaFormulario += sepCampos+Formulario.elements[i].name+'=';
			var spCp="";
			for (var j=0;j<lng;j++) {
				if (Formulario.elements[i].options[j].selected) {
					cadenaFormulario += spCp + Formulario.elements[i].options[j].value;
					spCp =",";
				}
			}
		}else{
			if ((Formulario.elements[i].value) == "on") {
				cadenaFormulario += sepCampos+Formulario.elements[i].name+'='+Formulario.elements[i].checked;
			}else{
				cadenaFormulario += sepCampos+Formulario.elements[i].name+'='+encodeURI(Formulario.elements[i].value);
			}
		}
	}
	return cadenaFormulario;
}