﻿function showCities() {
    if (document.getElementById('boxCidades').style.display == 'none' || document.getElementById('boxCidades').style.display == '') {
        document.getElementById('boxCidades').style.display = 'block';
        document.getElementById('clearBox').style.display = 'block';
    }
    else {
        document.getElementById('boxCidades').style.display = 'none';
        document.getElementById('clearBox').style.display = 'none';
    }
}
function showFlutuante(obj)
{
    document.getElementById(obj).style.display = 'block';
    
    if(obj != 'bodyDadosImovel')
    {
        document.getElementById('bodyDadosImovel').style.display = 'none';
        document.getElementById('menuDadosImovel').className = 'itemMenuBody';
    }
    else
    {
        document.getElementById('menuDadosImovel').className = 'itemMenuBody2';
    }
    if(obj != 'bodyLocalizacao')
    {
        document.getElementById('menuLocalizacao').className = 'itemMenuBody';
        document.getElementById('bodyLocalizacao').style.display = 'none';
    }
    else
    {
        document.getElementById('menuLocalizacao').className = 'itemMenuBody2';
    }
    if(obj != 'bodyCaracteristicas')
    {
        document.getElementById('menuCaracteristicas').className = 'itemMenuBody';
        document.getElementById('bodyCaracteristicas').style.display = 'none';
    }
    else
    {
        document.getElementById('menuCaracteristicas').className = 'itemMenuBody2';
    }
}


function SetUniqueRadioButton(nameregex, current)
{
   re = new RegExp(nameregex);
   for(i = 0; i < document.forms[0].elements.length; i++)
   {
      elm = document.forms[0].elements[i]
      if (elm.type == 'radio')
      {
         if (re.test(elm.name))
         {
            elm.checked = false;
         }
      }
   }
   current.checked = true;
}

function FormataCNPJ(Campo, teclapres){

   if(window.event){
    var tecla = teclapres.keyCode;
   }else  tecla = teclapres.which;

   var vr = new String(Campo.value);
   vr = vr.replace(".", "");
   vr = vr.replace(".", "");
   vr = vr.replace("/", "");
   vr = vr.replace("-", "");

   tam = vr.length + 1;

   
   if (tecla != 9 && tecla != 8){
      if (tam > 2 && tam < 6)
         Campo.value = vr.substr(0, 2) + '.' + vr.substr(2, tam);
      if (tam >= 6 && tam < 9)
         Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,tam-5);
      if (tam >= 9 && tam < 13)
         Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,tam-8);
      if (tam >= 13 && tam < 15)
         Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4)+ '-' + vr.substr(12,tam-12);
      }
}

function OnlyNumbers(Campo)
{
    c = Campo.value;
    numbers = '';
    n = 0;
    for(i=0;i<c.length;i++)
    {
        if((parseInt(c.charAt(i)) >= 0 && parseInt(c.charAt(i)) <= 9))
        {
            numbers += c.charAt(i)
        }
        
    }
    Campo.value = numbers;
}

function FormataCPF(Campo, teclapres)
{
   if(window.event)
   {
		var tecla = teclapres.keyCode;
   }
   else
	    tecla = teclapres.which;

   var vr = new String(Campo.value);

   vr = vr.replace(".", "");
   vr = vr.replace(".", "");
   vr = vr.replace("-", "");

   tam = vr.length + 1;

   if (tecla != 9 && tecla != 8)
   {
      if (tam > 3 && tam < 6)
         Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, tam);

      if (tam >= 7 && tam < 9)
         Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,tam-6);

      if (tam >= 10 && tam < 13)
         Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + '-' + vr.substr(9,tam-9);
    }
}


function ShowFotoGrande(Item, Iurl, Xurl)
{
    x=document.getElementById(Item);
    x.src = Iurl;
    
    /*
    if(Xurl != '')
    {
        x.onclick = "ShowFotoExtraGrande('" + Xurl + "')";
    }
    else
    {
        x.onclick = "";
    }
    */
}

function ShowFotoExtraGrande(Iurl)
{
    hrefPopup('./PopupFotoExtraGrande.aspx?urlfoto=' + Iurl, '640', '480', 'no', '')
}

function PopupTelefone(idAnuncio)
{
    hrefPopup('./PopupTelefone.aspx?idanuncio='+idAnuncio, '230', '110', 'no', 'PopupTelefone')
}

function linkImpressao(idAnuncio)
{
    hrefPopup('./Detalhes.aspx?idanuncio='+idAnuncio + '&versao=print', '778', '600', 'yes', 'Impressao');
}

function linkVendeSe(idAnuncio)
{
    hrefPopup('./PlacaVendeSe.aspx?idanuncio='+idAnuncio + '&versao=print', '778', '600', 'yes', 'Impressao');
}

function linkRecuperarSenha()
{
    hrefPopup('../RecuperarSenha.aspx', '445', '260', 'yes', 'RecuperarSenha');
}
			
function linkEnviar(page, parametros)
{
	window.open('/MaxTemporada/Envie.aspx?link='+page+''+parametros,'','width=445,height=398,left='+(screen.width-445)/2+',top='+(screen.height-398)/2)
}



function linkResponderProposta(idPropostaAnuncio)
{
    hrefPopup('./DetalheProposta.aspx?idpropostaanuncio='+idPropostaAnuncio, '445', '398', 'yes', 'Proposta');
}

function FormataDATA(Campo, teclapres){

   if(window.event)
   {
    var tecla = teclapres.keyCode;
   }
   else  
   tecla = teclapres.which;

   var vr = new String(Campo.value);
   vr = vr.replace("/", "");

   tam = vr.length + 1;

   
   if (tecla != 9 && tecla != 8){
      if (tam > 2 && tam < 6)
         Campo.value = vr.substr(0, 2) + '/' + vr.substr(2, tam);

      if (tam >= 7 && tam < 9)
         Campo.value = vr.substr(0,2) + '/' + vr.substr(2,2) + '/' + vr.substr(4,tam-4);

      if (tam >= 10 && tam < 10)
         Campo.value = vr.substr(0,2) + '/' + vr.substr(2,2) + '/' + vr.substr(4,4);
         }

}






/*
var vr = new String(Campo.value);
   vr = vr.replace(".", "");
   vr = vr.replace(".", "");
   vr = vr.replace("/", "");
   vr = vr.replace("-", "");

   tam = vr.length + 1;

   
   if (tecla != 9 && tecla != 8){
      if (tam > 2 && tam < 6)
         Campo.value = vr.substr(0, 2) + '.' + vr.substr(2, tam);
      if (tam >= 6 && tam < 9)
         Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,tam-5);
      if (tam >= 9 && tam < 13)
         Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,tam-8);
      if (tam >= 13 && tam < 15)
         Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4)+ '-' + vr.substr(12,tam-12);
      }
*/






//function FormataNUM(Campo, teclapres)
//{
//   if(window.event)
//   {
//		var tecla = teclapres.keyCode;
//   }
//   else
//	    tecla = teclapres.which;

//   var vr = new String(Campo.value);

//   vr = vr.replace(",", "");
//   vr = vr.replace(".", "");

//   tam = vr.length + 1;
//   if(tam >= 9)
//   {
//        Campo.value = Campo.value.substr(0, tam)
//        return;
//        
//   }

//  
//   if (tecla != 9 && tecla != 8)
//   {
//      
//      if(tam > 2)
//      {
//        vr = vr.substr(0, tam-2) + ',' + vr.substr(tam-2, 2);
//      }
//      
//      if(tam > 5)
//      {
//        vr = vr.substr(0, tam-5) + '.' + vr.substr(tam-5, 5);
//      }
//      
//      if(tam > 8)
//      {
//        vr = vr.substr(0, 9-8) + '.' + vr.substr(9-8, 8);
//      }
//      
//      Campo.value = vr;
//    }
//   
//  /*
//   if (tecla != 9 && tecla != 8)
//   {
//      if (tam >= 3 && tam < 6)
//         Campo.value = vr.substr(0, 1) + ',' + vr.substr(1, tam);
//      if(tam > 3 && tam < 6)   
//         Campo.value = vr.substr(0, 2) + ',' + vr.substr(2, 2)
//      if(tam > 4 && tam < 6)   
//         Campo.value = vr.substr(0, 3) + ',' + vr.substr(3, 3)
//    }
//    */
//}

function OnlyNumbers2(Campo)
{
    c = Campo.value;
    numbers = '';
    n = 0;
    for(i=0;i<c.length;i++)
    {
        if((parseInt(c.charAt(i)) >= 0 && parseInt(c.charAt(i)) <= 9))
        {
            numbers += c.charAt(i)
        }
        
    }
    return numbers;
}

function FormataNUM(Campo, teclapres, maxlength)
{
   if(window.event)
   {
		var tecla = teclapres.keyCode;
   }
   else
	    tecla = teclapres.which;

   var vr = new String(OnlyNumbers2(Campo));
   
   Campo.Value = vr;
   
   //alert(tecla);

   vr = vr.replace(",", "");
   vr = vr.replace(".", "");
   
   var scape = 0;
   
   if(maxlength > 2)
   {
    scape = 1;
   }
   
   if(maxlength > 7)
   {
    scape = 2;
   }
   
   if(maxlength > 10)
   {
    scape = 3;
   }

   if(tecla >= 48 && tecla <= 57)
   {
        tam = vr.length;
        if((tam + scape) > maxlength)
        {
            tam = tam - 1;
        }
   }
   else
   {
        tam = vr.length;
        if((tam + scape) > maxlength)
        {
            tam = tam - 1;
        }
   }
   
   //alert(tam);
   
   if (tecla >= 48 && tecla <= 57)
   {
      if(tam > 2)
      {
        vr = vr.substr(0, tam-2) + ',' + vr.substr(tam-2, 2);
        tam = tam + 1;
      }
      
      if(tam > 6)
      {
        vr = vr.substr(0, tam-6) + '.' + vr.substr(tam-6, 6);
        tam = tam + 1;
        //alert(vr);
      }
      
      if(tam > 10)
      {
        vr = vr.substr(0, tam-10) + '.' + vr.substr(tam-10, 10);
      }
      
      
      
      Campo.value = vr;
    }
   
  /*
   if (tecla != 9 && tecla != 8)
   {
      if (tam >= 3 && tam < 6)
         Campo.value = vr.substr(0, 1) + ',' + vr.substr(1, tam);
      if(tam > 3 && tam < 6)   
         Campo.value = vr.substr(0, 2) + ',' + vr.substr(2, 2)
      if(tam > 4 && tam < 6)   
         Campo.value = vr.substr(0, 3) + ',' + vr.substr(3, 3)
    }
    */
}
/* Mascara qualquer tipo númerico, como CPF, CEP, TELEFONE e CNPJ */
//
// getKey(key)
// Gets keycode. If 'x' is pressed then it hides the lightbox.
//

function getKey(e){
	if (e == null) { // ie
		keycode = event.keyCode;
	} else { // mozilla
		keycode = e.which;
	}
	key = String.fromCharCode(keycode).toLowerCase();
	
	if(key == 'x'){ hideLightbox(); }
}

//
// listenKey()
//
function listenKey () {	document.onkeypress = getKey; }

//
// addLoadEvent()
// Adds event to window.onload without overwriting currently assigned onload functions.
// Function found at Simon Willison's weblog - http://simon.incutio.com/
//
function addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}

/**
  * Get element by Id
  *
  * @param string Element name
  * @return object Element object
  */
function xGetElementById(e) {
	if(typeof(e)!='string') 
		return e;
	if(document.getElementById) 
		e=document.getElementById(e);
	else if(document.all) 
		e=document.all[e];
	else 
		e=null;
	return e;
}

/**
  * Get parent
  *
  * @param string Element name
  * @param boolean Node
  * @return object Parent object
  */
function xParent(e,bNode){
	if (!(e=xGetElementById(e))) return null;
	var p=null;
	if (!bNode && xDef(e.offsetParent)) p=e.offsetParent;
	else if (xDef(e.parentNode)) p=e.parentNode;
	else if (xDef(e.parentElement)) p=e.parentElement;
	return p;
}

/**
  * Verifies if defined
  * 
  * @param mixed
  * @return boolean
  */
function xDef() {
	for(var i=0; i<arguments.length; ++i){
		if(typeof(arguments[i])=='undefined') 
			return false;
	}
	return true;
}

/**
  * Verifies if string
  *
  * @param mixed
  * @return boolean
  */
function xStr(s) {
	for(var i=0; i<arguments.length; ++i){
		if(typeof(arguments[i])!='string') 
			return false;
	}
	return true;
}

/**
  * Verifies if number
  *
  * @param mixed
  * @return boolean
  */
function xNum(n) {
	for(var i=0; i<arguments.length; ++i){
		if(typeof(arguments[i])!='number') 
			return false;
	}
	return true;
}

/**
  * Shows element
  *
  * @param string Element name
  */
function xShow(e) {
	if(!(e=xGetElementById(e))) 
		return;
	if(e.style && xDef(e.style.visibility)) 
		e.style.visibility='visible';
}

/**
  * Hides element
  *
  * @param string Element name
  */
function xHide(e) {
	if(!(e=xGetElementById(e))) 
		return;
	if(e.style && xDef(e.style.visibility)) 
		e.style.visibility='hidden';
}

/**
  * Sets z index
  *
  * @param string Element name
  * @param int Z index
  * @return int Z index
  */
function xZIndex(e,uZ) {
	if(!(e=xGetElementById(e))) 
		return 0;
	if(e.style && xDef(e.style.zIndex)) {
		if(xNum(uZ)) 
			e.style.zIndex=uZ;
		uZ=parseInt(e.style.zIndex);
	}
	return uZ;
}


/**
  * Sets element color
  *
  * @param string Element name
  * @param string Color
  * @return string Color
  */
function xColor(e,sColor) {
	if(!(e=xGetElementById(e))) 
		return '';
	var c='';
	if(e.style && xDef(e.style.color)) {
		if(xStr(sColor)) 
			e.style.color=sColor;
		c=e.style.color;
	}
	return c;
}


/**
  * Sets element background
  *
  * @param string Element name
  * @param string Color
  * @param string Image url
  * @return string Background
  */
function xBackground(e,sColor,sImage) {
	if(!(e=xGetElementById(e))) 
		return '';
	var bg='';
	if(e.style) {
		if(xStr(sColor)) {
			if(!xOp5or6) 
				e.style.backgroundColor=sColor;
			else e.style.background=sColor;
		}
		if(xStr(sImage)) 
			e.style.backgroundImage=(sImage!='')? 'url('+sImage+')' : null;
		if(!xOp5or6) 
			bg=e.style.backgroundColor;
		else 
			bg=e.style.background;
	}
	return bg;
}


/**
  * Move element
  *
  * @param string Element name
  * @param int X
  * @param int Y
  */
function xMoveTo(e,iX,iY) {
	xLeft(e,iX);
	xTop(e,iY);
}

/**
  * Sets element left position
  *
  * @param string Element name
  * @param int X
  * @return int X
  */
function xLeft(e,iX) {
	if(!(e=xGetElementById(e))) 
		return 0;
	var css=xDef(e.style);
	if (css && xStr(e.style.left)) {
		if(xNum(iX)) 
			e.style.left=iX+'px';
		else {
			iX=parseInt(e.style.left);
			if(isNaN(iX)) 
				iX=0;
		}
	} else if(css && xDef(e.style.pixelLeft)) {
		if(xNum(iX)) 
			e.style.pixelLeft=iX;
		else 
			iX=e.style.pixelLeft;
	}
	return iX;
}

/**
  * Sets element top position
  *
  * @param string Element name
  * @param int Y
  * @return int Y
  */
function xTop(e,iY) {
	if(!(e=xGetElementById(e))) 
		return 0;
	var css=xDef(e.style);
	if(css && xStr(e.style.top)) {
		if(xNum(iY)) 
			e.style.top=iY+'px';
		else {
			iY=parseInt(e.style.top);
			if(isNaN(iY)) 
				iY=0;
		}
	} else if(css && xDef(e.style.pixelTop)) {
		if(xNum(iY)) 
			e.style.pixelTop=iY;
		else 
			iY=e.style.pixelTop;
	}
	return iY;
}

/**
  * Gets page X
  *
  * @param string Element name
  * @return int X
  */
function xPageX(e) {
	if (!(e=xGetElementById(e))) 
		return 0;
	var x = 0;
	while (e) {
		if (xDef(e.offsetLeft)) 
			x += e.offsetLeft;
		e = xDef(e.offsetParent) ? e.offsetParent : null;
	}
	return x;
}

/**
  * Gets page Y
  *
  * @param string Element name
  * @return int Y
  */
function xPageY(e) {
	if (!(e=xGetElementById(e))) 
		return 0;
	var y = 0;
	while (e) {
		if (xDef(e.offsetTop)) 
			y += e.offsetTop;
		e = xDef(e.offsetParent) ? e.offsetParent : null;
	}
	//  if (xOp7) return y - document.body.offsetTop; // v3.14, temporary hack for opera bug 130324
	return y;
}

/**
  * Gets offset left
  *
  * @param string Element name
  * @return int Offset
  */
function xOffsetLeft(e) {
	if (!(e=xGetElementById(e))) 
		return 0;
	if (xDef(e.offsetLeft)) 
		return e.offsetLeft;
	else return 0;
}

/**
  * Gets offset top
  *
  * @param string Element name
  * @return int Offset
  */
function xOffsetTop(e) {
	if (!(e=xGetElementById(e))) 
		return 0;
	if (xDef(e.offsetTop)) 
		return e.offsetTop;
	else return 0;
}

/**
  * Scrolls to left
  *
  * @param string Element name
  * @return int Offset
  */
function xScrollLeft(e) {
	var offset=0;
	if (!(e=xGetElementById(e))) {
		if(document.documentElement && document.documentElement.scrollLeft) 
			offset=document.documentElement.scrollLeft;
		else if(document.body && xDef(document.body.scrollLeft)) 
			offset=document.body.scrollLeft;
	} else { 
		if (xNum(e.scrollLeft)) 
			offset = e.scrollLeft; 
	}
	return offset;
}

/**
  * Scrolls to top
  *
  * @param string Element name
  * @return int Offset
  */
function xScrollTop(e) {
	var offset=0;
	if (!(e=xGetElementById(e))) {
		if(document.documentElement && document.documentElement.scrollTop) 
			offset=document.documentElement.scrollTop;
		else if(document.body && xDef(document.body.scrollTop)) 
			offset=document.body.scrollTop;
	} else { 
		if (xNum(e.scrollTop)) 
			offset = e.scrollTop; 
	}
	return offset;
}


/**
  * Checks if has point
  *
  * @param string Element name
  * @param int Left
  * @param int Top
  * @param int Clip top
  * @param int Clip right
  * @param int Clip bottom
  * @param int Clip left
  * @return boolean
  */
function xHasPoint(ele, iLeft, iTop, iClpT, iClpR, iClpB, iClpL) {
	if (!xNum(iClpT)){
		iClpT=iClpR=iClpB=iClpL=0;
	} else if (!xNum(iClpR)){
		iClpR=iClpB=iClpL=iClpT;
	} else if (!xNum(iClpB)){
		iClpL=iClpR; iClpB=iClpT;
	}
	var thisX = xPageX(ele), thisY = xPageY(ele);
	return (iLeft >= thisX + iClpL && iLeft <= thisX + xWidth(ele) - iClpR && iTop >=thisY + iClpT && iTop <= thisY + xHeight(ele) - iClpB );
}

/**
  * Resizes element
  *
  * @param string Element name
  * @param int Width
  * @param int Height
  */
function xResizeTo(e,uW,uH) {
	xWidth(e,uW);
	xHeight(e,uH);
}

/**
  * Sets element width
  *
  * @param string Element name
  * @param int Width
  * @return int Width
  */
function xWidth(e,uW) {
	if(!(e=xGetElementById(e))) 
		return 0;
	if (xNum(uW)) {
		if (uW<0) 
			uW = 0;
		else 
			uW=Math.round(uW);
	} else 
		uW=-1;
	var css=xDef(e.style);
	if(css && xDef(e.offsetWidth) && xStr(e.style.width)) {
		if(uW>=0) 
			xSetCW(e, uW);
		uW=e.offsetWidth;
	} else if(css && xDef(e.style.pixelWidth)) {
		if(uW>=0) 
			e.style.pixelWidth=uW;
		uW=e.style.pixelWidth;
	}
	return uW;
}

/**
  * Sets element height
  *
  * @param string Element name
  * @param int Height
  * @return int Height
  */
function xHeight(e,uH) {
	if(!(e=xGetElementById(e))) 
		return 0;
	if (xNum(uH)) {
		if (uH<0) 
			uH = 0;
		else 
			uH=Math.round(uH);
	} else 
		uH=-1;
	var css=xDef(e.style);
	if(css && xDef(e.offsetHeight) && xStr(e.style.height)) {
		if(uH>=0) 
			xSetCH(e, uH);
		uH=e.offsetHeight;
	} else if(css && xDef(e.style.pixelHeight)) {
		if(uH>=0) 
			e.style.pixelHeight=uH;
		uH=e.style.pixelHeight;
	}
	return uH;
}

/**
  * Gets computed style
  *
  * @param string Element name
  * @param string Property
  * @return int Computed style
  */
function xGetCS(ele,sP){
	return parseInt(document.defaultView.getComputedStyle(ele,'').getPropertyValue(sP));
}

/**
  * Sets CS Width
  *
  * @param string Element name
  * @param int Width  
  */
function xSetCW(ele,uW){
	var pl=0,pr=0,bl=0,br=0;
	if(xDef(document.defaultView) && xDef(document.defaultView.getComputedStyle)){
		pl=xGetCS(ele,'padding-left');
		pr=xGetCS(ele,'padding-right');
		bl=xGetCS(ele,'border-left-width');
		br=xGetCS(ele,'border-right-width');
	}else if(xDef(ele.currentStyle,document.compatMode)){
		if(document.compatMode=='CSS1Compat'){
			pl=parseInt(ele.currentStyle.paddingLeft);
			pr=parseInt(ele.currentStyle.paddingRight);
			bl=parseInt(ele.currentStyle.borderLeftWidth);
			br=parseInt(ele.currentStyle.borderRightWidth);
		}
	} else if(xDef(ele.offsetWidth,ele.style.width)){ // ?
		ele.style.width=uW+'px';
		pl=ele.offsetWidth-uW;
	}
	if(isNaN(pl)) 
		pl=0; 
	if(isNaN(pr)) 
		pr=0; 
	if(isNaN(bl)) 
		bl=0; 
	if(isNaN(br)) 
		br=0;
		
	var cssW=uW-(pl+pr+bl+br);
	if(isNaN(cssW)||cssW<0) 
		return;
	else 
		ele.style.width=cssW+'px';
}

/**
  * Sets CS Height
  *
  * @param string Element name
  * @param int Height  
  */
function xSetCH(ele,uH){
	var pt=0,pb=0,bt=0,bb=0;
	if(xDef(document.defaultView) && xDef(document.defaultView.getComputedStyle)){
		pt=xGetCS(ele,'padding-top');
		pb=xGetCS(ele,'padding-bottom');
		bt=xGetCS(ele,'border-top-width');
		bb=xGetCS(ele,'border-bottom-width');
	} else if(xDef(ele.currentStyle,document.compatMode)){
		if(document.compatMode=='CSS1Compat'){
			pt=parseInt(ele.currentStyle.paddingTop);
			pb=parseInt(ele.currentStyle.paddingBottom);
			bt=parseInt(ele.currentStyle.borderTopWidth);
			bb=parseInt(ele.currentStyle.borderBottomWidth);
		}
	} else if(xDef(ele.offsetHeight,ele.style.height)){ // ?
		ele.style.height=uH+'px';
		pt=ele.offsetHeight-uH;
	}
	
	if(isNaN(pt)) 
		pt=0; 
	if(isNaN(pb)) 
		pb=0; 
	if(isNaN(bt)) 
		bt=0; 
	if(isNaN(bb)) 
		bb=0;
	var cssH=uH-(pt+pb+bt+bb);
	if(isNaN(cssH)||cssH<0) 
		return;
	else 
		ele.style.height=cssH+'px';
}

/**
  * Sets clip
  *
  * @param string Element name
  * @param int Top
  * @param int Right
  * @param int Bottom
  * @param int Left
  */
function xClip(e,iTop,iRight,iBottom,iLeft) {
	if(!(e=xGetElementById(e))) 
		return;
	if(e.style) {
		if (xNum(iLeft)) 
			e.style.clip='rect('+iTop+'px '+iRight+'px '+iBottom+'px '+iLeft+'px)';
		else 
			e.style.clip='rect(0 '+parseInt(e.style.width)+'px '+parseInt(e.style.height)+'px 0)';
	}
}

/**
  * Gets client width
  *
  * @return int Width
  */
function xClientWidth() {
	var w=0;
	if(xOp5or6) w=window.innerWidth;
	else if(!window.opera && document.documentElement && document.documentElement.clientWidth)
	w=document.documentElement.clientWidth;
	else if(document.body && document.body.clientWidth)
	w=document.body.clientWidth;
	else if(xDef(window.innerWidth,window.innerHeight,document.height)) {
		w=window.innerWidth;
		if(document.height>window.innerHeight) w-=16;
	}
	return w;
}

/**
  * Gets client height
  *
  * @return int Height
  */
function xClientHeight() {
	var h=0;
	if(xOp5or6) h=window.innerHeight;
	else if(!window.opera && document.documentElement && document.documentElement.clientHeight)
	h=document.documentElement.clientHeight;
	else if(document.body && document.body.clientHeight)
	h=document.body.clientHeight;
	else if(xDef(window.innerWidth,window.innerHeight,document.width)) {
		h=window.innerHeight;
		if(document.width>window.innerWidth) h-=16;
	}
	return h;
}

/**
  * Sets inner html
  *
  * @param string Element name
  * @param string Html
  * @return string Html
  */
function xInnerHtml(e, sHtml) {
	if(!(e=xGetElementById(e))) 
		return '';
	if (xStr(e.innerHTML)) {
		if (xStr(sHtml)) 
			e.innerHTML = sHtml;
		else 
			return e.innerHTML;
	}
}

/**
  * Displays element
  *
  * @param string Element name
  */
function xDisplay(e) {
	if(!(e=xGetElementById(e))) 
		return;
	if(e.style && xDef(e.style.display)) 
		e.style.display = 'inline';
}

/**
  * Displays element
  *
  * @param string Element name
  */
function xDisplay2(e) {
	if(!(e=xGetElementById(e))) 
		return;
	if(e.style && xDef(e.style.display)) 
		e.style.display = '';
}

/**
  * Changes element display
  *
  * @param string Element name
  */
function xChangeDisplay(e) {
	if(!(e=xGetElementById(e))) 
		return;
	if(e.style && xDef(e.style.display)) {
		if(e.style.display == 'none')
			e.style.display = 'inline';
		else
			e.style.display = 'none';
	}
}

/**
  * Hides an element
  *
  * @param string Element name
  */
function xNoDisplay(e) {
	if(!(e=xGetElementById(e))) 
		return;
	if(e.style && xDef(e.style.display)) 
		e.style.display='none';
}

/**
  * Changes Image source
  *
  * @param string Element name
  * @param string Image src
  */
function xChangeImageSrc(e, source) {
	if(!(e=xGetElementById(e))) 
		return;
	if(e.src) 
		e.src=source;
}

/**
  * Displays element
  *
  * @param string Element name
  */
function xDisplayPos(e, e2, x, y) {
	if(!(e=xGetElementById(e)))
	return;

	if(e.style && xDef(e.style.display))
	e.style.display='';

	var left = xPageX(e2) + x;
	var top = xPageY(e2) + y;

	xLeft(e, left);
	xTop(e, top)
}

/**
  * Verifies if it's empty
  *
  * @param strin Value to be tested
  * @return boolean
  */
function isEmpty(value) {
	return ((value == null) || (value.length == 0));
}

/**
  * Verifies if it's whitespaces only
  *
  * @param strin Value to be tested
  * @return boolean
  */
function isWhitespace(value) {
	if(isEmpty(value)) return true;
	
	for(i=0; i<value.length; i++) {
		if(value.charAt(i) != ' ') {
			return false;
		}
	}
	return true;
}

/**
  * Verifies if it's a number
  *
  * @param strin Value to be tested
  * @return boolean
  */
function isNumber(value) {
	if(isEmpty(value)) return false;

	var reg = new RegExp('^[0-9]{1,15}(\,[0-9]{1,2}){0,1}$');
	if(value.match(reg))
		return true;
	return false;
}

/**
  * Verifies if it's digits only
  *
  * @param strin Value to be tested
  * @return boolean
  */
function isDigits(value) {
	if(isEmpty(value)) return false;

	var reg = new RegExp('^[0-9]+$');
	if(value.match(reg))
		return true;
	return false;
}


/**
  * Verifies if it's a phone
  *
  * @param strin Value to be tested
  * @return boolean
  */
function isPhone(value) {
	if(isEmpty(value)) return false;
	
	var reg = new RegExp('^[0-9]{3,4}[\-]{1}[0-9]{4}$');
	if(value.match(reg))
		return true;
	if(isDigits(value) && (value.length == 7 || value.length == 8))
		return true;
	return false;
}

/**
  * Verifies if it's a CEP
  *
  * @param strin Value to be tested
  * @return boolean
  */
function isCep(value) {
	if(isEmpty(value)) return false;
	
	var reg = new RegExp('^[0-9]{5}[\-]{1}[0-9]{3}$');
	if(value.match(reg))
		return true;
	if(isDigits(value) && value.length == 8)
		return true;
	return false;
}

/**
  * Verifies if it's a email
  *
  * @param strin Value to be tested
  * @return boolean
  */
function isEmail(value) {
	if(isEmpty(value)) return false;
	var reg = new RegExp('^([0-9,a-z,A-Z]+)([.,_,-]([0-9,a-z,A-Z]+))*[@]([0-9,a-z,A-Z]+)([.,_,-]([0-9,a-z,A-Z]+))*[.]([0-9,a-z,A-Z]){2}([0-9,a-z,A-Z])?$');
	if(value.match(reg))
		return true;
	return false;
}

/**
  * Verifies if it's a URL
  *
  * @param strin Value to be tested
  * @return boolean
  */
function isUrl(value) {
	if(isEmpty(value)) return false;

	var reg = new RegExp('^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*[^\.\,\)\(\s]$');
	if(value.match(reg))
		return true;
	return false;
}

/**
  * Verifies if it's a date
  *
  * @param strin Value to be tested
  * @return boolean
  */
function isDate(value) {
	if(isEmpty(value)) return false;
	var reg = new RegExp('^[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4}$');
	var data;
	var a_data;
	if(value.match(reg)) {
		a_data = value.split('/');
	} else {
		reg = new RegExp('^[0-9]{1,2}\-[0-9]{1,2}\-[0-9]{4}$');
		if(value.match(reg)) {
			a_data = value.split('-');
		} else {
			return false;
		}
	}
	a_data[0] = parseInt(a_data[0]);
	a_data[1] = parseInt(a_data[1]) - 1;
	a_data[2] = parseInt(a_data[2]);
	data = new Date(a_data[2],a_data[1],a_data[0]);
	if(data.getMonth() == a_data[1])
		return true;
	return false;
}

/*
 * lib_util.js
 *
 * (C) Copyright 2006 CCCCorp. All rights reserved.
 * Use is subject to license terms.
 */

/**
 * Utility library
 *
 * @author Juciano Araujo
 * @version 0.1
 */

var undefined;

/**
  * Submits a form
  *
  * @param string Fuseaction
  * @param object Form object
  */
function formSubmit (go, form) {
	if(go != '') {
		form.go.value = go;
	}

	form.submit();
}

/**
  * Cancels a form
  */
function formCancel() {
	if (window.history.length) {
		history.back();
	} else if (window.opener && !window.opener.closed) {
		self.close();
	}
}

/**
  * Gets a cookie
  *
  * @param string Cookie name
  * @return string Cookie value
  */
function getCookie(name) {
	if (document.cookie.length > 0) {
		var begin = document.cookie.indexOf(name+"=");
		if (begin != -1) {
			begin += name.length+1;
			var end = document.cookie.indexOf(";", begin);
			if (end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(begin, end));
		}
	}
	return null;
}

/**
  * Sets a cookie
  *
  * @param string Cookie name
  * @param string Cookie value
  */
function setCookie(name, value, expiredays) {
	var ExpireDate = new Date ();
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
	document.cookie = name + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}

/**
  * Removes a cookie
  *
  * @param string Cookie name
  */
function delCookie (name) {
	document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

/**
  * Sets the windows status
  *
  * @param string Message
  */
function setStatus(message) {
	window.status = message;
}

/**
  * Updates parent
  */
function updateParent() {
	if (window.opener && !window.opener.closed) {
		window.opener.location.href = window.opener.document.URL;
	}
	self.close();
}


/**
  * Opens a popup window
  *
  * @param string url
  * @param int width
  * @param int height
  * @param boolean scroll
  * @param string name
  */
function hrefPopup(url, width, height, scroll, name) {

   var win  = null;
   var winl = (screen.width - width)/2;
   var wint = (screen.height - height)/2;

   settings = 'height='+height+',width='+width+',top='+wint+',left='+winl+',scrollbars='+scroll+',toolbar=no,location=no,status=no,menubar=no,resizable=no,dependent=yes'

   if (name == '') {
      name = '_window';
   }

   win = window.open (''+url+'', ''+name+'', settings);
   if (parseInt(navigator.appVersion) >= 4) {
      win.window.focus();
   }
}

/**
  * Reloads a window
  */
function reload() {
	window.location.reload();
}

/**
  * Sets a refresh
  *
  * @param int time
  */
function refresh(time) {
	setTimeout("reload()", time);
}

/**
  * Counts the number of chars in input
  *
  * @param object Field
  * @param object Count Field
  * @param int Maximum number of chars
  */
function textCounter(field, countfield, maxlimit) {
   if (field.value.length > maxlimit) {
      field.value = field.value.substring(0, maxlimit);
   } else {
      countfield.value = maxlimit - field.value.length;
   }
}

/**
  * Changes array of checkbox
  *
  * @param object Checkbox
  * @param object Form
  * @param string Field name
  */
function changeCheck(check, form, name) {
	var field = form.elements[name];
	if(!field) return;
	if(!field.length) {
		field.checked = check.checked;
	} else {
		for(var i=0; i<field.length; i++) {
			field[i].checked = check.checked;
		}
	}
}

function anyChecked(form, name, msg) {
	var field = form.elements[name];
	if(!field) return;
	if(!field.length) {
		if(field.checked) {
			return true;
		}
	} else {
		for(var i=0; i<field.length; i++) {
			if(field[i].checked) {
				return true;
			}
		}
	}

	if(msg.length) {
		alert(msg);
	}
	return false;

}

function selected(name) {
	var select = xGetElementById(name);
	return select.options[select.selectedIndex].value;
}

function list_limit(select) {
	var limit = select.options[select.selectedIndex].value;
	var url = location.href;

	if(url.indexOf('&limit=') != -1) {
		url = url.replace(/limit=[0-9]*/, 'limit=' + limit);
	} else {
		url = url + '&limit=' + limit;
	}
	location.href = url;
}

function list_search(form) {

	var search = xGetElementById('SEARCH');
	var ssel = form.elements['SEARCH_SELECT[]'];
	var schk = form.elements['SEARCH_CHECK[]'];

	var url = location.href;

	if(search) {
		if(url.indexOf('&search=') != -1) {
			url = url.replace(/search=[^&]*/, 'search=' + escape(search.value));
		} else {
			url = url + '&search=' + escape(search.value);
		}

		if(ssel) {
			if(ssel.selectedIndex != undefined) {
				if(url.indexOf('&ssel1=') != -1) {
					url = url.replace(/ssel1=[^&]*/, 'ssel1=' + ssel.options[ssel.selectedIndex].value);
				} else {
					url = url + '&ssel1=' + ssel.options[ssel.selectedIndex].value;
				}
			} else {

				for(var i=0; i<ssel.length; i++) {
					if(url.indexOf('&ssel' + (i+1) + '=') != -1) {
						url = url.replace("&ssel"+(i+1)+'=', '&ssel0=');
						url = url.replace(/ssel0=[^&]*/, 'ssel' + (i+1) + '=' + ssel[i].options[ssel[i].selectedIndex].value);
					} else {
						url = url + '&ssel' + (i+1) + '=' + ssel[i].options[ssel[i].selectedIndex].value;
					}
				}
			}
		}

		if(schk) {
			if(!schk.length) {
				if(url.indexOf('&schk1=') != -1) {
					url = url.replace(/schk1=[^&]*/, (schk.checked ? 'schk1=' + schk.value : ''));
				} else {
					url = url + (schk.checked ? '&schk1=' + schk.value : '');
				}
			} else {

				for(var i=0; i<schk.length; i++) {
					if(url.indexOf('&schk' + (i+1) + '=') != -1) {
						url = url.replace("&schk"+(i+1)+'=', '&schk0=');
						url = url.replace(/schk0=[^&]*/, (schk[i].checked ? 'schk' + (i+1) + '=' + schk[i].value : ''));
					} else {
						url = url + (schk[i].checked ? '&schk' + (i+1) + '=' + schk[i].value : '');
					}
				}
			}
		}

	}
	location.href = url;
}

function list_search_default(form) {

	var ssel = form.elements['SEARCH_SELECT[]'];
	var schk = form.elements['SEARCH_CHECK[]'];
	var stex = form.elements['SEARCH_TEXT[]'];

	var url = location.href;

	if(form.elements['URL']) {
		url = form.elements['URL'].value;
	}
	if(ssel) {
		if(ssel.selectedIndex != undefined) {
			if(url.indexOf('&ssel1=') != -1) {
				url = url.replace(/ssel1=[^&]*/, 'ssel1=' + ssel.options[ssel.selectedIndex].value);
			} else {
				url = url + '&ssel1=' + ssel.options[ssel.selectedIndex].value;
			}
		} else {

			for(var i=0; i<ssel.length; i++) {
				if(url.indexOf('&ssel' + (i+1) + '=') != -1) {
					url = url.replace("&ssel"+(i+1)+'=', '&ssel0=');
					url = url.replace(/ssel0=[^&]*/, 'ssel' + (i+1) + '=' + ssel[i].options[ssel[i].selectedIndex].value);
				} else {

					url = url + '&ssel' + (i+1) + '=' + ssel[i].options[ssel[i].selectedIndex].value;
				}
			}
		}
	}

	if(schk) {
		if(!schk.length) {
			if(url.indexOf('&schk1=') != -1) {
				url = url.replace(/schk1=[^&]*/, (schk.checked ? 'schk1=' + schk.value : ''));
			} else {
				url = url + (schk.checked ? '&schk1=' + schk.value : '');
			}
		} else {

			for(var i=0; i<schk.length; i++) {
				if(url.indexOf('&schk' + (i+1) + '=') != -1) {
					url = url.replace("&schk"+(i+1)+'=', '&schk0=');
					url = url.replace(/schk0=[^&]*/, (schk[i].checked ? 'schk' + (i+1) + '=' + schk[i].value : ''));
				} else {
					url = url + (schk[i].checked ? '&schk' + (i+1) + '=' + schk[i].value : '');
				}
			}
		}
	}
	if(stex) {

		if(!stex.length) {
			if(url.indexOf('&stex1=') != -1) {
				url = url.replace(/stex1=[^&]*/, 'stex1=' + escape(stex.value));
			} else {
				url = url + '&stex1=' + escape(stex.value);
			}
		} else {
			for(var i=0; i<stex.length; i++) {
				if(url.indexOf('&stex' + (i+1) + '=') != -1) {
					url = url.replace("&stex"+(i+1)+'=', '&stex0=');
					url = url.replace(/stex0=[^&]*/, 'stex' + (i+1) + '=' + escape(stex[i].value));
				} else {
					url = url + '&stex' + (i+1) + '=' + stex[i].value;
				}
			}
		}
	}

	location.href = url;
}

function list_search_default_url(form, link) {

	var ssel = form.elements['SEARCH_SELECT[]'];
	var schk = form.elements['SEARCH_CHECK[]'];
	var stex = form.elements['SEARCH_TEXT[]'];

	var url = location.href;

	if(form.elements['URL']) {
		url = form.elements['URL'].value;
	}
	if(ssel) {
		if(ssel.selectedIndex != undefined) {
			if(url.indexOf('&ssel1=') != -1) {
				url = url.replace(/ssel1=[^&]*/, 'ssel1=' + ssel.options[ssel.selectedIndex].value);
			} else {
				url = url + '&ssel1=' + ssel.options[ssel.selectedIndex].value;
			}
		} else {

			for(var i=0; i<ssel.length; i++) {
				if(url.indexOf('&ssel' + (i+1) + '=') != -1) {
					url = url.replace("&ssel"+(i+1)+'=', '&ssel0=');
					url = url.replace(/ssel0=[^&]*/, 'ssel' + (i+1) + '=' + ssel[i].options[ssel[i].selectedIndex].value);
				} else {

					url = url + '&ssel' + (i+1) + '=' + ssel[i].options[ssel[i].selectedIndex].value;
				}
			}
		}
	}

	if(schk) {
		if(!schk.length) {
			if(url.indexOf('&schk1=') != -1) {
				url = url.replace(/schk1=[^&]*/, (schk.checked ? 'schk1=' + schk.value : ''));
			} else {
				url = url + (schk.checked ? '&schk1=' + schk.value : '');
			}
		} else {

			for(var i=0; i<schk.length; i++) {
				if(url.indexOf('&schk' + (i+1) + '=') != -1) {
					url = url.replace("&schk"+(i+1)+'=', '&schk0=');
					url = url.replace(/schk0=[^&]*/, (schk[i].checked ? 'schk' + (i+1) + '=' + schk[i].value : ''));
				} else {
					url = url + (schk[i].checked ? '&schk' + (i+1) + '=' + schk[i].value : '');
				}
			}
		}
	}
	if(stex) {

		if(!stex.length) {
			if(url.indexOf('&stex1=') != -1) {
				url = url.replace(/stex1=[^&]*/, 'stex1=' + escape(stex.value));
			} else {
				url = url + '&stex1=' + escape(stex.value);
			}
		} else {
			for(var i=0; i<stex.length; i++) {
				if(url.indexOf('&stex' + (i+1) + '=') != -1) {
					url = url.replace("&stex"+(i+1)+'=', '&stex0=');
					url = url.replace(/stex0=[^&]*/, 'stex' + (i+1) + '=' + escape(stex[i].value));
				} else {
					url = url + '&stex' + (i+1) + '=' + stex[i].value;
				}
			}
		}
	}
	url = url.substring(url.indexOf("&"));

	location.href = link + url;
}

function list_orderby(name) {
	var url = location.href;

	if(url.indexOf('&order=') != -1) {
		url = url.replace(/order=[^&]*/, 'order=' + escape(name));
	} else {
		url = url + '&order=' + escape(name);
	}

	location.href = url;
}


function OpenFile( fileUrl ) {
	window.top.opener.SetUrl( fileUrl ) ;
	window.top.close() ;
	window.top.opener.focus() ;
}


function preloadImages() {
	var d=document; if(d.images){ if(!d.p) d.p=new Array();
	var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

addEvent = function(o, e, f, s){
    var r = o[r = "_" + (e = "on" + e)] = o[r] || (o[e] ? [[o[e], o]] : []), a, c, d;
    r[r.length] = [f, s || o], o[e] = function(e){
        try{
            (e = e || event).preventDefault || (e.preventDefault = function(){e.returnValue = false;});
            e.stopPropagation || (e.stopPropagation = function(){e.cancelBubble = true;});
            e.target || (e.target = e.srcElement || null);
            e.key = (e.which + 1 || e.keyCode + 1) - 1 || 0;
        }catch(f){}
        for(d = 1, f = r.length; f; r[--f] && (a = r[f][0], o = r[f][1], a.call ? c = a.call(o, e) : (o._ = a, c = o._(e), o._ = null), d &= c !== false));
        return e = null, !!d;
    }
};

removeEvent = function(o, e, f, s){
    for(var i = (e = o["_on" + e] || []).length; i;)
        if(e[--i] && e[i][0] == f && (s || o) == e[i][1])
            return delete e[i];
    return false;
};

MaskInput = function(f, m){ //v1.0
    function mask(e){
        var patterns = {"1": /[A-Z]/i, "2": /[0-9]/, "4": /[À-ÿ]/i, "8": /./ },
            rules = { "a": 3, "A": 7, "9": 2, "C":5, "c": 1, "*": 8};
        function accept(c, rule){
            for(var i = 1, r = rules[rule] || 0; i <= r; i<<=1)
                if(r & i && patterns[i].test(c))
                    break;
                return i <= r || c == rule;
        }
        var k, mC, r, c = String.fromCharCode(k = e.key), l = f.value.length;
        (!k || k == 8 ? 1 : (r = /^(.)\^(.*)$/.exec(m)) && (r[0] = r[2].indexOf(c) + 1) + 1 ?
            r[1] == "O" ? r[0] : r[1] == "E" ? !r[0] : accept(c, r[1]) || r[0]
            : (l = (f.value += m.substr(l, (r = /[A|9|C|\*]/i.exec(m.substr(l))) ?
            r.index : l)).length) < m.length && accept(c, m.charAt(l))) || e.preventDefault();
    }
    for(var i in !/^(.)\^(.*)$/.test(m) && (f.maxLength = m.length), {keypress: 0, keyup: 1})
        addEvent(f, i, mask);
}
/*
forceMask = function(f, m)
{
    v = f.value;
    var nstr;
    for(k=1;k<v.length;k++)
    {
        nstr += v.substr(1,v.indexOf(m.charAt(k))
    }
}
*/
/*
forceMask = function(f,m)
{
    v = f.value;
    s = 0;
    svalue = '';
    var nstr='';
    for(k=0;k<m.length;k++)
    {
        //if(isNumber(m.charAt(k)) && isNumber)
        nstr += isNumber(m.charAt(k)) ? v.charAt(k) + (s > 0 ? (for (t=1;t<=s;t++){svalue+=v.charAt(k+t)}return svalue) : '') : m.charAt(k);
        alert(nstr)
    }
}*/
forceMask = function(f,m)
{
    onlyNumbers = function(c)
    {
        numbers = '';
        n = 0;
        for(i=0;i<c.length;i++)
        {
            if((parseInt(c.charAt(i)) >= 0 && parseInt(c.charAt(i)) <= 9))
            {
                numbers += c.charAt(i)
            }
            
        }
        return numbers;
    }
    v = f.value;
    var nstr='';
    s = 0;
    svalue = '';
    if(v.length > 0)
    {
    for(k=0;k<m.length;k++)
    {
        if(!(parseInt(m.charAt(k)) >= 0 && parseInt(m.charAt(k)) <= 9))
        {
           if(v.charAt(k) != m.charAt(k) || (k + 1)==v.length)
           s += 1;
        }
        nstr += (parseInt(m.charAt(k)) >= 0 ? v.charAt(k-s) : m.charAt(k))
    }
    if(nstr.length == m.length)
        f.value = nstr;
    else
        f.value = onlyNumbers(v)
    }
}

function FormataCEP(Campo, teclapres) {
    if (window.event) {
        var tecla = teclapres.keyCode;
    }
    else
        tecla = teclapres.which;

    var vr = new String(Campo.value);

    vr = vr.replace("-", "");
    vr = vr.replace("-", "");

    tam = vr.length + 1;

    if (tecla != 9 && tecla != 8) {
        if (tam > 5)
            Campo.value = vr.substr(0, 5) + '-' + vr.substr(5, tam);
    }
}

function FormataData(Campo, teclapres) {
    if (window.event) {
        var tecla = teclapres.keyCode;
    }
    else
        tecla = teclapres.which;

    var vr = new String(Campo.value);

    vr = vr.replace("/", "");
    vr = vr.replace("/", "");

    tam = vr.length + 1;

    if (tecla != 9 && tecla != 8) {
        if (tam > 2 && tam < 5)
            Campo.value = vr.substr(0, 2) + '/' + vr.substr(2, tam);

        if (tam >= 5)
            Campo.value = vr.substr(0, 2) + '/' + vr.substr(2, 2) + '/' + vr.substr(4, tam - 4);
    }
}

function FormataTelefone(Campo, teclapres) {
    if (window.event) {
        var tecla = teclapres.keyCode;
    }
    else
        tecla = teclapres.which;

    var vr = new String(Campo.value);

    vr = vr.replace("(", "");
    vr = vr.replace(")", "");

    tam = vr.length + 1;

    if (tecla != 9 && tecla != 8) {
        if (tam > 2)
            Campo.value = '(' + vr.substr(0, 2) + ')' + vr.substr(2, tam);

    }
}




