d=document

// +++++++++++++ COMEÇA BASICS +++++++++++++ //

function isDef(S){return(eval('typeof('+S+')')!='undefined'&&eval('typeof('+S+')')!='unknown')}

function getElm(id){return (is.ie4)?d.all[id]:d.getElementById(id)}

function toId(S){
	var S=S.toLowerCase()
	S=S.replace(/[áàãâä]/g,'a')
	S=S.replace(/[éèêë&]/g,'e')
	S=S.replace(/[íìîï]/g,'i')
	S=S.replace(/[óòõôö]/g,'o')
	S=S.replace(/[úùûü]/g,'u')
	S=S.replace(/[ç]/g,'c')
	for(var i=0;i<S.length;i++){if(' _0123456789abcdefghijklmnopqrstuvwxyz'.indexOf(S.charAt(i))==-1)S=S.replace(S.charAt(i),' ')}
	S=S.replace(/[ ]/g,'')
	S=S.replace(/[.]/g,'')
	return S
}

function openPopup(url,n,w,h,other,c){
	l=18;t=18
	if(c){l=(screen.availWidth-w)/2;t=(screen.availHeight-h)/2}
	url=url.replace(/[ ]/g,'%20')
	popup=window.open(url,'pop_'+n,'left='+l+',top='+t+',width='+w+',height='+h+',scrollbars=1'+((other)?','+other:''))
	other=other||''
	if(is.ie&&other.indexOf('fullscreen')!=-1){popup.moveTo(0,0);popup.resizeTo(screen.width,screen.height)}
	popup.focus()
}

function installSearchEngine() {
 if (window.external && ("AddSearchProvider" in window.external)) {
   // Firefox 2 and IE 7, OpenSearch
   window.external.AddSearchProvider("http://example.com/search-plugin.xml");
 } else if (window.sidebar && ("addSearchEngine" in window.sidebar)) {
   // Firefox <= 1.5, Sherlock
   window.sidebar.addSearchEngine("http://example.com/search-plugin.src",
                                  "http://example.com/search-icon.png",
                                  "Search Plugin", "");
 } else {
   // No search engine support (IE 6, Opera, etc).
   alert("No search engine support");
 }
}

function openBlank(url){window.open(url)}

function checkBrowser(){
	T=this
	b=navigator.appName
	v=navigator.appVersion
	u=navigator.userAgent
	if(b=='Netscape')T.b='ns'
	else if(b=='Microsoft Internet Explorer')T.b='ie'
	else T.b=b
	T.v=parseInt(v)
	T.ns=(T.b=='ns'&&T.v>=4)
	T.ns4=(T.b=='ns'&&T.v==4)
	T.ns5=(T.b=='ns'&&T.v==5)
	T.ns6=(T.b=='ns'&&T.v==5)
	T.ie=(T.b=='ie'&&T.v>=4)
	T.ie4=(u.indexOf('MSIE 4')>0)
	T.ie5=(u.indexOf('MSIE 5.0')>0)
	T.ie55=(u.indexOf('MSIE 5.5')>0)
	T.ie6=(u.indexOf('MSIE 6.0')>0)
	if(T.ie5)T.v=5
	if(T.ie55)T.v=5.5
	if(T.ie6)T.v=6
	T.min=(T.ns||T.ie)
	T.dom=(T.v>=5)
	T.win=(u.indexOf('Win')>0)
	T.mac=(u.indexOf('Mac')>0)
}
is=new checkBrowser()


// Page Dimensions

function docW(){return(is.ie?(d.body.scrollWidth):(d.width))}
function docH(){return(is.ie?(d.body.scrollHeight):(d.height))}
function winW(){return(is.ie?(d.body.clientWidth):(window.innerWidth))}
function winH(){return(is.ie?(d.body.clientHeight):(window.innerHeight))}

// Images

function pI(src){
	obj=src.substring(src.lastIndexOf('/')+1,src.lastIndexOf('.'))
	eval('i'+obj+'=new Image()')
	eval('i'+obj+'.src="'+src+'"')
}

function cI(id,obj,lyr){
	id=(is.ns4&&lyr)?'d.layers.'+lyr+'.document.images.'+id:'d.images[\''+id+'\']'
	if(isDef(id)&&isDef('i'+obj))eval(id).src=eval('i'+obj).src
}


// Layers

function newLyr(id,l,t,w,h,ct,z,v,bg,n,makeDL){
	if(is.ns4){
		if(n)var lyr=eval('d.layers.'+n+'.document.layers.'+id+'=new Layer('+w+',d.layers.'+n+')')
		else var lyr=d.layers[id]=new Layer(w)
		lyr.name=id
		lyr.left=l
		lyr.top=t
		if(h)lyr.clip.height=h
		if(ct){lyr.document.open();lyr.document.write(ct);lyr.document.close()}
		if(z)lyr.zIndex=z
		lyr.visibility=(v=='hidden')?'hide':'show'
		if(bg)lyr.bgColor=bg
	}
	else{
		if(n){
			index=n.lastIndexOf(".")
			var nestlyr=(index!=-1)?n.substr(index+1):n
		}
		if(is.dom){
			lyr=d.createElement('DIV')
			lyrS=lyr.style
			lyrS.position='absolute'
			lyrS.left=l+'px'
			lyrS.top=t+'px'
			if(w)lyrS.width=w+'px'
			if(h)lyrS.height=h+'px'
			else if(is.ie&&is.mac)lyrS.height='none'
			if(z)lyrS.zIndex=z
			if(v)lyrS.visibility=v
			if(bg)lyrS.backgroundColor=bg
			if(ct)lyr.innerHTML=ct+((is.ie&&is.mac)?'<span></span>':'')
			lyr.id=id
			if(n)d.getElementById(nestlyr).appendChild(lyr)
			else d.body.appendChild(lyr)
		}
		else{
			var S='\n<DIV id='+id+' style="position:absolute;left:'+l+';top:'+t
			if(w)S+=';width:'+w
			else S+=';width:1'
			if(h!=null)S+=';height:'+h
			if(z!=null)S+=';z-index:'+z
			if(v)S+=';visibility:'+v
			if(bg!=null)S+=';background:'+bg
			S+='">'+((ct)?ct:'')+'</DIV>'
			if(n)d.all[nestlyr].insertAdjacentHTML("BeforeEnd",S)
			else d.body.insertAdjacentHTML("BeforeEnd",S)
		}
	}
	if(makeDL){eval(((id.lastIndexOf('Div'))?id.substring(0,id.lastIndexOf('Div')):id)+'DL=new DL(\''+id+'\''+((n)?',\''+n+'\'':'')+')')}
}


// Reloads the window if Nav4 resized

function BUG_ns4_reloadOnResize(){
	if(!d.pgW){d.pgW=innerWidth;d.pgH=innerHeight;onresize=BUG_ns4_reloadOnResize}
	else if(innerWidth!=d.pgW||innerHeight!=d.pgH)location.reload()
}
if(d.layers)BUG_ns4_reloadOnResize()


// Objects Constructor

var DOA=new Array()
function DO(parent){this.arguments=DO.caller.arguments;this.newDO=newDO;this.parent=parent;this.itens=new Array()}
function newDO(){return (this.itens)?this.itens[this.itens.length]=new DO(this):DOA[DOA.length]=new DO()}


// DynLayer
// Copyright 1999 Dan Steinman
// http://www.dansteinman.com/dynapi/

function DL(id,n1,n2){
	var T=this
	if(is.ns4){
		if(n1){
			if(n2)T.elm=d.layers[n2].document.layers[n1].document.layers[id]
			else T.elm=d.layers[n1].document.layers[id]
		}
		else T.elm=d.layers[id]
		T.css=T.elm
		T.doc=T.elm.document
		T.l=T.css.left
		T.t=T.css.top
		T.w=T.css.clip.width
		T.h=T.css.clip.height
	}
	else{
		T.elm=T.event=(is.ie4)?d.all[id]:d.getElementById(id)
		T.css=T.elm.style
		T.doc=document
		T.l=T.elm.offsetLeft
		T.t=T.elm.offsetTop
		T.w=T.elm.offsetWidth
		T.h=T.elm.offsetHeight
		if(!T.w)T.w=T.css.pixelWidth
		if(!T.h)T.h=T.css.pixelHeight
	}
	T.obj=((id.lastIndexOf('Div'))?id.substring(0,id.lastIndexOf('Div')):id)+'DL'
	T.sh=DLsh
	T.hd=DLhd
	T.mTo=DLmTo
	T.mBy=DLmBy
	T.rTo=DLrTo
	T.rBy=DLrBy
	T.write=DLwrite
}

function DLsh(){this.css.visibility=(is.ns4)?'show':'visible'}
function DLhd(){this.css.visibility=(is.ns4)?'hide':'hidden'}

function DLmTo(l,t){
	if(l!=null){
		this.l=l
		if(!is.ie)this.css.left=this.l
		else this.css.pixelLeft=this.l
	}
	if(t!=null){
		this.t=t
		if(!is.ie)this.css.top=this.t
		else this.css.pixelTop=this.t
	}
}
function DLmBy(l,t){this.mTo(this.l+l,this.t+t)}

function DLrTo(w,h){
	if(w!=null){
		this.w=w
		if(is.ns4)this.css.clip.width=this.w
		else this.css.width=this.w
	}
	if(h!=null){
		this.h=h
		if(is.ns4)this.css.clip.height=this.h
		else this.css.height=this.h
	}
}
function DLrBy(w,h){this.rTo(this.w+w,this.h+h)}

function DLwrite(S){
	if(is.ns4){this.doc.close();this.doc.open();this.doc.write(S);this.doc.close()}
	else this.elm.innerHTML=S
}
//</script>





//ROLLOVER DOS BOTÕES DA HOME

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  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];}}
}

function MM_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


// +++++++++++++ TERMINA BASICS +++++++++++++ //





// +++++++++++++ COMEÇA FUNCTIONS +++++++++++++ //

function abre() { 
	//var foto = window.open("","janela","width=370,height=360,resizable=no,toolbar=0,location=0,directories=0,status=no,menubar=0"); document.dados.submit();
	window.open("http://www.catho.com.br/dt/?origem=home","janela","width=790,height=536,resizable=yes,scrollbars=1,toolbar=0,location=0,directories=0,status=no,menubar=0");
}

function abre_mapa_site() { 
	//var foto = window.open("","janela","width=370,height=360,resizable=no,toolbar=0,location=0,directories=0,status=no,menubar=0"); document.dados.submit();
	window.open("http://www.catho.com.br/dt/?origem=mapa+site","janela","width=790,height=536,resizable=yes,scrollbars=1,toolbar=0,location=0,directories=0,status=no,menubar=0");
}

function indique() {
	window.open("indique.phtml","janela","width=320,height=312,resizable=no,toolbar=0,location=0,directories=0,status=no,menubar=0"); 
}



//Função Pausa Objeto
//Impede multiplos clicks no botão do form de logon
var objeto;
var apertou = false;

function pausa_objeto(botao, tempo)
{
	objeto = botao;

	if(!apertou) {
		apertou = true;
		setTimeout("apertou = false;", tempo);
		return true;
	}
	return false;
}

// misc functions
function help(URL)
{ 
	window.open(URL, '_blank', 'width=750,height=495,scrollbars=yes,top=10,left=10');
}

function fac(URL)
{ 
	window.open(URL, '_blank', 'width=450,height=350,scrollbars=1,top=50,left=180');
}


function CentralAjuda()
{
	openPopup('http://www3.catho.com.br/help/','CentralAjuda',750,500,'scrollbars=yes,status=0',true)
//	window.open('http://www3.catho.com.br/help/', 'CentralAjuda','width=750,height=495,scrollbars=yes,top=10,left=10');
}


function ExAssinante()
{
	openPopup('http://www.catho.com.br/pop_exassinantes.php','ExAssinantes',340,270,'scrollbars=no,status=0',true)
}

function CvCarreira(url)
{
	openPopup(url,'CvCarreira',600,400,'scrollbars=yes,status=0',true)
}


function PassoCV_BR()		{
			window.open('http://www3.catho.com.br/passoapasso/inclusao_cv_port.html', 'Window', 'width=640,height=470,scrollbars=no,top=0,left=0');
		}


function PassoVAGA_BR()		{
			window.open('http://www3.catho.com.br/passoapasso/inclusao_vaga_port.html', 'Window', 'width=640,height=470,scrollbars=no,top=0,left=0');
		}

function PassoCV_CL()		{
			window.open('http://www3.catho.cl/passoapasso/inclusao_cv_esp.html', 'Window', 'width=640,height=470,scrollbars=no,top=0,left=0');
		}

function PassoVAGA_CL()		{
			window.open('http://www3.catho.cl/passoapasso/inclusao_vaga_esp.html', 'Window', 'width=640,height=470,scrollbars=no,top=0,left=0');
		}



// +++++++++++++ TERMINA FUNCTIONS +++++++++++++ //


// +++++++++++++ COMEÇA FORMS +++++++++++++ //

	

function checkForm(f,onlyObligatory,submitonce){
	clearClass(f)
	for(var i=0;i<f.length;i++){
		v=true
		if(f[i].type=='text'||f[i].type=='textarea'||f[i].type=='password')v=f[i].value
		else if(f[i].type=='select-one')v=f[i][f[i].selectedIndex].value
		else if(f[i].type=='radio'){v=false;for(var j=0;j<f[f[i].name].length;j++){if(f[f[i].name][j].checked)v=f[f[i].name][j].value}}
		else if(f[i].type=='hidden'){v=true;for(var j=0;j<f.length;j++){if(f[i].name==f[j].getAttribute('target')){if(!f[j].value)v=false}}}
		if(!v){
			obligatory=(d.layers)?null:f[i].getAttribute('obligatory')
			if(f[i].type!='hidden'&&(((!onlyObligatory&&obligatory!='no')||(onlyObligatory&&obligatory=='yes'))||d.layers)){checkFormAlert(f[i]);return false}
		}
		else{
			if(f[i].type=='text'||f[i].type=='textarea'||f[i].type=='password'){
				if(!checkMinLength(f[i]))return false
				if(!checkFormPlus(f[i]))return false
			}
			else if(f[i].type=='hidden'&&!d.layers){
				for(var j=0;j<f.length;j++){if(f[i].name==f[j].getAttribute('target')){f[i].value='';break}}
				for(var j=0;j<f.length;j++){if(f[i].name==f[j].getAttribute('target'))f[i].value+=f[j].value+((f[j].getAttribute('separator'))?f[j].getAttribute('separator'):'')}
				for(var j=0;j<f.length;j++){if(f[i].name==f[j].getAttribute('target')){if(!checkFormPlus(f[i]))return false}}
			}
		}
	}
	if(submitonce)submitonce(f)
	return true
}

function scrollTopPosition(){return (is.ie)?d.body.scrollTop:pageYOffset}
function checkFormAlert(f,plus){
	var scrTop=scrollTopPosition()
	if(f.type=='select-one'||f.type=='radio')S='Você deve escolher '
	else if(plus)S='Valor inválido do campo '
	else S='Você deve preencher o campo '
	label=(d.layers)?f.name:f.getAttribute('label')
	label=(label)?label:f.name
	S+=label
	if(plus=='password')S=label+' e sua confirmação não possuem os mesmos valores'
	if(plus=='minlength')S='O campo '+label+' deve ter no mínimo '+f.getAttribute('minlength')+' caracteres'
	if(f.type!='hidden'){
		if(!d.layers){
			if(plus=='password'){for(var i=0;i<f.form.length;i++){if(f.form[i].getAttribute('xtype')=='password')f.form[i].className='alert'}}
			else if(f.type=="radio"){for(var i=0;i<f.form[f.name].length;i++){f.form[f.name][i].className='alert'}}
			else f.className='alert'
		}
		f.focus()
	}
	else if(!d.layers){
		for(var i=0;i<f.form.length;i++){if(f.form[i].getAttribute('target')==f.name)f.form[i].className='alert'}
		for(var i=0;i<f.form.length;i++){if(f.form[i].getAttribute('target')==f.name){f.form[i].focus();break}}
	}
	if(scrTop!=scrollTopPosition())scrollBy(null,scrTop>scrollTopPosition()?-20:80)
	alert(S)
}

function checkMinLength(f){
	minLength=(d.layers)?null:f.getAttribute('minlength')
	if(minLength){if(f.value.length<minLength){checkFormAlert(f,'minlength');return false}}
	return true
}

function checkFormPlus(f){
	xtype=(d.layers)?null:f.getAttribute('xtype')
	if(xtype){
		S='check'+xtype.charAt(0).toUpperCase()+xtype.substring(1).toLowerCase()
		if(isDef(S)){if(!eval(S)((xtype=='password')?f:f.value)){checkFormAlert(f,xtype);return false}}
	}
	return true
}


// Plus Checks
function checkNumber(v){if(!isNaN(v))return true}
function checkDate(v){
	if(v.length!=10)return false
	var date=v.split('/')
	var d=parseInt(date[0],10)
	var m=parseInt(date[1],10)
	var y=parseInt(date[2],10)
	if(!checkDateDay(d))return false
	else if(!checkDateMonth(m))return false
	else if(!checkDateYear(y))return false
	else if( (m==4||m==6||m==9||m==11) && (d==31)) return false
	else if(m==2 && (d>29 || (d==29&&((y%4)!=0)))) return false
	return true
}

function checkDateDay(v){if(v>=1&&v<=31)return true}
function checkDateMonth(v){if(v>=1&&v<=12)return true}
function checkDateYear(v){if(v>=1)return true}

function checkBirthday(v){
	if(!checkDate(v))return false
	var date=v.split('/')
	var d=date[0]
	var m=date[1]
	var y=date[2]
	date=parseInt(date[2]+date[1]+date[0],10)
	if(date<19000101||date>((isDef('date'))?date:20020101))return false
	return true
}

function checkEmail(v){
	var a=0
	var p=0
	for(var i=1;i<v.length;i++){
		if(!v.charAt(i))return false
		else if(v.charAt(i)=='@'){a++;if(v.charAt(i+1)=='')return false}
		else if(v.charAt(i)=='.'){p++;if(v.charAt(i+1)==''||v.charAt(i+1)=='@'||v.charAt(i-1)=='@')return false}
	}
	if(a==1&&p)return true
}

function checkCpf(v){
	var s=null
	var r=null
	if(v.length!=11||
		v=='00000000000'||v=='11111111111'||v=='22222222222'||v=='33333333333'||v=='44444444444'||
		v=='55555555555'||v=='66666666666'||v=='77777777777'||v=='88888888888'||v=='99999999999')return false
	s=0
	for(var i=0;i<9;i++)s+=parseInt(v.charAt(i))*(10-i)
	r=11-(s%11)
	if(r==10||r==11)r=0
	if(r!=parseInt(v.charAt(9)))return false
	s=0
	for(var i=0;i<10;i++)s+=parseInt(v.charAt(i))*(11-i)
	r=11-(s%11)
	if(r==10||r==11)r=0
	if(r!=parseInt(v.charAt(10)))return false
	return true
}

function checkPassword(f){
	for(var i=0;i<f.form.length;i++){
		if(f.form[i].getAttribute('xtype')=='password'&&f.form[i]!=f){
			if(f.form[i].value&&f.value!=f.form[i].value)return false
		}
	}
	return true
}

function checkName(v){
	reg1=/[^ A-Záàãâäéèêëíìîïóòõôöúùûüç.´]/i
	reg2=/[ ]{2}/
	if(v.substr(0,1)==' ')return false
	else if((v.search(reg1)!=-1)||(v.search(reg2)!=-1))return false
	else if(v.substr(v.lastIndexOf(' '))==' ')return false
	else return true
}

function checkFullname(v){
	if(!checkName(v))return false
	if(v.indexOf(' ')==-1)return false
	else return true
}

function checkCep(v){
	if(v.length!=9)return false
	reg=/[^0-9-]/
	if(v.search(reg)!=-1)return false
	var codp=v.split('-')
	var cod1=parseInt(codp[0],10)
	var cod2=parseInt(codp[1],10)
	return true
}

// Tools
function selectRadio(radio,i){eval(radio)[parseInt(i)].checked='true'}
function textareaMaxLength(f,length,e){
	if(is.ns){if(e.which==0||e.which==8)return true}
	if(f.value.length>=length)return false
}

function textareaCheckLength(f,len){
	if(f.value.length>len){
		label=(d.layers)?f.name:f.getAttribute('label')
		label=(label)?label:f.name
		alert('O campo '+label+' deve ter no mámixo '+len+' caracteres.')
		f.value=f.value.substr(0,len);
	}
}



function textareaCounter(f,counter){eval('f.form.'+counter).value=f.value.length}

function changeField(f){
	if(f.value.length==f.maxLength){
  	for(var i=0;i<f.form.length;i++){
    	if(f.form[i]==f&&f.form[i+1]){f.form[i+1].focus();break}
		}
	}
}



function onlyThisChars(numbers,letters,others,e){
	if(window.event)key=window.event.keyCode
	else if(e)key=e.which
	else return true
	S=(others)?others:''

	if(numbers)S+='0123456789'
	if(letters)S+='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
	if(key==null||key==0||key==8||key==9||key==13||key==27)return true
	else if(S.indexOf(String.fromCharCode(key))!=-1)return true
	else return false
}

function notOnlyThisChars(S,e){
	if(window.event)key=window.event.keyCode
	else if(e)key=e.which
	else return true

	if(!S)return false
	else if(key==null||key==0||key==8||key==9||key==13||key==27)return true
	else if(S.indexOf(String.fromCharCode(key))!=-1)return false
	else return true
}

function submitonce(f){
	if(!d.layers){
		for(var i=0;i<f.length;i++){
			if(f[i].type=='submit'||f[i].type=='reset'||f[i].type=='image')f[i].disabled=true
		}
	}
}


function changeClassFocus(a,c){
	alert(a)
	clearClass(c.form)
	if(!d.layers){
		if(c.type=="radio"){for(var i=0;i<c.form[c.name].length;i++){c.form[c.name][i].className='alert'}}
		else c.className='alert'
	}
	c.focus()
	return false;
}


function clearClass(f){
	for(var i=0;i<f.length;i++){
		if(!d.layers){
			if(!f[i].classNameOld)f[i].classNameOld=f[i].className||'-null'
			else f[i].className=f[i].classNameOld
		}
	}
}



// Retorna o indice ou o valor de um campo

var retValue=false

function valSel(c,retValue){

	if(retValue) return c[c.selectedIndex].value

	else return c.selectedIndex

}


// +++++++++++++ TERMINA FORMS +++++++++++++ //

