﻿function InitProductions()
{
    
    FacilitiesPanelHeaderOnClick();
    PeoplePanelHeaderOnClick();
    ProductionsAwardsPanelHeaderOnClick();
   
    var urlParam = $.getURLParam("id");
    
    
    
    
    if (urlParam != null | urlParam != "")
    {
        FacilitiesGridLoad();
        ProductionsAwardGridLoad();
    }
    
    
    
}

function InitWebEditor()
{
    
    $("#freeRTE").blur( function () {
        rteFormHandler(); 
        document.getElementById(rteFormName).value = getXHTML(trim(document.getElementById(rteName).contentWindow.document.body.innerHTML));        
        $(".hiddenDescription").val(document.getElementById(rteFormName).value);
        
    }
    );
}

function RefreshEntireProductionPage()
{
    var date = new Date();
   var t = date.getTime()
    var sURL = unescape(window.location.pathname);
    sURL = sURL + "?id=" + $.getURLParam("id") + "&t=" + t;
    window.location.href = sURL;


}

function ProductionFacilitiesRemove(roleToProjectID)
{
   var date = new Date();
   var t = date.getTime()
    var remove = confirm('Remove this facility from this production?');
    
    if (remove)
    {
           $.ajax({
               type: "GET",
               url: "gridviews/ProductionFacilities.aspx",
               data: "delete=1&roletoprojectid=" + roleToProjectID + "&id=" + $.getURLParam("id") + "&t=" + t,
               success: function(msg){
                 
                 FacilitiesGridLoad();
                 
               },
                error : function (o, d, c)
                {
                    alert(d);
                }
                }); 
    }
}

function ProductionPeopleRemove(roleToProjectID)
{
   var date = new Date();
   var t = date.getTime() 
    var remove = confirm('Remove this person from this production?');
    
    if (remove)
    {
           $.ajax({
               type: "GET",
               url: "gridviews/ProductionPeople.aspx",
               data: "delete=1&roletoprojectid=" + roleToProjectID + "&id=" + $.getURLParam("id") + "&t=" + t,
               success: function(msg){
                 
                 FacilitiesGridLoad();
                 
               },
                error : function (o, d, c)
                {
                    alert(d);
                }
                }); 
    }
}

function FacilitiesGridLoad(nonIEChild)
{
   var date = new Date();
   var t = date.getTime()   
   $("#FacilitiesPanelGrid").html("<img src='images/loading.gif'/> loading ");


    if (!nonIEChild)
    {
        
        $.ajax({
            type: "GET",
            url: "gridviews/ProductionFacilities.aspx",
            data: "id=" + $.getURLParam("id") + "&productionid=" + facilityId + "&t=" + t,
            success: function(msg){
                $("#FacilitiesPanelGrid").html("");
                $("#FacilitiesPanelGrid").html(msg.replace("__VIEWSTATE","NOVIEWSTATEFacilities").replace("__VIEWSTATE","NOVIEWSTATEFacilities").replace("__VIEWSTATEENCRYPTED","NOVIEWSTATEENCRYPTEDFacilities").replace("__VIEWSTATEENCRYPTED","NOVIEWSTATEENCRYPTEDFacilities").replace('method="post"','').replace("form","span"));     
                $("#NOVIEWSTATEFacilities").val ("");
                
                PeopleGridLoad(nonIEChild);
            },
            error : function (o, d, c)
            {
                alert(d);
            }
            });
    }
    else
    {
        
        $.ajax({
            type: "GET",
            url: "../gridviews/ProductionFacilities.aspx",
            data: "id=" + $.getURLParam("id") + "&productionid=" + facilityId + "&t=" + t,
            success: function(msg){
                $("#FacilitiesPanelGrid").html("");
                $("#FacilitiesPanelGrid").html(msg.replace("__VIEWSTATE","NOVIEWSTATEFacilities").replace("__VIEWSTATE","NOVIEWSTATEFacilities").replace("__VIEWSTATEENCRYPTED","NOVIEWSTATEENCRYPTEDFacilities").replace("__VIEWSTATEENCRYPTED","NOVIEWSTATEENCRYPTEDFacilities").replace('method="post"','').replace("form","span"));     
                $("#NOVIEWSTATEFacilities").val ("");
                PeopleGridLoad(nonIEChild);
            },
            error : function (o, d, c)
            {
                alert(d);
            }
            });
    }
   

}


function PeopleGridLoad(nonIEChild)
{
   var date = new Date();
   var t = date.getTime()  
   $("#PeoplePanelGrid").html("<img src='images/loading.gif'/> loading ");
  

    if (!nonIEChild)
    {
        
        $.ajax({
            type: "GET",
            url: "gridviews/ProductionPeople.aspx",
            data: "id=" + $.getURLParam("id") + "&productionid=" + facilityId + "&t=" + t,
            success: function(msg){
                $("#PeoplePanelGrid").html("");
                $("#PeoplePanelGrid").html(msg.replace("__VIEWSTATE","NOVIEWSTATEPeople").replace("__VIEWSTATE","NOVIEWSTATEPeople").replace("__VIEWSTATEENCRYPTED","NOVIEWSTATEENCRYPTEDPeople").replace("__VIEWSTATEENCRYPTED","NOVIEWSTATEENCRYPTEDPeople").replace('method="post"','').replace("form","span"));     
                $("#NOVIEWSTATEFacilities").val ("");
                
            },
            error : function (o, d, c)
            {
                alert(d);
            }
            });
    }
    else
    {
        
        $.ajax({
            type: "GET",
            url: "../gridviews/ProductionPeople.aspx",
            data: "id=" + $.getURLParam("id") + "&productionid=" + facilityId + "&t=" + t,
            success: function(msg){
                $("#PeoplePanelGrid").html("");
                $("#PeoplePanelGrid").html(msg.replace("__VIEWSTATE","NOVIEWSTATEPeople").replace("__VIEWSTATE","NOVIEWSTATEPeople").replace("__VIEWSTATEENCRYPTED","NOVIEWSTATEENCRYPTEDPeople").replace("__VIEWSTATEENCRYPTED","NOVIEWSTATEENCRYPTEDPeople").replace('method="post"','').replace("form","span"));     
                $("#NOVIEWSTATEFacilities").val ("");
                
            },
            error : function (o, d, c)
            {
                alert(d);
            }
            });
    }
   

}
















function ProductionHideFacilitiesAndPeoplePanel()
{
    $("#FacilitiesPanel").hide();
    $("#PeoplePanel").hide();
    $("#AwardsPanel").hide();
}

function ProductionShowFacilitiesAndPeoplePanel()
{
    $("#FacilitiesPanel").show();
    $("#PeoplePanel").show();
}

function FacilitiesPanelHeaderOnClick()
{
    $("#FacilitiesPanelContent").hide();
    $("#FacilitiesPanelHeader").click
    ( function()
        {
            FacilitiesPanelContentToggle(); 
        }
    );
}

function PeoplePanelHeaderOnClick()
{
    $("#PeoplePanelContent").hide();
    $("#PeoplePanelHeader").click
    ( function()
        {
            PeoplePanelContentToggle(); 
        }
    );
}


function PeoplePanelContentToggle()
{
    if($("#PeoplePanelContent").css("display") == "block")
    {
        
        var discard = confirm('Your changes has not been saved\nDiscard your changes?');
        if(discard)
        {
            $("#PeoplePanelContent").slideToggle();
         }
        
    }
    else
    {
       
        PeoplePanelSlideToggleShow();
        
    }
}

function PeoplePanelSlideToggleShow()
{
    if($("#PeoplePanelContent").css("display") != "block")
    {
        $("#PeoplePanelContent").slideToggle();
    }
    else
    {
        $("#PeoplePanelContent").fadeIn("slow");

    }
    
    $("#PeoplePanelContentFrame").attr( "src", "Iframes/AddPeopleOld.aspx?id=" + $.getURLParam("id") + "&type=people");
}


function FacilitiesPanelContentToggle() 
{
    if($("#FacilitiesPanelContent").css("display") == "block")
    {
        
        var discard = confirm('Your changes has not been saved\nDiscard your changes?');
        if(discard)
        {
            $("#FacilitiesPanelContent").slideToggle();
         }
        
    }
    else
    {
       
       FacilitiesPanelSlideToggleShow();
        
    }
}


function FacilitiesPanelSlideToggleShow()
{
   $("#FacilitiesPanelContent").slideToggle();
   $("#FacilitiesPanelContentFrame").attr( "src", "Iframes/AddFacilitiesOld.aspx?id=" + $.getURLParam("id") + "&type=facilities");
}


function ProductionsAwardGridLoad(nonIEChild)
{

   var date = new Date();
   var t = date.getTime();    
   $("#AwardPanelGrid").html("<img src='images/loading.gif'/> loading ");
  
    
    if (!nonIEChild)
    {
        
        $.ajax({
            type: "GET",
            url: "gridviews/ProductionAwards.aspx",
            data: "id=" + $.getURLParam("id") + "&t=" + t,
            success: function(msg){
                $("#AwardPanelGrid").html("");
                $("#AwardPanelGrid").html(msg.replace("__VIEWSTATE","NOVIEWSTATEAwards").replace("__VIEWSTATE","NOVIEWSTATEAwards").replace("__VIEWSTATEENCRYPTED","NOVIEWSTATEENCRYPTEDAwards").replace("__VIEWSTATEENCRYPTED","NOVIEWSTATEENCRYPTEDAwards").replace('method="post"','').replace("form","span"));     
                $("#NOVIEWSTATEAwards").val ("");
                PeerGridLoad(nonIEChild);
            },
            error : function (o, d, c)
            {
                alert(d);
            }
            });
    }
    else
    {
        
        $.ajax({
            type: "GET",
            url: "../gridviews/ProductionAwards.aspx",
            data: "id=" + $.getURLParam("id") + "&t=" + t,
            success: function(msg){
                $("#AwardPanelGrid").html("");
                $("#AwardPanelGrid").html(msg.replace("__VIEWSTATE","NOVIEWSTATEAwards").replace("__VIEWSTATE","NOVIEWSTATEAwards").replace("__VIEWSTATEENCRYPTED","NOVIEWSTATEENCRYPTEDAwards").replace("__VIEWSTATEENCRYPTED","NOVIEWSTATEENCRYPTEDAwards").replace('method="post"','').replace("form","span"));     
                $("#NOVIEWSTATEAwards").val ("");
                
            },
            error : function (o, d, c)
            {
                alert(d);
            }
            });
    }


}

function ProductionsAwardsPanelHeaderOnClick()
{
    $("#AwardsPanelContent").hide();
    $("#AwardsPanelHeader").click
    ( function()
        {
            ProductionsAwardPanelContentToggle(); 
        }
    );
}

function ProductionsAwardPanelContentToggle()
{
     if($("#AwardsPanelContent").css("display") == "block")
    {
        
        var discard = confirm('Your changes has not been saved\nDiscard your changes?');
        if(discard)
        {
            $("#AwardsPanelContent").slideToggle();
         }
        
    }
    else
    {
        var date = new Date();
        var t = date.getTime() 
        $("#AwardsPanelContent").slideToggle();
        $("#AwardFrame").attr( "src", "Iframes/AddAwardsOld.aspx?id=" + $.getURLParam("id") + "&type=productions"  + "&t=" + t);
        
    }
}

function ProductionsAwardsRemove(awardHistoryID)
{
   var date = new Date();
   var t = date.getTime() 

   var remove = confirm('Remove this award from this production?');
    
   if (remove)
   {
           $.ajax({
               type: "GET",
               url: "gridviews/ProductionAwards.aspx",
               data: "delete=1&awardHistoryId=" + awardHistoryID + "&id=" + $.getURLParam("id") + "&t=" + t,
               success: function(msg){
                 
                 ProductionsAwardGridLoad();
                 
               }
                }); 
   }
}