	function nuevoAjax ()
	{
		var objXmlHttp = false;
		
		try {
			objXmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	    } catch (e) {
	    	try {
	    		objXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	    	} catch (E) {
	    		objXmlHttp = false;
			}
		}
	
		if (!objXmlHttp && typeof XMLHttpRequest!='undefined') {
			objXmlHttp = new XMLHttpRequest();
		}
		return objXmlHttp;
	}
	
	function Enviar(url, formid)
	{
		var Formulario = document.getElementById(formid);
		var longitudFormulario = Formulario.elements.length;
		var cadenaFormulario = "";
		var sepCampos = "";
		var errores = new Array ();
		var crv = new Array (0, 0, 0, 0);
		var textErr = new Array ("", "", "", "");
		var errores = new Array ();
		var crv = new Array (0, 0, 0, 0);
		var i;

		for (var i=0; i <= Formulario.elements.length-1;i++) {
			cadenaFormulario += sepCampos+Formulario.elements[i].name+'='+encodeURI(Formulario.elements[i].value);
			sepCampos="&";
		}
		peticion = nuevoAjax();
		peticion.open("POST", url, true);
		peticion.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
		peticion.send(cadenaFormulario);
		peticion.onreadystatechange = function() {
			if ((peticion.readyState == 4 || peticion.readyState == "complete") && (peticion.status == 200 || window.location.href.indexOf ("http") == - 1)){
				if (peticion.responseText == 1)
					location.href = 'mensaje.html';
				else{
					document.getElementById('respNombre').innerHTML = '';
					document.getElementById('respApellido').innerHTML = '';
					document.getElementById('respMail').innerHTML = '';
					document.getElementById('respComentario').innerHTML = '';
					
					errores = peticion.responseText.substring(0,(peticion.responseText.length - 3)).split('#');
					switch (errores.length){
						case 1:
							crv[0] = errores[0].substring((errores[0].length - 2), errores[0].length);
							break;
						case 2:
							crv[0] = errores[0].substring((errores[0].length - 2), errores[0].length);
							crv[1] = errores[1].substring((errores[1].length - 2), errores[1].length);
							break;
						case 3:
							crv[0] = errores[0].substring((errores[0].length - 2), errores[0].length);
							crv[1] = errores[1].substring((errores[1].length - 2), errores[1].length);
							crv[2] = errores[2].substring((errores[2].length - 2), errores[2].length);
							break;
						case 4:
							crv[0] = errores[0].substring((errores[0].length - 2), errores[0].length);
							crv[1] = errores[1].substring((errores[1].length - 2), errores[1].length);
							crv[2] = errores[2].substring((errores[2].length - 2), errores[2].length);
							crv[3] = errores[3].substring((errores[3].length - 2), errores[3].length);
							break;
					}
					
					for (i = 0; i < crv.length; i++){
						switch (crv[i]){
							case "01":
								document.getElementById('respNombre').innerHTML = errores[i].substring(0, (errores[i].length - 2));
								break;
							case "02":
								
								document.getElementById('respApellido').innerHTML = errores[i].substring(0, (errores[i].length - 2));
								break;
							case "03":
								document.getElementById('respMail').innerHTML = errores[i].substring(0, (errores[i].length - 2));
								break;
							case "04":
								document.getElementById('respComentario').innerHTML = errores[i].substring(0, (errores[i].length - 2));
								break;
							case 0:
								break;
						}
					}
				}
			}
		}
	}