
	//functions.js


	function trim(inputString) {
	   // Removes leading and trailing spaces from the passed string. Also removes
	   // consecutive spaces and replaces it with one space. If something besides
	   // a string is passed in (null, custom object, etc.) then return the input.
	   if (typeof inputString != "string") { return inputString; }
	   var retValue = inputString;
	   var ch = retValue.substring(0, 1);
	   while (ch == " ") { // Check for spaces at the beginning of the string
	      retValue = retValue.substring(1, retValue.length);
	      ch = retValue.substring(0, 1);
	   }
	   ch = retValue.substring(retValue.length-1, retValue.length);
	   while (ch == " ") { // Check for spaces at the end of the string
	      retValue = retValue.substring(0, retValue.length-1);
	      ch = retValue.substring(retValue.length-1, retValue.length);
	   }
	   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
	      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
	   }
	   return retValue; // Return the trimmed string back to the user
	} // Ends the "trim" function

	//Function to validate the addtask form.
	function validatetask (thevalue, thename){

		var nowcont = true;

		if (thename == "finput"){
			if (trim (thevalue) == ""){
				document.getElementById("themessage").innerHTML = "Введите Вашу Фамилию.";
				document.getElementById("newtask").finput.focus();
				nowcont = false;
			}
		}

		if (thename == "nameinput"){
			if (trim (thevalue) == ""){
				document.getElementById("themessage").innerHTML = "Введите Ваше Имя.";
				document.getElementById("newtask").nameinput.focus();
				nowcont = false;
			}
		}
		if (thename == "otinput"){
			if (trim (thevalue) == ""){
				document.getElementById("themessage").innerHTML = "Введите Ваше Отчество.";
				document.getElementById("newtask").otinput.focus();
				nowcont = false;
			}
		}

		if (nowcont == true){
			if (thename == "telinput"){
				if (trim (thevalue) == ""){
					document.getElementById("themessage").innerHTML = "Введите контактный телефон.";
					document.getElementById("newtask").telinput.focus();
					nowcont = false;
				}
			}
		}

		if (nowcont == true){
			if (thename == "prog"){
            	if (!document.getElementById("newtask").prog.checked) {
            		document.getElementById("themessage").innerHTML = "Необходимо согласится с Cтатутом и Программой Партии.";
            		document.getElementById("newtask").prog.focus();
					nowcont = false;
				}
			}
		}

    return nowcont;
    }
	var aok;


	//Functions to submit a form.
	function getformvalues (fobj, valfunc){

		var str = "";
		aok = true;
		var val;

		//Run through a list of all objects contained within the form.
		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) + "&";
			str += fobj.elements[i].name + "=" + encodeURIComponent(fobj.elements[i].value) + "&";
		}
		//Then return the string values.
		return str;
	}

	function submitform (theform, serverPage, objID, valfunc){
		var file = serverPage;
		var str = getformvalues(theform,valfunc);
		//If the validation is ok.
		if (aok == true){
			obj = document.getElementById(objID);
			processajax (serverPage, obj, "post", str);
		}
	}
