function setLclDisplayName(firstname, lastname, displayname)
{
  var manager = GetManager();	
  if (!manager) {    
    return; 
  }

  //In the outgoing invite of the ActiveX control, the users display name should be 
  //filled in the SIP from header.
  if (displayname == '') {  	
  	var displayname = firstname + ' ' + lastname;  	
  }            
  PrintToLogfile('VIDIVIC-LOG: function call: manager.SetLocalDisplayName(' + displayname.toString() + ')');
  var result = manager.SetLocalDisplayName( displayname );
  PrintToLogfile('VIDIVIC-LOG: function result: SetLocalDisplayName = ' + result.toString());    
}

function isLoggedOn()
{
	var manager = GetManager();	
	if (! manager) {
    alert(' isLoggedOn :: no manager! ');
  }  
  PrintToLogfile('VIDIVIC-LOG: function call: manager.IsSignedIn()');
  var result = manager.IsSignedIn ( );
  PrintToLogfile('VIDIVIC-LOG: function result: IsSignedIn = ' + result);  
  
  return result;
}

function iWebLogoff()
{
	var manager = GetManager();	
	if (!manager) {
    //window.location = "index.php?page=" + _PAGE_PREFERENCES;
    return false;
  }    
  PrintToLogfile('VIDIVIC-LOG: function call: SignOut()');  
  var result = manager.SignOut();
  PrintToLogfile('VIDIVIC-LOG: function result: SignOut = ' + result);  
  
  return result;
}


function create_manager(class_id, new_class_id, params, div_id, include_version)
{
  if( typeof include_version == "undefined")
    include_version = false;

  var div = document.getElementById(div_id);
  div.style.cssText = 'display: none;';
  //include_version is used for future releases... not needed right now...
  /*if( include_version )
  {*/
    div.innerHTML = '<object id="Intellivic_Manager" classid="CLSID:' + class_id + '" ' + params + '></object>' +
                  '<object id="Intellivic_New_Manager" classid="CLSID:' + new_class_id + '" ' + params + '></object>';
  /*}
  else
  {
    div.innerHTML = '<object id="Intellivic_New_Manager" classid="CLSID:' + new_class_id + '"  ></object>';
  }*/
  
  try
  {
    var manager = GetIntellivicJavascriptManager();
    makeCallbacks(manager);//TODO to be replaced in a future release (by intellivic_api.make_callbacks)
    
    keepAlive();
    
    //not yet created so check for version!
    if( manager.GetValueForKey('manager_created') == '' )
    {
      manager.SetValueForKey('manager_created','true');

      /*var sdk = GetJavascriptSdk();
      sdk.download_network_config_file();

      g_check_download_timeoutId = window.setTimeout("check_download_network_file()",1000);*/
	CheckVersion();
    }
    /*else //Manager is already declared
    {
      //test here if version is big enough;
      //if the function is called directly there is an indefinite loop :s
      alert('create_manager');
      g_version_check = window.setTimeout("CheckVersion()",500);
      return;
    }*/
  } catch( exc)
  {
  //in a future release this is used
    /*if( include_version == false)
    {
      div.innerHTML = "";
      create_manager(class_id,new_class_id,params,div_id,true);
    }*/
    return;
  }
  //if everything is ok include also the 'old' manager
  /*if( !include_version )
  {
	div.innerHTML = '<object id="Intellivic_Manager" classid="CLSID:' + class_id + '" ></object>' +
                  '<object id="Intellivic_New_Manager" classid="CLSID:' + new_class_id + '" ></object>';
  }*/
}

function CheckVersion()
{
  var sdk = GetJavascriptSdk();
  var updater = sdk.get_updater ();
  
  if( updater.get_status() == intellivic_api.updater.enum__status__mandatory || updater.get_status() == intellivic_api.updater.enum__status__optional)
  {
    parent.location.replace("index.php?page=download"); 
  }
}

g_Downloaded_Network_Config_File = false;
g_Downloaded_Network_Config_File_error = 0;
g_check_download_timeoutId = 0;

function check_download_network_file()
{
  try
  {
    if( !g_Downloaded_Network_Config_File ) 
    {
      g_check_download_timeoutId = window.setTimeout("check_download_network_file()",100);
    }
    else{ //check version!
      window.clearTimeout( g_check_download_timeoutId );
      CheckVersion();
      return;
    }
  } catch( exc)
  {
    ;//alert(exc);
  }
}

//Should be replace in a future release by intellivic_api.get_manager()
function GetIntellivicJavascriptManager()
{
  return Intellivic_New_Manager; 
}

/*
15.03.07: No longer used. If it ever was.
function ChangePrimaryAlias(sender)
{
	var control = myGetElementById(sender);
	if (!control) {
		return;
	}
	
	var email_id = control.value;
	
	window.location = "index.php?page=" + _PAGE_ACCOUNT + "&action=changeprimary&email_id=" + email_id;	
}
*/