/**
 * Javascript that should be included on each and every C21Online page
 */

/**
 * 21Online Utilities
 */
var C21online = new function() {
   /**
    * Get the cookie as name => value pairs object
    * @return object ex: {
    *    account_id : 30030091
    *    user_id : 'bob.dylan@century21.com',
    *    groupid : 3,
    *    logints : [Date Object],
    *    passwordandsaltmd5 : 'a156d2a177c9dad28452f24a07f31ecb'
    *    md5signature : '3363ec3bd6de802e31cf0f1d5f6f2376'
    * }
    */
   this.getAuthCookie = function() {
      // Example of parsable cookie:
      // 30030091:bob.dylan@century21.com:3:1266351921:a156d2a177c9dad28452f24a07f31ecb:3363ec3bd6de802e31cf0f1d5f6f2376

      // Grab the cookie
      var strCookie = CyberCore.getCookie('auth21online');

      // Get the values
      var aCookieValues = strCookie.split(':');

      return {
         account_id : parseInt(aCookieValues[0]),
         user_id : aCookieValues[1],
         group_id : parseInt(aCookieValues[2]),

         // Convert from Unix timestamp to javascript Date object
         logints : new Date(parseInt(aCookieValues[3]) * 1000),

         // These are probably not useful client-side
         passwordandsaltmd5 : aCookieValues[4],
         md5signature : aCookieValues[5]
      }
   };
};

//Returns FALSE on success, popup opened
function OpenInPagePopup( strUrl, strTitle, iWidth, iHeight ) {
   try {
      var pMask = CyberCore.getObj('popupmask');
      var pContainer = CyberCore.getObj('popupcontainer');
      CyberCore.setInnerHtml('popuptitle', strTitle);
      var strContents = '<iframe id="popupiframe" src="'+strUrl+'" width="'+iWidth+'" height="'+iHeight+'" scrolling="auto" frameborder="0"></iframe>';
      CyberCore.setInnerHtml('popupcontents', strContents);
      pMask.style.display = "block";
      pContainer.style.display = "block";
      pContainer.style.height = iHeight + 28 + 'px';

      pContainer.style.left = '50%';
      pContainer.style.marginLeft = '-' + parseInt(iWidth/2) + 'px';
      pContainer.style.width = iWidth + 'px';

      if( !g_pBrowser.bIsMsIe || g_pBrowser.fVersionMajor > 6  ) {
         try {
            pMask.style.position = "fixed";
            //Let user's scroll who are on small screens...
            //pContainer.style.position = "fixed";
         } catch( e ) {
         }
      }


      return false;
   } catch( e ) {
   }
   return true;
}

function OpenInPagePopupObject( strObjectId ) {
   try {
      var pMask = CyberCore.getObj('popupmask');
      var pContainer = CyberCore.getObj(strObjectId);

      pMask.style.display = "block";
      pContainer.style.display = "block";
      //pContainer.style.height = iHeight + 28 + 'px';
      //pContainer.style.left = '50%';
      //pContainer.style.marginLeft = '-' + parseInt(iWidth/2) + 'px';
      //pContainer.style.width = iWidth + 'px';

      if( !g_pBrowser.bIsMsIe || g_pBrowser.fVersionMajor > 6  ) {
         try {
            pMask.style.position = "fixed";
            //Let user's scroll who are on small screens...
            //pContainer.style.position = "fixed";
         } catch( e ) {
         }
      }


      return false;
   } catch( e ) {
   }
   return true;
}

function CloseInPagePopup() {
   try {
      CyberCore.getObj('popupcontainer').style.display = "none";
      CyberCore.getObj('popupmask').style.display = "none";
      CyberCore.setInnerHtml('popupcontents', '');
      return false;
   } catch( e ) {
   }
   return true;
}

function CloseInPagePopupObject( strObjectId ) {
   try {
      CyberCore.getObj(strObjectId).style.display = "none";
      CyberCore.getObj('popupmask').style.display = "none";
      return false;
   } catch( e ) {
   }
   return true;
}
