function ClearComboBox( combobox )
{		
  var firstChild = combobox.firstChild;
  while ( firstChild ) {
  	combobox.removeChild ( firstChild );
  	firstChild = combobox.firstChild;
  }
}	

function AudioInputs( manager )
{
	if (!manager) {
		return null;
	}

  PrintToLogfile('VIDIVIC-LOG: function call: manager.AudioInputs()');
	var variantList = new VBArray( manager.AudioInputs() );
	PrintToLogfile('VIDIVIC-LOG: function result: AudioInputs = '+variantList.toArray());
	
	return variantList.toArray();
}

function AudioOutputs( manager )
{
	if (!manager) {
		return null;
	}

  PrintToLogfile('VIDIVIC-LOG: function call: manager.AudioOutputs()');
	var variantList = new VBArray( manager.AudioOutputs() );
	PrintToLogfile('VIDIVIC-LOG: function result: AudioOutputs = '+variantList.toArray());
	
	return variantList.toArray();
}

function AudioProfiles( manager )
{
	if (!manager) {
    return null;
  }

  PrintToLogfile('VIDIVIC-LOG: function call: manager.AudioProfiles()');	  
  var variantList = new VBArray( manager.AudioProfiles() );
  PrintToLogfile('VIDIVIC-LOG: function result: AudioProfiles = '+variantList.toArray());
  
  return variantList.toArray();
}

function loadAudioProfiles(combobox)
{
  var _combo = myGetElementById( combobox );
  if (!_combo) {
  	return;
  }			
	
	var manager = GetManager();	
	if (!manager) {
		return;
	}
	
	ClearComboBox(_combo);      
	
  var profiles = AudioProfiles( manager );
	if (!profiles || profiles.length == 0) {
    return;
  }      			
	
  PrintToLogfile('VIDIVIC-LOG: function call: manager.DefaultAudioProfile()');	
	selectedProfileId = manager.DefaultAudioProfile();
	PrintToLogfile('VIDIVIC-LOG: function result: DefaultAudioProfile = '+selectedProfileId);
		
	for (i = 0; i < profiles.length; i++) {
		var profile = document.createElement( 'option' );
		profile.value = profiles[i];		
									
		profile.selected = profile.value == selectedProfileId;				
		
    PrintToLogfile('VIDIVIC-LOG: function call: manager.NameForAudioProfile('+profile.value+')');
		var profileName = manager.NameForAudioProfile( profile.value );
		PrintToLogfile('VIDIVIC-LOG: function result: NameForAudioProfile = '+profileName);
		
		profile.innerHTML = ' ' + profileName;				
		
		_combo.appendChild( profile );
	}		
		
	return selectedProfileId;  		
}

function loadAudioInputVolume( )
{	
	var manager = GetManager();
	if (!manager) {
		return false;
	}					

  PrintToLogfile('VIDIVIC-LOG: function call: manager.VolumeForCurrentAudioInput ().toFixed(2)');
  currentAudioInput = manager.VolumeForCurrentAudioInput ().toFixed(2);	 
  PrintToLogfile('VIDIVIC-LOG: function result: VolumeForCurrentAudioInput ().toFixed(2) = '+currentAudioInput);
	return currentAudioInput;
}

function loadAudioOutputVolume ( )
{							
	var manager = GetManager();
	if (!manager) {
		return false;
	}		
	
	PrintToLogfile('VIDIVIC-LOG: function call: manager.VolumeForCurrentAudioOutput ().toFixed(2)');
	currentAudioOutput = manager.VolumeForCurrentAudioOutput ().toFixed(2);
	PrintToLogfile('VIDIVIC-LOG: function result: VolumeForCurrentAudioOutput ().toFixed(2) = '+currentAudioOutput);
	
	return currentAudioOutput;
}

/*
  
  DEPRECATED

function loadAudioWaveOutputVolume(  )
{		
	var manager = GetManager();
	if (!manager) {
		return;
	}			
	
	PrintToLogfile('VIDIVIC-LOG: function call: manager.VolumeForCurrentWaveAudioOutput().toFixed(2)');
	currentAudioWaveVolume = manager.VolumeForCurrentWaveAudioOutput().toFixed(2);	  
  PrintToLogfile('VIDIVIC-LOG: function result: VolumeForCurrentWaveAudioOutput().toFixed(2) = '+currentAudioWaveVolume);
  
  return currentAudioWaveVolume;
}
*/

function UpdateAudioInputVolume( newVolume, throwError )
{		
	var manager = GetManager();	
	if (!manager) {
	  return null;
	}						
	if (typeof throwError == 'undefined') {
		throwError = true;
	}		   	
	try
	{				
	  PrintToLogfile('VIDIVIC-LOG: function call: manager.SetVolumeForCurrentAudioInput ('+newVolume+')');
    var error = manager.SetVolumeForCurrentAudioInput ( newVolume );  
    PrintToLogfile('VIDIVIC-LOG: function result: SetVolumeForCurrentAudioInput () = '+error, true);
    
    if (error != ISDKERROR_NONE && throwError) {
    	alert( showErrorMsg( error ) );
    }  			
  }
  catch(err) {  
  	if (throwError) {	
  	  alert( showErrorMsg(err) );    
  	}    	  	
  }
}

function UpdateAudioOutputVolume( newVolume, throwError )
{						
	var manager = GetManager();
	if (!manager) {
		return;
	}  		
	if (typeof throwError == 'undefined') {
		throwError = true;
	}		 													
  try
  {
    PrintToLogfile('VIDIVIC-LOG: function call: manager.SetVolumeForCurrentAudioOutput  ('+newVolume+')');
  	var error = manager.SetVolumeForCurrentAudioOutput  ( newVolume );
  	PrintToLogfile('VIDIVIC-LOG: function result: SetVolumeForCurrentAudioOutput  () = '+error, true);						
  	
  	//Volume wordt wel degelijk aangepast, maar toch blijft deze functie error code 2 teruggeven.		  	  	  		
  	if (error != ISDKERROR_NONE && throwError) {
  	  alert( showErrorMsg( error ) );
  	}	
  }
  catch(err) {
  	if (throwError) {	
  	  alert( showErrorMsg(err) );    
  	}  
  }
}

function UpdateAudioWaveOutputVolume( newVolume )
{
	var manager = GetManager();
	if (!manager) {
		return;
	}  																	
			
  try
  {
    PrintToLogfile('VIDIVIC-LOG: function call: manager.SetVolumeForCurrentWaveAudioOutput('+newVolume+')');
  	var error = manager.SetVolumeForCurrentWaveAudioOutput( newVolume );						
  	PrintToLogfile('VIDIVIC-LOG: function result: SetVolumeForCurrentWaveAudioOutput() = '+error, true);		
  	
  	//Volume wordt wel degelijk aangepast, maar toch blijft deze functie error code 2 teruggeven.		
  		
  	if (error != ISDKERROR_NONE) {
  	  alert( showErrorMsg( error ) );
  	}	
  }
  catch(err) {
  	alert( showErrorMsg(err) );
    //alert('Error thrown: ' + err); 
  }
}

function loadAudioOutputDevices(combobox)
{				
	var _combo = myGetElementById( combobox );
	if (!_combo) {
		return;
	}						
	
	var manager = GetManager();	
	if (!manager) {
		return;
	}	
	
	ClearComboBox(_combo);	
	var devices = AudioOutputs( manager );
	if (!devices || devices.length == 0) {
		return;
	}						
	
	PrintToLogfile('VIDIVIC-LOG: function call: manager.CurrentAudioOutput()');
	selectedDevice = manager.CurrentAudioOutput();				
	PrintToLogfile('VIDIVIC-LOG: function result: manager.CurrentAudioOutput() = '+selectedDevice);
	
	PrintToLogfile('VIDIVIC-LOG: function call: manager.SetCurrentAudioOutput('+selectedDevice+')');
  error = manager.SetCurrentAudioOutput( selectedDevice );				
  PrintToLogfile('VIDIVIC-LOG: function result: manager.SetCurrentAudioOutput() = '+error, true); 
  
  for (i = 0; i < devices.length; i++) {
  	
  	if (devices[i].toLowerCase() != 'default') {  	
		  var device = document.createElement( 'option' );
		  PrintToLogfile('VIDIVIC-LOG: function call: manager.NameForAudioOutput()');								
		  deviceName = manager.NameForAudioOutput(devices[i]);
		  PrintToLogfile('VIDIVIC-LOG: function result: manager.NameForAudioOutput() = '+deviceName);
      nameLength = deviceName.length;
      if(nameLength > 55)
        deviceName = deviceName.substring(0, 52)+'...';
		  device.value = devices[i];
		  device.selected = devices[i] == selectedDevice;								
		  device.innerHTML = ' ' + deviceName;						
		  _combo.appendChild( device );
		}  
	}		
		
	return selectedDevice;  				
}

function loadAudioInputDevices(combobox)
{
	var _combo = myGetElementById( combobox );
	if (!_combo) {
		return;
	}			
	
	var manager = GetManager();	
	if (!manager) {
		return;
	}
	
	ClearComboBox(_combo);
	var devices = AudioInputs( manager );
	if (!devices || devices.length == 0) {
		return;
	}					
	
	PrintToLogfile('VIDIVIC-LOG: function call: manager.CurrentAudioInput()');
	selectedDevice = manager.CurrentAudioInput();	
	PrintToLogfile('VIDIVIC-LOG: function result: manager.CurrentAudioInput() = '+selectedDevice);	
		
  PrintToLogfile('VIDIVIC-LOG: function call: manager.SetCurrentAudioInput('+selectedDevice+')');
  error = manager.SetCurrentAudioInput( selectedDevice );	      	
  PrintToLogfile('VIDIVIC-LOG: function result: manager.SetCurrentAudioInput() = '+error, true);    
    
  for (i = 0; i < devices.length; i++) {
  	if (devices[i].toLowerCase() != 'default') {
		  var device = document.createElement( 'option' );
		  PrintToLogfile('VIDIVIC-LOG: function call: manager.NameForAudioInput()');		
		  deviceName = manager.NameForAudioInput(devices[i]);
		  PrintToLogfile('VIDIVIC-LOG: function result: manager.NameForAudioInput() = '+deviceName);
      nameLength = deviceName.length;
      if(nameLength > 55)
        deviceName = deviceName.substring(0, 42)+'...';
		  device.value = devices[i];
		  device.selected = devices[i] == selectedDevice;								
		  device.innerHTML = ' ' + deviceName;						
		  _combo.appendChild( device );
		}  
	}		
		
	return selectedDevice;  				
}

function UpdateDefaultAudioProfile( combobox )
{
	var _combo = myGetElementById(combobox);
	if (!_combo) {
		return;
	}			
	
	var manager = GetManager();	
	if (!manager) {
	  return null;
	}				
  
  profile_id = _combo.value;              
  	
  try
  {
    PrintToLogfile('VIDIVIC-LOG: function call: manager.SetDefaultAudioProfile('+profile_id+')');
    error = manager.SetDefaultAudioProfile( profile_id );          
    PrintToLogfile('VIDIVIC-LOG: function result: manager.SetDefaultAudioProfile() = '+error, true);
    
    if (error != ISDKERROR_NONE) {
    	alert( showErrorMsg( error ) );
    }  		
  }
  catch(err) {
  	alert( showErrorMsg(err) );
    //alert('Error thrown : '+ err); 
  }
}

function UpdateDefaultAudioInputDevice( combobox )
{			
	var _combo = myGetElementById(combobox);
	if (!_combo) {
		return;
	}			
	
	var manager = GetManager();	
	if (!manager) {
		return null;
	}			
	
	
	device_id = _combo.value;			
	
	try
	{
	  PrintToLogfile('VIDIVIC-LOG: function call: manager.SetCurrentAudioInput('+device_id+')');
  	error = manager.SetCurrentAudioInput( device_id );	      	
    PrintToLogfile('VIDIVIC-LOG: function result: manager.SetCurrentAudioInput() = '+error, true);
  
  	if (error != ISDKERROR_NONE) {
  	  alert( showErrorMsg( error ) );
  	}	
  }
  catch(err) {
  	alert( showErrorMsg(err) );    
  }
}

function UpdateDefaultAudioOutputDevice( combobox )
{								
	var _combo = myGetElementById(combobox);
	if (!_combo) {
		return;
	}				
	
	var manager = GetManager();	
	if (!manager) {
		return null;
	}
	
  //device_id = ItemIndex(_combo);	    
  device_id = _combo.value;
	
	try
	{
	  PrintToLogfile('VIDIVIC-LOG: function call: manager.SetCurrentAudioOutput('+device_id+')');
  	error = manager.SetCurrentAudioOutput( device_id );				
  	PrintToLogfile('VIDIVIC-LOG: function result: manager.SetCurrentAudioOutput() = '+error, true);
  	
  	if (error != ISDKERROR_NONE) {
  		alert( showErrorMsg( error ) );
  	}					
  }
  catch(err) {
  	alert( showErrorMsg(err) );
    //alert('Error thrown : '+err); 
  }
}

function MuteAudioOutputVolume( checked )
{
	var _checked = myGetElementById( checked );
	if (!_checked) {
		return;
	}
	
	var manager = GetManager();
	if (!manager) {
		return null;
	}
	
	try
	{
	  PrintToLogfile('VIDIVIC-LOG: function call: manager.MuteCurrentAudioOutput ('+_checked.checked+')');
	  error = manager.MuteCurrentAudioOutput ( _checked.checked );
	  PrintToLogfile('VIDIVIC-LOG: function result: manager.MuteCurrentAudioOutput () = '+error, true);
	  
    if (error != ISDKERROR_NONE) {
    	alert( showErrorMsg( error ) );
    }			
	}
	catch(err) {
		alert( showErrorMsg(err) );
	  //alert('Error thrown: '+err);
  }
}

/*
function MuteAudioWaveOutputVolume( checked )
{
	var  _checked = myGetElementById( checked );
	if (!_checked) {
		return;
	}
	
	var manager = GetManager();
	if (!manager) {
		return null;
	}
	
	try
	{
	  PrintToLogfile('VIDIVIC-LOG: function call: manager.MuteCurrentWaveAudioOutput('+_checked.checked+')');
	  error = manager.MuteCurrentWaveAudioOutput( _checked.checked );
	  PrintToLogfile('VIDIVIC-LOG: function result: manager.MuteCurrentWaveAudioOutput() = '+error, true);
	  
    if (error != ISDKERROR_NONE) {
    	alert( showErrorMsg( error ) );
    }			
	}
	catch(err) {
		alert( showErrorMsg(err) );
	  //alert('Error thrown: '+err);
  }		
}
*/

function MuteAudioInputVolume( checked )
{
	var _checked = myGetElementById( checked );
	if (!_checked) {
		return;
	}
	
	var manager = GetManager();
	if (!manager) {
		return null;
	}
	
	try
	{
	  PrintToLogfile('VIDIVIC-LOG: function call: manager.MuteCurrentAudioInput('+_checked.checked+')');
	  error = manager.MuteCurrentAudioInput( _checked.checked );
	  PrintToLogfile('VIDIVIC-LOG: function result: manager.MuteCurrentAudioInput() = '+error, true);
	  
    if (error != ISDKERROR_NONE) {
    	alert( showErrorMsg( error ) );
    }			
	}
	catch(err) {
		alert( showErrorMsg(err) );
	  //alert('Error thrown: '+err);
  }			
}

function UpdateAEC( checked )
{
	var _checked = myGetElementById( checked );
	if (!_checked) {
		return;
	}
	
	var manager = GetManager();
	if (!manager) {
		return null;
	}
	
	try
	{
	  PrintToLogfile('VIDIVIC-LOG: function call: manager.SetAECEnabled('+_checked.checked+')');
  	error = manager.SetAECEnabled( _checked.checked );
  	PrintToLogfile('VIDIVIC-LOG: function result: manager.SetAECEnabled() = '+error, true);
  	
  	if (error != ISDKERROR_NONE) {
  		alert( showErrorMsg( error ) );
  	}
  }
  catch(err) {
  	alert( showErrorMsg(err) );
    //alert('Error thrown: '+err); 
  }
}

function CheckAEC( checked )
{		
	manager = GetManager();
	if (!manager) {
		return;
	}			
	_checkbox = myGetElementById(checked);
	if (!_checkbox) {
		return;
	}
	
	PrintToLogfile('VIDIVIC-LOG: function call: manager.IsAECEnabled()');
	_checkbox.checked = manager.IsAECEnabled();
	PrintToLogfile('VIDIVIC-LOG: function result: manager.IsAECEnabled() = '+_checkbox.checked);
}

function CheckCurrentAudioInputMuted( checked )
{
  manager = GetManager();
  if (!manager) {
  	return;
  }
  
  _checkbox = myGetElementById(checked);
  if (!_checkbox) {  	     
  	return;
  }
  
  PrintToLogfile('VIDIVIC-LOG: function call: manager.IsCurrentAudioInputMuted()');
  _checkbox.checked = manager.IsCurrentAudioInputMuted();  		
  PrintToLogfile('VIDIVIC-LOG: function result: manager.IsCurrentAudioInputMuted() = '+_checkbox.checked);
}  	

/*
function CheckCurrentMasterAudioOutputMuted( checked )
{
	manager = GetManager();
	if (!manager) {
		return;
	}
	
	_checkbox = myGetElementById(checked);
  if (!_checkbox) {
	  return;
  }
  
  PrintToLogfile('VIDIVIC-LOG: function call: manager.IsCurrentMasterAudioOutputMuted()');
  _checkbox.checked = manager.IsCurrentMasterAudioOutputMuted();
  PrintToLogfile('VIDIVIC-LOG: function result: manager.IsCurrentMasterAudioOutputMuted() = '+_checkbox.checked);
}
*/
function CheckCurrentAudioOutputMuted( checked )
{
	manager = GetManager();
	if (!manager) {
		return;
	}
	
	_checkbox = myGetElementById(checked);
  if (!_checkbox) {
	  return;
  }
  
  PrintToLogfile('VIDIVIC-LOG: function call: manager.IsCurrentAudioOutputMuted()');
  _checkbox.checked = manager.IsCurrentAudioOutputMuted();
  PrintToLogfile('VIDIVIC-LOG: function result: manager.IsCurrentAudioOutputMuted() = '+_checkbox.checked);
}

function CheckCurrentWaveAudioOutputMuted( checked )
{
	manager = GetManager();
	if (!manager) {
		return;
	}
	
	_checkbox = myGetElementById(checked);
	if (!_checkbox) {
		return;
	}
	
	PrintToLogfile('VIDIVIC-LOG: function call: manager.IsCurrentWaveAudioOutputMuted()');
  _checkbox.checked = manager.IsCurrentWaveAudioOutputMuted();
  PrintToLogfile('VIDIVIC-LOG: function result: manager.IsCurrentWaveAudioOutputMuted() = '+_checkbox.checked);
}

/****************/
/* Progress bar */
/****************/
//http://www.wingo.com/dhtml/ProgressBar.html
isdkProgressBar = function ( parent, width, fontSize, barClass, backgroundColor )
{
  // constructor for Progress Bar object; 'width' and 'fontSize' in pixels
  this.pixels = width;
  this.outerDIV = document.createElement ( "div" );
  this.outerDIV.style.border = "1px solid #000000";
  this.outerDIV.style.background = "#FFFFFF";
  this.outerDIV.style.fontFamily = "Arial,Verdana";
  this.outerDIV.style.fontSize = fontSize + "px";
  this.outerDIV.style.width = ( width + 2 ) + "px";
  this.outerDIV.style.textAlign = "left";
  parent.appendChild ( this.outerDIV );

  this.fillDIV = document.createElement ( "div" );
  this.fillDIV.style.textAlign = "right";
  this.fillDIV.style.overflow = "hidden";
  this.fillDIV.innerHTML = "x";
  this.fillDIV.style.width = "0px";
  if ( barClass )
    this.fillDIV.className = barClass;
  else
  {
    this.fillDIV.style.background = "#00008b";
    this.fillDIV.style.border = "1px solid #FFFFFF";
    this.fillDIV.style.color = "#FFFFFF";
  }
  this.outerDIV.appendChild(this.fillDIV);
}

isdkProgressBar.prototype.setPercent = function ( pct )
{
  // expects 'pct' values between 0.0 and 1.0
  var fillPixels;
  if ( pct < 1.0 )
    fillPixels = Math.round ( this.pixels * pct );
  else
  {
    // avoid round off error
    pct = 1.0;
    fillPixels = this.pixels;
  }
  this.fillDIV.innerHTML = Math.round ( 100 * pct ) + "%";
  this.fillDIV.style.width = fillPixels + "px";
}

function PlayTestSound(start, stop)
{
 	manager = GetManager();          
	if (!manager) {		
	  return;		
 	}			       	 	
 	
	var startbutton = myGetElementById(start);
	startbutton.disabled = true;
	var stopbutton = myGetElementById(stop);
	stopbutton.disabled = false; 	 	 	  	        			        	        
  
  PrintToLogfile('VIDIVIC-LOG: function call: manager.Path('+ISDKPATH_APPLICATION+')');  
  path = manager.Path( ISDKPATH_APPLICATION ) + '\\data\\media\\default\\sounds\\test.wav';		      		      		        		      		      		      		          
  PrintToLogfile('VIDIVIC-LOG: function result: manager.Path() = '+path);
  
  PrintToLogfile('VIDIVIC-LOG: function call: manager.PlaySoundWithCurrentAudioOutput('+path+', true)');  
  var error = manager.PlaySoundWithCurrentAudioOutput(path, true);
  PrintToLogfile('VIDIVIC-LOG: function result: manager.PlaySoundWithCurrentAudioOutput() = '+error, true);
  
  if (error != ISDKERROR_NONE) {  	   
    alert( showErrorMsg( error ) );
  }  	
}

function StopTestSound(start, stop)
{
	manager = GetManager();
	if (!manager) {
		return;
	}	
	
	var startbutton = myGetElementById(start);
	if (startbutton) {
	  startbutton.disabled = false;
	}	  
	var stopbutton = myGetElementById(stop);
	if (stopbutton) {
	  stopbutton.disabled = true;
	}  
	
	PrintToLogfile('VIDIVIC-LOG: function call: manager.StopSoundWithCurrentAudioOutput()');  
	var error = manager.StopSoundWithCurrentAudioOutput();
	PrintToLogfile('VIDIVIC-LOG: function result: manager.StopSoundWithCurrentAudioOutput() = '+error, true);
	
	if (error != ISDKERROR_NONE) {
		alert( showErrorMsg( error ) );
	}	
}