﻿// Início - Carrega scripts.
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

window.onload = function() {
    GoogleAnalytics();
}
// Fim - Carrega scripts.

Local = [];
Local.push({ cod: 1, nome: 'Sede Corporativa', end: 'Av. Barão Homem de Melo, 4500 | Point Office Tower - 6º Andar | Estoril - Belo Horizonte - MG | CEP 30450-250', tel: '+55 (31) 3064-6600', lat: -19.965557, log: -43.955406 });
Local.push({ cod: 2, nome: 'Filial Fortaleza', end: 'Rua Dom Luiz, 300 | Sala 1226 | Aldeota - Fortaleza - CE | CEP 60150-150', tel: '+55 (85) 3264-9720', lat: -3.732917, log: -38.498636 });
Local.push({ cod: 3, nome: 'Filial Salvador', end: 'Av. Brasil, 129 | Sala 01 | Centro - Dias D Ávila - BA | CEP 42850-000', tel: '+55 (71) 4102-6074|+55 (71) 9151-8026', lat: -12.610359, log: -38.298249 });
var ctlTime = false;
var ctlTimeSuporte = false;

function Login() {
    // Início - Recebendo dados.
    var Login = CBoxLogin.GetValue();
    var Senha = CBoxSenha.GetValue();
	// Fim - Recebendo dados.

	// Início - Validando dados.
	MSGRetorno(null);
	if (Login == null) {
	    MSGRetorno('O campo Login não pode ficar em branco!');
	    return null;
	}
	if (Senha == null) {
	    MSGRetorno('O campo Senha não pode ficar em branco!');
	    return null;
	}
	CBoxSenha.SetValue('');
	// Fim - Validando dados.

	updPanel.PerformCallback("{Categoria:'LOGIN',Param: ['" + Login + "', '" + Senha + "'] }");

	callSuporte();
}

function AbreApp(app) {
    MSGRetorno(null);
    window.open('download.ashx?app=' + app, 'Download');
}

function AbreNoticia(idNoticia) {
    MSGRetorno(null);
    updPanel.PerformCallback("{Categoria:'NOTICIA',Param: ['" + idNoticia + "'] }");
}

function AbreCategoria(nomeCat) {
    ctlTime = false;
    MSGRetorno(null);
    updPanel.PerformCallback("{Categoria:'" + nomeCat + "',Param: [] }");
    switch (nomeCat.toString().toUpperCase()) {
        case "EMPRESA":
            callMaps()
            break;
        default:
            window.clearTimeout();
            break;
    }
}

function callSuporte() {
    window.setTimeout('validaLogin()', 2)
}

function callMaps() {
    window.setTimeout('validaObjMaps()', 2)
}

// Início - UnsoftChat Suporte.
var Suporte = { Param: [], Log:false };

function validaLogin() {
    objNome = $('#ClienteNome');
    objEmail = $('#ClienteEmail');
    
    if (!ctlTimeSuporte) {
        
        if (objNome.val() == undefined || objEmail.val()== undefined) {
            callSuporte();
            return;
        } else {
            ctlTimeSuporte = true;
            window.clearTimeout();
            
            var objImagem = $('#UnsoftChatImagem');
            var imgAtual = objImagem.attr("src");
            
            objImagem.attr("src", imgAtual.replace('atendimentoComercialIco', 'suporteOnlineIco'));
            
            Suporte.Param.push('Nome=' + objNome.val());
            Suporte.Param.push('Email=' + objEmail.val());
            Suporte.Log = true;
            
            objImagem.removeAttr('onclick');
            objImagem.unbind();
            objImagem.bind('click',function() {
                AbreUnsoftChatSuporte(Suporte.Param.toString().replaceAll(',', '&')); 
            });
        }
    }
}

function AbreUnsoftChatSuporte(param) {
    var url = 'http://www.unsoft.com.br/chatSuporte';
    AbreUnsoftChat(url,param);
}

function AbreUnsoftChat(url,param) {

    if (url==null)
        url = 'http://www.unsoft.com.br/chat';
    if (param==null)
        param='';
    
    var iframe = '<iframe id="UnsoftChat" frameborder="0" allowTransparency="true" class="UnsoftFrameChat" src="' + url + '/UnsoftChat.htm?' + param + '" />';
    
    $(iframe).dialog({
        title: 'UnsoftChat',
        autoOpen: true,
        width: 400,
        height: 490,
        modal: false,
        resizable: false,
        autoResize: false,
        open: function(ev, ui) {
            $("#UnsoftChat").css('width', '98%');
            $("#UnsoftChat").css('heigth', '98%');
        },
        close: function(ev, ui) { $(this).remove(); }
    });
}
// Fim - UnsoftChat.

function ReenvioSenha() {
    // Início - Recebendo dados.
    var Login = CLogin.GetValue();
    var Email = CEmail.GetValue();

    if (Login == null && Email == null) {
        MSGRetorno('O campo Login ou Email deve ser preenchido!');
        return null;
    } else if (Email != null) {
        if (!validaEmail(Email)) {
            MSGRetorno('O Email informado é inválido!');
            return null;
        }
    }

    MSGRetorno(null);
    updPanel.PerformCallback("{Categoria:'REENVIOSENHA',Param: ['" + Login + "', '" + Email + "'] }");
}

function EnviaContato() {

    // Início - Recebendo dados.
    var Nome = CNome.GetValue();
    var Email = CEmail.GetValue();
    var Empresa = CEmpresa.GetValue();
    var Telefone = CTelefone.GetValue();
    var Assunto = CAssunto.GetValue();
    var Mensagem = CMensagem.GetValue();
    // Fim - Recebendo dados.

    // Início - Validando dados.
    if (Nome == null) {
        Sinalizador(LoadObj('Nome'),CNome, true);
        MSGRetorno('O campo Nome não pode ficar em branco!');
        return null;
    } else
        Sinalizador(LoadObj('Nome'),CNome, false);

    if (Email == null) {
        Sinalizador(LoadObj('Email'), CEmail, true);
        MSGRetorno('O campo Email não pode ficar em branco!');
        return null;
    } else {

        if (!validaEmail(Email)) {
            Sinalizador(LoadObj('Email'), CEmail, true);
            MSGRetorno('O Email informado é inválido!');
            return null;
        } else
            Sinalizador(LoadObj('Email'), CEmail, false);
     }

    if (Assunto == null) {
        Sinalizador(LoadObj('Assunto'),CAssunto, true);
        MSGRetorno('O campo Assunto não pode ficar em branco!');
        return null;
    } else
        Sinalizador(LoadObj('Assunto'),CAssunto, false);

    if (Mensagem == null) {
        Sinalizador(LoadObj('Mensagem'),CMensagem, true);
        MSGRetorno('O campo Mensagem não pode ficar em branco!');
        return null;
    } else
        Sinalizador(LoadObj('Mensagem'),CMensagem, false);
    // Fim - Validando dados.

    MSGRetorno(null);
    updPanel.PerformCallback("{Categoria:'CONTATO',Param: ['" + Nome + "', '" + Email + "', '" + Empresa + "', '" + Telefone + "', '" + Assunto + "', '" + Mensagem + "'] }");
}

function EnviaTestDrive() {

    // Início - Recebendo dados.
    var Nome = CNome.GetValue();
    var Email = CEmail.GetValue();
    var Empresa = CEmpresa.GetValue();
    var Telefone = CTelefone.GetValue();
    var ADMWIN = CADMWIN.GetValue();
    var CPVWIN = CCPVWIN.GetValue();
    var CONTFIN = CCONTFIN.GetValue();
    var CONDWIN = CCONDWIN.GetValue();
    var CRMWIN = CCRMWIN.GetValue();
    var JURWIN = CJURWIN.GetValue();
    var CTBWIN = CCTBWIN.GetValue();
    var WEBDIRECT = CWEBDIRECT.GetValue();
    var NFSESMART = CNFSESMART.GetValue();
    var ComoConheceu = CComoConheceu.GetValue();
    // Fim - Recebendo dados.

    // Início - Validando dados.
    if (Nome == null) {
        Sinalizador(LoadObj('Nome'), CNome, true);
        MSGRetorno('O campo Nome não pode ficar em branco!');
        return null;
    } else
        Sinalizador(LoadObj('Nome'), CNome, false);

    if (Email == null) {
        Sinalizador(LoadObj('Email'), CEmail, true);
        MSGRetorno('O campo Email não pode ficar em branco!');
        return null;
    } else {

        if (!validaEmail(Email)) {
            Sinalizador(LoadObj('Email'), CEmail, true);
            MSGRetorno('O Email informado é inválido!');
            return null;
        } else
            Sinalizador(LoadObj('Email'), CEmail, false);
    }
    // Fim - Validando dados.

    var Param = [];
    Param.push("'" + Nome + "'");
    Param.push("'" + Email + "'");
    Param.push("'" + Empresa + "'");
    Param.push("'" + Telefone + "'");
    Param.push("'" + ADMWIN + "'");
    Param.push("'" + CPVWIN + "'");
    Param.push("'" + CONTFIN + "'");
    Param.push("'" + CONDWIN + "'");
    Param.push("'" + CRMWIN + "'");
    Param.push("'" + JURWIN + "'");
    Param.push("'" + CTBWIN + "'");
    Param.push("'" + WEBDIRECT + "'");
    Param.push("'" + NFSESMART + "'");
    Param.push("'" + ComoConheceu + "'");

    MSGRetorno(null);
    updPanel.PerformCallback("{Categoria:'TESTDRIVE',Param: [" + Param.toString() + "] }");
    
}

function MSGRetorno(strRetorno) {
    objRetorno = LoadObj('MSGRetorno');
    objRetorno.html('&nbsp;'+strRetorno+'&nbsp;');
    if (strRetorno == null)
        objRetorno.hide();
    else
        objRetorno.show("slow");
}

function LoadObj(Nome) {
    return $('#'+Nome);
}

function Sinalizador(objSinalizador,objTXT, truefalse) {
    if (typeof objSinalizador != null) {
        if (truefalse) {
            $(objSinalizador).show();
            objTXT.SetFocus();
        }
        else
            $(objSinalizador).hide();
    }
}

function retQuebra(str) {
    var param = str.split('|');
    var strret = '';
    for (var x = 0; x < param.length; x++) {
        strret += param[x] + '<br>';
    }
    return strret;
}

function validaEmail(strEmail) {
    var chaveexp = /^[A-Za-z0-9._\-]{2,}\@[.a-zA-Z0-9]{3,}\.[a-zA-Z]{2,3}$/;
    return chaveexp.test(strEmail);
}

function validaObjMaps() {
    if (document.getElementById("map_canvas") && !ctlTime) {
        initialize()
        ctlTime = true;
    } else
        callMaps();
}

// Início - Funcionalidades do google maps.
function createMarker(index) {
    // Create a lettered icon for this point using our icon class
    var tinyIcon = new GIcon();
    tinyIcon.image = "imgs/LogoGmaps.png";
    //tinyIcon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
    tinyIcon.iconSize = new GSize(26, 23);
    tinyIcon.shadowSize = new GSize(26, 23);
    tinyIcon.iconAnchor = new GPoint(26, 23);
    tinyIcon.infoWindowAnchor = new GPoint(5, 1);

    // Set up our GMarkerOptions object
    markerOptions = { icon: tinyIcon };
    var marker = new GMarker(new GLatLng(Local[index].lat, Local[index].log), markerOptions);

    GEvent.addListener(marker, "click", function() {
        marker.openInfoWindowHtml("<b>" + Local[index].nome + "</b><br>" + retQuebra(Local[index].end) + "<br>" + retQuebra(Local[index].tel));
    });
    return marker;
}

var map = null;
function initialize() {
    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        PosCentralMapa();

        for (var i = 0; i < Local.length; i++)
            map.addOverlay(createMarker(i));
    }
}

function ApontaMapa(index) {
    if (map != null) {
        map.setCenter(new GLatLng(Local[index].lat, Local[index].log), 17);
    }
}

function PosCentralMapa() {
    map.setCenter(new GLatLng(-15.284185, -57.216797), 3);
}
// Fim - Funcionalidades do google maps.

// Início - Google Analytics.
function GoogleAnalytics() {
    try {
        var pageTracker = _gat._getTracker("UA-12792491-1");
        pageTracker._trackPageview();
    } catch (err) {}
}
// Fim - Google Analytics.
