﻿/// <reference name="MicrosoftAjax.js"/>
//Cookie = function(name, value)
//{
//  this._name = name;
//  this._value = value;
//}

//Cookie.prototype = {
//  getCookie: function(name)
//  {
//    /// <summary>
//    /// Retrieves a cookie object with the specified name from the document
//    /// </summary>
//    /// <param name="name">Name of the cookie to retrieve</param>
//    /// <returns>Cookie object</returns>
//    // first we'll split this cookie up into name/value pairs
//    // note: document.cookie only returns name=value, not the other components
//    var a_all_cookies = document.cookie.split(';');
//    var a_temp_cookie = '';
//    var cookie_name = '';
//    var cookie_value = '';
//    var b_cookie_found = false; // set boolean t/f default f

//    for (i = 0; i < a_all_cookies.length; i++)
//    {
//      // now we'll split apart each name=value pair
//      a_temp_cookie = a_all_cookies[i].split('=');


//      // and trim left/right whitespace while we're at it
//      cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

//      // if the extracted name matches passed check_name
//      if (cookie_name == name)
//      {
//        b_cookie_found = true;
//        // we need to handle case where cookie has no value but exists (no = sign, that is):
//        if (a_temp_cookie.length > 1)
//        {
//          cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, ''));
//        }
//        // note that in cases where cookie is initialized but no value, null is returned
//        
//      }
//      a_temp_cookie = null;
//      cookie_name = '';
//    }
//    if (!b_cookie_found)
//    {
//      return null;
//    }
//  },

//  
//  get_name: function()
//  {
//    /// <summary>
//    /// Retrieves the name of the cookie
//    /// </summary>
//    return this._name;
//  },
//  get_value: function()
//  {
//    /// <summary>
//    /// Retrieves the value of the cookie
//    /// </summary>
//    return this._value;
//  }
//}

//Cookie.registerClass('Cookie');

Page = function()
{
  this._cookies = Page.getCookies();
  this._queryStringParameters = Page.getQueryStringParameters();
}
//Page.current = null;
Page.prototype = {
  get_cookies: function()
  {
    return this._cookies;
  },
  get_queryStringParameters: function()
  {
    return this._queryStringParameters;
  }
}
Page.setCookie = function(name, value, expires, path, domain)
{
  /// <summary>
  /// Sets the values for a cookie object with the specified name from the document
  /// </summary>
  /// <param name="name">Name of the cookie to set</param>
  /// <param name="value">Value to set for the named cookie</param>
  /// <param name="expires">Number of days the cookie will be stored for</param>
  /// <param name="path">Path to the cookie</param>
  /// <param name="domain">Domain of the cookie (only use if you're accessing from a subdomain)</param>

  // set time, it's in milliseconds
  var today = new Date();
  today.setTime(today.getTime());

  /*
  if the expires variable is set, make the correct
  expires time, the current script below will set
  it for x number of days, to make it for hours,
  delete * 24, for minutes, delete * 60 * 24
  */
  if (expires)
  {
    expires = expires * 1000 * 60 * 60 * 24;
  }
  var expires_date = new Date(today.getTime() + (expires));

  document.cookie = name + "=" + escape(value) +
    ((expires) ? ";expires=" + expires_date.toGMTString() : "") +
    ((path) ? ";path=" + path : "") +
    ((domain) ? ";domain=" + domain : "");
}
Page.getCookies = function()
{
  /// <summary>
  /// Retrieves a dictionary of cookies and their values from the document 
  /// </summary>
  cookieDict = {};
  var a_all_cookies = document.cookie.split(';');
  var a_temp_cookie = '';
  var cookie_name = '';

  for (i = 0; i < a_all_cookies.length; i++)
  {
    // now we'll split apart each name=value pair
    a_temp_cookie = a_all_cookies[i].split('=');


    // and trim left/right whitespace while we're at it
    cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

    // we need to handle case where cookie has no value but exists (no = sign, that is):
    if (a_temp_cookie.length > 1)
    {
      cookieDict[cookie_name] = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, ''));
    }
    a_temp_cookie = null;
    cookie_name = '';
  }
  return cookieDict;
}
Page.getQueryStringParameters = function()
{
  /// <summary>
  /// Retrieves a dictionary of query string parameters and their values from the document 
  /// </summary>
  var url = window.location.toString();
  //get the parameters
  url.match(..\\http\\MS_157.html?(.+)$/);
  var params = RegExp.$1;
  // split up the query string and store in an
  // associative array
  var params = params.split("&");
  var queryStringList = {};

  for (var i = 0; i < params.length; i++)
  {
    var tmp = params[i].split("=");
    queryStringList[tmp[0].toLowerCase()] = unescape(tmp[1]);
  }
  return queryStringList;
}
//Page.get_current = function()
//{
//  /// <summary>
//  /// Retrieves the only instance of the page class or creates a new one if none exists
//  /// </summary>
//  if (Page.current == null)
//  {
//    Page.current = new Page();
//    Page.current._cookies = Page.getCookies();
//    Page.current._queryStringParameters = Page.getQueryStringParameters();
//  }
//  return Page.current;
//}

Page.registerClass("Page");

if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();