function stopErrors(msg, file, line) 
{
    debug('<hr>');
    debug('Datei:&nbsp;'+file);
    debug('Zeile:&nbsp;'+line);
    debug(msg);
    debug('<hr>');
	return true;
}
// window.onerror = stopErrors;

// JS Debug Fenster:
var debug_win;
function debug(text) {
    if(location.href.indexOf('hq.spin.de') != -1) {
        if((typeof[debug_win] != 'undefined') || (debug_win.closed)) {
            debug_win = window.open('','debug','width=450,height=300,scrollbars=1,resizable=1');
            debug_win.document.write('<html><head><title>Debug</title><head><body></body><html>');
            debug_win.moveTo(0,0);
            // newwindow.push(debug_win);
        }
        
        if(text == '<hr>') {
            debug_win.document.body.innerHTML += '<hr noshade>';
        } 
        else {
            debug_win.document.body.innerHTML += text+'<br>';
        }
        debug_win.focus();
    }
}

var titleText = new Array();

// Document Ready:
$(document).ready(function() {
    
    if($("body#dyn_off").length == 0) {
        // Rollover Effekte:
        $("div[@class^='mo_'], a[@class^='mo_'], td[@class^='mo_']").not("[@class$='_hi']").each(function(i) {
            $(this).hover(function() {
                    // var new_name = this.className+'_hi';
                    var new_name = this.className.split(" ");
                    for(var i=0; i<new_name.length; i++) {
                        if(new_name[i].indexOf('mo_') == 0) {
                            new_name[i] = new_name[i]+'_hi';
                            break;
                        }
                    }
                    $(this).attr("class", new_name.join(" "));
                }, function() {
                    var new_name = this.className.replace(/\_hi/, "");
                    $(this).attr("class", new_name); 
            });
        });
    
        // Tooltips:    
        $("img.tooltip_icon").click(function(e) {
            if($("div.tooltip_txt", this.parentNode).is(":visible")) {
                $("div.tooltip_txt", this.parentNode).fadeOut("fast");
            }
            else {
                $("div.tooltip_txt", this.parentNode).fadeIn("fast");
            }
        });
        
        $("a.tooltip_close").click(function(e) {
            $(this).parents("div.tooltip_txt").fadeOut("fast");
        });
    }
    
    if($("body#dyn").length > 0) {
    
        // Akkordeon klickbar machen:
        $("div.acc_head").click(function(e) {
            var content = $("div.acc_content[@id='"+this.id+"_c']").get();
            if(content.length == 1) {
            if($(content[0]).is(":hidden")) {
                    // $("div.acc_content:visible", this.parentNode).slideUp(); 
                    // $("div.acc_head", this.parentNode).removeClass("acc_open");
                    $(content[0]).slideDown("fast");
                    $(this).addClass("acc_open");
                } else {
                    $(content[0]).slideUp();
                    $(this).removeClass("acc_open");
                }
            }
        });
        
        $("div.acc-header").click(function(e) {
            var content = $("div.acc-content#"+this.id+"_c").get();
            if(content.length == 1) {
            if($(content[0]).is(":hidden")) {
                    $(content[0]).slideDown("fast");
                    $(this).addClass("acc-open");
                } else {
                    $(content[0]).slideUp();
                    $(this).removeClass("acc-open");
                }
            }
        });
    
        // Rollover Effekt bei Tabellen:
        $("table.par_table").find("td").each(function(i) {
            $(this).hover(function() {
                $(this).addClass("thover");
            },
            function() {
                $(this).removeClass("thover");
            }    
            );
        });

        // Hover Fix bei IE:
        if($.browser.msie) {
            $(".ie-hover").hover(function() {
                $(this).addClass("ie-hi");
            }, function() {
                $(this).removeClass("ie-hi");
            });
        }
        
        $("div.sub-menter").bind("mouseenter", function(e) { 
            $(this).addClass("hi");
        });

        $("div.sub-mleave").bind("mouseleave", function(e) { 
            $(this).parents("div.sub-menter").removeClass("hi");
        });        
        
        // Tool Tip Icons:
        $("img.tticon").hover(
            function() {
                var h = parseInt($(this).height()); 
                var w = parseInt($(this).width());
                if((h > 0) && (w > 0)) {
                    if($(this).parents("div.inline_image_right").size() == 1) {
                        $("div.ttcontent", this.parentNode).css("right", "-"+($(this).parents("div.inline_image_right").width()-5)+"px");                    
                    }
                    else {
                        $("div.ttcontent", this.parentNode).css("left", "5px");
                    }
                    $("div.ttcontent", this.parentNode).fadeIn("fast");
                }
            },
            function() {
                $("div.ttcontent", this.parentNode).fadeOut("fast");
            }
        ).css("cursor","pointer");
        
        // Popup Icons klickbar machen:
        $("div[@class^='inline_image']").each(function(i) {
            var linktag = $("a", this).get();
            if(linktag.length>0) {
                $("img.ppicon", this).click($(linktag[0]).attr("onclick")).css("cursor","pointer");
            }
        });
        
        // Tab Menu klickbar machen:
        $("a[@id^='tm-']","div.tm-head").click( function() {
            this.blur();
            var id = $(this).attr("id").replace(/\-tab/, "");
            $("a[@id^='tm-']","div.tm-head").not(this).removeClass("sel");
            $(this).addClass("sel");
            $("div.tm-body","div.tab-menu").hide();
            $("div.tm-body#"+id,"div.tab-menu").show();
            setCookie('tab-menu', id);
        });

        $("div.tm-body:empty","div.tab-menu").html('<div class="broken">Noch kein Inhalt hinterlegt.</div>');

        $("div.par_date").html(currentDate());
        
        if($.browser.msie) {
            $("td:first-child,th:first-child","table.par_table").addClass("first-child");
        }
        
        $("div.item", "div.mainnav").hover(function() { 
            $("a", this).animate({top:0},100, function() { $(this).css("top",0) });
        }, function() { 
            $("a", this).animate({top:-8},100);
        }).click(function() { 
            $(this).unbind("hover");
        });
        
        $("a","div.ownerbox").each(function(i) {
            $(this).hover(function() {
                if(!$(this).attr("text")) {
                    var text = new Array();
                    text["idrucken"] = "Seite drucken";
                    text["irecherche"] = "Seite in die Recherchemappe legen";
                    text["ipdf"] = "Als PDF herunterladen";
                    $("div.idesc","div.ownerbox").html(text[$(this).attr("id")]);
                }
                else {
                    $("div.idesc","div.ownerbox").html($(this).attr("text"));
                }
            }, function() {
                $("div.idesc","div.ownerbox").html("");
            });
        });

        $("a","div#site-footer").each(function(i) {
            if($(this).attr("id") && $(this).attr("title")) {
                titleText[$(this).attr("id")] = $(this).attr("title");
                // $(this).attr("title", "");
                $(this).hover(function() {
                    if(titleText[$(this).attr("id")]) {
                        $("div#sf-title","div#site-footer").html(titleText[$(this).attr("id")]);
                    }
                }, function() {
                    $("div#sf-title","div#site-footer").html("");
                });
            }
        });
    
        $("div.rot_cont").each(function(i) { 
            var cID = 'c'+i;
            $(this).attr("id", cID);
            rotContent[cID] = true;
            
            $("img", this).each(function(i) { 
                var iID = 'i'+i;
                $(this).attr("id", iID);
            });
            curImage[cID] = "i0";
            
            $("td", this).each(function(i) { 
                var tID = 't'+i;
                $(this).attr("id", tID);

                if(i==0) {
                    $(this).addClass("hi");
                }
                
                $(this).hover(function() {
                    $(this).addClass("hi");
                    var cID = $(this).parents("div.rot_cont").attr("id");
                    rotContent[cID] = false;
                    var iID = 'i'+$(this).attr("id").replace(/t/,"");
                    $("img.gfx", "div.rot_cont[@id='"+cID+"']").hide();
                    $("img.gfx[@id='"+iID+"']", "div.rot_cont[@id='"+cID+"']").show();
                    curImage[cID] = iID;
                }, function() { 
                    $(this).removeClass("hi");
                    var cID = $(this).parents("div.rot_cont").attr("id");
                    rotContent[cID] = true;
                });
                
            });
            
        });
        
        $("div.tagcloud").each(function(i) { 
            var areaName = $(this).attr("id");
            if(areaName != "") {
                $(this).load("/ext/o2/search/tagcloud", { 
                    area:areaName,
                    limit:25,
                    max_fontsize:20
                });
            }
        });
        
        rotIv = window.setInterval("rotImage()", 2000);
        
        $(".closable").click(function() {
            if($(this).next(".cl-body").is(":visible")) {
                $(this).next(".cl-body").slideUp(function() {
                    $(this).prev(".closable").addClass("closed");
                });
            }
            else if(!$(this).hasClass("closed")) {
                $(this).addClass("closed");
            }
            else {
                $(this).removeClass("closed");
                $(this).next(".cl-body").slideDown(function() {
                    if($(this).parents(".cl-group").size() > 0) {
                        var myGroup = $(this).parents(".cl-group").get(0);
                        $(".cl-body", myGroup).not(this).slideUp(function() {
                            $(this).prev(".closable").addClass("closed");
                            $(".closable", this).not(".closed").addClass("closed").each(function() {
                                if($(this).next("div").is(":visible")) {
                                    $(this).next("div").hide();
                                }
                            });
                        });
                    }
                });
            }
        });
        
        // Such Text Hervorhebung:
        searchHighlight();
    }
});

// Popup:
var newwindow = new Array();

var myPageID=0;
function popup(pURL, x, y, options, num)
{
    if(typeof(num) == 'undefined') { 
        num = "popup"+Math.round(Math.random()*100000); 
    }
    else {
        num = "" +num + "";
    }
	if((typeof(options) != 'undefined') && (options != "")) { options = ","+options; }
	else { options = ",resizable=1,scrollbars=1"; }
	if((typeof(newwindow[num])!='undefined') && (!newwindow[num].closed)) { newwindow[num].focus(); }
	else newwindow[num]=window.open(pURL,"popupwin"+num,"width="+x+",height="+y+options);
    if(num.indexOf('itv') != -1) {
    	x2=screen.width;
    	y2=screen.height;
    	if (x2 < 900) {
    		newwindow[num].moveTo (0,0);
        }
    	else {
    		newwindow[num].moveTo (x2/2-(x/2),y2/2-(y/2)+20);
        }
    }
    else {
	    newwindow[num].moveTo(0,0);
    }
	return false;
}

function par_popup(pURL, x, y, options, num)
{
	if((typeof(options) != 'undefined') && (options != "")) { options = ","+options; }
	if((typeof(newwindow[num])!='undefined') && (!newwindow[num].closed)) { newwindow[num].focus(); }
	else newwindow[num]=window.open(pURL,"popupwin"+num,"width="+x+",height="+y+options);
	newwindow[num].moveTo(0,0);
	return false;
}

// Login Popup oeffnen:
function loginPopup() {
    return popup("/session/cookie/ext/o2/login/login?login_popup=1;login_url="+escape(location.pathname+location.search), "370", "215", ",scrolling=0,resize=0,status=1");
}

// Page Unload:
function unload() {
    // Alle Fenster wieder schliessen:
    for (var i in newwindow) {
        if(typeof(newwindow[i].closed) != 'undefined') {
            if( (i.indexOf('itv') == -1) &&
                (i.indexOf('sitemap') == -1) ) {
                if(!newwindow[i].closed) { newwindow[i].close(); }
            }
        }
    }
}

// Parameter holen:
function param(name) {
    var param_list = location.search.substr(1, location.search.length).split(/;|&/);
    for(var i in param_list) {
        if(param_list[i].indexOf(name) == 0) {
            return param_list[i].substr(name.length+1, param_list[i].length);
        }            
    }
    return '';
}

// Flash Erkennung:
var UseFlash = 0;

var NN4=false; // Netscape 4+
var MSI=false; // Internet Explorer 4+
var MSIVB=false; // Internet Explorer mit VB Script

var IEFlash7=false;
var IEFlash9=false;
var NNFlash=false;
var CSS=false;

var MAC=false;
var LINUX=false;
var WINDOWS=false;

var uagent=navigator.userAgent;
if((uagent.indexOf("Windows")!=-1) || (uagent.indexOf("Win")!=-1) || (uagent.indexOf("win 9x 4.90")!=-1)) WINDOWS=true
else if((uagent.indexOf("PPC")!=-1) || (uagent.indexOf("powerpc")!=-1) || (uagent.indexOf("mac")!=-1)) MAC=true
else if(uagent.indexOf("Linux")!=-1) LINUX=true;

if((WINDOWS||MAC)&&(uagent.indexOf("MSIE")!=-1)&&(navigator.appVersion.substring(0,1)>="4")&&(navigator.appName.indexOf("Internet Explorer")!=-1)&&(uagent.indexOf("Opera")==-1)&&(uagent.indexOf("OmniWeb")==-1)&&(uagent.indexOf("iCab")==-1)) MSI=true;

if(WINDOWS && MSI && typeof(execScript)!='undefined')
{
	execScript("On Error Resume Next: IEFlash7 = (IsObject(CreateObject(\"ShockwaveFlash.ShockwaveFlash.7\")))", "VBScript");
	execScript("On Error Resume Next: IEFlash9 = (IsObject(CreateObject(\"ShockwaveFlash.ShockwaveFlash.9\")))", "VBScript");
	execScript("MSIVB=true", "VBScript");	
}

if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] ) {
	// Check for Flash version 4 or greater in Netscape
	var plugin = navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin;
    var flashVersion = parseInt(plugin.description.substring(plugin.description.indexOf(".")-2,plugin.description.indexOf(".")));
	if (plugin && (flashVersion >= 7))
		UseFlash = 1;
        if(flashVersion >= 9) {
            IEFlash9 = true;
            IEFlash7 = true;
        }
        else {
            IEFlash7 = true;
        }
} else if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && 
	  navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	// Assume any Windows IE except for Windows 3.1 supports the OBJECT tag
	if(IEFlash7||IEFlash9) UseFlash = 1;
}

/* function currentDate()
{
	var now = new Date();

	var weekday = new Array("Sonntag","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag");
	var day = now.getDate();
	var month = (now.getMonth()+1);
	var year = now.getYear();
	var hours = now.getHours();
	var minutes = now.getMinutes();
	var seconds = now.getSeconds();
    
	if(day<10) day = '0'+day;
	if(month<10) month = '0'+month;
	if(year<1900) year = 1900+year;
	if(hours<10) hours = '0'+hours;
	if(minutes<10) minutes = '0'+minutes;
	if(seconds<10) seconds = '0'+seconds;
    
	document.getElementById('datum_uhrzeit').value=(weekday[now.getDay()]+' | '+day+'.'+month+'.'+year+' | '+hours+':'+minutes+' Uhr');
    window.setTimeout("currentDate()", 1000);
} */

function lOpen(url, target, width, height, scrollbars, resizable)
{
	switch(target)
	{
		case 'main':
		parent.frames['main'].location.href=url;
		break;
		case 'maincontent':
		parent.location.href=url;
		break;
		case '_top':
		top.location.href=url;
		break;
		case '_self':
		location.href=url;
		break;
		default:
		window.open(url,'_popup',"resizable="+resizable+",scrollbars="+scrollbars+",menubar=1,toolbar=1,directories=1,status=1,location=1,titlebar=1");
		break;

	}	
}


// Adapted from http://www.kryogenix.org/code/browser/searchhi/
function searchHighlight() 
{

  if (!document.createElement) return;
  // if (document.URL.indexOf('/search/') != -1) return;
//  var div = document.getElementById("searchable");
//  if (!div) return;
  var div = $(".searchable").get();
  if (div.length == 0) return;

  function set_span(node, pos, length, wordindex)
  {
  		var span = document.createElement("span");
		span.className = "searchword" + (wordindex % 5);
		span.appendChild(document.createTextNode(
		node.nodeValue.substr(pos, length)));
		var newNode = node.splitText(pos);
		newNode.nodeValue = newNode.nodeValue.substr(length);
		node.parentNode.insertBefore(span, newNode);
		return true;
  }
  
  function getSearchWords(url) {
    if (url.indexOf('?') == -1) return [];
    var queryString = url.substr(url.indexOf('?') + 1);
	queryString = queryString.replace(/;/, "&");
    var params = queryString.split('&');
    for (var p = 0; p < params.length; p++) {
      var param = params[p].split('=');
      if (param.length < 2) continue;
      if (param[0] == 'q' || param[0] == 'p') { // q= for Google, p= for Yahoo
	    
		// neu (A5)
		var phrasen = new Array();
		var words = new Array();
		
		var searchstring = unescape(param[1].replace(/\+/g, ' '));
		phrasen = searchstring.match(/\".+?\"/g);
		searchstring = searchstring.replace(/\".+?\"/g, ''); // phrasen aus dem Searchstring raus

		words = searchstring.split(/\s+/);
		
		if (phrasen != null)
		{
			for (var i = 0; i < phrasen.length; ++i)
			{
				words.push(phrasen[i].substr(1, phrasen[i].length -2 )); // substr = " " weg
			}
		}
		
		return words;
		
		// alt
        // return unescape(param[1].replace(/\+/g, ' ')).split(/\s+/);
      }
    }
    return [];
  }
var wcounter = 0;
  function highlightWord(node, word, searchwordindex) {
    // If this node is a text node and contains the search word, highlight it by
    // surrounding it with a span element
	
	if (node.nodeType == 3) { // Node.TEXT_NODE
		
		var next_node = node.nextSibling;
		if ((word == "o2") && (node.nodeValue.substr(node.nodeValue.length - 1, 1) == "O") &&  (next_node != null) && (next_node.nodeName == 'SUB') && (next_node.firstChild.nodeType == 3) && (next_node.firstChild.nodeValue == "2"))
		{
			word = 'O';
			pos = node.nodeValue.length - 1;
			set_span(next_node.firstChild, 0, 1, searchwordindex);
		}
		else
		{
			pos = node.nodeValue.toLowerCase().indexOf(word.toLowerCase());
		}
		
		if (pos >= 0 && !/^searchword\d$/.test(node.parentNode.className)) {
			return set_span(node, pos, word.length, searchwordindex);
		}
	
	}
	else if (!node.nodeName.match(/button|select|textarea/i)) {
      // Recurse into child nodes
      for (var i = 0; i < node.childNodes.length; i++) {
        if (highlightWord(node.childNodes[i], word, searchwordindex)) i++;
      }
    }
    return false;
  }

  var words = getSearchWords(document.URL);
  if (!words.length) words = getSearchWords(document.referrer);
  if (words.length) {
    for (var w = 0; w < words.length; w++) {
      for( var n = 0; n < div.length; n++) {
          if (words[w].length) highlightWord(div[n], words[w], w);
      }
    }
  }
}

// Weiterleitung per Link Tag:
function jump_to(link_tag, state, style)
{
    if(link_tag)
    {
        state = (state == 'preview') ? 'preview' : 'online';
        $.getJSON(getSessionUrl()+'/ext/ajax/link_info', { 
            'link_tag':link_tag, 
            'state':state, 
            'style':style }, 
            function(data) {
                if(data.length > 0) {
                    if(data[0].popup == 1) {
                        popup(data[0].url, data[0].popup_width, data[0].popup_height, data[0].popup_option);
                    }
                    else if(data[0].target == "_blank") {
                        window.open(data[0].url);
                    }
                    else {
                        location.href = data[0].url;
                    }
                }
        });
        // top.location.href="/session/cookie/ext/common/link_tag?link_tag="+escape(link_tag)+";state="+escape(state)+";style="+escape(style);
    }
}

// Cookie setzen:
function setCookie(name, content) {
    if(navigator.cookieEnabled) {
        document.cookie=name+'='+content+';path=/';
    }
}

// Cookie holen:
function getCookie(name) {
    if(navigator.cookieEnabled) {
        var myCookie = $.grep(document.cookie.split(';'), function(i) { return i.indexOf(name) != -1; });
        if(myCookie.length == 1) {
            var myContent = myCookie[0].split('=');
            return (myContent.length > 1) ? myContent[1] : '';
        }
    }
    return '';
}

// Poll abschicken:
function submit_poll(poll_form)
{
    if(typeof(poll_form) != 'undefined')
    {
        var selected = false;
        for(var i = 0; i < poll_form.poll_element_id.length; i++)
        {
            if(poll_form.poll_element_id[i].checked)
            {
                selected = true;
                break;
            }
        }
        if(selected)
        {
            poll_form.submit();
        }
        else
        {
            alert('Bitte wählen Sie eine Antwort aus.');
        }
    }   
    return false;
}

// Profil Popup:
function showProfile(phone_manual_id, user_id)
{
	if(phone_manual_id > 0)
	{
		popup('/session/cookie/ext/o2/profile/user?phone_manual_id='+phone_manual_id, 550, 645, '', 'infos'+phone_manual_id);
	}
    else if(user_id > 0)
    {
		popup('/session/cookie/ext/o2/profile/user?user_id='+user_id, 550, 645, '', 'infos'+user_id);
    }
}

// Picture Gallery Popup
function showPictureGallery(gallery_id) {
    popup('/session/cookie/ext/o2/gallery/index?gallery_id='+gallery_id, 750, 530, 'scrollbars=0,resize=0', 'image_gallery');
}

// Telefonbuch Suche:
function searchIntranet(form, start_search) {
    var redirect;
    var cmd;
    var query;
    
    if(start_search == true) {
    	query = form.q.value;
        cmd = 'search';
        redirect = (query != '') ? true : false;
    }
    else {
        query = '';
        cmd = '';
        redirect = true;
    }
    
    if(redirect == true) {
    	if(form.search.value == "telefonbuch") {
            location.href = "/session/cookie/ext/o2/search/phonebook?cmd="+cmd+"&additional=1&name="+escape(query);
    	}
    	else {
            location.href = "/session/cookie/ext/o2/search/index?cmd="+cmd+"&q="+escape(query);
    	}
    }
    else {
    	if(form.search.value == "telefonbuch") {
            location.href = "/session/cookie/ext/o2/search/phonebook";
    	}
    	else {
            location.href = "/session/cookie/ext/o2/search/index";
    	}
    }
}

// Suche in den iFrames:
function searchIframe(form) {
    if(form.search[0].checked == true) {
        $(form).attr('action', '/session/cookie/ext/o2/search/iframe');
        $("input[@name='tab']", form).attr('value', 'employee');
    }
    else {
        $(form).attr('action', '/session/cookie/ext/o2/search/index');
        $("input[@name='tab']", form).attr('value', 'intranet');
    }
    form.submit();
}

// START OF SmartSource Data Collector TAG 

var gImages=new Array;
var gIndex=0;
//var DCS=new Object();
//var WT=new Object();
//var DCSext=new Object();

var gDomain=(location.href.indexOf("o2-wizard.hq.spin.de")!=-1) ? window.location.hostname : "sdc.de.o2.com";
var gDcsId="";
/*
var gDomain="sdc2.o2.spin.de";
var gDcsId="dcs5w0txb10000wocrvqy1nqm_6n1p";
*/
// Add customizations here
//WT.sp="@@SPLITVALUE@@";

function dcsVar(){
	var dCurrent=new Date();
	WT.tz=dCurrent.getTimezoneOffset()/60*-1;
	WT.bh=dCurrent.getHours();
	WT.ul=navigator.appName=="Netscape"?navigator.language:navigator.userLanguage;
	if (typeof(screen)=="object"){
		WT.cd=screen.colorDepth;
		WT.sr=screen.width+"x"+screen.height;
	}
	if (typeof(navigator.javaEnabled())=="boolean"){
		WT.jo=navigator.javaEnabled()?"Yes":"No";
	}
	if (document.title){
		WT.ti=document.title;
	}
	WT.js="Yes";
	if (typeof(gVersion)!="undefined"){
		WT.jv=gVersion;
	}
	DCS.dcsdat=dCurrent.getTime();
	//DCS.dcssip=window.location.hostname;
	DCS.dcsuri=window.location.pathname;
	if (window.location.search){
		DCS.dcsqry=window.location.search;
	}
	if ((window.document.referrer!="")&&(window.document.referrer!="-")){
		if (!(navigator.appName=="Microsoft Internet Explorer"&&parseInt(navigator.appVersion)<4)){
			DCS.dcsref=window.document.referrer;
		}
	}
}

function A(N,V){
	return "&"+N+"="+dcsEscape(V);
}

function dcsEscape(S){
	if (typeof(RE)!="undefined"){
		var retStr = new String(S);
		for (R in RE){
			retStr = retStr.replace(RE[R],R);
		}
		return retStr;
	}
	else{
		return escape(S);
	}
}

function dcsCreateImage(dcsSrc){
// document.write(dcsSrc);
	if (document.images){
		gImages[gIndex]=new Image;
		gImages[gIndex].src=dcsSrc;
		gIndex++;
	}
	else{
		document.write('<IMG BORDER="0" NAME="DCSIMG" WIDTH="1" HEIGHT="1" SRC="'+dcsSrc+'">');
	}
}

function dcsMeta(){
	var myDocumentElements;
	if (document.all){
		myDocumentElements=document.all.tags("meta");
	}
	else if (document.documentElement){
		myDocumentElements=document.getElementsByTagName("meta");
	}
	if (typeof(myDocumentElements)!="undefined"){
		for (var i=1;i<=myDocumentElements.length;i++){
			myMeta=myDocumentElements.item(i-1);
			if (myMeta.name){
				if (myMeta.name.indexOf('WT.')==0){
					WT[myMeta.name.substring(3)]=myMeta.content;
				}
				else if (myMeta.name.indexOf('DCSext.')==0){
					DCSext[myMeta.name.substring(7)]=myMeta.content;
				}
				else if (myMeta.name.indexOf('DCS.')==0){
					DCS[myMeta.name.substring(4)]=myMeta.content;
				}
			}
		}
	}
}

function dcsTag(){
	var P="http"+(window.location.protocol.indexOf('https:')==0?'s':'')+"://"+gDomain+(gDcsId==""?'':'/'+gDcsId)+"/dcs.gif?";
	for (N in DCS){
		if (DCS[N]) {
			P+=A(N,DCS[N]);
		}
	}
	for (N in WT){
		if (WT[N]) {
			P+=A("WT."+N,WT[N]);
		}
	}
	for (N in DCSext){
		if (DCSext[N]) {
			P+=A(N,DCSext[N]);
		}
	}
	if (P.length>2048&&navigator.userAgent.indexOf('MSIE')>=0){
		P=P.substring(0,2040)+"&WT.tu=1";
	}
	dcsCreateImage(P);
}

// Inner Height eines Objekts holen:
function getInnerHeight(obj) {
    if(typeof(obj.offsetHeight) != 'undefined') {
        return obj.offsetHeight;
    }
    else if(typeof(obj.innerHeight) != 'undefined') {
        return obj.innerHeight;    
    }
    else {
        return 0;
    }
}

// Bestimmen ob es eine Session gibt:
function getSessionUrl() {
    return (location.href.indexOf('session/cookie')!=-1) ? '/session/cookie' : '';
}

// Stock nach dem Laden anzeigen:
function showStock(stock_url, iHeight) {
    // Stock: http://ir3.quartalflife.com/data/telefonica/tele_ticker_d.php
    if($("div.stock_html").size() == 1) {
        // var iframe_height = (stock_url.indexOf("https://secure.flife.de/ir/data/telefonica/teledeu_ticker_d.php") != -1) ? 82 : 60;
        // var iframe_height = (stock_url.indexOf("teledeu_ticker_d") != -1) ? 82 : 60;
        $("div.stock_html").html('<iframe src="'+stock_url+'" width="100%" height="'+iHeight+'" scrolling="no" frameborder="0"></iframe>');        
    }
}


// Nur das eine Element id der Klasse cname anzeigen:
function showClassID(cname, id) {
    var active = $("div[@id='"+id+"']").get();
    if(active.length == 1) {
        $("div."+cname).hide();
        $(active[0]).show();
    }
}


// Ownerbox:
var ob_open = "";
function showObButton() {
    switch(ob_open) {
        case "ob_info":
            $("td#ob_info").attr("class", "ob_open");
            $("td#ob_suggest").attr("class", "ob_closed_1");
            $("td#ob_rate").attr("class", "ob_closed_1");
            $("table#ob_button").addClass("open");
            $("div.ob_content").show();
        break;
        case "ob_suggest":
            $("td#ob_info").attr("class", "ob_closed_2");
            $("td#ob_suggest").attr("class", "ob_open");
            $("td#ob_rate").attr("class", "ob_closed_1");
            $("table#ob_button").addClass("open");            
            $("div.ob_content").show();
        break;
        case "ob_rate":
            $("td#ob_info").attr("class", "ob_closed_1");
            $("td#ob_suggest").attr("class", "ob_closed_2");
            $("td#ob_rate").attr("class", "ob_open");
            $("table#ob_button").addClass("open");            
            $("div.ob_content").show();
        break;
        default:
            $("td#ob_info").attr("class", "ob_closed_1");
            $("td#ob_suggest").attr("class", "ob_closed_1");
            $("td#ob_rate").attr("class", "ob_closed_1");
            $("table#ob_button").removeClass("open");            
            $("div.ob_content").hide();
            $("div#ob_html").html("");
        break;
    }
}

// Toggle Button:
function obToggle(obj, myurl) {
    var ob_id = obj.id;
    if(ob_open == ob_id) {
        ob_open = "";
        showObButton();
    }
    else {
        ob_open = ob_id;
        switch(ob_open) {
            case "ob_info":
                $("div#ob_html").load(getSessionUrl()+"/ext/common/info", {
                        url: myurl,
                        _utf8_: 1,
                        popup_style: "ownerbox"
                    },
                    showObButton()
                );            
            break;
            case "ob_suggest":
                $("div#ob_html").load(getSessionUrl()+"/ext/common/suggest_url", {
                      url: myurl,
                      _utf8_: 1,
                      popup_style: "ownerbox"
                    },
                    showObButton()
                );            
            break;
            case "ob_rate":
                var my_identifier = (obToggle.arguments.length>2) ? obToggle.arguments[2] : '';
                $("div#ob_html").load(getSessionUrl()+"/ext/common/rate", {
                      url: myurl,
                      description: document.title,
                      identifier: my_identifier,
                      _utf8_: 1,
                      popup_style: "ownerbox"
                    },
                    showObButton()
                );
            break;
            default:
                ob_open = "";
                showObButton();    
            break;
        }
    }
}


function clean_text(text) {
    text = text.replace(/\´/g, "'");
    text = text.replace(/\`/g, "'");

    text = text.replace(/\u2018/g, "'");
    text = text.replace(/\u2019/g, "'");
    text = text.replace(/\u201A/g, "'");
    text = text.replace(/\u201B/g, "'");

    text = text.replace(/\u201C/g, '"');
    text = text.replace(/\u201D/g, '"');
    text = text.replace(/\u201E/g, '"');
    text = text.replace(/\u2013/g, '-');
    text = text.replace(/\u2014/g, '-');
    text = text.replace(/\u2015/g, '-');
    
    return text;
}

// Ownerbox abschicken:
function submitOwnerbox(form) {
    if(form.nodeName == "FORM") {
        var args = {};
        var submit_url = form.action;
        for(var i = 0; i < form.elements.length; i++) {
            if(typeof(form.elements[i].type) != 'undefined') {

                if( (form.elements[i].type == "hidden") ||
                    (form.elements[i].type == "text") ||
                    (form.elements[i].type == "textarea") ){
        
                    args[form.elements[i].name] = clean_text(form.elements[i].value);
                }
                else if( (form.elements[i].type == "radio") ||
                         (form.elements[i].type == "checkbox")
                        ) {
                    if(form.elements[i].checked) {
                    
                        args[form.elements[i].name] = clean_text(form.elements[i].value);
                    }
                }
            }
        }
        args["popup_style"] = "ownerbox";
        args["_utf8_"] = 1;
        
        $("div#ob_html").load(submit_url, args, showObButton() );
    }
    return false;
}

// Intraview Fenster oeffnen:
function openBroadcast(broadcast_id, state, style) {
    $.get( "/session/cookie/ext/o2/intraview/popup_size",
           { broadcast_id: broadcast_id, state: state, style: style },
           function(data) {
                var popup_size = data.split('$');
                if(popup_size.length == 2) {
                    var popup_width = popup_size[0].replace(/\D/,"");
                    var popup_height = popup_size[1].replace(/\D/,"");
                    if((popup_width != "") && (popup_height != "")) {
                        popup("/session/cookie/ext/o2/intraview/popup?broadcast_id="+escape(broadcast_id)+";state="+escape(state)+";style="+escape(style), popup_width, popup_height, "resizable=0,scrollbars=0", "itv"+escape(broadcast_id));
                    }
                }
           }
    );
}

// Custom Slider:
function slideCustom(str, speed, btobj, classo, classc) {
    if(speed == "") { speed = "fast"; }
    var tag = $(str).get(0);
    if(typeof(tag) != "undefined") {
        if($(tag).is(":visible")) {
            if(speed == "show") {
                $(tag).hide();
            }
            else {
                $(tag).slideUp(speed);
            }
            if(typeof(btobj) != "undefined") {
                $(btobj).attr('class', classc);
            }
        }
        else {
            if(speed == "show") {
                $(tag).show();
            }
            else {
                $(tag).slideDown(speed);
            }
            if(typeof(btobj) != "undefined") {
                $(btobj).attr('class', classo);
            }
        }
    }
    return false;
}

// HTML Escape
function html_escape(to_encode) {
    var text = ""+to_encode+"";
    if(text=="") { return ""; }
    text = text.replace(/\&/g, '&amp;');
    text = text.replace(/\"/g, '&quot;');
    text = text.replace(/\</g, '&lt;');
    text = text.replace(/\>/g, '&gt;');
    text = text.replace(/\ü/g, '&#252;');
    text = text.replace(/\Ü/g, '&#220;');
    text = text.replace(/\ä/g, '&#228;');
    text = text.replace(/\Ä/g, '&#196;');
    text = text.replace(/\ö/g, '&#246;');
    text = text.replace(/\Ö/g, '&#214;');
    text = text.replace(/\ß/g, '&#223;');
    return text;
}

// PDB log download:
function pdb_log_download(tree_id, path, filename) {
    if(path.indexOf('/online/')!=-1) {
        if(typeof(top.hidden)!='undefined') {
            // top.hidden.location.href="/session/cookie/ext/o2/productdb/log_download?tree_id="+escape(tree_id)+"&filename="+escape(filename);
            $.get("/session/cookie/ext/o2/productdb/log_download", { tree_id: tree_id, filename: filename } );
        }
    }
    return true;
}

// TopStory Init:
function topStoryInit(ts_par) {
    ts_par = "div#"+ts_par;
    // Top Story Tabs klickbar machen:
    $("td.ts_item, td.ts_item_hi", ts_par).click(function(e) {
        var tab_id = this.id;    
        var content_id = this.id+"_c";
        var media_id = this.id+"_m";

        $("td.ts_item[@id!='"+tab_id+"'], td.ts_item_hi", $(this).parents("div.par")).attr("class","ts_item");
        $("td.ts_item[@id='"+tab_id+"']", $(this).parents("div.par")).attr("class","ts_item_hi");
        $("div.ts_content[@id!='"+content_id+"'], div.ts_media[@id!='"+media_id+"']", $(this).parents("div.par")).hide();
        $("div.ts_content[@id='"+content_id+"'], div.ts_media[@id='"+media_id+"']", $(this).parents("div.par")).show();
    });
}


// Portal Rotator:
var curImage = new Array();
var rotContent = new Array();
var rotIv;

function rotImage() {
    for (var i in rotContent) {
        if(rotContent[i]) {
            $("img[@id='"+curImage[i]+"']", "div.rot_cont[@id='"+i+"']").fadeOut("fast", function() { 
                var cID = $(this).parents("div.rot_cont").attr("id");
                var iNum = parseInt(curImage[cID].replace(/i/,""));
                iNum = (iNum < 3) ? (iNum+1) : 0;
                curImage[cID] = 'i'+iNum;
                $("td", "div.rot_cont[@id='"+cID+"']").removeClass("hi");
                $("img[@id='"+curImage[cID]+"']", "div.rot_cont[@id='"+cID+"']").fadeIn("fast", function() { 
                    var tNum = "t"+$(this).attr("id").replace(/i/, "");
                    var cID = $(this).parents("div.rot_cont").attr("id");
                    $("td[@id='"+tNum+"']", "div.rot_cont[@id='"+cID+"']").addClass("hi");
                });
            });
        }
    }
}

// Datum:
function currentDate() {
    var now = new Date();
    var weekday = new Array("Sonntag","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag");
    var day = now.getDate();
    var month = (now.getMonth()+1);
    var year = now.getYear();
    var hours = now.getHours();
    var minutes = now.getMinutes();
    if(day<10) day = '0'+day;
    if(month<10) month = '0'+month;
    if(year<1900) year = 1900+year;
    if(hours<10) hours = '0'+hours;
    if(minutes<10) minutes = '0'+minutes;
    return weekday[now.getDay()]+'&nbsp;|&nbsp;'+day+'.'+month+'.'+year+'&nbsp;|&nbsp;'+hours+':'+minutes;
}

// Comments
function showComments(pageId, state, style, show) {
    $("div.ob_comment_box").load(
        getSessionUrl()+'/ext/o2/wizard/comment/ajax_show',
        { page_id : pageId,
          state : state,
          style : style,
          show : show
        },
        function() {
            $("img.tooltip_icon", this).click(function(e) {
                if($("div.tooltip_txt", this.parentNode).is(":visible")) {
                    $("div.tooltip_txt", this.parentNode).fadeOut("fast");
                }
                else {
                    $("div.tooltip_txt", this.parentNode).fadeIn("fast");
                }
            });
            $("a.tooltip_close", this).click(function(e) {
                $(this).parents("div.tooltip_txt").fadeOut("fast");
            });        
            /*$("div.ob_comment_entry").hover(function() { 
                $("div.ob_options", this).show();    
            }, function() { 
                $("div.ob_options", this).hide();    
            });*/
        }
    );
    saveCommentBoxState(pageId, show);
}

function saveCommentBoxState(pageId, show) {
    setCookie("commentBox"+pageId, show);
    return true;
}

function addComment(content, pageId, commentId, state, style, myTop) {
    
    $("div.ob_comment_box").load(
            getSessionUrl()+'/ext/o2/wizard/comment/ajax_show', {
            page_id : pageId,
            cmd : "add",
            comment_id : commentId,
            content : content,
            state : state,
            style : style,
            show : 1
        },
        function() {
            if(myTop != undefined) {
                window.scrollTo(0, myTop);
            }
            else {
                window.scrollTo(0, this.offsetTop+this.offsetHeight);
            }
        }        
    );
}

// Kommentar loeschen:
function deleteComment(pageId, commentId, state, style, myTop) {
    if(confirm("Kommentar löschen. Sind sie sicher?")) {
        $("div.ob_comment_box").load(
                getSessionUrl()+'/ext/o2/wizard/comment/ajax_show', {
                page_id : pageId,
                cmd : "delete",
                comment_id : commentId,
                state : state,
                style : style,
                show : 1
            },
            function() {
                if(myTop != undefined) {
                    window.scrollTo(0, myTop);
                }
                else {
                    window.scrollTo(0, this.offsetTop+this.offsetHeight);
                }
            }        
        );
    }
}


function showCommentBox(obj, pageId, commentId, state, style, myWidth, sessionId) {
    var inputBox = $("div#comment_"+commentId).get(0);
    if($(inputBox).is(":visible")) {
        $(inputBox).slideUp();
    }
    else {
        $(inputBox).slideDown(function() { 
            $("div.ob_comment_input:visible").not(this).slideUp();
        });
    }
}

// Kalender:
function loadCalendar(obj, url) {
    $(obj).parents("div.calendar").load(url);
}


// Link Tag einfuegen:

// Linktag holen:
function getSelectedLinkTag(textarea) {
    textarea.focus();
    var sel, start, end, link_tag, link_tag_start, cursor_in_tag;
    var content = textarea.value;

    if(typeof(document["selection"]) != "undefined") {
        sel = document.selection.createRange().text;
        var dummy = "[[#NEW#]]";
        document.selection.createRange().text = dummy;
        start = textarea.value.indexOf(dummy);
        if(sel.length > 0) {
            document.selection.createRange().text = sel;
            end = start+sel.length;
            if(textarea.value.indexOf(dummy) != -1) {
                textarea.value = textarea.value.replace(dummy, "");
            }
        }
        else {
            end = start;
            var range = textarea.createTextRange();
            range.findText(dummy);
            range.select();
            range.text = "";
        }
    } 
    else if (typeof(textarea["setSelectionRange"]) != "undefined") {
        start = textarea.selectionStart;
        end = textarea.selectionEnd;
        sel = textarea.value.substring(start, end);
    }

    // Steht der Cursor am Rand?
    if(sel.search(/^\[[^\[]/)) {
        if(start > 1) {
            if(content.substring(start-2, start-1) == "[") {
                if(start == end) { end++; }
                start++;
                sel = content.substring(start, end);
            }
        }
    }
    else if(sel.search(/[^\]]\]$/)) {
        if(end < content.length) {
            if(content.substring(end, end+1) == "]") {
                if(start == end) { start--; }
                end--;
                sel = content.substring(start, end);
            }
        }
    }
    
    link_tag = "";
    link_tag_start = 0;
    if((start == end) || (sel.indexOf("[[") == -1)) {
        var part1 = content.substring(0, start);
        link_tag_start = part1.lastIndexOf("[[");
        if(link_tag_start > part1.lastIndexOf("]]")) {
            var part2 = content.substring(link_tag_start);
            link_tag = content.substr(link_tag_start, part2.indexOf("]]")+2);
            cursor_in_tag = true;
        }
    }
    else if(sel.indexOf("[[") != -1) {
        link_tag_start = start+sel.indexOf("[[");
        var part = sel.substring(sel.indexOf("[["))+content.substring(end);
        link_tag = part.substring(0, part.indexOf("]]")+2);
    }
    
    if(!link_tag.match(/^\[\[.*\]\]$/)) {
        link_tag = "";
    }
    
    // Cursor innerhalb des Tags:
    if((link_tag != "") && (link_tag.length >= sel.length)) {
        cursor_in_tag = true;
    }
    
    return [link_tag, link_tag_start, cursor_in_tag];
}

// Selektierten Text holen:
function getSelectedText(textarea) {
    textarea.focus();
    var sel;
    if (typeof(document["selection"]) != "undefined") {
        sel = document.selection.createRange().text;
    } 
    else if (typeof(textarea["setSelectionRange"]) != "undefined") {
        var start = textarea.selectionStart;
        var end = textarea.selectionEnd;
        sel = textarea.value.substring(start, end);
    }
    else {
        sel = "";
    }
    return sel;
}

// Tags in Textarea einfuegen:
function encloseSelection(textarea, prefix, suffix) {
    textarea.focus();
    var start, end, sel, scrollPos, subst;
    if (typeof(document["selection"]) != "undefined") {
        sel = document.selection.createRange().text;
    } 
    else if (typeof(textarea["setSelectionRange"]) != "undefined") {
        start = textarea.selectionStart;
        end = textarea.selectionEnd;
        scrollPos = textarea.scrollTop;
        sel = textarea.value.substring(start, end);
    }
    else if(suffix == "") {
        if(textarea.value != "") {
                link_tag = ' '+link_tag;
        }

        textarea.value += prefix;
    }
    
    if (sel.match(/ $/)) { // exclude ending space char, if any
        sel = sel.substring(0, sel.length - 1);
        suffix = suffix + " ";
    }
    
    // Bestimmte Tags nicht verschachteln:
    sel = sel.replace(/\{li\}|\{\/li\}|\{li2\}|\{\/li2\}|\{b\}|\{\/b\}/g, "");
        
    subst = prefix + sel + suffix;
    if (typeof(document["selection"]) != "undefined") {
        var range = document.selection.createRange();
        range.text = subst;
        if(sel.length == 0) {
            range.move('character', ((-1)*suffix.length));
            range.select();
        }
        else {
            textarea.caretPos -= suffix.length;
        }
        range.select();
    } else if (typeof(textarea["setSelectionRange"]) != "undefined") {
        textarea.value = textarea.value.substring(0, start) + subst +
        textarea.value.substring(end);
        if (sel) {
            textarea.setSelectionRange(start + subst.length, start + subst.length);
        } else {
            textarea.setSelectionRange(start + prefix.length, start + prefix.length);
        }
            textarea.scrollTop = scrollPos;
    }
}

// Auswahl ersetzen:
function replaceSelection(textarea, new_text, old_text, start, scrolltop) {
    textarea.focus();
    var content = textarea.value;
    textarea.value = content.substring(0, start)+new_text+content.substring(start+old_text.length);
    if(typeof(document["selection"]) != "undefined") {
        var range = textarea.createTextRange();
        /*
            range.moveStart('character', start);
            range.moveEnd('character', 0 - (textarea.value.length - (start+new_text.length)) );
            range.select();
        */
        range.findText(new_text);
        range.select();
        textarea.focus();
    }
    else if(typeof(textarea.setSelectionRange) != "undefined") {
        textarea.selectionStart = start;
        textarea.selectionEnd = start + new_text.length;
        textarea.focus();
    }
    textarea.scrollTop = scrolltop;
}

// Tag einfuegen:
function insertTag(textarea, start_tag, end_tag) {
    
    // Checken ob Cursor in einem Tag steht:
    var selected_arr = getSelectedLinkTag(textarea);
    if((selected_arr[0] != "") && (selected_arr[2]) ){
        // Cursor steht in einem Tag:
        var old_text = selected_arr[0];
        var new_text = start_tag+selected_arr[0]+end_tag;
        var start = selected_arr[1];
        var scrolltop = textarea.scrollTop;
        replaceSelection(textarea, new_text, old_text, start, scrolltop);
    }
    else {
        // Cursor steht nicht in einem Tag:
        encloseSelection(textarea, start_tag, end_tag)
    }
}

// Link Tag aus Popup holen:
function get_link_tag(link_tag) {

    // Sind alle Werte vorhanden?
    if( (!link_tag_name) || 
        (link_tag_name == 'no_link_tag') ||
        (link_form == null) ||
        (typeof(link_form.elements[link_tag_name]) == 'undefined') ) {
        return false;
    }

    // Link Tag in Formular einfuegen:
    if(link_insert_mode == "append") {
        if(link_form.elements[link_tag_name].value != "") {
            link_tag = ' '+link_tag;
        }
        link_form.elements[link_tag_name].value += link_tag;
        link_submit = false;
    }
    else if(link_insert_mode == "insert") {
        // Link Tag einsetzen:

        // Soll der Link einen anderen Link ersetzen?
        if(link_selected_tag != "") {
            replaceSelection(link_form.elements[link_tag_name], link_tag, link_selected_tag, link_selected_start, link_scroll_top);
        }
        else {
            // Link an aktueller Cursorposition einsetzen:
            var link_split = link_tag.split("\["+link_desc+"\]");
            if((link_desc != "") && (link_split.length == 2)) {
                // Link um aktuelle Description einsetzen:
                encloseSelection(link_form.elements[link_tag_name], link_split[0]+"[", "]"+link_split[1]);
            }
            else {
                // Link einfach an Cursorposition setzen:
                if(link_desc != "") {
                    link_tag = " "+link_tag;
                }
                encloseSelection(link_form.elements[link_tag_name], "", link_tag);
            }
        }
        link_submit = false;
    }
    else {
        link_form.elements[link_tag_name].value = link_tag;
    }    
    
    // Formular abschicken:
    if(link_submit == true) {
        if(typeof(link_form.elements['cmd']) != 'undefined') {
            link_form.elements['cmd'].value = 'save_link';
        }
        if(typeof(link_form.elements['link_tag_name']) != 'undefined') {
            link_form.elements['link_tag_name'].value = link_tag_name;
        }
        if(typeof(link_form.elements['scroll_top']) != 'undefined') {
            link_form.elements['scroll_top'].value = document.documentElement.scrollTop;
        }           
        link_form.submit();       
    }
    
    // Default Werte setzen:    
    set_link_popup_defaults();
    
    return true;
}

// Link Tag loeschen:
function remove_link_tag(link_tag_name)
{
    if(!link_tag_name)
    {
        return false;
    }
    
    var formnum = -1;
    for(var i=0; i < document.forms.length; i++)
    {
        if(typeof(document.forms[i].elements[link_tag_name]) != 'undefined')
        {
            formnum = i;
            break;
        }
    }
    
    if(formnum > -1)
    {
        document.forms[formnum].elements[link_tag_name].value = '';
        if(typeof(document.forms[formnum].elements['cmd']) != 'undefined')
        {
            document.forms[formnum].elements['cmd'].value = 'delete_link';
        }
        if(typeof(document.forms[formnum].elements['link_tag_name']) != 'undefined')
        {
            document.forms[formnum].elements['link_tag_name'].value = link_tag_name;
        }
        if(typeof(document.forms[formnum].elements['scroll_top']) != 'undefined') {
            document.forms[formnum].elements['scroll_top'].value = document.documentElement.scrollTop;
        }                     
        document.forms[formnum].submit();
        return true;
    }
    else
    {
        return false;
    }
}

// Link Tag einfuegen Ende


// Search Help Text:
var sHelpText = {};
$(document).ready(function() {
    $("li.h-help").each(function() {
        sHelpText[$(this).attr("id")] = jQuery.trim($(this).html());
    });
});

// Ist es ein Hilfetext?
function isHelpText() {
    var myText = document.forms["hsearch"].q.value;
    if(myText == "") return true;
    for(var i in sHelpText) {
        if(sHelpText[i] == myText) {
            return true;
        }
    }
    return false;
}

// Hilfetext anzeigen:
function showHelpText() {
    var myType = document.forms["hsearch"].search.value;
    if(isHelpText() && (sHelpText[myType] != undefined)) {
        document.forms["hsearch"].q.value = sHelpText[myType];
        $("input[name='q']", "div.h-search").css({'color':'#999999'});
    }
}

// Hilfetext verstecken:
function hideHelpText() {
    if(isHelpText()) {
        document.forms["hsearch"].q.value = "";
        $("input[name='q']", "div.h-search").css({'color':'#000000'});
    }
}

// Suchmaschine setzen:
function setSearchType(myType) {
    if(sHelpText[myType] != undefined) {
        document.forms["hsearch"].search.value = myType;
        setCookie("hsearch", myType);
        showHelpText();
    }
}

// Drawer:
function toggleDrawer(sessionInfo, drawerInfo) {
    var oldDrawerId = $("div.drawer").attr("id");
    var newDrawerId = 'dr-'+sessionInfo+'-'+drawerInfo;
    if(oldDrawerId.indexOf("closed") != -1) {
        // Geschlossen:
        $("div.drawer").attr("id", newDrawerId);
        $("div.dr-main").hide();
        $("div#dr-"+drawerInfo).show();
        $("div.drawer").animate({"top":0}, 200);
        setCookie("hdrawer", newDrawerId);
    }
    else {
        // Offen:
        if(oldDrawerId == newDrawerId) {
            $("div.pd-content").hide();
            $("div.drawer").animate({"top":-24}, 200, function() { 
                if(oldDrawerId.indexOf("off") != -1) {
                    $("div.drawer").attr("id", "dr-off-closed");
                }
                else {
                    $("div.drawer").attr("id", "dr-on-closed");
                }
                setCookie("hdrawer", "closed");
            });
        }
        else {
            $("div.drawer").attr("id", newDrawerId);
            $("div.dr-main").hide();
            $("div#dr-"+drawerInfo).show();
            setCookie("hdrawer", newDrawerId);
        }
    }
}

// Pulldown laden:
function loadPulldown(pname) {
    if($("div.pd-content#"+pname).is(":empty")) {
        $("div.pd-content#"+pname).load(
            getSessionUrl()+"/ext/o2/drawer/pulldown",
            { type:pname.substr(1) },
            function() {
                if($(this).find("a").size() > 8) {
                    $(this).css({height:"136px"});
                }
                // $(this).show();
        });    
    }
}

// Pulldown Boxen:
function togglePulldownBox(pname) {
    if($("div.pd-content#"+pname).is(":hidden")) {
        $("div.pd-content").hide();
        if($("div.pd-content#"+pname).is(":empty")) {
            $("div.pd-content#"+pname).load(
                getSessionUrl()+"/ext/o2/drawer/pulldown",
                { type:pname.substr(1) },
                function() {
                    if($(this).find("a").size() > 8) {
                        $(this).css({height:"136px"});
                    }
                    $(this).show();
            });    
        }
        else {
            $("div.pd-content#"+pname).show();
        }
    }
    else {
        $("div.pd-content").hide();
    }
}

// Feed Accordion:
function showAccNewsFeed(obj, destObj, categoryId, treeId, groupId, groupYear) {
    if($(obj).next(destObj).is(":visible")) {
        $(obj).next(destObj).slideUp();
    }
    else {
        $.getJSON(getSessionUrl()+'/ext/ajax/acc_news_feed', { 'category_id':categoryId, 'tree_id':treeId, 'group_id':groupId, 'year':groupYear }, function(data) {
            $(obj).next(destObj).html("");
            var count = 0;
            $.each(data, function(i, item) {
                $(obj).next(destObj).append('<div class="acc_item"><div class="date">'+item.date+'</div><a href="'+item.url+'">'+item.title+'</a></div>');
                count++;
            });
            
            if(!count) {
                $(obj).next(destObj).append('<div class="acc_item">Keine News gefunden.</div>');
            }
            else {
                $(obj).next(destObj).append('<div class="acc_item"><a href="'+getSessionUrl()+'/ext/o2/news/list_messages?category_id='+categoryId+';tree_id='+treeId+'">... weitere Meldungen</a></div>');
            }
            
            if($(obj).next(destObj).is(":hidden")) {
                $(obj).next(destObj).slideDown(function() { 
                    $(destObj).not(this).slideUp(function() {
                        $(this).prev(obj).addClass("closed");
                    });                    
                });
            }
        });
    }
}

function showAccRssFeed(obj, destObj, rssId, rssHash) {
    if($(obj).next(destObj).is(":visible")) {
        $(obj).next(destObj).slideUp();
    }
    else {
        $.getJSON(getSessionUrl()+'/ext/ajax/acc_rss_feed', { 'rss_id':rssId, 'rss_hash':rssHash }, function(data) {
            $(obj).next(destObj).html("");
            var count = 0;
            $.each(data, function(i, item) {
                $(obj).next(destObj).append('<div class="acc_item"><div class="date">'+item.date+'</div><a href="'+item.url+'" target="_blank">'+item.title+'</a></div>');
                count++;
            });
            
            if(!count) {
                $(obj).next(destObj).append('<div class="acc_item">Keine News gefunden.</div>');
            }
            else {
                $(obj).next(destObj).append('<div class="acc_item"><a href="/ext/common/rss_feed_forward?rss_id='+rssId+';rss_hash='+rssHash+'" target="_blank">... weitere Meldungen</a></div>');
            }
                        
            if($(obj).next(destObj).is(":hidden")) {
                $(obj).next(destObj).slideDown(function() { 
                    $(destObj).not(this).slideUp(function() {
                        $(this).prev(obj).addClass("closed");
                    });                    
                });
            }
        });
    }
}

// Intranet Suche Pulldown Menu:
var toSearchPulldown;
$(document).ready(function() {
    if($("div#h-bar").size()) {
        $("div#h-icon").mouseover(function() {
            window.clearTimeout(toSearchPulldown);
            openSearchPulldown(document.forms['hsearch'].search.value);
        });
        $("div#h-icon, div#h-pulldown").mouseout(function() {
            toSearchPulldown = window.setTimeout("closeSearchPulldown()", 600);
        });
        $("div#h-pulldown").mouseover(function() {
            window.clearTimeout(toSearchPulldown);
        });
        
        $("div.h-sitem", "div#h-pulldown").click(function() {
            changeSearchType($(this).attr("id"));
        }).hover(function() { $(this).addClass("hover") }, function() { $(this).removeClass("hover") });
        $("input[@name='q']", "div#h-bar").keydown(function() {
            $("div#h-help").hide();
        }).keyup(function() {
            if(this.value == "") {
                $("div#h-help").show();
            }
        });
        $("div#h-help").click(function() {
            $(this).hide(function() {
                $("input[@name='q']", "div#h-bar").focus();
            });
        });
    }
});

function openSearchPulldown(currentSearch) {
    if($("div#h-pulldown").is(":visible")) {
        $("div#h-pulldown").fadeOut("fast", function() {
            $("input[@name='q']", "div#h-bar").focus();
        });
    }
    else {
        $("div.h-sitem").not("#"+currentSearch).show(function() { 
            $("div#h-pulldown").fadeIn("fast");
        });
        
    }
}

function closeSearchPulldown() {
    $("div#h-pulldown").fadeOut("fast", function() {
        $("input[@name='q']", "div#h-bar").focus();
    });
}

function changeSearchType(newSearch) {
    $("div#h-icon").removeClass().addClass(newSearch);
    $("div#h-pulldown").fadeOut("fast", function() {
        $("div.h-sitem").hide();
        $("div#h-help").html($("div#"+newSearch, this).html());
        document.forms['hsearch'].search.value = newSearch;
        $("input[@name='q']", "div#h-bar").focus();
        setCookie("hsearch", newSearch);
    });
    
}



/*
 * Autocomplete - jQuery plugin 1.0 Alpha
 *
 * Copyright (c) 2007 Dylan Verheul, Dan G. Switzer, Anjesh Tuladhar, Jï¿½Zaefferer
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 * Revision: $Id: jquery.autocomplete.js 1870 2007-05-05 17:01:31Z dan $
 *
 */
 
jQuery.fn.extend({
	autocomplete: function(urlOrData, options) {
		var isUrl = typeof urlOrData == "string";
		options = jQuery.extend({}, jQuery.Autocompleter.defaults, {
			url: isUrl ? urlOrData : null,
			data: isUrl ? null : urlOrData,
			delay: isUrl ? jQuery.Autocompleter.defaults.delay : 10
		}, options);
		
		// if highlight is set to false, replace it with a do-nothing function
		options.highlight = options.highlight || function(value) { return value; };
		// if moreItems is false, replace it w/empty string
		options.moreItems = options.moreItems || "";
		
		return this.each(function() {
			new jQuery.Autocompleter(this, options);
		});
	},
	result: function(handler) {
		return this.bind("result", handler);
	},
	search: function(handler) {
		return this.trigger("search", [handler]);
	},
	flushCache: function() {
		return this.trigger("flushCache");
	},
	setOptions: function(options){
		return this.trigger("setOptions", [options]);
	}
});

jQuery.Autocompleter = function(input, options) {

	var KEY = {
		UP: 38,
		DOWN: 40,
		DEL: 46,
		TAB: 9,
		RETURN: 13,
		ESC: 27,
		COMMA: 188
	};

	// Create jQuery object for input element
	var $input = jQuery(input).attr("autocomplete", "off").addClass(options.inputClass);

	var timeout;
	var previousValue = "";
	var cache = jQuery.Autocompleter.Cache(options);
	var hasFocus = 0;
	var lastKeyPressCode;
	var select = jQuery.Autocompleter.Select(options, input, selectCurrent);
	
	$input.keydown(function(event) {
		// track last key pressed
		lastKeyPressCode = event.keyCode;
		switch(event.keyCode) {
		
			case KEY.UP:
				event.preventDefault();
				if ( select.visible() ) {
					select.prev();
				} else {
					onChange(0, true);
				}
				break;
				
			case KEY.DOWN:
				event.preventDefault();
				if ( select.visible() ) {
					select.next();
				} else {
					onChange(0, true);
				}
				break;
			
			// matches also semicolon
			case options.multiple && jQuery.trim(options.multipleSeparator) == "," && KEY.COMMA:
			case KEY.TAB:
			case KEY.RETURN:
				if( selectCurrent() ){
					// make sure to blur off the current field
					if( !options.multiple )
						// $input.blur(); // BY A5
					event.preventDefault();
				}
				break;
				
			case KEY.ESC:
				select.hide();
				break;
				
			default:
				clearTimeout(timeout);
				timeout = setTimeout(onChange, options.delay);
				break;
		}
	}).keypress(function() {
		// having fun with opera - remove this binding and Opera submits the form when we select an entry via return
	}).focus(function(){
		// track whether the field has focus, we shouldn't process any
		// results if the field no longer has focus
		hasFocus++;
	}).blur(function() {
		hasFocus = 0;
		hideResults();
	}).click(function() {
		// show select when clicking in a focused field
		if ( hasFocus++ > 1 && !select.visible() ) {
			onChange(0, true);
		}
	}).bind("search", function() {
		var fn = (arguments.length > 1) ? arguments[1] : null;
		function findValueCallback(q, data) {
			var result;
			if( data && data.length ) {
				for (var i=0; i < data.length; i++) {
					if( data[i].result.toLowerCase() == q.toLowerCase() ) {
						result = data[i];
						break;
					}
				}
			}
			if( typeof fn == "function" ) fn(result);
			else $input.trigger("result", result && [result.data, result.value]);
		}
		jQuery.each(trimWords($input.val()), function(i, value) {
			request(value, findValueCallback, findValueCallback);
		});
	}).bind("flushCache", function() {
		cache.flush();
	}).bind("setOptions", function() {
		// overwrite the options
		for( var k in arguments[1] ){
			// update the options
			options[k] = arguments[1][k];
			// if we've updated the data, repopulate
			if( k == "data" ) cache.populate();
		}
	});
	
	hideResultsNow();
	
	function selectCurrent() {
		var selected = select.selected();
		if( !selected )
			return false;
		
		var v = selected.result;
		previousValue = v;
		
		if ( options.multiple ) {
			var words = trimWords($input.val());
			if ( words.length > 1 ) {
				v = words.slice(0, words.length - 1).join( options.multipleSeparator ) + options.multipleSeparator + v;
			}
			v += options.multipleSeparator;
		}
		
		$input.val(v);
		hideResultsNow();
		$input.trigger("result", [selected.data, selected.value]);
		return true;
	}
	
	function onChange(crap, skipPrevCheck) {
		if( lastKeyPressCode == KEY.DEL ) {
			select.hide();
			return;
		}
		
		var currentValue = $input.val();
		
		if ( !skipPrevCheck && currentValue == previousValue )
			return;
		
		previousValue = currentValue;
		
		currentValue = lastWord(currentValue);
		if ( currentValue.length >= options.minChars) {
			$input.addClass(options.loadingClass);
			if (!options.matchCase)
				currentValue = currentValue.toLowerCase();
			request(currentValue, receiveData, hideResultsNow);
		} else {
			stopLoading();
			select.hide();
		}
	};
	
	function trimWords(value) {
		if ( !value ) {
			return [""];
		}
		var words = value.split( jQuery.trim( options.multipleSeparator ) );
		var result = [];
		jQuery.each(words, function(i, value) {
			if ( jQuery.trim(value) )
				result[i] = jQuery.trim(value);
		});
		return result;
	}
	
	function lastWord(value) {
		if ( !options.multiple )
			return value;
		var words = trimWords(value);
		return words[words.length - 1];
	}
	
	// fills in the input box w/the first match (assumed to be the best match)
	function autoFill(q, sValue){
		// autofill in the complete box w/the first match as long as the user hasn't entered in more data
		// if the last user key pressed was backspace, don't autofill
		if( options.autoFill && (lastWord($input.val()).toLowerCase() == q.toLowerCase()) && lastKeyPressCode != 8 ) {
			// fill in the value (keep the case the user has typed)
			$input.val($input.val() + sValue.substring(lastWord(previousValue).length));
			// select the portion of the value not typed by the user (so the next character will erase)
			jQuery.Autocompleter.Selection(input, previousValue.length, previousValue.length + sValue.length);
		}
	};

	function hideResults() {
		clearTimeout(timeout);
		timeout = setTimeout(hideResultsNow, 200);
	};

	function hideResultsNow() {
		select.hide();
		clearTimeout(timeout);
		stopLoading();
		if (options.mustMatch) {
			// call search and run callback
			$input.search(
				function (result){
					// if no value found, clear the input box
					if( !result ) $input.val("");
				}
			);
		}
	};

	function receiveData(q, data) {
		if ( data && data.length && hasFocus ) {
			stopLoading();
			select.display(data, q);
			autoFill(q, data[0].value);
			select.show();
		} else {
			hideResultsNow();
		}
	};

	function request(term, success, failure) {
		if (!options.matchCase)
			term = term.toLowerCase();
		var data = cache.load(term);
		// recieve the cached data
		if (data && data.length) {
			success(term, data);
		// if an AJAX url has been supplied, try loading the data now
		} else if( (typeof options.url == "string") && (options.url.length > 0) ){
			jQuery.ajax({
				url: options.url,
				data: jQuery.extend({
					q: lastWord(term),
					limit: options.max
				}, options.extraParams),
				success: function(data) {
					var parsed = options.parse && options.parse(data) || parse(data);
					cache.add(term, parsed);
					success(term, parsed);
				}
			});
		} else {
			failure(term);
		}
	}
	
	function parse(data) {
		var parsed = [];
		var rows = data.split("\n");
		for (var i=0; i < rows.length; i++) {
			var row = jQuery.trim(rows[i]);
			if (row) {
				row = row.split("|");
				parsed[parsed.length] = {
					data: row,
					value: row[0],
					result: options.formatResult && options.formatResult(row, row[0]) || row[0]
				};
			}
		}
		return parsed;
	}

	function stopLoading() {
		$input.removeClass(options.loadingClass);
	}

}

jQuery.Autocompleter.defaults = {
	inputClass: "ac_input",
	resultsClass: "ac_results",
	loadingClass: "ac_loading",
	minChars: 1,
	delay: 400,
	matchCase: false,
	matchSubset: true,
	matchContains: false,
	cacheLength: 10,
	mustMatch: false,
	extraParams: {},
	selectFirst: true,
	max: 10,
	moreItems: "&#x25be;&#x25be;&#x25be; more &#x25be;&#x25be;&#x25be;",
	//size: 10,
	autoFill: false,
	width: 0,
	multiple: false,
	multipleSeparator: ", ",
	highlight: function(value, term) {
		return value.replace(new RegExp("(?!<[^<>]*)(" + term + ")(?![^<>]*>)", "gi"), "<strong>$1</strong>");
	}
};

jQuery.Autocompleter.Cache = function(options) {

	var data = {};
	var length = 0;
	
	function matchSubset(s, sub) {
		if (!options.matchCase) 
			s = s.toLowerCase();
		var i = s.indexOf(sub);
		if (i == -1) return false;
		return i == 0 || options.matchContains;
	};
	
	function add(q, value) {
		if (length > options.cacheLength){
			flush();
		}
		if (!data[q]){ 
			length++;
		}
		data[q] = value;
	}
	
	function populate(){
		if( !options.data ) return false;
		// track the matches
		var stMatchSets = {},
			nullData = 0;

		// no url was specified, we need to adjust the cache length to make sure it fits the local data store
		if( !options.url ) options.cacheLength = 1;
		
		// track all options for minChars = 0
		stMatchSets[""] = [];
		
		// loop through the array and create a lookup structure
		jQuery.each(options.data, function(i, rawValue) {
			// if row is a string, make an array otherwise just reference the array
			
			var value = options.formatItem
				? options.formatItem(rawValue, i+1, options.data.length)
				: rawValue;
			if ( value === false )
				return;
				
			var firstChar = value.charAt(0).toLowerCase();
			// if no lookup array for this character exists, look it up now
			if( !stMatchSets[firstChar] ) 
				stMatchSets[firstChar] = [];

			// if the match is a string
			var row = {
				value: value,
				data: rawValue,
				result: options.formatResult && options.formatResult(rawValue) || value
			}
			
			// push the current match into the set list
			stMatchSets[firstChar].push(row);

			// keep track of minChars zero items
			if ( nullData++ < options.max ) {
				stMatchSets[""].push(row);
			}
		});

		// add the data items to the cache
		jQuery.each(stMatchSets, function(i, value) {
			// increase the cache size
			options.cacheLength++;
			// add to the cache
			add(i, value);
		});
	}
	
	// populate any existing data
	populate();
	
	function flush(){
		data = {};
		length = 0;
	}
	
	return {
		flush: flush,
		add: add,
		populate: populate,
		load: function(q) {
			if (!options.cacheLength || !length)
				return null;
			/* 
			 * if dealing w/local data and matchContains then we must make sure
			 * to loop through all the data collections looking for matches
			 */
			if( !options.url && options.matchContains ){
				// track all matches
				var csub = [];
				// loop through all the data grids for matches
				for( var k in data ){
					// don't search through the stMatchSets[""] (minChars: 0) cache
					// this prevents duplicates
					if( k.length > 0 ){
						var c = data[k];
						jQuery.each(c, function(i, x) {
							// if we've got a match, add it to the array
							if (matchSubset(x.value, q)) {
								csub.push(x);
							}
						});
					}
				}				
				return csub;
			} else 
			// if the exact item exists, use it
			if (data[q]){
				return data[q];
			} else
			if (options.matchSubset) {
				for (var i = q.length - 1; i >= options.minChars; i--) {
					var c = data[q.substr(0, i)];
					if (c) {
						var csub = [];
						jQuery.each(c, function(i, x) {
							if (matchSubset(x.value, q)) {
								csub[csub.length] = x;
							}
						});
						return csub;
					}
				}
			}
			return null;
		}
	};
};

jQuery.Autocompleter.Select = function (options, input, select) {
	var CLASSES = {
		ACTIVE: "ac_over"
	};
	
	// Create results
	var element = jQuery("<div>")
		.hide()
		.addClass(options.resultsClass)
		.css("position", "absolute")
		.appendTo("body");
	
	var list = jQuery("<ul>").appendTo(element).mouseover( function(event) {
		active = jQuery("li", list).removeClass().index(target(event));
		jQuery(target(event)).addClass(CLASSES.ACTIVE);
	}).mouseout( function(event) {
		jQuery(target(event)).removeClass();
	}).click(function(event) {
		jQuery(target(event)).addClass(CLASSES.ACTIVE);
		select();
		input.focus();
		return false;
	});
	var listItems,
		active = -1,
		data,
		term = "";
		
	if( options.moreItems.length > 0 ) 
		var moreItems = jQuery("<div>")
			.addClass("ac_moreItems")
			.css("display", "none")
			.html(options.moreItems)
			.appendTo(element);
		
	if( options.width > 0 )
		element.css("width", options.width);
		
	function target(event) {
		var element = event.target;
//		while(element.tagName != "LI") // BY A5
//			element = element.parentNode;
		if (element.tagName == "STRONG")
			element = element.parentNode;
		return element;
	}

	function moveSelect(step) {
		active += step;
		wrapSelection();
		listItems.removeClass().eq(active).addClass(CLASSES.ACTIVE);
	};
	
	function wrapSelection() {
		if (active < 0) {
			active = listItems.size() - 1;
		} else if (active >= listItems.size()) {
			active = 0;
		}
	}
	
	function limitNumberOfItems(available) {
		return (options.max > 0) && (options.max < available)
			? options.max
			: available;
	}
	
	function fillList() {
		list.empty();
		var num = limitNumberOfItems(data.length);
		for (var i=0; i < num; i++) {
			if (!data[i])
				continue;
			
			var formatted = options.formatItem ? options.formatItem(data[i].data, i+1, num, data[i].value) : data[i].value;
			if ( formatted === false )
				continue;
			
			jQuery("<li>").html( options.highlight(formatted, term) ).appendTo(list)[0].index = i;
		}
		listItems = list.find("li");
		if ( options.selectFirst ) {
			listItems.eq(0).addClass(CLASSES.ACTIVE);
			active = 0;
		}
		if( options.moreItems.length > 0 ) moreItems.css("display", (data.length > num)? "block" : "none");
		list.bgiframe();
	}
	
	return {
		display: function(d, q) {
			data = d;
			term = q;
			fillList();
		},
		next: function() {
			moveSelect(1);
		},
		prev: function() {
			moveSelect(-1);
		},
		hide: function() {
			element.hide();
			active = -1;
		},
		visible : function() {
			return element.is(":visible");
		},
		current: function() {
			return this.visible() && (listItems.filter("." + CLASSES.ACTIVE)[0] || options.selectFirst && listItems[0]);
		},
		show: function() {
			element.css({
				width: typeof options.width == "string" || options.width > 0 ? options.width : jQuery(input).width()
				//height: jQuery(listItems[0]).height() * options.size,
			}).below(input).show();
		},
		selected: function() {
			return data && data[ listItems.filter("." + CLASSES.ACTIVE)[0].index ];
		}
	};
}

jQuery.Autocompleter.Selection = function(field, start, end) {
	if( field.createTextRange ){
		var selRange = field.createTextRange();
		selRange.collapse(true);
		selRange.moveStart("character", start);
		selRange.moveEnd("character", end);
		selRange.select();
	} else if( field.setSelectionRange ){
		field.setSelectionRange(start, end);
	} else {
		if( field.selectionStart ){
			field.selectionStart = start;
			field.selectionEnd = end;
		}
	}
	field.focus();
};


/* Copyright (c) 2006 Brandon Aaron (http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * $LastChangedDate: 2007-03-19 16:02:41 +0100 (Mo, 19 Mrz 2007) $
 * $Rev: 1546 $
 */
(function($){$.fn.bgIframe=jQuery.fn.bgiframe=function(s){if(!($.browser.msie&&typeof XMLHttpRequest=='function'))return this;s=$.extend({top:'auto',left:'auto',width:'auto',height:'auto',opacity:true,src:'javascript:false;'},s||{});var prop=function(n){return n&&n.constructor==Number?n+'px':n;},html='<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+s.src+'"style="display:block;position:absolute;z-index:-1;'+(s.opacity!==false?'filter:Alpha(Opacity=\'0\');':'')+'top:'+(s.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(s.top))+';left:'+(s.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(s.left))+';width:'+(s.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(s.width))+';height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(s.height))+';"/>';return this.each(function(){if(!$('iframe.bgiframe',this)[0])this.insertBefore(document.createElement(html),this.firstChild);});};})(jQuery);

/**
 *
 * Copyright (c) 2007 Sam Collett (http://www.texotela.co.uk)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 */

 
/**
 * Places selected element under another one
 *
 * @name     below
 * @name     element Which element to place the current one under
 * @param    options Hash with the following options:
 *                   adjustRight   How many pixels to adjust right by
 *                   adjustDown    How many pixels to adjust down by
 * @author   Sam Collett (http://www.texotela.co.uk)
 * @example  $("#mytip").below("#myinput");
 * @example  $("#mytip").below("#myinput", {adjustRight: 10});
 */
jQuery.fn.below = function(element, options)
{
	element = element || null;
	options = jQuery.extend({adjustRight: 0, adjustDown: 0}, options);
	return this.each(
		function()
		{
			if(element == null) return false;
			var what = jQuery(element);
			var left = what[0].offsetWidth - options.adjustRight, top = what[0].offsetHeight + options.adjustDown;
			if(jQuery.browser.opera)
			{
				var version = navigator.userAgent.match(/\d+\.\d+/);
				if(version < 9)
				{
					left += (parseInt(jQuery.css(what[0], 'borderLeftWidth'))  || 0) +
						(parseInt(jQuery.css(what.parent()[0], 'paddingLeft'))  || 0);
				}
			}
			what.after(this);
			jQuery(this).css(
				{
					position: "absolute",
					display: "inline",
					marginLeft: "-" + left  + "px",
					marginTop: top + "px"
				}
			);
		}
	);
}

