// Cria mascara para campos de data, e adiciona um calendario par seleção de datas

//For IE6 - Background flicker fix
try {
  document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}



var blockScroll_foto = true;
var pxScroll_foto = 500;
function arq(direcao){
	
    
	 if(blockScroll_foto){
	   	
			blockScroll_foto = false;
			var directionScroll = (direcao == "esq")?'-=':'+=';
			 
			//jQuery('#prox_imagem').bind('',scrollTo( directionScroll+pxScroll_foto, 400, {axis:'x', onAfter:function(){blockScroll_foto = true}}) );
	   //}
	   
	   
	  // jQuery('#prox_imagem').scrollTo(200,200,{axis:'x', onAfter:''});
	   jQuery('#prox_imagem').scrollTo( directionScroll+pxScroll_foto, 400, {axis:'x', onAfter:function(){blockScroll_foto = true}}) ;
	   }
	   
}


/* Galeria de Imagens */
var blockScroll = true;
//var pxScroll = 550;
var pxScroll = 436;
function galeria(direcao){
   if(blockScroll){
		blockScroll = false;
		var directionScroll = (direcao == "esq")?'-=':'+=';
		//jQuery('#bloco_galeria').scrollTo( directionScroll+pxScroll, 400, {axis:'x', onAfter:function(){blockScroll = true}} );
		jQuery('#corpo .bg_corpo .conteudo .meio .galeria_img .thumbs_galeria').scrollTo( directionScroll+pxScroll, 400, {axis:'x', onAfter:function(){blockScroll = true}} );
   }
}
var pxScroll2 = 500;
var blockScroll2 = true;
function depoimentos(direcao){
   if(blockScroll2){
		blockScroll2 = false;
		var directionScroll = (direcao == "esq")?'-=':'+=';
		jQuery('#lista_depoimentos').scrollTo( directionScroll+pxScroll2, 400, {axis:'x', onAfter:function(){blockScroll2 = true}} );
   }
}
/* AUMENTA E DIMINUE A FONTE*/
var atualSize = 0;
function sizeFont(opt){
	x = false;
	
	if(opt == 'maior'){
		
		jQuery(".sizeText").each(function(){
			
			//size = this.style.fontSize;
			size = jQuery(this).css('font-size');
			aux = size.split('p');
			if(atualSize < 4){
				this.style.fontSize = (parseInt(aux[0])+1)+"px";
				x = true;
			}
		});
		if(x){
			atualSize++;	
		}
	}else if(opt == 'menor'){
		
		jQuery(".sizeText").each(function(){
			
			//size = this.style.fontSize;
			size = jQuery(this).css('font-size');
			aux = size.split('p');
			if(atualSize > 0){
				this.style.fontSize = (parseInt(aux[0])-1)+"px";
				x = true;
			}
		});
		if(x){
			atualSize--;	
		}
	}
}

function getPageSize(){
    var xScroll, yScroll;

    if (window.innerHeight && window.scrollMaxY) {          
	   xScroll = document.body.scrollWidth;
	   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
       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;
    }              
    var pageHeight, pageWidth;

    // 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 = windowWidth;
    } else {
                   pageWidth = xScroll;
    }

    return {
                   pageWidth: pageWidth ,
                   pageHeight: pageHeight , 
                   windowWidth: windowWidth, 
                   windowHeight: windowHeight
    };
}

function changeHeightSite(){
	               
    var heightTopo = 115;
    var heightRodape = 97;
    var size = getPageSize();
    var height = size.windowHeight - heightTopo - heightRodape;
    if(jQuery('#pagina').outerHeight() != null){
       if(jQuery('#pagina').outerHeight() < height){
			jQuery('#pagina').css("height",height+"px");
       }
    }
}

function checkMail(mail){
	var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
	if(typeof(mail) == "string"){
	        if(er.test(mail)){ return true; }
	}else if(typeof(mail) == "object"){
        if(er.test(mail.value)){ 
                return true; 
        }
	}else{
    	return false;
    }
}

function load_depoimento(path, player, id)
{
	var flashvars = { "path": path };
    var params = {
    	allowFullScreen:"true",
    	wmode: "transparent"
    };
	swfobject.embedSWF(player, id, 491, 276, "10.0.0","",flashvars,params);
}

var status_contraste = false;
function contraste(){
	
	if(status_contraste){
		jQuery("html").removeClass('contraste');
		status_contraste = false;
	}else{
		jQuery("html").addClass('contraste');
		status_contraste = true;
	}
}

function desfocar_menu(id)
{
	jQuery('.itens a').each(function(i){
		
		if(jQuery(this).attr('id') != id && i != 0) {
			
			var aux1 = jQuery.trim(jQuery(this).attr('class').replace('fl',''));
			
			var aux2 = jQuery(this).attr('id').split('-');
			var theclass = aux2[1];
			var aux3 = theclass+'_hover';
			
			if(aux1 == aux3) {
				jQuery(this).addClass(theclass).removeClass(aux1);
			}
		}
		
	});
}

jQuery(document).ready(function(){

    //Posicionando o rodape
    jQuery("body").attr('onload','changeHeightSite()');
    jQuery(window).resize(function(){changeHeightSite();});
    changeHeightSite();

});

function mostra_alert()
{
			jQuery("#esqueceu_senha").modal({
				
				onOpen: function (dialog) {
					dialog.overlay.fadeIn();
					dialog.container.fadeIn();
					dialog.data.fadeIn();
				},
				onClose: function (dialog) {
					dialog.data.fadeOut()
					dialog.container.slideUp();
					dialog.overlay.fadeOut('normal', function () {
						jQuery.modal.close(); // must call this!
					});					
				}
			});
}
function close_lightbox() 
{
    jQuery.modal.close();
}

/*
*    Script:    Mascaras em Javascript
*    Autor:    Matheus Biagini de Lima Dias
*    Data:    26/08/2008
*    Obs:    
*/
    /*Função  Pai de Mascaras*/
    function Mascara(o,f){
        v_obj=o
        v_fun=f
        setTimeout("execmascara()",1)
    }
    
    /*Função que Executa os objetos*/
    function execmascara(){
        v_obj.value=v_fun(v_obj.value)
    }
    
    /*Função que Determina as expressões regulares dos objetos*/
    function leech(v){
        v=v.replace(/o/gi,"0")
        v=v.replace(/i/gi,"1")
        v=v.replace(/z/gi,"2")
        v=v.replace(/e/gi,"3")
        v=v.replace(/a/gi,"4")
        v=v.replace(/s/gi,"5")
        v=v.replace(/t/gi,"7")
        return v
    }
    
    /*Função que permite apenas numeros*/
    function Integer(v){
        return v.replace(/\D/g,"")
    }
    
    /*Função que padroniza  telefone (11) 4184-1241*/
    function Telefone(v){
        v=v.replace(/\D/g,"")                 
        v=v.replace(/^(\d\d)(\d)/g,"($1) $2") 		/* tirarando o (11) */
        v=v.replace(/(\d{4})(\d)/,"$1-$2")    
        return v
    }
    
    /*Função que padroniza telefone (11) 41841241*/
    function TelefoneCall(v){
        v=v.replace(/\D/g,"")                 
        v=v.replace(/^(\d\d)(\d)/g,"($1) $2")    
        return v
    }
    
    /*Função que padroniza CPF*/
    function Cpf(v){
        v=v.replace(/\D/g,"")                    
        v=v.replace(/(\d{3})(\d)/,"$1.$2")       
        v=v.replace(/(\d{3})(\d)/,"$1.$2")       
                                                 
        v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") 
        return v
    }
    
    /*Função que padroniza CEP*/
    function Cep(v){
        v=v.replace(/D/g,"")                
        v=v.replace(/^(\d{5})(\d)/,"$1-$2") 
        return v
    }
    
    /*Função que padroniza CNPJ*/
    function Cnpj(v){
        v=v.replace(/\D/g,"")                   
        v=v.replace(/^(\d{2})(\d)/,"$1.$2")     
        v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3") 
        v=v.replace(/\.(\d{3})(\d)/,".$1/$2")           
        v=v.replace(/(\d{4})(\d)/,"$1-$2")              
        return v
    }

    /*Função que padroniza DATA*/
    function Data(v){
        v=v.replace(/\D/g,"") 
        v=v.replace(/(\d{2})(\d)/,"$1/$2") 
        v=v.replace(/(\d{2})(\d)/,"$1/$2") 
        return v
    }
    
    /*Função que padroniza DATA*/
    function Data_en(v){
        v=v.replace(/\D/g,"") 
        v=v.replace(/(\d{4})(\d)/,"$2/$2") 
        v=v.replace(/(\d{4})(\d)/,"$1/$4") 
        return v
    }
    
    /*Função que padroniza DATA*/
    function Hora(v){
        v=v.replace(/\D/g,"") 
        v=v.replace(/(\d{2})(\d)/,"$1:$2")  
        return v
    }
    
function in_array_mes(mes){
	var ames = new Array(1,3,5,7,8,10,12);
	
	for(i=0;i<ames.length;i++){
		if(mes == ames[i]) return true;
	}
	return false;
}

var x = 2;
function adcionar_anexos()
{
	
	var div = '';
	
	div+= '<div id="input_'+x+'" class="fl">'
	div+= '<input class="email fl" id="arquivo'+x+'" value="" type="file" name="arquivo[]" style="width:258px;margin-left:51px;" />';
	div+= '<span id="span_'+x+'" class="fl" onclick="remover_anexos('+x+');" style="margin: 3px 9px 13px 10px;cursor:pointer;">Remover</span>';
	div+= '<br clear="all"/>';
	div+= '</div>';
	
	if(x <= 5){
		jQuery("#anexos").append(div);
		x++;
	}
	
	
	
}

function remover_anexos(id)
{
	var input = "#input_"+id;
	
	jQuery(input).html("");
	
	x--;
	
	

	
}
function strtr (str, from, to) {
    
    
    var fr = '',
        i = 0,
        j = 0,
        lenStr = 0,
        lenFrom = 0,
        tmpStrictForIn = false,
        fromTypeStr = '',
        toTypeStr = '',
        istr = '';
    var tmpFrom = [];
    var tmpTo = [];
    var ret = '';
    var match = false;
    if (typeof from === 'object') {
        tmpStrictForIn = this.ini_set('phpjs.strictForIn', false);
        from = this.krsort(from);
        this.ini_set('phpjs.strictForIn', tmpStrictForIn);

        for (fr in from) {
            if (from.hasOwnProperty(fr)) {
                tmpFrom.push(fr);
                tmpTo.push(from[fr]);
            }
        }

        from = tmpFrom;
        to = tmpTo;
    }

    lenStr = str.length;
    lenFrom = from.length;
    fromTypeStr = typeof from === 'string';
    toTypeStr = typeof to === 'string';

    for (i = 0; i < lenStr; i++) {
        match = false;
        if (fromTypeStr) {
            istr = str.charAt(i);
            for (j = 0; j < lenFrom; j++) {
                if (istr == from.charAt(j)) {
                    match = true;
                    break;
                }
            }
        } else {
            for (j = 0; j < lenFrom; j++) {
                if (str.substr(i, from[j].length) == from[j]) {
                    match = true;
                    i = (i + from[j].length) - 1;
                    break;
                }
            }
        }
        if (match) {
            ret += toTypeStr ? to.charAt(j) : to[j];
        } else {
            ret += str.charAt(i);
        }
    }

    return ret;
}
function show_agentes(id_agentes){
	
	jQuery.ajax({
		type: "POST",
		url: site_url+"/projetos/busca_agente/",
		data: "id_agentes="+id_agentes,
		success: function(msg){
			
			jQuery("#conteudo_agentes").html(msg);
			jQuery("#lightBoxAgentes").modal({
		
				opacity:80,
				overlayClose:true,
				autoResize: true,
				onOpen: function (dialog) {
					dialog.overlay.fadeIn();
					dialog.container.fadeIn();
					dialog.data.fadeIn();
					
				},
				onClose: function (dialog) {
					dialog.data.fadeOut()
					dialog.container.slideUp();
					dialog.overlay.fadeOut('normal', function () {
						jQuery.modal.close(); 
					});
					
				}
			});
			
		}
	});
	
}
function show_releases (id)
{
	jQuery.ajax({
		type: "POST",
		url: site_url+"/midia_imprensa/busca_midia/",
		data: "id="+id,
		success: function(msg){
			
			//alert(msg);
			
			jQuery("#MidiaImprensa_conteudo").html(msg);
			jQuery("#lightBoxMidiaImprensa").modal({
		
				opacity:80,
				overlayClose:true,
				autoResize: true,
				onOpen: function (dialog) {
					dialog.overlay.fadeIn();
					dialog.container.fadeIn();
					dialog.data.fadeIn();
					
				},
				onClose: function (dialog) {
					dialog.data.fadeOut()
					dialog.container.slideUp();
					dialog.overlay.fadeOut('normal', function () {
						jQuery.modal.close(); 
					});
					
				}
			});
			
		}
	});
	
}

function remover_item(id,i){

    if(confirm(_lang.alert_excluir_arquivo)){
    	jQuery.ajax({
    		type: "POST",
    		url: site_url+"/login_investidores/delete/",
    		data: "id="+id,
    		success: function(msg){
    		  
                    if(msg==1)
                    {
                        alert(_lang.alert_excluir_arquivo_sucesso);
                        jQuery("#"+i).hide();
                    
                    } else {
                        
                        alert(msg);
                    }
                    
    			}
    	});
    }
}
function confirm_remove(id)
{
	
    if (confirm(_lang.alert_excluir_arquivo)) {   
      location.href=site_url+'/login_investidores/delete/'+id;
    }   
	
}

function delete_faq(id,div)
{
    if(confirm(_lang.alert_excluir_arquivo)){
    	jQuery.ajax({
    		type: "POST",
    		url: site_url+"/investidores_faq/delete",
    		data: "id="+id,
    		success: function(msg){
    		  
                alert(msg);
                jQuery("#edit_"+div).slideUp("slow",function(){
                    
                    jQuery(this).remove();
                    jQuery("#img_"+div).remove();
                    jQuery("#perg_"+div).remove();
                    
                });
                
   			}
    	});
    }
    
}

function delete_img(id)
{
    if(confirm(_lang.alert_excluir_arquivo)){
    	jQuery.ajax({
    		type: "POST",
    		url: site_url+"/investidores_como/delete",
    		data: "id="+id+"&tipo=imagem",
    		success: function(msg){
    		  
                    alert(msg);
                    jQuery("#imagem_excluir").slideUp("slow",function(){
                    jQuery('#imagem_video_oculto').attr('value','');
                    jQuery(this).remove();
                    
                });
                
   			}
    	});
    }
    
}

function delete_video(id)
{
    if(confirm(_lang.alert_excluir_arquivo)){
    	jQuery.ajax({
    		type: "POST",
    		url: site_url+"/investidores_como/delete",
    		data: "id="+id+"&tipo=video",
    		success: function(msg){
    		  
                    alert(msg);
                    jQuery("#video_excluir").slideUp("slow",function(){
                        
                    jQuery('#arquivo_video_oculto').attr('value','');
                    jQuery(this).remove();
                    
                });
                
   			}
    	});
    }
    
}

function slide_resposta(i)
{
    jQuery('#rsp_'+i).slideToggle("slow");
}


function validaDat(valor) {
	var date=valor;
	var ardt=new Array;
	var ExpReg=new RegExp("(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[012])/[12][0-9]{3}");
	ardt=date.split("/");
    if(LANG == 'en')
    {
        date = ardt[2]+'/'+ardt[1]+'/'+ardt[0];
        ardt=date.split("/");
        
    }
	erro=false;
   	
	if (date.search(ExpReg)==-1) { erro = true; } 
	else if (((ardt[1]==4)||(ardt[1]==6)||(ardt[1]==9)||(ardt[1]==11))&&(ardt[0]>30)) erro = true;
	else if ( ardt[1]==2) {
		if ((ardt[0]>28)&&((ardt[2]%4)!=0)) erro = true;
		if ((ardt[0]>29)&&((ardt[2]%4)==0)) erro = true;
	}
	
	if(erro) {
		return false;
	}
	
	return true;
}


// =================================================================================
// =================================================================================
// =================================================================================
// TINY MCE  - ADMIN
var load_tiny = false;
var load_language_tiny = 'pt';

// Carrega .js referentes so tinyMCE via Gzip
function loadJSTinyMCE(){
	tinyMCE_GZ.init({
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
		themes : 'simple, advanced',
		languages : load_language_tiny,
		disk_cache : true,
		debug : false
	});			
}

// Configurações do tiny MCE
function loadConfigTypeTinyMCE(type){
	var conf = {};
	// Configuração completa do TinyMCE
	if(type == 'full'){
		conf = {
			plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
			
			theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
			theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
			theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
			theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak"		
		};
		
	// Configuração padrão da área administrativa Sapien	
	}else if(type == 'admin_full'){
		conf = {			
			plugins : "inlinepopups,contextmenu,style,layer,table,save,advhr,advimage,advlink,insertdatetime,preview,searchreplace,paste,directionality",
	
			theme_advanced_buttons1: "bold,italic,underline,justifyleft,justifycenter,justifyright,justifyfull,|,cut,copy,paste,|,pastetext,pasteword,|,image,|,link,unlink,anchor,replace,|,code",
			theme_advanced_buttons2: "outdent,indent,|,bullist,numlist,|,tablecontrols,|,undo,redo",
			theme_advanced_buttons3: "styleselect",
			theme_advanced_buttons4: ""
		};
		
	// Configuração com controles básicos da área administrativa Sapien							
	}else if(type == 'basic'){
		conf = {			
			plugins : "inlinepopups,style,layer,table,save,advhr,advimage,advlink,advimage,insertdatetime,preview,searchreplace,paste,directionality",
	
			theme_advanced_buttons1: "bold,italic,underline,pastetext,pasteword,code,image,link,unlink,",
			theme_advanced_buttons2: "",
			theme_advanced_buttons3: "",
			theme_advanced_buttons4: ""	
		};
	}
	
	var configTiny = {
		// language
		language : load_language_tiny,
		
		// General options
		theme : "advanced",
		
		// Plugins
		plugins : conf.plugins,

		// Theme options
		theme_advanced_buttons1 : conf.theme_advanced_buttons1,
		theme_advanced_buttons2 : conf.theme_advanced_buttons2,
		theme_advanced_buttons3 : conf.theme_advanced_buttons3,
		theme_advanced_buttons4 : conf.theme_advanced_buttons4,
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "center",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : false,

		// Example content CSS (should be your site CSS)
		content_css : base_url + "css/tiny.css",
		
		valid_elements : "*[*]",
		invalid_elements: "applet,iframe",	
		remove_script_host : false,
		relative_urls : false,
		force_p_newlines : false,
		force_br_newlines : true,
        forced_root_block : '', // Needed for 3.x
				
		apply_source_formatting : true,	
		
		document_base_url : base_url,		
					
		file_browser_callback : "tinyBrowser"
	};
	
	return configTiny;
}
	
// Inicializa os Editores TinyMCE
jQuery(function() {
	jQuery('textarea.tinymce_adminfull').each(function (i) {
		if(load_tiny == false){	load_tiny = true; loadJSTinyMCE();}
		jQuery(this).tinymce(loadConfigTypeTinyMCE('admin_full'));
	});
	
	jQuery('textarea.tinymce_basic').each(function (i) {
		if(load_tiny == false){	load_tiny = true; loadJSTinyMCE();}
		jQuery(this).tinymce(loadConfigTypeTinyMCE('basic'));
	});		
	
	jQuery('textarea.tinymce_full').each(function (i) {
		if(load_tiny == false){	load_tiny = true; loadJSTinyMCE();}
		jQuery(this).tinymce(loadConfigTypeTinyMCE('full'));
	});			
});



// =================================================================================
