st_useSmartTools = false; //value is changed when smart_tools.js is loaded
var timezone = null;

$(document).ready (
  function()
  {
    timezone = jstz.determine_timezone();
    $.post('set_timezone.php',{tz_name:timezone.name(),tz_dst:timezone.dst(),tz_offset:timezone.offset()},
      function(data)
      {
        switch(data.error)
        {
          case 'ok':
//            alert('ready');
            break;
          default:
            handleError(data);
            break;
        }
        
      },'json'
    )
    
    if(isSet(st_useSmartTools) && st_useSmartTools==true)
      setTimeout('st_checkToDoPopup()',1000);
    
    setInterval(
      function()
      {
        $.post('refresh.php',null,
          function(data)
          {
            
          },'html'
        );
        
        if(isSet(st_useSmartTools) && st_useSmartTools==true)
          st_checkToDoPopup();
        
      },300000
    );
  }
)

function checkBrowser(level)
{
  switch(level)
  {    
    case 'SMART_TOOLS':
      //check if the browser is good enough for use of the smart tools

      if($.browser.msie && $.browser.version<7)
      {
        alert('this browser is not capable of displaying this smart tool correctly. If you want to use Internet Explorer, please use version 7 or higher. You can also use Google Chrome or Mozilla Firefox.');
        return false;
      }
      return true;
    default:
      return true;
  }
  
  return true;
}

function changePassword()
{
  if(siteClientID==-1)
  {
    alert("MRC-Transmark users cannot change their password through the website. Contact your system administrator for more information");
  }
  else
  {
//    alert("change password for user with id: " + siteClientID);
    
//    $.post('changePassword_submit.php',{userID:siteClientID
    $('#change_password_div').removeClass('hide_password_box');
    openModal($('#change_password_div'));
    $('#close_password_box').unbind("click").click(
      function()
      {
        closeModal($('#change_password_div'));
        $('#change_password_div').addClass('hide_password_box');
      }
    )
    
    $('#change_password_send').unbind("click").click(
      function()
      {
        var oldpw = $('#change_password_old').val();
        var newpw1 = $('#change_password_new').val();
        var newpw2 = $('#change_password_new2').val();
        $.post('changePassword_submit.php',{old:oldpw,new1:newpw1,new2:newpw2},changePasswordReady,'json');
      }
    )
  }
}
function changePasswordReady(data)
{
  switch (data.error)
	{
	case 'OK':
    alert('password changed successfully');
		break;
	default:
		alert(data.error);
		break;
	}
	$('#change_password_div').addClass('hide_password_box');
	closeModal($('#change_password_div'));
}
