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 postwith(to, p) 
{
	var myForm = document.createElement("form");
	myForm.method="post";
	myForm.action = to;
	
	target = (BrowserDetect.browser == "Internet Explorer" && BrowserDetect.version <= "6") ? "_blank" : "_self";
	myForm.setAttribute("target", target);
	
	for (var k in p) 
	{
		var myInput = document.createElement("input") ;
		myInput.setAttribute("name", k) ;
		myInput.setAttribute("value", p[k]);
		myForm.appendChild(myInput);
	}
	document.body.appendChild(myForm);
	myForm.submit();
	document.body.removeChild(myForm);
}

function postwith2(to, p) 
{
	var myDiv = document.getElementById("divForm");
	myDiv.innerHTML = "<form name=\"frmPost\" method=\"post\" action=\"" + to + "\" id=\"frmPost\" target=\"_blank\">";

	for (var k in p) 
	{
		myDiv.innerHTML += "<input type=\"hidden\" name=\"" + k + "\" value=\"" + p[k] + "\" />"
	}

	myDiv.innerHTML += "</form>";
	document.frmPost.submit();
}

function evazio(t) 
{
	for (i = 0; i <= (t.length-1); i++) 
	{
		l=t.charAt(i);

		if (l!=" ")
		{ 
			return false 
		}
	}

	return true
}

function mascara(o,f)
{
    v_obj = o;
    v_fun = f;

    setTimeout("execmascara()",1)
}

function execmascara()
{
    v_obj.value=v_fun(v_obj.value)
}

function leech(v)
{
    v=v.replace(/o/gi,"0")
    v=v.replace(/i/gi,"1")
    v=v.replace(/z/gi,"2")
    v=v.replace(/e/gi,"3")
    v=v.replace(/a/gi,"4")
    v=v.replace(/s/gi,"5")
    v=v.replace(/t/gi,"7")

    return v
}

function soNumeros(v)
{
    return v.replace(/\D/g,"")
}

function tel(v)
{
    v=v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
    v=v.replace(/^(\d\d)(\d)/g,"($1) $2") //Coloca parênteses em volta dos dois primeiros dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")    //Coloca hífen entre o quarto e o quinto dígitos

	return v
}

function cpf(v){

    v=v.replace(/\D/g,"")                    //Remove tudo o que não é dígito

    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos

    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos

                                             //de novo (para o segundo bloco de números)

    v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") //Coloca um hífen entre o terceiro e o quarto dígitos

    return v

}



function cepv(v)
{
    v=v.replace(/D/g,"")                //Remove tudo o que não é dígito
    v=v.replace(/^(\d{5})(\d)/,"$1-$2") //Esse é tão fácil que não merece explicações

	return v
}



function cnpj(v)
{
    v=v.replace(/\D/g,"")                           //Remove tudo o que não é dígito
    v=v.replace(/^(\d{2})(\d)/,"$1.$2")             //Coloca ponto entre o segundo e o terceiro dígitos
    v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3") //Coloca ponto entre o quinto e o sexto dígitos
    v=v.replace(/\.(\d{3})(\d)/,".$1/$2")           //Coloca uma barra entre o oitavo e o nono dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")              //Coloca um hífen depois do bloco de quatro dígitos

    return v

}



function abrePopup(theURL,W,H,features) { //v2.0

	var L = (screen.width/2) - (W/2);
	var T = (screen.height/2) - (H/2) - 24;

	window.open(theURL,'',"Width="+W+",Height="+H+",Top="+T+",Left="+L+",resizable=no,"+features);
}

var BrowserDetect = {
    init: function () {
        this.browser = this.searchString(this.dataBrowser) || "Não reconhecido";
        this.version = this.searchVersion(navigator.userAgent)
            || this.searchVersion(navigator.appVersion)
            || "Versão não detectada";
        this.OS = this.searchString(this.dataOS) || "Sistema não detectado";
        
        if(this.browser == null) {
            return null;
        }

    },
    searchString: function (data) {
        for (var i=0;i<data.length;i++)    {
            var dataString = data[i].string;
            var dataProp = data[i].prop;
            this.versionSearchString = data[i].versionSearch || data[i].identity;
            if (dataString) {
                if (dataString.indexOf(data[i].subString) != -1)
                    return data[i].identity;
            }
            else if (dataProp)
                return data[i].identity;
        }
    },
    searchVersion: function (dataString) {
        var index = dataString.indexOf(this.versionSearchString);
        if (index == -1) return;
        return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
    },
    dataBrowser: [
        {     
			string: navigator.userAgent,
            subString: "OmniWeb",
            versionSearch: "OmniWeb/",
            identity: "OmniWeb"
        },
        {
            string: navigator.vendor,
            subString: "Apple",
            identity: "Safari"
        },
        {
            prop: window.opera,
            identity: "Opera"
        },
        {
            string: navigator.vendor,
            subString: "iCab",
            identity: "iCab"
        },
        {
            string: navigator.vendor,
            subString: "KDE",
            identity: "Konqueror"
        },
        {
            string: navigator.userAgent,
            subString: "Firefox",
            identity: "Firefox"
        },
        {
            string: navigator.vendor,
            subString: "Camino",
            identity: "Camino"
        },
        {        // for newer Netscapes (6+)
            string: navigator.userAgent,
            subString: "Netscape",
            identity: "Netscape"
        },
        {
            string: navigator.userAgent,
            subString: "MSIE",
            identity: "Internet Explorer",
            versionSearch: "MSIE"
        },
        {
            string: navigator.userAgent,
            subString: "Gecko",
            identity: "Mozilla",
            versionSearch: "rv"
        },
        {         // for older Netscapes (4-)
            string: navigator.userAgent,
            subString: "Mozilla",
            identity: "Netscape",
            versionSearch: "Mozilla"
        }
    ],
    dataOS : [
        {
            string: navigator.platform,
            subString: "Win",
            identity: "Windows"
        },
        {
            string: navigator.platform,
            subString: "Mac",
            identity: "Mac"
        },
        {
            string: navigator.platform,
            subString: "Linux",
            identity: "Linux"
        }
    ]

};
BrowserDetect.init();

function getXmlHttpRequest() 
{
	var httpRequest = null;
	try 
	{
		httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
	} 
	catch (e) 
	{
		try 
		{
			httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch (e) 
		{
			httpRequest = null;
		}
	}
	
	if (!httpRequest && typeof XMLHttpRequest != "undefined")
	{
		httpRequest = new XMLHttpRequest();
	}
	
	return httpRequest;
}

function makeRequest(tipo, url, post, returnFunction) 
{
	var varRequest = null;

	if (window.XMLHttpRequest) 
	{ // Mozilla, Safari,...
		varRequest = new XMLHttpRequest();
		if (varRequest.overrideMimeType) 
		{
		    varRequest.overrideMimeType('text/xml');
			// See note below about this line
		}
	} 
	else if (window.ActiveXObject) 
	{ // IE
		try 
		{
			varRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) 
		{
			try 
			{
				varRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e) {}
		}
	}

	if (!varRequest) 
	{
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}

	varRequest.onreadystatechange = function() 
	{
		if(varRequest.readyState == 4)
		{
			if (varRequest.status == 200)
			{
				try
				{
					returnFunction(tipo,varRequest)
				}
				catch(e){}
			}
		}
    }

	varRequest.open('GET', url, true);
	varRequest.send(post);
}

function execOnSuccess(stateChangeCallback) 
{
	return function(xmlHttpReq) 
	{
		if (xmlHttpReq.readyState == 4 && xmlHttpReq.status == 200) 
		{
		  stateChangeCallback(xmlHttpReq);
		}
	};
}

function getNavegador()
{
	agent = navigator.userAgent;
	
	IE = (agent.indexOf("MSIE") > -1)?true:false;
	FIREFOX  = (agent.indexOf("Firefox")> -1)?true:false;

	if (IE)
		return "IE";
	else
		if (FIREFOX)
			return "FIREFOX";
}


function SomenteLetras(e)
{
    var tecla = (window.event) ? event.keyCode : e.which;

	//alert(tecla);
	
	if (tecla <= 46)
		return true;
	if (tecla >= 65 && tecla <= 90) 
		return true;
	else if (tecla >= 97 && tecla <= 122)
		return true;
	else
		return false;
}

function BloquearCtrl(e)
{
	var tecla = (window.event) ? event.keyCode : (e.which ? e.which : e.charCode);

	if (tecla==17){
		//event.which = 0;
		return false;
	}
}

function SomenteNumero(teclapres)
{
// codigo ASCII da tecla pressionada
	switch (getNavegador())	
	{
		case 'IE':
			codtecla = teclapres.keyCode;
			break;
		case 'FIREFOX':
			codtecla = teclapres.which;
			break;
	}

	//alert(codtecla);
	if (!(((codtecla >= 48) && (codtecla <= 57)) || ((codtecla >= 48) && (codtecla <= 57)) || (codtecla == 0) || (codtecla == 8) || (codtecla == 9) || (codtecla == 13)))
		return false;
}


function check_email(emailStr)
{
	var emailPat = /^(.+)@(.+)$/
	var specialChars = "\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars = "\[^\\s" + specialChars + "\]"
	var quotedUser = "(\"[^\"]*\")"
	var ipDomainPat = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom = validChars + '+'
	var word = "(" + atom + "|" + quotedUser + ")"
	var userPat = new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat = new RegExp("^" + atom + "(\\." + atom +")*$")

	var matchArray = emailStr.match(emailPat)
	if (matchArray == null)
	{
		return false;
	}

	var user = matchArray[1]
	var domain = matchArray[2]

	if (user.match(userPat) == null)
	{
		return false;
	}

	var IPArray = domain.match(ipDomainPat)

	if (IPArray != null)
	{
		for (var i=1;i<=4;i++)
		{
			if (IPArray[i]>255)
			{
			return false;
			}
		}
		return true;
	}

	var domainArray = domain.match(domainPat)

	if (domainArray == null)
	{
		return false;
	}
	
	var atomPat = new RegExp(atom,"g")
	var domArr = domain.match(atomPat)
	var len = domArr.length
	
	var pos_arroba = emailStr.indexOf("@");
	var str_pos_arroba = emailStr.substr(pos_arroba+1);
	var ponto = str_pos_arroba.indexOf(".");
	var str_dominio = emailStr.substr(pos_arroba, ponto);
	
	if((str_dominio.length) <= 1)
	{
		return false;
	}
	
	if (domArr[domArr.length-1].length < 2 || domArr[domArr.length-1].length > 3)
	{
  		return false;
	}

	if (len < 2)
	{
  		return false;
	}
	return true;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
