if (typeof encodeURIComponent == "undefined") {
    encodeURIComponent = function(URIComponentString) {
        var escapedString = "";
        if (typeof URIComponentString == "string") {
            escapedString = escape(URIComponentString);
        }
        return escapedString;
    }
}

// Return the available content width space in browser window
function getInsideWindowWidth() {
    var windowWidth = 0;
    if (typeof(window.innerWidth) == "number") {
        windowWidth = window.innerWidth;
    } else {
        if (document.documentElement && document.documentElement.clientWidth) {
            windowWidth = document.documentElement.clientWidth;
        } else {
            if (document.body && document.body.clientWidth) {
                windowWidth = document.body.clientWidth;
            }
        }
    }
    return windowWidth;
}

// Return the available content height space in browser window
function getInsideWindowHeight() {
    var windowHeight = 0;
    if (typeof(window.innerHeight) == "number") {
        windowHeight = window.innerHeight;
    } else {
        if (document.documentElement && document.documentElement.clientHeight) {
            windowHeight = document.documentElement.clientHeight;
        } else {
            if (document.body && document.body.clientHeight) {
                windowHeight = document.body.clientHeight;
            }
        }
    }
    return windowHeight;
}

/* Set height of an iframe in dependence of the height of the browser window */
function setIframe(id, percentage) {
    if (document.getElementById) {
        var windowHeight = getInsideWindowHeight();
        if (windowHeight > 0) {
            var iframeElement = document.getElementById(id);
            var iframeHeight = windowHeight / 100 * percentage;
            iframeElement.style.height = iframeHeight + "px";
        }
    }
}

/* Switch actual stylesheet to print and trigger print dialog if supported */
function setupPrint() {
    // hide whole body to avoid flickering while disabling and enabling the stylesheets
    document.body.style.display = "none";
    if (document.getElementsByTagName) {
        var elem;
        for(var i = 0; (elem = document.getElementsByTagName("link")[i]); i++) {
            if (elem.getAttribute("rel").indexOf("style") != -1) {
                elem.disabled = true;
                // if link is an alternate stylesheet and has both screen and print media type
                if (elem.getAttribute("rel").indexOf("alt") != -1 && elem.getAttribute("media").indexOf("screen, print") != -1) {
                    // enable stylesheet
                    elem.disabled = false;
                }
            }
        }
    }
    // show body again
    document.body.style.display = "block";
    if (window.print) {
        window.setTimeout("window.print()", 1000);
    }
}

/* Open new popup window */
function openAndReturnPopup(href, window_name, width, height, is_resizable, show_scrollbars, show_menubar, show_statusbar, centered, show_toolbars) {
    if (!window_name || window_name == "") window_name = "popup";
    window_name = window_name.replace(/ /g, "_"); // ... window_name must not contain spaces
    var features = '';
    if (is_resizable) {
        features += ',resizable=yes'
    } else {
        features += ',resizable=no'
    }
    if (show_scrollbars) {
        width = parseInt(width) + 16; // ... the vertical scrollbar does need some place for itself
        features += ',scrollbars=yes'
    } else {
        features += ',scrollbars=no'
    }
    if (show_menubar) {
        features += ',menubar=yes'
    } else {
        features += ',menubar=no'
    }
    if (show_statusbar) {
        features += ',status=yes'
    } else {
        features += ',status=no'
    }
    if (centered) {
        var x = (window.screen.availWidth - width) / 2;
        var y = (window.screen.availHeight - height) / 2;
	    features += ",left=" + x + ",top=" + y;
    }
    if (show_toolbars) {
        features += ',toolbar=yes';
    } else {
        features += ',toolbar=no';
    }
    features = 'width=' + width + ',height=' + height + features + ',dependent=yes,location=no,directories=no';
    var popup = window.open(href, window_name, features);
    popup.focus();
    return popup;
}

function openPopup(href, window_name, width, height, is_resizable, show_scrollbars, show_menubar, show_statusbar, centered, show_toolbars) {
    openAndReturnPopup(href, window_name, width, height, is_resizable, show_scrollbars, show_menubar, show_statusbar, centered, show_toolbars);
}

function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else
		begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
		end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}

// moock fpi [f.lash p.layer i.nspector]
// version: 1.3.6
// written by colin moock
// code maintained at: http://www.moock.org/webdesign/flash/detection/moockfpi/
// terms of use posted at: http://www.moock.org/terms/



// =============================================================================
// These are the user defined globals.
// Modify the following variables to customize the inspection behaviour.

var requiredVersion = 6;   // Version the user needs to view site (max 9, min 2)

// =============================================================================

// System globals
var flash2Installed = false;    // boolean. true if flash 2 is installed
var flash3Installed = false;    // boolean. true if flash 3 is installed
var flash4Installed = false;    // boolean. true if flash 4 is installed
var flash5Installed = false;    // boolean. true if flash 5 is installed
var flash6Installed = false;    // boolean. true if flash 6 is installed
var flash7Installed = false;    // boolean. true if flash 7 is installed
var flash8Installed = false;    // boolean. true if flash 8 is installed
var flash9Installed = false;    // boolean. true if flash 9 is installed
var maxVersion = 9;             // highest version we can actually detect
var actualVersion = 0;          // version the user really has
var hasRightVersion = false;    // boolean. true if it's safe to embed the flash movie in the page
var jsVersion = 1.0;

// Check the browser...we're looking for ie/win, but not aol
var isAOL = (navigator.appVersion.indexOf("AOL") != -1) ? true : false;
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;    // true if we're on ie
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false; // true if we're on windows

// This is a js1.1 code block, so make note that js1.1 is supported.
jsVersion = 1.1;

// Write vbscript detection on ie win. IE on Windows doesn't support regular
// JavaScript plugins array detection.
if(isIE && isWin && !isAOL){
  document.write('<scr' + 'ipt type="text/vbscript"\>\n');
  document.write('on error resume next \n');
  document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
  document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
  document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
  document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');  
  document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');  
  document.write('flash7Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7"))) \n');
  document.write('flash8Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8"))) \n');
  document.write('flash9Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.9"))) \n');
  document.write('<\/scr' + 'ipt\>\n'); // break up end tag so it doesn't end our script
}
// Next comes the standard javascript detection that uses the 
// navigator.plugins array. We pack the detector into a function so that 
// it preloads before being run.

function detectFlash() {  
  // If navigator.plugins exists...
  if (navigator.plugins) {
    // ...then check for flash 2 or flash 3+.
    if (navigator.plugins["Shockwave Flash 2.0"]
        || navigator.plugins["Shockwave Flash"]) {

      // Some version of Flash was found. Time to figure out which.
      
      // Set convenient references to flash 2 and the plugin description.
      var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;

      // DEBUGGING: uncomment next line to see the actual description.
      // alert("Flash plugin description: " + flashDescription);
      
      // A flash plugin-description looks like this: Shockwave Flash 4.0 r5
      // We can get the major version by grabbing the character before the period
      // note that we don't bother with minor version detection. 
      // Do that in your movie with $version or getVersion().
      var flashVersion = parseInt(flashDescription.substring(16));

      // We found the version, now set appropriate version flags. Make sure
      // to use >= on the highest version so we don't prevent future version
      // users from entering the site.
      flash2Installed = flashVersion == 2;    
      flash3Installed = flashVersion == 3;
      flash4Installed = flashVersion == 4;
      flash5Installed = flashVersion == 5;
      flash6Installed = flashVersion == 6;
      flash7Installed = flashVersion == 7;
      flash8Installed = flashVersion == 8;
      flash9Installed = flashVersion >= 9;
    }
  }
  
  // Loop through all versions we're checking, and
  // set actualVersion to highest detected version.
  for (var i = 2; i <= maxVersion; i++) {  
    if (eval("flash" + i + "Installed") == true) actualVersion = i;
  }
  
  // If we're on msntv (formerly webtv), the version supported is 4 (as of
  // January 1, 2004). Note that we don't bother sniffing varieties
  // of msntv. You could if you were sadistic...
  if(navigator.userAgent.indexOf("WebTV") != -1) actualVersion = 4;  
  
  // DEBUGGING: uncomment next line to display flash version
  // alert("version detected: " + actualVersion);


  // We're finished getting the version on all browsers that support detection.
  // Time to take the appropriate action.

  // If the user has a new enough version...
  if (actualVersion >= requiredVersion) {
    hasRightVersion = true;                
  }
}

detectFlash();  // call our detector now that it's safely loaded.


// In this section we set up the content to be placed dynamically on the page.

function printFlash(flash, noFlashContent, width, height) {
    var xhtml = "";
    if (hasRightVersion && width > 0 && height > 0) {
	// if we've detected an acceptable version
        xhtml += noFlashContent;
        var sos = new SWFObject(flash, "contentVisual", width, height, requiredVersion, "#fff");
        sos.write("contentVisual");
    } else if (noFlashContent != "null") {  
	// flash is too old or we can't detect the plugin
        xhtml += '<img src="' + noFlashContent + '" alt="" width="' + width + '" height="' + height + '" />';
    }
    document.write(xhtml);  // embed the flash movie respectively the alternate content
}

function focusNextFormElem(formElem) {
    var nextFormElem = null;
    if (formElem && formElem.form) {
        var formElems = formElem.form.elements;
        for (var i = 0; i < formElems.length; i++) {
            if (formElem == formElems[i]) {
                nextFormElem = formElems[i+1];
                break;
            }
        }
    }
    if (nextFormElem && nextFormElem.focus) {
        nextFormElem.focus();
    }
}

/* neu */
function getElementStyle(elem, IEStyleProp, CSSStyleProp) {
    if (elem.currentStyle) {
        return elem.currentStyle[IEStyleProp];
    } else if (window.getComputedStyle) {
        var compStyle = window.getComputedStyle(elem, "");
        return compStyle.getPropertyValue(CSSStyleProp);
    }
    return "";
}

function arrangeList() {
    var agent = navigator.userAgent.toLowerCase();
    var isIE = agent.indexOf("msie") != -1 && agent.indexOf("opera") == -1;
    var isOpera = agent.indexOf("opera") != -1;
    if ((isIE || isOpera)) {
		var contentBox = getElementsByClassName("magContentBoxWrap");
		if (contentBox.length > 0) {
			var container = contentBox[0];
			var ulChildNodes = container.getElementsByTagName("ul");
			var olChildNodes = container.getElementsByTagName("ol");
			var divChildNodes = container.getElementsByTagName("div");
			if (divChildNodes.length > 0) {
				if (!divChildNodes[0].className) {
					var imgChildNodes = divChildNodes[0].getElementsByTagName("img");
					// If there is an image, the first one is the left floated image...
					if (imgChildNodes.length > 0) {
						var img = imgChildNodes[imgChildNodes.length-1];
						var marginBottom = parseInt(getElementStyle(img, "marginBottom", "margin-bottom"));
						marginBottom = isNaN(marginBottom) ? 9 : marginBottom;
						var marginRight = parseInt(getElementStyle(img, "marginRight", "margin-right"));
						marginRight = isNaN(marginRight) ? 9 : marginRight;
						var imgBottom = img.offsetTop + img.offsetHeight + marginBottom; // top + height + margin-bottom
						var liMarginLeft = img.offsetWidth + marginRight; // width + margin-right
						
						for (var i = 0; i < olChildNodes.length; i++) {
							var olNode = olChildNodes[i];
							olNode.style.width = "auto";
							var liArray = olNode.getElementsByTagName("li");
							
							for (var j = 0; j < liArray.length; j++) {
								// If top of li is above the image bottom
								var liNode = liArray[j];
								if ((liNode.offsetTop - imgBottom) <= 0) {
									liNode.style.marginLeft = liMarginLeft + 10 + "px";
								} // end if ((liNode.offsetTop - imgBottom) <= 0)
							} // end for (var j = 0; j < liArray.length; j++)
						} // end for (var i = 0; i < olChildNodes.length; i++)

					    for (var i = 0; i < ulChildNodes.length; i++) {
							var ulNode = ulChildNodes[i];
							ulNode.style.width = "auto";
							var liArray = ulNode.getElementsByTagName("li");
							
							for (var j = 0; j < liArray.length; j++) {
								// If top of li is above the image bottom
								var liNode = liArray[j];
								if ((liNode.offsetTop - imgBottom) <= 0) {
									liNode.style.marginLeft = liMarginLeft + "px";
								} // end if ((liNode.offsetTop - imgBottom) <= 0)
							} // end for (var j = 0; j < liArray.length; j++)
						} // end for (var i = 0; i < ulChildNodes.length; i++)

					} // end if (imgChildNodes.length > 0)
				} // end if (imgChildNodes.length > 0)
			} // end if (divChildNodes.length > 0)
        } // end if (contentBox.length > 0)
    } // end if ((isIE || isOpera))
} // end function arrangeList()

function getElementsByClassName(class_name) {
    var agent = navigator.userAgent.toLowerCase();
	var isIE = agent.indexOf("msie") != -1 && agent.indexOf("opera") == -1 && document.all;
	var ret_obj = new Array(), j=0, attr;
	if (document.getElementsByTagName) {
		var divNodes = document.getElementsByTagName("div");
		for (i=0; i < divNodes.length; i++) {
			var tempobj = divNodes[i];
			if (isIE) {
				attr = 'className';
			} else {
				attr = 'class';
			}
			//if(all_obj[i].className==class_name) {
			if(divNodes[i].getAttribute(attr) == class_name) {
			  ret_obj[j]=divNodes[i];
			  j++;
			}
		}
	}
	return ret_obj;
}

// MS, 24.01.2005
function displayIFrame (url) {
	// catch all iframe elements on the page
	var objFrames = document.getElementsByTagName('iframe');
	// if there were iframes
	if (objFrames.length > 0 ) {
		// open url in first iframe
		objFrames[0].src = url
	} else {
		// open url in new window
		window.open(url);
	}
}

// MS, 04.03.2005
function switchButton (formElem, elem1, elem2) {
    var agent = navigator.userAgent.toLowerCase();
	var isIE = agent.indexOf("msie") != -1 && agent.indexOf("opera") == -1 && document.all;
	if (isIE) {
		if (formElem.checked && elem1 && elem2) {
			elem1.style.display = "block";
			elem2.style.display = "none";
		} else {
			elem1.style.display = "none";
			elem2.style.display = "block";
		}
	} else { /* reason for that extra work: Opera 5+6 */
		if (formElem.checked && elem1 && elem2) {
			elem2.setAttribute('class','nmdb-button-submit');
			elem2.setAttribute('type','submit');
		} else {
			elem2.setAttribute('class','nmdb-button-submit-inactive');
			elem2.setAttribute('type','button');
		}
	}
}


window.onload = arrangeList;

