//--------------------------------------------------------------------//
// fctCheck()                                                    //
// Checkbox de busca                                       //
// Criado por: Victor Leonardo Data: 08/01/2008  //
// Modificado por:                 Em: __/__/____    //
//----------------------------------------------------------------//
var classes;
var categorias;

function fctCheck(){
    var checks = $$('.check_list').getElements('a');
    var btnBuscar = $$('.btn_busca');
	var btnFechar = $$('.btn_fechar');
    var exibe = false;

    btnBuscar.addEvent("click", function(){
        if(exibe == false){
            $$(".float_busca").setStyle("display", "block");
            exibe = true;
        }
        else{
            $$(".float_busca").setStyle("display", "none");
            exibe = false;
        }
    });

	btnFechar.addEvent("click", function(){
        if(exibe == false){
            $$(".float_busca").setStyle("display", "block");
            exibe = true;
        }
        else{
            $$(".float_busca").setStyle("display", "none");
            exibe = false;
        }
    });
    
    checks.each(function(li, index){

            li.addEvent("click", function(){			

                if(this.hasClass("op_contem") == false && this.hasClass("op_nao_contem") == false){
                    this.addClass('op_contem');
                    this.setProperty('checked','true');
			
					classes = new CriaArray(checks[0].length);
					categorias = new CriaArray(checks[0].length);

					for(i = 0; i < checks[0].length; i++)
					{
						classes[i] = li[i].className;
						categorias[i] = li[i].innerHTML;
					}
                    return;
                }

                else if(this.hasClass("op_contem") == true){
                    this.removeClass("op_contem");
                    this.addClass('op_nao_contem');

					classes = new CriaArray(checks[0].length);
					categorias = new CriaArray(checks[0].length);

					for(i = 0; i < checks[0].length; i++)
					{
						classes[i] = li[i].className;
						categorias[i] = li[i].innerHTML;
					}
                    return;
                }

                else if(this.hasClass("op_nao_contem") == true){
                    this.removeClass("op_nao_contem");

					classes = new CriaArray(checks[0].length);
					categorias = new CriaArray(checks[0].length);

					for(i = 0; i < checks[0].length; i++)
					{
						classes[i] = li[i].className;
						categorias[i] = li[i].innerHTML;
					}
                }
            });
    });
}

function CriaArray(n){
this.length=n
for(var i=0;i<=n-1;i++){
  this[i]=null;
}
}


function fctMenus(){
    var btnBuscar = $$('.btn_veja_mais');
	var btnFechar = $$('.btn_fechar_veja_mais');
    var exibe = false;

    btnBuscar.addEvent("click", function(){
        if(exibe == false){
            $$(".float_veja_mais").setStyle("display", "block");
            exibe = true;
        }
        else{
            $$(".float_veja_mais").setStyle("display", "none");
            exibe = false;
        }
    });

	btnFechar.addEvent("click", function(){
        if(exibe == false){
            $$(".float_veja_mais").setStyle("display", "block");
            exibe = true;
        }
        else{
            $$(".float_veja_mais").setStyle("display", "none");
            exibe = false;
        }
    });
}

//-----------------------------------------------//
// fctFonte()                                    //
// Ajusta tamanho da fonte                       //
// Criado por: Victor Leonardo Data: 10/01/2008  //
// Modificado por:             Em: __/__/____    //
//-----------------------------------------------//

function fctFonte(){
    if($$('.fonte') != ""){
        var tamPequeno = $$('.pequeno');
        var tamMedio = $$('.medio');
        var tamGrande = $$('.grande');

        tamPequeno.addEvent("click", function(){
            $$(".texto").setStyle('font-size', '100%');
        });
        tamMedio.addEvent("click", function(){
            $$(".texto").setStyle('font-size', '120%');
        });
        tamGrande.addEvent("click", function(){
            $$(".texto").setStyle('font-size', '140%');
        });
    }
    else{return};
}

//-----------------------------------------------//
// fctValidacao()                                //
// Controla as mensagens de validação            //
// Criado por: Victor Leonardo Data: 21/01/2008  //
// Modificado por:             Em: __/__/____    //
//-----------------------------------------------//

function fctValidacao(){
    if($$('.deixe_comentario') !=""){
        var inputs = $$('.deixe_comentario').getElements('input');

        inputs.each(function(inp, index){
            inp.addEvent("keypress", function(e){
                e = new Event(e);
                    if(e.key == "tab" || e.key == "backspace" || e.key == "esc" || e.key =="delete" || e.key=="space"){return;}
                if($$('.msg_nome') != ""){
                    $$('.msg_nome').setStyle('display', 'none');
                    return;
                }
                if($$('.msg_mail') != ""){
                    $$('.msg_mail').setStyle('display', 'none');
                    return;
                }
                if($$('.msg_comentario') != ""){
                    $$('.msg_comentario').setStyle('display', 'none');
                    return;
                }
            });

        });
    }
}

//--------------------------------------------------------------------//
// fctCss()                                                    //
// Carrega CSS apenas da interna                         //
// Criado por: Victor Leonardo Data: 28/01/2008  //
// Modificado por:                 Em: __/__/____    //
//----------------------------------------------------------------//

function fctCss(){
    if($$('.con_interna') != ""){
        new Asset.css('layout/css/interna.css?cache=1', {id: 'estiloInterna', title: 'estiloInterna'});
    }
    if (window.ie6 == true){
        new Asset.css('layout/css/estilo_ie6.css?cache=1', {id: 'estiloIE6', title: 'estiloIE6'});
    }
    else{
        return;
    }
}

//################################################################################//

//  Function:       Mascara()																		                    //                                                                                                                 //
//  Criador:			 Rafael Une.																						//
//  Description:              Cria uma mascara no campo informado de acordo com				//
//									o tipo do campo.											                        //

//################################################################################//
function Mascara(tipo, campo, teclaPress) {
	if (window.event)
	{
		var tecla = teclaPress.keyCode;
	} else {
		tecla = teclaPress.which;
	}
 
	var s = new String(campo.value);
	// Remove todos os caracteres à seguir: ( ) / - . e espaço, para tratar a string denovo.
	s = s.replace(/(\.|\(|\)|\/|\-| )+/g,'');
 
	tam = s.length + 1;
 
	if ( tecla != 9 && tecla != 8 ) {
		switch (tipo)
		{
		case 'CPF' :
			if (tam > 3 && tam < 7)
				campo.value = s.substr(0,3) + '.' + s.substr(3, tam);
			if (tam >= 7 && tam < 10)
				campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,tam-6);
			if (tam >= 10 && tam < 12)
				campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,3) + '-' + s.substr(9,tam-9);
		break;
 
		case 'CNPJ' :
 
			if (tam > 2 && tam < 6)
				campo.value = s.substr(0,2) + '.' + s.substr(2, tam);
			if (tam >= 6 && tam < 9)
				campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,tam-5);
			if (tam >= 9 && tam < 13)
				campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,tam-8);
			if (tam >= 13 && tam < 15)
				campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,4)+ '-' + s.substr(12,tam-12);
		break;
 
		case 'TEL' :
			if (tam > 2 && tam < 4)
				campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,tam);
			if (tam >= 7 && tam < 11)
				campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,4) + '-' + s.substr(6,tam-6);
		break;
 
		case 'DATA' :
			if (tam > 2 && tam < 4)
				campo.value = s.substr(0,2) + '/' + s.substr(2, tam);
			if (tam > 4 && tam < 11)
				campo.value = s.substr(0,2) + '/' + s.substr(2,2) + '/' + s.substr(4,tam-4);
		break;
		}
	}
}

window.addEvent('domready', function(){
    fctCheck();
    fctMenus();
    fctFonte();
    fctCss();
    fctValidacao();
});

/*
|----------------------------------------------------------------------------------------------------|
|           Função: OnlyNumbersData()                                                                |
|        Descrição: Permite somente números entre 0 e 9 e as "/" para data.                          |
|  ================================================================================================  |
|       Parâmetros: oEvent = Objeto event, necessário para funcionar Cross-Browser                   |
|           Evento: onkeypress                                                                       |
|  Tipo de Retorno: void                                                                             |
|  ================================================================================================  |
|           Criado: 19/02/2008 | Por: Clayton Caliari                                                |
|       Modificado: __/__/____ | Por:                                                                |
|----------------------------------------------------------------------------------------------------|
*/
function OnlyNumbersData(src, mask, oEvent)
{
    var oRegExp = /[0-9]/;
    var tecla_codigo;
    var tecla_char;
    
    if (oEvent.keyCode)
        tecla_codigo = oEvent.keyCode;
    else if (oEvent.which)
        tecla_codigo = oEvent.which;
    
    tecla_char = String.fromCharCode(tecla_codigo);
    
    var i = src.value.length;
    var saida = mask.substring(0,1);
    var texto = mask.substring(i);
    if (texto.substring(0,1) != saida)
    {
        if (tecla_codigo != 8)
            src.value += texto.substring(0,1);
    }
        
    //Permite algumas teclas
    if (tecla_codigo == 8 || tecla_codigo == 9 || (tecla_codigo == 35 && oEvent.shiftKey) || (tecla_codigo == 36 && oEvent.shiftKey) || (tecla_codigo == 37 && (oEvent.shiftKey || tecla_char != '%')) || (tecla_codigo == 39 && tecla_char != "'") || (tecla_codigo == 46 && tecla_char != '.') || (tecla_codigo == 47))
    {                
        return true;
    }
    //Se for número
    else if (!oRegExp.test(tecla_char))
        return false;
    //Se não for número
    else
        return true;
}
var markers = null;
var map;
var endereco;
//-----------------------------------------------//
// Script show_map - Kopenhagem                  //
// Criado por: Clayton Caliari Data: 26/03/2008  //
// Modificado por:             Em: __/__/____    //
//-----------------------------------------------//
function show_map(latitude, longitude, titulo, rua, numero, bairro, cidadesestado, cep, telefone, ddd, url_balao)
{          
     if (GBrowserIsCompatible()) {
        map = new GMap2($("contain_map"));
        //Centraliza o mapa de acordo com essas coordenadas. Aproximadamente perto do Distrito Federal - Brasil.
        map.setCenter(new GLatLng(-14.349548, -50.361328), 4);
        
        latitudes = latitude.split("#");
        longitudes = longitude.split("#");
        titulos = titulo.split("#");
        ruas = rua.split("#");
        bairros = bairro.split("#");
        numeros = numero.split("#");
        cidadesestados = cidadesestado.split("#");
        ceps = cep.split("#");	
		telefones = telefone.split("#");
		ddds = ddd.split("#");

		textos_balao = new CriaArray(latitudes.length);
		markers = new CriaArray(latitudes.length);

        for(i=1; i< latitudes.length; i++)
        {    
            //Configuracao da latitude e longitude
            var point = new GLatLng(latitudes[i], longitudes[i], true);

            //Formata o texto que será exibido no balão de informacoes.
			var text = "<div><h3 style='font-style:normal; font-weight: 800; font-family:Trebuchet ms; float: left; width:290px;'>" + titulos[i] + "</h3>";
			    text += "<br/>";
			    text += "<p style='clear: both; width: 280px;'>" + ruas[i] + "," + numeros[i] + " - " + bairros[i] + " - " + cidadesestados[i] + "</p>";
			    text += "<p style='width: 280px;'>CEP: " + ceps[i] + "</p>";
			    if(telefones[i] != '')
			        text += "<b>Tel:(" + ddds[i] + ") " + telefones[i] + "</b><br /><br />";
			    
			    endereco = ruas[i] + "," + numeros[i] + " - " + bairros[i] + " - " + cidadesestados[i];
			    text += "<div id='todos'>";
			        text += "Como Chegar: <a href='http://maps.google.com.br/maps?daddr="+ endereco +"&geocode=&dirflg=&saddr=&f=d&sll=-23.233223,-45.87822&sspn=0.052133,0.075188&ie=UTF8&z=10' target='_blank' title='Para cá'>Para cá</a> - <a href='http://maps.google.com.br/maps?daddr=&geocode=&dirflg=&saddr="+ endereco +"&f=d&sll=-23.233223,-45.87822&sspn=0.052133,0.075188&ie=UTF8&z=10' target='_blank' title='Daqui'>Daqui</a>";
			    text += "</div>";			
			text += "</div>";

			//armazena o texto formato no array
			textos_balao[i] = text;
            
            	//Adiciona marcação do local.	

			function createMarker(point, text)
			{
			    //Configuracoes do icone
			     var blueIcon = new GIcon(G_DEFAULT_ICON);
			     blueIcon.image = url_balao;//"http://gmaps-samples.googlecode.com/svn/trunk/markers/blue/blank.png";
			     blueIcon.iconSize = new GSize(22,34);
			     markerOptions = { icon:blueIcon };
    	 
			     //Criando o icone.
			     var marker = new GMarker(point, markerOptions);
			     //Adicionando o evento clique.
			     GEvent.addListener(marker,"click", function() {
				    map.openInfoWindowHtml(point, text);
			    });
			    
			    return marker;
		    }
			
            
            //Adiciona o icone
		    map.addOverlay(createMarker(point, textos_balao[i]));
        }
        
		map.setCenter(new GLatLng(latitudes[1],longitudes[1]), 15);
		 
        //Adiciona controles do mapa
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
      }
}
//-----------------------------------------------//
// Script fctClearText - Kopenhagem              //
// Criado por: Clayton Caliari Data: 28/03/2008  //
// Modificado por:             Em: __/__/____    //
//-----------------------------------------------//
function fctClearText(txtclientID)
{
	document.getElementById(txtclientID).value = '';
}
//-----------------------------------------------//
// Script fctCompletText - Kopenhagem            //
// Criado por: Clayton Caliari Data: 28/03/2008  //
// Modificado por:             Em: __/__/____    //
//-----------------------------------------------//
function fctCompletText(txtclientID)
{
    if(document.getElementById(txtclientID).value == '')
	    document.getElementById(txtclientID).value = 'Ex.: São Paulo,SP';
}
//-----------------------------------------------//
// Script fctShowGoogleMap - Kopenhagem            //
// Criado por: Clayton Caliari Data: 17/06/2008  //
// Modificado por:             Em: __/__/____    //
//-----------------------------------------------//
function fctShowGoogleMap(id)
{
    window.open('addons/GoogleMaps.aspx?lid='+ id,'','menubar=0,resizable=0,width=630,height=300');
}

//----------------------------------------------//
// Script show_map - Kopenhagem  //  
// Criado por: Clayton Caliari Data: 18/06/2008 //
// Modificado por:             Em: __/__/____   //
//----------------------------------------------/
function show_map_rote(origem)
{
       var rota;
       switch(origem)
        {
            case 1:
                rota = document.getElementById('txtPartida').value;
            break;
            case 2:
                rota = document.getElementById('txtDestino').value;
            break;
        }
       
      if (GBrowserIsCompatible()) {      
        document.getElementById("contain_map").innerHTML = "";
        map = new GMap2(document.getElementById("contain_map"));
        
        gdir = new GDirections(map);
        GEvent.addListener(gdir, "error", handleErrors);

        switch(origem)
        {
            case 1:
                gdir.load("from: " + rota + " to: " + endereco,
                    { "locale": "pt_BR" });
            break;
            case 2:
                gdir.load("from: " + endereco + " to: " + rota,
                    { "locale": "pt_BR" });
            break;
        }
		
        //Adiciona controles do mapa
        map.addControl(new GMapTypeControl());
    }
}