/**
 * @author cpid
 */
function getPageSize(){ //Função que retorna o tamanho da área do navegador.
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else 
		if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		}
		else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
	
	var windowWidth, windowHeight;
	
	if (self.innerHeight) { // all except Explorer
		if (document.documentElement.clientWidth) {
			windowWidth = document.documentElement.clientWidth;
		}
		else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	}
	else 
		if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		}
		else 
			if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}
	
	// for small pages with total height less then height of the viewport
	if (yScroll < windowHeight) {
		pageHeight = windowHeight;
	}
	else {
		pageHeight = yScroll;
	}
	
	// for small pages with total width less then width of the viewport
	if (xScroll < windowWidth) {
		pageWidth = xScroll;
	}
	else {
		pageWidth = windowWidth;
	}
	pageWidth = pageWidth;
	return [pageWidth, pageHeight];
	
}

//Função que exibe o overlay, tampando todo o fundo da página.
function bodyOverlay() {
	var objBody = document.getElementsByTagName('body').item(0);
	var arrayPageSize = getPageSize();
	var bodyOverlay = document.createElement("div");
	
	bodyOverlay.setAttribute('id','bodyOverlay');
	bodyOverlay.style.width = arrayPageSize[0] + 'px';
	bodyOverlay.style.height = arrayPageSize[1] + 'px'; // fundo com o tamanho total da página.
	if (!document.getElementById('bodyOverlay')) {
		objBody.insertBefore(bodyOverlay, objBody.firstChild);
		$('bodyOverlay').appear({duration: 0.5, from: 0.0, to: 0.5});
	}
}

//Função que remove o overlay da tela.
function removerOverlay() {
	var bodyOverlay = document.getElementById('bodyOverlay');
	var caixaDivMensagem = document.getElementById("caixaDivMensagem");
	var sombracaixaDivMensagem = document.getElementById("sombracaixaDivMensagem");
	
	if (bodyOverlay) {
		$('bodyOverlay').fade({duration: 0.5});
		$('caixaDivMensagem').fade({duration: 0.5});
		$('sombracaixaDivMensagem').fade({duration: 0.5});
		
		/*caixaDivMensagem.parentNode.removeChild(caixaDivMensagem);
		caixaDivMensagem.close();
		sombracaixaDivMensagem.parentNode.removeChild(sombracaixaDivMensagem);*/
		//bodyOverlay.parentNode.removeChild(bodyOverlay);
	}
}

//Função que adiciona mais um campo para o Licenças/Afastamentos, etc.
var qtdInput = 0;
function adicionaCampo()
{
	//Declarando as inputs necessárias.
	var input1 = document.createElement("input");
	var input2 = document.createElement("input");
	var input3 = document.createElement("input");
	var input4 = document.createElement("input");
	
	input1.setAttribute("name","registro_"+qtdInput);
	input1.setAttribute("size","5");
	input2.setAttribute("name","nome_"+qtdInput);
	input2.setAttribute("size","50");
	input3.setAttribute("name","cargo_"+qtdInput);
	input4.setAttribute("name","motivo_"+qtdInput);
	//classe do css das inputs geradas
	input1.className = "inputDinamica";
	input2.className = "inputDinamica";
	input3.className = "inputDinamica";
	input4.className = "inputDinamica";
	
	//Obtendo o nome do elemento (div), onde os campos irão entrar.
	var licenca = document.getElementById("qtdLicenca");
	
	//Adicionando os campos criados à div selecionada.
	licenca.appendChild(input1);
	licenca.appendChild(input2);
	licenca.appendChild(input3);
	licenca.appendChild(input4);
	
	qtdInput++;
	//passando a quantidade de campos da licença p/ o input hidden.
	document.formulario.qtdLicenca.value = qtdInput;
}

function adicionaCampoVisualizar(rf, nome, cargo, motivo, codigoLicenca)
{
	//Declarando as inputs necessárias.
	var input1 = document.createElement("input");
	var input2 = document.createElement("input");
	var input3 = document.createElement("input");
	var input4 = document.createElement("input");
	var input5 = document.createElement("input");
	
	input1.setAttribute("name","registro_"+qtdInput);
	input1.setAttribute("value",rf);
	input1.setAttribute("size","5");
	input2.setAttribute("name","nome_"+qtdInput);
	input2.setAttribute("value",nome);
	input2.setAttribute("size","50");
	input3.setAttribute("name","cargo_"+qtdInput);
	input3.setAttribute("value",cargo);
	input4.setAttribute("name","motivo_"+qtdInput);
	input4.setAttribute("value",motivo);
	input5.setAttribute("type","hidden");
	input5.setAttribute("name","update_"+qtdInput);
	input5.setAttribute("value",codigoLicenca)
	//classe do css das inputs geradas
	input1.className = "inputDinamica";
	input2.className = "inputDinamica";
	input3.className = "inputDinamica";
	input4.className = "inputDinamica";
	
	//Obtendo o nome do elemento (div), onde os campos irão entrar.
	var licenca = document.getElementById("qtdLicenca");
	
	//Adicionando os campos criados à div selecionada.
	licenca.appendChild(input1);
	licenca.appendChild(input2);
	licenca.appendChild(input3);
	licenca.appendChild(input4);
	licenca.appendChild(input5);
	
	qtdInput++;
	//passando a quantidade de campos da licença p/ o input hidden.
	document.formulario.qtdLicenca.value = qtdInput;
}

