// BinaryChoice - JScripts Library // 
// Rogério Chiavegatti :: 09/2005
// Última Atualização :: 30/2007

// Hide Status Bar - [DESCONTINUADA]
function hidestatus(){
var statusmsg="Internet"
window.status=statusmsg
return true;
}

//  Janelas Pop-UP
// Uso: javascript: WindowsShow('elemento.ext','150','200','yes')
<!--
function WindowShow(elemento,wsize,hsize,scro)
{
if (navigator.appName == "Microsoft Internet Explorer")
{
wsize = parseInt(wsize) + 20;
hsize = parseInt(hsize) + 20;
}
BinaryWindow = window.open(elemento,"WinView","resizable=no,toolbar=no,status=no,menubar=no,scrollbars="+scro+",screenX=20,screenY=20,top=20,left=20,dependent=yes,width="+wsize+",height="+hsize+"")
if(false == BinaryWindow.closed) 
 {
   BinaryWindow.close ();
   BinaryWindow = window.open(elemento,"WinView","resizable=no,toolbar=no,status=no,menubar=no,scrollbars="+scro+",screenX=20,screenY=20,top=20,left=20,dependent=yes,width="+wsize+",height="+hsize+"")
 }
}
// -->
// ===================================================================================================== //
// == Limpar Campos																						==
// == uso: <input onfocus="LimpaCampo(this);"> 														 	==
// =======================================================================================================
function LimparCampo(obj){
if (obj.defaultValue==obj.value)
obj.value = ""
}
function LimparCampo2(obj){
if (obj.value !="")
obj.value = ""
}
// Restaura o valor do campo
// uso: <input onBlur="RestoreCampo(this);"> 
function RestoreCampo(obj){
if (obj.value=="")
obj.value = obj.defaultValue
}
//========================================================================================================
// Exibe oculta objetos
// action: 0=exibe | 1=oculta
//========================================================================================================
function showHide(id,action) {
 var obj = document.getElementById(id);
 
 if(action == true) {
  obj.style.display = "inline";
 } if  (action == false){
  obj.style.display = "none";
 }
}



//========================================================================================================
// Mudar a Cor dos campos de texto  																	==
//uso: <input onfocus="change(this,'#FF0000','#00FF00');"> 												==
//========================================================================================================

function frmFieldColor(Obj,fgColor,bgColor){

//var Obj = document.getElementById(id);
var CorTexto = fgColor
var CorFundo = bgColor

Obj.style.color = CorTexto;
Obj.style.backgroundColor = CorFundo;
}

//========================================================================================================
// Mudar a Classe dos inputs		  																	==
//uso: <input onfocus="change(this,1);"> 																==
//========================================================================================================
function InputCor(Obj,changer){
//changer: 1= Focus 2=Blur
if (changer == 1){
var CssClass = 'inputFocus'
}
if (changer==2){
var CssClass = 'inputBlur'
	}
Obj.className = CssClass;
}

function TxtAreaCor(Obj,changer){
//changer: 1= Focus 2=Blur
if (changer == 1){
var CssClass = 'TextAreaFocus'
}
if (changer==2){
var CssClass = 'TextAreaBlur'
	}
Obj.className = CssClass;
}
//========================================================================================================
// Mudar a Classe das TD´s  		  																	==
//uso: onmouseover="tdCorClass(this,'tdOver');" onmouseout="tdCorClass(this,'tdNormal');"			    ==
//========================================================================================================

function tdCorClass(Obj,nomeClass){
var CssClass = nomeClass;
Obj.className = CssClass;
}

//uso: onmouseover="tdBgStyle(this,'#F8FDC6');" onmouseout="tdBgStyle(this,'#D1E809');"

function tdBgStyle(Obj,Cor){
var CssStyle = Cor;
Obj.style.backgroundColor = CssStyle;
}



//========================================================================================================
// Formatação de campos para moeda  																	==
//uso: <input type="Text" name="fat_vr_bruto" maxlength="17" onKeyDown="FormataValor(this,17,event)"> 	==
//========================================================================================================
function FormataValor(campo,tammax,teclapres) 
 {
	var tecla = teclapres.keyCode;
	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 ) ;}
	}			
}
//============================================================================
// Formata campo de CEP Ex: 13420-669 [ Cross: IE / FireFox (31/05/2006)]   ==
// [Uso] onKeyPress="formataCEP('CEP', window.event.keyCode, this);"  	    ==
//============================================================================
function formataCEP (formato,e,objeto)
{

campo = eval(objeto);

var key = window.event ? e.keyCode : e.which;
//var keychar = String.fromCharCode(key);
//alert(campo)

if((key >=48 && key <=57) || key==0 || key==45 || key==8)
key.returnValue = true;
	else 
//e.returnValue = false;
if (e.preventDefault) {
      e.preventDefault();
    } else {
      e.returnValue = false;
    }
if (formato=='CEP')
	{
	caracteres = '01234567890';
	separacoes = 1;
	separacao1 = '-';
	conjuntos = 2;
	conjunto1 = 5;
	conjunto2 = 3;
	if ((caracteres.search(String.fromCharCode (key))!=-1) && campo.value.length < 
	(conjunto1 + conjunto2 + 1))
		{
		if (campo.value.length == conjunto1) 
		   campo.value = campo.value + separacao1;
		}
	else 
		key.returnValue = false;
	}
}

//============================================================================
//Formata CPF [ Cross: IE / FireFox (31/05/2006)] 						    ==
// [Uso] onKeyPress="formataCEP('CEP', window.event.keyCode, this);"  	    ==
//============================================================================
function FormataCPF(Campo, e){

var tecla = window.event ? e.keyCode : e.which;
	//alert(tecla)
if((tecla >=48 && tecla <=57) || tecla==45 || tecla==8 || tecla==120)
tecla.returnValue = true;
	else 
//e.returnValue = false;
if (e.preventDefault) {
      e.preventDefault();
    } else {
      e.returnValue = false;
    }	
	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 < 7)
			Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, tam);
		if (tam >= 7 && tam <10)
			Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,tam-6);
		if (tam >= 10 && tam < 12)
			Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + '-' + vr.substr(9,tam-9);
		}
}

//============================================================================
//Formata CNPJ [ Cross: IE / FireFox (31/05/2006)]						    ==
// [Uso] onKeyPress="FormataCNPJ(this,event);"                      	    ==
//============================================================================
 
function FormataCNPJ(Campo,e){

    var tecla = window.event ? e.keyCode : e.which;
	//alert(key)
if((tecla >=48 && tecla <=57) || tecla==45 || tecla==8)
tecla.returnValue = true;
	else 
//e.returnValue = false;
if (e.preventDefault) {
      e.preventDefault();
    } else {
      e.returnValue = false;
    }
	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);
		}
}


//============================================================================
// Formata campos: Somente Inteiros [ Cross: IE / FireFox (31/05/2006)]     ==
// [Uso] onKeyPress="return soNumeros(event);"				  	   		    ==
//============================================================================
function soNumeros(evt) {
	
		var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;

}

function trim(valorTrim){
	var len = valorTrim.length;
	for(var x=0; x<len; x++) if(valorTrim.charCodeAt(x)!=32 && valorTrim.charCodeAt(x)!=10 && valorTrim.charCodeAt(x)!=13) break;
	valorTrim = valorTrim.substring(x,len);
	len = valorTrim.length;
	for(x=len-1; x>1; x--) if(valorTrim.charCodeAt(x)!=32 && valorTrim.charCodeAt(x)!=10 && valorTrim.charCodeAt(x)!=13) break;
	valorTrim = valorTrim.substring(0,x+1);
	return valorTrim;
}

function getFocus(formulario, campo){
	eval("document." + formulario + "." + campo + ".focus()")
}

// Formata campo vazio, verifica o preenchimento do Form


function camposVazios(formulario){
	//se retornar false quer dizer que o formulário não possui nenhum campo em branco
	var i, temp;
	var args = camposVazios.arguments;
	var nomeCampo = false;
	
	for(i=1; i<args.length; i++){
		if(eval("trim(document." + formulario + "." + args[i] + ".value)")=="" ){
			nomeCampo = args[i];
			break;
		}
	}
	return nomeCampo;
}

//coloque os caracteres que deseja bloquear no argumento da função
//ex: blockChar('0123456789') -- Bloqueia os numeros
//se quiser bloquear pelo codigo ASC coloque outros parametros na frente do primeiro;
//ex: blockChar('', 13, 85, 94)

function blockChar(args){
	
	for(var i=0; i<args.length;  i++){
		if (window.event.keyCode == args.charCodeAt(i)){
			event.returnValue = false;
			break;
		}
	}//end for

	if(blockChar.arguments.length > 1){
		for(var i=1; i<blockChar.arguments.length; i++){
			if (!isNaN(blockChar.arguments[i]) && window.event.keyCode == blockChar.arguments[i]){
				event.returnValue = false;
				break;
			}
		}//end for
	}// end if
}//eend function



// Esconder Camadas

function showHideLayers() { //v2.0
  var i, visStr, args, theObj;
  args = showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) { //with arg triples (objNS,objIE,visStr)
    visStr   = args[i+2];
    if (navigator.appName == 'Netscape' && document.layers != null) {
      theObj = eval(args[i]);
      if (theObj) theObj.visibility = visStr;
    } else if (document.all != null) { //IE
      if (visStr == 'show') visStr = 'visible'; //convert vals
      if (visStr == 'hide') visStr = 'hidden';
      theObj = eval(args[i+1]);
      if (theObj) theObj.style.visibility = visStr;
  } }
}


function repeatString(str, count){
	var novaStr="";
	for(var i=0; i<count; i++) novaStr = novaStr + str;
	return novaStr
}


// Formatar Campos:: Validar Emails

function validarMail(email) 
{
	 if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))
 	   {
			return true;
       }
	 else
	   { 
	      return false;
	   }
}

// Comprar Datas


function comparaData(data1, data2){
	//------------------------------
	// Uso: comparaData("10/01/2002", "10/03/2002");
	// data1 e data2 no formato "dd/mm/aaaa"
	// se retornar 1 "data1" é maior
	// se retornar 2 "data2" é maior
	// se retornar 0 "data1" é igual a "data2"
	//------------------------------
	var dataDiff = transformaData(data2) - transformaData(data1);
	var maiorData;

	if(dataDiff > 0){dataSaida = 2;}
	else if(dataDiff < 0){dataSaida = 1;}
	else {dataSaida == 0;}

	return dataSaida;
}


// Trasnformar o Formato das Datas


function transformaData(data){// data no formato dd/mm/aaaa
	var data = trim(data);
	argDia = parseInt(data.substring(0,2), 10);
	argMes = parseInt(data.substring(3,5), 10) - 1;
	argAno = parseInt(data.substring(6,10),10);
	data = new Date(argAno, argMes, argDia);
	return data;
}

function isDate(data){
	var data = trim(data);
	if(data != ""){
		dia = parseInt(data.substring(0,2), 10);
		mes = parseInt(data.substring(3,5), 10);
		ano = parseInt(data.substring(6,10),10);
		//Verifica se o tamanho da string é 10 
		if(data.length < 10 || (mes < 1 || mes > 12) || (dia > 31 || dia < 1)) 
			return false;
		var quantDias;
		if(mes==4 || mes==6 || mes==9 || mes==11)//mes com 30 dias
			quantDias = 30;
		else if(mes==1 || mes==3 || mes==5 || mes==7 || mes==8 || mes==10 || mes==12)//mes com 31	
			quantDias = 31;
		else if(mes==2){ //mes com 28
			if((ano % 4 == 0) && (ano % 100 != 0 || ano % 400 ==0)) quantDias = 29; //verifica se é bissexto
			else quantDias = 28;
		}
		if(dia > quantDias || dia < 1) return false;
	}
	return true;
}


// Formata campos de moeda (segunda function)


function FormataValor(campo,tammax,teclapres) 
 {
 	//uso:
	//<input type="Text" name="fat_vr_bruto" maxlength="17" onKeyDown="FormataValor(this,17,event)">

	var tecla = teclapres.keyCode;
	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 ) ;}
	}			
}


// Formata Data : Segunda Function


function FormataData(nomecampo,teclapres) {
//	onKeydown="FormataData('nome_campo',event);"
	var tecla = teclapres.keyCode;
	vr = nomecampo.value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			nomecampo.value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			nomecampo.value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 3 ); }
}

function FormataData2(nomecampo,teclapres) {
//	onKeydown="FormataData('nome_campo',event);"
	var tecla = teclapres.keyCode;
	vr = document.form2[nomecampo].value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			document.form2[nomecampo].value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			document.form2[nomecampo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); }
}

// Formata a Adição aos Favoritos


function addBookmark(url, titulo)
{
	//Parâmetros: 
	//url: Endereço a ser adicionado
	//titulo: Título que aparecerá nos Favoritos
	if (document.all)
		window.external.AddFavorite(url, titulo)
}

// Validação do CEP

function validarCep(cep)
{
	txCep = trim(cep);
	if(txCep.length == 0)
		return false;

	txCep = txCep.replace("-","");
	txCep = txCep.replace(".","");
	if(txCep.length != 8 || isNaN(txCep))
		return false;
	else
		return true;
}

// Exibição de Camadas e Divs - Controle de exposição

//  usado para exibir e omitir as subcategorias

//------------------------------------------------------------------------------------------------------------------------
// Menu em camadas
//------------------------------------------------------------------------------------------------------------------------

function SwitchMenu(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementById("masterdiv").getElementsByTagName("span"); 
		if(el.style.display != "block"){ 
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="submenu") 
				ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}
//------------------------------ Switchmenu2
function SwitchMenu2(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementById("masterdiv2").getElementsByTagName("span"); //DynamicDrive.com change
		if(el.style.display != "block"){ //DynamicDrive.com change
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="submenu2") //DynamicDrive.com change
				ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}

// --------------------------------------------------------- Formata Dolar
// Uso: onKeyPress="return(currencyDolar(this,',','.',event))"
function currencyDolar(fld, milSep, decSep, e) {
  var sep = 0;
  var key = '';
  var i = j = 0;
  var len = len2 = 0;
  var strCheck = '0123456789';
  var aux = aux2 = '';
  var whichCode = (window.Event) ? e.which : e.keyCode;

  if (whichCode == 13) return true;  // Enter
  if (whichCode == 8) return true;  // Delete
  key = String.fromCharCode(whichCode);  // Get key value from key code
  if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
  len = fld.value.length;
  for(i = 0; i < len; i++)
  if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
  aux = '';
  for(; i < len; i++)
  if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
  aux += key;
  len = aux.length;
  if (len == 0) fld.value = '';
  if (len == 1) fld.value = '0'+ decSep + '0' + aux;
  if (len == 2) fld.value = '0'+ decSep + aux;
  if (len > 2) {
    aux2 = '';
    for (j = 0, i = len - 3; i >= 0; i--) {
      if (j == 3) {
        aux2 += milSep;
        j = 0;
      }
      aux2 += aux.charAt(i);
      j++;
    }
    fld.value = '';
    len2 = aux2.length;
    for (i = len2 - 1; i >= 0; i--)
    fld.value += aux2.charAt(i);
    fld.value += decSep + aux.substr(len - 2, len);
  }
  return false;
}
// ----------------------------------------------------------------------------- Enable / Disable fields
// Uso: 
function enableDisable(oChk){
		var disable = !oChk.checked;
		var arglen = arguments.length;
		var obj, startIndex = 1;
		var frm = oChk.form;
		for (var i=startIndex;i<arglen;i++){
			obj = frm.elements[arguments[i]];
			if (typeof obj=="object"){
				if (document.layers) {
					if (disable){
						obj.onfocus=new Function("this.blur()");
						if (obj.type=="text") obj.onchange=new Function("this.value=this.defaultValue");
					}
					else {
						obj.onfocus=new Function("return");
						if (obj.type=="text") obj.onchange=new Function("return");
					}
				}
				else obj.disabled=disable;
			}
		}
	}
	
// ---------------------------------------------------------------------------------- Contador de caracteres
function CheckFieldLength(fn,wn,rn,mc) {
  var len = fn.value.length;
  if (len > mc) {
    fn.value = fn.value.substring(0,mc);
    len = mc;
  }
  document.getElementById(wn).innerHTML = len;
  document.getElementById(rn).innerHTML = mc - len;
}

/////////////////////////////////////////////////////////////////////////////////////////////////// Masks RegExpress
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 reNumeros(v){
    return v.replace(/\D/g,"")
}

function retelefone(v){
    v=v.replace(/\D/g,"")                 //Remove tudo o que nao e digito
    v=v.replace(/^(\d\d)(\d)/g,"($1) $2") //Coloca parenteses em volta dos dois primeiros digitos
    v=v.replace(/(\d{4})(\d)/,"$1.$2")    //Coloca hifen entre o quarto e o quinto digitos
    return v
}

function recpf(v){
    v=v.replace(/\D/g,"")                    //Remove tudo o que nao e digito
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto digitos
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto digitos
                                             //de novo (para o segundo bloco de numeros)
    v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") //Coloca um hifen entre o terceiro e o quarto digitos
    return v
}

function recep(v){
    v=v.replace(/D/g,"")                //Remove tudo o que nao e digito
    v=v.replace(/^(\d{5})(\d)/,"$1-$2") //Esse e tao facil que nao merece explicacoes
    return v
}

function recnpj(v){
    v=v.replace(/\D/g,"")                           //Remove tudo o que nao e digito
    v=v.replace(/^(\d{2})(\d)/,"$1.$2")             //Coloca ponto entre o segundo e o terceiro digitos
    v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3") //Coloca ponto entre o quinto e o sexto digitos
    v=v.replace(/\.(\d{3})(\d)/,".$1/$2")           //Coloca uma barra entre o oitavo e o nono digitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")              //Coloca um hifen depois do bloco de quatro digitos
    return v
}

function reromanos(v){
    v=v.toUpperCase()             
    v=v.replace(/[^IVXLCDM]/g,"") 
    while(v.replace(/^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/,"")!="")
        v=v.replace(/.$/,"")
    return v
}

function resite(v){
    v=v.replace(/^http:\/\/?/,"")
    dominio=v
    caminho=""
    if(v.indexOf("/")>-1)
        dominio=v.split("/")[0]
        caminho=v.replace(/[^\/]*/,"")
    dominio=dominio.replace(/[^\w\.\+-:@]/g,"")
    caminho=caminho.replace(/[^\w\d\+-@:\?&=%\(\)\.]/g,"")
    caminho=caminho.replace(/([\?&])=/,"$1")
    if(caminho!="")dominio=dominio.replace(/\.+$/,"")
    v="http://"+dominio+caminho
    return v
}

/////////////////////////////////////////////////////////////////////////////////////////////////// AJAX - XMLHTTPRequests.
function createXMLHTTP() 
	{
		var ajax;
		try 
		{
			ajax = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(e) 
		{
			try 
			{
				ajax = new ActiveXObject("Msxml2.XMLHTTP");
				alert(ajax);
			}
			catch(ex) 
			{
				try 
				{
					ajax = new XMLHttpRequest();
				}
				catch(exc) 
				{
					 alert("Este navegador nao suporta recursos de Ajax.");
					 ajax = null;
				}
			}
			return ajax;
		}
	
	
		   var arrSignatures = ["MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0",
							    "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP",
							    "Microsoft.XMLHTTP"];
		   for (var i=0; i < arrSignatures.length; i++) 
		   {
				try 
				{
					var oRequest = new ActiveXObject(arrSignatures[i]);
					return oRequest;
				} 
				catch (oError) 
				{
			    }
		   }
		
			   throw new Error("MSXML nao esta instalado neste sistema.");
	}
	
	
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
