
//Copyright (c), 2001, Innovagency

NS=(document.layers && !document.all)?1:0
NS6=(document.getElementById && !document.all)?1:0

// ---------------------------------------------- //
// ----- Funções de leitura de propriedades ----- //
// ---------------------------------------------- //

// ---------------------------------------------- //
// --- Função de submit da pesquisa principal --- //
// ---------------------------------------------- //
function SubmitProcurar() {
	if(document.procurar.text.value.length>=3){
		document.procurar.submit();
	}
	return;
}

// ----------------------------------------------- //
// - Função de submit da pesquisa de diréctorios - //
// ----------------------------------------------- //
function SubmitDirectorio() {
//	if((document.directorio.especialidadeid.value!=0)||(document.directorio.nome.value!="")){
		document.directorio.submit();
//	}
	return;	
}

// ----------------------------------------------- //
// - Função de submit do formulário contacte-nos - //
// ----------------------------------------------- //
function SubmitContactenos() {
	document.contactenos.submit();
	return;	
}

// ----------------------------------------------- //
// - Função que limpa o formulário contacte-nos  - //
// ----------------------------------------------- //
function CleanContactenos() {
	//document.contactenos.reset();
	document.contactenos.nome.value="";
	document.contactenos.email.value="";
	document.contactenos.descricao.value="";
	document.contactenos.tiposugestaoid.value=0;
	return;	
}

// ----------------------------------------------- //
// - Função de submit da pesquisa de diréctorios - //
// ----------------------------------------------- //
function SubmitExame() {
//	if((document.exame.grupoexameid.value!=0)||(document.exame.exame.value!="")){
		document.exame.submit();
//	}
	return;	
}

// ----------------------------------------------- //
// -- Função de submit do formulário currículo  -- //
// ----------------------------------------------- //
function SubmitCurriculo( iOportunidadeID_IN ) {
	var i;
	var sAlert = "";
	var bSubmit = true;

	if( document.curriculo.nome.value == "" ) {
		bSubmit = false;
		sAlert = "Por favor, preencha o campo 'Nome'.";
	} else {
		if( document.curriculo.email.value == "" ) {
			bSubmit = false;
			sAlert = "Por favor, preencha o campo 'Email'.";
		} else {
			if( !EmailIsOk( document.curriculo.email.value ) ) {
				bSubmit = false;
				sAlert = "Por favor, preencha o campo 'Email' correctamente.";
			} else {
				if( document.curriculo.telefone.value == "" ) {
					bSubmit = false;
					sAlert = "Por favor, preencha o campo 'Telefone'.";
				} else {
					if( document.curriculo.telemovel.value == "" ) {
						bSubmit = false;
						sAlert = "Por favor, preencha o campo 'Telemovel'.";
					} else {
						if( document.curriculo.morada.value == "" ) {
							bSubmit = false;
							sAlert = "Por favor, preencha o campo 'Morada'.";
						} else {
							if( document.curriculo.codpostal.value == "" ) {
								bSubmit = false;
								sAlert = "Por favor, preencha o campo 'Cód. Postal'.";
							} else {
								if( document.curriculo.experiencia.value == "" ) {
									bSubmit = false;
									sAlert = "Por favor, preencha o campo 'Experiência'.";
								} else {
									if( document.curriculo.obs.value == "" ) {
										bSubmit = false;
										sAlert = "Por favor, preencha o campo 'Observações'.";
									} else {
										if( document.curriculo.File1.value == "" ) {
											bSubmit = false;
											sAlert = "Por favor, preencha o campo 'CV'.";
										} else {
											if( iOportunidadeID_IN == 0 ) {
												if( document.curriculo.especialidadeid.value == 0 ) {
													bSubmit = false;
													sAlert = "Por favor, preencha o campo 'Especialidade'.";
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}

	if( bSubmit ) {
		document.curriculo.submit();
	} else {
		alert( sAlert );
	}

	return;	
}

// ------------------------------------------ //
// --- Função que valida um endereço mail --- //
// ------------------------------------------ //
function EmailIsOk( sEmail_IN ) {
	var sChr;
	var sEmail;
	var lEmail;
	var k, i;
	var med;
	var bResult = false;

	lEmail=sEmail_IN.length;

	for (i=2;i<=lEmail;i++) {
		sChr=sEmail_IN.substr(i, 1);
		if (sChr=="@") {
			k=i;
			break;
		}
	}

	for (i=k+3;i<=lEmail;i++) {
		sChr=sEmail_IN.substr(i, 1);
		if (sChr==".") {
			med=i+2;
			break;
		}
	}

	if (lEmail>med) {
		bResult =true;
	}

	return bResult;
	return;
}

// ----------------------------------------------- //
// --- Função que limpa o formulário currículo --- //
// ----------------------------------------------- //
function CleanCurriculo( iOportunidadeID_IN ) {
	document.curriculo.reset();
	return;	
}

// ---------------------------------------------- //
// ---- Função de aquisição do objecto layer ---- //
// ---------------------------------------------- //
// [oLayer_IN] - ID da layer a obter
// ---------------------------------------------- //
function IN_getLayer(oLayer_IN, doc) { //v1.0
	var i,tLayer;if(!doc) doc=document;
	if(!(tLayer=doc[oLayer_IN])&&!(doc.all)) tLayer=doc.getElementById(oLayer_IN);
	if(!tLayer&&!(tLayer=doc[oLayer_IN])&&doc.all) tLayer=doc.all[oLayer_IN];
	for(i=0;!tLayer&&doc.layers&&i<doc.layers.length;i++) tLayer=IN_getLayer(oLayer_IN,doc.layers[i].document);
	return tLayer;
}

// ---------------------------------------------- //
// - Função de controlo de visibilidade --------- //
// ------ de uma layer -------------------------- //
// ---------------------------------------------- //
// [oLayer] - ID da layer a ser alterada
// ---------------------------------------------- //
function IN_setVisibility(oLayer_IN,iLeft_IN,iTop_IN) { //v1.0
	var tableWidth=760;
	var tableHeight=0;
	var extraWidth=20;
	var extraHeight=4;

	var windowInnerWidth=(NS)?window.innerWidth:document.body.offsetWidth-extraWidth;
	var windowInnerHeight=(NS)?window.innerHeight:document.body.offsetHeight-extraHeight;

	oLayer=IN_getLayer(oLayer_IN);
	if(NS){
		if(oLayer.visibility=='visible'){
			oLayer.visibility='hidden';
		}else{
			oLayer.visibility='visible';
		}
		if((tableWidth!=0)&&(windowInnerWidth>=tableWidth)){
			oLayer.left=((windowInnerWidth-tableWidth)/2)+iLeft_IN;
		}else{
			oLayer.left=iLeft_IN;
		}
		if((tableHeight!=0)&&(windowInnerHeight>=tableHeight)){
			oLayer.top=((windowInnerHeight-tableHeight)/2)+iTop_IN;
		}else{
			oLayer.top=iTop_IN;
		}
	}else{
		if(oLayer.style.visibility=='visible'){
			oLayer.style.visibility='hidden';
		}else{
			oLayer.style.visibility='visible';
		}
		if((tableWidth!=0)&&(windowInnerWidth>=tableWidth)){
			oLayer.style.left=((windowInnerWidth-tableWidth)/2)+iLeft_IN;
		}else{
			oLayer.style.left=iLeft_IN;
		}
		if((tableHeight!=0)&&(windowInnerHeight>=tableHeight)){
			oLayer.style.top=((windowInnerHeight-tableHeight)/2)+iTop_IN;
		}else{
			oLayer.style.top=iTop_IN;
		}
	}

	return;
}

// ---------------------------------------------- //
// - Função que torna todas as layers dos menús - //
// - invisiveis									- //
// ---------------------------------------------- //
function IN_setInvisibility(oLayer_IN) { //v1.0
	oLayer1=IN_getLayer('menu1');
	oLayer2=IN_getLayer('menu2');
	oLayer3=IN_getLayer('menu3');
	oLayer4=IN_getLayer('menu4');
	oLayer5=IN_getLayer('menu5');
	oLayer6=IN_getLayer('menu6');
	oLayer7=IN_getLayer('submenu1');
	if(NS){
		if(oLayer_IN!='menu1'){
			oLayer1.visibility='hidden';
		}
		if(oLayer_IN!='menu2'){
			oLayer2.visibility='hidden';
		}
		if(oLayer_IN!='menu3'){
			oLayer3.visibility='hidden';
		}
		if(oLayer_IN!='menu4'){
			oLayer4.visibility='hidden';
		}
		if(oLayer_IN!='menu5'){
			oLayer5.visibility='hidden';
		}
		if(oLayer_IN!='menu6'){
			oLayer6.visibility='hidden';
		}
		if(oLayer_IN!='submenu1'){
			oLayer7.visibility='hidden';
		}
	}else{
		if(oLayer_IN!='menu1'){
			oLayer1.style.visibility='hidden';
		}
		if(oLayer_IN!='menu2'){
			oLayer2.style.visibility='hidden';
		}
		if(oLayer_IN!='menu3'){
			oLayer3.style.visibility='hidden';
		}
		if(oLayer_IN!='menu4'){
			oLayer4.style.visibility='hidden';
		}
		if(oLayer_IN!='menu5'){
			oLayer5.style.visibility='hidden';
		}
		if(oLayer_IN!='menu6'){
			oLayer6.style.visibility='hidden';
		}
		if(oLayer_IN!='submenu1'){
			oLayer7.style.visibility='hidden';
		}
	}

	return;
}

function IN_setVisibility_old(oLayer_IN) { //v1.0
	oLayer=IN_getLayer(oLayer_IN);
	if(NS){
		if(oLayer.visibility=='visible'){
			oLayer.visibility='hidden';
		}else{
			oLayer.visibility='visible';
		}
	}else{
		if(oLayer.style.visibility=='visible'){
			oLayer.style.visibility='hidden';
		}else{
			oLayer.style.visibility='visible';
		}
	}

	return;
}

function NewWindow( sName, sUrl, iWidth, iHeight, iResize, iScrollbar ) {
	var iLeft;
	var iTop;

	if ( screen.width > iWidth ) {
		iLeft = parseInt( ( screen.width - iWidth ) / 2 );
	} else {
		iLeft = 0
	}

	if ( screen.height > iHeight ) {
		iTop = parseInt( ( screen.height - iHeight ) / 2 );
	} else {
		iTop = 0
	}

	window.open( sUrl, sName, 'width=' + iWidth + ',height=' + iHeight + ',resizable=' + iResize + ',scrollbars=' + iScrollbar + ',left=' + iLeft + ',top=' + iTop );
}

function WindowImgResize( sPathImg_IN, sNameImg_IN ) {
	if( sPathImg_IN = "" ) {
		window.close();
	} else {
		var oIm = document.all( sNameImg_IN );
		var iWidth;
		var iHeight;
		
		if( iWidth > 800 ) {
			iWidth = 800;
		} else {
			iWidth = oIm.width + 28 + 20;
		}

		if( iHeight > 600 ) {
			iHeight = 600;
		} else {
			iHeight = oIm.height + 31 + 20;
		}

		window.resizeTo( iWidth, iHeight );
		window.moveTo( ( ( screen.width - iWidth ) / 2 ), ( ( screen.height - iHeight ) / 2 ) );
	}
}