	
	//functions.js
	//A variable used to distinguish whether to open or close the calendar.
	var showOrHide = true;
	
	function showHideCalendar() {
		
		//The location we are loading the page into.
		var objID = "calendar";
		
		//Change the current image of the minus or plus.
		if (showOrHide == true){
			//Show the calendar.
			document.getElementById("opencloseimg").src = "images/mins.gif";
			//The page we are loading.
			var serverPage = "calendar.php";
			//Set the open close tracker variable.
			showOrHide = false;
			var obj = document.getElementById(objID);
			processajax (serverPage, obj, "get", "");
		} else {
			//Hide the calendar.
			document.getElementById("opencloseimg").src = "images/plus.gif";
			showOrHide = true;
			//Reset the content.
			document.getElementById(objID).innerHTML = "";
		}
		
		
	}
	
	function createform (e, thedate){
		
		theObject = document.getElementById("createtask");
		
		theObject.style.visibility = "visible";
		theObject.style.height = "200px";
		theObject.style.width = "200px";
		
		var posx = 0;
		var posy = 0;
		
		posx = e.clientX + document.body.scrollLeft;
		posy = e.clientY + document.body.scrollTop;
		
		theObject.style.left = posx + "px";
		theObject.style.top = posy + "px";
		
		//La ubicación en la que estamos cargando la página.
		var objID = "createtask";
		var serverPage = "theform.php?thedate=" + thedate;
		
		var obj = document.getElementById(objID);
		processajax (serverPage, obj, "get", "");
		
	}
		
	function closetask (){
		
		theObject = document.getElementById("createtask");
		
		theObject.style.visibility = "hidden";
		theObject.style.height = "0px";
		theObject.style.width = "0px";
		
		acObject = document.getElementById("autocompletediv");
		
		acObject.style.visibility = "hidden";
		acObject.style.height = "0px";
		acObject.style.width = "0px";
	}
	
	function findPosX(obj){
		var curleft = 0;
		if (obj.offsetParent){
			while (obj.offsetParent){
				curleft += obj.offsetLeft
				obj = obj.offsetParent;
			}
		} else if (obj.x){
			curleft += obj.x;
		}
		return curleft;
	}
	
	function findPosY(obj){
		var curtop = 0;
		if (obj.offsetParent){
			while (obj.offsetParent){
				curtop += obj.offsetTop
				obj = obj.offsetParent;
			}
		} else if (obj.y){
			curtop += obj.y;
		}
		return curtop;
	}
	
	function autocomplete (thevalue, e){
		
		theObject = document.getElementById("autocompletediv");
		
		theObject.style.visibility = "visible";
		theObject.style.width = "152px";
		
		var posx = 0;
		var posy = 0;
		
		posx = (findPosX (document.getElementById("yourname")) + 1);
		posy = (findPosY (document.getElementById("yourname")) + 23);
		
		theObject.style.left = posx + "px";
		theObject.style.top = posy + "px";
		
		var theextrachar = e.which;
		
		if (theextrachar == undefined){
			theextrachar = e.keyCode;
		}
		
		//The location we are loading the page into.
		var objID = "autocompletediv";

		//Take into account the backspace.
		if (theextrachar == 8){
			if (thevalue.length == 1){
				var serverPage = "autocomp.php";
			} else {
				var serverPage = "autocomp.php" + "?sstring=" + thevalue.substr (0, (thevalue.length -1));
			}
		} else {
			var serverPage = "autocomp.php" + "?sstring=" + thevalue + String.fromCharCode (theextrachar);
		}
		var obj = document.getElementById(objID);
		processajax (serverPage, obj, "get", "");
	}
	
	function setvalue (thevalue){
		acObject = document.getElementById("autocompletediv");
		
		acObject.style.visibility = "hidden";
		acObject.style.height = "0px";
		acObject.style.width = "0px";
		
		document.getElementById("yourname").value = thevalue;
	}
	
	function validateform (thevalue){
		
		serverPage = "validator.php?sstring=" + thevalue;
		objID = "messagebox";
		
		var obj = document.getElementById(objID);
		processajax (serverPage, obj, "get", "");
	}
	
	function checkfortasks (thedate, e){
		
		theObject = document.getElementById("taskbox");
		
		theObject.style.visibility = "visible";
		
		var posx = 0;
		var posy = 0;
		
		posx = e.clientX + document.body.scrollLeft;
		posy = e.clientY + document.body.scrollTop;
		
		theObject.style.left = posx + "px";
		theObject.style.top = posy + "px";
		
		serverPage = "taskchecker.php?thedate=" + thedate;
		objID = "taskbox";
		
		var obj = document.getElementById(objID);
		processajax (serverPage, obj, "get", "")
	}
	
	function hidetask (){
		tObject = document.getElementById("taskbox");
		
		tObject.style.visibility = "hidden";
		tObject.style.height = "0px";
		tObject.style.width = "0px";
	}
	
	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 formulario addtask.
	function validatetask (thevalue, thename){
			;
		}
	
	
	var aok;
	
	//Funciones para enviar un formulario.
	//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 + "=" + encodeURIComponent(fobj.elements[i].value) + "&";
		}
		//Devolver los valores de la cadena
		//str2=unescape(str);
		//alert (str);
		//document.write(str);
		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);
			if(serverPage=="finalizar_seleccion.php"){
				//alert(serverPage);
				runajax (serverPage, objID, "post", str, enviar_formulario_tpv);
			}
			else{
				processajax (serverPage, obj, "post", str);
			}
		}
	}
