///////////////////////////////////////////////
// Screen Height
///////////////////////////////////////////////

  if (typeof window.attachEvent != 'undefined')
  {
    window.attachEvent('onload', SetMainScreenPositions);
    window.attachEvent('onresize', SetMainScreenPositions);
  }
  if (typeof window.addEventListener != 'undefined')
  {
    window.addEventListener('load', SetMainScreenPositions, false);
    window.addEventListener('resize', SetMainScreenPositions, false);
  }
  
  var HasResized = 0;

  function SetMainScreenPositions()
  {
    //if (HasResized == 1) return;
    //var iHeight = f_clientHeight() - 20;
    //if (iHeight > document.body.clientHeight) iHeight = document.body.clientHeight - 20;
    //HasResized = 1;
    //var tableOuter = document.getElementById('divOuter');
    //if (tableOuter != null)
    //{
    //  tableOuter.height = iHeight + 'px';
    //}
    //var iHeight = f_clientHeight();
    
    
    //var iHeight = document.body.Height;
    //alert(iHeight);
    //if (IsInitialScreen == 0)
    //  iHeight = iHeight - 255;
    //else
    //  iHeight = iHeight;
    ////iHeight = 300;
    //alert(iHeight);
    //var tableInner = document.getElementById('tableInner');
    //if (tableInner != null)
    //{
    //  tableInner.height = (iHeight - 200) + 'px';
    //}
    //window.setTimeout("resetResizeIndicator()",1000)   
    SetProcessingDiv(); 
    CreateWelcomeMessagePos();
    ShowCompanyLogoPos();
  }

  function resetResizeIndicator()
  {
    HasResized = 0;
  }

  function f_clientHeight() 
  {
	  return f_filterResults (
		  window.innerHeight ? window.innerHeight : 0,
		  document.documentElement ? document.documentElement.clientHeight : 0,
		  document.body ? document.body.clientHeight : 0
	  );
	}
	
	function f_filterResults(n_win, n_docel, n_body) {
	  var n_result = n_win ? n_win : 0;
	  if (n_docel && (!n_result || (n_result > n_docel)))
		  n_result = n_docel;
	  return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
  }
	
  //window.attachEvent('onload', SetProcessingDiv);
  //window.attachEvent('onresize', SetProcessingDiv);
  var IsInitialScreen = 0;

  function SetProcessingDiv()
  {
    if (IsInitialScreen == 0)
    {
      bic_ProcessingDivTop = 30; 
      bic_ProcessingDivLeft = (document.body.clientWidth/2)+185;
    }
    else
    {
      bic_ProcessingDivTop = 30; 
      bic_ProcessingDivLeft = (document.body.clientWidth/2)-100;
    }    
    bic_ProcessingDivHeight = 60; 
    bic_ProcessingDivWidth = 220;
  }

////////////////////////////////////////
// Welcome message
////////////////////////////////////////
  function CreateWelcomeMessage(sName)
  {
    var topDiv = document.createElement('DIV');
    topDiv.id = 'divWelcomeTop';    
    topDiv.style.position = 'absolute';
    topDiv.style.overflow = 'hidden';
    topDiv.className = 'WelcomeStyleTop';
    topDiv.innerHTML = 'Welcome ' + sName;  
    
    document.forms[0].appendChild(topDiv); 
    CreateWelcomeMessagePos();  

    /*var bottomDiv = document.createElement('DIV');
    bottomDiv.id = 'divWelcomeBottom';    
    bottomDiv.style.top = '184px';
    bottomDiv.style.left = '0px';
    bottomDiv.style.height = '18px';
    bottomDiv.style.width = '100%';
    bottomDiv.style.position = 'absolute';
    bottomDiv.style.overflow = 'hidden';
    //bottomDiv.className = 'WelcomeStyle';
    bottomDiv.innerHTML = '<div class="WelcomeStyleBottom" style="top:-9px;position:absolute;width:100%;">WELCOME ' + sName + '</div>';    
    
    document.forms[0].appendChild(bottomDiv); */
  }
  
  function CreateWelcomeMessagePos()
  {
    var divMessageDiv = document.getElementById('divWelcomeTop');
    if (divMessageDiv != null)
    {
      divMessageDiv.style.top = '15px';
      divMessageDiv.style.left =  (document.body.clientWidth/2)+95 + 'px';
      divMessageDiv.style.height = '18px';
      divMessageDiv.style.width = '300px';    
    }
  }
  
////////////////////////////////////////
// Image Resizing
////////////////////////////////////////
  var HasResizedImage = 0;
  function ResizeImage(imgID, MaxHeight, MaxWidth)
  {    
    var imgToResize = document.getElementById(imgID);
    imgToResize.removeAttribute("height");
    imgToResize.removeAttribute("width");
    if (imgToResize.height > MaxHeight)
    {
      imgToResize.height = MaxHeight;
    }
    // Check that the width is under the maxwidth after the height is set - if not, set the width
    // (which will cause the height to adjust
    if (imgToResize.width > MaxWidth)
    {
      imgToResize.removeAttribute("height");
      imgToResize.width = MaxWidth;
    }
    if (HasResizedImage == 0)
    {
      HasResizedImage = 1;
      window.setTimeout("ResizeImage('" + imgID + "'," + MaxHeight + "," + MaxWidth + ")",20)
    } 
  }
  
////////////////////////////////////////
// Show Company Logo
////////////////////////////////////////
  function ShowCompanyLogo(lAttID, lVN)
  {
    var logoDiv = document.createElement('DIV');
    logoDiv.id = 'divCompanyLogo';    
    logoDiv.style.position = 'absolute';
    logoDiv.style.overflow = 'hidden';
    logoDiv.style.verticalAlign = 'top';

    var sInnerHTML = '';
    
    sInnerHTML = '<table cellSpacing="0" cellPadding="0" border="0" style="height:96%">';
    sInnerHTML += ' <tr height="100%">';
    sInnerHTML += '   <td nowrap class="CompanyLogoLeftStyle"></td>';
    sInnerHTML += '   <td nowrap width="100%" align="center" valign="middle">';
    sInnerHTML += '     <img id="imgCompanyLogo" src="AttachmentViewer.aspx?AttID=' + lAttID + '&vn=' + lVN + '" style="border-width:0px;" />';
    sInnerHTML += '   </td>';
    sInnerHTML += ' </tr>';
    sInnerHTML += ' <tr>';
    sInnerHTML += '   <td nowrap class="CompanyLogoBottomLeftStyle"></td>';
    sInnerHTML += '   <td nowrap class="CompanyLogoBottomStyle"></td>';
    sInnerHTML += ' </tr>';
    sInnerHTML += ' </tr>';

    
    logoDiv.innerHTML = sInnerHTML;    
    
    document.forms[0].appendChild(logoDiv); 
    ShowCompanyLogoPos();
    
    ResizeImage('imgCompanyLogo', 75, 200);
  }
  
  bicShowCompanyLogo = 1;
  function ShowCompanyLogoPos()
  {
    if (bicShowCompanyLogo == 1)
    {
      var logoDiv = document.getElementById('divCompanyLogo');
      if (logoDiv != null)
      {    
        logoDiv.style.top = '265px';
        logoDiv.style.left =  (document.body.clientWidth/2)+198 + 'px';
        logoDiv.style.height = '80px';
        logoDiv.style.width = '204px';    
      }
    }
  }
  
  function HideCompanyLogo()
  {
    bicShowCompanyLogo = 0;
    var logoDiv = document.getElementById('divCompanyLogo');
    if (logoDiv != null)
    {
      logoDiv.style.display = 'none';      
      document.forms[0].removeChild(logoDiv); 
    }
  }

////////////////////////////////////////
// Activity Balloon
////////////////////////////////////////
  function ActivityBalloon(sCompanyActivityID, sType, iActivityType, sDescription, sLocation, sDate, sWarning, iWarningType, iButtonType, iPoints, iDisplayWarningWhenAdding)
  {
    var activityDiv = document.createElement('DIV');
    activityDiv.style.height = '50px';
    activityDiv.style.overflow = 'hidden';
    
    var sInnerHTML = '';
    
    sInnerHTML =  '<div style="height:276px; overflow-y: auto; overflow-x: hidden;">';
    sInnerHTML += '<table cellSpacing="0" cellPadding="0" border="0" height="276px" style="height:276px;Width:95%;">';
    sInnerHTML += ' <tr>';
    sInnerHTML += '   <td style="vertical-align:top;font-weight:bold;">';
    sInnerHTML += '     <div style="overflow:auto;">';
    sInnerHTML += '        <table cellSpacing="0" cellPadding="0" border="0" style="Height:100%;Width:100%;">';
    sInnerHTML += '         <tr><td class="LabelStyle" colspan="2" style="color:blue;">';
    if (iActivityType != 3)
    {
      sInnerHTML += 'Activity Type&nbsp;&nbsp;';
      if (iActivityType == 1)
        sInnerHTML += '<span style="color:green;font-style:normal;">Active</span>&nbsp;&nbsp;&nbsp;&nbsp;';
      else
        sInnerHTML += '<span style="color:purple;font-style:normal;">Online</span>&nbsp;&nbsp;&nbsp;&nbsp;';
    }
    sInnerHTML += '         Points:&nbsp;' + iPoints + '</td></tr>';
    sInnerHTML += '         </td></tr>';
    sInnerHTML += '         <tr><td height="5px"></td></tr>';
    sInnerHTML += '         <tr><td class="LabelStyle" colspan="2" style="color:blue;">';
    if (iActivityType != 3)
      sInnerHTML += 'Activity Description';
    else
      sInnerHTML += 'Description';
    sInnerHTML += '         </td></tr>';
    sInnerHTML += '         <tr><td colspan="2">';
    sInnerHTML += sDescription
    sInnerHTML += '         </td></tr>';
    sInnerHTML += '         <tr><td height="10px"></td></tr>';
    sInnerHTML += '         <tr>';
    if (sLocation != '')
    {
      sInnerHTML += '         <td class="LabelStyle" width="50%" style="color:blue;">';
      sInnerHTML += 'Location';
      sInnerHTML += '         </td>';
    }
    else
      sInnerHTML += '         <td></td>';
    if (sDate != '')
    {
      sInnerHTML += '         <td class="LabelStyle" style="color:blue;">';
      sInnerHTML += 'Date';
      sInnerHTML += '         </td>';
    }
    else
      sInnerHTML += '         <td></td>';
    sInnerHTML += '         </tr>';
    sInnerHTML += '         <tr>';
    if (sLocation != '')
    {
      sInnerHTML += '         <td>';
      sInnerHTML += sLocation
      sInnerHTML += '         </td>';
    }
    else
      sInnerHTML += '         <td></td>';
    if (sDate != '')
    {
      sInnerHTML += '         <td valign="top">';
      sInnerHTML += sDate
      sInnerHTML += '         </td>';
    }
    else
      sInnerHTML += '         <td></td>';
    sInnerHTML += '         </tr>';
    sInnerHTML += '         <tr><td height="10px"></td></tr>';
    if (sWarning != '')
    {
      sInnerHTML += '         <td style="color:';
      if (iWarningType == 1)
        sInnerHTML += 'red;';
      else
        sInnerHTML += 'blue;';
      sInnerHTML += '" colspan="2">';
      sInnerHTML += sWarning
      sInnerHTML += '         </td>';
    }    
    sInnerHTML += '       </table>';
    sInnerHTML += '     </div">';
    sInnerHTML += '   </td>';
    sInnerHTML += ' </tr> ';
    // Buttons
    if (iButtonType != 0)
    {
      sInnerHTML += ' <tr>';
      sInnerHTML += '   <td align="center" style="vertical-align: bottom";>';
      sInnerHTML += '     <table cellSpacing="0" cellPadding="0" border="0">';
      sInnerHTML += '       <tr>';    
      sInnerHTML += '         <td>';    
      if (iButtonType == 1)
      {
        sInnerHTML += '           <a onclick="javascript:__doPostBack(\'CALEStartActivity\', \'' + sCompanyActivityID + '\');"';
        sInnerHTML += ' class="LinkButtonBalloonStyle">Start Activity</a>';    
        sInnerHTML += '       </td><td style="width:30px"></td><td>';    
        sInnerHTML += '           <a onclick="javascript:__doPostBack(\'CALERemoveActivity\',\'' + sCompanyActivityID + '\');"';
        sInnerHTML += ' class="LinkButtonBalloonStyle">Remove Activity</a>';    
      }
      if (iButtonType == 2)
      {
        //sInnerHTML += '           <a onclick="javascript:__doPostBack(\'CALEStartAndAddActivity\', \'' + sCompanyActivityID + '\');"';
        //sInnerHTML += ' class="LinkButtonBalloonStyle">Start Activity</a>';    
        //sInnerHTML += '       </td><td style="width:30px"></td><td>';    
        sInnerHTML += '           <a onclick="javascript:ActivityBalloonAdd(' + sCompanyActivityID + ',' + iDisplayWarningWhenAdding + ');"';
        sInnerHTML += ' class="LinkButtonBalloonStyle">Add to my activities</a>';    
      }      
      if (iButtonType == 3)
      {
        sInnerHTML += '           <a onclick="javascript:ActivityBalloonAdd(' + sCompanyActivityID + ',' + iDisplayWarningWhenAdding + ');"';
        sInnerHTML += ' class="LinkButtonBalloonStyle">Add to my activities</a>';    
      }
      if (iButtonType == 4)
      {
        sInnerHTML += '           <a onclick="javascript:__doPostBack(\'CALERedoActivity\', \'' + sCompanyActivityID + '\');"';
        sInnerHTML += ' class="LinkButtonBalloonStyle">Redo Activity</a>';    
      }
      if (iButtonType == 5)
      {
        sInnerHTML += '           <a onclick="javascript:__doPostBack(\'CALEGotoActivity\', \'' + sCompanyActivityID + '\');"';
        sInnerHTML += ' class="LinkButtonBalloonStyle">Goto Activity</a>';    
      }
      if (iButtonType == 6)
      {
        sInnerHTML += '           <a onclick="javascript:__doPostBack(\'CALERemoveActivity\',\'' + sCompanyActivityID + '\');"';
        sInnerHTML += ' class="LinkButtonBalloonStyle">Remove Activity</a>';    
      }
      sInnerHTML += '         </td>';
      sInnerHTML += '       </tr>';    
      sInnerHTML += '       <tr><td height="5px"></td></tr>';
      sInnerHTML += '     </table>';    
      sInnerHTML += '   </td>';
      sInnerHTML += ' </tr> ';    
    }
    sInnerHTML += '</table>';
    sInnerHTML += '</div>';
    
    activityDiv.innerHTML = sInnerHTML;  
    bicBalloon(activityDiv, sType, 300, 500);
  }
  
  function ActivityBalloonAdd(sCompanyActivityID, iDisplayWarningWhenAdding)
  {
    if (iDisplayWarningWhenAdding == 1)
    {
      if (!confirm('Your company has set limits for this type of activity. By adding or completing this activity, ' +
        'you may not get recognition for completing this activity, unless you have discussed this with your HR manager or senior manager. ' +
        'Please try to balance the different types of activities you do, to ensure a balanced approach to your development. ' +
        'If your unsure how to achieve this, please talk to your HR manager or talk to the Leadership OnTrack(TM) team. ' +
        'You may proceed to add this activity to your plan. This is just a warning message.'))
        return;
    }
    __doPostBack('CALEAddActivity','' + sCompanyActivityID + '');    
  }

////////////////////////////////////////
// Search Panel State Changed
////////////////////////////////////////
  function SearchPanelStateChanged(panel, oEvent)
  {
    //if (panel._expanded)
    //  alert('expand');
    //else
    //  alert('collapse');
    //alert(panel._header._panel.setText(panel._header, 'here'));
  }
  
////////////////////////////////////////
// CheckBox List Select
////////////////////////////////////////
  function chkboxlistSelectAll(sChkID)
  {
    chkboxlistSelectAllNone(sChkID, 'checked');
  }
  
  function chkboxlistSelectNone(sChkID)
  {
    chkboxlistSelectAllNone(sChkID, '');
  }

  function chkboxlistSelectAllNone(sChkID, sChecked)
  {
    var ControlExists = 1;
    var i = -1;
    while (ControlExists == 1)
    {    
      i++;
      var oCheck = document.getElementById(sChkID + "_" + i);
      if (oCheck != null)
      {        
        oCheck.checked = sChecked;
      }
      else
        ControlExists = false;
    }
  }