﻿if(GPD==null){var GPD=function(){}}
GPD.IMThis=function(AppID,OnIMThisFail)
{

  var objMessengerActiveP4=null;
  var appId=AppID;
  this.Event_OnIMThisFailCallBack=OnIMThisFail || null;//imthis in web page needs to check does user client support imthis.


this.IMThisSetCookie=function(_key,_value)
{
	//GPD.Util.DeleteCookie(_key);
  GPD.Util.SetCookie(_key,_value);
};


/*
* Func   - IMThisReadCookie
* Read Saved cookie when p4 page loaded and delete it after read
* para   - 
*          _key- cookie name
* return - cookie value || "" 
*/
this.IMThisReadCookie=function(_key)
{
  var _value=GPD.Util.ReadCookie(_key);
  var  exp  =  new  Date();
  exp.setTime(exp.getTime()  -  1000);
  document.cookie  =  _key  +  "="  +  _value  +  ";  expires="+  exp.toGMTString();
  return _value;
};


/*
* Func   - IMThisTryLaunchP4
*launch succeed || call Event_OnIMThisFailCallBack
* para   - 
*          
* return - true || false
*/
this.IMThisTryLaunchP4=function()
{
    try 
    { 
		//try {
        objMessengerActiveP4 = new ActiveXObject("MSNMessenger.P4QuickLaunch");
		//} catch(e) {
		//	alert("fail to load messenger component");
		//}
        objMessengerActiveP4.LaunchApp(appId, '');
        return true;
    } 
    catch(e)
    {  // alert("fail to load p4 app");
        if(this.Event_OnIMThisFailCallBack!=null)
        {
            this.Event_OnIMThisFailCallBack();
            objMessengerActiveP4 = null;
        }
        return false;
    }
};

};


