var httpRequestObj;


function CacheImagens() {
	cacheArr = new Array(
					"../imagens/login-empresas-hover.gif"
					);
	imageCache = new Array();
	
	for (a = 0; a < cacheArr.length; a++) {
		imageCache[a] = new Image();
		imageCache[a].src = cacheArr[a];
	}
}

CacheImagens();


function Janela(e, w, h, p) {
	try {
		param = "";
		if (p != null)
			param = ", " + p;

		centrox = (screen.width / 2) - (w / 2);
		centroy = (screen.height / 2) - (h / 2);

		if (navigator.appName.indexOf("Opera") != -1) {
			test = (screen.height - (screen.height * 0.25));
			centroy = (test / 2) - (h / 2);
		}
		if (navigator.appName.indexOf("Explorer") != -1) {
			w -= 20;
		}

		window.open(e.href, '', "left=" + centrox + ", top=" + centroy + ", width=" + w + ", height=" + h + "" + param);

		if (window.event)
			event.returnValue = false;
	}
	catch(e) {
		if (window.event)
			event.returnValue = true;
		
	}
	return false;
}

function Janela2(e, w, h, p) {
	try {
		param = "";
		if (p != null)
			param = ", " + p;

		centrox = (screen.width / 2) - (w / 2);
		centroy = (screen.height / 2) - (h / 2);

		if (navigator.appName.indexOf("Opera") != -1) {
			test = (screen.height - (screen.height * 0.25));
			centroy = (test / 2) - (h / 2);
		}
		if (navigator.appName.indexOf("Explorer") != -1) {
			w -= 20;
		}

		window.open(e, '', "left=" + centrox + ", top=" + centroy + ", width=" + w + ", height=" + h + "" + param);

		if (window.event)
			event.returnValue = false;
	}
	catch(e) {
		if (window.event)
			event.returnValue = true;
		
	}
	return false;
}

function ValidarFormulario(Form) {

	Campos = Form.getElementsByTagName("select");
	for (a = 0; a < Campos.length; a++) {
		if (Campos[a].getAttribute("obrigatorio") != null && Campos[a].options[Campos[a].selectedIndex].value.length == "") {
			alert("Campo de preenchimento obrigatório.");
			Campos[a].focus();
			return false;
		}
	}

	Campos = Form.getElementsByTagName("input");
	for (a = 0; a < Campos.length; a++) {
		if (Campos[a].type == "text" && Campos[a].getAttribute("obrigatorio") != null && Campos[a].value.length == 0) {
			alert("Campo de preenchimento obrigatório.");
			Campos[a].focus();
			return false;
		}
	}
	
	
	Campos = Form.getElementsByTagName("textarea");
	for (a = 0; a < Campos.length; a++) {
		if (Campos[a].getAttribute("obrigatorio") != null && Campos[a].value.length == 0) {
			alert("Campo de preenchimento obrigatório.");
			Campos[a].focus();
			return false;
		}
	}
	
	return true;
}


/* Oculta texto do campo */

function campoFocusValueClass(obj) {

	obj.onfocus = function() {

		if (this.campoFocusValor == null){
			this.campoFocusValor = this.value;
			this.value = "";
		}
		else {
			if (this.value == this.campoFocusValor)
				this.value = "";
		}
	}
	
	obj.onblur = function() {
		if (this.value == ""){
			this.value = this.campoFocusValor;
		}	
	}

}



function fsize(size,unit,id){
	var vfontsize = document.getElementById(id);
	if(vfontsize){
		vfontsize.style.fontSize = size + unit;
	}
}


function loginEmpresasHome(img) {
	imagem = document.getElementById("imagemLoginEmpresas");
	imagem.src = img;
}

function Enderecos(obj) {
	url = obj.options[obj.selectedIndex].value;

	if (url != "") {
		document.location.href = url;
	}
}



/* Oculta texto do campo */

function campoFocusValueClass(obj) {
	obj.onfocus = function() {

		if (this.campoFocusValor == null){
			this.campoFocusValor = this.value;
			this.value = "";
		}
		else {
			if (this.value == this.campoFocusValor)
				this.value = "";
		}
	}
	
	obj.onblur = function() {
		if (this.value == ""){
			this.value = this.campoFocusValor;
		}	
	}
}



function IsNumeric(sText) {
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;

	for (i = 0; i < sText.length && IsNumber == true; i++) { 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) {
			IsNumber = false;
		}
	}
	return IsNumber;

}

function senhasAlterarValidarCampo() {

	var campoExtrato = document.getElementById("campoReferenciaConsulta");
	var dvListagemSenhasItens = document.getElementById("dvListagemSenhasItens");
	
	if (campoExtrato.value.length < 7)
	{
		alert("Controle inválido.");
		campoExtrato.focus();
		return false;
	}

	if (dvListagemSenhasItens != null) {
		dvListagemSenhasItens.style.display = "none";
	}

	document.getElementById("dvAguarde").style.display = "block";

	



	return true;

}

function extratoValidarCampo() {

	campoExtrato = document.getElementById("campoReferenciaConsulta");
	
	if (campoExtrato.value.length < 7)
	{
		alert("Formato de data inválida");
		campoExtrato.focus();
		return false;
	}

	document.getElementById('dvAguarde').style.display = 'block';

	return true;

}

function dirfValidarCampo() {

	campoDirf = document.getElementById("campoReferenciaConsulta");
	
	if (campoDirf.value.length < 4)
	{
		alert("Formato de ano inválido");
		campoDirf.focus();
		return false;
	}

	document.getElementById('dvAguarde').style.display = 'block';

	return true;

}



function enviarFormularioWebmail() {

	campoEmail = document.getElementById("WebmailCampoEmail");
	campoSenha = document.getElementById("WebmailCampoSenha");

	if (campoEmail.value == "e-mail") {
		campoEmail.focus();
		alert("É necessário informar o seu nome de usuário.");
		return false;
	}
	if (campoSenha.value == "senha") {
		campoSenha.focus();
		alert("É necessário informar a sua senha.");
		return false;
	}

	if (campoEmail.value.indexOf("@uniodontosc.com.br") == -1) {
		campoEmail.value += "@uniodontosc.com.br";
	}

	document.getElementById("formularioWebmail").submit();
	
	campoEmail.value = "e-mail";
	campoSenha.value = "senha";

	return false;

}


function contatoEnderecos() {

	var ulEscritorios = document.getElementById("ulEscritorios");
	var dvCTCidades = document.getElementById("dvCTCidades");
	var dvFormularioEmail = document.getElementById("dvFormularioEmail");

	ulEscritorios.style.display = "block";
	dvCTCidades.className = "Cidades_Open";


	if (dvFormularioEmail != null)
	{
		dvFormularioEmail.style.display = "none";
	}




}


function senhaCooperadoValidar() {

	campoSenha = document.getElementById("campoSenha");
	campoSenha2 = document.getElementById("campoSenha2");
	campoSenha3 = document.getElementById("campoSenha3");
	
	if (campoSenha.value.length == 0)
	{
		alert("O campo 'Senha Atual' deve ser preenchido.");
		campoSenha.focus();
		return false;
	}

	if (campoSenha2.value.length == 0)
	{
		alert("O campo 'Nova Senha' deve ser preenchido.");
		campoSenha2.focus();
		return false;
	}

	if (campoSenha3.value.length == 0)
	{
		alert("Você deve repetir a sua nova senha.");
		campoSenha3.focus();
		return false;
	}

	if (campoSenha2.value != campoSenha3.value)
	{
		alert("Você deve repetir a senha corretamente.");
		campoSenha3.focus();
		return false;
	}

	return true;

}



function getPosition(element) {
	var left = 0;
	var top = 0;
	if(element.offsetParent) {
		while(element) {
			left += element.offsetLeft;
			top += element.offsetTop;
			element = element.offsetParent;
		}
	}
	return {offsetLeft: left, offsetTop: top};
}
function carregaGlosa(idLink, idGlosa, total) {

	tr = document.getElementById(idLink);

	posicaoLink = getPosition(tr);

	tr.style.cursor = "hand";

	for (a = 0; a < total; a++) {

		if (document.getElementById("dvGlosaFlutuante" + a) != null)
			document.getElementById("dvGlosaFlutuante" + a).style.display = "none";

	}

	topo = posicaoLink.offsetTop - 22;

	document.getElementById(idGlosa).style.top = topo + "px";
	document.getElementById(idGlosa).style.display = "block";

}

function carregaGlosaPericia(idLink, idGlosa, total) {

	tr = document.getElementById(idLink);

	posicaoLink = getPosition(tr);

	tr.style.cursor = "hand";

	for (a = 0; a < total; a++) {

		if (document.getElementById("dvGlosaFlutuante" + a) != null)
			document.getElementById("dvGlosaFlutuante" + a).style.display = "none";

	}

	//alert(posicaoLink.offsetTop);
	topo = posicaoLink.offsetTop;
	

	document.getElementById(idGlosa).style.left = "194px";
	document.getElementById(idGlosa).style.top = "284px";
	//document.getElementById(idGlosa).style.top = topo + "px";
	document.getElementById(idGlosa).style.display = "block";

}

function ocultaGlosas(total) {
	for (a = 0; a < total; a++) {
		if (document.getElementById("dvGlosaFlutuante" + a) != null)
			document.getElementById("dvGlosaFlutuante" + a).style.display = "none";

	}
}