function switchImage(sImgId, sNewImg) {
	var imgTag = document.getElementById(sImgId);
	imgTag.src = sNewImg;
}



function switchBackground(sEleId, sNewImg) {
	var imgDiv = document.getElementById(sEleId);
	imgDiv.style.backgroundImage = 'url(' + sNewImg + ')';
}

function switchBackgroundV2(sEleId) {
	sNewImg = "";
	iCounter = 0;
	while (true) {
		iCounter++;
		if (iCounter == 6) {
			break;
		}
		iSwitchImgNo++;
		iNo = iSwitchImgNo % 5;
		if (aSwitchImages[iNo] && aSwitchImages[iNo] != "") {
			sNewImg = aSwitchImages[iNo];
		} else {
			continue;
		}
		iCounter++;
		if (sNewImg != "") {
			break;
		}
	}
	var imgDiv = document.getElementById(sEleId);
	imgDiv.style.backgroundImage = 'url(' + sNewImg + ')';
}

function showLay(sLayer, sTable) {
	var myLayer = document.getElementById(sLayer);
	var myTable = document.getElementById(sTable);
	var myItemRows = document.getElementsByTagName('div');
	if (myLayer) {
		myLayer.style.display = 'block';
	}
	
	if (myTable) {
		for(i=0; i<myItemRows.length; i++) {
			if (myItemRows[i].className == 'itemRowBlock') {
				myItemRows[i].style.display = 'none';
			}
		}
	}
	myTable.style.display = 'block';
}

function hideLay(sLayer) {
	var myLayer = document.getElementById(sLayer);
	if (myLayer) {
		myLayer.style.display = 'none';
	}
}

function hideAllOffers() {
	var myItemRows = document.getElementsByTagName('div');
	for(i=0; i<myItemRows.length; i++) {
		if (myItemRows[i].className == 'itemRowBlock') {
			myItemRows[i].style.display = 'none';
		}
	}
}

function toggleDisplay(sId, doHide) {
	var theLayer = document.getElementById(sId);
	if (!doHide) {
		doHide = 1;
	}
	if (theLayer) {
		if (theLayer.style.display == 'block') {
			if (doHide == 1) {
				theLayer.style.display = 'none';
			}
		} else {
			theLayer.style.display = 'block';
		}
	}
}

/** 
 * sets url to be loaded in iframe.
 * this is called at the end of an iframe article
 */
function setIframeUrl() {
	var ibeUrl = getURLParam('ibe_pass');
	window.frames.ibe_order_frame.location.href = ibeUrl;
}

/** 
 * get value of a passed GET parameter
 * @param {string} strParamName
 * @return string
 */
function getURLParam(strParamName){
	var strReturn = "";
	var strHref = window.location.href;
	if ( strHref.indexOf("?") > -1 ){
		var strQueryString = strHref.substr(strHref.indexOf("?"));
		var aQueryString = strQueryString.split("&");
		for ( var iParam = 0; iParam < aQueryString.length; iParam++ ) {
			if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ) {
			var aParam = aQueryString[iParam].split("=");
			strReturn = aParam[1];
			break;
			}
		}
	}
	return unescape(strReturn);
}

function openAgb() {
	window.open('15_89.html', '15_89.html', 'height=500, width=400, location=no, menubar=no, scrollbars=yes');
	return false;
}

function closeAlertPop() {
	var mydiv = document.getElementById('alertPopup');
	if (mydiv) {
		mydiv.style.display = 'none';
		createCookie('read_alert', '1');
	}
}
function toggleAlertPop() {
	var cookieval = readCookie('read_alert');
	var mydiv = document.getElementById('alertPopup');
	if (mydiv) {
		if (cookieval) {
			mydiv.style.display = 'none';
		} else {
			mydiv.style.display = 'block';
		}
	}
}

/** 
 * Cookie handling: Create cookie
 * @param {Object} name
 * @param {Object} value
 * @param {Object} days
 */
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

/** 
 * Cookie handling: Read cookie
 * @param {Object} name
 */
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

/** 
 * Cookie handling: Delete cookie
 * @param {Object} name
 */
function eraseCookie(name) {
	createCookie(name,"",-1);
}


/* viewport functions */

function DisplaySettings() {
	var isIE = false;
	var isOpera = false;
	var ua = navigator.userAgent;
	var m = false;
	
	// check for Opera and IE only!
	m = ua.match(/Opera[\s\/]([^\s]*)/);
	if (m && m[1]) {
		isOpera = true;
	} else { // !WebKit && !Opera
		m = ua.match(/MSIE\s([^;]*)/);
		if (m && m[1]) {
			isIE = true;
		}
	}
	
	// for all viewport-/scroll-/document sizes see:
	// http://www.quirksmode.org/viewport/compatibility.html
	/**
	 * Current browsers viewport width.
	 * @method getViewportWidth
	 * @return {Int} Width of viewable area (exlude scrollbar).
	 */
	this.getViewportWidth = function () {
		var width = self.innerWidth; // all except IE
		var mode = document.compatMode;
		
		if ( (mode || isIE)) { // all except Safari
			width = (mode == "CSS1Compat")
				? document.documentElement.clientWidth // Standard
				: document.body.clientWidth; // Quirks | BackCompat
		}
		
		return width;
	};

	/**
	 * Current browsers viewport height.
	 * @method getViewportHeight
	 * @return {Int} Height of viewable area (exlude scrollbar).
	 */
	this.getViewportHeight = function () {
		var height = self.innerHeight; //all except IE
		var mode = document.compatMode;
		
		if ( (mode || isIE) && !isOpera) { // IE, Gecko
			height = (mode == "CSS1Compat") ?
				document.documentElement.clientHeight : // Standard
				document.body.clientHeight //Quirks | BackCompat
		}
		
		return height;
	}

	/**
	 * Current browsers viewport width and height
	 * @method getViewport
	 * @return {Array} Widht|Height of viewable area (exclude scrollbar).
	 */
	this.getViewport = function () {
		return [this.getViewportWidth(), this.getViewportHeight()];
	}
	
	/**
	 * Returns the height of the document.
	 * @method getDocumentHeight
	 * @return {Int} The height of the actual document (including body and its margin).
	 */
	this.getDocumentHeight = function () {
		var scrollHeight = (document.compatMode == "CSS1Compat") ?
			document.documentElement.scrollHeight : // Standard
			document.body.scrollHeight; //Quirks | BackCompat
		
		return Math.max(this.getViewportHeight(), scrollHeight);
	}
	
	/**
	 * Returns the width of the document.
	 * @method getDocumentWidth
	 * @return {Int} The width of the actual document (including body and its margin).
	 */
	this.getDocumentWidth = function () {
		var scrollWidth = (document.compatMode == "CSS1Compat") ?
			document.documentElement.scrollWidth : // Standard
			document.body.scrollWidth; //Quirks | BackCompat
		
		return Math.max(this.getViewportWidth(), scrollWidth);
	}
	
	/**
	 * Returns the top scroll value of the document.
	 * @method getDocumentScrollTop
	 * @return {Int} The amount that the document is scrolled to the top.
	 */
	this.getDocumentScrollTop = function () {
		var scrollTop = self.pageYOffset;
		var mode = document.compatMode;
		
		if (mode || isIE) {
			scrollTop = (mode == "CSS1Compat") ?
				document.documentElement.scrollTop : // Standard
				document.body.scrollTop; //Quirks | BackCompat
		}
		
		return scrollTop;
	};

	/**
	 * Returns the left scroll value of the document
	 * @method getDocumentScrollLeft
	 * @return {Int} The amount the document is scrolled to the left.
	 */
	this.getDocumentScrollLeft = function () {
		var scrollLeft = self.pageXOffset;
		var mode = document.compatMode;
		
		if (mode || isIE) {
			scrollLeft = (mode == "CSS1Compat") ?
				document.documentElement.scrollLeft : // Standard
				document.body.scrollLeft; //Quirks | BackCompat
		}
		
		return scrollLeft;
	};

	this.getPageScroll = function () {
		return [this.getDocumentScrollLeft(), this.getDocumentScrollTop()];
	}
}

var Screen = new DisplaySettings();

function positionIbePop() {
	var theBox = document.getElementById('view_IBE_page2'); // ibe box to position
	
	var a = Screen.getViewport();
	var aScroll = Screen.getPageScroll();
	
	//alert('width; '+a[0]+', height: '+a[1]+', scrollTop: '+aScroll[1]);
	var fCenter = aScroll[1] + (a[1] / 2);
	//alert('center: ' + fCenter);
	
	var iMiddleW = parseInt((a[0] / 2)-217); // width of box is 434px
	var iMiddleH = parseInt(fCenter - 190); // height of box is variable
	
	if (theBox) {
		theBox.style.position = 'absolute';
		theBox.style.left = iMiddleW+'px';
		theBox.style.top = iMiddleH+'px';
	}
}

/** 
 * Position IBE Popup P. V2
 */
function positionIbePopV2() {
	var theBox = document.getElementById('view_IBE_page2'); // ibe box to position
	
	var a = Screen.getViewport();
	var aScroll = Screen.getPageScroll();
	
	var fCenterH = aScroll[1] + (a[1] / 2);
	var fCenterW = (a[0] / 2);
	
	var PosX = parseInt(fCenterW);
	var PosY = parseInt(fCenterH);
	
	PosX = 470 - parseInt(310 / 2); // content box is 940px wide, ibe popup box is 310 wide. so we assume users screen is wider than 940...
	PosY = PosY - 100;
	
	if (theBox) {
		theBox.style.position = 'absolute';
		theBox.style.left = PosX+'px';
		theBox.style.top = PosY+'px';
	}
}

function setScreen() {
	var isIE = false;
	var ua = navigator.userAgent;
	var m = false;
	// IE
	m = document.uniqueID /*IE*/
&& document.compatMode /*>=IE6*/
&& !window.XMLHttpRequest /*<=IE6*/
&& document.execCommand;
	if (!!m) {
		var myInner = document.getElementById('content');
		if (myInner)  {
			var myHeight = myInner.offsetHeight;
			var myOuter = document.getElementById('page');
			if (myOuter) {
				myOuter.style.height = (myHeight -22) + 'px';
			}
		}
	}
}
