// ===================================================================
// File Created By Mark Paul on 30/08/2007
// File Description: This file contains misc functions that are used by our webpages. Please see description of each function below
// Last file update by Mark Paul on 31/08/2007 to function IMThis
// ===================================================================

// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Coded By Mark Paul on 30/08/2007
// Function Description: Used to initialise a call to the IMThis feature we have for articles and basic web pages (not to be used for media - video etc)
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function IMThis()
{
   var debugMode = false; // set true/false to show alert msgs

   try
   {
      obj = new ActiveXObject("MSNMessenger.P4QuickLaunch");
   }
   catch(e)
   {
      obj = null;
   }

   if (obj != null)
   {
      // -------------------------------------------
      // S: create the custom optimised cookie
      // -------------------------------------------
      function MakeCookie()
      {
         var expMinutes = 5;
         var cookieExpiresOn = new Date();
         cookieExpiresOn.setTime(cookieExpiresOn.getTime() + (expMinutes*60*1000));
         cookieExpiresOn = cookieExpiresOn.toGMTString()

         //var cookieValue = "http://dolly.ninemsn.com.au/article.aspx?id=124847"; // For local testing
         var cookieValue =  document.location; // Live url capture

         if (String(cookieValue).indexOf('#') != -1)
         {
            cookieValue = String(cookieValue).replace("#","");
         }

         if (String(cookieValue).indexOf('?') == -1)
         {
            cookieValue = cookieValue + "?print=true&imview=true";
         }
         else
         {
            cookieValue = cookieValue + "&print=true&imview=true";
         }

         var cookieValue = escape(cookieValue);

         if (debugMode)
         {
            alert(cookieValue);
         }

         var cookieDomain = ".ninemsn.com.au";

         document.cookie = "imthis_page=" + cookieValue + ";expires=" + cookieExpiresOn + ";path=/" + ";domain=" + cookieDomain;

         return true;
      }
      // -------------------------------------------
      // E: create the custom optimised cookie
      // -------------------------------------------


      var createUrlCookie = MakeCookie();

      if (createUrlCookie)
      {
         obj.LaunchApp("99995227","");
      }
      else
      {
         alert("ERROR: Cookie could not be created");
      }
   }
   else
   {
      alert("Sorry, your configuration does not support this IM This feature.\nThe minimum requirements are MSN Messenger 6.0 or higher and Internet Explorer 5.5 or higher.");
   }
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Coded By Mark Paul on 30/08/2007
// Function Description: Used to initialise a call to the IMThis feature we have for articles and basic web pages (not to be used for media - video etc)
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function blogThis(u, title, abstract)
{
   var msnSpacesApi = "http://spaces.msn.com/BlogIt.aspx";
   var seltitle = "";
   var sel = "";

   if(u.charAt(0) == "/")
   {
      u = "http://" + window.location.host + u
   }
   else
   {
      u = window.location.href
   }

   if (title && title !== "" && title !== "undefined")
   {
      seltitle = title;
   }
   else
   {
      seltitle = document.title;
   }

   if (abstract && abstract !== "" && abstract !== "undefined")
   {
      sel = abstract;
   }
   else
   {
     if (document.selection)
     {
         sel = document.selection.createRange();
         sel.expand("word");
         sel = sel.text;
     }
   }

   window.open(msnSpacesApi + "?Title=" + escape(seltitle) + "&SourceURL=" + escape(u) + "&description=" + escape(sel) + "&&CM=BlogThis&CE=1");
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


