// ========================================================================================
// GENERAL FUNCTION
// ========================================================================================

// Get the homepage
var homepage = GetHomePage();

// ============= GetHomePage =============
function GetHomePage()
// Function to calculate the url of the homepage
{
  // Build url to homepage, depends on environment
  var localhomepage = "";
  var currentlocation = location.href;

  // Check environment
  if (currentlocation.indexOf("localhost") > 0) {
		    // When testing on localhost
		    localhomepage = "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);
		    localhomepage = theroot + "/DesktopDefault.aspx?tabid=1&index=0.0.0";
  }

  // Return homepage
  return localhomepage;
}

// ============= setRightPaneWidth =============
function setRightPaneWidth() {
		    // Get the content of the righpane
            _rightpane = '';
	        try { _rightpane = document.getElementById('RightPane').innerHTML; } catch(e) {}
	        // set the image width when length content in leftpane
	        if (_rightpane.length > 0) {
	          // Retrieve the image
		      img = document.all["RightPaneImage"];
		      // Set image width
		      img.width="180";
	        }		    		  
}

/*
// ============= relocateAndResize =============
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 = "";
}
*/

// ============= MenuSubNavigation_Goto =============
function MenuSubNavigation_Goto( theurl, thetarget){
  //alert('test:' + theurl + '|target:' + thetarget);
  if(thetarget == '_blanc'){
    OpenNewWindow(theurl);
  } else {
    document.location = theurl;
  }
}
		  

// ============= OpenNewWindow =============
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+"");
}

// ============= InitializeCommandsToBeExecutedAfterRendering =============
function InitializeCommandsToBeExecutedAfterRendering()
// Function which should be called before adding commands to the list
{
  var CTBEAR = new Array();
}

// ============= ExecuteCommandsToBeExecutedAfterRendering =============
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]);
      }
    }
  }
}

// ============= SwitchToLanguage =============
function SwitchToLanguage(culture)
{
	// Get the current url
	url = document.location.href;
	
	// Check if there are allready url paramters in the querystring
	if (url.indexOf('?') > 0)
	{
		// Check if their is allready a culture parameter in the url
		pos = url.indexOf('culture=')
		if (pos > 0)
		{
			//replace the culture with the new
			part1 = url.substr(0,pos+8);
			part2 = culture;
			part3 = (url.length > pos+13) ? url.substr(pos+13) : '';				                
			url = part1 + part2 + part3;
			
		} else {
			// add the culture
			url += '&culture=' + culture;
		}
		
	} else  {
		// Add the culture
		url = 'DesktopDefault.aspx?culture=' + culture;
	}

	// Filter # sign, gives problems with redirect
	url = url.replace('#','');

    // Redirect
	document.location.href = url;
}

// ========================================================================================
// 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');
    }    
  }
}
