/**
 *  Utility functions
 *  util.js
 *  $Revision: 1.26 $
 */

if (typeof (cdc) == "undefined") cdc = {};
if (typeof (cdc.util) == "undefined") cdc.util = {};
/**
 * ensureNamespace: Make sure that the name space with the specified name is available.
 * For example: <code>cdc.util.ensureNamespace ("cdc.partner.portlet")</code> ensures that the namespace
 * <code>cdc.partner.portlet</code> is valid. This function simply declares global objects with the appropriate
 * keys specified in them; for example, the call <code>cdc.util.ensureNamespace ("cdc.partner.portlet")</code>
 * is equivalent to the following code fragment:
 * <code>
 *    if (typeof (cdc) != "object") window.cdc = new Object();
 *    if (typeof (cdc.partner) != "object") window.cdc.partner = new Object();
 *    if (typeof (cdc.partner.portlet) != "object") window.cdc.partner.portlet = new Object();
 * </code>
 * @param namespaceStr the namespace specification
 *
 */
cdc.util.ensureNamespace = function (namespaceStr) {
    if (!namespaceStr) return;
    var parts = namespaceStr.split (".");
    var o = window;
    for (var i = 0; i < parts.length; i++) {
        var aPart = parts[i];
        if (typeof (o[aPart]) != "object") {
            o[aPart] = {};
        }
        o = o[aPart];
    }
}

// skeleton debug framework
if (typeof cdc.debug == "undefined") cdc.debug = {};
cdc.debug.log   = function() {};
cdc.debug.dump  = function() {};
cdc.debug.alert = function() {};

/**
 * openCdcPopup : Opens up a child window to developer supplied dimmensions
 * @param {Object/String} url An object containing configuration settings for the child window
 * @param {Integer} width (optional)
 * @param {Integer} height (optional)
 */
cdc.util.openCdcPopup = function (url, width, height) {
  if (!url) {return true;} //where url is not supplied do nothing

  var windowControls='';
  var windowOptions='';
  var windowName = 'globalCDCpopup';

  if(typeof(url) == "object"){
     // create temp variables to function params map
     width  = url.width;
     height = url.height;
     xtop = typeof(url.top) != "undefined" ? url.top : ''; //named "xtop" because "top" kills IE
     left = typeof(url.left) != "undefined" ? url.left : '';
     windowOptions = "top="+xtop+",left="+left+",";
     if(typeof(url.windowName) != "undefined"){windowName = url.windowName;};

     if (url.controls != false){ //undefined = true
       if(typeof(url.location) != "undefined" && url.location == "no"){
          var windowControls = ",toolbar=yes,location=no,menubar=yes";
       }else{
          var windowControls = ",toolbar=yes,location=yes,menubar=yes";
       }
     }
     url = url.address;   // doing this last because it nukes the url object
  }

  width = isNaN(parseInt(width)) ? 550 : parseInt(width);
  height = isNaN(parseInt(height)) ? 550 : parseInt(height);

  /* ie scrollbar behaviour adjustment */
  if(document.all){ width = width+20; }

  windowOptions +=  "width="+width+",height="+height+",status=yes,scrollbars=yes,resizable=yes"+windowControls;
  var popup = window.open ( url, windowName, windowOptions);
  if (popup) popup.focus();
  return false;
};


// Grabs a parameter from the URL.  Returns an empty
// string if parameter does not exist.
cdc.util.getParameter = function(param) {

        var val = "";
        var qs = window.location.search;
        var start = qs.indexOf(param);

        if (start != -1) {
                start += param.length + 1;
                var end = qs.indexOf("&", start);
                if (end == -1) {
                        end = qs.length
                }
                val = qs.substring(start,end);
        }
        return val;
};



/*---------------------------------------------------------
  Intercept popup window decision process functions
------------------------------------------------------------ */

/* ------------------------------------------------------------------
  Use timedPop() to popup an intercept window only if they've been
  on-site for a while.

  They will NEVER get this window on the first page they come to,
  even if minutes=0. Use randomPop() instead if you need that

   minutes: how long they need to be onsite before getting popup
   frequency: how often to ask people - random number between 1 & frequency generated
   url: url of window to pop open
   stopcookie: name of cookie that lets you know they've been asked already
   expires: number of days to keep the stopcookie active
   windowsize: small, medium, large - defaults to large -- sizes defined in window opening functions
---------------------------------------------------------------------*/

function timedPop(minutes, frequency, url, stopcookie, expires, windowsize ) {
  myDomain = window.location.host;

  if ( (myDomain == "cisco.com" || myDomain == "www.cisco.com" || myDomain == "elovejoy-lnx" || myDomain == "maunaloa" || myDomain == "maunaloa.cisco.com" || myDomain == "newsroom.cisco.com" ) && window.location.pathname.match("/en/US/") ) { /* don't let this interfere w/ apps or theaters */

    timeCookie= "CDCsitetimer";

    /* check for time cookie */
    now = new Date();
    nowMinutes = now.getTime()/60000;
    var msec = cdc.cookie.daysFutureToTimeMS(0);

    if ( cookietime = cdc.cookie.getCookie({cookieName:timeCookie})) {
      // alert("long enough? cookietime="+cookietime +" & now is "   +nowMinutes);

      if ( cookietime != "Done" && (nowMinutes - cookietime) >= minutes )   {
        // alert("time to pop");
        randomPop(frequency,  url, stopcookie, expires, windowsize);
        cdc.cookie.setCookie({cookieName:'timeCookie',cookieValue:'Done',msecs:msec});
      }

    } else {
      /* if they don't have a timer make one */
      cdc.cookie.setCookie({cookieName:'timeCookie',cookieValue:nowMinutes,msecs:msec});
   }
   //} else { alert("we don't pop on your domain");

  } /* end domain check */
}

/* -------------------------------------------------------------------
 randomPop() will popup an intercept window if the randomly generated number = 1
 If frequency=1 this will always get called.
 This _can_ happen on the first page someone lands on.

   frequency: odds of getting popup = 1/frequency times
   url: url of the content for popup window
   stopcookie: name of cookie that keeps them from getting popup again
   expiredays: number of days to keep the stopcookie active
   windowsize: small, medium, large - defaults to large
   -- these sizes are defined in the window opening functions
  ------------------------------------------------------------------- */

function randomPop (frequency, url, stopcookie, expiredays, windowsize){
  var cookiename = 'IntSurP';
  var validDate;
  var random_num;

  frequency <= 1 ? random_num = 1: random_num = Math.ceil( frequency * Math.random()) ;

  if ((random_num == 1) ) {
   validDate = cdc.cookie.extractCookieChip(cookiename,stopcookie);

   if ( validDate && validDate < Date.parse(Date()) ) {
      /* they had the cookie, but it's too old to matter */
      cdc.cookie.crumbleCookieChip(cookiename, stopcookie);
      validDate = "";
   }

   if (!validDate ) {
      /* they don't have a cookie telling us to stop */

      expiredays = cdc.cookie.daysFutureToTimeMS(expiredays);
      cdc.cookie.addCookieChip(cookiename, stopcookie,expiredays);

      if ( windowsize=="medium" ) {
        openMediumPopup(url,"popWin");
      } else if ( windowsize=="small") {
     openSmallPopup(url,"popWin");
      } else {
        openLargePopup(url,"popWin");
      }

   //} else {
    //alert("You've got the Cookie! " + stopcookie);

  }  /* ends if (!validDate) */
  //} else {
     /* it was a different random number */
    // alert("random_num was "+random_num)  // for debugging purposes only
  } /* ends if (random_num ==1) */
} // end randomPop()


/* ------------------------------------------------------------
   function call to initiate timed survey
   ------------------------------------------------------------ */
// How to use timedPop. Comment out the following line to turn it off.
// timedPop(1, 50, "http://www.cisco.com/survey/intercept.html", "cdcsurvey", 183, "small" );

/* ---------------------------------------------------------------
        Search box -- Function to clear the word Search
   when you go into the field. Could be used for other
   default text
   --------------------------------------------------------------- */

cdc.util.checkClear = function(input,defaultPhrase) {
  if (input.value == defaultPhrase) input.value = "";
  if (input.id == "searchPhrase") {
    if (!document.getElementById("search-drop-down")){
      setupSearch();
    }
    if (document.getElementById("search-drop-down")){
      showSuggestionsContainer();
    }
  }
};




// test src url before showing image
// invoke with: onload="cdc_display_image_when_loaded(this,'my_source_url.jpg');"
cdc.util.displayImageWhenLoaded = function(img,url){
   // we're extending img with .tempImg to do a test load of the src with a new image object
   img.tempImg = new Image();
   img.tempImg.onload = function(){
      // this prevents the image src in html from firing the onload again
      img.onload=null;
      img.src = img.tempImg.src;
      img.tempImg.onload=null;

      if(img.id == "bam_img"){
         img.parentNode.href = img.src.replace('image.ng','click.ng');
      }
   };
   // putting this after the onload handler above
   img.tempImg.src = url;
};

// cache buster - puts a cache avoidance param on a url with a random number
// invoke with:
// cdc.util.cacheBust('http://www.cisco.com');          = YourUrl?cacheReset=rand#
// cdc.util.cacheBust('http://www.cisco.com','foo');    = YourUrl?foo=rand#
// cdc.util.cacheBust('http://ng-prod1/image');         = YourUrl&cacheReset=rand#
// cdc.util.cacheBust('http://cisco.com/edit.pl?a=3');  = YourUrl&cacheReset=rand#
cdc.util.cacheBust = function (url,param){
   if (!param) {param = 'cacheReset'};
   var delim = "?";
  // if url is ng-prod1(bam) or has ?, set param delimeter to &
  if (url.match(/(ng-prod1|\?)/)) {delim = "&"};
  var fullParam = delim+param+'=';
   // degug alert(url+fullParam+cdc.util.randomNumber());
   return url+fullParam+cdc.util.randomNumber();
};

// randum number generator
// input: takes param limit to set random max, default is 1000
// output: 'TimeInSeconds-RandNum'
// invoke with: cdc.util.randomNumber(50); or cdc.util.randomNumber();
cdc.util.randomNumber = function(limit){
   if (!limit) {limit = 1000};
   var sNum = Math.floor(Math.random()*limit)+1;
  var sTime = (new Date).getTime();
  var rNum = sTime+"-"+sNum;
  return rNum;
}


cdc.util.getSiteArea = function(){

/*
must be one of:
-------------------
About_Cisco
Campaign_Sites
Discussion_Forums
Framework
Global
Home_Pages
Industry_Solutions
Learning_and_Events
Mobile
Networking_Solutions
Ordering
Partners_and_Resellers
Products
Search
Security
Services
Tech_Support
Technologies

*/

   var cdcSiteArea='';
   var siteAreaFrom='';
   // Check URL for known matches
   var siteareasArray = [
      ["\/web\/about\/", "About Cisco"],
      ["\/web\/learning\/", "Learning and Events"],
      ["\/web\/ordering\/", "Ordering"],
      ["\/web\/partners\/", "Partners and Resellers"],
      ["\/web\/strategy\/", "Industry Solutions"]
   ];
   for (z = 0; z < siteareasArray.length; z++) {
      if (location.href.search(siteareasArray[z][0]) != -1) {
         cdcSiteArea = siteareasArray[z][1];
         siteAreaFrom = 'url';
      }
   }


   //check hinav
   try{
      //cdcSiteArea = document.getElementById("framework-column-left").getElementsByTagName('li')[1].childNodes[0].innerHTML;

      cdcSiteArea = document.getElementById("framework-column-left").getElementsByTagName('li')[1].getElementsByTagName('a')[0].innerHTML;

      siteAreaFrom = 'hinav';

   } catch(e) {}


   // Check "iaPath" Meta tag data if present
   var metatags = document.getElementsByTagName("meta");
   for (var m = 0; m < metatags.length; m++) {
      var curr_name = metatags[m].getAttribute("name");
      var curr_content = metatags[m].getAttribute("content");
      if (curr_name == "iaPath") {
         var iaPathArray = curr_content.split("#");
         cdcSiteArea = iaPathArray[1]?iaPathArray[1]:cdcSiteArea;
         siteAreaFrom = 'meta';
      }
   }
   for (m = 0; m < metatags.length; m++) {
      var curr_name = metatags[m].getAttribute("name");
      var curr_content = metatags[m].getAttribute("content");
      if (curr_name == "contentType") {
         if (curr_content.indexOf("postSales") > 0){
           cdcSiteArea = "Support";
           siteAreaFrom = 'meta(support)';
         }
      }
   }

   cdcSiteArea = cdcSiteArea.toLowerCase();
   var t = cdcSiteArea.split(' ');
   cdcSiteArea="";
   for (var m=0;m<t.length;m++){
      if (t[m]=='and'){
         cdcSiteArea += t[m] + " ";
      }
      else {
         cdcSiteArea += t[m].substring(0,1).toUpperCase() + t[m].substring(1) + " ";
      }
   }
   cdcSiteArea = cdcSiteArea.replace(/ $/,'');

   cdcSiteArea = cdcSiteArea.replace(/ &amp; /,'_and_');
   cdcSiteArea = cdcSiteArea.replace(/ /g,'_');
   cdcSiteArea = cdcSiteArea.replace(/Partner_Central/,'Partners_and_Resellers');
   cdcSiteArea = cdcSiteArea.replace(/Support/,'Tech_Support');
   return cdcSiteArea;

} // end getSiteArea()


/* ------------------------------------------------------------
  page location hash reader/setter for widgets
   ------------------------------------------------------------ */

cdc.util.setToHash = function(widget,val){
   var cur = cdc.util.getFromHash();
   var newHash='';
   if (widget&&val){
      cur[widget] = val;
   }
   for (widget in cur){
      newHash += widget+'~'+cur[widget]+',';
   }
   newHash = newHash.substr(0,newHash.length-1);
   newHash = '#~'+newHash;
   window.location.hash = newHash;
};

cdc.util.getFromHash = function(){
   var ret = {};
   var h = window.location.hash;
   if (h.indexOf("#~")<0){
      return ret;
   }
   h = h.substr(2);

   currHashArr = h.split(",");
   for (h=0; h<currHashArr.length; h++){
      var pair = new Array();
      pair = currHashArr[h].split('~');
      if (!(pair[1])){
         ret['tab']=pair[0];
      } else {
         ret[pair[0]] = pair[1];
      }
   }
   return ret;
};

/* This is being obsoleted by /web/fw/lo/sso.js, leaving temporarily */
/* cdc.util.sso = function () {
   if ((window.location.host == 'cisco.com')||(window.location.host == 'www.cisco.com')||(window.location.host == 'www-test.cisco.com')){
      var url = "https://fedps.cisco.com/idp/startSSO.ping?PartnerSpId=https://fedam.cisco.com&IdpAdapterId=fedsmidpCCO&TargetResource=http%3A//www.cisco.com/cisco/psn/web/site/collab/sign.html";
   }
   else {
      var url = "https://fedps-stage.cisco.com/idp/startSSO.ping?PartnerSpId=pfoam&IdpAdapterId=fedsmidpCCO&TargetResource=http%3A//cepx-active-stage1.cisco.com/cisco/psn/web/site/collab/sign.html";
   }
   if (cdc.cookie.getCookie({cookieName:"SMSESSION"})!='') {
      if (cdc.cookie.getCookie({cookieName:"LtpaToken"})==''||cdc.cookie.getCookie({cookieName:"cdc_ltpa_timeout"})=='') {
         document.tempImg = new Image();
         document.tempImg.src = url;
         /*
         try{
            var t = jQuery.ajax({'url':url,
               complete:function(x,t){
                  //todo: check if this has been redirected to a login page
                  //and if so clear cookies
                  //console.log('success');
               },
               error: function(x,t){
                  if (x.status == '302'){
                     cdc.cookie.setCookie({cookieName:"SMSESSION",cookieValue:'',msecs:2});
                     cdc.cookie.setCookie({cookieName:"LtpaToken",cookieValue:'',msecs:2});
                     cdc.cookie.setCookie({cookieName:"cdc_ltpa_timeout",cookieValue:'',msecs:2});
                  }
               }
            });
         }catch(e){
            //console.log('catch');
         }
         */
/*         var msecsFromNow = (1000*60*19);
         var n = new Date();
         n.setTime(n.getTime()+msecsFromNow);
         cdc.cookie.setCookie({cookieName:"cdc_ltpa_timeout",cookieValue:n.getTime(),msecs:msecsFromNow});
      }
      if (cdc.cookie.getCookie({cookieName:"cdc_ltpa_timeout"})){
         //set timeout for as long as cookie has left; call self at timeout end.
         var n = new Date();
         var timerDuration = cdc.cookie.getCookie({cookieName:"cdc_ltpa_timeout"}) - n.getTime() + 100;
         if (timerDuration>0){
            setTimeout(cdc.util.sso,timerDuration);
         }
      }
   }
}
*/

/**
 * isAuthenticated: Returns user authentication status, decoupled from direct Cookie value. For use in Universal Tagging integration points and other 3rd party tools.
 *
 * Example:
 *    var userStatus = cdc.util.isAuthenticated();
 *    
 */
cdc.util.isAuthenticated = function () {
	var loggedInCookieVal = cdc.cookie.getCookie('SMSESSION');
    var userAuthStatus = null;
    if ( loggedInCookieVal && loggedInCookieVal != '' && loggedInCookieVal != 'LOGGEDOFF'){
    	userAuthStatus = true;
    } 
    else {
    	userAuthStatus = false;
    }
    return userAuthStatus; 
} 
 
 
/**
 * htmlEscape: Replace escapable characters by their encoded HTML equivalents.
 * Each occurrence of one of the escapable characters in the string is replaced by its
 * numerically-HTML-escaped form. (For example, the '<' symbol is replaced by the string &#60;)
 * @param aString the string to escape
 * @param escapeChars (optional) the characters in the string that should be escaped. If this parameter is not
 * specified, it is assumed to be the string "<>'", thus escaping the three characters ", < and >.
 * @return the escaped string
 */
cdc.util.htmlEscape = function (aString, escapeChars) {
    if (!aString || typeof (aString) != "string") return aString;
    if (typeof (escapeChars) == "undefined") escapeChars = "<>\'";
    var escapeCharsRegex = new RegExp ("([" + escapeChars + "])", "g");
    return aString.replace (escapeCharsRegex, function (match) {
        return "&#" + match.charCodeAt(0) + ";";
    });
};

/**
 * cdc.util.addCorners - takes the jQuery selector string to hunt for as required input.
 * then adds spans to put the corners in
 * css needs to be written separately to specify what images to use for corners and how to position them
 */
cdc.util.addCorners = function (myselect,doDiv) {
    if (doDiv) {
       jQuery(myselect).append(
          '<div class="ctl"></div><div class="ctr"></div><div class="cbl"></div><div class="cbr"></div>'
       );
    }
    else {
       jQuery(myselect).prepend('<span class="cl-top-corners"><span></span></span>').append('<span class="cl-bottom-corners"><span></span></span>');
    }
}



/**
 * formatString: A simple string formatting utility
 *
 * Example:
 *    var fName = "Joe", lName = "Smith";
 *    var formatted = cdc.util.formatString ("Dear {0} {1}", fName, lName);
 */
cdc.util.formatString = function (formatStr) {
    var args = arguments.length > 1 ? Array.prototype.slice.call (arguments, 1) : [];
    var str = formatStr.replace (/\{\d+\}/g, function (match) {
        var index = parseInt (match.substring (1, match.length-1));
        return args.length > index ? args[index] : match;
    });
    return str;
};


// bam adaptive/targeted media
cdc.bam = {};
cdc.bam.mediaCallback = function(data){
   jQuery(data.domId).show();
   jQuery(data.domId).html(data.blob);
   data.readyCallback();
};


/* *** For Newsfeeds, code used by N05v17 can be used by others *** */
   cdc.util.ensureNamespace('cdc.newsfeed');

   cdc.newsfeed.renderNews = function (json) {
      alert("cdc.newsfeed.renderNews() has not been defined by a consumer! Specify for your own component incoming json: " + json);
   }

   cdc.util.ensureNamespace('cdc.homepage.newsfeed');
   cdc.homepage.newsfeed.renderNews = function (json) { cdc.newsfeed.renderNews(json); }



// why is this here and not somewhere else?
cdc.mru = {
   serviceHost: "",
   serviceUrl: "/cisco/web/cdc/psa/mru?command=update&callbackFunctionName=somevalue",
   // -- Special need for server-side gzip support --^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ (Without this parameter, certain web clients will break when the content is gzipped)
   // Rant: This really should have been handled by said web client, but that client is breaking HTTP protocol. Oh well.
   timeOutMsecs: 250,
   makeMruRequest: function(anchor,args) {

      var updateUrl = cdc.mru.serviceHost + cdc.mru.serviceUrl;
      if (args){
         updateUrl += args;
      }
      else if (anchor.mruExpando){
         updateUrl += anchor.mruExpando;
      }
      else if (anchor.rel) {
         updateUrl += anchor.rel;
      }

      var serviceReturnUrl = anchor.href;
      var timeoutUrl = anchor.href;
      if (cdc.debug.on){
         timeoutUrl += "?timeout";
         serviceReturnUrl += "?serviceReturn";
      }
      var loadHandler = function(){window.location.href=serviceReturnUrl;};
      cdc.mru.tempDoc = document.createElement('iframe');
      document.getElementById('framework-footer').appendChild(cdc.mru.tempDoc);
      if (cdc.mru.tempDoc.attachEvent){
         cdc.mru.tempDoc.attachEvent('onload', loadHandler);
      }
      else {
         cdc.mru.tempDoc.onload = loadHandler;
      }
      cdc.mru.tempDoc.src = updateUrl;
      jQuery(cdc.mru.tempDoc).hide();

      setTimeout("window.location.href='" + timeoutUrl+"'", cdc.mru.timeOutMsecs);
      return false;
   }
};

cdc.mru.timeOutMsecs = 50000;

cdc.util.is1x = (window.location.href.indexOf("/en/US/") >1 );
cdc.util.campPlatforms = new Array ("tools.cisco.com","tools-dev.cisco.com","tools-stage.cisco.com","apps.cisco.com","apps-dev.cisco.com","apps-stage.cisco.com","/cgi-bin/","/pcgi-bin/");
cdc.util.isCamp = false;
for (platform in cdc.util.campPlatforms) {
    if (window.location.href.indexOf(cdc.util.campPlatforms[platform]) >1 ) {
        cdc.util.isCamp = true;
        break;
    }
}

/*
//TODO: delete this comment
//moving this to _toolbar.js -gr
if ( cdc.util.is1x || cdc.util.isCamp ) {
    jQuery(document).ready(function() {
		var logouturl = "https://www-stage.cisco.com/autho/logout.html?ReturnUrl=http://ecmx-active-stage.cisco.com/web/fw/lo/logout.html?locale=en_US";
		var loggedInCookie = cdc.cookie.getCookie({cookieName:'SMSESSION'});
		if ( loggedInCookie && loggedInCookie != '' && loggedInCookie != 'LOGGEDOFF'){
			jQuery(".ft-register").remove();
			jQuery(".ft-login").replaceWith('<div class="ft-sect ft-logout"><a class="ft-label" href="'+logouturl+'">Log Out</a></div>');
		}
	});
}
*/

//jQuery(document).ready(function() {
///* temporary - turn logout link back on for js-only solution */
//	jQuery('.ft-logout').css('display','inline');
//});

cdc.util.ensureNamespace('cdc.util.logoutdialog');

cdc.util.logoutdialog.show = function() {
	
	cdc.util.ensureNamespace('cdc.local.wpx');
	if (! jQuery('#logoutmsg').length ) {

		// if other values were in RB bundle, those are used, otherwise here are defaults
		cdc.local.wpx = jQuery.extend({
			LOGOUT_MODAL_TITLE: "Log Out",
			LOGOUT_MODAL_QUERY: "You are about to logout of Cisco.com.<br />If your task is incomplete, please click Cancel to finish or save.",
			LOGOUT_YES_BUTTON_TEXT: "Log Out",
			LOGOUT_NO_BUTTON_TEXT: "Cancel"
		}, cdc.local.wpx);
        
        cdc.util.logoutdialog.url = this.href;

		cdc.util.logoutdialog.html =
			'<div id="logoutmsg"><span id="lm-corner-top"><span></span></span>'
				+'<h4>'+cdc.local.wpx.LOGOUT_MODAL_TITLE+'</h4>'
				+'<div>'+cdc.local.wpx.LOGOUT_MODAL_QUERY+'</div>'
				+'<a class="a00v1" href="'+cdc.util.logoutdialog.url+'">'+cdc.local.wpx.LOGOUT_YES_BUTTON_TEXT+'</a>'
				+'<a id="logoutclose" class="a00v1" href="javascript:return false">'+cdc.local.wpx.LOGOUT_NO_BUTTON_TEXT+'</a>'
			+'<span id="lm-corner-bot"><span></span></span></div>';

		jQuery(this).append(cdc.util.logoutdialog.html);
		jQuery('#logoutmsg').jqm({modal: true, toTop: true}).jqmAddClose('#logoutmsg #logoutclose');
	}
	jQuery('#logoutmsg').css('left',  jQuery('#fw-banner').offset().left+240 );
	jQuery('#logoutmsg').jqmShow();
	return false;
}

/* logout dialog box gets shown to all platforms except IE 6, when logout clicked, if js is enabled. */
if ( ! (jQuery.browser.msie && jQuery.browser.version <"7" ) ) jQuery('.ft-logout a[href]').live('click', cdc.util.logoutdialog.show);


/**
 * Replaces 1.x footer copyright current year with id specified year.
 * Will only replace inside correctly id'd item, in this case a span tag.
 * This is only a turn of the year band-aid.
 * "footer_nav_legal.xsl" must still be updated.
*/
jQuery(document).ready(function() {
   var copyrightYear = '2010';
   if (jQuery("#footer-copyright-year").html() < copyrightYear) {
      jQuery("#footer-copyright-year").html(copyrightYear);
   }
});
/* remove this if all is well after 10/5 masterbrand release - equivalent code is in masterbrand_frag/_skip.js
jQuery(document).ready(function(){
    jQuery("#skiplinks").addClass('skiplinks').removeClass('skiplinkShow');
    jQuery("#skiplinks a").focus(function() { jQuery("#skiplinks").addClass('skiplinkShow').removeClass('skiplinks');});
    jQuery("#skiplinks a").blur(function() { jQuery("#skiplinks").addClass('skiplinks').removeClass('skiplinkShow');});
});
*/


document.write('<style>.showForJs{display:block;}.showInlineForJs{display:inline;}.hideForJs{display:none;}</style>');

