var ar=new Array();
function bd(tx) {
	if(tx==null)return false;
	if(vermodelo(tx,'00/00/0000')==false){
		if(tx.nodeName){tx.value='';tx.focus();}
		alert('Digite a data conforme o modelo: 10/08/1988');
		return false;
	}else return true;
}

function vermodelo(o,m){
		if(o==null)return false;
		if(o.name)t=o.value;else t=o
		e=0;
		if(t=="") return true;
		if(t.length!=m.length)e=1;
		if(e==0)
		for(var i=0;i<t.length;i++){
	 		//alert(t.charCodeAt(i));
			k=t.charCodeAt(i);
			j=m.charCodeAt(i);
			if(j==47 && k!=j)e=1;
			if(j==48)
			if(k>=48 && k<=57);else e=1;

			//if(t.indexOf(String.fromCharCode(iKeyCode)) alert('as');
	 	}
		if(e==1){
			//alert('Digite a data conforme o modelo: '& m)
			return false;
		}else return true;
	
}

function mascara(o,f,e){
//	if(e!=null){if(e.keyCode==9 || e.keyCode==16)return false;}
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",5)
    return true;
}

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 $sonumeros(v){
    return v.replace(/\D/g,"")
}

function $telefone(v){
	v=sonum(v,"-")
    v=v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
    v=v.replace(/^(\d\d)(\d)/g,"($1) $2") //Coloca parênteses em volta dos dois primeiros dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")    //Coloca hífen entre o quarto e o quinto dígitos
    return v
}

function $mil(v){
	v=sonum(v,".")
    v=v.replace(/\D/g,"")                    //Remove tudo o que não é dígito
    v=preal(v).replace(",00","")
    return v
}
function $nv(v){
	var p=(v.indexOf(',')!=-1)
	v=sonum(v,".,")
	v=preal(rpl(v,".",""),1)
	if(!p)v=v.replace(",00","")
    return v
}

function $num(v){
	if(v)v=sonum(v)
    return v
}

function $rg(v){
	v=sonum(v,".-")
	v=rpl(v,"-",",")
	if(v=="")return ""
	v=rpl(preal(rpl(v,".",""),1).replace(",00",""),",","-")
    return v
}

function $cpf(v){
	v=sonum(v,".-")
    v=v.replace(/\D/g,"")                    //Remove tudo o que não é dígito
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
                                             //de novo (para o segundo bloco de números)
    v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") //Coloca um hífen entre o terceiro e o quarto dígitos
    return v
}

function $data(v){
//    v=v.replace(/D/g,"")                //Remove tudo o que não é dígito
	if(v)v=sonum(v,"/")
    v=v.replace(/^(\d{2})(\d)/,"$1/$2")       
	v=v.replace(/^(\d{2})\/(\d{2})(\d)/,"$1/$2/$3")
    return v
}

function sonum(s,am) {
	var a=s;var b='';
	perm="0123456789";
	if(am!=null)perm+=am;
	for(i=0;i<a.length;i++){
		if(perm.indexOf(a.substring(i,i+1))>=0)b=b+a.substring(i,i+1);

	}
	return b;
}

function $cep(v){
    v=v.replace(/D/g,"")                //Remove tudo o que não é dígito
    v=v.replace(/^(\d{5})(\d)/,"$1-$2") //Esse é tão fácil que não merece explicações
    return v
}

function $tel(v){
	v=sonum(v,"-")
    v=v.replace(/^(\d{4})(\d)/,"$1-$2") //Esse é tão fácil que não merece explicações
    return v
}

function $cnpj(v){
    v=v.replace(/\D/g,"")                           //Remove tudo o que não é dígito
    v=v.replace(/^(\d{2})(\d)/,"$1.$2")             //Coloca ponto entre o segundo e o terceiro dígitos
    v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3") //Coloca ponto entre o quinto e o sexto dígitos
    v=v.replace(/\.(\d{3})(\d)/,".$1/$2")           //Coloca uma barra entre o oitavo e o nono dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")              //Coloca um hífen depois do bloco de quatro dígitos
    return v
}

var ar=new Array();
function wb(end,wd,hg,cfg,nome,h_offset,volta,alias,fecha_se_sair) {
	if(typeof(end)!="string")end=end.href;
	if(h_offset==null)h_offset=0
	if(alias==null)alias="w2"

	if(nome==null){
		nome=end.substring(0,end.length<15?end.length:14)
		nome=nome.replace('.','')
		nome=nome.replace('.asp','')
		nome=nome.replace('.php','')
		nome=nome.replace('=','')
		nome=nome.replace('//','')
		nome=nome.replace('/','')
		nome=nome.replace(':','')
		nome=nome.replace('?','')
		nome=nome.replace('&','')
	}
//	if(a_ex)nome="_blank";

	if(cfg==null)cfg=',menubar=no,scrollbars=yes,resizable=yes,status=no,location=no,tollbar=no';
	var lg="";
	var tpp=Math.round((screen.height/2)-(hg/2)-40+h_offset);
	if(tpp<0)tpp=0;
	if(wd!=null && hg!=null)lg='width='+wd+',height='+hg+',top='+
		tpp+',left='+((screen.width/2)-(wd/2)-15);
	if(ar[alias]!=0 && ar[alias] && 0){
		if(fecha_se_sair==1){
			ar[alias].close();
		}else{
			wd=10;hg=4;
			ar[alias]=window.open('about:blank',nome,'width='+wd+',height='+hg+',top='+
				Math.round((screen.height/2)-(hg/2)-h_offset)+',left='+((screen.width/2)-(wd/2)-15)+
				",menubar=no,scrollbars=no,resizable=no,status=no,location=no,tollbar=no");
			ar[alias].close();
		}
	}

	ar[alias]=window.open(end,nome,lg+cfg);


	if(ar[alias]!=0)setTimeout(function(){ ar[alias].focus();}, 100);
//	if(nome.indexOf('http')==-1 && volta!=0)addEvent(ar[alias],'unload',function() {zera();this.focus();});
//	addEvent(window,'unload',function() {ar[alias].close();ar[alias]=0;});
	ar[alias].focus();
	
//	return false;
}

function addEvent(obj, evt, func) {
//var obj=$o(ob)
  if (obj.attachEvent) {
    return obj.attachEvent(("on"+evt), func);
  } else if (obj.addEventListener) {
    obj.addEventListener(evt, func, true);
    return true;
  }
  return false;
}
function removeEvent( obj, type, fn ) {
  if ( obj.detachEvent ) {
    obj.detachEvent( 'on'+type, fn );
  } else {
    obj.removeEventListener( type, fn, false ); }
} 

function $h(o,b) {
	var o=$oo(o);
	for(var i=0;i<o.length;i++){
//		alert(o[i]);
		o[i].style.display=ef(b==1,'none','block');
	}	
}

function $oo(a) {
	var a=a.split(",")
	var o=new Array();
	for(var i=0;i<a.length;i++){
		if(typeof(a[i])!="string")
			o[i]=a[i]
		else if(document.getElementById(a[i]))
			o[i]=document.getElementById(a[i])
//		o[i]=(typeof(a[i])=="string"?document.getElementById(a[i]):a[i]);
	}
	return o;
}
function $o(a) {
	return typeof(a)=="string"?document.getElementById(a):a;
}

function eef(cond,t) {
	if(cond)return t; else return "";
}
function ef(cond,t,t2) {
	if(cond)return t; else return t2;
}

function d_divh(d) {
	
}
function f_div(d) {
	var a=['sol','meio','campo','terra'];
	var atual=null;
	for(var i=0;i<a.length;i++){
		if(ar[a[i]]==1 && a[i]!=d){
			ar[a[i]]=0;
			$h('p_'+a[i],1)
		}
	}
	ar[d]= ef(ar[d]==1,0,1)
	$h('p_'+d,ef(ar[d]==1,0,1))

	var gra=1
	for(var i=0;i<a.length;i++)if(ar[a[i]]==1)gra=0
	for(var i=0;i<a.length;i++){
			if(gra==0)
				$o('i_'+a[i]).src=$o('i_'+a[i]).src.replace("pt2.png","pt.png")
			else
				$o('i_'+a[i]).src=$o('i_'+a[i]).src.replace("pt.png","pt2.png")
	}

}
