function mudaOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}
function Fade(id, opacStart, opacEnd, millisec) {
    var speed = Math.round(millisec / 100);
    var timer = 0;

    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("mudaOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
		document.getElementById(id).style.display = "block";
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("mudaOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}
function FadeAutomatico(modo,maximo){
	num = document.getElementById("contadorhome").value;
	if (modo==1){
		var prox = Number(num) - 1;
		if (prox==0) prox=maximo-1;
	} else {
		var prox = Number(num) + 1;
		if (prox==maximo) prox=1;
	}
	Fade("destaque"+num,100,0,500);
	Fade("destaque"+prox,0,100,500);

	document.getElementById("numeroatual").innerHTML = "0"+prox;
	document.getElementById("contadorhome").value = prox;
}
function CampoExtra(modo){
	var obj = document.getElementById(modo);
	var conteudo = obj.innerHTML;
	var novo = document.createElement('div');
	novo.className = "subsub";
	novo.innerHTML = conteudo;
	obj.parentNode.appendChild(novo);
}
function NovoIdiomaCV(elem){
	var valor = elem.value;
	if (valor==7){
		elem.parentNode.getElementsByTagName("input")[0].style.display = "inline";
		elem.style.width = "98px";
	} else {
		elem.parentNode.getElementsByTagName("input")[0].style.display = "none";
		elem.style.width = "252px";
	}
}
function ValidaCurriculo(){
	if (ChecaCampo("nom","nome")&&ChecaCampo("rg","RG")&&ChecaCampo("org","Orgao Expedidor")&&ChecaCampo("nat","Naturalidade")&&ChecaCampo("end","Endereco")&&ChecaCampo("bai","Bairro")&&ChecaCampo("cid","Cidade")&&ChecaCampo("est","Estado")&&ChecaCampo("cep","CEP")&&ChecaTelefone("trs")&&ChecaEmail("eml")){
		//alert("tudo bem");
		document.getElementById('formcv').submit();
	};
}
function ChecaCampo(campo,nome){
	if (document.getElementById('campo'+campo).getElementsByTagName("input")[0].value==''){
		document.getElementById('campo'+campo).getElementsByTagName("input")[0].style.backgroundColor = "#FCC";
		alert("O campo \""+nome+"\" nao foi preenchido.\nPreencha esse campo.");
		scrollTo(0,0);
		return false;
	} else return true;
}
function ChecaTelefone(campo){
	if (document.getElementById('campo'+campo).getElementsByTagName("input")[0].value==''){
		document.getElementById('campo'+campo).getElementsByTagName("input")[0].style.backgroundColor = "#FCC";
		alert("O DDD do telefone residencial nao foi preenchido.\nPreencha esse campo.");
		scrollTo(0,0);
		return false;
	} else if (document.getElementById('campo'+campo).getElementsByTagName("input")[1].value==''){
		document.getElementById('campo'+campo).getElementsByTagName("input")[1].style.backgroundColor = "#FCC";
		alert("O numero do telefone residencial nao foi preenchido.\nPreencha esse campo.");
		scrollTo(0,0);
		return false;
	} else return true;
}
function ChecaEmail(campo){
	if (document.getElementById('campo'+campo).getElementsByTagName("input")[0].value==''){
		document.getElementById('campo'+campo).getElementsByTagName("input")[0].style.backgroundColor = "#FCC";
		alert("O campo de e-mail nao foi preenchido.\nPreencha esse campo.");
		scrollTo(0,0);
		return false;
	} else if (document.getElementById('campo'+campo).getElementsByTagName("input")[0].value.indexOf("@") == -1 || document.getElementById('campo'+campo).getElementsByTagName("input")[0].value.indexOf(".") == -1){
		document.getElementById('campo'+campo).getElementsByTagName("input")[0].style.backgroundColor = "#FCC";
		alert("O campo de e-mail nao foi preenchido corretamente.\nPreencha esse campo corretamente.");
		scrollTo(0,0);
		return false;
	} else return true;
}
function AreaTotal(){
	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){ // todos menos Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...funcionaria tb no Explorer 6 modo Strict, Mozilla e Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// todos menos Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 modo Strict 
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // outros Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	if (yScroll < windowHeight){
		AlturaTotal = windowHeight;
	} else {
		AlturaTotal = yScroll;
	}
	if (xScroll < windowWidth){
		LarguraTotal = windowWidth;
	} else {
		LarguraTotal = xScroll;
	}

	return [LarguraTotal,AlturaTotal,windowWidth,windowHeight];
}
function Overlay(modo,uri,w,h) {
	var objBody = document.getElementsByTagName('body').item(0);
	var Area = AreaTotal();
	var Largura = Area[0];
	var Altura = Area[1];
	var LarguraTela = Area[2];
	var AlturaTela = Area[3];
	var bodyOverlay = document.createElement("div");
	bodyOverlay.setAttribute('id','bodyOverlay');
	bodyOverlay.style.height = Altura + 'px'; // fundo com o tamanho total da página.
	if (!document.getElementById('bodyOverlay')) {
		objBody.insertBefore(bodyOverlay, objBody.firstChild);
	}
	if (modo=="img"){
		var bed = document.createElement("div");
		bed.setAttribute('id','bedOverlay');
		bed.style.width = '100%';
		bed.style.height = Altura + 'px';
		bed.style.top = ((AlturaTela/2)-(h/2)) + "px";
		bed.style.left = ((LarguraTela/2)-(w/2)) + "px";
		objBody.insertBefore(bed, objBody.firstChild);
		
		var fechar = document.createElement("a");
		fechar.setAttribute('id','fechar');
		fechar.innerHTML = "fechar";
		fechar.setAttribute('href','javascript:removerOverlay("img")');
		fechar.style.width = (w-28) + "px";
		bed.appendChild(fechar);
		var imagem = document.createElement("img");
		imagem.setAttribute('id','imgOverlay');
		imagem.setAttribute('src',uri);
		bed.appendChild(imagem);
	} else {
		document.getElementById('alterar_'+uri).style.display="block";
	}
}
/*function mapa(endereco){
	Overlay('mapa','',450,300);
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("imgOverlay"));
		var coder = new GClientGeocoder();
		var cords = coder.getLocations(endereco,null);
		var marca= new GMarker(cords);
		map.addOverlay(marca);
		map.setCenter(cords, 13);
	}
}
*/
function removerOverlay(modo) {
	var bodyOverlay = document.getElementById('bodyOverlay');
	if (bodyOverlay) {
		bodyOverlay.parentNode.removeChild(bodyOverlay);
	}
	if (modo=="img"){
		document.getElementById('bedOverlay').parentNode.removeChild(document.getElementById('bedOverlay'));
	} else {
		document.getElementById('alterar_'+modo).style.display="none";
	}
}

function TipValor(elem,foco,tip) {
	if (foco == 1 && elem.value==tip){//entrafoco
		elem.value='';
	} else {//saifoco
		if (elem.value=='') elem.value=tip;
	}
}

function LinkInterno(pag){
	uri = pag+".cs";
	document.location.href = uri;
}
function SubMenu(num){
	var divs = document.getElementById("menu").getElementsByTagName("div");
	var x = false;
	
	for (var d=0; d<divs.length ;d++){
		if (divs[d].id.substr(5,1)==num){
			var dd = divs[d].style.display;
			if (dd=="none" || !dd){
				if (!x) x="block"; 
				divs[d].style.display=x;
			} else {
				if (!x) x="none"; 
				divs[d].style.display=x;
			}
		}
	}
}

function ValidaComTip(elem,tipo){
	if (tipo=="busca") var tip = 'busca';
	else if (tipo=="buscahome") var tip = 'digite palavra-chave';
	else if (tipo=="cadastronome") var tip = 'seu nome';
	else if (tipo=="cadastroemail") var tip = 'seu e-mail';
	
	if (elem.value==''||elem.value==tip){
		alert("Preencha este campo");
		return false;
	} else {
		return true;
	}
}

function MostrAJAX(uri, elem){
    if (window.XMLHttpRequest) reqvar = new XMLHttpRequest();
	else if (window.ActiveXObject) reqvar = new ActiveXObject("Microsoft.XMLHTTP");
	
    reqvar.onreadystatechange= function() { 
        if (reqvar.readyState==4) {
			if (reqvar.status==200) {
				document.getElementById(elem).innerHTML = reqvar.responseText;
			} else {//if (reqvar.status == 404){
				document.getElementById(elem).innerHTML = "erro: "+reqvar.statusText;
			}
		} else if (reqvar.readyState == 1) { //carregando
			document.getElementById(elem).innerHTML = "<span id='carregando' style='width:260px;height:110px;top:0px'>carregando</span>";
		}
    }
	
    reqvar.open("GET",uri,true);
	
    if (window.XMLHttpRequest) reqvar.send(null);
	else if (window.ActiveXObject) reqvar.send();
}
function AlertAJAX(uri){
    if (window.XMLHttpRequest) reqvar = new XMLHttpRequest();
	else if (window.ActiveXObject) reqvar = new ActiveXObject("Microsoft.XMLHTTP");
	
    reqvar.onreadystatechange= function() { 
        if (reqvar.readyState==4) {
			if (reqvar.status==200) {
				alert(reqvar.responseText);
			} else {//if (reqvar.status == 404){
				alert("ERRO: "+reqvar.statusText);
			}
		} else if (reqvar.readyState == 1) { //carregando
			//document.getElementById(elem).innerHTML = "<span id='carregando' style='width:260px;height:110px;top:0px'>carregando</span>";
		}
    }
	
    reqvar.open("GET",uri,true);
	
    if (window.XMLHttpRequest) reqvar.send(null);
	else if (window.ActiveXObject) reqvar.send();
}