//----------------------------------------------//
//			SEJA ORIGINAL / BE ORIGINAL			//
//			ISSO SÓ EU TENHO MAGRINHO			//
//	Programador José Eduardo Perotta de Almeida	//
//			perottas1@hotmail.com				//
//				+55 (27) 8836-8760				//
//----------------------------------------------//
function get(elemento)
{
	return document.getElementById(elemento);
}
var xmlhttp = iniciaAjax();
function iniciaAjax() {
	if (window.XMLHttpRequest)
	{
		return new XMLHttpRequest(); 
	} else if (window.ActiveXObject) 
	{
			return new ActiveXObject("Microsoft.XMLHTTP");
	}
}
function ajaxLoad(what, where)
{
	xmlhttp.open("GET", what, true);
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState==4)
		{
			get(where).innerHTML = xmlhttp.responseText;
		}
	}	
	xmlhttp.send(null);
}
function fazerContato()
{
	if (get('nomecontato').value == "" || get('emailcontato').value == "" || get('mensagemcontato').value == "")
	{
		window.alert('Favor informar ao menos seu nome, e-mail e a mensagem que deseja enviar!');
		get('nomecontato').focus();return (false);
	}else xmlhttp.open("GET", "Scripts/processacontato.asp?nomecontato=" + get('nomecontato').value + "&emailcontato=" + get('emailcontato').value + "&telefonecontato=" + get('telefonecontato').value + "&mensagemcontato=" + get('mensagemcontato').value + "", true);
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState==4)
		{
			get('boxrespostacontato').style.display='block';
			get('respostacontato').innerHTML = xmlhttp.responseText;
		}
	}	
	xmlhttp.send(null);
}
function validacaonewsletter()
{
	if (get('nome').value == "" || get('nome').value == "cadastre seu nome")
	{
		window.alert('Favor informar seu nome!');
		get('nome').focus();
		return (false);
	}else if (get('email').value == "" || get('email').value == "cadastre seu e-mail")
	{
		window.alert('Favor informar seu e-mail!');
		get('email').focus();return (false);
	}else if (!/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/.test(get('email').value))
	{
		window.alert('O e-mail fornecido está incorreto\nO e-mail deve ser semelhante à email@email.com!');
		get('email').focus();
		return (false);
	}else xmlhttp.open("GET", "Scripts/processanews.asp?nome=" + get('nome').value + "&email=" + get('email').value + "", true);
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState==4)
		{
			get('respostanewsletter').innerHTML = xmlhttp.responseText;
			get('boxrespostanewsletter').style.display='block';
		}
	}
	xmlhttp.send(null);
}
function fazerpergunta()
{
	xmlhttp.open("GET", "Scripts/processapergunta.asp?duvida=" + get('duvida').value + "", true);
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState==4)
		{
			get('boxprocessapergunta').style.display='block';get('respostaprocessapergunta').innerHTML = xmlhttp.responseText;
		}
	}	
	xmlhttp.send(null);
}
function trabalhar()
{
	xmlhttp.open("GET", "Scripts/processatrabalhe01.asp?passo=primeiro&nomecandidato=" + get('nomecandidato').value + "&sexo=" + get('sexoh').value + "&cpf=" + get('cpf').value + "&telefone=" + get('telefone').value + "&celular=" + get('celular').value + "&nascimento=" + get('nascimento').value + "&estadocivil=" + get('estadocivilh').value + "&naturalidade=" + get('naturalidade').value + "&nacionalidade=" + get('nacionalidade').value + "&cnh=" + get('cnhh').value + "&carro=" + get('carroh').value + "&areasdeinteresse=" + get('areasdeinteresseh').value + "&habilidades=" + get('habilidadesh').value + "", true);
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState==4)
		{
			get('boxrespostatrabalhe').style.display='block';get('respostatrabalhe').innerHTML = xmlhttp.responseText;
		}
	}	
	xmlhttp.send(null);
}
function trabalhar2()
{
	xmlhttp.open("GET", "Scripts/processatrabalhe01.asp?passo=segundo&idcandidato=" + get('idcandidato').value + "&endereco=" + get('endereco').value + "&bairro=" + get('bairro').value + "&cidade=" + get('cidade').value + "&uf=" + get('uf').value + "&cep=" + get('cep').value + "&email=" + get('emailcandidato').value + "&msn=" + get('msn').value + "&orkut=" + get('orkut').value + "&twitter=" + get('twitter').value + "&resumo=" + get('resumo').value + "&informacoescomplementares=" + get('informacoescomplementares').value + "", true);
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState==4)
		{
			get('boxrespostatrabalhe').style.display='block';get('respostatrabalhe').innerHTML = xmlhttp.responseText;
		}
	}	
	xmlhttp.send(null);
}
function trabalhar3()
{
	xmlhttp.open("GET", "Scripts/processatrabalhe01.asp?passo=terceiro&idcandidato=" + get('idcandidato').value + "&grau=" + get('grau').value + "&mesinicio=" + get('mesinicio').value + "&anoinicio=" + get('anoinicio').value + "&mestermino=" + get('mestermino').value + "&anotermino=" + get('anotermino').value + "&curso=" + get('curso').value + "&periodoatual=" + get('periodoatual').value + "&horario=" + get('horario').value + "&instituicao=" + get('instituicao').value + "&maisescolaridade=" + get('maisescolaridade').value + "", true);
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState==4)
		{
			get('boxrespostatrabalhe').style.display='block';get('respostatrabalhe').innerHTML = xmlhttp.responseText;
		}
	}	
	xmlhttp.send(null);
}
function trabalhar4()
{
	xmlhttp.open("GET", "Scripts/processatrabalhe01.asp?passo=quarto&idcandidato=" + get('idcandidato').value + "&mesinicioe=" + get('mesinicioe').value + "&anoinicioe=" + get('anoinicioe').value + "&mesterminoe=" + get('mesterminoe').value + "&anoterminoe=" + get('anoterminoe').value + "&empresa=" + get('empresa').value + "&cargo=" + get('cargo').value + "&realizacoesnocargo=" + get('realizacoesnocargo').value + "&maisexperiencia=" + get('maisexperiencia').value + "", true);
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState==4)
		{
			get('boxrespostatrabalhe').style.display='block';get('respostatrabalhe').innerHTML = xmlhttp.responseText;
		}
	}	
	xmlhttp.send(null);
}
function manipulaelemento(objetotela, acao) {
	var objetotela = get(objetotela);
	if (acao == "o"){objetotela.style.display = "none";} 
	if (acao == "e"){objetotela.style.display = "block";}
	if (acao == "l"){objetotela.value = "";}
}
function precarregaimgs()
{
	var d=document; if(d.images)
	{
		if(!d.MM_p) d.MM_p=new Array();
    	var i,j=d.MM_p.length,a=precarregaimgs.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 trocaimgsrestaura()
{
	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 identObjeto(n, d)
{
	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=identObjeto(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function trocaimgs()
{
	var i,j=0,x,a=trocaimgs.arguments;
	document.MM_sr=new Array;
	for(i=0;i<(a.length-2);i+=3)
		if ((x=identObjeto(a[i]))!=null)
		{
			document.MM_sr[j++]=x;
			if(!x.oSrc) x.oSrc=x.src;
			x.src=a[i+2];
		}
}
function mascara(o,f){
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
}
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=v.replace(/\D/g,"")                 
    v=v.replace(/^(\d\d)(\d)/g,"($1) $2") 
    v=v.replace(/(\d{4})(\d)/,"$1-$2")    
    return v
}
function telep(v){
    v=v.replace(/\D/g,"")                 
    v=v.replace(/^(\d\d)(\d)/g,"($1) $2") 
    v=v.replace(/(\d{4})(\d)/,"$1-$2")   
    return v
}
function ddata(v){
    v=v.replace(/\D/g,"")                 
    v=v.replace(/(\d{2})(\d)/,"$1/$2")    
	v=v.replace(/(\d{2})(\d)/,"$1/$2")    
    return v
}
function cccpf(v){
    v=v.replace(/\D/g,"")                    
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       
    v=v.replace(/(\d{3})(\d)/,"$1.$2")      
    v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") 
    return v
}
function cccep(v){
    v=v.replace(/\D/g,"")               
    v=v.replace(/^(\d{5})(\d)/,"$1-$2") 
    return v
}
function cccnpj(v){
    v=v.replace(/\D/g,"")                           
    v=v.replace(/^(\d{2})(\d)/,"$1.$2")             
    v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3") 
    v=v.replace(/\.(\d{3})(\d)/,".$1/$2")          
    v=v.replace(/(\d{4})(\d)/,"$1-$2")              
    return v
}
function urlsite(v){
    v=v.replace(/^http:\/\/?/,"")
    dominio=v
    caminho=""
    if(v.indexOf("/")>-1)
        dominio=v.split("/")[0]
        caminho=v.replace(/[^\/]*/,"")
    dominio=dominio.replace(/[^\w\.\+-:@]/g,"")
    caminho=caminho.replace(/[^\w\d\+-@:\?&=%\(\)\.]/g,"")
    caminho=caminho.replace(/([\?&])=/,"$1")
    if(caminho!="")dominio=dominio.replace(/\.+$/,"")
    v="http://"+dominio+caminho
    return v
}
function FormataReal(nvalor){
	nvalor = nvalor.replace(".","");
	nvalor = nvalor.replace(",",".");
	return nvalor;
}
function FormataRealn(nvalor){
	nvalor = nvalor.replace(".",",");
	nvalor = nvalor.replace(",",".");
	return nvalor;
}
function FormataValor(objeto,teclapres,tammax,decimais) 
{
	var tecla			= teclapres.keyCode;
	var tamanhoObjeto	= objeto.value.length;
	if ((tecla == 8) && (tamanhoObjeto == tammax))
	{
		tamanhoObjeto = tamanhoObjeto - 1 ;
	}
    if (( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) && ((tamanhoObjeto+1) <= tammax))
	{
		vr	= objeto.value;
		vr	= vr.replace( "/", "" );
		vr	= vr.replace( "/", "" );
		vr	= vr.replace( ",", "" );
		vr	= vr.replace( ".", "" );
		vr	= vr.replace( ".", "" );
		vr	= vr.replace( ".", "" );
		vr	= vr.replace( ".", "" );
		tam	= vr.length;
		if (tam < tammax && tecla != 8)
		{
			tam = vr.length + 1 ;
		}
		if ((tecla == 8) && (tam > 1))
		{
			tam = tam - 1 ;
			vr = objeto.value;
			vr = vr.replace( "/", "" );
			vr = vr.replace( "/", "" );
			vr = vr.replace( ",", "" );
			vr = vr.replace( ".", "" );
			vr = vr.replace( ".", "" );
			vr = vr.replace( ".", "" );
			vr = vr.replace( ".", "" );
		}
		if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
		{
			if (decimais > 0)
			{
				if ( (tam <= decimais) )
				{ 
					objeto.value = ("0," + vr) ;
				}
				if( (tam == (decimais + 1)) && (tecla == 8))
				{
					objeto.value = vr.substr( 0, (tam - decimais)) + ',' + vr.substr( tam - (decimais), tam ) ;	
				}
				if ( (tam > (decimais + 1)) && (tam <= (decimais + 3)) &&  ((vr.substr(0,1)) == "0"))
				{
					objeto.value = vr.substr( 1, (tam - (decimais+1))) + ',' + vr.substr( tam - (decimais), tam ) ;
				}
				if ( (tam > (decimais + 1)) && (tam <= (decimais + 3)) &&  ((vr.substr(0,1)) != "0"))
				{
				    objeto.value = vr.substr( 0, tam - decimais ) + ',' + vr.substr( tam - decimais, tam ) ; 
				}
				if ( (tam >= (decimais + 4)) && (tam <= (decimais + 6)) )
				{
			 		objeto.value = vr.substr( 0, tam - (decimais + 3) ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
				}
			 	if ( (tam >= (decimais + 7)) && (tam <= (decimais + 9)) )
				{
			 		objeto.value = vr.substr( 0, tam - (decimais + 6) ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
				}
				if ( (tam >= (decimais + 10)) && (tam <= (decimais + 12)) )
				{
			 		objeto.value = vr.substr( 0, tam - (decimais + 9) ) + '.' + vr.substr( tam - (decimais + 9), 3 ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
				}
				if ( (tam >= (decimais + 13)) && (tam <= (decimais + 15)) )
				{
			 		objeto.value = vr.substr( 0, tam - (decimais + 12) ) + '.' + vr.substr( tam - (decimais + 12), 3 ) + '.' + vr.substr( tam - (decimais + 9), 3 ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
				}
			}
			else if(decimais == 0)
			{
				if ( tam <= 3 )
				{ 
			 		objeto.value = vr ;
				}
				if ( (tam >= 4) && (tam <= 6) )
				{
					if(tecla == 8)
					{
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
					}
					objeto.value = vr.substr(0, tam - 3) + '.' + vr.substr( tam - 3, 3 ); 
				}
				if ( (tam >= 7) && (tam <= 9) )
				{
					if(tecla == 8)
					{
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
					}
					objeto.value = vr.substr( 0, tam - 6 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ); 
				}
				if ( (tam >= 10) && (tam <= 12) )
				{
			 		if(tecla == 8)
					{
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
					}
					objeto.value = vr.substr( 0, tam - 9 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ); 
				}

				if ( (tam >= 13) && (tam <= 15) )
				{
					if(tecla == 8)
					{
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
					}
					objeto.value = vr.substr( 0, tam - 12 ) + '.' + vr.substr( tam - 12, 3 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ) ;
				}			
			}
		}
	}
	else if((window.event.keyCode != 8) && (window.event.keyCode != 9) && (window.event.keyCode != 13) && (window.event.keyCode != 35) && (window.event.keyCode != 36) && (window.event.keyCode != 46))
		{
			window.event.cancelBubble = true;
			window.event.returnValue = false;
		}
}
$(document).ready(function() {		
	
	//Execute the slideShow
	slideShow();

});

function slideShow() {

	//Set the opacity of all images to 0
	$('#gallery a').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('#gallery a:first').css({opacity: 1.0});
	
	//Set the caption background to semi-transparent
	$('#gallery .caption').css({opacity: 0.7});

	//Resize the width of the caption according to the image width
	$('#gallery .caption').css({width: $('#gallery a').find('img').css('width')});
	
	//Get the caption of the first image from REL attribute and display it
	$('#gallery .content').html($('#gallery a:first').find('img').attr('rel'))
	.animate({opacity: 0.7}, 400);
	
	//Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('gallery()',10000);
	
}

function gallery() {
	
	//if no IMGs have the show class, grab the first image
	var current = ($('#gallery a.show')?  $('#gallery a.show') : $('#gallery a:first'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#gallery a:first') :current.next()) : $('#gallery a:first'));	
	
	//Get next image caption
	var caption = next.find('img').attr('rel');	
	
	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
	//Set the opacity to 0 and height to 1px
	$('#gallery .caption').animate({opacity: 0.0}, { queue:false, duration:50 }).animate({height: '1px'}, { queue:true, duration:300 });	
	
	//Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
	$('#gallery .caption').animate({opacity: 0.7},100 ).animate({height: '50px'},500 );
	
	//Display the content
	$('#gallery .content').html(caption);
}