function openWindow(url, propriedades) {
  window.open(url,'_blank',"toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no," + propriedades);
}

function AplicarMascara_Monetario(campo,tammax,evento) {
	
	if(document.getElementById('ativar_valor').checked != false)
	{
        var tecla = evento.keyCode;
		if(tecla==0) tecla = evento.which;
		caracteres = '1234567890';
		vr = campo.value;
		vr = vr.replace( "/", "" );
		vr = vr.replace( "/", "" );
		vr = vr.replace( ",", "" );
		vr = vr.replace( ".", "" );
		vr = vr.replace( ".", "" );
		vr = vr.replace( ".", "" );
		vr = vr.replace( ".", "" );
		tam = vr.length;

		if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

		if (tecla == 8 ){        tam = tam - 1 ; }

		if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
				if ( tam <= 2 ){
						 campo.value = vr ; }
				 if ( (tam > 2) && (tam <= 5) ){
						 campo.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
				 if ( (tam >= 6) && (tam <= 8) ){
						 campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3) + ',' + vr.substr( tam - 2, tam ) ; }
				 if ( (tam >= 9) && (tam <= 11) ){
						 campo.value = vr.substr( 0, tam - 8) + '.' + vr.substr( tam - 8, 3) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
				 if ( (tam >= 12) && (tam <= 14) ){
						 campo.value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
				 if ( (tam >= 15) && (tam <= 17) ){
						 campo.value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;}
		}
	}
}
function atualiza_campo(url,campo,zerar)
{
	// Apaga o valor dos próximos campos
	zerar = zerar.split(",");
	for(x=0;x < zerar.length; x++){
		document.getElementById(zerar[x]).options.length = 0;
	}
	///
	http.open("GET", url, true);
	http.send(null);
	http.onreadystatechange=function(){
		if (http.readyState == 4) {
			document.getElementById(campo).options.length = 0;
			results = http.responseText.split(",");
			for( i = 0; i < results.length; i++ )
			{
				string = results[i].split( "|" );
				if(string!=""){
					document.getElementById(campo).options[i] = new Option( string[0], string[1] );
				}
			}
		}
	}
}

function getHTTPObject() {
	var req;
	try {
	if (window.XMLHttpRequest) {
	req = new XMLHttpRequest();
	if (req.readyState == null) {
	req.readyState = 1;
	req.addEventListener("load", function () {
	req.readyState = 4;
	if (typeof req.onReadyStateChange == "function")
	req.onReadyStateChange();
	}, false);
	}
	return req;
	}
	if (window.ActiveXObject) {
	var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
	for (var i = 0; i < prefixes.length; i++) {
	try {
	req = new ActiveXObject(prefixes[i] + ".XmlHttp");
	return req;
	} catch (ex) {};
	}
	}
	} catch (ex) {}
	alert("XmlHttp Objects not supported by client browser");
}

var http = getHTTPObject();
