/**
* createAjaxRequestObject
* 
* Create a ajax request object
*/
function createAjaxRequestObject() {
  try { // Opera 8.0+, Firefox, Safari
    return new XMLHttpRequest();
  } catch(e) {
    try { // Internet Explorer 
      return new ActiveXObject( "Msxml2.XMLHTTP" );
    } catch(e) {
      try { // Other Internet explorer browsers
        return new ActiveXObject( "Microsoft.XMLHTTP" );
      } catch(e) { // Something went bad
        alert( "Could not create an ajax request object" );
      }
    }
  }
}

/**
* changeMenu
*
* Change a menu to a target div
*/
function changeMenu(url, target) { 
  var ajaxRequest = createAjaxRequestObject();
  
  if( ajaxRequest == null)
    return;
  
  // Define what to do with the response
  ajaxRequest.onreadystatechange = function() {
    if( ajaxRequest.readyState == 4 ) { // Request complete
      var display = document.getElementById( target );          
      display.innerHTML = ajaxRequest.responseText;
    }
  }
  
  ajaxRequest.open("Get", url, true);
  ajaxRequest.send(null);
}

/**
* CSS-loader
*
* Load a css file dynamically
*/
function loadCSS( file ) {
  var links = document.getElementsByTagName('link');
  
  /* Check whether the CSS file is already loaded */
  for( var i=0; i<links.length; i++ )
    if( links.item(i).href == file )
      return;
      
  var link  = document.createElement('link');
  link.href = file;
  link.rel  = 'stylesheet'; 
  link.type = 'text/css';
  document.getElementsByTagName('head')[0].appendChild(link); 
}
