// ========================================================================================
// GENERAL FUNCTION
// ========================================================================================


function GetHomePage()
// Function to calculate the url of the homepage
{
  // Build url to homepage, depends on environment
  var homepage = "";
  var currentlocation = location.href;

  // Check environment
  if (currentlocation.indexOf("localhost") > 0) {
		    // When testing on localhost
		    homepage = "http://localhost/PortalFX/DesktopDefault.aspx?tabid=1&index=0.0.0"
  } else {
		    var theindex = location.href.indexOf("/",8);
		    var theroot = location.href.slice(0,theindex);
		    homepage = theroot + "/DesktopDefault.aspx?tabid=1&index=0.0.0";
  }

  // Return homepage
  return homepage;
}
/*
function relocateAndResize() {
  // Set contentpane height by image name
  img = document.all["ContentPaneHeight"];
  img.height = document.body.scrollHeight-25-180;
  // Search FOOTERLAYER
  footer = document.all["FOOTERLAYER"];
  // Relocate the FOOTERLAYER to bottom of screen
  footer.style.top = document.body.scrollHeight-25;
  // Show FOOTERLAYER
  footer.style.display = "";
}
*/

function MenuSubNavigation_Goto( theurl, thetarget){
  //alert('test:' + theurl + '|target:' + thetarget);
  if(thetarget == '_blanc'){
    OpenNewWindow(theurl);
  } else {
    document.location = theurl;
  }
}
		  

function OpenNewWindow(url){
  // Set default window with and height
  var width = 640;
  var height = 480
  // Get a part of the current window size for the new window;
  if (document.layers) {
    width = window.outerWidth/4*3;
    height=winwdow.outerHeight/4*3;
  } else if (document.all) {
    width = document.body.clientWidth/4*3;
    height = document.body.clientHeight/4*3;
  }
  // open the window
  targetwindow = window.open(url,"","toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width="+width+",height="+height+"");
}

function InitializeCommandsToBeExecutedAfterRendering()
// Function which should be called before adding commands to the list
{
  var CTBEAR = new Array();
}

function ExecuteCommandsToBeExecutedAfterRendering()
// Function which should be called after the last table is closed. (just before </body>)
{
  // Check if their is a command to be executed
  if (CTBEAR) {
    if (CTBEAR.length > 0) {
      // Loop through all the commands
      for (var i = 0; i< CTBEAR.length; i++) {
        // Execute the commands
        eval(CTBEAR[i]);
      }
    }
  }
}

// ========================================================================================
// SCRIPTS FOR UPLOADEDDOCUMENTSMODULE
// ========================================================================================

// Function for width calculation of the columns
function renderColumns(name) {
  // Get the image of which contains the width of the column
  img = document.getElementById('Col_' + name);
  // Get the a list of all the div's which has to be updated
  divarray = document.getElementById('div_' + name);
  // try to change div's (catch no row's!)
  if (divarray) {
    // Check if array (More then one row)
    if (eval('div_' + name + '.length')) {
      if (eval('div_' + name + '.length') > 0) {     
        if (eval('div_' + name + '.length') == 1) {     
          // Change the width of the div
          divarray.style.width = img.width; // Not an array
        } else {
          // Loop through all the div's
          for (var i=0;i<eval('div_' + name + '.length');i++){
            // Change the width of the div
            eval('div_' + name + '[' + i + '].style.width = img.width');
          }
        }
      }
    } else {
      // if no array, only one row exists
      eval('div_' + name + '.style.width = img.width');
    }    
  }
}
