function trim(inputString){
	/*Remove espaços precedentes e posteriores da string transmitida.Remove também espaços consecutivos e os substitui por um único espaço.
	Se algo além de uma string for transmitido (objeto nulo, sob medida,etc),entào retornar a entrada.*/
	if (typeof inputString != "string"){return inputString;}
	var retValue = inputString;
	var ch = retValue.substring(0,1);
	while (ch==" "){//verificar a existência de espaços no início da string
		retValue = retValue.substring(1,retValue.length);
		ch=retValue.substring(0,1);	
	 }
	ch=retValue.substring(retValue.length-1,retValue.length);
	while (ch==" "){//verificar a existência de espaços no início da string
		retValue = retValue.substring(0,retValue.length-1);
		ch = retValue.substring(retValue.length-1,retValue.length);
	} 
	while (retValue.indexOf(" ")!= -1){
		//portanto procurar espaços múltiplos na string
		retValue = retValue.substring(0,retValue.indexOf(" ")) + retValue.substring(retValue.indexOf(" ") + 1,retValue.length);
		//Novamente, há dois espaços em cada uma das strings
		//Observar que há dois espaços na string
	}
	return retValue;//Retornar a string "trim" ao usuário
}//Finaliza a função trim


	var ok;
	
//Função recebe como parâmetros nome do formulário e função de valida formulário. Retorna valores dos objetos do formulário numa string.
//Passa a string(str) à função processajax. 
function getformvalues(form,funcValForm){
		var str = "";
		ok = true;
		var val;
		
		//executa uma lista de todos os objetos contidos dentro do formulário
		for (var i=0; i < form.elements.length; i++){
		
		if(funcValForm){
			if(ok == true){
					val = funcValForm(form.elements[i].value, form.elements[i].name);
					if (val == false){
						ok = false;
					}
				}
			}	
			str += form.elements[i].name + "=" + escape(form.elements[i].value) + "&";
		}		
		
		// Em seguida retornar os valores da string
		return str;
}


// Função para submeter formulário recebendo como parâmteros: 
//nome do formulario,página php a ser processada no ajax,objeto que recebe retorno do ajax e funcao de valida formulário.
function submitform(form,serverPage,objID,funcValForm){
	var page = serverPage;
	var str = getformvalues(form,funcValForm);
	//se a validação estiver ok
	if (ok == true){
		obj = document.getElementById(objID);
		processajax(serverPage,obj,"post",str);
	}
}

//Função para mudar a cor da borda do Input Text
function mudaCor(txt,classe){
document.getElementById(txt).className=classe;
}




























