Util = {

	
		formatDefine:
                function(value,format){

                      value = value.replace(/\D/g,"");
                      var result="";

                      if(format.length < value.length)
                              return value;

                      for(i=0,j=0;(i<format.length)&&(j<value.length);i++)
                      {
                              var ch = format.charAt(i) ;
                              if(ch == '#')
                              {
                                      result += value.charAt(j++);
                                      continue;
                              }
                              result += ch;
                      }
                      return result;
                },
		
				
		removeItem:
                          function(_objSelect,_str)
                          {
                                  var objSelect = document.getElementById(_objSelect);
                                  var str = document.getElementById(_str);
                                  if ( objSelect.length == 0){
                                          alert("Não há itens a serem removidos!");
                                          return false;
                                  }	
                                  if( objSelect.selectedIndex == -1 ){
                                          alert("Selecione um item na lista");
                                          return false;
                                  }
                                  objSelect.remove(objSelect.selectedIndex);
                                  this.agruparItens(objSelect,str);
                          },

				
		copyOption:
                        function (_origem, _destino,_str)
                        {
                              var origem = document.getElementById(_origem);
                              var destino = document.getElementById(_destino);
                              var str = document.getElementById(_str);
                              var i=0;

                              // Somente se um item for selecionado na origem
                              if( origem.selectedIndex >= 1)
                              {
                                      // Checando se o item já está cadastrado
                                      for( i=0; i < destino.length; i++ )
                                      {
                                              if( destino.options[i].value == origem.options[origem.selectedIndex].value)
                                              {
                                                      alert('Item já está relacionado!');
                                                      return false;
                                              }
                                      }
                                      destino.options[destino.length] = new Option(origem.options[origem.selectedIndex].text, origem.options[origem.selectedIndex].value);
                                      //origem.remove(origem.selectedIndex);
                                      this.agruparItens(destino,str);

                              }else{
                                      alert("Selecione um item na lista!");
                              }
                        },
		

				
		agruparItens:
                        function (origem, destino)
                        {
                                //var origem = document.getElementById(_origem);
                                //var destino = document.getElementById(_destino);
                                var i = 0;
                                var str = "";

                                for( i=0; i < origem.length; i++ )
                                {		
                                        str += origem.options[i].value+"|";
                                        //alert(str);
                                }

                                // Retirando o '|' final 
								//alert(destino);
                                destino.value = str.substr(0, (str.length -1));
                                
                        },

				
		mostraAlert:
				function()
				{
					alert("teste");
				}
			
				
					
}

		

	
//		function addHandle(obj, funcao, evento){
//			if (window.addEventListener)
//				obj.addEventListener(evento, funcao, true);
//			else if (window.attachEvent)
//					obj.attachEvent("on"+evento, funcao);
//		}
			
		//addHandle(document.getElementById("bt_add"), Util.mostraAlert(), "click");
		
		
		
		//document.getElementById("bt_add").onclick = function(){alert("Teste")};
		//var obj = document.getElementById("bt_add");
		//document.addEventListener("click", function(event) { alert(event); }, false);
		//obj.addEventListener("click", Util.mostraAlert(), false)
		//document.addEventListene


		
	
	
	
	
	
	
	
	
	
	
	
		
