var iStart = 5;
var activeZIndexNovo = 0;	
function changeOn(image) {
  activeZIndexNovo = document.getElementById(image).style.zIndex;
  document.getElementById(image).style.zIndex = iStart;
}
function changeOff(image) {
  document.getElementById(image).style.zIndex = activeZIndexNovo;
}
function popUp_print(pagina){
	pop1 = open(pagina,"","width=845,location=no,menubar=no,statusbar=no,toolbar=no,resizable=yes,scrollbars=yes")
	pop1.focus()  // forces the popup to come to the front if it has already been opened, but not closed
}
//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}
//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
//Resize - Lightbox
function resizeBackgroud(){
	// prep objects
	var objOverlay = document.getElementById('overlay');
	var arrayPageSize = getPageSize();
	
	objOverlay.style.width =  (arrayPageSize[0]  + 'px');
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	
}
window.onresize = function (){
	resizeBackgroud();	
}
//Popup 
function showPopup(visibility,boxPopup){
	
	$("#popContent").text("");

	if (visibility == true ){
		display = "block";
		$('embed, object, select').css({ 'visibility' : 'hidden' });
	} else {
		display = "none";
		$('embed, object, select').css({ 'visibility' : 'visible'});
	}
	resizeBackgroud();
	//Esconde os conteudos
	
	$("#overlay").css({'display' : display }); 
	$("#popup").css({'display' : display }); 
	
	switch (boxPopup) {
		case "termo":
			$("#popContent").load("/web/site/vf/termo_de_uso.jsp");
			break
		case "imprensa":
			$("#popContent").load("/web/site/vf/imprensa.jsp");
			break
		case "politica":
			$("#popContent").load("/web/site/vf/politica.jsp");
			break			
	}	
}

/*Popup Print*/
function popUp_print(pagina){
	pop1 = open(pagina,"","width=845,location=no,menubar=no,statusbar=no,toolbar=no,resizable=yes,scrollbars=yes")
	pop1.focus()  // forces the popup to come to the front if it has already been opened, but not closed
}

/*Itens Show/Hide*/
function toggleItens(item){
	$('#'+item).toggle();
	if ( $('#'+item).is(':hidden') ){
		$('#img-'+item).attr('src', '/web/site/vf/imagens/conteudo/icoQuadMostra.gif');
	} else {
		$('#img-'+item).attr('src', '/web/site/vf/imagens/conteudo/icoQuadEsconde.gif');
	}
}

/*Contato*/
function encaminhar() {
	var link;
	var empresaSelecionada = document.getElementById("empresa").options[document.getElementById("empresa").selectedIndex].value; 
	if("Selecione" == empresaSelecionada) {
		//alert("Seleciona alguma coisa nÃ© mano !");
	} else {
		if("Banco Votorantim" == empresaSelecionada) {
			//alert("mandei para http://votorantimfinancas.ats.hrsmart.com/cgi-bin/a/viewprofile.cgi?companyid=4?empresa=1");
			link="http://votorantimfinancas.ats.hrsmart.com/cgi-bin/a/viewprofile.cgi?companyid=4?empresa=1"
		} else if("VAM - Votorantim Asset Management" == empresaSelecionada) {
					//alert("mandei para http://votorantimfinancas.ats.hrsmart.com/cgi-bin/a/viewprofile.cgi?companyid=4?empresa=9");
			link="http://votorantimfinancas.ats.hrsmart.com/cgi-bin/a/viewprofile.cgi?companyid=4?empresa=9"
		} else if("Votorantim Corretora" == empresaSelecionada) {
					//alert("mandei para http://votorantimfinancas.ats.hrsmart.com/cgi-bin/a/viewprofile.cgi?companyid=4?empresa=8");
			link="http://votorantimfinancas.ats.hrsmart.com/cgi-bin/a/viewprofile.cgi?companyid=4?empresa=8"	
		} else if("BV Financeira" == empresaSelecionada) {
					//alert("mandei para http://votorantimfinancas.ats.hrsmart.com/cgi-bin/a/viewprofile.cgi?companyid=4?empresa=4");
			link="http://votorantimfinancas.ats.hrsmart.com/cgi-bin/a/viewprofile.cgi?companyid=4?empresa=4"
		} else if("BV Leasing" == empresaSelecionada) {
					//alert("mandei para http://votorantimfinancas.ats.hrsmart.com/cgi-bin/a/viewprofile.cgi?companyid=4?empresa=5");
			link="http://votorantimfinancas.ats.hrsmart.com/cgi-bin/a/viewprofile.cgi?companyid=4?empresa=5"
		} else if("BV Sistemas" == empresaSelecionada) {
					//alert("mandei para http://votorantimfinancas.ats.hrsmart.com/cgi-bin/a/viewprofile.cgi?companyid=4?empresa=7");
			link="http://votorantimfinancas.ats.hrsmart.com/cgi-bin/a/viewprofile.cgi?companyid=4?empresa=7"
		}
		var width = 603;
		var height = 450;
		var left   = (screen.width  - width)/2;
		var top    = (screen.height - height)/2;
		var params = 'width='+width+', height='+height;
		params += ', top='+top+', left='+left;
		params += ', directories=no';
		params += ', location=no';
		params += ', menubar=no';
		params += ', resizable=no';
		params += ', scrollbars=yes';
		params += ', status=no';
		params += ', toolbar=no';
	
		newwin=window.open(link,'trabalhe', params);
		if (window.focus) {newwin.focus();}
		return false;			
	}
}

function checkIt(evt) {
    evt = (evt) ? evt : window.event
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        status = ""
        return false
    }
    status = ""
    return true
}
function focusNome() {
	document.getElementById("txtNome").focus();
}

/*
$().ready(function(){
	$.mask.addPlaceholder("~","[+-]");
	$("#txtDDD").mask("99");
	$("#txtTelefone").mask("9999-9999"); 			
});
*/
var whitespace = " \t\n\r";
function isEmail (s) {   
	
	if (isEmpty(s)) { 
    	if (isWhitespace(s)) return false;
    }
    
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@")) { 
    	i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) {
    	return false;
    } else{
          if(s.charAt(i+1) == ".") {
          	  return false;
          } else {        
      	  	  i += 2;
      	  }				      							     									    
    }
    								 
    while ((i < sLength) && (s.charAt(i) != ".")) { 
    	i++
    }

    if ((i >= sLength - 1) || (s.charAt(i) != ".")) {
    	return false;
    } else {
    	return true;
    } 
    
    
}

function isEmpty(s) {
   return ((s == null) || (s.length == 0))
}

function isWhitespace (s) {
     var i;

    // Is s empty?
    if (isEmpty(s)) {
    	return true;
    }

    for (i = 0; i < s.length; i++) {   
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    return true;
}


function VerificarForm(f)
{
	div = document.getElementById("msgErroEmail");
	div.style.display="none";
	div = document.getElementById("msgErro");
	div.style.display="none";
	
	var flag = 0;
	var flag1 = 0;
	
	for( i=0; i<document.frmEmail.length; i++ )
	{
		if( document.frmEmail[i].value == "" && document.getElementById("msg_" + document.frmEmail[i].name) )
		{
			var div = document.getElementById("div_" + document.frmEmail[i].name);
			div.style.color="#E10101";
			div = document.getElementById("msgErro");
			div.style.display="block";
			if (flag1==0) {
				document.frmEmail[i].focus();
				flag1=1;
			}
			flag = 1;
		} else if (document.getElementById("msg_" + document.frmEmail[i].name)) {
			var div = document.getElementById("div_" + document.frmEmail[i].name);
			div.style.color="#666666";
		}
	}
	
	if( !isEmail($('#txtEmail').val()) && flag == 0) {
		div = document.getElementById("msgErroEmail");
		div.style.display="block";
		$('#txtEmail').focus();
		div = document.getElementById("div_txtEmail");
		div.style.color="#E10101";
	}

	if (flag == 0) {
		div = document.getElementById("msgErro");
		div.style.display="none";
		if(isEmail($('#txtEmail').val())){
			div = document.getElementById("msgErroEmail");
			div.style.display="none";
			document.frmEmail.submit();	
		}
	}
}

//Login
function validaLogin(){
	//Reset
	$("#error").hide();
	$("#div_txtCPF").css({ color:"#666666"});
	$("#div_txtDataNascimento").css({ color:"#666666"});
	
	if ( $("#txtCPF").val() == "") {
		$("#error").show();
		$("#error").html("Campo <b>CPF</b> está vazio <br />");
		$("#div_txtCPF").css({ color:"red"});						
	} else if ( $("#txtDataNascimento").val() == "") {
		$("#error").show();
		$("#error").html("Preencha a <b>Data de Nascimento</b> no formato dd/mm/aaaa. <br />");
		$("#div_txtDataNascimento").css({ color:"red"});
	} else {						
		$("#error").hide();						
		
		if(!ehCpfCnpjValido()) {
			$("#error").show();
			$("#error").html("<b>CPF</b> inválido <br />");
			$("#div_txtCPF").css({ color:"red"});								
		} else {
			$("#login").submit();
		}
		
	}				
}

function ehCpfCnpjValido() {
	var obj = $("#txtCPF").val(); 
	var cpfcnpj = new String(obj);
	cpfcnpj= cpfcnpj.replace(".", "");
	cpfcnpj= cpfcnpj.replace(".", "");
	cpfcnpj= cpfcnpj.replace(".", "");
	cpfcnpj= cpfcnpj.replace("-", "");
	cpfcnpj= cpfcnpj.replace("/", "");
	if(cpfcnpj.length < 14) {
		if (cpfcnpj.length != 11 
			|| cpfcnpj== "00000000000" 
			|| cpfcnpj== "11111111111" 
			|| cpfcnpj== "22222222222" 
			|| cpfcnpj== "33333333333" 
			|| cpfcnpj== "44444444444" 
			|| cpfcnpj== "55555555555" 
			|| cpfcnpj== "66666666666" 
			|| cpfcnpj== "77777777777" 
			|| cpfcnpj== "88888888888" 
			|| cpfcnpj== "99999999999") {
			return false;	
		} else {
			
			var numeros, digitos, soma, i, resultado, digitosIguais;
			digitosIguais = 1;
			if (cpfcnpj.length < 11) {
				return false;
			}
			
			for (i = 0; i < cpfcnpj.length - 1; i++) {
				if (cpfcnpj.charAt(i)  != cpfcnpj.charAt(i + 1)) {
					digitosIguais = 0;
					break;
				}
			}
			
			if (!digitosIguais) {
				numeros = cpfcnpj.substring(0, 9);
				digitos = cpfcnpj.substring(9);
				soma = 0;
				
				for (i = 10; i > 1; i--) {
					soma += numeros.charAt(10 - i) * i;
				}
				
				resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
				
				if (resultado != digitos.charAt(0) ) {
					return false;
				}
				
				numeros = cpfcnpj.substring(0, 10);
				
				soma = 0;
				
				for (i = 11; i > 1; i--) {
					soma += numeros.charAt(11 - i) * i;
				}
				
				resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
				
				if (resultado != digitos.charAt(1)) {
					return false;
				}
				
				return true;
			
			} else {
				return false;
			}	
		}
	}
}
