	//xmlhttp.js
	
	//Función para crear un objeto XML-http
	function getxmlhttp (){
		//Crear una varialbe de ool para comprobar si se utiliza una instancia válida de ActiveX Microsoft.
		var xmlhttp = false;
		
		//Comprobar si se está utilizando Internet Explorer.
		try {
			//Si la versión de javascript es superior a la 5.
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			//En caso contrario, utilizar el tradicional objeto ActiveX.
			try {
				//Si se está utilizando Internet Explorer.
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
				//En caso contrarios, no se está utilizando Internet Explorer.
				xmlhttp = false;
			}
		}
		
		//Si no se está usando Internet Explorer, crear una instancia javascript del objeto.
		if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
			xmlhttp = new XMLHttpRequest();
		}
		
		return xmlhttp;
	}
	
	
	//Función para procesar una petición XMLHttpRequest.
	function processajax (serverPage, obj,getOrPost, str){
		//Obtener el objeto XMLHttpRequest a utilizar.
		xmlhttp = getxmlhttp ();
		if (getOrPost == "get"){
			obj.innerHTML = '<span style="color:#ff5300;"><b>Validando...</b></span>';
			xmlhttp.open("GET", serverPage);
			xmlhttp.onreadystatechange = function() {
				if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
					obj.innerHTML = xmlhttp.responseText;
					if(xmlhttp.responseText=="ok"){
					closetask("datos");
					clearmes ("themessage");
					showload("themessage");
					setTimeout('clearmes ("themessage")', refreshrate);
					setTimeout('opentask("success")', refreshrate);
					}
				}
			}
			xmlhttp.send(null);
			
		} else {
			obj.innerHTML = '<span style="color:#ff5300;"><b>Validando...</b></span>';
			xmlhttp.open("POST", serverPage, true);
			xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
			xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
					obj.innerHTML = xmlhttp.responseText;
					if(xmlhttp.responseText=="ok"){
					closetask("datos");
					clearmes ("themessage");
					showload("themessage");
					setTimeout('clearmes ("themessage")', refreshrate);
					setTimeout('opentask("success")', refreshrate);
					}
				}
			}
			xmlhttp.send(str);
			
			
	}
	}
	
	function enviaficha (serverPage, obj,getOrPost, str){
		//Obtener el objeto XMLHttpRequest a utilizar.
		xmlhttp = getxmlhttp ();
			obj.innerHTML = '<span style="color:#5c2d00;">Enviando...</span>';
			xmlhttp.open("POST", serverPage, true);
			xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
			xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
					obj.innerHTML = xmlhttp.responseText;
					if(xmlhttp.responseText=="ok"){
					closetask("datosficha");
					clearmes ("ocurrencia");
					showloadenvia("ocurrencia");
					setTimeout('clearmes ("ocurrencia")', refreshrate);
					setTimeout('opentask("successficha")', refreshrate);
					}
				}
			}
			xmlhttp.send(str);
	}	
	
	//functions.js
			
	function closeopentask (hide,show,mensaje){
		clearmes (mensaje);
		
		//Ocultar hide
		closetask(hide);
		
		//Mostrar show
		opentask(show);
	}
	
	function closeopentaskficha (hide,show,mensaje){
		clearmes (mensaje);
		
		//Ocultar hide
		closetask(hide);
		
		//Mostrar show
		opentaskficha(show);
	}
	
	function muestrapagina (hide1,hide2,hide3,show){
		//Ocultar hide
		closetask(hide1);
		//Ocultar hide
		closetask(hide2);
		//Ocultar hide
		closetask(hide3);
		
		//Mostrar show
		opentask1(show);
	}
	
	function closetask (obj){
		
		theObject = document.getElementById(obj);
		theObject.style.visibility = "hidden";
		theObject.style.display = "none";
						
	}
	
	function opentask (obj){
		
		theObject = document.getElementById(obj);
		theObject.style.visibility = "visible";
		theObject.style.display = "inline";
		document.getElementById("yourname").value = "";
		document.getElementById("yourtask").value = "";
				
	}
	
	function opentask1 (obj){
		
		theObject = document.getElementById(obj);
		theObject.style.visibility = "visible";
		theObject.style.display = "inline";
						
	}
	
	function opentaskficha (obj){
		
		theObject = document.getElementById(obj);
		theObject.style.visibility = "visible";
		theObject.style.display = "inline";
		document.getElementById("nombreficha").value = "";
		document.getElementById("correoficha").value = "";
		document.getElementById("mensajeficha").value = "";
				
	}
	
	var refreshrate=1000;
	
	function clearmes (obj){
		
		document.getElementById(obj).innerHTML = "";
						
	}
	
	function showload (obj){
		
		document.getElementById(obj).innerHTML = "<img src='../images/grabar.gif'><br><span><b>Grabando...</b></span>";
						
	}
	
	function showloadenvia (obj){
		
		document.getElementById(obj).innerHTML = "<img src='../images/grabar.gif'><br><span>Enviando...</span>";
						
	}
	
	function trim(inputString) {
	   // Elimina los espacios iniciales y finales de la cadena que recibe. También elimina
	   // espacios consecutivos y los sustituye por uno solo. Si se recibe algo que no sea una 
	   //cadena (null, objeto personalizado, ...), devuelve la entrada.
	   if (typeof inputString != "string") { return inputString; }
	   var retValue = inputString;
	   var ch = retValue.substring(0, 1);
	   while (ch == " ") { // Busca espacios al principio de la cadena
	      retValue = retValue.substring(1, retValue.length);
	      ch = retValue.substring(0, 1);
	   }
	   ch = retValue.substring(retValue.length-1, retValue.length);
	   while (ch == " ") { // Busca espacios al final de la cadena
	      retValue = retValue.substring(0, retValue.length-1);
	      ch = retValue.substring(retValue.length-1, retValue.length);
	   }
	   while (retValue.indexOf("  ") != -1) { // Comprueba si hay espacios consecutivos
	      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
	   }
	   return retValue; // Devuelve la cadena sin espacios
	} // Final de la función "trim"
	
	//Función para validar el correo de la ficha del producto.
	function validaficha (thevalue, thename){
		
		var nowcont = true;
		
		if (thename == "nombreficha"){
			if (trim (thevalue) == ""){
				document.getElementById("ocurrencia").innerHTML = '<span style="color:#b55b02;">Hace falta tu nombre.</span>';
				document.getElementById("preguntaform").nombreficha.focus();
				nowcont = false;
			}
		}
		if (nowcont == true){
			if (thename == "correoficha"){
				if (trim (thevalue) == ""){
					document.getElementById("ocurrencia").innerHTML = '<span style="color:#b55b02;">Ahora, hace falta tu correo.</span>';
					document.getElementById("preguntaform").correoficha.focus();
					nowcont = false;
				}
			}
			
		}
		if (nowcont == true){
			if (thename == "mensajeficha"){
				if (trim (thevalue) == ""){
					document.getElementById("ocurrencia").innerHTML = '<span style="color:#b55b02;">Ahora, hace falta tu pregunta.</span>';
					document.getElementById("preguntaform").mensajeficha.focus();
					nowcont = false;
				}
			}
			
		}		
		return nowcont;
	}
	
	//Función para validar el formulario addtask.
	function validatetask (thevalue, thename){
		
		var nowcont = true;
		
		if (thename == "yourname"){
			if (trim (thevalue) == ""){
				document.getElementById("themessage").innerHTML = '<span style="color:#ff5300;"><b>Hace falta tu nombre.</b></span>';
				document.getElementById("newtask").yourname.focus();
				nowcont = false;
			}
		}
		if (nowcont == true){
			if (thename == "yourtask"){
				if (trim (thevalue) == ""){
					document.getElementById("themessage").innerHTML = '<span style="color:#ff5300;"><b>Ahora, hace falta tu correo.</b></span>';
					document.getElementById("newtask").yourtask.focus();
					nowcont = false;
				}
			}
		}
					
		return nowcont;
	}
	
	var aok;
	
	//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;
					}
				}
			}
			str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
		}
		//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 = document.getElementById(objID);
			processajax(serverPage, obj,"post", str);
							
			}
	}
	
	function submitficha (theform, serverPage, objID, valfunc){
		var file = serverPage;
		var str = getformvalues(theform,valfunc);
		//Si la validación es correcta.
		if (aok == true){
			obj = document.getElementById(objID);
			enviaficha(serverPage, obj,"post", str);
							
			}
	}
