UTF8 = {
	encode: function(s){
		for(var c, i = -1, l = (s = s.split("")).length, o = String.fromCharCode; ++i < l;
			s[i] = (c = s[i].charCodeAt(0)) >= 127 ? o(0xc0 | (c >>> 6)) + o(0x80 | (c & 0x3f)) : s[i]
		);
		return s.join("");
	},
	decode: function(s){
		for(var a, b, i = -1, l = (s = s.split("")).length, o = String.fromCharCode, c = "charCodeAt"; ++i < l;
			((a = s[i][c](0)) & 0x80) &&
			(s[i] = (a & 0xfc) == 0xc0 && ((b = s[i + 1][c](0)) & 0xc0) == 0x80 ?
			o(((a & 0x03) << 6) + (b & 0x3f)) : o(128), s[++i] = "")
		);
		return s.join("");
	}
};
	



	$(function() {
		$("#separador").toggle(
			function() {
				$("#conteudo").animate({marginLeft: '-53%'}, 500);
			},
			function() {
				$("#conteudo").animate({marginLeft: '0%'}, 500);
			}
		);
	});


	function replaceAll(str, de, para){
	    var pos = str.indexOf(de);
	    while (pos > -1){
			str = str.replace(de, para);
			pos = str.indexOf(de);
		}
	    return (str);
	}


	function mostraResposta(v){
		
		if(v==1){
			back = '#029696';
			msg='Operação efetuada  com sucesso.';
			cor='#fff'
		}else{
			back = '#FFFF99';
			msg='Nenhum operação efetuada.';
			cor='#333'
		}
		
	    $(document).ready(function() {
	        //$('#demo11').click(function() {
	            $.blockUI({
	                message: msg,
	                fadeIn: 700,
	                fadeOut: 700,
	                timeout: 3000,
	                showOverlay: false,
	                centerY: false,
	                css: {
	                    width: '220px',
	                    //margin: '0 auto',
	                    top: '25px', 
	                    left: '', 
	                    right: '5px', 
	                    border: 'none',
	                    padding: '5px',
	                    backgroundColor: back,
	                    '-webkit-border-radius': '4px',
	                    '-moz-border-radius': '4px',
	                    opacity: .9,
	                    fontWeight: 'bold',
	                    color: cor
	                }
	            });
	        //});
	    });
		
	}
	
	function idsDivs(classe){	
		arrayDivs=$("."+classe);
		stringArrays='';
		for(t=0;t<arrayDivs.length;t++){
			stringArrays=stringArrays+'_'+arrayDivs[t].id;
		}
		return stringArrays;
	}
	
	function submeter2(formulario,content,pasta,content_form,acao,conteudoSelecionado){

		
	       $("#"+formulario).ajaxSubmit({
	    	   		
	           target: '',
	           url: acao+'&respAjax=1', 
	           type: 'post', 
	           success: function(resposta) {

		   			resposta=replaceAll(resposta,"&amp;","&");
	   			
					resp=resposta.split(',,');
					destino=resp[2];
					
					if(destino){
						if(destino[destino.length-1]==1){
							$("#"+formulario+" input").removeClass("erro");
						}
					}

				   if(resp[1]=='respAjax'){
					    mostraResposta(resp[0]);
					    url=pasta+destino;
						carregarConteudo(content,content_form,url,conteudoSelecionado);
	               }else{
	            	   $(content_form).html(resposta).show();
			       }
	           }
	       
	       		
	       });
	      
	       return true;
		}

	function submeter(formulario,content,pasta,content_form,acao,conteudoSelecionado,alerta){
		
		   $("#"+formulario).ajaxForm(function() {
			   
	       $("#"+formulario).ajaxSubmit({
	    	   		
	               target: '',
	               url: acao+'&respAjax=1', 
	               type: 'post', 
	               success: function(resposta) {
			
	    	   			resposta=replaceAll(resposta,"&amp;","&");
    	   			
						resp=resposta.split(',,');
						destino=resp[2];
						
						if(alerta!=null){
							if(resp[1]=='respAjax'){
								alert(alerta);
							}else{
								
								alert('Verifique se os campos foram preenchidos corretamente.');
							}
						}else{
						
							if(destino){
	
								if(destino[destino.length-1]==1){
									$("#"+formulario+" input").removeClass("erro");
								}
							}
	
						   if(resp[1]=='respAjax'){
							    mostraResposta(resp[0]);
							    url=pasta+destino;
								carregarConteudo(content,content_form,url,conteudoSelecionado);
			               }else{
			            	   $(content_form).html(resposta).show();
					       }
					   
					   }
	               }
	       });
	       
	       return false;
		   });
  
	       
	}
	
    function closeJanelas(){
    	$('.janela').fadeIn(500).dialog('close');
    }
	
    function adicionarConteudo(titulo,divContent,divDestino,url,atualizarConteudo,w,h,mW,mH){
    	
    	if(w==null){
    		w=620;
    	}
    	
    	if(h==null){
    		h=540;
    	}
    	
    	if(mW==null){
    		mW=460;
    	}
    	
    	if(mH==null){
    		mH=260;
    	}

    	var Content=divContent.split('#');
    	

		if(document.getElementById(Content[1])==null){
			$('body').append("<div class='janela' title='"+titulo+"' id='"+Content[1]+"'></div>");
			carregarConteudo(divContent,divDestino,url+'&popup=1');
		}else{
			if(atualizarConteudo){
				carregarConteudo(divContent,divDestino,url+'&popup=1');
			}
		}
		
		//position: ['right','bottom'], 
		
		$(divContent).fadeIn(500).dialog({  stack: true, height: h,width: w,minHeight: h,minWidth: w });	
		$(divContent).fadeIn(500).dialog('open');
		$(divContent).dialog( 'moveToTop' );
		$(divContent).dialog('option', 'title', titulo);
		
    }
    
    
    var destinos = new Array(); 

	function carregarConteudo(elemento,content_destino,url,conteudoSelecionado){
		
		
		if(destinos[elemento]==null){
			destinos[elemento]=content_destino;
		}else{
			content_destino=destinos[elemento];
		}
				
		url=url+"&content="+replaceAll(elemento,'#',';')+"&content_destino="+replaceAll(content_destino,'#',';');	
		
		if(conteudoSelecionado!=null){
			url+=" "+conteudoSelecionado;
		}
		$(function(){$(elemento).load(url);});
		
		
	} 
	
	function selecionarTodos(content){

		var arrayIds = document.getElementById(content).arrayIds;
		var marcarTodos = document.getElementById(content).marcarTodos;
		
		if(!marcarTodos.checked){ 
			b=false;
		} else{ 
			b=true; 
		}
		
		marcarTodos.checked=b;
		
		if(!(arrayIds.length)){
			arrayIds.checked=b;
			
		}else{
			for (var x=0; x < arrayIds.length; x++) {
				arrayIds[x].checked=b;
			}
						
		}
		
		return false;
	}

	
	function is_array(input){
		return typeof(input)=='object'&&(input instanceof Array);
	}


	function confDel(formLista,elemento,elemento_destino,chave,id,destino,destinoFinal){
		
		busca='';

		if(id=='deletarEmMassa'){

			var arrayIDS = buscarSelecionados(formLista);
			
			var stringIds = 'delMassa';

			for (i=0;i<arrayIDS.length;i++){
				stringIds=stringIds+';;'+arrayIDS[i].value;	
			}
			
			id=stringIds;

			
			var arrayIds = document.getElementById(formLista).arrayIds;

			if(document.getElementById(formLista).arrayIds.length==arrayIDS.length || !(arrayIds.length)){
				busca+="&ultimo=1";
			}

		}
		

		if(id=='delMassa'){
			alert('Você precisa selecionar algum item.');
		}else{	
			if (confirm("Tem certeza?")){

		       $("#"+formLista).ajaxSubmit({
		    	   		
		               target: '',
		               url: destino+"&"+chave+"="+id+'&respAjax=1', 
		               type: 'post', 
		               success: function(resposta) {
							
							resp=resposta.split(',,');
							
							destino=resp[2];
							
							
							mostraResposta(resp[0]);
							
							carregarConteudo(elemento,elemento_destino,destinoFinal);
			               
		               }
		       });
	  
		       return false; 
			}
		}
		 
	}

	
	
	function limparCampos(campos){
  		
  		var arrayCampos=campos.split(',');
  		
  		b=0; while(b < arrayCampos.length ){
  			document.getElementById(arrayCampos[b]).value='';
  			b++;
  		}
  	}


	function buscar(form,elemento,elemento_destino,destino,conteudo){
		
		var noincludes='';
		var busca="buscar=";
		for (i=0;i<form.elements.length;i++){
			if(form.elements[i].type != "submit" && form.elements[i].name!='noincludes'){
				if(form.elements[i].type != "radio" && form.elements[i].type != "checkbox" ){
					busca+="||"+form.elements[i].name+"="+form.elements[i].value;
				}else{
					if(form.elements[i].checked == true ){
						busca+="||"+form.elements[i].name+"="+form.elements[i].value;
					}
				}
			}
		}
		caminho=destino+"&"+busca;

		caminho=replaceAll(caminho," ", ";");
		
		if(conteudo!=null){
			caminho+=" "+conteudo;
		}
		
		carregarConteudo(elemento,elemento_destino,caminho);

		
	}
	

	function buscarSelecionados(Elemento){
	

  		var arrayIds = document.getElementById(Elemento).arrayIds; 

  		var cont = 0; 
		
		var arrayIDS = new Array();

		if(!(arrayIds.length)){
			if(arrayIds.checked){
				arrayIDS[0]=arrayIds;
				return arrayIDS;
			}
		}
		
		for (var x=0; x < arrayIds.length; x++) {
			if (arrayIds[x].checked) {
				arrayIDS[cont] = arrayIds[x];
				cont = cont + 1;
			}
  		}
		
		return arrayIDS;
	}
	
	
	
	function setFile(elementId) {
		var win = window.open('../../suportes/ajaxfilemanager/ajaxfilemanager.php?editor=form&elementId='+elementId, 'ajaxFileImageManager', 'width=782,height=500');		
		return false;
	}
	
	function campoData(campo,time){
		

		$(function() {  
		    $(campo).datepicker({
		    	showButtonPanel: true,
				duration: '',
				dateFormat:'dd/mm/yy',  
				showTime: time,  
				constrainInput: false,  
				stepMinutes: 1,  
				stepHours: 1,  
				altTimeField: '',
				changeMonth: false,
				changeYear: false,
				dayNames: ['Domingo', 'Segunda', 'Terça', 'Quata', 'Quita', 'Sexta', 'S&aacute;bado'],
				dayNamesMin: ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'S&aacute;b'],
				dayNamesShort: ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'S&aacute;b'],
				monthNames: ['Janeiro','Fevereiro','Março','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'],
				monthNamesShort: ['Jan','Fev','Mar','Abr','Mai','Jun','Jul','Ago','Set','Out','Nov','Dez'],
		        time24h: true  
		     });
		    

		});
		
	}
	
	
	
	
	
	



