function getHTMLfunction(url,pars,target,method,funcao){
		var myAjax = new Ajax.Updater(
			target, 
			url, 
			{
				method: method, 
				parameters: pars,
				onComplete: eval(funcao)
			});}
function getHTMLscript(url,pars,target,method){
	$('div_loading').show();
		var myAjax = new Ajax.Updater(
			target, 
			url, 
			{
				method: method, 
				parameters: pars,
				evalScripts: true
			});}
function getHTMLscriptfront(url,pars,target,method){
		var myAjax = new Ajax.Updater(
			target, 
			url, 
			{
				method: method, 
				parameters: pars,
				evalScripts: true
			});}
function getHTMLFormscript(url,formulario,target,method){
	show_div('div_loading');
		var pars = Form.serialize(formulario);
		var myAjax = new Ajax.Updater(
			target, 
			url, 
			{
				method: method, 
				parameters: pars,
				evalScripts: true
			});}
function getHTMLFormscriptFront(url,formulario,target,method){
		var pars = Form.serialize(formulario);
		var myAjax = new Ajax.Updater(
			target, 
			url, 
			{
				method: method, 
				parameters: pars,
				evalScripts: true
			});}
function getHTMLFormfunction(url,formulario,target,method,funcao){
		var pars = Form.serialize(formulario);
		var myAjax = new Ajax.Updater(
			target, 
			url, 
			{
				method: method, 
				parameters: pars,
				evalScripts: true
			});}
function show_div(obj){
	$(obj).style.display='block';}
function hide_div(obj){
	$(obj).style.display='none';}
function hide_div_parent(obj){
	parent.document.getElementById(obj).style.display = 'none';}

function url_encode(str) {  
        var hex_chars="0123456789ABCDEF";  
        var noEncode=/^([a-zA-Z0-9\_\-\.])$/;  
        var n, strCode, hex1, hex2, strEncode = "";  
        for(n=0;n<str.length;n++) {  
            if (noEncode.test(str.charAt(n))) {  
                strEncode+=str.charAt(n);  
            } else {  
                strCode=str.charCodeAt(n);  
                hex1=hex_chars.charAt(Math.floor(strCode / 16));  
                hex2=hex_chars.charAt(strCode % 16);  
                strEncode += "%" + (hex1 + hex2);  
            }  
        }  
        return strEncode;}  
 
function url_decode(str){  
        var n, strCode, strDecode = "";  
        for (n=0;n<str.length;n++) {  
            if (str.charAt(n) == "%") {  
                strCode=str.charAt(n + 1) + str.charAt(n + 2);  
                strDecode += String.fromCharCode(parseInt(strCode, 16));  
                n += 2;  
            } else {  
                strDecode += str.charAt(n);  
            }  
        }  
        return strDecode;}

function textCounter(field, countfield, maxlimit) {
if ($(field).value.length > maxlimit) // if too long...trim it!
$(field).value = $(field).value.substring(0, maxlimit);
else 
$(countfield).value = maxlimit - $(field).value.length;
}
function abrePopUP(URL,nome,comprimento,altura){window.open(URL,nome,'top=100,left=200,width='+comprimento+',height='+altura+'');}

function doClick(index, numTabs, id, class_on, class_off) {
$("tab"+id+index).className=class_on;
for (var i=1; i < numTabs; i++) {
$("tab"+id+(index+i)%numTabs).className=class_off;
}
$("ev"+id+index).style.display="block";
for (var j=1; j < numTabs; j++) {
$("ev"+id+(index+j)%numTabs).style.display="none";
}
}
function rePosition(objbase,objpos,pX,pY){
	var obj=$(objbase);
	var curleft=curtop=0;
	if (obj.offsetParent) {
		curleft=obj.offsetLeft
		curtop=obj.offsetTop
		while (obj=obj.offsetParent) {
			curleft+=obj.offsetLeft
			curtop+=obj.offsetTop
		}
	}
	var x=curleft;
  	var y=curtop;
	$(objpos).style.left=pX+"%";
    $(objpos).style.top=y+pY+"px";		
}
function loadRpos(obj,objPos,vLeft,vTop){
	var obj=$(obj);
	var curleft=curtop=0;
	if (obj.offsetParent) {
		curleft=obj.offsetLeft
		curtop=obj.offsetTop
		while (obj=obj.offsetParent) {
			curleft+=obj.offsetLeft
			curtop+=obj.offsetTop
		}
	}
	var x=curleft;
  	var y=curtop;
	$(objPos).style.left=x+vLeft+"px";
    $(objPos).style.top=y+vTop+"px";		
}

function montaCombo(url,target,vlr_campo,tipo,vlr_select){
    getHTMLscript(url,'vlr='+vlr_campo+'&tp='+tipo+'&selected='+vlr_select,target,'get');
}

function SoNumero(e) {
    if (window.event)
    {tecla=e.keyCode;}
    else if (e.which)
    {tecla=e.which;}
    if (tecla==8 || tecla==13)
     {event.keyCode=0; 
     }else if (tecla<40 && tecla>37)
	 {event.keyCode=0;}
    if (tecla!=8 || tecla<48 || tecla>57) return ((tecla>47) && (tecla<58))
    {return true;}
}

function moeda(z){  
v = z.value;
v=v.replace(/\D/g,"")  //permite digitar apenas nmeros
v=v.replace(/[0-9]{12}/,"inválido")   //limita pra mximo 999.999.999,99
//v=v.replace(/(\d{1})(\d{8})$/,"$1.$2")  //coloca ponto antes dos ltimos 8 digitos
//v=v.replace(/(\d{1})(\d{5})$/,"$1.$2")  //coloca ponto antes dos ltimos 5 digitos
v=v.replace(/(\d{1})(\d{1,2})$/,"$1,$2")    //coloca virgula antes dos ltimos 2 digitos
z.value = v;
}

//Exceptions
var myGlobalHandlers = {
				onException: function(request, exception) {
					alert("Js Exception: " + exception);
				}
				};
				
				Ajax.Responders.register(myGlobalHandlers);