// set static-host if needed
var uiStaticHost = "//static.gmx.net/current/de/";
if (window.location.href.indexOf("gmx")!=-1) {
	uiStaticHost = "//static.gmx.net/current/de/";
} else if (window.location.href.indexOf("web")!=-1) {
	uiStaticHost = "//static.web.de/current/de/";
} else if (window.location.href.indexOf("1und1")!=-1) {
	uiStaticHost = "//static.1und1/current/de/";
}
if (window.location.href.indexOf("capa")!=-1 || window.location.href.indexOf("cms.gmx.net")!=-1) {
	uiStaticHost = "//gmx.capa-test007.v300.gmx.net/current/de/";
}

function Counter(piPixel, ivwPixel, pixelboxPixel, webdePiPixel, alternatePixel) {
  this.piPixel = piPixel;
  this.ivwPixel = ivwPixel;
  this.pixelboxPixel = pixelboxPixel;
  if(typeof alternatePixel == 'undefined') {
      this.alternatePixel = '';
  } else {
	  this.alternatePixel = alternatePixel;
  }
  if(typeof webdePiPixel == 'undefined'){
      this.webdePiPixel = '';
  } else {
      this.webdePiPixel = webdePiPixel;
  }
}

Counter.prototype.randomize = function(pixel){
  var rand = Math.floor(Math.random()*600000);
  if (pixel.indexOf("&") != -1 || pixel.indexOf("?") != -1) {
    pixel+="&";
  } else  {
    pixel+="?";
  }
  return pixel+="ts="+rand;
}

Counter.prototype.countClick = function(ccPixel){
  if(ccPixel !=''){
    var ccImage = new Image();
    ccImage.src = this.randomize(ccPixel);
  }
}

Counter.prototype.countPI = function(){
  if(this.piPixel !=''){
    var piImage = new Image();
    piImage.src = this.randomize(this.piPixel);
  }
  if(this.ivwPixel !=''){
    var ivwImage = new Image();
    ivwImage.src = this.randomize(this.ivwPixel);
  }
  if(this.pixelboxPixel !=''){
    var pixelboxImage = new Image();
    pixelboxImage.src = this.randomize(this.pixelboxPixel);
  }
  if(this.webdePiPixel !=''){
    var webdePiPixelImage = new Image();
    webdePiPixelImage.src = this.randomize(this.webdePiPixel);
  }
  if(this.alternatePixel !=''){
	var alternatePixelImage = new Image();
	alternatePixelImage.src = this.randomize(this.alternatePixel);
  }
}

Counter.prototype.countAll = function(ccPixel){
  this.countClick(ccPixel);
  this.countPI();
}

function slideshow(url) {
  swpopup = window.open(url,'slideshow','width=640,height=480,resizable=no,status=no');
  if (window.swpopup) {
    window.swpopup.focus();
  }
}

function imagepopup(url) {
  imgpopup = window.open(url,'imgpopup','width=640,height=480,resizable=no,status=no');
  if (window.imgpopup) {
    window.imgpopup.focus();
  }
}

// wrapper for portalpopupportalpopup without returnvalue
function videoStreamPopup(url, windowname, style, returncode) {
	videopopup = portalPopup(url, windowname, style, returncode);
}

function blowUpToFullScreen(url, windowname) {
	var fs = window.open(url, windowname, "toolbar=no,width=" + screen.availWidth  + ",height=" + screen.availHeight + ",status=no,resizable=yes,fullscreen=yes,scrollbars=no");
	fs.focus();
}

/*
* overload this functions to get other sizes
*/
function getVideoWidth(width) {
    return width;
}

function getVideoHeight(width, height) {
	return height;
}

function submitVoting(vtid,link,formname) {
  var answer = "";
  if (answers = document.getElementById("voting"+vtid).answer[0]) {
    answers = document.getElementById("voting"+vtid).answer;
    for (var i=0; i<answers.length; i++)
      if ((answers[i].checked) && (answer == ""))
        answer = '?answer='+answers[i].value;
  }
  document.getElementById("voting"+vtid+"poll").style.display = "none";
  document.getElementById("voting"+vtid+"poll").style.visibility = "hidden";
  document.getElementById("voting"+vtid+"done").style.display = "block";
  document.getElementById("voting"+vtid+"done").style.visibility = "visible";
  showVotingResult(vtid,link+answer);
}

function showVotingResult(vtid,link) {
  vtpopup = window.open(link,'voting','resizable=no,width=505,height=425,scrollbars=no');
  if (window.vtpopup) {
    window.vtpopup.focus();
  }
}

function portalPopup(url, windowname, style, returncode) {
	var cwin = window.open(url, windowname, style);
	if (window.focus) {
	  cwin.focus();
	}
	if (returncode == "false") {
	  return false;
	}
	else if ((returncode == true) || (returncode == "true")) {
		return true;
	}
}

// constructor
function FormDataReader() {
    this.data = new Array();
}

// reads the form data and writes them into an array
FormDataReader.prototype.read = function(formObj) {
    this.data["action"] = formObj.action;
    for(i=0; i<formObj.elements.length; i++) {
        el = formObj.elements[i];
        switch(el.type) {
            case "radio":           if(el.checked) {
                                        this.data[el.name] = el.value;
                                    }
                                    break;

            case "checkbox":        var arrName = el.name.replace(/\[\]/, '');
                                    if(!this.data[arrName]) this.data[arrName] = new Array();
                                    if(el.checked) {
                                        this.data[arrName][this.data[arrName].length] = el.value;
                                    }
                                    break;

            case "select-one":      this.data[el.name] = el.value;
                                    break;

            case "select-multiple": var arrName = el.name.replace(/\[\]/, '');
                                    if(!this.data[arrName]) this.data[arrName] = new Array();
                                    for(k=0; k<el.options.length; k++) {
                                        if(el.options[k].selected) {
                                            this.data[arrName][this.data[arrName].length] = el.options[k].value;
                                        }
                                    }
                                    break;

            //case "submit":          break;

            case "reset":           break;

            case "password":        this.data[el.name] = el.value;

            default:                this.data[el.name] = el.value;
        }
    }
}


// constructor
function GetStringBuilder() {
    this.urlString = '';
}

// builds and returns a GET string
// expects associative array
GetStringBuilder.prototype.getUrlString = function(data, suppressEmptyFields) {

    this.urlString += data["action"];

    var count = 0;

    if (this.urlString.indexOf("?")>0) count++;

    for(el in data) {
        if(el == "action") {
            continue;
        }
        if(data[el] == '') {
            if(suppressEmptyFields) {
                continue;
            } else {
                this.urlString += (count == 0)? '?' : '&';
                this.urlString += el + '=';
            }
        }
        if(data[el].match && data[el].match(/\w+/)) {
            this.urlString += (count == 0)? '?' : '&';
            this.urlString += el + '=' + encodeURI(data[el]);
        } else {
            for(k=0; k<data[el].length; k++) {
                this.urlString += (count == 0)? '?' : '&';
                this.urlString += el + '=' + encodeURI(data[el][k]);
            }
        }
        count++;
    }
    return this.urlString;
}

function processForm(formObj, name, style) {
    myFormDataReader    = new FormDataReader();
    myGetStringBuilder  = new GetStringBuilder();
    myFormDataReader.read(formObj);

    var popup = window.open(myGetStringBuilder.getUrlString(myFormDataReader.data, true), name, style);
    return false;
}

// ---------- FOR AC-Player
function setBandwidthCheck(bw){
	// store bw in Cookie
        var cookieTime = 1000 * 60 * 60 * 24 * 365;
      	var jetzt = new Date();
      	var Auszeit = new Date(jetzt.getTime() + cookieTime);
      	document.cookie = "Bandwidth=" + bw + "; expires=" + Auszeit.toGMTString() + ";";
}


// ---------- FLASH-DETECTION

// Flash Player Version Detection - Rev 1.5
// Detect Client Browser type
// Copyright(c) 2005-2006 Adobe Macromedia Software, LLC. All rights reserved.
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

function ControlVersion()
{
	var version;
	var axo;
	var e;

	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry

	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {
	}

	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");

			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful.

			// default to the first public version
			version = "WIN 6,0,21,0";

			// throws if AllowScripAccess does not exist (introduced in 6.0r47)
			axo.AllowScriptAccess = "always";

			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");

		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}

	return version;
}

// JavaScript helper required to detect Flash Player PlugIn version information
function GetSwfVer(){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;

	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
			var versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( isIE && isWin && !isOpera ) {
		flashVer = ControlVersion();
	}
	return flashVer;
}

// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
	versionStr = GetSwfVer();
	if (versionStr == -1 ) {
		return false;
	} else if (versionStr != 0) {
		if(isIE && isWin && !isOpera) {
			// Given "WIN 2,0,0,11"
			tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
			tempString        = tempArray[1];			// "2,0,0,11"
			versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
		} else {
			versionArray      = versionStr.split(".");
		}
		var versionMajor      = versionArray[0];
		var versionMinor      = versionArray[1];
		var versionRevision   = versionArray[2];

        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
		if (versionMajor > parseFloat(reqMajorVer)) {
			return true;
		} else if (versionMajor == parseFloat(reqMajorVer)) {
			if (versionMinor > parseFloat(reqMinorVer))
				return true;
			else if (versionMinor == parseFloat(reqMinorVer)) {
				if (versionRevision >= parseFloat(reqRevision))
					return true;
			}
		}
		return false;
	}
}

// ------ FLASH ENDS

// GMX functions
function faq_gmx(nav) {
  faq = window.open("http://faq.gmx.de/" + nav ,"faq_gmx", "resizable=yes,width=700,height=500,scrollbars=yes");
  if (window.faq) {
    window.faq.focus();
  }
}
// GMX functions ENDS

// 1und1 functions
var	popupCounter = 1;
var	infoPopups = new Array();

function infoPopup(page, width, height, scrollbars, resizable) {
  if(typeof resizable == 'undefined')
    resizable = 'no';

  var pName	 = "Popup_1und1_"+popupCounter;
  var params = "width="+width+",height="+height+",location=no,menubar=no,resizable=no,scrollbars="+scrollbars+",status=yes,toolbar=no,resizable="+resizable;

  infoPopups = window.open(page, pName, params);
  popupCounter++;
}



// Function for Advisor

function switchTabTool(showDiv, hideDiv, showClass, hideClass) {
	// switch divs
	poma.dom.$id(showDiv).style.display = "block";
	poma.dom.$id(hideDiv).style.display = "none";
	// switch classes
	poma.dom.$id("tab-" + showDiv).className = showClass;
	poma.dom.$id("tab-" + hideDiv).className = hideClass;
	poma.dom.$id("link-" + showDiv).className = "active";
	poma.dom.$id("link-" + hideDiv).className = "";
}


//Social Bookmarks

//Show
function showSB(div) {
	poma.dom.$id(div).style.display = 'block';
}

//Hide
function hideSB(div) {
	poma.dom.$id(div).style.display = 'none';
}



/* #MOD - AdRefresh */

var adRefresh = new Object;

adRefresh.init = function(mandatory) {
	//set some variables
	adRefreshTimeout = false;
	seconds = 3;
	changeTopBanner = true;
	recheck = true;
	advSky =$ui('#adv-sky');
	advTop =$ui('#adv-aux');
	adTopPos = 220;

	switch(mandatory) {
		case 'gmx':
			adLeftPos = 10;
		break;
		case 'webde':
			adLeftPos = 10;
		break;
		case '1und1':
			adLeftPos = 15;
		break;
		default:
			adLeftPos = 10;
		break;
	}
}

adRefresh.refresh = function(adRefresh) {

	var adr = new Array();
	adr['url']	= "//adclient.uimserv.net/html.ng/";
	adr['params-top']	= "adrefresh_1&params.styles=adrefresh_top_html,adrefresh_top_img";  //notwendig
	adr['params-sky']	= "adrefresh_1&params.styles=adrefresh_sky_html,adrefresh_sky_img";  //notwendig

	if(adRefresh=="adRefresh") {
		if(!adRefreshTimeout) {
			// Delete all Markup in #adv-sky
			advSky.removeAttr("style");
			advSky.empty();

			// Build URL
			var skySrc = adr['url'];
			skySrc = skySrc + 'site=' + ad_cl + '&special=sky&adsize=120x600&adsize=160x600&adsize=300x600&adsize=320x600&section=' + ad_sc +'/&pageview=' + ad_partner + '&pageview=ng_outer&tile=' + ad_ts + '&pp=' + ad_pp + '&pa=' + ad_pa + '&pg=' + ad_pg + '&pageview=' + ad_eros + '&category=' + ad_cat + '&ag=' + ad_ag + '&cc=' + ad_cc + '&pageview=' + adr['params-sky'];

			// Append iFrame Sky
			advSky.append('<iframe id="adrefresh" frameborder="0" scrolling="no">dont support frames</iframe>');
			advSkyFrame = $ui('iframe#adrefresh');
			advSkyFrame.attr('src', skySrc);
			advSkyFrame.attr('height', '800');
			advSkyFrame.attr('width', '300');
			advSkyFrame.attr('marginheight', '0');
			advSkyFrame.attr('marginwidth', '0');
			advSkyFrame.attr('style', 'margin: 0;');

			// Position AD for IE6
			if(jQuery.browser.msie && jQuery.browser.version < 7) { //Todo: If updating jQuery to 1.3.x this is deprecated
				var scrollTop = $ui(window).scrollTop();
				if(scrollTop > adTopPos) {
					var pos = scrollTop - adTopPos;
					$ui('iframe#adrefresh').css({
						"position" : "absolute",
						"top" : pos + "px"
					});
				}
			}

			// Change Top Banner (only first time)
			if(changeTopBanner) {
				// Delete all Markup in #adv-aux
				advTop.removeAttr("style");
				advTop.empty();

				//Build URL
				var topSrc = adr['url'];
				topSrc = topSrc + 'site=' + ad_cl + '&special=top&adsize=728x90&adsize=468x60&adsize=778x90&section=' + ad_sc +'/&pageview=' + ad_partner + '&pageview=ng_outer&tile=' + ad_ts + '&pp=' + ad_pp + '&pa=' + ad_pa + '&pg=' + ad_pg + '&pageview=' + ad_eros + '&category=' + ad_cat + '&ag=' + ad_ag + '&cc=' + ad_cc + '&pageview=' + adr['params-top'];

				// Append iFrame Top
				advTop.append('<iframe id="adrefresh-top" frameborder="0" scrolling="no">dont support frames</iframe>');
				advTopFrame = $ui('iframe#adrefresh-top');
				advTopFrame.attr('src', topSrc);
				advTopFrame.attr('height', '90');
				advTopFrame.attr('width', '728');
				advTopFrame.attr('marginheight', '0');
				advTopFrame.attr('marginwidth', '0');

				changeTopBanner = false;

				// Checking the Scroll Position will be not done in IE6
				if(!(jQuery.browser.msie && jQuery.browser.version < 7)) { //Todo: If updating jQuery to 1.3.x this is deprecated
					this.checkScrollPosition();
					//adRefresh.checkScrollPosition();
				}
			}

			adRefreshTimeout = true;
			setTimeout('adRefreshTimeout = false', seconds * 1000);
		}
	}
}

adRefresh.checkScrollPosition = function() {
	if (this.recheckTimeout) {
		clearTimeout(this.recheckTimeout);
		this.recheckTimeout = null;
	}

	var scrollTop = $ui(window).scrollTop();
	if(jQuery.browser.mozilla) { //Todo: If updating jQuery to 1.3.x this is deprecated
		if(scrollTop > adTopPos) {
			$ui('#adv-sky').css({
				"position" : "fixed",
				"top" : "10px",
				"left" : "833px"
			});
		} else {
			var topPosition = adTopPos + 10 - scrollTop
			$ui('#adv-sky').css({
				"position" : "fixed",
				"top" : topPosition + "px",
				"left" : "833px"
			});
		}
	} else {
		if(scrollTop > adTopPos) {
			$ui('#adv-sky').css({
				"position" : "fixed",
				"top" : "10px",
				"left" : "833px"
			});
		} else {
			$ui('#adv-sky').css({
				"position" : "absolute",
				"top" : "10px",
				"left" : "825px"
			});
		}
	}

	if (!this.reCheck) {
		this.recheckTimeout = setTimeout("adRefresh.checkScrollPosition();", 100);
	}
}


function countAndRefresh() {
	//do something
	adRefresh.refresh("adRefresh");
	counter.countPI();
}



/* #MOD ----- Star Rating ----- */


var starRating = new Object;

starRating.init = function(ratingId, serviceUrl) {

	// Some variables
	ratingUrl = serviceUrl;
	alreadyVoted = false;

	// Build markup
	$ui("#stars").empty();
	$ui("#stars").css("opacity", "1.0");
	for(var i=0; i<5; i++) {
		$ui("#stars").append("<span></span>");
	}

	// Get rating and animate Stars
	starRating.rate.getRating(ratingId);


	$ui('#stars span').each(
		function eachSpan(i) {
			var j = i+1;
			$ui(this).bind("mouseover", function() {
				starRating.rate.animateStars(j);
			});

			$ui(this).bind("mouseout", function() {
				starRating.rate.animateStars(average);
			});

			$ui(this).bind("click", function() {
				starRating.rate.setRating(ratingId, j);
			});
		}
	);
}

starRating.rate = {

	//animate
	animateStars: function(i) {
		switch(i) {
			case 0: $ui('#stars').removeClass();
					$ui('#stars').addClass("rating-0");
			break;
			case 1: $ui('#stars').removeClass();
					$ui('#stars').addClass("rating-1");
			break;
			case 2: $ui('#stars').removeClass();
					$ui('#stars').addClass("rating-2");
			break;
			case 3: $ui('#stars').removeClass();
					$ui('#stars').addClass("rating-3");
			break;
			case 4: $ui('#stars').removeClass();
					$ui('#stars').addClass("rating-4");
			break;
			case 5: $ui('#stars').removeClass();
					$ui('#stars').addClass("rating-5");
			break;
		}
	},

	//rating
	getRating: function(ratingId) {
		$ui.ajax({
			type: "GET",
			url: ratingUrl,
			data: "method=getRating&ratingId=" + ratingId,
			dataType: "json",
			success: function(jsonData) {
				average = jsonData.starRating.ratingCountAverage;
				if(average == 0) { average = 3; }
				starRating.rate.animateStars(average);
			},
			error: function(msg) {
				average = 0;
				$ui("#stars").css("opacity", "0.5");
			}
		});
	},

	setRating: function(ratingId, ratingCount) {
		if(!alreadyVoted) {
			$ui.ajax({
				type: "GET",
				url: ratingUrl,
				data: "method=setRating&ratingId=" + ratingId + "&ratingCount=" + ratingCount,
				dataType: "json",
				success: function(jsonData){
					alreadyVoted = true;
					average = jsonData.starRating.ratingCountAverage;
					$ui("div#stars").after('<span class="txt response">Bewertung gespeichert</span>');
					$ui("#stars span").unbind();
					$ui("#stars span").css("cursor", "default");
					starRating.rate.animateStars(ratingCount);
				},
				error: function(message) {
					average = 0;
					$ui("#stars").css("opacity", "0.5");
					starRating.rate.getRating(ratingId);
				}
			});
		}
	}

}
// functions ENDS


// Top-Search
var portalSearch = new Object();

portalSearch.init = function(selector) {
	var input = $ui(selector);
	var def = "";
	this.text = "";
	input.val(def);
	input.addClass("def");
	input.bind("focus", function() {
		focus(input);
	});
	input.bind("blur", function() {
		blur(input);
	});
	function focus(input) {
		input.removeClass("def");
	};
	function blur(input) {
		if (input.val() == def) {
			input.addClass("def");
		}
	};
};

portalSearch.prepare = function(form, webSearchCheckboxValue, siteSearchCheckboxValue, valueWebRb, searchActionUrlAT, searchActionUrlCH) {
	var hostFieldWeb = form.elements["host"][0];
	var hostFieldDomain = form.elements["host"][1];
	var mcField = form.elements["mc"];
	form.elements["origin"].value = "magazin";

	if (hostFieldWeb.checked) {
		mcField.value = webSearchCheckboxValue;
		form.elements["webRb"].value = "";
	} else if (hostFieldDomain.checked) {
		mcField.value = siteSearchCheckboxValue;
		form.elements["webRb"].value = valueWebRb;
	}

	if (ipInfo == 'AT') {
		form.action = searchActionUrlAT;
	}
	if (ipInfo == 'CH') {
		form.action = searchActionUrlCH;
	}

    // GMX-Logout needs a special Counting-Parameter
	if (webSearchCheckboxValue.indexOf("logout") != -1 && form.action.indexOf("gmx") != -1) {
		if (form.elements["origin"]) form.elements["origin"].value = "FM_logout";
	}

	// empty the search-input, if there is still the default entered
	if (form.elements["su"].value == this.def) form.elements["search"].value = "";

	return true;
}

portalSearch.prepareBtm = function(form, webSearchCheckboxValue, siteSearchCheckboxValue, valueWebRb, searchActionUrlAT, searchActionUrlCH) {
	var hostFieldWeb = false, hostFieldDomain = false;
	if($ui('#search-domain-btm').val() != "") {
		hostFieldDomain = true;
	} else {
		hostFieldWeb = true;
	}
	var mcField = form.elements["mc"];
	form.elements["origin"].value = "unddu";

	if (hostFieldWeb == true) {
		mcField.value = webSearchCheckboxValue;
		form.elements["webRb"].value = "";
	} else if (hostFieldDomain == true) {
		mcField.value = siteSearchCheckboxValue;
		form.elements["webRb"].value = valueWebRb;
	}

	if (ipInfo == 'AT') {
		form.action = searchActionUrlAT;
	}
	if (ipInfo == 'CH') {
		form.action = searchActionUrlCH;
	}

    // GMX-Logout needs a special Counting-Parameter
	if (webSearchCheckboxValue.indexOf("logout") != -1 && form.action.indexOf("gmx") != -1) {
		if (form.elements["origin"]) form.elements["origin"].value = "FM_logout";
	}

	// empty the search-input, if there is still the default entered
	if (form.elements["su"].value == this.def) form.elements["search"].value = "";

	return true;
}
// Top-Search END

/* Browser-Topper
 * This ads a so-called "topper" to all magazine-pages, if someone has an "old" browser, showing the download to a newer version
 * NOTE: ONLY FOR GMX
 */
var Topper = new function() {
	this.ua = {
		ie: (document.all && !window.opera) ? ((typeof(window.XMLHttpRequest) == 'object') ?
											   (typeof(window.maxConnectionsPerServer) == 'number' ? 8 : 7) : 6) : 0,
		ff: typeof(window.external) == 'object' && typeof(document.evaluate) == 'function' ?
			(typeof(window.postMessage) == 'function' ? (typeof(window.localStorage) == 'object' ? 3.5 : 3) : 2) : 0,
		opera: window.opera ? 9 : 0,
		chrome: window.chrome ? 1 : 0,
		safari: typeof(window.openDatabase) == 'function' ? 3 : 0
	};
	this.fill = function(ad) {
		if (!this.content[ad] || !this.content[ad].url || !this.content[ad].text) { return false; }
		this.contentdiv.innerHTML = '<a href="" onclick="Topper.slide(); return false;" style="background: url(' + uiStaticHost + 'images/temp/topper/bg-movein-close.gif) no-repeat 0 50%; color: #888888; font: bold 11px Verdana,Arial,Helvetica,sans-serif; float: right; font-weight: 700; line-height: 27px; padding-left: 24px;"><span>Schlie&szlig;en</span></a></div>'+
									'<span style="float: left; padding: 4px 84px 0 0;"><img height="16" width="16" style="position: relative; top: 3px;" alt="" src="' + uiStaticHost + 'images/temp/topper/icon-info-16x16.gif"/></span>'+
									'<p style="float: left; line-height: 27px; height: 27px;"><a onclick="Topper.slide(); return true;" href="'+this.content[ad].url+'" style="font: bold 11px Verdana,Arial,Helvetica,sans-serif; color: #000000; text-decoration: none;">'+this.content[ad].text+'</a>'+
									'<a onclick="Topper.slide(); return true;" href="'+this.content[ad].url+'" style="font: bold 11px Verdana,Arial,Helvetica,sans-serif; line-height: 27px; text-decoration: underline;"><span>'+this.content[ad].dltext+'</span></a></p><img src="' + uiStaticHost + 'images/temp/topper/bg-movein-buster-right.gif" style="position: absolute; right: 0px; top: 20px; z-index: 9;" />';
		return true;
	}

	// Initialisieren
	this.init = function(options) {
		if (window.location.host.indexOf("gmx.net") != -1) {
			if (window.location.host.indexOf("capa-test") != -1) { return; }
			if (document.cookie.indexOf("ui_magazine=topper") != -1) { return; }
			if (!options || !options.content | typeof(options.choice) != 'function') { return; }
			this.content = options.content;
			this.choice = options.choice();
			if (this.choice) {
				document.cookie = "ui_magazine=topper;path=/;";
				this.topperdiv = document.createElement('div');
				this.topperdiv.style.backgroundColor = '#E3EDFA';
				this.topperdiv.style.height = '0px';
				this.topperdiv.style.overflow = 'hidden';
				this.topperdiv.style.position = 'relative';
				this.topperdiv.style.width = (options.width || 825)+'px';
				var body = document.getElementsByTagName('body')[0];
				body.insertBefore(this.topperdiv, body.firstChild);
				var innerdivW = (parseInt(this.topperdiv.style.width) - 33) + "px";
				this.topperdiv.innerHTML = '<div style="background: url(' + uiStaticHost + 'images/temp/topper/bg-movein-buster-left.gif) no-repeat 0px 20px; bottom: 0px; height: 29px; margin-right: 10px; position: absolute; padding: 20px 10px 0; left: 10px; width: ' + innerdivW + '"></div>';
				this.contentdiv = this.topperdiv.getElementsByTagName('div')[0];
				if (!this.fill(this.choice)) { return; };
				window.setTimeout("Topper.slide(true)", options.timeout);
				if (options.ivwurl) {
					(new Image()).src = options.ivwurl.replace(/\<ivwid\>/g, (this.content[this.choice].ivwid || this.choice)).replace(/\<ts\>/g, (new Date()*1));
				}
			}
		}
	}
	this.pos = 0;
	this.step = this.ua.msie ? 5 : 2;
	this.slide = function(show) {
		Topper.showInterval = window.setInterval(function(show) { return function() {
			var pos = (Topper.pos += (show ? 1 : -1) * Topper.step);
			if (pos < 0 || pos > 39) {
				Topper.topperdiv.style.height = (show ? '39px' : '0px');
				window.clearInterval(Topper.showInterval);
				return;
			}
			Topper.topperdiv.style.height = Math.max(0,Topper.pos)+'px';
		}}(show), 15);
	};
}
// Browser-Topper END

// additional loading and init of functions
if (typeof $ui == "function") {
	$ui(document).ready(function() {
		// Adrefresh
		if(window.location.href.indexOf("gmx") != -1) {
			adRefresh.init("gmx");
		} else if(window.location.href.indexOf("web") != -1) {
			adRefresh.init("webde");
		} else if(window.location.href.indexOf("1und1") != -1) {
			adRefresh.init("1und1");
		}

		// lightbox
		$ui(function() {
			$ui("a[rel*=lightbox]").lightBox(); // Select all links that contains lightbox in the attribute rel
		});
		$ui("div.image a[rel*=lightbox]").css("display", "block");

		// Top-Search
		portalSearch.init("#nav-top-bin #search");
		portalSearch.init("#ntb-search-input-btm #search-btm");


		// Games Teaser
		if($ui(".overlay > span.play").length > 0) {
			$ui("span.play").bind("mouseover mouseout", function() {
				$ui(this).toggleClass("over");
			});
		}

		// Browser-Topper - NOTE: ONLY FOR GMX
		Topper.init({
			content: {
				ff: {
					url: 'http://service.gmx.net/de/cgi/g.fcgi/products/browser?mc=logout@home@topper@browser_ffm',
					text: 'Besser und schneller im Web mit dem neuen Mozilla Firefox - ',
					dltext: 'jetzt downloaden!',
					ivwid: 'mff'
				},
				ie: {
					url: 'http://service.gmx.net/de/cgi/g.fcgi/products/browser?mc=logout@home@topper@browser_IE8',
					text: 'Sicherer, schneller und einfacher: Der neue Internet Explorer 8 - ',
					dltext: 'jetzt downloaden!'
				},
				ie8: {
					url: 'http://service.gmx.net/de/cgi/g.fcgi/products/browser?mc=logout@home@topper@browser_IE8OEM',
					text: 'Der Internet Explorer 8 von GMX - inkl. der beliebten GMX Vorteile: ',
					dltext: 'hier downloaden!',
					ivwid: 'ieoem'
				}
			},
			choice: function() { return (
				(!window.noTopper && !Topper.ua.safari && ((Topper.ua.ie < 8 || (Topper.ua.ie == 8 && !/(WEB.DE|GMX)/.test(navigator.userAgent))) && Topper.ua.ff < 3.5)) ?
				(Topper.ua.ie ? 'ie'+(Topper.ua.ie == 8 ? '8' : '') : 'ff')
				: false);
			},
			width: 823,
			timeout: 1000,
			ivwurl: '//img.web.de/ivw/SP/gmx_hp/logoutlounge/advtopper/browser/<ivwid>?ts=<ts>'
		});
	});
}

/* Handle Formular Labels
 * Never pass the action- and stop-params, if using this function!
 * If you don't know the defaultColor, just leave it empty.
 */
function handleFormLabel(id, defaultVal, defaultColor, color, action, stop) {
	var formFieldSel = $ui("#" + id);

	defaultColor = (defaultColor == "" || !defaultColor) ? "#888" : defaultColor;
	if (action == "focus") { //focus?
		if (formFieldSel.val() == defaultVal) {
			formFieldSel.css("color", color).val("");
		}
	} else if (action == "blur") { //blur?
		if (formFieldSel.val() == "" || formFieldSel.val() == defaultVal) {
			formFieldSel.css("color", defaultColor).val(defaultVal);
		} else {
			formFieldSel.css("color", color);
		}
	} else {
		formFieldSel.css("color", defaultColor);
	}

	$ui(formFieldSel).bind("change", function() {
		if (formFieldSel.val() != "" || formFieldSel.val() != defaultVal) {
			formFieldSel.css("color", color);
		}
	});

	if (!stop) {
		// only the bound functions can have the stop-param
		formFieldSel.bind("focus", function() {
			handleFormLabel(id, defaultVal, defaultColor, color, "focus", true);
		}).bind("blur", function() {
			handleFormLabel(id, defaultVal, defaultColor, color, "blur", true);
		});
	}
}

/* transferCCParameter
 * This function transfers the ccParam via AJAX
 * cc: 00000937750007317012936P75
 * s: e52qL
 * transferCCParam(cc, s);
 */
function uiCC(ccParam, s) {
	var timestamp = new Date().getTime();
	$ui.ajax({
		type: "GET",
		async: false,
		timeout: 1000,
		cache: false,
		url: "/click?cc=" + ccParam + "&s=" + s + "&t=" + timestamp
	});
}

function uiFC(fc, fl, ff, fs) {
	$ui.ajax({
		type: "GET",
		async: false,
		timeout: 1000,
		cache: false,
		url: "/click?fc=" + fc + "&fl=" + fl + "&ff=" + ff + "&fs=" + fs
	});
}

function openLightbox(ui, width, height){
    var object = $ui("#" + flashElement);
	var objectWidth = object.outerWidth();
	var objectHeight = object.outerHeight();
    object.after('<div id="flashplayer-temp" style="width: ' + objectWidth + 'px; height: ' + objectHeight + 'px;"></div>').blur().hide();
	this.pageWidth = $ui("body").width();
	this.pageHeight = $ui("body").height();
	$ui("body").append('<div id="flashplayer-lb" style="width: ' + this.pageWidth + 'px; height: ' + this.pageHeight + 'px;"></div');
	$ui("#flashplayer-lb").show("slow", function callback() {
		$ui("#flashplayer-lb").bind("click", function() {
			closeLightbox();
		});
		var count = 0;
		$ui(document).keyup(function(event) {
			if(event.keyCode == 27 && count == 0) {
				count++;
				closeLightbox(objectWidth, objectHeight);
				$ui(document).unbind('keypress');
			}
		});
		$ui('#flashplayer-lb').bind('click', function() {
			closeLightbox(objectWidth, objectHeight);
		});
		$ui("body").append('<div id="flashplayer-container"></div>');
		$ui("#flashplayer-container").append('<div id="flashplayer-object"></div>');
		$ui("#flashplayer-object").animate({
			width: width + 'px',
			height: height + 'px'
		}, "slow", function() {
			object.appendTo("#flashplayer-object").show();
			object.css({
                "width": width,
                "height": height
            }).attr('width', width).attr('height', height);
		});
	});
	findPlayer(flashElement).lightboxReady();

}

function closeLightbox(width, height){

	findPlayer(flashElement).closeLightbox(); // jetzt schlieÃŸen (video stoppt, resize etc.)
	var object = $ui("#flashplayer-object").children();
	$ui("#flashplayer-temp").replaceWith(object);
	object.css({
        "width": width,
        "height": height
    }).attr('width', width).attr('height', height);
	$ui("#flashplayer-lb").hide("slow").remove();
	$ui("#flashplayer-container").remove();
	$ui("#flashplayer-object").remove();

	findPlayer(flashElement).lightboxClosed(); // schlieÃŸen abgeschlossen (video spielt weiter)
}

function findPlayer(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	var isOpera = navigator.appName.indexOf("Opera") != -1;
	return (isIE || isOpera) ? window[movieName] : document[movieName];
}