﻿
var arrTeachers = new Array();

jQuery(function() {
    var v = jQuery("#ajaxFormStep1To2").validate({
        submitHandler: function(form) {
            casting.Step1To2();
        },
        errorLabelContainer: null
    });

    jQuery("#reset").click(function() {
        v.resetForm();
    });

    jQuery("#resetBottom").click(function() {
        v.resetForm();
    });
});


var casting = {
    Step1To2: function() {
        
    }
}

var getJsonItems = {
    getDataJSon: function(Url, additionalData, ResponseFunction) {
        $.getJSON(Url, additionalData,
        function(data) {
            eval("getJsonItems." + ResponseFunction + "(data)");
        });
    },
    setTeachers: function(data) {
        if (data.length > 0) {
            arrTeachers = data;
            Teachers.showTeacher(0);
        } else {
            openWin.init(['alertOK', 'Profesores', 'Lo sentimos, no hay profesores publicados.', ""]);
        }
    }
}

function getRealTop(item) {
    yPos = item.offsetTop;
    tempEl = item.offsetParent;
    while (tempEl != null) {
        yPos += tempEl.offsetTop;
        tempEl = tempEl.offsetParent;
    }
    return yPos;
}

function openPage(item) {
    var type = item.split("-")[0];
    if (type == "Video") {

        if (item.split("-")[1].split("/").length > 1) {
            var itemsVideo = item.split("-")[1].split("/");
            itemPopUp.getItem(this, "/Programas/SimpleVideo/" + itemsVideo[0] + "/" + itemsVideo[1] + "/" + itemsVideo[2]);

        } else {
            itemPopUp.getItem(this, "/Programas/SimpleVideo/" + item.split("-")[1] + "/" + item.split("-")[2] + "/" + item.split("-")[3]);
        }
    }
    else if (type == "Foto") {
        itemPopUp.getItem(this, "/Programas/SimpleFoto/" + item.split("-")[1] + "/" + item.split("-")[2] + "/?pathFoto=" + item.split("-")[3]);
    }
    else { open(item.split("-")[1], "_self"); }
}

var itemPopUp = {
    init: function() {

        var backLayUpload = document.getElementById("BackAlertLay");
        backLayUpload.innerHTML = "";

        var tamScreenW = $(window).width();
        var tamScreenH = $(window).height();

        var tamBodyH = $("body").height();

        $("#BackAlertLay").get(0).style.height = (tamBodyH > tamScreenH) ? tamBodyH + 50 + "px" : tamScreenH + 50 + "px";
    },
    getItem: function(item, url) {
        // Posicionamos la ventana respecto al top del link pulsado
        var lnkY = getRealTop(item);
        var backLayUpload = document.getElementById("BackAlertLay");

        var objItem = document.getElementById("AlertLayContent");
        var iframeDemo = document.createElement("iframe");
        iframeDemo.className = "intIframe";
        iframeDemo.frameBorder = 0;
        iframeDemo.id = "iframeItem";
        iframeDemo.src = url;

        objItem.appendChild(iframeDemo);

        if ($.browser.msie && $.browser.version == "6.0") {
            window.frames["iframeItem"].location.reload();
        }

        //alert(objItem);

        backLayUpload.style.display = "block";
        document.getElementById("alertLay").style.display = "block";

        document.getElementById("alertLay").style.top = $(window).scrollTop() + "px";
        itemPopUp.init();
    }
}

var childMenu = {
    init: function() {
    },
    showMenu: function(item) {

        if (item.parentNode.className != "sel") { $("li").removeClass("sel"); item.parentNode.className = "sel"; }
        else { $("li").removeClass("sel"); }

        $("#ChildMenu").toggle(400);
        //En funcion de la opcion seleccionada dibuja una cosa u otra;
    }
}

var LayEditions = {
    init: function() {
        var pos = $(".showEditionsLay").position();
        $(".layEdiciones").css('left', pos.left);
    },
    show: function() {
        $(".layEdiciones").visible;
        $(".layEdiciones").toggle(400);
    }
}

var LayFotoVideo = {
    showVideo: function(item) {
        $("li").removeClass("selSubMenuVideo");

        item.parentNode.className = "selSubMenuVideo";
        $(".layVideoGal").hide("fast");

        var itemVideo = item.id.split("Link")[1];
        $("#" + itemVideo).show("fast");
    },
    showFoto: function(item) {

        $("li").removeClass("selSubMenuFoto");

        item.parentNode.className = "selSubMenuFoto";
        $(".layFotoGal").hide("fast");

        var itemFoto = item.id.split("Link")[1];
        $("#" + itemFoto).show("fast");
    }
}

var Teachers = {
    getTeachers: function() {
        getJsonItems.getDataJSon("/Programas/InformacionProfesores/" + idPrograma + "/" + idEdicion, "", "setTeachers");
    },
    showTeacher: function(pos) {


        $(".layFoto").get(0).style.backgroundImage = "url('/Medias" + arrTeachers[pos].Foto + "')";

        $(".HeaderData h3").get(0).innerHTML = arrTeachers[pos].Nombre;
        $(".HeaderData p").get(0).innerHTML = arrTeachers[pos].Perfil;

        $(".bodyData").get(0).innerHTML = "<p>" + arrTeachers[pos].Descripcion + "</p>";
    }
}

var openWin = {
    init: function(data) {
        var backLayAlert = document.getElementById("BackAlertLay");
        backLayAlert.innerHTML = "";

        var tamScreenW = $(window).width();
        var tamScreenH = $(window).height();

        var tamBodyH = $("body").height();

        $("#BackAlertLay").get(0).style.height = (tamBodyH > tamScreenH) ? tamBodyH + 50 + "px" : tamScreenH + 50 + "px";
        openWin.outWin(data);
    },
    outWin: function(data) {
        var backLayAlert = document.getElementById("BackAlertLay");
        backLayAlert.style.display = "block";

        var LayAlert = document.getElementById("itemAlert");
        LayAlert.style.display = "block";

        var itemDiv = document.getElementById("itemAlertContent");
        itemDiv.innerHTML = "";

        // Titulo
        var titleDiv = document.createElement("h2")
        titleDiv.appendChild(document.createTextNode(data[1]));

        // Cuerpo
        var textItemDiv = document.createElement("div");
        if (data[0] == "confirm") { textItemDiv.className = "bodyAlerLay confirmItem"; }
        else if (data[0] == "alertOK") { textItemDiv.className = "bodyAlerLay alertOK"; }
        else if (data[0] == "alertKO") { textItemDiv.className = "bodyAlerLay alertKO"; }

        var textItem = document.createElement("p");
        textItem.appendChild(document.createTextNode(data[2]));

        //Botones
        var ButtonDiv = document.createElement("div");
        ButtonDiv.className = "bodyAlertBtn";

        if (data[0] == "confirm") {
            var btn1 = document.createElement("a");
            btn1.href = "javascript:void(0)";
            btn1.onclick = function() {
                var url = data[3];

                if (data[3].split("http://").length == 1)
                { url = "http://" + data[3]; }
                open(url);
                openWin.OnClose();
            }

            var imgBtn1 = document.createElement("img");
            imgBtn1.src = "/Content/img/BtnAceptar.gif";

            btn1.appendChild(imgBtn1);

            var btn2 = document.createElement("a");
            btn2.href = "javascript:void(0)";
            btn2.onclick = function() {
                openWin.OnClose();
            }

            var imgBtn2 = document.createElement("img");
            imgBtn2.src = "/Content/img/BtnCancelar.gif";

            btn2.appendChild(imgBtn2);


            ButtonDiv.appendChild(btn1);
            ButtonDiv.appendChild(btn2);
        } else {
            var btn1 = document.createElement("a");
            btn1.href = "javascript:void(0)";
            btn1.onclick = function() {
                var url = data[3];
                if (url != "") { open(url, "_self"); }
                else { openWin.OnClose(); }
                //openWin.OnClose();
            }

            var imgBtn1 = document.createElement("img");
            imgBtn1.src = "/Content/img/BtnAceptar.gif";

            btn1.appendChild(imgBtn1);

            ButtonDiv.appendChild(btn1);
        }



        textItemDiv.appendChild(textItem);
        textItemDiv.appendChild(ButtonDiv);




        itemDiv.appendChild(titleDiv);
        itemDiv.appendChild(textItemDiv);
    },
    OnClose: function() {
        var backLayAlert = document.getElementById("BackAlertLay");
        backLayAlert.style.display = "none";

        var LayAlert = document.getElementById("itemAlert");
        LayAlert.style.display = "none";
    }
}

var tooltip = {
    open: function(idItem) {
        var itemTool = idItem.split("itemLinkredes")[1];
        $(".tooltipLay").hide();
        $(".itemLeft" + itemTool + "").show();
    },
    close: function() {
        $(".tooltipLay").hide();
    }
}

var itemFlash = {
    init: function() {
        var backLayUpload = document.getElementById("BackIntroLay");
        backLayUpload.innerHTML = "";

        var tamScreenW = $(window).width();
        var tamScreenH = $(window).height();

        var tamBodyH = $("body").height();

        $("#BackIntroLay").get(0).style.height = (tamBodyH > tamScreenH) ? tamBodyH + 50 + "px" : tamScreenH + 50 + "px";

        backLayUpload.style.display = "block";

        var layIntro = document.createElement("div");
        layIntro.className = "layIntro";

        var txtFlash = '<object type="application/x-shockwave-flash" data="/Content/Flash/Intro/LogoZeppelin_01.swf" width="800" height="600">';
        txtFlash += '<param name="wmode" value="transparent" />';
        txtFlash += '<param name="movie" value="/Content/Flash/Intro/LogoZeppelin_01.swf" />';
        txtFlash += '</object>';

        layIntro.innerHTML = txtFlash;

        $("body").append(layIntro);

    },
    close: function() {
        var backLayUpload = document.getElementById("BackIntroLay");
        backLayUpload.style.display = "none";

        $(".layIntro").remove();
    }
}


$(document).ready(function() {

    itemPopUp.init();
    if ($(".ItemChild").length > 0) {

        childMenu.init();

        $(".ItemChild").mouseover(function() {
            childMenu.showMenu(this);
            return false;
        });

    }

    if ($(".showEditionsLay").length > 0) {
        LayEditions.init();

        $(".showEditionsLay").css('cursor', 'pointer');
        $(".showEditionsLay").click(function() {
            LayEditions.show();
        });
    }
    if ($(".itemVideo").length > 0) {
        $(".itemVideo").click(function() { LayFotoVideo.showVideo(this); });
    }
    else {
        if ($(".itemFoto").length > 0) {
            LayFotoVideo.showFoto($(".itemFoto").get(1));
        }
    }
    if ($(".itemFoto").length > 0) {
        $(".itemFoto").click(function() { LayFotoVideo.showFoto(this); });
    }

    if ($(".imgVideoGal").length > 0) {
        $(".imgVideoGal").mouseover(function() { this.src = "/Content/img/BackGalItems_ON.png"; });
        $(".imgVideoGal").mouseout(function() { this.src = "/Content/img/BackGalVideoItems.png"; });
    }

    if ($(".AllFotos").length > 0) {
        $(".AllFotos").click(function() { LayFotoVideo.showFoto($(".itemFoto").get(2)); });
    }

    if ($(".AllVideos").length > 0) {
        $(".AllVideos").click(function() { LayFotoVideo.showVideo($(".itemVideo").get(2)); });
    }

    if ($(".showVideoLink").length > 0) {

        // /Programas/GaleriaVideos/id/id2

        $(".showVideoLink").click(function() {
            var idVideo = (this.parentNode.parentNode.className == "contentFotoVideoGal") ? this.parentNode.parentNode.id : this.parentNode.parentNode.parentNode.id;
            itemPopUp.getItem(this, "/Programas/GaleriaVideos/" + idPrograma + "/" + idEdicion + "/" + idVideo);
        });
    }

    if ($(".imgFotoGal").length > 0) {
        $(".imgFotoGal").mouseover(function() { this.src = "/Content/img/BackGalFotoItems_ON.png"; });
        $(".imgFotoGal").mouseout(function() { this.src = "/Content/img/BackGalFotoItems.png"; });
    }

    if ($(".showFotoLink").length > 0) {
        // /Programas/GaleriaFotos/id/id2
        $(".showFotoLink").click(function() {

            var idFoto = (this.parentNode.parentNode.className == "contentFotoVideoGal") ? this.parentNode.parentNode.id : this.parentNode.parentNode.parentNode.id;
            itemPopUp.getItem(this, "/Programas/GaleriaFotos/" + idPrograma + "/" + idEdicion + "/" + idFoto);
        });
    }
    if ($(".fichaProfesor").length > 0) {
        Teachers.getTeachers();
    }

    //    if ($("a[target$='_blank']").length > 0) {
    //        $("a[target$='_blank']").click(function() {
    //            openWin.init(['confirm', 'Va a abandonar la web', 'Usted va a abandonar la web, ¿esta seguro?', this.href]);
    //            return false;
    //        });
    //    }

    if ($(".tooltipLay").length > 0) {
        $(".toolTip").mouseover(function() {
            var layItem = this.id.split("itemLinkredes")[1];

            var pos = $("#image" + this.id).position();

            var toolW = $("#tooltipLay" + layItem).width();
            var toolH = $("#tooltipLay" + layItem).height();

            $("#tooltipLay" + layItem).get(0).style.top = (pos.top - toolH) + "px";

            //$("#tooltipLay" + layItem).get(0).style.top = pos.top + "px";

            tooltip.open(this.id);

        });
        $(".toolTip").mouseout(function() {
        });
    }
    if ($(".cboCasting").length > 0) {
        $(".cboCasting").change(function() {
            if ($('.cboCasting :selected').val() == "1") { open("/Castings", "_self"); }
            else if ($('.cboCasting :selected').val() == "-1") {
                openWin.init(['alertOK', 'Castings', 'Seleccione una opción si quiere acceder a los castings.', ""]);
            }
            else {
                var url = "";
                var idProgram = $('.cboCasting :selected').val().split("-")[0];
                var idValidacion = $('.cboCasting :selected').val().split("-")[1];

                if (idValidacion == "True") { url = "/Castings/CastingSMS/" + idProgram; }
                else { url = "/Castings/Registro/" + idProgram; }
                open(url, "_self");
            }
        });
    }

    if ($(".cboPublico").length > 0) {
        $(".cboPublico").change(function() {
            if ($('.cboPublico :selected').val() == "1") { open("/Publico", "_self"); }
            else if ($('.cboPublico :selected').val() == "-1") {
                openWin.init(['alertOK', 'Público', 'Seleccione una opción si quiere asistir como público.', ""]);
            }
            else {
                var idProgram = $('.cboPublico :selected').val().split("-")[0];
                //var idEdition = $('.cboPublico :selected').val().split("-")[1];

                var url = "/Programas/Publico/" + idProgram;
                open(url, "_self");
            }
        });
    }


    if ($("#Content4.aboutUsPage").length > 0) { $("#NavMenu ul li").get(0).className = "sel"; }
    if ($(".bodyContent.Programas").length > 0) { $("#NavMenu ul li").get(1).className = "sel"; }
    if ($("#Content31.castingsPage").length > 0) { $("#NavMenu ul li").get(2).className = "sel"; }
    if ($("#Content31.spectatorsPage").length > 0) { $("#NavMenu ul li").get(3).className = "sel"; }
    if ($("#Content31.pressPage").length > 0) { $("#NavMenu ul li").get(4).className = "sel"; }
    if ($("#Content4.pressPage").length > 0) { $("#NavMenu ul li").get(4).className = "sel"; }
    if ($("#Content31.contactPage").length > 0) { $("#NavMenu ul li").get(5).className = "sel"; }

    if ($("#UltimoModulo").length > 0) {
        if (introItem == "true") {
            itemFlash.init();
        }
    }

    if ($(".lnkTeminos").length > 0) {
        $(".lnkTeminos").click(function() {
            $(".layTerminos").toggle(40);
        });
    }

    if ($(".inputTextChange").length > 0) {
        $(".inputTextChange").focus(function() {
            if (this.value == "Nombre del medio") { this.value = ""; }
        });
        $(".inputTextChange").blur(function() {
            if (this.value == "") { this.value = "Nombre del medio"; }
        });

    }
    if ($(".LoginForm").length != 0) {
        if ($.cookie("UserEmail") != null) {
            $("input[name$='txtMail']").val($.cookie("UserEmail"));
            $("input[name$='remember']").get(0).checked = true;
        }
    }

    //Prensa
    if ($(".showFotoPrensaLink").length > 0) {
        // /Programas/GaleriaFotos/id/id2
        $(".showFotoPrensaLink").click(function() {
            var idFoto = (this.parentNode.parentNode.className == "contentFotoVideoGal") ? this.parentNode.parentNode.id : this.parentNode.parentNode.parentNode.id;
            //itemPopUp.getItem(this, "/Programas/GaleriaFotos/" + idPrograma + "/" + idEdicion + "/" + idFoto);
            itemPopUp.getItem(this, "/Programas/GaleriaFotos/xxx/xxxx/" + idFoto);
        });
    }

    if ($(".imgPrensaFotoGal").length > 0) {
        $(".imgPrensaFotoGal").mouseover(function() { this.src = "/Content/img/BackPrensaFotoON.png"; });
        $(".imgPrensaFotoGal").mouseout(function() { this.src = "/Content/img/BackPrensaFoto.png"; });
    }

    if ($(".showVideoPrensaLink").length > 0) {
        $(".showVideoPrensaLink").click(function() {
            var idVideo = (this.parentNode.parentNode.className == "contentFotoVideoGal") ? this.parentNode.parentNode.id : this.parentNode.parentNode.parentNode.id;

            itemPopUp.getItem(this, "/Programas/GaleriaVideos/Prensa/" + idNotaPrensa + "/" + idVideo);
        });
    }

    $("input[type$='radio']").addClass("radioInput");
    $("input[type$='checkbox']").addClass("radioInput");

    if ($(".imgClose").length > 0) {
        $(".imgClose").click(function() {
            OnClose();
        });
    }

    if ($(".imgAlertClose").length > 0) {
        $(".imgAlertClose").click(function() {
            openWin.OnClose();
        });
    }

    $(document).mouseover(function(e) {
        var pos = $("#ChildMenu").position();

        var X1 = pos.left;
        var X2 = X1 + $("#ChildMenu").width();

        var Y1 = pos.top-5;
        var Y2 = Y1 + $("#ChildMenu").height();

        if (X1 < e.pageX && X2 > e.pageX && Y1 < e.pageY && Y2 > e.pageY) { }
        else { $("#ChildMenu").hide(400); }
    });


    $(document).click(function(e) {
        $(".tooltipLay").hide();
    });
});	
