//Rodrigo Chiarato
//Modifica altura do frame de ouvidoria para 1019px e outros tipos de assunto para 819px
function AjustaIFrameOuvidoria(obj)
{
    //encontrei 3 nomes para esse frame
	FrameOVD = parent.document.getElementById('FALE CONOSCO - SUA EMPRESA');
	if(FrameOVD==null)
		FrameOVD = parent.document.getElementById('links');
	if(FrameOVD==null)
		FrameOVD = parent.document.getElementById('Faleconosco');
	if(FrameOVD==null)
		FrameOVD = parent.document.getElementById('Fale Conosco');
	if(FrameOVD==null)
		FrameOVD = parent.document.getElementById('Faleconoscounicard');
	if(FrameOVD==null)
		FrameOVD = parent.document.getElementById('Fale Conosco Unicard');
	
	//configura altura do frame
	if(FrameOVD!=null)
	{
		if (obj.selectedIndex==7) //Ouvidoria
		   FrameOVD.height = 1019; //parseInt(parent.document.getElementById('links').height) + 289;
		else
		   FrameOVD.height = 819; 
	}   
}
	
function valida()
{	
    var erro='';
    
    if (document.frmFc.radTipo[0]==null || document.frmFc.radTipo[0].checked==true)//correntista
    {
        var blTp = true;//tudo preenchido?
        if(document.frmFc.numAgencia.value=='')
        {
            erro += 'Preencha agência|'; 
            blTp = false;
        }
        if(document.frmFc.numConta.value=='')
        {
            erro += 'Preencha Conta|';
            blTp = false;
        }
        if(document.frmFc.numDigitoConta.value=='')
        {
            erro += 'Preencha Dv Conta|';
            blTp = false;
        }
        if(!isCC(document.frmFc.numAgencia.value,document.frmFc.numConta.value,document.frmFc.numDigitoConta.value) && blTp)
        {
            erro += 'Agência e Conta|';
        }
    }
    else//não correntista
    {
        if (isVisible('cNCor'))//PF
        {
        	//if(document.frmFc.numCPFC.type != 'hidden') //utilizado
        	//{
            if((document.frmFc.numCPFC.value == '') || (document.frmFc.numCPFD.value == ''))
            {
                erro += 'Preencha o campo CPF|';
            }
            else
            {
                if(!isCPF(document.frmFc.numCPFC.value+document.frmFc.numCPFD.value))
                {
                    erro += 'CPF inválido|';
                }
            }
        }
        if (isVisible('cNCor2'))//PJ
        {
            if((document.frmFc.numCNPJC.value == '') || (document.frmFc.numCNPJD.value == ''))
            {
                erro += 'Preencha o campo CNPJ|';
            }
            else
            {
                if(!isCNPJ(document.frmFc.numCNPJC.value+document.frmFc.numCNPJD.value))
                {
                    erro += 'CNPJ inválido|';
                }
            }
        }
    }//fim corr ncorr
/*
	if (document.frmFc.strNome.value=='')
	{
		erro += 'Informe seu nome|';
	}  
	*/   
	if (document.frmFc.emlEmail.value=='')
	{
		erro += 'Informe seu e-mail|';
	}
	else
	{ 
	    if(!isEmail(document.frmFc.emlEmail.value))
	    {
	        erro += 'E-mail inválido|';
	    }
	}	
    if (document.frmFc.selTipoEmail.value=='0')
	{
		erro += 'Selecione o tipo de e-mail|';
	} 	
	if (document.frmFc.selAssunto.value=='0')
	{
		erro += 'Selecione o assunto|';
	}
	
	var objOuv = new getObj('tblOuvidoria');		
	if (objOuv.style.display == '')
	{
		erro += validaProtocolo();		
		if ((document.frmFc.nrProtocolo.value != '') && (erro == ''))
		{
			erro += ValidaElegibilidade(document.frmFc.nrProtocolo.value);
		}
	}	
	
	var objMsg = new getObj('trTxMensagem');
	if (objMsg.style.display == '')
	{
		if (document.frmFc.strMensagem.value=='')
		{
			erro += 'Escreva sua Mensagem|';
		}		
	}

	if (erro != '')
	{
		var strURL = window.location.href;
		var intIndex = strURL.indexOf('_pvt');
		if (intIndex != -1)
		{
			MostraErros('lyrErr', erro, true);
			return false;
		}
		else
		{
			MostraErros('lyrErr', erro, false);
			return false;
		}	    
	}
	
	if (document.frmFc.fgProtocolo.value == '1')
	{		
		shMensagem(true);
		document.frmFc.fgProtocolo.value = ''	
		document.frmFc.nrProtocolo.disabled = true;
		resizeIframe('links');
		return false;
	}
	else
	{
		document.frmFc.nrProtocolo.disabled = false;
		resizeIframe('links');
	}
	
	return true;
}

function validaUnicard()
{	
    var erro='';   
	if (document.frmFc.txtAssunto.value=='')
	{
		erro += 'Preencha o assunto|';
	}     
    if (document.frmFc.selTipoEmail.value=='0')
	{
		erro += 'Selecione o tipo de e-mail|';
	} 	    	
	if (document.frmFc.strNome.value=='')
	{
		erro += 'Informe seu nome|';
	}     
	if (document.frmFc.emlEmail.value=='')
	{
		erro += 'Informe seu e-mail|';
	}
	else
	{ 
	    if(!isEmail(document.frmFc.emlEmail.value))
	    {
	        erro += 'E-mail inválido|';
	    }
	}		
    if (document.getElementById('numCPFC') != null && isVisible('cNCor'))//PF
    {		
        if((document.frmFc.numCPFC.value == '') || (document.frmFc.numCPFD.value == ''))
        {
            erro += 'Preencha o campo CPF|';            
        }
        else
        {
            if(!isCPF(document.frmFc.numCPFC.value+document.frmFc.numCPFD.value))
            {
                erro += 'CPF inválido|';
            }
        }
    }    
    if (document.getElementById('numCNPJC') != null)//PJ
    {
        if((document.frmFc.numCNPJC.value == '') || (document.frmFc.numCNPJD.value == ''))
        {
            erro += 'Preencha o campo CNPJ|';
        }
        else
        {
            if(!isCNPJ(document.frmFc.numCNPJC.value+document.frmFc.numCNPJD.value))
            {
                erro += 'CNPJ inválido|';
            }
        }
    }
    
	var objOuv = new getObj('tblOuvidoria');		
	if (objOuv.style.display == '')
	{		
		erro += validaProtocolo();				
		if ((document.frmFc.nrProtocolo.value != '') && (erro == ''))
		{
			erro += ValidaElegibilidadeUnicard(document.frmFc.nrProtocolo.value);
		}			
	}	    
      
	var objMsg = new getObj('trTxMensagem');
	if (objMsg.style.display == '')
	{
		if (document.frmFc.strMensagem.value=='')
		{
			erro += 'Escreva sua Mensagem|';
		}		
	}	
	if (erro != '')
	{
	    MostraErrosOVD('lyrErr', erro, false);	    
	    return false;
	}
	
	if (document.frmFc.fgProtocolo.value == '1')
	{		
		shMensagem(true);
		document.frmFc.fgProtocolo.value = '';
		document.frmFc.nrProtocolo.disabled = true;
		resizeIframe('links');
		return false;
	}
	else
	{
		document.frmFc.nrProtocolo.disabled = false;
		resizeIframe('links');
	}	
	
	return true;
}

function validarCodigoImagem()
{
	var blnReturn;
	blnReturn = false;
	switch(document.frmFc.objImgCod.value)
	{
		case '01':
			if(document.frmFc.txtCodigo.value.toLowerCase() == 'brlm') blnReturn = true;
			break;
		case '02':
			if(document.frmFc.txtCodigo.value.toLowerCase() == 'c6hm') blnReturn = true;
			break;
		case '03':
			if(document.frmFc.txtCodigo.value.toLowerCase() == 'cxjf') blnReturn = true;
			break;
		case '04':
			if(document.frmFc.txtCodigo.value.toLowerCase() == 'd9df') blnReturn = true;
			break;
		case '05':
			if(document.frmFc.txtCodigo.value.toLowerCase() == 'e8x6') blnReturn = true;
			break;
		case '06':
			if(document.frmFc.txtCodigo.value.toLowerCase() == 'jb7f') blnReturn = true;
			break;
		case '07':
			if(document.frmFc.txtCodigo.value.toLowerCase() == 'p6wi') blnReturn = true;
			break;
		case '08':
			if(document.frmFc.txtCodigo.value.toLowerCase() == 'sfdc') blnReturn = true;
			break;
		case '09':
			if(document.frmFc.txtCodigo.value.toLowerCase() == 'vhdg') blnReturn = true;
			break;
		case '10':
			if(document.frmFc.txtCodigo.value.toLowerCase() == 'wh4c') blnReturn = true;
			break;
		case '11':
			if(document.frmFc.txtCodigo.value.toLowerCase() == 'wnff') blnReturn = true;
			break;
		case '12':
			if(document.frmFc.txtCodigo.value.toLowerCase() == 'xubg') blnReturn = true;
			break;			
	}	
	return blnReturn;
}

//verifica se o nr do protocolo eh valido, 7 digitos não começando com zero(0)
function validaProtocolo()
{
	var erro = '';
	if(document.frmFc.nrProtocolo.value == '')
	{
		erro += 'Preencha o campo Número do Protocolo.|';
	}
	
	if(document.frmFc.txtCodigo.value == '')
	{
		erro += 'Preencha o campo Código.|';		
	}	
	else
	{
		if (validarCodigoImagem() == false)
		{
			erro += 'Código Inválido.|';
		}
	}
	
	/*else
	{
		if(document.frmFc.nrProtocolo.value.substring(0,1)=='0' || document.frmFc.nrProtocolo.value.length != 7)
		{
			erro += 'Número de Protocolo Inválido.<br><br>' +
				'<img src="/ubb2007/images/formularios/faleConosco/alert.gif" width="35" height="31" align="left" hspace="10" />'+
				'Este número de processo não é válido. Por favor, informe o número correto ou <a href="/ubb2007/_exc/frm/faleOVD.asp?te=Reclamação" class="fcLink">clique aqui</a> para enviar seu e-mail.'+
				'<br><br>Se preferir contate a Ouvidoria do Conglomerado Unibanco pelo telefone XXXX-XXXXX ou 0800-XXXXXXX.'+
				'<br>Em dias úteis das 09h às 18h|';
		}
	}*/
	
	if (erro != '')
	{
	    //MostraErros('lyrErr', erro);
	    return erro;
	}
	else
	{
	    return '';
	}
}


function ValidaElegibilidade(nmProtocolo)
{
	// ********************************************************************************
	// ************** Validação de Protocolo (Elegibilidade) **************************
	// ********************************************************************************		
	var strURL = window.location.href;
	var intIndex = strURL.indexOf('?');
	if (intIndex != -1)
	{
		strURL = strURL.substring(0,intIndex);
	}			
	if (nmProtocolo.length != 7)
	{
		document.frmFc.action = strURL + '?status=5';
		document.frmFc.submit();
		
		//window.location = strURL + '?status=5';
		return false;
	}
	else
	{
		var strRetorno, MR_IAPJS_CDTRAN, MR_IAPJS_CDCANA, MR_IAPJS_IDENTEMP, MR_IAPJS_IDENTNEG, MR_IAPJS_NUMEPARM
		MR_IAPJS_CDTRAN = 'UM8N'
		MR_IAPJS_CDCANA = '11'
		MR_IAPJS_IDENTEMP = '1' //(1) Banco Unibanco
		MR_IAPJS_IDENTNEG = '6'
		MR_IAPJS_NUMEPARM = nmProtocolo
		//http://10.52.128.24		
		strRetorno = GetUrlOVD('/ajax/Elegibilidade/ValidaProtocolo.asp?MR_IAPJS_CDTRAN=' + MR_IAPJS_CDTRAN + '&MR_IAPJS_CDCANA=' + MR_IAPJS_CDCANA + '&MR_IAPJS_IDENTEMP=' + MR_IAPJS_IDENTEMP + '&MR_IAPJS_IDENTNEG=' + MR_IAPJS_IDENTNEG + '&MR_IAPJS_NUMEPARM=' + MR_IAPJS_NUMEPARM + '');
		strRetorno = strRetorno.split('|');		
		if (strRetorno.length == 2)
		{			
			var strStatus, strElegivel
			strStatus = strRetorno[0];
			strElegivel = strRetorno[1];				
			if (strStatus != '00')
			{				
				return 'Erro ao validar o Protocolo.|';
			}
			else
			{				
				if (strElegivel == 'N')
				{	
					document.frmFc.action = strURL + '?status=5';
					document.frmFc.submit();				
					//window.location = strURL + '?status=5';
					return false;
				}
			}
		}
		else
		{
			return 'Erro ao validar o Protocolo.|';
		}
		return '';
	}
	// ********************************************************************************
	// ********************************************************************************
	// ********************************************************************************
}


function ValidaElegibilidadeUnicard(nmProtocolo)
{
	// ********************************************************************************
	// ************** Validação de Protocolo (Elegibilidade) **************************
	// ********************************************************************************		
	var strURL = window.location.href;
	var intIndex = strURL.indexOf('?');
	if (intIndex != -1)
	{
		strURL = strURL.substring(0,intIndex);
	}			
	if ((nmProtocolo.length != 7) && (nmProtocolo.length != 9))
	{		
		document.frmFc.action = strURL + '?status=5';
		document.frmFc.submit();
		
		//window.location = strURL + '?status=5';
		return false;
	}
	else
	{
		var strRetorno, MR_IAPJS_CDTRAN, MR_IAPJS_CDCANA, MR_IAPJS_IDENTEMP, MR_IAPJS_IDENTNEG, MR_IAPJS_NUMEPARM
		MR_IAPJS_CDTRAN = 'UM8N'
		MR_IAPJS_CDCANA = '11'
		MR_IAPJS_IDENTEMP = '2' //(1) Banco Unicard
		MR_IAPJS_IDENTNEG = '6'
		MR_IAPJS_NUMEPARM = nmProtocolo
		//http://10.52.128.24		
		strRetorno = GetUrlOVD('/ajax/Elegibilidade/ValidaProtocolo.asp?MR_IAPJS_CDTRAN=' + MR_IAPJS_CDTRAN + '&MR_IAPJS_CDCANA=' + MR_IAPJS_CDCANA + '&MR_IAPJS_IDENTEMP=' + MR_IAPJS_IDENTEMP + '&MR_IAPJS_IDENTNEG=' + MR_IAPJS_IDENTNEG + '&MR_IAPJS_NUMEPARM=' + MR_IAPJS_NUMEPARM + '');
		strRetorno = strRetorno.split('|');		
		if (strRetorno.length == 2)
		{			
			var strStatus, strElegivel
			strStatus = strRetorno[0];
			strElegivel = strRetorno[1];				
			if (strStatus != '00')
			{				
				return 'Erro ao validar o Protocolo.|';
			}
			else
			{				
				if (strElegivel == 'N')
				{	
					document.frmFc.action = strURL + '?status=5';
					document.frmFc.submit();				
					//window.location = strURL + '?status=5';
					return false;
				}
			}
		}
		else
		{
			return 'Erro ao validar o Protocolo.|';
		}
		return '';
	}
	// ********************************************************************************
	// ********************************************************************************
	// ********************************************************************************
}

//monstra o campo de protocolo na pag.
function shProtocolo(intSH)
{
	//var objProtl = new getObj('lProtocolo');
	var objProtl = new getObj('tblOuvidoria');
	if (intSH == 0)
	{
		document.frmFc.fgProtocolo.value = '';
		objProtl.style.display = 'none';
	}
	else
	{
		if (intSH == 1)
		{			
			objProtl.style.display = '';
			document.frmFc.fgProtocolo.value = '1';
		}
	}
}

//troca a pagina para a pag q pede o nr do protocolo
function chPagProtoc(url, valor)
{	
	if(valor=='99999')
	{
		shMensagem(false);
		shProtocolo(1);				
	}
    else
    {
		shMensagem(true);
		shProtocolo(0);
		if (valor == '0')
		{
			shMensagem(false);
		}				
    }    
    resizeIframe('links');
}

function resizeIframe(frameid)
{
	var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
	var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers	
	var currentfr=parent.document.getElementById(frameid);	
	if (currentfr && !window.opera)
	{
		currentfr.style.display="block";
		
		try
		{
			if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
			{
				currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight; 
			}
			else if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax
			{	
				currentfr.height = currentfr.Document.body.scrollHeight;
				document.getElementById('MenuBgEspaco').style.height=currentfr.Document.body.scrollHeight;
			}
			else if(currentfr.contentDocument && currentfr.contentDocument.body.scrollHeight) //ie5+ syntax
			{
				currentfr.height = currentfr.contentDocument.body.scrollHeight;
			}
		}
		catch(ex)
		{
			
		}
	}
}

function shMensagem(blnShow)
{
	if (blnShow)
	{
		var objTR = new getObj('trlbMensagem');
		objTR.style.display = '';
		var objTR = new getObj('trTxMensagem');
		objTR.style.display = '';			
	}
	else
	{
		var objTR = new getObj('trlbMensagem');
		objTR.style.display = 'none';
		var objTR = new getObj('trTxMensagem');
		objTR.style.display = 'none';				
	}
}

//seleciona um campo tipo de email baseado num parametro da querystring
function chCBPar()
{	
	objDdl = new getObj('selTipoEmail');
    var qs = '';
    for(i=0;i<objDdl.obj.length;i++)
	{
	    qs = url_decode(window.location.search);
	    if(qs.indexOf(objDdl.obj.options[i].text) > 0)
	    {
			objDdl.obj.options[i].selected=true;
	    }	    
	}
}

function inicia(canal)
{
    if(document.frmFc.radTipo[0]==null || document.frmFc.radTipo[0].checked==true)
    {
        showL('cCor');
        hideL('cNCor');
        hideL('cNCor2');
    }
    if(document.frmFc.radTipo[1]!=null && document.frmFc.radTipo[1].checked==true)
    {
        hideL('cCor');
        if(canal==3)
        {
            showL('cNCor2');
            hideL('cNCor');
        }
        else
        {
            showL('cNCor');
            hideL('cNCor2');
        }
    }
    ddlTE = new getObj('selTipoEmail')
    if(ddlTE.obj.value == '99999')//se eh ouvidoria
    {
		shProtocolo(1);
    }
    else
    {
		shProtocolo(0);
    }
    chCBPar();
    LoadUrl('/ajax/formularios/faleconosco/faleconosco.asp?tipoEmail='+ddlTE.obj.value, 'selAssuntoL');
    setTimeout("setValorDdl('selTipoEmail','strTipoEmail');",2000);
	setTimeout("setValorDdl('selAssunto','strAssunto');",2000);
}

function CancelaOK()
{
    window.location.href = window.location.pathname+'?ms=1';
}

function CancelaNOK()
{

}

function ShowHint(strLayer)
{
    var objL = new getObj(strLayer);
    objL.style.visibility = 'visible';
}
function HideHint(strLayer)
{
    var objL = new getObj(strLayer);
    objL.style.visibility = 'hidden';    
}
function submitaEnter(e)
{
	var tecla = getKey(e);
	if(tecla == 13)
	{
		if(validaProtocolo())
		{			
			document.frmFc.action = window.location.pathname;
			document.frmFc.submit();
		}
		else
		{
			document.frmFc.nrProtocolo.focus();
		}
	}
}

function scrollTop()
{
	try
	{
		window.scrollTo(0,0);
		parent.window.scrollTo(0,0);
	}
	catch(ex)
	{
	
	}
}

function AjustaFormulario()
{
	var selTipoEmail = document.getElementById('selTipoEmail');	
	if (selTipoEmail != null)
	{
		for (i=0; i < selTipoEmail.length ; i++)
		{
			if ((selTipoEmail[i].selected) && (selTipoEmail[i].text.toUpperCase() == 'OUVIDORIA'))			
			{
				var tblOuvidoria = document.getElementById('tblOuvidoria');
				if (tblOuvidoria != null)
				{
					tblOuvidoria.style.display = '';
				}
			}
		}
	}
	resizeIframe('links');
	document.frmFc.nrProtocolo.disabled = false;
}