function abre_curriculum()
{
	window.open("http://www.construtores.novopca.pt/recursoshumanos/curriculum/index.php","_blank");
}



//rotator
var interval = 5; // delay between rotating images (in seconds)
var random_display = 1; // 0 = no, 1 = yes
interval *= 1000;
var intervaloBanner;
var imagemBanner
var proximaImagem=1



function rotateImage(place) {
if(!document.getElementById(place)){
	if(!intervaloBanner)return false //hack para nao começar logo no inicio
clearTimeout(intervaloBanner)
return false
}



proximaImagem=(proximaImagem==imagemBanner)?1:(proximaImagem+1);
$.post("empresa/escolheImagem.php?n="+proximaImagem+'&r='+ Math.floor ( Math.random ( ) * 50 + 1 ),function(data){
		
			
$('#' + place).fadeOut("slow",
					 function(){
						 $(this).html(data)
						 $(this).fadeIn("slow");
						 })

var recur_call = "rotateImage('"+place+"')";
intervaloBanner=setTimeout(recur_call, interval);
});

}

function pageload(site) {
	conc=(site.indexOf("?")!="-1")?"&":"?"
		// hash doesn't contain the first # character.
		if(site) {
			// restore ajax loaded state
			$("#conteudo").html('<img src="js/ajax-loader_base.gif" style="margin-left:15px;">')
		
		$("#conteudo").load(site  + conc +'r='+ Math.floor ( Math.random ( ) * 50 + 1 ), function(){
										 //   recur_call = "rotateImage('bannerRotator')";
											//intervaloBanner=setTimeout(recur_call, interval);
										  // timer();
										   if(site=='empresa/empresa.php'){
											//   $('#flashIntro').html(' ')
											   
										
											   
											   
											   }
												   
												   });
		$('[@class=subMenu]').css({ backgroundColor:"", fontWeight:"" });
		if(site)$('[@class=subMenu][@href*='+site+']').css({ fontWeight:"bold" });
		} else {
			// start page
			$("#load").empty();
		}
	}


function abrepagina(site){
	$.historyLoad(site);	
}



var intervalID;
$(document).ready(function() {
	
	$.historyInit(pageload);
	initShowHideDivs();
	//Mudar Tamanho da Estrutura da Pagina caso browser = Firefox
	
	myabc = document.location.href;
 	posn = myabc.indexOf("#");
 	if (posn==-1) {
 		abrepagina('empresa/empresa.php');
	}
	//$('#dhtmlgoodies_q1').click();
	if(navigator.userAgent.indexOf("Firefox")!=-1)
	{
		document.all('corpo').style.width=820;
		document.all('reguladorMenu').style.width=160;
		document.all('reguladorCorpo').style.width=788;
		setTimeout('pollHashF();',2000);
		
	}
	
	
})

//LOGIN
function login() {
	parent.top.location="http://intranet.novopca.pt";
}

//SLIDE
var dhtmlgoodies_slideSpeed = 10;	// Higher value = faster
var dhtmlgoodies_timer = 10;	// Lower value = faster

var objectIdToSlideDown = false;
var dhtmlgoodies_activeId = false;
function showHideContent(e,inputId)
{
	
	if(!inputId)inputId = this.id;
	inputId = inputId + '';
	//alert(e + ' :' + inputId)
	var numericId = inputId.replace(/[^0-9]/g,'');
	var answerDiv = document.getElementById('dhtmlgoodies_a' + numericId);
	
	objectIdToSlideDown = false;
	
	if(!answerDiv.style.display || answerDiv.style.display=='none'){

		if(dhtmlgoodies_activeId &&  dhtmlgoodies_activeId!=numericId){			
			objectIdToSlideDown = numericId;
			slideContent(dhtmlgoodies_activeId,(dhtmlgoodies_slideSpeed*-1));
		}else{
			
			answerDiv.style.display='block';
			answerDiv.style.visibility = 'visible';
			
			slideContent(numericId,dhtmlgoodies_slideSpeed);
		}
	}else{
		slideContent(numericId,(dhtmlgoodies_slideSpeed*-1));
		dhtmlgoodies_activeId = false;
	}	
}

function slideContent(inputId,direction)
{
	//alert(inputId + ': ' + direction)
	var obj =document.getElementById('dhtmlgoodies_a' + inputId);
	var contentObj = document.getElementById('dhtmlgoodies_ac' + inputId);
	height = obj.clientHeight;
	height = height + direction;
	rerunFunction = true;
	if(height>contentObj.offsetHeight){
		height = contentObj.offsetHeight;
		rerunFunction = false;
	}
	if(height<=1){
		height = 1;
		rerunFunction = false;
	}

	obj.style.height = height + 'px';
	var topPos = height - contentObj.offsetHeight;
	if(topPos>0)topPos=0;
	contentObj.style.top = topPos + 'px';
	if(rerunFunction){
		setTimeout('slideContent(' + inputId + ',' + direction + ')',dhtmlgoodies_timer);
	}else{
		if(height<=1){
			obj.style.display='none'; 
			if(objectIdToSlideDown && objectIdToSlideDown!=inputId){
				document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.display='block';
				document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.visibility='visible';
				slideContent(objectIdToSlideDown,dhtmlgoodies_slideSpeed);				
			}
		}else{
			dhtmlgoodies_activeId = inputId;
		}
	}
}



function initShowHideDivs()
{
	var divs = document.getElementsByTagName('DIV');
	var divCounter = 1;
	for(var no=0;no<divs.length;no++){
		if(divs[no].className=='dhtmlgoodies_question'){
			divs[no].onclick = showHideContent;
			divs[no].id = 'dhtmlgoodies_q'+divCounter;
			
			var answer = divs[no].nextSibling;
			while(answer && answer.tagName!='DIV'){
				answer = answer.nextSibling;
			}
			
			answer.id = 'dhtmlgoodies_a'+divCounter;	
			
			contentDiv = answer.getElementsByTagName('DIV')[0];
			contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px'; 	
			contentDiv.className='dhtmlgoodies_answer_content';
			contentDiv.id = 'dhtmlgoodies_ac' + divCounter;
			answer.style.display='none';
			answer.style.height='1px';
			divCounter++;
		}		
	}	
	
	
	
	
	
	

}


function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Email inválido")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Email inválido")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Email inválido")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Email inválido")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Email inválido")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Email inválido")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Email inválido")
		    return false
		 }

 		 return true					
	}

function ValidateForm(){
	///serve para envio de curriculum dos recursos humanos
	var emailID=document.form1.email
	var tituloID=document.form1.titulo
	var nomeID=document.form1.nome
	var apelidoID=document.form1.apelido
	var uploadID=document.form1.upload
	
	if ((tituloID.value==null)||(tituloID.value=="")){
		alert("Preencha o Campo Título")
		//tituloID.style.backgroundColor="red"
		tituloID.focus()
		return false
	}
	if ((nomeID.value==null)||(nomeID.value=="")){
		alert("Preencha o Campo Nome")
		nomeID.style.backgroundColor="red"
		nomeID.focus()
		return false
	}
	if ((apelidoID.value==null)||(apelidoID.value=="")){
		alert("Preencha o Campo Apelido")
		apelidoID.style.backgroundColor="red"
		apelidoID.focus()
		return false
	}
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Preencha o Campo Email")
		emailID.style.backgroundColor="red"
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.style.backgroundColor="red"
		emailID.focus()
		return false
	}
	
	if ((uploadID.value==null)||(uploadID.value=="")){
		alert("Seleccione um ficheiro")
		uploadID.style.backgroundColor="red"
		uploadID.focus()
		return false
	}

	OK = new Array ('zip', 'pdf', 'xps','doc', 'rar', 'docx');
	theFile = uploadID.value; // i.e. the file name passed to the function
	extensao=theFile.split('.')
	ultimo=(extensao.length)-1
	testa=extensao[ultimo].replace(/^\s*/, "").replace(/\s*$/, "").toLowerCase();
	
	fileOK = false;
	for (i = 0; i < OK.length; i++) {
		
		if (testa.toString()==OK[i].toString()) {
		
		fileOK = true; // one of the file extensions found
		
		}

	}
	
	if (fileOK!=true){
	
	alert("Apenas são válidos ficheiros com o formato: .pdf, .xps, .doc, .docx, .zip, .rar ")
	uploadID.style.backgroundColor="red"
	uploadID.focus()
	return false;
	}
	
	
	
	
	document.form1.submit()
 }


