
	// AJAX

	var xmlhttp;

	function getAjax(Metodo, Endereco, Funcao, Parametros){

		xmlhttp = getObjAjax();

		if(xmlhttp != null || Endereco.length > 0){

			xmlhttp.onreadystatechange = Funcao;

			if(Metodo=="post" && !Parametros==false && Parametros!= ""){
				xmlhttp.open("POST", Endereco, true);
				xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
				xmlhttp.send(Parametros);
			}else{
				xmlhttp.open("GET", Endereco, true);
				xmlhttp.send(null);
			}

		}

	}

	function limpa(nome) {
		document.getElementById(nome).value = "";
	}

	function getObjAjax() {

		objXML = null;

		var arrXml = new Array(
			'Msxml2.XMLHTTP.5.0',
			'Msxml2.XMLHTTP.4.0',
			'Msxml2.XMLHTTP.3.0',
			'Msxml2.XMLHTTP',
			'Microsoft.XMLHTTP');

		try {
			objXML = new XMLHttpRequest();
		} catch (e) {
			for (var i = 0; i < arrXml.length; i++) {
				try {
					objXML = new ActiveXObject(arrXml[i]);
				} catch (ee) {
					objXML = null;
				}
			}
		}

		return objXML;

	}

	function printById(id,texto){
		document.getElementById(id).innerHTML = texto;
	}

	function listarCampos(frm){
	
		var listagem = "";
		var FormCampos = frm.elements;
		var qtdCampos = frm.elements.length;
		var campo;

		this.juntarCampo = function(nome,valor) { 
								if (listagem.length > 0) { 
									listagem += "&";
								}
								listagem += encodeURIComponent(nome) + "=" + encodeURIComponent(valor);
							}

		for (var i=0; i < qtdCampos; i++) {
			campo = FormCampos[i];
			if (!campo.disabled) {
				switch(campo.type) {
					case 'text': case 'password': case 'hidden': case 'textarea': 
						this.juntarCampo(campo.name, campo.value);
						break;
					case 'select-one':
						if (campo.selectedIndex >= 0) {
							this.juntarCampo(campo.name, campo.options[campo.selectedIndex].value);
						}
						break;
					case 'select-multiple':
						for (var j=0; j < campo.options.length; j++) {
							if (campo.options[j].selected) {
								this.juntarCampo(campo.name, campo.options[j].value);
							}
						}
						break;
					case 'checkbox': case 'radio':
						if (campo.checked) {
							this.juntarCampo(campo.name, campo.value);
						}
						break;
				}
			}
		}	

		return(listagem);

	}


	function flash(arquivo, largura, altura){

		document.writeln('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' + largura + '" height="' + altura + '">');
		document.writeln('  <param name="movie" value="' + arquivo + '">');
		document.writeln('  <param name="quality" value="high">');
		document.writeln('  <param name="allowScriptAccess" value="sameDomain" />');
		document.writeln('  <param name="wmode" value="transparent" />');
		document.writeln('  <param name="menu" value="false" />');
		document.writeln('  <param name="bgcolor" value="#ffffff" />');
		document.writeln('  <embed src="' + arquivo + '" quality="high" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + largura + '" height="' + altura + '"></embed>');
		document.writeln('</object>');

	}


	function AbreJanela(link, x, y, s) {

		var t = (screen.height - y) / 2;
		var e = (screen.width - x) / 2;

		window.open(link,'','width=' + x + ',height=' + y + ',scrollbars=' + s + ',toolbar=0,location=0,status=0,menubar=0,resizable=0,left=' + e + ',top=' + t + '');

	}

	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 numeros(v){
		return v.replace(/\D/g,"");
	}

	function telefone(v){
		v=v.replace(/\D/g,"");
		v=v.replace(/^(\d\d)(\d)/g,"($1) $2");
		v=v.replace(/(\d{4})(\d)/,"$1-$2");
		return v
	}

	function codigopostal(v){
		v=v.replace(/\D/g,"");
		v=v.replace(/^(\d{5})(\d)/,"$1-$2");
		return v
	}

	function cpf(v){
		v=v.replace(/\D/g,"");
		v=v.replace(/(\d{3})(\d)/,"$1.$2");
		v=v.replace(/(\d{3})(\d)/,"$1.$2");
		v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2");
		return v
	}

	function cnpj(v){
		v=v.replace(/\D/g,"");
		v=v.replace(/^(\d{2})(\d)/,"$1.$2");
		v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3");
		v=v.replace(/\.(\d{3})(\d)/,".$1/$2");
		v=v.replace(/(\d{4})(\d)/,"$1-$2");
		return v
	}

	function rg(v){
		v=v.replace(/\D/g,"");
		v=v.replace(/(\d{2})(\d)/,"$1.$2");
		v=v.replace(/(\d{3})(\d)/,"$1.$2");
		v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2");
		return v
	}

	function $(campo){
		return document.getElementById(campo);
	}

	function chamarCalendario(mes,ano){

		getAjax('get', 'ajax/calendario.asp?m='+mes+'&a='+ano, chamarCalendario_fun);
		
	}

	function chamarCalendario_fun(){

		if(xmlhttp.readyState==4){ 
		
			if(parseInt(xmlhttp.status)==200){ 
					
				$('calendario_box').innerHTML = xmlhttp.responseText;
				
			}else{
				
				$('calendario_box').innerHTML = 'Não foi possível carregar o calendário';
				
			}
			
		}else{
			
			$('calendario_box').innerHTML = '<img src=\'img/ajax.gif\'>';
			
		}

	}

	




