﻿/**************************************************************
*
* CLASSE JAVASCRIPT Banners Portal
*
* CRIADO POR: CRISTIANO TAVELLA 
* DATA: 19/10/2010
* OBS:
* EDITADO POR: CRISTIANO TAVELLA
* DATA: 19/10/2010
* OBS:
*
*************************************************************/

function setClique(x) {

    if ($.trim(this.linkdestino[x].replace("http://", "")) != "")
        window.open(this.linkdestino[x], "_bank");

    $.post(raiz + "Components/banners/Ajax/Processa.aspx", { action: "cliques", pkbanner: this.pkbanner[x] }, function (retorno) {

    });
}

function set(posicao, campo, value) {
    eval("this." + campo + "[" + posicao + "] = '" + value.replace(/\'/g, "\\\'") + "';");
}

function print() {
   
    $("#" + this.destino).html('');

    var script = "";
    var visualizacoes = "";

    if (this.tipoBanner == "1") {
        if (this.banner.length == 0)
            $("#" + this.destino).append("<img src=\"Images/banner_topo.gif\" style=\"width:470px; height:90px; \" >");
        else {
            $("#" + this.destino).html(this.banner[0] + "<script>document.write('<div onclick=\"banner" + this.destino + ".setClique(0);\" style=\"position:absolute;" + ($.trim(this.linkdestino[0].replace("http://", "")) != "" ? "cursor:pointer;" : "") + " width:'+$('#" + this.destino + "_" + 0 + "').css('width')+'; height:'+$('#" + this.destino + "_" + 0 + "').css('height')+'; background:#000; opacity:0;filter:alpha(opacity=0); left:' + getPosicaoElemento('" + this.destino + "_" + 0 + "').left +'px; top:' + getPosicaoElemento('" + this.destino + "_" + 0 + "').top + 'px; \"></div>'); </script>");
            visualizacoes = this.pkbanner[0];
        }
    }
    else if (this.tipoBanner == "2") {
        var tamanho = 0;
        for (var x = 0, total = this.banner.length; x < total; x++) {
            $("#" + this.destino).append(this.banner[x] + "<script>document.write('<div onclick=\"banner" + this.destino + ".setClique(" + x + ");\" style=\"position:absolute;" + ($.trim(this.linkdestino[x].replace("http://", "")) != "" ? "cursor:pointer;" : "") + " width:'+$('#" + this.destino + "_" + x + "').css('width')+'; height:'+$('#" + this.destino + "_" + x + "').css('height')+'; background:#000; opacity:0;filter:alpha(opacity=0); left:' + getPosicaoElemento('" + this.destino + "_" + x + "').left +'px; top:' + getPosicaoElemento('" + this.destino + "_" + x + "').top + 'px; \"></div>'); </script>");

            if (this.tipo[x] == "1")
                tamanho += 95;
            else
                tamanho += 605;

            if(x == 0)
                visualizacoes =  this.pkbanner[x];
            else
                visualizacoes += "," + this.pkbanner[x];

            if (tamanho >= 1175)
                break;
        }
        /*
        for (var x = tamanho; x < 1175; x += 95) {
            if (tamanho == 0 && x == 95) {
                $("#" + this.destino).append("<img src=\"Images/banner2.gif\" style=\"width:120px; height:600px; \" >");
                x += 510;
            }
            else
                $("#" + this.destino).append("<img src=\"Images/banner1.gif\" style=\"width:120px; height:90px; \" >");
        }*/

    }
    else if (this.tipoBanner == "3") {
       
        script+= "<div style=' width:300px; height:450px; float:left'>";

        for (var x = 0, total = this.banner.length; x < total; x++) {
            if (x == 3 && var_fkrepresentante != '0')
                break;
            else if (x == 4)
                break;

            script += this.banner[x];
            script += "<script>document.write('<div onclick=\"banner" + this.destino + ".setClique(" + x + ");\" style=\"position:absolute;" + ($.trim(this.linkdestino[x].replace("http://", "")) != "" ? "cursor:pointer;" : "") + " width:'+$('#" + this.destino + "_" + x + "').css('width')+'; height:'+$('#" + this.destino + "_" + x + "').css('height')+'; background:#000; opacity:0;filter:alpha(opacity=0); left:' + getPosicaoElemento('" + this.destino + "_" + x + "').left +'px; top:' + getPosicaoElemento('" + this.destino + "_" + x + "').top + 'px; \"></div>'); </script>";
            if(x==1)
               script+="</div><div style=' width:300px; height:450px; float:left'>";

            if (x == 0)
                visualizacoes = this.pkbanner[x];
            else
                visualizacoes += "," + this.pkbanner[x];
        }
        if (var_fkrepresentante == '0') {
            if (total < 4) {
                for (var x = total; x < 4; x++) {
                    script += "<img src=\"Images/banner3.gif\" style=\"width:290px; height:215px; \" >";
                    if (x == 1)
                        script += "</div><div style=' width:300px; height:450px; float:left'>";
                }
            }
        }
        else {
            if (total < 3) {
                for (var x = total; x < 3; x++) {
                    script += "<img src=\"Images/banner3.gif\" style=\"width:290px; height:215px; \" >";
                    if (x == 1)
                        script += "</div><div style=' width:300px; height:450px; float:left'>";
                }
            }
        }

        script += "</div>";
        $("#" + this.destino).html(script);
    }
    else if (this.tipoBanner == "5") {



        for (var x = 0, total = this.banner.length; x < total; x++) {
            if (x == 3)
                break;

            script += this.banner[x];
            script += "<script>document.write('<div onclick=\"banner" + this.destino + ".setClique(" + x + ");\" style=\"position:absolute;" + ($.trim(this.linkdestino[x].replace("http://", "")) != "" ? "cursor:pointer;" : "") + " width:'+$('#" + this.destino + "_" + x + "').css('width')+'; height:'+$('#" + this.destino + "_" + x + "').css('height')+'; background:#000; opacity:0;filter:alpha(opacity=0); left:' + getPosicaoElemento('" + this.destino + "_" + x + "').left +'px; top:' + getPosicaoElemento('" + this.destino + "_" + x + "').top + 'px; \"></div>'); </script>";

            if (x == 0)
                visualizacoes = this.pkbanner[x];
            else
                visualizacoes += "," + this.pkbanner[x];
        }
        
        if (total < 3) {
            for (var x = total; x < 3; x++) {
              
                script += "<img src=\"Images/banner3.gif\" style=\"width:290px; height:215px; margin-right:20px; \" >";
              
            }
        }
        

        script += "</div>";
        $("#" + this.destino).html(script);
    }
    else if (this.tipoBanner == "6") {

        script += "<div style=' width:300px; height:450px; float:left'>";

        for (var x = 0, total = this.banner.length; x < total; x++) {
            if (x == 4)
                break;

            script += this.banner[x];
            script += "<script>document.write('<div onclick=\"banner" + this.destino + ".setClique(" + x + ");\" style=\"position:absolute;" + ($.trim(this.linkdestino[x].replace("http://", "")) != "" ? "cursor:pointer;" : "") + " width:'+$('#" + this.destino + "_" + x + "').css('width')+'; height:'+$('#" + this.destino + "_" + x + "').css('height')+'; background:#000; opacity:0;filter:alpha(opacity=0); left:' + getPosicaoElemento('" + this.destino + "_" + x + "').left +'px; top:' + getPosicaoElemento('" + this.destino + "_" + x + "').top + 'px; \"></div>'); </script>";
            if (x == 1)
                script += "</div><div style=' width:300px; height:450px; float:left'>";

            if (x == 0)
                visualizacoes = this.pkbanner[x];
            else
                visualizacoes += "," + this.pkbanner[x];
        }

        if (total < 4) {
            for (var x = total; x < 4; x++) {
                script += "<img src=\"Images/banner3.gif\" style=\"width:290px; height:215px; \" >";
                if (x == 1)
                    script += "</div><div style=' width:300px; height:450px; float:left'>";
            }
        }
        
        

        script += "</div>";
        $("#" + this.destino).html(script);
    }
    else if (this.tipoBanner == "7") {


        for (var x = 0, total = this.banner.length; x < total; x++) {
            if (x ==2)
                break;

            script += "<div class='box_opt_publicidade'>" + this.banner[x] + "</div>";
            script += "<script>document.write('<div onclick=\"banner" + this.destino + ".setClique(" + x + ");\" style=\"position:absolute;" + ($.trim(this.linkdestino[x].replace("http://", "")) != "" ? "cursor:pointer;" : "") + " width:'+$('#" + this.destino + "_" + x + "').css('width')+'; height:'+$('#" + this.destino + "_" + x + "').css('height')+'; background:#000; opacity:0;filter:alpha(opacity=0); left:' + getPosicaoElemento('" + this.destino + "_" + x + "').left +'px; top:' + getPosicaoElemento('" + this.destino + "_" + x + "').top + 'px; \"></div>'); </script>";

            if (x == 0)
                visualizacoes = this.pkbanner[x];
            else
                visualizacoes += "," + this.pkbanner[x];
        }

        if (total < 2) {
            for (var x = total; x < 2; x++) {
                script += '<div class="box_opt_publicidade"><div style="text-align:center; margin-top:50px;">Publicidade</div></div>';
               
            }
        }

        $("#banners_evento_7").html(script);
    }
    else if (this.tipoBanner == "8") {

        script += "<div style=' width:300px; height:450px; float:left'>";

        for (var x = 0, total = this.banner.length; x < total; x++) {
            if (x == 4)
                break;

            script += this.banner[x];
            script += "<script>document.write('<div onclick=\"banner" + this.destino + ".setClique(" + x + ");\" style=\"position:absolute;" + ($.trim(this.linkdestino[x].replace("http://", "")) != "" ? "cursor:pointer;" : "") + " width:'+$('#" + this.destino + "_" + x + "').css('width')+'; height:'+$('#" + this.destino + "_" + x + "').css('height')+'; background:#000; opacity:0;filter:alpha(opacity=0); left:' + getPosicaoElemento('" + this.destino + "_" + x + "').left +'px; top:' + getPosicaoElemento('" + this.destino + "_" + x + "').top + 'px; \"></div>'); </script>";
            if (x == 1)
                script += "</div><div style=' width:300px; height:450px; float:left'>";

            if (x == 0)
                visualizacoes = this.pkbanner[x];
            else
                visualizacoes += "," + this.pkbanner[x];
        }

        if (total < 4) {
            for (var x = total; x < 4; x++) {
                script += "<img src=\"Images/banner3.gif\" style=\"width:290px; height:215px; margin-bottom:10px; \" >";
                if (x == 1)
                    script += "</div><div style=' width:300px; height:450px; float:left'>";
            }
        }



        script += "</div>";
        $("#" + this.destino).html(script);
    }

    $.post(raiz + "Components/banners/Ajax/Processa.aspx", { action: "visualizacoes", visualizacoes: visualizacoes }, function (retorno) {

    });
}

function Banners(tipoBanner, destino, fkrepresentante) {
    this.tipoBanner = tipoBanner;
    this.destino = destino;
    this.fkrepresentante = fkrepresentante;

    this.print = print;
    this.set = set;
    this.setClique = setClique;

    this.banner = new Array();
    this.tipo = new Array();
    this.pkbanner = new Array();
    this.linkdestino = new Array();
}
