
//Function to process an XMLHttpRequest.
function processajax (serverPage, obj, getOrPost, str){
	//Get an XMLHttpRequest object for use.
	xmlhttp = getxmlhttp ();
	if (getOrPost == "get"){
		xmlhttp.open("GET", serverPage);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				obj.innerHTML = xmlhttp.responseText;
			}
		}
	xmlhttp.send(null);
	} else {
	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;
			}
		}
	xmlhttp.send(str);
	}
}


function getxmlhttp(){

	//Create a boolean variable to check for a valid Microsoft active x instance.
	var xmlhttp = false;

	//Check if we are using internet explorer.
	try {
		//If the javascript version is greater than 5.
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		//If not, then use the older active x object.
		try {
			//If we are using internet explorer.
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			//Else we must be using a non-internet explorer browser.
			xmlhttp = false;
		}
	}
	// If not using IE, create a
	// JavaScript instance of the object.
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		xmlhttp = new XMLHttpRequest();
		}
	return xmlhttp;
	}
	
// validate form
function validateform (thevalue){
	serverPage = "validator.php?sstring=" + thevalue;
	objID = "messagebox";
	var obj = document.getElementById(objID);
	xmlhttp.open("GET", serverPage);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		obj.innerHTML = xmlhttp.responseText;
		}
	}
xmlhttp.send(null);
}



try{
    xmlhttp = new XMLHttpRequest();
}catch(ee){
    try{
       xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
       try{
          xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
       }catch(E){
          xmlhttp = false;
       }
    }
}



//Function to validate the addtask form.
function validatetask (thevalue, thename){
	var nowcont = true;
	if (thename == "remnome"){
		if (trim (thevalue) == ""){
		document.getElementById("themessage").innerHTML = "<span class=aviso>Digite seu nome</span>";
		//document.getElementById("lrconteudo").yourname.focus();
		nowcont = false;
		}
	}
	if (thename == "rememail"){
		if (trim (thevalue) == ""){
		document.getElementById("themessage").innerHTML = "<span class=aviso>Digite seu e-mail</span>";
		//document.getElementById("lrconteudo").yourname.focus();
		nowcont = false;
		}
	}
	if (thename == "remtelefone"){
		if (trim (thevalue) == ""){
		document.getElementById("themessage").innerHTML = "<span class=aviso>Digite seu telefone</span>";
		//document.getElementById("lrconteudo").yourname.focus();
		nowcont = false;
		}
	}
	if (thename == "destnome"){
		if (trim (thevalue) == ""){
		document.getElementById("themessage").innerHTML = "<span class=aviso>Digite o nome de seu amigo</span>";
		//document.getElementById("lrconteudo").yourname.focus();
		nowcont = false;
		}
	}
	if (nowcont == true){
		if (thename == "destemail"){
			if (trim (thevalue) == ""){
			document.getElementById("themessage").innerHTML = "<span class=aviso>Digite o e-mail de seu amigo</span>";
			//document.getElementById("lrconteudo").yourname.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 = validatetask(fobj.elements[i].value,fobj.elements[i].name);
				if (val == false){
					aok = false;
				}
			}
		}
	str += fobj.elements[i].name + "=" + escape(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);
	}
}


function trim (inputString) {
	// Removes leading and trailing spaces from the passed string. Also removes
	// consecutive spaces and replaces them 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 there are two spaces in the string
		// Therefore look for multiple spaces in 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 show a loading message.
function updateStatus()
{
	//document.getElementById("errordiv").innerHTML = "";
	document.getElementById("lrconteudo").innerHTML = "<span class=aviso> Carregando ... </span>";
}

function conteudo(conteudo){
    //Abre a conexão
	updateStatus(); 

    xmlhttp.open("GET",conteudo);
    xmlhttp.onreadystatechange=mostracont
    //Executa
    xmlhttp.send(null)

}

function mostracont() {
if (xmlhttp.readyState==4){
   //Mostra o HTML recebido
   document.getElementById('lrconteudo').innerHTML=xmlhttp.responseText
   }
}




function updateStatuspostar()
{
	//document.getElementById("errordiv").innerHTML = "";
	document.getElementById("lrpostar").innerHTML = "<span class=aviso> Carregando ... </span>";
}


function postar(conteudo){
    //Abre a conexão
	updateStatuspostar(); 

    xmlhttp.open("GET",conteudo);
    xmlhttp.onreadystatechange=mostrapostar
    //Executa
    xmlhttp.send(null)

}

function mostrapostar() {
if (xmlhttp.readyState==4){
   //Mostra o HTML recebido
   document.getElementById('lrpostar').innerHTML=xmlhttp.responseText
   }
}


	

//-->



<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->

<!--
function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}





//-->




