﻿function ResizeChatWindow()
{
  var dialogueDiv = document.getElementById('DialogueDiv');
  var chatdialogueDiv = document.getElementById('chatdialogue');
  var videoDiv = document.getElementById('VideoDiv');
  var chatReqDiv = document.getElementById('RequestListDiv');
  var thumbDiv = document.getElementById('ThumbnailDiv');
  var alertMeDiv = document.getElementById('AlertMeDiv');
  var inputDiv = document.getElementById('InputDiv');
  var buttonsDiv = document.getElementById('ButtonsDiv');
  
  var iWidth = ReturnWindowWidth();
 
  if(iWidth > 600)
  {
    var videoWidth = videoDiv.offsetWidth;
    videoDiv.style.left = iWidth - videoWidth + 'px';

    var chatReqWidth = chatReqDiv.offsetWidth;
    chatReqDiv.style.left = iWidth - chatReqWidth + 'px';

    var buttonsWidth = buttonsDiv.offsetWidth;
    buttonsDiv.style.left = iWidth - buttonsWidth + 'px';

    var leftsideNewWidth = iWidth - videoWidth - 20;
    dialogueDiv.style.width = leftsideNewWidth + 'px';
    chatdialogueDiv.style.width = leftsideNewWidth - 20 + 'px';
    alertMeDiv.style.width = leftsideNewWidth + 'px';
    inputDiv.style.width = leftsideNewWidth - thumbDiv.offsetWidth + 16 + 'px';
    
    var msgareaDiv = ChatInputFrame.document.getElementById('msgarea');
    var inputBox =ChatInputFrame.document.getElementById('Msg_TextBox');
    var inputFrame = document.getElementById('ChatInputFrame');

    var inputDivNewWidth = inputDiv.offsetWidth;
    inputFrame.style.width = inputDivNewWidth - 20 + 'px';
    msgareaDiv.style.width = inputDivNewWidth - 20 + 'px';
    inputBox.style.width = inputDivNewWidth - 25 + 'px';
  }
  
  var iHeight = ReturnWindowHeight();
  if(iHeight > 500)
  {

    var buttonHeight = buttonsDiv.offsetHeight;
    buttonsDiv.style.top = iHeight - buttonHeight + 'px';

    var videoHeight = videoDiv.offsetHeight;
    chatReqDiv.style.height = iHeight - buttonHeight - videoHeight - 10 + 'px';

    var thumbHeight = thumbDiv.offsetHeight;
    thumbDiv.style.top = iHeight - thumbHeight + 'px';    
    inputDiv.style.top = iHeight - thumbHeight + 'px';

    var alertDivHeight = alertMeDiv.offsetHeight;
    var inputDivTop = inputDiv.offsetTop;
    alertMeDiv.style.top = inputDivTop - alertDivHeight -2 + 'px';

    dialogueDiv.style.height = alertMeDiv.offsetTop - 5 + 'px';
    chatdialogueDiv.style.height = dialogueDiv.offsetHeight - 20+ 'px';
  }

}

function ReturnWindowHeight()
{
  var theHeight = 500;
  if(typeof( window.innerHeight ) == 'number' )
  {
    theHeight = window.innerHeight;
  }
  else if(document.documentElement && document.documentElement.clientHeight)
  {
    theHeight = document.documentElement.clientHeight;
  }
  else if(document.body && document.body.clientHeight)
  {
    theHeight = document.body.clientHeight;
  }
  else
  {
    theHeight = 500;
  }
  return theHeight;
}

function ReturnWindowWidth()
{
  var theWidth = 600;
  if( typeof( window.innerWidth ) == 'number' )
  {
    theWidth = window.innerWidth;
  }
  else if(document.documentElement && document.documentElement.clientWidth)
  {
    theWidth = document.documentElement.clientWidth;
  }
  else if(document.body && document.body.clientWidth)
  {
    theWidth = document.body.clientWidth;
  }
  else
  {
    theWidth = 800;
  }
  return theWidth;
}

function ChangeFont()
{
  var fontSizePref = parseInt(GetCookieValue('fontsize'));
  if(isNaN(fontSizePref)){fontSizePref = 10;}
  document.body.style.fontSize = fontSizePref + 'px';
  document.getElementById('AlertMeDiv').style.fontSize = 10 + 'px';
}

function ChangeInputFont()
{
  try
  {
    if(ChatInputFrame)
    {
      var fontSizePref = parseInt(GetCookieValue('fontsize'));
      if(isNaN(fontSizePref)){fontSizePref = 11;}
      var inputBox =ChatInputFrame.document.getElementById('Msg_TextBox');
      inputBox.style.fontSize = fontSizePref + 'px';
    }
  }catch(e){}
}
