function pngAlpha(objImagem,strW,strH) {
	if (document.all) {
		document.write("<div class=\"brwPng\" style=\"position:absolute; width:"+strW+"; height:"+strH+"; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+objImagem+"');\">&nbsp;</div>");
	}
	else {
		document.write("<div class=\"brwPng\" style=\"position:absolute;\"><img src='"+objImagem+"'></div>");
	}
}
function limparForm(strForm) {
	eval("document." + strForm + ".reset()");
}
function Esconde(){
document.getElementById('popHome').style.visibility="hidden";
}
function inputOn(objInput, strCampo) {
	if (objInput.value == strCampo) {
		if ( (objInput.name == 'senha_conveniado') || (objInput.name == 'senha_beneficiario') ) {
			objInput.style.background = '#FFF';
		}
		objInput.value = '';
	}
}

function inputOff(objInput, strCampo) {
	if (objInput.value == '') {
		if ( (objInput.name == 'senha_conveniado') || (objInput.name == 'senha_beneficiario') ) {
			objInput.style.background = 'url(../../img/bgr_inputsenha.jpg) no-repeat';
			objInput.value = '';
		}
		else {
			objInput.value = strCampo;
		}
	}
}

function keyPress(e){
	var keyNum;
	if(window.event)
	keyNum = window.event.keyCode;
	else if(e.keyCode)
	keyNum = e.keyCode;
	if ( (keyNum == 32) ||
		 (keyNum == 33) ||
		 (keyNum == 34) ||
		 (keyNum == 35) ||
		 (keyNum == 36) ||
		 (keyNum == undefined) ) {
		return false;
	}
}

function alertar(strTit,strTxt,strBotoesPadrao) {
	objDivAlert = document.getElementById('divAlert');
	objDivAlert.innerHTML = '<div id="divAlertTit">'+strTit+'</div>';
	
	intTop = (screen.availHeight-550)/2;
	intLeft = (document.body.offsetWidth-236)/2;
	if (document.documentElement.scrollHeight > screen.availHeight) { intTop = intTop+(document.documentElement.scrollTop); }
	paginaRolar = document.documentElement.scrollTop;
	
	objDivAlert.style.top = intTop + "px";
	objDivAlert.style.left = intLeft + "px";
	
	objDivAlert.style.visibility = 'visible';
	document.onkeypress = keyPress;
	
	alertarTexto(strTxt);
	alertarBotoes(strBotoesPadrao);
	window.scrollTo(0,paginaRolar);
}

function alertarTexto(strTxt) {
	objDivAlert = document.getElementById('divAlert');
	objDivAlert.innerHTML += '<div id="divAlertTexto">' + strTxt + '</div>';
}

function alertarBotoes(strBotoesPadrao) {

	arrBotoes = strBotoesPadrao.split(";");
	
	for (i=0; i<arrBotoes.length; i++) {
		arrAcao = arrBotoes[i].split(",");
		verificarBotoes(arrAcao[0],arrAcao[1]);
		arrAcao = '';
	}
	
	objDivAlert = document.getElementById('divAlert');
	objDivAlert.innerHTML += '<div id="divAlertBotoes">' + strBotoes + '</div>';
	strBotoes = '';
}

function verificarBotoes(strBotaoNome,strBotaoAcao) {
	
	switch (strBotaoNome) {
		case "Sim":
			strBotoes += '<img name="btn_' + strBotaoNome + '" src="../../img/btn_sim.gif" onclick="botaoClick(\'' + strBotaoNome + '\',\'' + strBotaoAcao + '\')">';
			break;
		case "Nao":
			strBotoes += '<img name="btn_' + strBotaoNome + '" src="../../img/btn_nao.gif" onclick="botaoClick(\'' + strBotaoNome + '\',\'' + strBotaoAcao + '\')">';
			break;
		case "Ok":
			strBotoes += '<img name="btn_' + strBotaoNome + '" src="../../img/btn_ok.gif" onclick="botaoClick(\'' + strBotaoNome + '\',\'' + strBotaoAcao + '\')">';
			break;
		case "Cancelar":
			strBotoes += '<img name="btn_' + strBotaoNome + '" src="../../img/btn_cancelar.gif" onclick="botaoClick(\'' + strBotaoNome + '\',\'' + strBotaoAcao + '\')">';
			break;
		default:;
	}
	
}

function botaoClick(strBotaoNome,strBotaoAcao) {

	switch (strBotaoNome) {
		case "Sim":
			location.replace(strBotaoAcao);
			break;
		case "Nao":
			alertarFechar();
			break;
		case "Ok":
			alertarFechar();
			break;
		case "Cancelar":
			alertarFechar();
			break;
		default:;
	}
	
}


function alertarFechar() {
	objDivAlert = document.getElementById('divAlert');
	objDivAlert.style.visibility = 'hidden';
	document.onkeypress = '';
}

function validarForm(strForm,strRetorno,strCampos,strTitErro,strFuncao) {
	
	strErro = '';
	strErroNull = '';
	strFormulario = '';

	strFormulario = document.getElementById(strForm);
	arrCampos = strCampos.split(';');
	for (i=0; i<arrCampos.length; i++) {
		arrTipo = arrCampos[i].split(',');
		verificar(strFormulario,arrTipo[0],arrTipo[1]);
	}

	if (strErro == '') {
		eval(strFuncao);
		//eval("document."+strForm+".submit()");
	}
	else {
		alertar(strTitErro,'Preencha corretamente os campos marcados em vermelho.<br/>' + strErroNull,'Ok,false');
	}
}

function verificar(strFormulario,strCampo,strTipo) {

	objCampo = document.getElementById(strCampo);

	switch (strTipo) {
		case 'txt': {
			MostraErro(strCampo, '', (objCampo.value == '') || (objCampo.value == 'nome'), strTipo);
			break;
		}
		
		case 'num': {
			MostraErro(strCampo, '', !ApenasNumeros(objCampo.value), strTipo);
			break;
		}
		
		case 'ema': {
			MostraErro(strCampo, '', !EmailValido(objCampo.value), strTipo);
			break;
		}
		
		case 'null': {
			MostraErro(strCampo, '', !RadioValido(strCampo), strTipo);
			break;
		}
		
		default: break;
	}
	
}

function RadioValido(strRadio) {
	for (iRadio=1; iRadio<6; iRadio++) {
		objRadio = document.getElementById(strRadio+iRadio);
		if (objRadio.checked == true) {
			return true;
		}
	}
	strErroNull = 'Escolha uma alternativa';
	return false;
}

function ApenasNumeros(strNumero) {
	objRegExp = new RegExp("^[0-9]{1,}$");
	return objRegExp.test(strNumero);
}

function EmailValido(objEmail) {
	if (objEmail.indexOf("@") == -1 ||
		objEmail.indexOf(".") == -1 ||
		objEmail.indexOf(" ") != -1 ||
		objEmail.length < 6)
	{
		return false;
	}
	else {
		return true;
	}
}

function MostraErro(strObjID, strMensagem, blnErro, strTipo) {
	
	strBordaOn = '1px solid #C00';
	strBackgroundOn = '#FDFDFD';

	strBordaOff = '1px solid #85A1BC';
	strBackgroundOff = '#FFF';

	objCampo   = document.getElementById(strObjID);

	if (blnErro == true) {
		if (strTipo != 'null') {
			objCampo.style.border     = strBordaOn;
			objCampo.style.background = strBackgroundOn;
		}
		strErro = true;
	}
	else {
		if (strTipo != 'null') {
			objCampo.style.border      = strBordaOff;
			objCampo.style.background  = strBackgroundOff;
		}
	}
}

// Altera o tamanho da fonte utilizando-se das classes do CSS.
// Cada tamanho deverá ter uma classe no CSS, específico para a fonte.
function sizeFont (nivel, elem)
{
  document.getElementById(elem).className = "nivel"+nivel;
}

// Altera o tamanho da fonte até um determinado limite.
// Não é necessário CSS para este script funcionar.
function sizeFont2 (elem, acao)
{
  // tamanho inicial da fonte (em px)
  var tamInic = 11;
  
  // Tamanho mínimo da fonte (em px)
  var tamMin = 13;
  
  // Tamanho máximo da fonte (em px)
 // var tamMax = 14;

  // Pega o tamanho da fonte. Se não foi setada ainda (primeira vez
  // que a função é executada) terá como tamanho padrão 'tamInic'.
  if (document.getElementById(elem).style.fontSize == "") 
	var tamFonte = tamInic;
  else
	var tamFonte = parseInt(document.getElementById(elem).style.fontSize);
  switch (acao)
  {
	// Aumenta o tamanho, enquanto foi menor que 'tamMax'
	case '+':
	  if (tamFonte < tamMax)
		document.getElementById(elem).style.fontSize = (tamFonte + 2) + "px";
	break;
	
	// Diminui o tamanbo, enquanto for maior que 'tamMin'
	case '-':
	  if (tamFonte > tamMin)
		document.getElementById(elem).style.fontSize = (tamFonte - 2) + "px";
	break;
  }
}

function abreresp(name) {
	if (name.style.display == 'block') {
		name.style.display = 'none';
	}
	else {
		name.style.display = 'block';
	}
}

function abreDisc(strDivId,objDivPrincipal) {
	objDiv = document.getElementById(strDivId);
	if (objDiv.style.display == 'block') {
		objDivPrincipal.className = 'disListPrincipal';
		objDiv.style.display = 'none';
	}
	else {
		objDivPrincipal.className = 'disListPrincipalOn';
		objDiv.style.display = 'block';
	}
}

function mostraCampos (objTipo) {
	switch (objTipo) {
		default:
			document.getElementById("planoConveniado").style.display   = 'none';
			document.getElementById("planoBeneficiario").style.display = 'none';
		break;

		case "cb": 
			document.getElementById("planoBeneficiario").style.display = 'block';
			document.getElementById("planoConveniado").style.display   = 'none';
		break;

		case "cc": 
			document.getElementById("planoConveniado").style.display   = 'block';
			document.getElementById("planoBeneficiario").style.display = 'none';
		break;
	}
}

function esqueciSenha (objTipo) {
	switch (objTipo) {
		default:
			document.getElementById("senhaConveniado").style.display   = 'none';
			document.getElementById("senhaBeneficiario").style.display = 'none';
			document.getElementById("obsEmail").style.display          = 'none';
		case "cb": 
			document.getElementById("senhaBeneficiario").style.display = 'block';
			document.getElementById("senhaConveniado").style.display   = 'none';
			document.getElementById("obsEmail").style.display          = 'block';
		break;

		case "cc": 
			document.getElementById("senhaConveniado").style.display   = 'block';
			document.getElementById("senhaBeneficiario").style.display = 'none';
			document.getElementById("obsEmail").style.display          = 'block';
		break;
	}
}

function copiaLayer ( objOrigem, objDestino ) {
	document.getElementById(objDestino).innerHTML = document.getElementById(objOrigem).innerHTML;
}

function setCookie(name, value, expires, path, domain, secure) {
        var curCookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
        document.cookie = curCookie;
}

function getCookie(name) {
       var dc = document.cookie;
       var prefix = name + "=";
       var begin = dc.indexOf("; " + prefix);
       if (begin == -1) {
       begin = dc.indexOf(prefix);
       if (begin != 0) return null;
       } else
       begin += 2;
       var end = document.cookie.indexOf(";", begin);
       if (end == -1)
       end = dc.length;
       return unescape(dc.substring(begin + prefix.length, end));
}
