// GetCPLocation();          // Initial call

function SwapControlPanel() {
   SC = document.getElementById('SideControls');
   BC = document.getElementById('BottomControls');
   if (CPLocation == 'Side') {
      BC.innerHTML = SC.innerHTML;
      SC.innerHTML = '';
      CPLocation   = 'Bottom';}
   else {
      SC.innerHTML = BC.innerHTML;
      BC.innerHTML = '';
      CPLocation   = 'Side';
   };
}

function GetCPLocation() {
   CPLocation = GetCookie('CPLocation');
   if ((CPLocation == null)   
    || (CPLocation == "")
    || (CPLocation == 'Side'))
      CPLocation = 'Side';
   else {
      CPLocation = 'Side';
      SwapControlPanel();
   };
}
  
function SaveControlPanelLocation() {
//   SwapControlPanel();  // stupid call in order to get rid of single click;
   SetCookie('CPLocation',CPLocation,91);
   alert('Control Panel saved to '+CPLocation);
}

function GetCookie(CookieName) {
   if (document.cookie.length>0) {
      CookieStart=document.cookie.indexOf(CookieName + "=");
      if (CookieStart!=-1) { 
         CookieStart=CookieStart + CookieName.length+1;
         CookieEnd=document.cookie.indexOf(";",CookieStart);
         if (CookieEnd==-1) CookieEnd=document.cookie.length
            return unescape(document.cookie.substring(CookieStart,CookieEnd));
    };
  };
  return "";
}

function SetCookie(CookieName,Value,Expiredays) {
   var expdate=new Date();
   expdate.setDate(expdate.getDate()+Expiredays);
   document.cookie=CookieName + "=" + escape(Value) +
      ((Expiredays==null) ? "" : ";expires=" + expdate.toGMTString());
}
