/* 
*  Author:  Jim Harvey
*  File name: ShowHide.js
*
*  Shows and hides the right rail on the ContentPage
*/

var isLeftHidden = true;
var isRightHidden = false;

/*
*   Function name: showHideColumn
*	Inputs:  rhrId - the id of the table that holds the right hand rail
			 showLinkId - the id of the show link
			 hideLinkId - the id of the hide link
			 showHide - either 'show' or 'hide' to direct function's effects
*/
function showHideColumn (rhrId,showLinkId,hideLinkId,showHide) {
  createCookie('showHideCookie', showHide);
  var rhr = document.getElementById(rhrId);
  var sl = document.getElementById(showLinkId);
  var hl = document.getElementById(hideLinkId);
  var lc = document.getElementById('show_hide_link_container');
  if(showHide == 'show')
  {
    rhr.style.display = '';
  	sl.style.display = 'none';
  	hl.style.display = '';
  }
  else 
  {
    rhr.style.display = 'none';
  	hl.style.display = 'none';
  	sl.style.display = '';
  }
  if(lc.style.display == 'none') lc.style.display = 'block';
  return false;
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function initShowHide()
{
  if((location.href.indexOf('showRHR=true')>0) || (location.href.match(/content7_.*_.*_.*_.*_.*_true/i) != null))
  {
    var cookieData = readCookie('showHideCookie');
    if(cookieData != null)
    {
      showHideColumn ('right_hand_rail', 'show_link', 'hide_link', cookieData);
    }
    else
    {
      showHideColumn ('right_hand_rail', 'show_link', 'hide_link', 'show');
    }
  }
}