var aok;

function urlDecode(s) 
{
	return unescape(s).replace(/\+/gi, ' ');
}

function nuevoAjax()
{
	/* Crea el objeto AJAX. Esta funcion es generica para cualquier utilidad de este tipo, por
	lo que se puede copiar tal como esta aqui */
	var xmlhttp=false;
	try
	{
		// Creacion del objeto AJAX para navegadores no IE
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			// Creacion del objet AJAX para IE
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(E) 
		{ 
			xmlhttp=false; 
		}
	}
	if (!xmlhttp && typeof XMLHttpRequest!="undefined") 
	{ 
		xmlhttp=new XMLHttpRequest(); 
	}
	return xmlhttp;
}


//Funciones para enviar un formulario. 
function getformvalues (fobj, valfunc){ 
	 
	var str = ""; 
	aok = true; 
	var val; 
	 
	//Recorrer la lista de todos los objetos que contiene el formulario. 
	for(var i = 0; i < fobj.elements.length; i++){ 
		if(valfunc) { 
			if (aok == true){ 
				val = valfunc (fobj.elements[i].value,fobj.elements[i].name);  
				if (val == false){ 
					aok = false; 
				} 
			} 
		}
		if (fobj.elements[i].type!="checkbox")
		{
			str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&"; 
		}else
		{
			if (fobj.elements[i].checked)
			{
				str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&"; 
			}
			else
			{
				str += fobj.elements[i].name + "=&"; 
			}
		}
		
	} 
	//Devolver los valores de la cadena 
	return str; 
} 

function submitform (theform, serverPage, objID, valfunc){ 
	var file = serverPage; 
	var str = getformvalues(theform,valfunc); 
	//Si la validación es correcta.
	if (aok == true){ 
		obj = objID; 
		procesarFormAjax (serverPage, obj, "post", str); 
	} 
}
  
