﻿// global.js


 /////////////////////////////////////////////////////////////////////////
 // Function: jsonParseDate                                             //
 // Input: Json object containing a date                                //
 //                                                                     //
 // Purpose: To convert the date from json format (Unix time, which is  //
 //          the number of milliseconds that has elapsed since          //
 //          Jan 1, 1970 and the date to be converted) to a user        //
 //          friendly format                                            //
 //          concerning pages, related pages, and Discussion Data       //
 // Calls:   The .Net Date function                                     //
 /////////////////////////////////////////////////////////////////////////
function jsonParseDate(obj) {
             if (typeof obj !== "string") {
                 return obj;
             }

             var match = obj.match(/^\/Date\((-?\d+)\)\/$/);

             if (!match) {
                 return obj;
             }
             var dt = new Date(parseInt(match[1]));
             var formattedDate = dt.toDateString() + " " + dt.toTimeString();
             return formattedDate;
         }
         
       
        ///////////////////////////////////////////////////////////////////////
        // The queryST function parses the querystring received by this page // 
        // and returns the value selected by it's single argument            //
        ///////////////////////////////////////////////////////////////////////
         function querySt(ji) {
            hu = window.location.search.substring(1);
            gy = hu.split("&");
                for (i=0;i<gy.length;i++) {
                    ft = gy[i].split("=");
                if (ft[0] == ji) {
                    return ft[1];
                }
            }
        }
        
        // Cookie functions
        function setCookie(c_name, value, expiredays) {
            var exdate = new Date();
            exdate.setDate(exdate.getDate() + expiredays);
            document.cookie = c_name + "=" + escape(value) +
            ((expiredays == null) ? "" : ";expires=" + exdate.toUTCString());
        }

        function getCookie(c_name) {
            //alert("getCookie");
            if (document.cookie.length > 0) {
                c_start = document.cookie.indexOf(c_name + "=");
                if (c_start != -1) {
                    c_start = c_start + c_name.length + 1;
                    c_end = document.cookie.indexOf(";", c_start);
                    if (c_end == -1) c_end = document.cookie.length;
                    return unescape(document.cookie.substring(c_start, c_end));
                }
            }
            return "";
        }

        function deleteCookie(cookie_name) {
            var cookie_date = new Date();  // current date & time
            cookie_date.setTime(cookie_date.getTime() - 1);
            document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
        }



