navie=(navigator.userAgent.indexOf("MSIE")==-1?false:true);
// Função de replace all
function repstr (str, str1, str2) {
	while (true) {
		if (str.indexOf(str1)==-1) break;
		str=str.replace(str1,str2);
	}
	return str;
}

// Valida objeto data
function valida_data(obj) {
	if (ValidaData(obj.value)) {
		alert("Data inválida!");
		obj.focus();
		return false;
	} else {
		return true;
	}
}

function ValidaData(data) {
	if (data.length!=10) return 1;
	numeros="";
	dia=data.substring(0,2);
	mes=data.substring(3,5);
	ano=data.substring(6,10);
	data=ano+mes+dia;
	if ((ano < 1900) || (ano > 2020) || (mes==0) || (mes>12) || (dia==0) || (dia>31)) return 2;
	if (((mes==4) || (mes==6) || (mes==9) || (mes==11)) && (dia==31)) return 3;
	if (((ano % 4)==0) && ((ano % 100)!=0) || ((ano % 400)==0)) div=0; else div=1;
	if ((div==0) && (mes==2) && (dia>29)) return 4;
	if ((div==1) && (mes==2) && (dia>28)) return 5;
//	if (parseInt(data) > parseInt(datahoje)) return 6;
}

function validata_data_ini_fim(data_ini,data_fim) {
	l_data_ini=data_ini.substring(6,10)+data_ini.substring(3,5)+data_ini.substring(0,2);
	l_data_fim=data_fim.substring(6,10)+data_fim.substring(3,5)+data_fim.substring(0,2);
	if (l_data_ini > l_data_fim) return 1;
}

// verifica se existem caracateres invalidos
function CaracteresInvalidos(CharsInvalidos,objeto,msg){
	// Retorna se o string str conter algum caracter invalido
	// por caracteres contidos no string CharsInvalidos.
	for (fc_i=0;fc_i < CharsInvalidos.length;fc_i++) {
		if (objeto.value.indexOf(CharsInvalidos.charAt(fc_i))!=-1) {
			alert(msg);
			return 1;
		}
	}
}

// Função para validar login
function fv_login(src) {
	if (src.value.indexOf(' ')!=-1) {
		return "Campos não pode conter espaços";
	}
	if (src.value.length < 5) {
		return "Tamanho mínimo de 5 caracteres";
	}
	car_valid="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
	for (ii=0;ii<src.value.length;ii++) {
		if (car_valid.indexOf(src.value.charAt(ii))==-1) return "Caracter "+src.value.charAt(ii)+" não é válido para login";
		}
	return "";
}

// Função para procurar na dropdown a string digitada
var objeto;
function dropdown(fld, e, st) {
	var key = '';
	var strCheck = 'abcdefghijklmnopqrtsuvwxyz0123456789 ';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 9 || whichCode == 38 || whichCode == 40) return true;
	if (whichCode == 8 && acha_drop=="") return false;
	if (typeof acha_drop!="string") acha_drop="";

	if (typeof tf_1!="undefined") window.clearTimeout(tf_1);

	if (st && st==1 && fld.onchange) {
		objeto=fld;
		tf_1=window.setTimeout("acha_drop='';objeto.onchange();window.clearTimeout(tf_1);",2000);
	} else {
		tf_1=window.setTimeout("acha_drop='';window.clearTimeout(tf_1);",2000);
	}

	if (whichCode == 8) {
		acha_drop=acha_drop.substring(0,acha_drop.length-1);
	} else {
		key = String.fromCharCode(whichCode);  // Get key value from key code
		acha_drop+=key;
		if (strCheck.indexOf(key.toLowerCase()) == -1) return false;  // Not a valid key
	}
	flag=false;
	for (i=0;i<fld.length;i++) {
		if (fld.options[i].text.substring(0,acha_drop.length).toLowerCase()==acha_drop.toLowerCase()) {
			fld.options[i].selected=true;
			flag=true;
			break;
		}
	}
	if (flag==false && acha_drop!="") acha_drop=acha_drop.substring(0,acha_drop.length-1);
	return false;
}

// arredonda campos para 2 posições
function f_round2pos(src) {
	res=(Math.round(src*100))/100;
	return res;
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_dragLayer(objName,x,hL,hT,hW,hH,toFront,dropBack,cU,cD,cL,cR,targL,targT,tol,dropJS,et,dragJS) { //v4.01
  //Copyright 1998 Macromedia, Inc. All rights reserved.
  var i,j,aLayer,retVal,curDrag=null,curLeft,curTop,IE=document.all,NS4=document.layers;
  var NS6=(!IE&&document.getElementById), NS=(NS4||NS6); if (!IE && !NS) return false;
  retVal = true; if(IE && event) event.returnValue = true;
  if (MM_dragLayer.arguments.length > 1) {
    curDrag = MM_findObj(objName); if (!curDrag) return false;
    if (!document.allLayers) { document.allLayers = new Array();
      with (document) if (NS4) { for (i=0; i<layers.length; i++) allLayers[i]=layers[i];
        for (i=0; i<allLayers.length; i++) if (allLayers[i].document && allLayers[i].document.layers)
          with (allLayers[i].document) for (j=0; j<layers.length; j++) allLayers[allLayers.length]=layers[j];
      } else {
        if (NS6) { var spns = getElementsByTagName("span"); var all = getElementsByTagName("div"); 
          for (i=0;i<spns.length;i++) if (spns[i].style&&spns[i].style.position) allLayers[allLayers.length]=spns[i];}
        for (i=0;i<all.length;i++) if (all[i].style&&all[i].style.position) allLayers[allLayers.length]=all[i]; 
    } }
    curDrag.MM_dragOk=true; curDrag.MM_targL=targL; curDrag.MM_targT=targT;
    curDrag.MM_tol=Math.pow(tol,2); curDrag.MM_hLeft=hL; curDrag.MM_hTop=hT;
    curDrag.MM_hWidth=hW; curDrag.MM_hHeight=hH; curDrag.MM_toFront=toFront;
    curDrag.MM_dropBack=dropBack; curDrag.MM_dropJS=dropJS;
    curDrag.MM_everyTime=et; curDrag.MM_dragJS=dragJS;
    curDrag.MM_oldZ = (NS4)?curDrag.zIndex:curDrag.style.zIndex;
    curLeft= (NS4)?curDrag.left:(NS6)?parseInt(curDrag.style.left):curDrag.style.pixelLeft; 
    if (String(curLeft)=="NaN") curLeft=0; curDrag.MM_startL = curLeft;
    curTop = (NS4)?curDrag.top:(NS6)?parseInt(curDrag.style.top):curDrag.style.pixelTop; 
    if (String(curTop)=="NaN") curTop=0; curDrag.MM_startT = curTop;
    curDrag.MM_bL=(cL<0)?null:curLeft-cL; curDrag.MM_bT=(cU<0)?null:curTop-cU;
    curDrag.MM_bR=(cR<0)?null:curLeft+cR; curDrag.MM_bB=(cD<0)?null:curTop+cD;
    curDrag.MM_LEFTRIGHT=0; curDrag.MM_UPDOWN=0; curDrag.MM_SNAPPED=false; //use in your JS!
    document.onmousedown = MM_dragLayer; document.onmouseup = MM_dragLayer;
    if (NS) document.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);
  } else {
    var theEvent = ((NS)?objName.type:event.type);
    if (theEvent == 'mousedown') {
      var mouseX = (NS)?objName.pageX : event.clientX + document.body.scrollLeft;
      var mouseY = (NS)?objName.pageY : event.clientY + document.body.scrollTop;
      var maxDragZ=null; document.MM_maxZ = 0;
      for (i=0; i<document.allLayers.length; i++) { aLayer = document.allLayers[i];
        var aLayerZ = (NS4)?aLayer.zIndex:parseInt(aLayer.style.zIndex);
        if (aLayerZ > document.MM_maxZ) document.MM_maxZ = aLayerZ;
        var isVisible = (((NS4)?aLayer.visibility:aLayer.style.visibility).indexOf('hid') == -1);
        if (aLayer.MM_dragOk != null && isVisible) with (aLayer) {
          var parentL=0; var parentT=0;
          if (NS6) { parentLayer = aLayer.parentNode;
            while (parentLayer != null && parentLayer.style.position) {             
              parentL += parseInt(parentLayer.offsetLeft); parentT += parseInt(parentLayer.offsetTop);
              parentLayer = parentLayer.parentNode;
          } } else if (IE) { parentLayer = aLayer.parentElement;       
            while (parentLayer != null && parentLayer.style.position) {
              parentL += parentLayer.offsetLeft; parentT += parentLayer.offsetTop;
              parentLayer = parentLayer.parentElement; } }
          var tmpX=mouseX-(((NS4)?pageX:((NS6)?parseInt(style.left):style.pixelLeft)+parentL)+MM_hLeft);
          var tmpY=mouseY-(((NS4)?pageY:((NS6)?parseInt(style.top):style.pixelTop) +parentT)+MM_hTop);
          if (String(tmpX)=="NaN") tmpX=0; if (String(tmpY)=="NaN") tmpY=0;
          var tmpW = MM_hWidth;  if (tmpW <= 0) tmpW += ((NS4)?clip.width :offsetWidth);
          var tmpH = MM_hHeight; if (tmpH <= 0) tmpH += ((NS4)?clip.height:offsetHeight);
          if ((0 <= tmpX && tmpX < tmpW && 0 <= tmpY && tmpY < tmpH) && (maxDragZ == null
              || maxDragZ <= aLayerZ)) { curDrag = aLayer; maxDragZ = aLayerZ; } } }
      if (curDrag) {
        document.onmousemove = MM_dragLayer; if (NS4) document.captureEvents(Event.MOUSEMOVE);
        curLeft = (NS4)?curDrag.left:(NS6)?parseInt(curDrag.style.left):curDrag.style.pixelLeft;
        curTop = (NS4)?curDrag.top:(NS6)?parseInt(curDrag.style.top):curDrag.style.pixelTop;
        if (String(curLeft)=="NaN") curLeft=0; if (String(curTop)=="NaN") curTop=0;
        MM_oldX = mouseX - curLeft; MM_oldY = mouseY - curTop;
        document.MM_curDrag = curDrag;  curDrag.MM_SNAPPED=false;
        if(curDrag.MM_toFront) {
          eval('curDrag.'+((NS4)?'':'style.')+'zIndex=document.MM_maxZ+1');
          if (!curDrag.MM_dropBack) document.MM_maxZ++; }
        retVal = false; if(!NS4&&!NS6) event.returnValue = false;
    } } else if (theEvent == 'mousemove') {
      if (document.MM_curDrag) with (document.MM_curDrag) {
        var mouseX = (NS)?objName.pageX : event.clientX + document.body.scrollLeft;
        var mouseY = (NS)?objName.pageY : event.clientY + document.body.scrollTop;
        newLeft = mouseX-MM_oldX; newTop  = mouseY-MM_oldY;
        if (MM_bL!=null) newLeft = Math.max(newLeft,MM_bL);
        if (MM_bR!=null) newLeft = Math.min(newLeft,MM_bR);
        if (MM_bT!=null) newTop  = Math.max(newTop ,MM_bT);
        if (MM_bB!=null) newTop  = Math.min(newTop ,MM_bB);
        MM_LEFTRIGHT = newLeft-MM_startL; MM_UPDOWN = newTop-MM_startT;
        if (NS4) {left = newLeft; top = newTop;}
        else if (NS6){style.left = newLeft; style.top = newTop;}
        else {style.pixelLeft = newLeft; style.pixelTop = newTop;}
        if (MM_dragJS) eval(MM_dragJS);
        retVal = false; if(!NS) event.returnValue = false;
    } } else if (theEvent == 'mouseup') {
      document.onmousemove = null;
      if (NS) document.releaseEvents(Event.MOUSEMOVE);
      if (NS) document.captureEvents(Event.MOUSEDOWN); //for mac NS
      if (document.MM_curDrag) with (document.MM_curDrag) {
        if (typeof MM_targL =='number' && typeof MM_targT == 'number' &&
            (Math.pow(MM_targL-((NS4)?left:(NS6)?parseInt(style.left):style.pixelLeft),2)+
             Math.pow(MM_targT-((NS4)?top:(NS6)?parseInt(style.top):style.pixelTop),2))<=MM_tol) {
          if (NS4) {left = MM_targL; top = MM_targT;}
          else if (NS6) {style.left = MM_targL; style.top = MM_targT;}
          else {style.pixelLeft = MM_targL; style.pixelTop = MM_targT;}
          MM_SNAPPED = true; MM_LEFTRIGHT = MM_startL-MM_targL; MM_UPDOWN = MM_startT-MM_targT; }
        if (MM_everyTime || MM_SNAPPED) eval(MM_dropJS);
        if(MM_dropBack) {if (NS4) zIndex = MM_oldZ; else style.zIndex = MM_oldZ;}
        retVal = false; if(!NS) event.returnValue = false; }
      document.MM_curDrag = null;
    }
    if (NS) document.routeEvent(objName);
  } return retVal;
}

// Função para ler os parâmetros de url
function get_par() {
parametros=false;
pos=document.URL.indexOf("?");
if (pos!=-1) {
	cont=0;
	function par(nome,valor) {
		this.nome=nome;
		this.valor=valor;
		}
	a_param=new Array();
	while (true) {
		parametros=true;
		pos2=document.URL.indexOf("=",pos);
		if (pos2==-1) pos2=document.URL.length;
		nome=document.URL.substring(pos+1,pos2);
		pos3=document.URL.indexOf("&",pos2);
		if (pos3==-1) pos3=document.URL.length;
		valor=document.URL.substring(pos2+1,pos3);
		a_param[cont]=new par(nome,valor);
		pos=document.URL.indexOf("&",pos2);
		if (pos==-1) break;
		cont++;
		}
	}
}
/* Come ler?
// chamar a função
get_par();
// se parametros=false não tem parâmetros
// se parametros=true existem parâmetros
// se existir parâmetros é gerado um array chamedo a_param com os parâmetros encontrados
// ler o resultado
if (parametros==true) {
	for (i=0;i<a_param.length;i++){
		alert("Parâmetro:("+a_param[i].nome+") tem o valor de:("+a_param[i].valor+")");
// o a_param[ind].nome tras o nome da variável
// o a_param[ind].valor tras o valor da variável
		}
	}
*/

// Cálculo de Datas
function calc_data (data,dias,tipo) {
if (typeof tipo=="undefined" || tipo=="") tipo="+";
if (typeof dias=="undefined" || dias=="") dias=0;
if (typeof data=="undefined" || data=="") {dt=new Date(); data=dt.getDate()+"/"+(dt.getMonth()+1)+"/"+dt.getYear();}
sp=data.split('/');
if (tipo=='+')
	calc=new Date(parseFloat(sp[2]),parseFloat(sp[1])-1,parseFloat(sp[0])+parseFloat(dias));
else
	calc=new Date(parseFloat(sp[2]),parseFloat(sp[1])-1,parseFloat(sp[0])-parseFloat(dias));
dd=calc.getDate();
if (dd<10) dd="0"+dd;
mm=calc.getMonth()+1;
if (mm<10) mm="0"+mm;
yy=calc.getYear();
volta=dd+'/'+mm+'/'+yy;
return volta;
}

// Preload
function MM_preloadImages() 
	{
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	}
// VerySign
function certisign(url) 
	{
	sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=500,height=450');
	self.name = "mainWin"; 
	}

// Rollover dos menus
function eOvr(e,src,clrOver) {
 if (window.event) e = window.event; 
 var srcEl = e.srcElement? e.srcElement : e.target; 
 srcEl.style.cursor = 'pointer';
 srcEl.bgColor = clrOver;
}
function eOut(e, src,clrIn) {
 if (window.event) e = window.event; 
 var srcEl = e.srcElement? e.srcElement : e.target; 
 srcEl.style.cursor = 'default';
 srcEl.bgColor = clrIn;
}
function mOvr(src,clrOver) {
 if (!src.contains(event.fromElement)) {
  src.style.cursor = 'hand';
  src.bgColor = clrOver;
 }
}
function mOut(src,clrIn) {
 if (!src.contains(event.toElement)) {
  src.style.cursor = 'default';
  src.bgColor = clrIn;
 }
}
function mClk(src) {
if(event.srcElement.tagName=='TD'){
src.children.tags('a')[0].click();
}
}


// Compra Página Conceitual Produtos Service
function f_como_adquirir()
	{
	if (document.formcompra.selectcompra.value==0)
		{
		alert('Escolha o tipo de usuário');
		}
	if (document.formcompra.selectcompra.value==1)
		{
		window.open('/login.htm', 'Login', 'width=231, height=290, status=yes');
		}
	if (document.formcompra.selectcompra.value==2)
		{
		document.location.href='/requisicao.cfm?assinante=PF'
		}
	if (document.formcompra.selectcompra.value==3)
		{
		document.location.href='/requisicao.cfm?assinante=PJ'
		}
	}
	
// Aviso de Produto já existente
function f_aviso()
	{
		alert('Você já possui este produto. Para renovação consulte a seção MINHA CONTA.');
	}
	
// Rollover form but

function change(color){
var el=event.srcElement
if ((el.tagName=="INPUT"&&el.type=="button") || (el.tagName=="INPUT"&&el.type=="submit") || (el.tagName=="INPUT"&&el.type=="reset") || (el.tagName=="INPUT"&&el.type=="file"))
event.srcElement.style.backgroundColor=color
}

// Chama tela de contato

function chama_contato() {
tipo=typeof(contato);
if (tipo=="undefined")
	document.location.href="/helpdesk/contato.cfm";
else
	document.location.href="/helpdesk/contato.cfm?produto="+contato;
}

// Só aceita minúsculas

function sominusculas(fld, e) {
var sep = 0;
var key = '';
var i = j = 0;
var len = len2 = 0;
var strCheck = 'abcdefghijklmnopqrstuvwxyz';
var aux = aux2 = '';
var whichCode = (window.Event) ? e.which : e.keyCode;
if (whichCode == 13) return true;  // Enter
key = String.fromCharCode(whichCode);  // Get key value from key code
if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
if ((key==',') && fld.value.indexOf(key) != -1) return false;
return true;
}

// Só aceita números

function sonumeros(fld, 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
key = String.fromCharCode(whichCode);  // Get key value from key code
if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
if ((key==',') && fld.value.indexOf(key) != -1) return false;
return true;
}

// Só aceita números

function sovalor(fld, 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
key = String.fromCharCode(whichCode);  // Get key value from key code
if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
if ((key==',') && fld.value.indexOf(key) != -1) return false;
return true;
}

var triOver = "/imagens_ds/minha_conta_seta.gif"; // triangle images
var triUp = "/imagens_ds/minha_conta_seta.gif";
var triDown = "/imagens_ds/minha_conta_seta.gif";
var antId="";

function t(groupId, itemId){
	detail = document.all(groupId + "_d" + itemId);
	button = document.all(groupId + "_b" + itemId);
	
	isExpanded =  ((detail.style.display == "") || (detail.style.display == "none"));
	setExpanded(detail, button, isExpanded);

	if (groupId!="minhaconta") {
		if ((antId!="") && (antId!=groupId)) {
			detail = document.all(antId + "_d" + itemId);
			button = document.all(antId + "_b" + itemId);
			isExpanded =  ((detail.style.display == "") || (detail.style.display == "none"));
			if (isExpanded==false) setExpanded(detail, button, isExpanded);
			}
		antId=groupId;
		}
	return false;
}

function setExpanded(detail, button, isExpanded)
{
	if (isExpanded) {
		detail.style.display = "block";
//		button.src = triDown;
	} else {
		detail.style.display = "none";
//		button.src = triUp;
	}
}

// Expand/contract all the boxes in the group
function toggleAll(groupId)
{
	var row;
	var i = 0;
	var expand;
	
	if( document.all(groupId + "_e").AllExpand == null )
		expand = true;
	else
		expand = ! document.all(groupId + "_e").AllExpand;
	
	while(true)
	{
		detail = document.all(groupId + "_d" + i);
		button = document.all(groupId + "_b" + i);
		
		if (detail == null) {
			break;
		}
		
		setExpanded(detail, button, expand);
		i++;
	}
	
	document.all(groupId + "_e").innerText = (expand == true ? "Contract all" : "Expand all");
	document.all(groupId + "_e").AllExpand = expand;
}

// OverHeaderBar
function v(groupId, itemId, cssClass)
{
	
	document.all(groupId + "_h" + itemId).className = cssClass;
//	document.all(groupId + "_b" + itemId).src = triOver;
}	

// outHeaderBar
function u(groupId, itemId, cssClass)
{
	var img;
		
	//<%-- if the associated item is displayed, show the down error, otherwise the up arrow --%>
	if (document.all(groupId + "_d" + itemId).style.display == "block")
		img = triDown;
	else 
		img = triUp;
	
	document.all(groupId + "_h" + itemId).className = cssClass;
//	document.all(groupId + "_b" + itemId).src = img;
}

function sodatas(fld, 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
key = String.fromCharCode(whichCode);  // Get key value from key code
if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
if ((key==',') && fld.value.indexOf(key) != -1) return false;
return true;
}

function montadata(data) {
/*	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
	key = String.fromCharCode(whichCode);  // Get key value from key code
	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
	if ((key==',') && fld.value.indexOf(key) != -1) return false;
	return true;*/
	var strCheck = '0123456789';
	numeros = "";
	for(i=0;i<data.value.length && numeros.length<8;i++){
		if(strCheck.indexOf(data.value.charAt(i))!=-1) numeros+=data.value.charAt(i);
	}
	nova_data = "";
	for(i=0;i<numeros.length;i++){
		if((i==2) || (i==4)){
			nova_data+="/"+numeros.charAt(i);
		} else {
			nova_data+=numeros.charAt(i);
		}
	}
	data.value = nova_data;
}

function monta_data(data) {
	numeros = "";
	for(i=0;i<data.value.length;i++){
		if(data.value.charAt(i)!="/") numeros+=data.value.charAt(i);
	}
	nova_data = "";
	for(i=0;i<numeros.length;i++){
		if((i==2) || (i==4)){
			nova_data+="/"+numeros.charAt(i);
		} else {
			nova_data+=numeros.charAt(i);
		}
	}
	data.value = nova_data;
}

function monta_cep(cep) {
numeros = "";
  for(i=0;i<cep.value.length;i++){
    if(cep.value.charAt(i)!="-") numeros+=cep.value.charAt(i);
  }
novo_cep = "";
  for(i=0;i<numeros.length;i++){
   if(i==5){
	 novo_cep+="-"+numeros.charAt(i);}
   else{
	 novo_cep+=numeros.charAt(i);}
   }
cep.value = novo_cep;
}

function emailCheck (emailStr) {
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address. 
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a 
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	return 1;
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    return 2;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
		return 3;
	    }
    }
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
    return 4;
}
/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */
/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   return 5;
}
// Make sure there's a host name preceding the domain.
if (len<2) {
   return 6;
}
// If we've gotten this far, everything's valid!
}

function ValidaCPF (cpf) {
	if (cpf.length!=0) {
	cpf = sonumero (cpf);
    if (cpf.length != 11)
		return 1;
    for (i = 10; i <= 11; i++) {
		d = 0
		for (j = i; j >= 2; j--)
	    	d += parseInt (cpf.charAt (i-j)) * j
			d = (d %= 11) < 2 ? 0 : 11 - d
			if (parseInt (cpf.charAt (i-1)) != d)
	    	return 2;
	    }
	}
}

function sonumero (s) {
    saida = new String()
	numeros="0123456789";
    for (i = 0; i < s.length; i++) {
		if (numeros.indexOf(s.charAt(i))!=-1) saida+=s.charAt(i);
    }
    return saida;
}
//window opem
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function achaTop(ob, ind){
	var obj = document.getElementById(ob);
	if (ind>=0){
		var pos = obj[ind].offsetTop;
		try {
			pos += obj[ind].offsetParent.offsetTop;
			pos += obj[ind].offsetParent.offsetParent.offsetTop;
			pos += obj[ind].offsetParent.offsetParent.offsetParent.offsetTop;
			pos += obj[ind].offsetParent.offsetParent.offsetParent.offsetParent.offsetTop;
			pos += obj[ind].offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetTop;
			pos += obj[ind].offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetTop;
			pos += obj[ind].offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetTop;
			pos += obj[ind].offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetTop;
			pos += obj[ind].offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetTop;
			pos += obj[ind].offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetTop;
			pos += obj[ind].offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetTop;
		}
		catch (APPLICATION){
			return pos;
		};
	}
	else{
		var pos = obj.offsetTop;
		try{
			pos += obj.offsetParent.offsetTop;
			pos += obj.offsetParent.offsetParent.offsetTop;
			pos += obj.offsetParent.offsetParent.offsetParent.offsetTop;
			pos += obj.offsetParent.offsetParent.offsetParent.offsetParent.offsetTop;
			pos += obj.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetTop;
			pos += obj.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetTop;
			pos += obj.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetTop;
			pos += obj.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetTop;
			pos += obj.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetTop;
			pos += obj.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetTop;
			pos += obj.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetTop;
		}
		catch (APPLICATION){
			return pos;
		};
	}
}

function achaLeft(ob, ind){
	var obj = document.getElementById(ob);
	if (ind>=0){
		var pos = obj[ind].offsetLeft;
		try {	
			pos += obj[ind].offsetParent.offsetLeft;
			pos += obj[ind].offsetParent.offsetParent.offsetLeft;
			pos += obj[ind].offsetParent.offsetParent.offsetParent.offsetLeft;
			pos += obj[ind].offsetParent.offsetParent.offsetParent.offsetParent.offsetLeft;
			pos += obj[ind].offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetLeft;
			pos += obj[ind].offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetLeft;
			pos += obj[ind].offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetLeft;
			pos += obj[ind].offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetLeft;
			pos += obj[ind].offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetLeft;
			pos += obj[ind].offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetLeft;
			pos += obj[ind].offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetLeft;
		}
		catch (APPLICATION){
			return pos;
		};
	}
	else{
		var pos = obj.offsetLeft;
		try {
			pos += obj.offsetParent.offsetLeft;
			pos += obj.offsetParent.offsetParent.offsetLeft;
			pos += obj.offsetParent.offsetParent.offsetParent.offsetLeft;
			pos += obj.offsetParent.offsetParent.offsetParent.offsetParent.offsetLeft;
			pos += obj.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetLeft;
			pos += obj.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetLeft;
			pos += obj.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetLeft;
			pos += obj.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetLeft;
			pos += obj.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetLeft;
			pos += obj.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetLeft;
			pos += obj.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetLeft;
		}
		catch (APPLICATION){
			return pos;
		};
	}
}

