﻿/*
|----------------------------------------------------------------------------------------------------|
|           Desenvolvido por: Focusnetworks Interactive Ltda.                                        |
|                    Contato: http://www.focusnetworks.com.br                                        |
|                    Contratante: Intermédica Sistema de Saúde                                       |
|----------------------------------------------------------------------------------------------------|
*/

var timerMediaBox = null;

$(document).ready(function(){
	if(jQuery.browser.msie && jQuery.browser.version == "6.0")
	{
	    
	    var supersleight	= function() {
	        var root = false;
	        var applyPositioning = true;
        	
	        // Path to a transparent GIF image
	        var shim  =	'x.gif';		//= RootUrl + 'x.gif';
        	
	        // RegExp to match above GIF image name
	        var shim_pattern	= /x\.gif$/i;
        	
	        var fnLoadPngs = function() { 
		        if (root) {
			        root = document.getElementById(root);
		        }else{
			        root = document;
		        }
        		
		        for (var i = root.all.length - 1, obj = null; (obj = root.all[i]); i--)
		        {	
		            if ((obj.id && obj.id != 'noPng') || obj.className.indexOf('noPng') == -1)
		            {
			            // background pngs
			            if (obj.currentStyle.backgroundImage.match(/\.png/i) !== null) {
				            bg_fnFixPng(obj);
			            }
			            // image elements
			            if (obj.tagName=='IMG' && obj.src.match(/\.png$/i) !== null){
				            el_fnFixPng(obj);
			            }

        //			    // apply position to 'active' elements
			            if (applyPositioning && (obj.tagName=='A' || obj.tagName=='INPUT') && obj.style.position === ''){
				            obj.style.position = 'relative';
			            }
			        }
			        else
			        {
				        //alert(obj.className);
			        }
		        }
	        };

	        var bg_fnFixPng = function(obj) {
		        var mode = 'scale';
		        var bg	= obj.currentStyle.backgroundImage;
		        var src = bg.substring(5,bg.length-2);
		        if (obj.currentStyle.backgroundRepeat == 'no-repeat') {
			        mode = 'crop';
		        }
		        obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + mode + "')";
		        obj.style.backgroundImage = 'url('+shim+')';
	        };

	        var el_fnFixPng = function(img) {
		        var src = img.src;
		        img.style.width = img.width + "px";
		        img.style.height = img.height + "px";
		        img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')";
		        img.src = shim;
	        };
        	
	        var addLoadEvent = function(func) {
		        var oldonload = window.onload;
		        if (typeof window.onload != 'function') {
			        window.onload = func;
		        } else {
			        window.onload = function() {
				        if (oldonload) {
					        oldonload();
				        }
				        func();
			        };
		        }
	        };
        	
	        return {
		        init: function() { 
			        addLoadEvent(fnLoadPngs);
		        },
        		
		        limitTo: function(el) {
			        root = el;
		        },
        		
		        run: function() {
			        fnLoadPngs();
		        }
	        };
        }();

        // limit to part of the page ... pass an ID to limitTo:
        // supersleight.limitTo('header');
        supersleight.init();
	}
		
	if($('#a_e_itens li a.lnkTit').val() != undefined)
		$('#a_e_itens li a.lnkTit').click(function(){
			if(!$(this).parent().hasClass('on')){
				$("#a_e_itens li.on").animate({height:'32px'}, 300, function(){
					$(this).removeAttr("style").removeClass("on");
				});
				$(this).parent().animate({height:"105px"},700).addClass('on');
			}
		});

	if($('.media_box a').val() != undefined){
		$('.media_box a').click(function(){
				if(!$(this).hasClass('on')){
					clearTimeout(timerMediaBox);
					$(".media_box a.on").removeClass("on");
					var _src = $(this).addClass('on').next().val();
					var _alt = $(this).next().next().val();
					var _link = $(this).next().next().next().val();
					var _externo = $(this).next().next().next().next().val();
					
					$(".flash_img").fadeOut("slow", function(){
						$(this).empty();
						fctMediaBox(_src, _alt, _link, _externo);
					});
				}
			}
		);
		//timerMediaBox = setTimeout("fctMediaBoxAuto()", 5000);
	}
});

function fctMediaBoxAuto(){
	
	var _src;
	eLI = $(".media_box a.on").parent().next();
	
	if($(".media_box a.on").parent().get(0).className == ("mb"+$(".media_box li").length)){
		$(".media_box a.on").removeClass("on");
		$(".media_box li").children()[0].className = "on";
		_src = $(".media_box li").children()[1].value;
		_alt = $(".media_box li").children()[2].value;
		_link = $(".media_box li").children()[3].value;
		_externo = $(".media_box li").children()[4].value;
		
	}else{
		$(".media_box a.on").removeClass("on");
		_src = eLI.children()[1].value;
		_alt = eLI.children()[2].value;
		_link = eLI.children()[3].value;
		_externo = eLI.children()[4].value;
		
		eLI.children()[0].className = "on";	
	}
	
	$(".flash_img").fadeOut("slow", function()
	{
		$(this).empty();
		
		fctMediaBox(_src, _alt, _link, _externo);
	});
}


function fctMediaBox(_arquivo, _titulo, _link, _externo){
	if(_arquivo.indexOf(".swf") != -1){
		$(".flash_img").html('<div id="genFlashMediaBox"></div>');
		var flashvars = {};
		var params = { wmode: 'transparent' };
		swfobject.embedSWF(_arquivo, 'genFlashMediaBox', '100%', '100%', '9.0.0', '/layout/swf/expressInstall.swf', flashvars, params);		
	}else {
	    var _html = "";	
	    if(_link != null && _link != "") {
	        if(_externo == "true")
	            _html = '<a href="' + _link + '" title="' + _titulo + '" target="_blank">';
            else
                _html = '<a href="' + _link + '" title="' + _titulo + '">';
	        _html += '<img src="'+ _arquivo +'" alt="' + _titulo + '" />';
	        _html += '</a>';
        } else {
            _html += '<img src="'+ _arquivo +'" alt="' + _titulo + '" />';
        }
	        
		$(".flash_img").html(_html);
	}

	$(".flash_img").fadeIn("slow");
	
	clearTimeout(timerMediaBox);
	timerMediaBox = setTimeout("fctMediaBoxAuto()", 8000);
}

var _open = true;
function fctSubMenu(_sObj){
	$("#"+_sObj+" ul").toggle();
	if(_open){
		_open = false;
		$("#"+_sObj+"").css({zIndex:'2'})
	}else{
		_open = true;
		$("#"+_sObj+"").removeAttr("style");
	}
}

function fctDetalhePlano(URL){
	window.open(URL,'Ver','left=20%,top=10%,width=620,height=650,location=0,resizable=no,scrollbars=yes');
}

var _premio = false;
function fctPremio(_this){
	if(!_premio){
		$("#"+_this+" p").toggle().parent().parent().css({zIndex:'2'});
		_premio = true;
	}else{
		$("#"+_this+" p").toggle().parent().parent().removeAttr('style');
		_premio = false;
	}
}

function ToolTipPremio(){
	setTimeout(function(){
		for(i = 0; i < $(".lista_premios li div").length; i++){
			$("#div_"+i+ " img").wTooltip({
				content: $("#div_"+i+ " span").html(),
				className: "tooltip",
				fadeIn: 400,
				fadeOut: 400
			});
		}
	}, 500);
}

var row = 0;
var posUL = 0;
var qtd;
$(document).ready(function(){$("#lista_programas").attr('style','width:auto'); });
function fctSlideProgramas(tipo)
{
	qtd = $("#lista_programas > li").length;
	
	if(!tipo)
	{
		if(row > 0)
		{
			row = row-3;
			posUL = posUL - 864;
			$("#lista_programas").animate({left:-posUL},700);
			if(posUL < 1)
				$('.outras_uni .lnkFAnterior').addClass("lnkFAnterior_off").removeClass("lnkFAnterior");
			$('.outras_uni .lnkFProximo_off').addClass("lnkFProximo").removeClass("lnkFProximo_off");
		}
	}
	else
	{
		if(row < qtd -3)
		{
			row = row + 3;
			var rowAux = row;
		    var cont = 0;
			while(cont < 3)
			{
			  if($("#imgOutrasUnidades_"+rowAux).attr('src') == '')
			  {
			    var img = $("#imgOutras_"+rowAux).val();
			    $("#imgOutrasUnidades_"+rowAux).attr('src',img);
			  }
			  cont++;
			  rowAux++;
			}
			posUL = row * 288;
			$("#lista_programas").animate({left:-posUL},500);
			$("#lista_programas").attr('style','width=auto');
			if(posUL > 0)
				$('.outras_uni .lnkFAnterior_off').addClass("lnkFAnterior").removeClass("lnkFAnterior_off");
			if(qtd <= (row + 3))
				$('.outras_uni .lnkFProximo').addClass("lnkFProximo_off").removeClass("lnkFProximo");
		}
	}
}

var index = 0;
                    
function fctSlideFotos(tipo, qtd)
{
    if(!tipo)
    {
        if(index > 0)
        {
            index--;
            
            var img = $("#img_"+index).val();
            var descricao = $("#descricao_"+index).val();
            
            $(".mid_r span.img").css({background:"url("+RootUrl+"layout/img/loading_big.gif) no-repeat center center"});
            $("#imgFoto").fadeOut("slow", function(){
                $("#imgFoto").attr('src',img);
                $("#genDescricao").html(descricao);
                $("#imgFoto").fadeIn("slow", function(){$(".mid_r span.img").removeAttr("style");});
            });
            
            if(index == 0)
                $('.mid_r .lnkFAnterior').addClass("lnkFAnterior_off").removeClass("lnkFAnterior");
                
            $('.mid_r .lnkFProximo_off').addClass("lnkFProximo").removeClass("lnkFProximo_off");
        }
    }
    else
    {
        if(index < qtd-1)
        {
            index++;
            var img = $("#img_"+index).val();
            var descricao = $("#descricao_"+index).val();
            
            $(".mid_r span.img").css({background:"url("+RootUrl+"layout/img/loading_big.gif) no-repeat center center"});
            $("#imgFoto").fadeOut("slow", function(){
                $("#imgFoto").attr('src',img);
                $("#genDescricao").html(descricao);
                $("#imgFoto").fadeIn("slow", function(){$(".mid_r span.img").removeAttr("style");});
            });
            
            if(qtd-1 == index)
                $('.mid_r .lnkFProximo').addClass("lnkFProximo_off").removeClass("lnkFProximo");
            
			$('.mid_r .lnkFAnterior_off').addClass("lnkFAnterior").removeClass("lnkFAnterior_off");
		}
    }
}

function valida_cnpj(sender,args)
{
    var exp = /\.|\-|\//g;
    var cnpj = $('.cnpj_form').val().replace( exp, "" );
    var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais;
    digitos_iguais = 1;
    
    if (cnpj.length < 14 && cnpj.length < 15)
    {
        args.IsValid = false;
        return;
    }
    
    for (i = 0; i < cnpj.length - 1; i++)
        if (cnpj.charAt(i) != cnpj.charAt(i + 1))
        {
              digitos_iguais = 0;
              break;
        }
        
    if (!digitos_iguais)
    {
        tamanho = cnpj.length - 2
        numeros = cnpj.substring(0,tamanho);
        digitos = cnpj.substring(tamanho);
        soma = 0;
        pos = tamanho - 7;
        for (i = tamanho; i >= 1; i--)
        {
            soma += numeros.charAt(tamanho - i) * pos--;
            if (pos < 2)
                pos = 9;
        }
        resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
        if (resultado != digitos.charAt(0))
        {
              args.IsValid = false;
              return;
        }
        tamanho = tamanho + 1;
        numeros = cnpj.substring(0,tamanho);
        soma = 0;
        pos = tamanho - 7;
        for (i = tamanho; i >= 1; i--)
        {
          soma += numeros.charAt(tamanho - i) * pos--;
          if (pos < 2)
                pos = 9;
        }
        resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
        if (resultado != digitos.charAt(1))
        {
              args.IsValid = false;
              return;
        }
        args.IsValid = true;
    }
    else
        args.IsValid = false;
} 

/*function hideDropDowns()
{
    if(navigator.userAgent.indexOf("MSIE 6.0") > 0)
    {
        $('select').each(function (){
            $(this)
                .css('display','none')
                .after('<span style="background:' + $(this).css('background') + ';width:' + $(this).width() + ';padding:2px 0 2px 4px;border:solid 1px black;">' + this.options[this.selectedIndex].text + '</span>');
        });
    }
}

function showDropDowns()
{
    if(navigator.userAgent.indexOf("MSIE 6.0") > 0)
    {
        $('select + span').remove();
        $('select').css('display','inline');
    }
}*/

function toggleDropDowns()
{
    if(navigator.userAgent.indexOf("MSIE 6.0") > 0)
    {
        if($('select').is(':visible'))
        {
            $('select').each(function (){
                $(this)
                    .css('display','none')
                    .after('<span style="background:'+$(this).css('background')+';height:'+$(this).height()+';width:'+$(this).width()+';border:1px '+$(this).css('border-style')+' '+$(this).css('border-color')+';padding:2px 0 2px 4px;">' + (this.selectedIndex >= 0 ? this.options[this.selectedIndex].text : '') + '</span>');
            });
        }
        else
        {
            $('select + span').remove();
            $('select').css('display','inline');
        }
    }
}

/*
|----------------------------------------------------------------------------------------------------|
|           Função: IsValidCheckBoxDisponibilidadeSemanal()                                          |
|        Descrição: Função que valida se o check box de disponibilidade semanal possui um item       |
|                   selecionado                                                                      |
|  ================================================================================================  |
|           Criado: 21/07/2009 | Por: Rafael K. Une                                                  |
|       Modificado: __/__/____ | Por:                                                                |
|----------------------------------------------------------------------------------------------------|
*/
function IsValidCheckBoxDisponibilidadeSemanal(sender,args) {
    var checkboxlist = $('.rblDisponibilidadeSemanal input');
     args.IsValid = false;

    for (index = 0; index < checkboxlist.length; index++) {
        if(checkboxlist[index].checked) {
            args.IsValid = true;
            return;
        }
    }
 }

/*
|----------------------------------------------------------------------------------------------------|
|           Função: IsValidCheckBoxDisponibilidadeHorario()                                          |
|        Descrição: Função que valida se o check box de disponibilidade de horário possui um item    |
|                   selecionado                                                                      |
|  ================================================================================================  |
|           Criado: 21/07/2009 | Por: Rafael K. Une                                                  |
|       Modificado: __/__/____ | Por:                                                                |
|----------------------------------------------------------------------------------------------------|
*/
function IsValidCheckBoxDisponibilidadeHorario(sender,args) {
    var checkboxlist = $('.rblDisponibilidadeHorario input');
     args.IsValid = false;

    for (index = 0; index < checkboxlist.length; index++)
    {
        if(checkboxlist[index].checked)
        {
            args.IsValid = true;
            return;
        }
    }
 }
 
/*
|----------------------------------------------------------------------------------------------------|
|           Função: IsValidCheckBoxPopulacao()                                                       |
|        Descrição: Função que valida se o check box de população possui um item selecionado         |
|  ================================================================================================  |
|           Criado: 21/07/2009 | Por: Rafael K. Une                                                  |
|       Modificado: __/__/____ | Por:                                                                |
|----------------------------------------------------------------------------------------------------|
*/
function IsValidCheckBoxPopulacao(sender,args) {
    var checkboxlist = $('.rblPopulacao input');
     args.IsValid = false;

    for (index = 0; index < checkboxlist.length; index++) {
        if(checkboxlist[index].checked)
            args.IsValid = true;
    }

    if(!args.IsValid) {
         var txtTiposTrabalho = $('.txtPopulacao').val();
         if(txtTiposTrabalho != '' && txtTiposTrabalho.length > 0)
            args.IsValid = true;
    }
 }
 
/*
|----------------------------------------------------------------------------------------------------|
|           Função: IsValidCheckBoxRegiao()                                                          |
|        Descrição: Função que valida se o check box de região possui um item selecionado            |
|  ================================================================================================  |
|           Criado: 21/07/2009 | Por: Rafael K. Une                                                  |
|       Modificado: __/__/____ | Por:                                                                |
|----------------------------------------------------------------------------------------------------|
*/ 
function IsValidCheckBoxRegiao(sender,args) {
    var checkboxlist = $('.rblRegiao input');
     args.IsValid = false;

    for (index = 0; index < checkboxlist.length; index++) {
        if(checkboxlist[index].checked)
            args.IsValid = true;
    }

    if(!args.IsValid) {
         var txtTiposTrabalho = $('.txtRegiao').val();
         if(txtTiposTrabalho != '' && txtTiposTrabalho.length > 0)
            args.IsValid = true;
    }
 }

/*
|----------------------------------------------------------------------------------------------------|
|           Função: IsValidCheckBoxTipoTrabalho()                                                    |
|        Descrição: Função que valida se o check box de tipo de trabalho possui um item selecionado  |
|  ================================================================================================  |
|           Criado: 21/07/2009 | Por: Rafael K. Une                                                  |
|       Modificado: __/__/____ | Por:                                                                |
|----------------------------------------------------------------------------------------------------|
*/
function IsValidCheckBoxTipoTrabalho(sender,args) {
    var checkboxlist = $('.rblTipoTrabalho input');
     args.IsValid = false;

    for (index = 0; index < checkboxlist.length; index++)
    {
        if(checkboxlist[index].checked)
            args.IsValid = true;
    }

    if(!args.IsValid)
    {
         var txtTiposTrabalho = $('.txtTiposTrabalho').val();
         if(txtTiposTrabalho != '' && txtTiposTrabalho.length > 0)
            args.IsValid = true;
    }
 }
 
/*
|----------------------------------------------------------------------------------------------------|
|           Função: IsValidCheckBoxPopulacaoAlvoEntidade()                                           |
|        Descrição: Função que valida se o check box de população alvo da entidade possui um item    |
|                   selecionado                                                                      |
|  ================================================================================================  |
|           Criado: 21/07/2009 | Por: Rafael K. Une                                                  |
|       Modificado: __/__/____ | Por:                                                                |
|----------------------------------------------------------------------------------------------------|
*/ 
function IsValidCheckBoxPopulacaoAlvoEntidade(sender, args) {
    var checkboxlist = $('.rblPopulacaoAlvoEntidade input');
     args.IsValid = false;

    for (index = 0; index < checkboxlist.length; index++) {
        if(checkboxlist[index].checked)
            args.IsValid = true;
    }

    if(!args.IsValid) {
         var txtTiposTrabalho = $('.txtPopulacaoAlvoEntidade').val();
         if(txtTiposTrabalho != '' && txtTiposTrabalho.length > 0)
            args.IsValid = true;
    }
 }
 
/*
|----------------------------------------------------------------------------------------------------|
|           Função: ListBoxValid()                                                                   |
|        Descrição: Função que valida se o listbox do formulário de voluntário possui um item        |
|                   selecionado                                                                      |
|  ================================================================================================  |
|           Criado: 21/07/2009 | Por: Rafael K. Une                                                  |
|       Modificado: __/__/____ | Por:                                                                |
|----------------------------------------------------------------------------------------------------|
*/
function ListBoxValid(sender, args) {
    args.IsValid = ($('.qualidadeprosele option').length > 0);
}

function ValidarSummary() {
    setTimeout("ValidarSummary_fct();", 100);
}
function ValidarSummary_fct()
{
	if(Page_IsValid == false)
    {
        toggleDropDowns();
        $('.area_erro_form').show();
        $('.area_erro_form h4')
            .css('cursor','pointer')
            .unbind("click")
            .bind(
                "click",
                function(){
                    toggleDropDowns();
                    $('.area_erro_form .random_class_vs').slideToggle();
                }
            );
        $('.area_erro_form .lnk_collapse, .area_erro_form .lnk_expand')
            .css('cursor','pointer')
            .unbind("click")
            .bind(
                "click",
                function(){
                    toggleDropDowns();
                    if($(this).attr('class') == 'lnk_collapse')
                        $(this).removeClass().addClass('lnk_expand');
                    else
                        $(this).removeClass().addClass('lnk_collapse');
                    
                    $('.area_erro_form .random_class_vs').slideToggle();
                }
            );
    }
    else
    {
        $('.area_erro_form').hide();
    }
}

function resizeMenuLateral() {
    $('.menu_cont').css('height','auto');
    $('.menu_cont').height($('.bg_listra').height()-175);
}

function fecharCortinaAbertura(){
    //if(jQuery.browser.msie)
        $('.flash_abertura').remove();
    //else
        //setTimeout("$('.flash_abertura').remove();",3000);
}

function VerificaDataValida(oValue)
{
    var oRegExp = /^(0[1-9]|[12][0-9]|[3][01])\/(0[1-9]|1[012])\/([12][0-9]{3})?$/;
    
    if(!oRegExp.test(oValue) && oValue != '')
        return false;
    
  return true;
}

function ValidaDataTextBox(oCampo)
{
    VerificaEntradaAlfaNumPaste(oCampo);
        
    var valueCampo = document.getElementById(oCampo).value;
    
    if(!VerificaDataValida(valueCampo))
    {
        document.getElementById(oCampo).value = '';
        return false;
    }
    
    return true;
}

function EntradaAlfaNumEnter(caixaAlta, outrosCarac, espaco, oCampo, oEvent)
{
    if (oEvent.keyCode)
        tecla_codigo = oEvent.keyCode;
    else if (oEvent.which)
        tecla_codigo = oEvent.which;
       
    if (tecla_codigo == 60 || tecla_codigo == 62)
        return false;
    else
        return true;
}


function OpenPopup(url)
{
    window.open(url,'Intermédica Download','left=100,top=100,width=auto,height=auto,location=0,resizable=no,scrollbars=yes');
}
