// Global vars
var menu_image_location = "/NewRe/Resources/Images/Menu/"; 
var icons_image_location = "/NewRe/Resources/Images/Icons/"; 
var selectedMenuImage = false;
var oldPosY;


// General image high-light function
function imageOn(_current_name, _img_location, _dontUseLanguage)
{
	try
	{
		document.images[_current_name].src = 
			_img_location + _current_name + (_dontUseLanguage ? "" : "_" + currentlanguage) + "_hi.gif";
	}
	catch(e) {}
}

function imageOff(_current_name, _img_location, _dontUseLanguage)
{
	try
	{
		document.images[_current_name].src = 
			_img_location + _current_name + (_dontUseLanguage ? "" : "_" + currentlanguage) + ".gif";
	}
	catch(e) {}
}

// Menu high-lighting
function menuOn  (_current_name) { imageOn (_current_name, menu_image_location); }
function menuOff (_current_name)
{
	if (_current_name==selectedMenuImage) return;
	imageOff(_current_name, menu_image_location);
}

// Icon high-lighting
function iconOn  (_current_name) { imageOn (_current_name, icons_image_location, true); }
function iconOff (_current_name) { imageOff(_current_name, icons_image_location, true); }



function printLink(_isActive,_id,_url,_target,_text, imageStyle)
{
  if (_url.indexOf("print=true")>-1)
  {
      var left = _url.substr(0, _url.indexOf("print=true")-1);
      if (left.indexOf("?") > -1)
        _url = _url.replace("?print=true", "&print=true");
  }

	var _locSearch = location.search.toLowerCase();
	var _editMode = ( _locSearch.indexOf("nrmode=unpublished")!=-1 || _locSearch.indexOf("nrmode=update")!=-1 );
	if (((_isActive=="true") || (_isActive=="")) && (! _editMode))
	{
		if(_text.indexOf("|")>-1)
			if (currentlanguage=="de")
				_text = (_text.split("|"))[0];
			else
				_text = (_text.split("|"))[1];

		with (document)
		{
			write("<a href=\"" + _url + "\"" + (_target ? (" target=" + _target) : "") + ">");
			write("<img name=\"" + _id + "\" title=\"" + _text + "\" border=0 ");
			if (typeof(imageStyle) != 'undefined')
			  write("style=\"" +imageStyle + "\" ");
			write("onMouseOver=\"iconOn(this.name)\" onMouseOut=\"iconOff(this.name)\" ");
			write("src=\""+ icons_image_location + _id + ".gif\" /></a>");
		}
	}
	else
	{
		if (currentlanguage == "de")
			_text = "Funktion nicht aktiv";
		else
			_text = "Function not active";
		with (document)
		{
			write("<img name=\"" + _id + "\" title=\"" + _text + "\" border=0 ");
			if (typeof(imageStyle) != 'undefined')
			  write("style=\"" +imageStyle + "\" ");
			write("src=\""+ icons_image_location + _id + "_na.gif\" /></a>");
		}
	}
}

function BookmarkPage()
{
	var _currentPageURL   = self.location;
	var _currentPageTitle = document.title;
	if (_currentPageURL=="" || _currentPageTitle=="")
	{
	  if (currentlanguage == 'en')
	    alert("Bookmark function temporarily not available.");
	  else
	    alert("Funktion vorübergehend nicht verfügbar.");
		return;
	}
	else
	{
		window.external.AddFavorite(_currentPageURL,_currentPageTitle);
	}
}

function HighlightChannel()
{
  var content = document.getElementById("highlightChannel").value;
  if (content == "")
    return;
  // try the main menu (posting)
  var mainMenu = document.getElementById("menu_main");
  var links = mainMenu.getElementsByTagName("a");
  if (!links)
    return;
  var length = links.length;
  for (var i = 0; i < length; i++)
  {
    if (links[i].title.toLowerCase().replace(/ /g, "") == content)
    {
      links[i].style.color = "white";
      return;
    }
  }
  
  // otherwise try the quicklings
  var quickLinks = document.getElementById("quick_links");
  if (!quickLinks)
    return;
  links = quickLinks.getElementsByTagName("a");
  if (!links)
    return;
  length = links.length;
  for (var i = 0; i < length; i++)
  {
    if (links[i].href.toLowerCase().indexOf(content.toLowerCase()) >= 0)
    {
      var image = links[i].getElementsByTagName("img")[0];
      if (image)
        image.src = image.src.replace(".gif", "_hi.gif");
      image.onmouseout = null;
      return;
    }
  }
}

/*
    LAYOUT CALCULATION
    
*/

function isEditing() {
  return (typeof(XCMSDocedit)!='undefined');
}

function calcContentTop() {
  var top = 85+28+36;  //header + navigation + breadcrumb
  return top;
}  

function calcLeft() {
  return (parseInt(contentbody.offsetWidth)-calcWidth())/2;
}

function calcWidth() {
  var width = parseInt(contentbody.offsetWidth);
  
  if(width>1050) 
    width=1050;
  if (location.href.indexOf("print=true") > -1)
    width = parseInt(contentbody.offsetWidth);
  if(width<640)
    width=640;
  return width;
}

function calcContentWidth() {
  var width = calcWidth();
  width -= 48; //left + right padding 24px
  return width;
}

function calcHeight() {
  var height = parseInt(contentbody.offsetHeight)-4;
  if(typeof(tgxMBbodyContent)!='undefined')
    height -= 58;  //tgx toolbar height
  if(height<480) 
    height=480;
  return height;
}

function calcContentHeight() {
  var height = calcHeight();
  height -= 85+28+28+20; //header + navigation + breadcrumb + margin-bottom
  return height;
}

function calcAddedValueHeight()
{
  var addition = 85+28+16;
  var added = document.getElementById("addedvalue");
  if (added == null)
    return addition;
  return parseInt(added.offsetHeight) + addition;
}

