// JavaScript Document

function createXMLHTTP() {
	try {
		ajax = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	catch(e) {
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
			alert(ajax);
		}
		catch(ex) {
			try {
				ajax = new XMLHttpRequest();
			}
			catch(exc) {
				alert("Este browser nao tem recursos para executar esta tarefa.");
				ajax = null;
			}
		}
	return ajax;
	}
	var arrSignatures = ["MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
	for (var i = 0; i < arrSignatures.length; i++) {
		try {
			var oRequest = new ActiveXObject(arrSignatures[i]);
			return oRequest;
		}
		catch (oError) {
		}
	}
	throw new Error("MSXML nao esta instalado no seu sistema.");
}

function charPostCod(str) {
	//Codifica os strings para o Ajax
	/*
	1 > &
	2 > %
	3 > " "
	4 > \
	5 > +
	*/
	var newStr;
	newStr = replaceStr(str, "&", "codStr[$*1*$]");
	newStr = replaceStr(newStr, "%", "codStr[$*2*$]");
	newStr = replaceStr(newStr, " ", "codStr[$*3*$]");
	newStr = replaceStr(newStr, "\\", "codStr[$*4*$]");
	newStr = replaceStr(newStr, "+", "codStr[$*5*$]");
	return newStr;
}

function replaceStr(texto, procurar, novo) {
	len = procurar.length;
	pos = texto.indexOf(procurar);
	while (pos > -1) {
		parte1 = texto.substring(0, pos);
		parte2 = texto.substring(pos + len , texto.length);
		texto = parte1 + novo + parte2;
		pos = texto.indexOf(procurar);
	}
	return texto;
}

