﻿// JScript File


        //This function determines if a take is to be set as an editor's pick or removed.
       function validateIsEditorPick(chk, stockId){
            
            var url = "/AJAX/PostPages/Picks/Admin/setEditorPick.aspx?TAKEID=" + stockId;
            if (chk.checked == true)
            {
                url += "&isEditorPick=1";
                IsEditorPick(url);
            }
            else
            {
                url += "&isEditorPick=0";
                RemoveEditorPick(url);
            }
           
        }
        
       //Process an Take to be set as editor Pick
        function IsEditorPick(url)
       {
           
            // branch for native XMLHttpRequest object
            if (window.XMLHttpRequest) {
                req = new XMLHttpRequest();
                req.onreadystatechange = processIsEditorPick;
                req.open("GET", url, true);
                req.send(null);
               // branch for IE/Windows ActiveX version
            } else if (window.ActiveXObject) {
                isIE = true;
                req = new ActiveXObject("Microsoft.XMLHTTP");
                if (req) {
                    req.onreadystatechange = processIsEditorPick;
                    req.open("GET", url, true);
                    req.send();
                }
            }
         
        
       }
       
       
       function RemoveEditorPick(url)
       {
           // branch for native XMLHttpRequest object
            if (window.XMLHttpRequest) {
                req = new XMLHttpRequest();
                req.onreadystatechange = processRemoveEditorPick;
                req.open("GET", url, true);
                req.send(null);
               // branch for IE/Windows ActiveX version
            } else if (window.ActiveXObject) {
                isIE = true;
                req = new ActiveXObject("Microsoft.XMLHTTP");
                if (req) {
                    req.onreadystatechange = processRemoveEditorPick;
                    req.open("GET", url, true);
                    req.send();
                }
            }
       }
        
        
       
       function processIsEditorPick()
       {
            if (req.readyState == 4) {
                // only if "OK"
                if (req.status == 200) {
                
                    if(req.responseText == "True")
                        alert("Pick has been set as an Editor Pick");
                    else
                        alert("Error loading Picks, please refresh your browser");
                   
                
                }
                else
                 {
                     alert("Error loading Picks, please refresh your browser");
                 }
                
            }
       
       }
       
        function processRemoveEditorPick()
       {
            if (req.readyState == 4) {
                // only if "OK"
                if (req.status == 200) {
                
                    if(req.responseText == "True")
                        alert("Pick has removed as an Editor Pick");
                    else
                        alert("Error loading Picks, please refresh your browser");
                   
                
                }
                else
                 {
                     alert("Error loading Picks, please refresh your browser");
                 }
                
            }
       
       }
       



    function ShowAdminLoading(show, divAdmin, divLoading)
    {
        if (show == true)
        {
            $_(divAdmin).style.display = "none";
            $_(divLoading).style.display = "block";
        }
        else
        {
            $_(divAdmin).style.display = "block";
            $_(divLoading).style.display = "none";
        }
    }

    function DeletePick(pickId, container, divAdmin, divLoading)
    {
        ShowAdminLoading(true, divAdmin, divLoading);
        
        var url = "/AJAX/PostPages/Picks/Admin/setEditorPick.aspx?delete=" + pickId;

        new Ajax.Request( url, {
                    method: 'post', 
                    onSuccess: function(AJAXResponse) 
                            {
                                 ProcessDelete(AJAXResponse, container, divAdmin, divLoading); 
                            }
                    ,
                    onFailure: function(AJAXResponse)
                            {
                                 
                                 alert("Error deleting pick, please refresh your browser and try again");
                                 ShowAdminLoading(false, divAdmin, divLoading);
                            } 
                      });

    }
    
    function ProcessDelete(AJAXResponse, container, divAdmin, divLoading)
    {
        ShowAdminLoading(false, divAdmin, divLoading);
        
        if (AJAXResponse.status == 200) 
        {
            if (AJAXResponse.responseText == "true")
            {
                $_(container).style.display = "none";
            }
            else
            {
                alert("Error deleting pick, please refresh your browser");
            }
        } 
        else 
        {
             alert("Error deleting pick, please refresh your browser and try again");
        }
    
    }
