window.onstopscroll = function(){
	formtrabalhe.alinha();
	//alert('teste');
}

function postar(){
	var ofrm = document.frm_contato;

	if (ofrm.nome.value.length == 0 || ofrm.nome.value.replace(/\ /g, "") == ""){
		SA.open('Aten&ccedil;&atilde;o!', 'Por favor, preencha o campo nome.', null, 1, 1);
		return false;
	}else if (ofrm.departamento.value.length == 0 || ofrm.departamento.value.replace(/\ /g, "") == ""){
		SA.open('Aten&ccedil;&atilde;o!', 'Por favor, preencha o campo departamento.', null, 1, 1);
		return false;
	}else if (ofrm.empresa.value.length == 0 || ofrm.empresa.value.replace(/\ /g, "") == ""){
		SA.open('Aten&ccedil;&atilde;o!', 'Por favor, preencha o campo empresa.', null, 1, 1);
		return false;
	}else if (ofrm.fone.value.length == 0 || ofrm.fone.value.replace(/\ /g, "") == ""){
		SA.open('Aten&ccedil;&atilde;o!', 'Por favor, preencha o campo telefone corretamente.', null, 1, 1);
		return false;
	}else if (ofrm.cidade.value.length == 0 || ofrm.cidade.value.replace(/\ /g, "") == ""){
		SA.open('Aten&ccedil;&atilde;o!', 'Por favor, preencha o campo cidade corretamente.', null, 1, 1);
		return false;
	}else if (ofrm.email.value.length == 0 || ofrm.email.value.replace(/\ /g, "") == ""){
		SA.open('Aten&ccedil;&atilde;o!', 'Por favor, preencha o campo e-mail.', null, 1, 1);
		return false;
	}else if (!verifica_email(ofrm.email.value)){
		SA.open('Aten&ccedil;&atilde;o!', 'Preencha corretamente o campo e-mail.', null, 1, 1);
		return false;
	}else if (ofrm.texto.value.length == 0 || ofrm.texto.value.replace(/\ /g, "") == ""){
		SA.open('Aten&ccedil;&atilde;o!', 'Por favor, preencha o campo comentário.', null, 1, 1);
		return false;
	}

	//document.frm_contato.submit();
	
	
	SAWait.open();
	
	var form = $('frm_contato');
	var xml = new xmlConnection();
	if (xml.create()){
		xml.setURL('/enviaContato/');
		xml.setMethod('POST');
		xml.addParameters('nocache',nocache());
		xml.addParameters('nome',form.nome.value);	
		xml.addParameters('departamento',form.departamento.value);	
		xml.addParameters('empresa',form.empresa.value);	
		xml.addParameters('fone',form.fone.value);
		xml.addParameters('estado',form.estado.value);
		xml.addParameters('cidade',form.cidade.value);
		xml.addParameters('email',form.email.value);
		xml.addParameters('texto',form.texto.value);
		xml.addParameters('atividade',form.atividade.value);
		xml.addParameters('segmento',form.segmento.value);
		
		var itens = document.getElementsByTagName("input"); 
		for (var i = 0; i < itens.length; i++) { 
			if(itens[i].type=="checkbox" && itens[i].name.substr(0,7)=="areaint" && itens[i].checked==true){
				xml.addParameters(itens[i].id,itens[i].value);
			}
		}
	
		
		
	}
	xml.onComplete = function() {
		SAWait.close();
		
		this.setChildName('return');
		if(this.getAttByName('retorno',0)==1){
			var cb = new Object();
			cb.onOk = function(){
				SA.close();
				$('frm_contato').reset();				
			}
			SA.open('Contato enviado!', 'Obrigado por entrar em contato com a Contemp. Em breve responderemos.', cb, 1, 1);	
		}else{
			SA.open('Erro ao enviar!', 'Ocorreu um erro ao enviar seu contato. Favor tente novamente mais tarde.', null, 1, 1);
		}
	}
	formtrabalhe.hide();
	xml.execute();

	
}

seleciona = function(atividade){
	$('segmento').length = 1;

	SAWait.open();

	var upost = 'atividade='+atividade;

	var CB={
		success:function(o){
			var xml = new xmlParse();
			xml.setObjAjax(o);
			xml.setChildName('segmento');
			xml.parse();

			var no = "";
			var total = xml.getCountItens();
			if (total>0){
				for (var i=0; i<total; i++){
					no = document.createElement("OPTION");
					$('segmento').appendChild(no);
					no.value = xml.getAttByName('id', i);
					no.text = xml.getAttByName('nome', i);
				}
			}

			SAWait.close();
		},
		failure:function(){
			SA.open('Erro!', 'Ocorreu um erro ao selecionar os segmentos. Favor tente novamente mais tarde.', null, 1, 1);
		}
	};
	Connect.asyncRequest('GET', '/segmentoAtividadeXML/?'+upost, CB, null);
}

function ver_select(idx)
{
	var oSel = $('segmento');
	var oDiv = document.getElementById("oSeg");
	var a = $('atividade').options[idx].value.split("|");

	if (a[1] == 1) {
		seleciona($('atividade').options[idx].value);
		oSel.style.display = "block";
		oDiv.style.display = "block";
	} else {
		oDiv.style.display = "none";
		oSel.style.display = "none";
		oSel.selectedIndex = 0;
		oSel.length = 1;
	}
}

acoesInit = function(e){
	
	/* UPLOAD */
	var d = new Date()
	var filename = d.getFullString();
	
	var swfu = new simpleSwfUpload({
		'file_types': "*.pdf;*.doc;*.docx;*.txt;",
		'file_types_description': "Documentos",
		'upload_url':'/curriculo/upload/?filename='+filename,
		'button_placeholder_id': "btprocurar",									   
		'button_image_url': '/media/img/pt-br/btProcurar.gif',
		'button_width': 90,
		'button_height': 22,
		'flash_url': '/media/swf/swfupload.swf',
		'debug': false
	});
	
	swfu.fileQueued = function(file){
		try {
			arrArq = file.name.split('.');
			$('curriculotrabalhe').value = filename+'.'+arrArq[1];
		}catch (e) {}
	}
	
	//swfu.setButtonCursor(-2);
	
	swfu.fileDialogComplete = function(numFilesSelected, numFilesQueued){
		if(numFilesSelected != 0){
			if(numFilesSelected == 1){
				try {
					swfu.startUpload();
				}catch (e) {}
			}else{
				alert('Selecione somente um arquivo!');
				this.cancelUpload();
			}
		}
	}
	
	
	swfu.uploadSuccess = function(file, serverData) {
		try{
			if (serverData === " ") {
				this.customSettings.upload_successful = false;
			} else {
				this.customSettings.upload_successful = true;
			}
		}catch(e) {}
	}
	
	swfu.uploadComplete = function(file) {
		try {
			if (this.customSettings.upload_successful) {
				this.setButtonDisabled(true);				
			} else {							
				alert('erro');
				$('curriculotrabalhe').value = "";
			}
		} catch (e) {
		}
	}
	

	
	
	mostraFlash("banner", "/media/swf/banner.swf?secao=contato", 980, 196);
	addEvent('atividade', "keyup", function(e){acoesKB(e)});
}

acoesKB = function(e){
	if(!is_ie)if(e.which==38||e.which==40)ver_select($('atividade').selectedIndex);
}

addEvent(window, "load", function(e){acoesInit(e)});



var formtrabalhe = {
	'opened': false,
	'show': function(foto){
		this.opened = true;
		mensure.load();
		
		var DS = {x:mensure.widthVisible(), y:mensure.heightTotal()};
		$('blockbg').style.height = DS.y + 'px';
		if (!is_ie) {
			$('blockbg').style.width = (DS.x - 17) + 'px';
		} else {
			$('blockbg').style.width = DS.x + 'px';
		}
		setAlpha('blockbg', 80);
		$('blockbg').style.display = 'block';
		
		this.alinha();
		
	},
	'alinha' : function(){
		if(!this.opened) return;
		
		$('trabalhe').style.display = 'block';
		
		var SC = {x:mensure.posScrollX(), y:mensure.posScrollY()};
		var VS = {x:mensure.widthVisible(), y:mensure.heightVisible()};
		var SZ = {x:$('trabalhe').offsetWidth, y:$('trabalhe').offsetHeight};
		
		newX = (VS.x-SZ.x)/2+SC.x;
		newY = (VS.y-SZ.y)/2+SC.y;
		
		
		$('trabalhe').style.top = newY+'px';
		$('trabalhe').style.left = newX+'px';		
		

	},
	'hide': function(){
		this.opened = false;
		$('blockbg').style.display = 'none';
		$('trabalhe').style.display = 'none';
		
		
		$('nometrabalhe').value = '';
		$('emailtrabalhe').value = '';
		$('curriculotrabalhe').value = '';	
		
		
	}
} 


verificaTrabalhe = function(){
	var form = $('form1');
	erro = ''
	
	if(form.nometrabalhe.value==''){
		erro += 'Preencha seu nome.<br>';	
	}
	if(form.emailtrabalhe.value=='' || !form.emailtrabalhe.value.isMail()){
		erro += 'Preencha seu e-mail corretamente.<br>';	
	}
	if(form.curriculotrabalhe.value==''){
		erro += 'Preencha seu currículo.<br>';	
	}
	if(form.ait.value==''){
		erro += 'Preencha a área de interesse.<br>';	
	}
	if(erro==''){
		SAWait.open();
		var xml = new xmlConnection();
		if (xml.create()){
			xml.setURL('/curriculo/enviar/');
			xml.setMethod('POST');
			xml.addParameters('nocache',nocache());
			xml.addParameters('nome',form.nometrabalhe.value);		
			xml.addParameters('email',form.emailtrabalhe.value);
			xml.addParameters('curriculo',form.curriculotrabalhe.value);
			xml.addParameters('ait',form.ait.value);
			
		}
		xml.onComplete = function() {
			SAWait.close();
			this.setChildName('return');
			if(this.getAttByName('retorno',0)==1){
				var cb = new Object();
				cb.onOk = function(){
					//limparContato();
					SA.close();
					
				}
				SA.open('Currículo enviado!', 'Seu currículo foi enviado com sucesso. Em breve entraremos em contato.', cb, 1, 1);	
			}else{
				SA.open('Erro ao enviar!', 'Ocorreu um erro ao enviar seu currículo. Favor tente novamente mais tarde.', null, 1, 1);
			}
		}
		formtrabalhe.hide();
		xml.execute();
	}else{
		SA.open('Alerta', erro, null, 1, 1);	
	}
	
}

