var theURL="0.html";
function trocar(obj){
	theURL = obj.options[obj.selectedIndex].value;
	self.location.href=theURL;
}

function TAU_openBrWindow(theURL,winName,features,largura,altura,f) { //v2.0
  if(f==1){
    l=0;t=0;largura=(screen.availWidth-10);altura=(screen.availHeight-26);
  }else{
    var l = ((screen.availWidth)/2) - (largura/2);
    var t = ((screen.availHeight)/2) - ((altura/2)+20);
  }
  features = features + ",width=" + largura + ",height=" + altura + ",left=" + l + ",top=" + t;
  window.open(theURL,winName,features);
}

ns4 = (document.layers)? true:false;
ie4 = (document.all)? true:false;
dom = (ns4|ie4)? false:true;
var string = "";
function verifica_campos()
{
  var ok = true;
  string = "";
  if (ie4)
  with (document.forms[0])
   {
         if (nome.value == "") { string += 'Nome\n' ;ok = false; };
         if (email.value == "" ){ string += 'E-mail\n'; ok = false; };
         if (mensagem.value == "") { string += 'Mensagem\n'; ok = false;};
         if (!ok)
              alert("Os campo(s):\n\n" + string + "\ndeve(m) ser preenchido(s)");
         else
             return true;
   }
  if (ns4)
  with (document.mascara.document.txt.document.forms[0])
   {
       if (nome.value == "") { string += 'Nome\n'; ok = false; };
         if (email.value == "" ){ string += 'E-mail\n'; ok = false; };
         if (mensagem.value == "") { string += 'Mensagem\n'; ok = false;};
         if (!ok)
              alert("Os campo(s):\n\n" + string + "\ndeve(m) ser preenchido(s)");
         else
             return true;
   }
}

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_findObj(n, d) { //v3.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); 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];}
}

ns6=(navigator.userAgent.indexOf("Gecko")!=-1)?true:false

function getRefToDiv(divID) {
	if( document.layers ) { return document.layers[divID+'C'].document.layers[divID]; }
	if( document.getElementById ) { return document.getElementById(divID); }
	if( document.all ) { return document.all[divID]; }
	if( document[divID+'C'] ) { return document[divID+'C'].document[divID]; }
	return false;
}

function rSDiv(oName,newWidth,newHeight) {
	var myReference = getRefToDiv(oName), noPx = document.childNodes ? 'px' : 0;
	if( myReference.style ) { myReference = myReference.style; }
	if( myReference.resizeTo ) { myReference.resizeTo( newWidth, newHeight ); }
	myReference.width = newWidth + noPx; myReference.pixelWidth = newWidth;
	myReference.height = newHeight + noPx; myReference.pixelHeight = newHeight;
}

function moveRodape()
{
var caixa = document.getElementById("conteudo");
var min = document.body.clientHeight - 165 - 51;

//var noPx = document.childNodes ? 'px' : 0;

if(ns6){
	var caixa = getRefToDiv("conteudo"), noPx = document.childNodes ? 'px' : 0;
	if(min>caixa.offsetHeight){
		rSDiv('conteudo',535,min-4)
	}
}else{
	if (min>caixa.style.pixelHeight) {
    	caixa.style.pixelHeight = min;
	}
}
document.getElementById("corpo").style.display = "block";
}

//+------------------------------------------------------------------+
//+ Seu Talento - funcoes do site Seu Talento
//+ 
//+ Versao: 1.0 
//+
//+ ChangeLog:
//+ <autor> : <descricao da mudanca> <data>
//+------------------------------------------------------------------+

/*
 * Recebe o nome do objeto form da pagina, e o modo de login
 * (admin|analista|candidato), e envia o form, se login e senha forem validos. 
 */
function envialogin(form,mode,event)
{
    var username = new Object();
    var password = new Object();
    switch(mode) {
        case 'analista':
        case 'admin':
//            username.field = "login";
//            password.field = "senha";
            username.restriction = "RehRange2:12";
            password.restriction = "RehRange2:12";
        break;
        case 'candidato':
//            username.field = "cpf";
//            password.field = "senha";
            username.restriction = "RehCPF";
            password.restriction = "RehRange6:12";
        break;
        default:
    }
    var msg = Tau_validateForm(form['username'],'login',username.restriction,form['password'],'senha',password.restriction);
    //alert(msg);
    if (msg === true) {
        form.submit();
    } else {
        alert(msg);
    }
}

/*
 * Alterna o valor de 'display' de 'divnum' no DOM da CSS entre 'none' e
 * 'block'.
 *
 * <a href="javascript:showhide(1)">Foo</a>bar
 *
 */
function showhide(div,num)
{
    var curr = document.getElementById(div+num).style.display;
    var i=1;
    //swap de modos de display da layer e de seu link
    if (curr!="block") {
        curr = "block";
    } else {
        curr = "none";
    }
/*
    while (document.getElementById(div+i) != null && document.getElementById(div+i) != null) {
        //alert(document.getElementById(div+i));
        //SHCallback.trace(div,i);
        //alert(document.getElementById(div+i).style.display);
        if (i===num) {
            //alert('!');
            SHCallback.on(div,i);
            document.getElementById(div+i).style.display = curr;
        } else {
            SHCallback.off(div,i);
            document.getElementById(div+i).style.display = 'none';
        }
        //alert(document.getElementById(div+i).style.display);
        i++;
    }
*/
    SHCallback.on(div,num);
    document.getElementById(div+num).style.display = curr;
}

/*
 * Mostra uma mensagem como alerta, se msg existir.
 */
function mensagem(msg)
{
    if (msg !== true && msg.length > 0) {
        alert(msg);
    }
}

/*
 * Posiciona conteudo
 */
function init(){
brsr = navigator.userAgent;
  if(brsr.indexOf('Opera')!= -1){
    var largura = (document.body.clientWidth)/2;
    var altura = (document.body.clientHeight);
    //document.images['ajuste'].height = altura - 376;
    document.all['conteudo'].style.pixelLeft=largura-82;
    document.all['conteudo'].style.height = altura-130;
    document.all['conteudo'].style.visibility = "visible";
  }
  if(brsr.indexOf('MSIE')!= -1 && brsr.indexOf('Opera')== -1){
    var largura = (document.body.clientWidth)/2;
    var altura = (document.body.clientHeight);
    document.all['conteudo'].style.pixelLeft=largura-82;
    document.all['conteudo'].style.height = altura-130;
    document.all['conteudo'].style.visibility = "visible";
  }
}



/*
 * Posiciona conteudo de algumas paginas em candidatos
 */
function init_candidatos(){
brsr = navigator.userAgent;
  if(brsr.indexOf('Opera')!= -1){
    var largura = (document.body.clientWidth)/2;
    var altura = (document.body.clientHeight);
    //document.images['ajuste'].height = altura - 376;
    document.all['conteudo'].style.pixelLeft=largura-82;
    document.all['conteudo'].style.height = altura-85;
    document.all['conteudo'].style.visibility = "visible";
  }
  if(brsr.indexOf('MSIE')!= -1 && brsr.indexOf('Opera')== -1){
    var largura = (document.body.clientWidth)/2;
    var altura = (document.body.clientHeight);
    document.all['conteudo'].style.pixelLeft=largura-82;
    document.all['conteudo'].style.height = altura-85;
    document.all['conteudo'].style.visibility = "visible";
  }
}


/*--------------------------
 *
 * Tau Validate Form .js
 *
 *--------------------------
 */

function Tau_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=Tau_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) {
  	test=args[i+2];
    //alert(typeof args[i].value);
    var val = args[i];
	if (val) {
        if(val.length && !val.options) {
            //alert('Radio!');
            var radio = "";
            for(var rL=0;rL<val.length;rL++) {
                if (val[rL].checked) {
                    radio = val[rL];
                }
            }
            val = radio;
        }
		//nm=val.name;
		nm=args[i+1];
        //alert(nm+": "+val.value);
        val = val.value;
        if (val == null) {
            val = "";
        }
		if (val.length == 0 && test.charAt(0) == 'R') {
			errors += '- '+nm+' é de preenchimento obrigatório\n';
        }
        if (val.length > 0) {
            if (test.indexOf('ehNum')!=-1) {
                p = val.match(/^[0-9]+$/);
                if (p == null) {
    			    errors+='- '+nm+' deve ser um composto por números.\n';
                }
            }
			if (test.indexOf('isEmail')!=-1) {
				p=val.indexOf('@');
				if (p<1 || p==(val.length-1))
					errors+='- '+nm+' deve conter um endereço de email.\n';
			}
			else if (test.indexOf('ehData')!=-1) {
				p=
val.match(/(0[1-9]|[12][0-9]|3[01])\/(0[1-9]|1[12])\/[12][0-9]{3}/);
				if (p == null)
					errors+='- '+nm+' deve conter uma data.\n';
			}
			else if (test.indexOf('ehEmail')!=-1) {
				p=emailCheck(val);
				if (typeof p == "string")
					errors+='- erro em '+nm+'. '+p+'\n';
			}
			else if (test.indexOf('ehCPF')!=-1) {
				p=cpfCheck(val);
				if (p==false)
					errors+='- '+nm+' deve conter um número de CPF válido.\n';
			}
			else if (test.indexOf('ehCNPJ')!=-1) {
				p=cnpjCheck(val);
				if (p==0)
					errors+='- '+nm+' deve conter um número de CNPJ válido.\n';
			}
                    
			    else if (test.indexOf('ehRange') != -1) {
				    //p=test.indexOf(':');
				    min=parseInt(test.replace(/.*ehRange(\d*):\d*/,"$1"));
				    max=parseInt(test.replace(/.*ehRange\d*:(\d*)/,"$1"));
                    //max=parseInt(test.substring(p+1));
                    //alert(min+' '+max);
			        if (typeof val === "string") {
					    if (val.length<min || max<val.length) {
						    errors+='- '+nm+' deve conter entre '+min+' e '+max+' caracteres.\n';
                        }
                   } else {
				        errors+='- '+nm+' deve ser um valor alfanumérico.\n';
                   } 
				}
                else if (test.indexOf('inRange') != -1) {
					num = parseFloat(val);
			        if (isNaN(val)) {
					    errors+='- '+nm+' deve conter um número.\n';
                    }
                    //p=test.indexOf(':');
					//min=test.substring(7,p); max=test.substring(p+1);
				    min=parseInt(test.replace(/.*inRange(\d*):\d*/,"$1"));
				    max=parseInt(test.replace(/.*inRange\d*:(\d*)/,"$1"));
                    //alert(min+' '+max);
					if (num<min || max<num)
						errors+='- '+nm+' deve conter um número entre '+min+' e '+max+'.\n';
				}
		}
    }
/*
else if (test.charAt(0) == 'R')
			errors += '- '+nm+' é de preenchimento obrigatório\n';
*/
  }
  if (errors) {
  	return 'Erro(s) encontrado(s):\n'+errors;
  //document.MM_returnValue = (errors == '');
  } else {
    return true;
  }
}

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;
}

/*----------------------------------
 *
 *TauFormFunctions.js
 *
 *----------------------------------
 */

/*************** TAU Functions ****************/
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 "Endereço de email incorreto (verifique @ e '.')."
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    return "Nome de usuário de email inválido."
}

/* 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 "IP de destino inválido."
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
    return "Nome de domínio inválido."
}

/* 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 "O endereço de email deve terminar em um domínio de três letras ou um código de país de duas letras."
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   return "Endereço sem um 'hostname'!"
}

// If we've gotten this far, everything's valid!
return true;
}
//  End -->

function cpfCheck(s){ 
  var i; 
  var c = s.substr(0,9); 
  var dv = s.substr(9,2); 
  var d1 = 0; 
    if (s.match(/(00000000000|11111111111|22222222222|33333333333|44444444444|55555555555|66666666666|77777777777|88888888888|99999999999)/) != null) {
        return false;
    }
    for (i = 0; i < 9; i++){ 
      d1 += c.charAt(i)*(10-i); 
    } 
    if (d1 == 0){ 
      return false
    } 
    d1 = 11 - (d1 % 11); 
    if (d1 > 9) d1 = 0; 
    if (dv.charAt(0) != d1){ 
      return false
    } 
  d1 *= 2; 
    for (i = 0; i < 9; i++){ 
      d1 += c.charAt(i)*(11-i); 
    } 
  d1 = 11 - (d1 % 11); 
    if (d1 > 9) d1 = 0; 
    if (dv.charAt(1) != d1){ 
      return false
    } 
  return true; 
} 

function isNUMB(c)
	{
	if((cx=c.indexOf(","))!=-1)
		{		
		c = c.substring(0,cx)+"."+c.substring(cx+1);
		}
	if((parseFloat(c) / c != 1))
		{
		if(parseFloat(c) * c == 0)
			{
			return(1);
			}
		else
			{
			return(0);
			}
		}
	else
		{
		return(1);
		}
	}

function LIMP(c)
	{
	while((cx=c.indexOf("-"))!=-1)
		{		
		c = c.substring(0,cx)+c.substring(cx+1);
		}
	while((cx=c.indexOf("/"))!=-1)
		{		
		c = c.substring(0,cx)+c.substring(cx+1);
		}
	while((cx=c.indexOf(","))!=-1)
		{		
		c = c.substring(0,cx)+c.substring(cx+1);
		}
	while((cx=c.indexOf("."))!=-1)
		{		
		c = c.substring(0,cx)+c.substring(cx+1);
		}
	while((cx=c.indexOf("("))!=-1)
		{		
		c = c.substring(0,cx)+c.substring(cx+1);
		}
	while((cx=c.indexOf(")"))!=-1)
		{		
		c = c.substring(0,cx)+c.substring(cx+1);
		}
	while((cx=c.indexOf(" "))!=-1)
		{		
		c = c.substring(0,cx)+c.substring(cx+1);
		}
	return(c);
	}

function cnpjCheck(CNPJ)
	{
	CNPJ = LIMP(CNPJ);
	if(isNUMB(CNPJ) != 1)
		{
		return(0);
		}
	else
		{
		if(CNPJ == 0)
			{
			return(0);
			}
		else
			{
			g=CNPJ.length-2;
			if(RealTestaCNPJ(CNPJ,g) == 1)
				{
				g=CNPJ.length-1;
				if(RealTestaCNPJ(CNPJ,g) == 1)
					{	
					return(1);
					}
				else
					{
					return(0);
					}
				}
			else
				{
				return(0);
				}
			}
		}
	}
function RealTestaCNPJ(CNPJ,g)
	{
	var VerCNPJ=0;
	var ind=2;
	var tam;
	for(f=g;f>0;f--)
		{
		VerCNPJ+=parseInt(CNPJ.charAt(f-1))*ind;
		if(ind>8)
			{
			ind=2;
			}
		else
			{
			ind++;
			}
		}
		VerCNPJ%=11;
		if(VerCNPJ==0 || VerCNPJ==1)
			{
			VerCNPJ=0;
			}
		else
			{
			VerCNPJ=11-VerCNPJ;
			}
	if(VerCNPJ!=parseInt(CNPJ.charAt(g)))
		{
		return(0);
		}
	else
		{
		return(1);
		}
	}


/*
 *
 *Envia um formulario com o serial para o caminho dado na funcao serializaform,
 *funcao do php
 */

function enviar_serial(serial){
    document.forms[0].action=serial;
    document.forms[0].submit();
} 
/*
 * Funcao padrao para abrir janelas.
 */
function TAU_openBrWindow(theURL,winName,features,largura,altura,f) { //v2.0
  if(f==1){
    l=0;t=0;largura=(screen.availWidth-10);altura=(screen.availHeight-26);
  }else{
    var l = ((screen.availWidth)/2) - (largura/2);
    var t = ((screen.availHeight)/2) - ((altura/2)+20);
  }
  features = features + ",width=" + largura + ",height=" + altura + ",left=" + l + ",top=" + t;
  window.open(theURL,winName,features);
}

/*
 *Funcao que trata a data no formato mm/yyyy
 */

function trata_data(hidden,texto){

    var frm=document.forms[0];

    if(frm[texto].value.length==7){
        frm[hidden].value="01/"+frm[texto].value;
    }else if(frm[texto].value==""){
        frm[hidden].value="";
    }else{
        frm[hidden].value=frm[texto].value;
    }
    
}


