var Util = new Class({
	vazio: function() {},

	options: {
		base_url:'',
		site_url:'',
		suffix_url:'',
		method:'get'
	},

	call: function(uri, data, response, method)
	{
		
		var site_url = util.options.site_url;        
		data = data!=null ?data :null;
        response = response!=null ?response :new Util().vazio;

        if (site_url.substr(site_url.length-1, 1) != '/' )
            site_url+= '/';
			
        var url = site_url + 'json/' + uri + this.options.suffix_url;
        response = (response!=null) ?response :this.vazio;
        method = (method!=null) ?method :this.options.method;
        
        new Request.JSON({
            url: url,
            method: method,
            onComplete: response,
            data: data
        }).send();
    },
    callHTML: function(uri, data, response, method)
	{
		
		var site_url = this.options.site_url;
        data = data!=null ?data :null;
        response = response!=null ?response :new Util().vazio;

        if (site_url.substr(site_url.length-1, 1) != '/' )
            site_url+= '/';
			
        var url = site_url + 'json/' + uri + this.options.suffix_url;
        response = (response!=null) ?response :this.vazio;
        method = (method!=null) ?method :this.options.method;
        
        new Request({
            url: url,
            method: method,
            onComplete: response,
            data: data
        }).send();
    },
	soNums: function(e)
    {
        if (document.all){var evt=event.keyCode;} // caso seja IE
        else{var evt = e.charCode;}    // do contrrio deve ser Mozilla
        var valid_chars = '0123456789';    // criando a lista de teclas permitidas
        var chr= String.fromCharCode(evt);    // pegando a tecla digitada
        if (valid_chars.indexOf(chr)>-1 ){return true;}    // se a tecla estiver na lista de permisso permite-a
        // para permitir teclas como <BACKSPACE> adicionamos uma permisso para
        // cdigos de tecla menores que 09 por exemplo (geralmente uso menores que 20)
        if (valid_chars.indexOf(chr)>-1 || evt < 9){return true;}    // se a tecla estiver na lista de permisso permite-a
        return false;    // do contrrio nega
    },
	mouseover: function(obj)
    {
            obj.bgColor='#e0e0e0';
            //obj.style.cursor='pointer';
    },
	mouseout: function(obj)
    {
            obj.bgColor='#ffffff';
            //obj.style.cursor='pointer';
    }, 
    ativaAba:function(id)
    {
    	for(i=1;i<=7;i++)
    	{
    		if($("orcamento_form_"+i))
    		{
    			if(i==id)
    			{
    				$("orcamento_form_"+i).style.display = "block";
    				
    				$("link_"+id).addClass("current");
    			}else{
    				$("orcamento_form_"+i).style.display = "none";
    				
    				$("link_"+i).removeClass("current");
    			}	
    		}	
    	}	
    },	
	selOrcamento:function(id)
	{
		var orcamentos =  $$('.orcamentos');
		
		
		for(var i = 0; orcamentos.length > i ; i++)
		{
			orcamentos[i].style.display = 'none';
		}    
		
		$(id).style.display = '';
				
	},
	verifica: function(form)
	{
	    var erro = 0;
        var reEmail2 = /^[\w-]+(\.[\w-]+)*@(([\w-]{2,63}\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;

        if($('mail'))
        {
            if( !reEmail2.test( $('mail').value ))
            {
                $('mail').style.border = '1px solid red';
                              
                $('error_mail').innerHTML = 'Esse n&atilde;o &eacute; um e-mail v&aacute;lido';
                
                erro ++;
              }
              else
              {
                $('mail').style.border = '1px solid #54807f';
                              
                $('error_mail').innerHTML = '';
                
              }
          }
        if($('text'))
        {
            if ($('text').value.length < 10)
            {
                $('text').style.border = '1px solid red';
                              
                $('error_text').innerHTML = 'Campo n&atilde; tem que conter no m&iacute;nimo 10 caracteres ';
                erro ++;
              }    
              else
              {
                  $('text').style.border = '1px solid #54807f';
                              
                $('error_text').innerHTML = '';
                
              }
        
        }
        
        if(erro == 0)
        {
            $(form).submit();
        }
	},
	aba:function(open)
    {	
		var abas = $$('.aba');		
		
		for ( var i = 0; i < abas.length; i++ )
		{				
			slideup(abas[i].id); 
			
			str = new String(abas[i].id);		
            
            if(str.indexOf('idioma_' + open + '_') == 0)
            	slidedown(str); 
			
		}			
		
    },
	template:function(id)
    {
    	
    	$(id).submit();	
		
		
    },
    submenu:function(obj,id)
    {    				
    	    	
    	if(obj.className == 'menos')
		{
			obj.className = 'mais';
			$(id).style.display = 'none';
		}
		else	
		{
			obj.className = 'menos';
			$(id).style.display = '';
			
		}	
		
    },
    montaPagina: function( combo, value )
    { 	
    	util.callHTML('home/paginaSub/' + value + '/' + combo ,null, function(response)
    	{
    	
	    	var id_sub = parseInt(combo) + 1;
	    		    		
	    	if(response != null)
	        {	    			    	
	        		$('pag_pag_id').value = value;
	    			
	    			if(combo == 1)
	    			{
	    				$('sub').innerHTML= response;	    				    				
	    			}
	    			else
	    			{		    					    			
		    			if($('sub_'+ id_sub) )
		    			{    					    								
		    				$('sub').removeChild($('sub_'+ id_sub)) ;
		    			}
		    			
		    			$('sub').innerHTML += response;
		    			
		    			
	    			}		
	        }
    	});
    },
	getImage: function(nome)
	{
    	util.callHTML('combo/getByNome/' + nome ,null,function(response)
    	{    	    			    			    	    		
    		//$('img_form_1').innerHTML =	response;
    		var result = JSON.decode(response);
    		$('img_form_1').innerHTML =	result.img;
    		
    		if($('frase_auxiliar'))
    			$("frase_auxiliar").innerHTML = result.frase;
    		
    		var comando = nome; 
    		
    		$('qtd_parada').empty();
    		
    		if(comando.indexOf("GENIUS") != -1 || comando.indexOf("IFL") != -1 )
    		{
    			for(i=1;i<=32;i++)
    			{
    				var opt = new Option(i,i);
    				opt.inject($('qtd_parada'));
    			}
    		}else{
    			if(comando.indexOf("JR") != -1)
    			{
        			for(i=1;i<=9;i++)
        			{
        				var opt = new Option(i,i);
        				opt.inject($('qtd_parada'));
        			}
    			}
    		}
    	});
	}
});


var obj;
var tagname = new Array('a', 'img', 'address');

var tooltip = {
	
	init: function(){
				
		obj = document.createElement('div');
		obj.setAttribute('id', 'tooltip');
		
		document.body.appendChild(obj);
		
		window.document.onmousemove = this.move;
		
		for(var i = 0; i < tagname.length; i++){
			
			var ancora = document.getElementsByTagName(tagname[i]);
			
			for(var j = 0; j < ancora.length; j++){
				
				var a = ancora[j];
				texttitle = a.getAttribute('title');
				
				if(texttitle){
					
					a.setAttribute('sTitle', texttitle);
					a.removeAttribute('title');
					
					a.onmouseover = function(){
						
						t = this.getAttribute('sTitle');
						
						obj.innerHTML = t;
						obj.style.display = 'block';
						
					};// end function
					
					a.onmouseout = function(){
						
						obj.innerHTML = '';
						obj.style.display = 'none';
						
					};// end function
					
				}//end if
				
			}//end for
			
		}//end for
		
	},
	
	move: function(e){
		
		e = e || window.event;
		
		if(e.pageX || e.pageY){
			
			x = e.pageX;
			y = e.pageY;
			
		}else{
			
			x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
			y = e.clientY + (document.documentElement.scrollTop ||  document.body.scrollTop) -  document.documentElement.clientTop;
			
		}//end if
		
		obj.style.left = (x+5)+'px';
		obj.style.top = (y-35)+'px';
		obj.style.position = 'absolute';
		
		return true;
		
	}	
};


