/**********************************************************************
* 	tools.js
*	
*	Autor: Kristian Augustin GETIT GmbH
*	Requires: jQuery 1.3.0+
*	----------------------
*
*	Different Standard-Functions 
*	* init-functions after document:loaded
*	*	* Pager Initialization
*	*	* Navigation  Initialization
*	*	* Tooltip Initialization
*	*	* Prefilled-Inputs Initialization
*	* Shadowbox.init()
* 	* openZahlartenShadowbox()
*	* openShadowbox(url, width, height)
*	* comparePopup()
*
**********************************************************************/

/**
* @section Init
*/
var doRefresh = false;
$(document).ready(function () {

	/**
	* @section Top-Nav
	*/
	var openTopNav = null
	$('#topnav li a.handle').mouseover(function() {
		openTopNav = $(this);
		openTopNav.addClass('hover');
		$('#' + $(this).attr('id') + '-layer').show();
		$('#' + $(this).attr('id') + '-layer').mouseover(function() {
			openTopNav.addClass('hover');
			$(this).show();
		}).mouseout(function() {
			openTopNav.removeClass('hover');
			$(this).hide();
		});
	  }).mouseout(function() {
		openTopNav.removeClass('hover');
		$('#' + $(this).attr('id') + '-layer').hide();
	});

	/**
	* @section Pager/Dropdown
	*/
	var openHandle = null;
	$(".pager > .handle").click(function() {
		// check for visibility 
		var elem = $(this).siblings('div.dropdown').children('div');
		if ( elem.css('display') == 'none') {
			if (openHandle != null && openHandle != $(this) ) {
				var elems = openHandle.siblings('div.dropdown').children('div');
				elems.hide();
			}
			openHandle = $(this);
			elem.show();
		}
		else {
			elem.hide();
		}
	});

	if ($(".pager > .handle").length > 0) {
		$("*:not(a)").click(function(clickEvent) {
			// step through DOM and watch if dropdown handle was clicked
			// if clicked in dropdown
			if ( $(this).parents('.pager').length != 0) {
				clickEvent.stopPropagation();
			}
			else {
				if (openHandle != null) {
					var elems = openHandle.siblings('div.dropdown').children('div');
					elems.hide();
				}
			}
		});
	}

	$(".dropdown a.active-country").click(function(event) {
		if ($(this).hasClass('active')) {
			$(this).siblings("#country-layer").slideUp(200);
			$(this).removeClass('active');
		}
		else {
			$(this).siblings("#country-layer").slideDown(200);
			$(this).addClass('active');
			var that = this;
			event.stopPropagation();
			$('*').live('click', function(event) {
				if (!$(this).parents('.carousel').hasClass('carousel')) {
					if (!$(this).parents('#country-layer').hasClass('country-layer')) {
						$(that).siblings("#country-layer").slideUp(200);
						$(that).removeClass('active');
						//alert ("close it");
						//$('*').unbind('click');
						event.stopPropagation();
					}
				}
			});
		}
	});

	/**
	* @section Input-Field-Toggle
	*/
	if (doRefresh != true) {
		$('.prefilled').coolinput();
	}


	/**
	* @section Tooltips
	*/
	$('.tooltip').tooltip({ 
		track: true, 
		delay: 0.5, 
		showURL: false, 
		fade: 250,
		fixPNG: true
	});

	/**
	* @section PNGFIX 
	*/
	jQuery(document).pngFix();
	
	/**
	 * Entferne alle Targets von Shadowbox-Links
	 */
	var linksArray = document.getElementsByTagName("a"); 
	for (var i = 0; i < linksArray.length; ++i){ 
		if (linksArray[i].rel === "shadowbox"){ 
			linksArray[i].target = ""; 
		}
	}
	
	function checkVoucherInput () 
	{
		var RE_VOUCHER = /[A-Z,Ä,Ö,Ü,É,È,Ú,Ù,Í,Ì,Ó,Ò,Á,À,Ý,a-z,ä,ö,ü,é,è,ú,ù,í,ì,ó,ò,á,à,ý,0-9,\-,_]+/;
		var newText = "";
		var oldText = $(this).val(); 
		for ( var idx = 0; idx < oldText.length; idx++ )
		{
			if ( RE_VOUCHER.test( oldText.substr( idx, 1 ) ) ) newText +=  oldText.substr( idx, 1 );
		}
		$(this).val( newText );
	}
	
	$('#voucherInput').keyup( checkVoucherInput );
	
	$('.perfectPartner input:checkbox').click( function( event ) {
		if ( $('.perfectPartner input:checkbox:checked').length > parseInt($('#perfectBundlePromotionCount').html()) ) $(event.target).attr('checked', false );
	});

});

function clr(e) {
	e.value='';
}
function keypresspw (x) {
	y=document.getElementById("register_login");
	x = x || window.event;
	if ((x.ctrlKey || x.metaKey) && x.charCode == 118) {
		clr(y);
	} else if (x.ctrlKey && x.keyCode == 86) {
		clr(y);
	} else if (x.ctrlKey && x.keyCode == 22) {
		clr(y);
	} else if (x.metaKey && x.keyCode == 118) {
		clr(y);
	}
} 
function pastepw () { 
	window.setTimeout("clr(document.getElementById(\"register_login\"));",10); 
} 
function keypresspc (e) {
	f=document.getElementById("login_confirm");
	e = e || window.event;
	if ((e.ctrlKey || e.metaKey) && e.charCode == 118) {
		clr(f);
	} else if (e.ctrlKey && e.keyCode == 86) {
		clr(f);
	} else if (e.ctrlKey && e.keyCode == 22) {
		clr(f);
	} else if (e.metaKey && e.keyCode == 118) {
		clr(f);
	}
} 
function pastepc () { 
	window.setTimeout("clr(document.getElementById(\"login_confirm\"));",10); 
} 
function initNoPaste () { 
	if (null!=document.getElementById("login_confirm")) {
		var pcelem = document.getElementById("login_confirm"); 
		pcelem.onkeyup = keypresspc;
		pcelem.onpaste = pastepc;
	}
	if (null!=document.getElementById("register_login")) {
		var pwelem = document.getElementById("register_login"); 
		pwelem.onkeyup = keypresspw;
		pwelem.onpaste = pastepw;
	}
}

Shadowbox.init({
	autoplayMovies:true,
	handleOversize: 'resize',
 	handleUnsupported:  'remove',
	skipSetup: false,
	players: ["html", "iframe", "img"],
	width: 800,
	height: 600,
	overlayColor:"#000",
	overlayOpacity:0.7
}); 

$(document).ready(function() { 
	$("#additionalTable").hide();
	$("#additionalHint").show();
	var register_password = $("#register_password");
	if (register_password.val() != null) {
		checkPassword(register_password.val());
	}
	var addressinfo = $("#addressinfo");
	var addressinfoDefault = $("#addressinfoDefault");
	if (addressinfo.val() == "") {
		addressinfo.hide();
		addressinfoDefault.show();
	}
	addressinfoDefault.focus(function() {
		addressinfoDefault.hide();
		addressinfo.show();
		addressinfo.focus();
	});
	addressinfo.blur(function() {
		if (this.value == "") {
			addressinfo.hide();
			addressinfoDefault.show();
		}
	});
	var birthday = $("#birthday");
	var birthdayDefault = $("#birthdayDefault");
	if (birthday.val() == "") {
		birthday.hide();
		birthdayDefault.show();
	}
	birthdayDefault.focus(function() {
		birthdayDefault.hide();
		birthday.show();
		birthday.focus();
	});
	birthday.blur(function() {
		if (this.value == "") {
			birthday.hide();
			birthdayDefault.show();
		}
	});
	var phone1 = $("#phone1");
	var phone1Default = $("#phone1Default");
	if (phone1.val() == "") {
		phone1.hide();
		phone1Default.show();
	}
	phone1Default.focus(function() {
		phone1Default.hide();
		phone1.show();
		phone1.focus();
	});
	phone1.blur(function() {
		if (this.value == "") {
			phone1.hide();
			phone1Default.show();
		}
	});
	var register_login = $("#register_login");
	var register_loginDefault = $("#register_loginDefault");
	if (register_login.val() == "") {
		register_login.hide();
		register_loginDefault.show();
	}
	register_loginDefault.focus(function() {
		register_loginDefault.hide();
		register_login.show();
		register_login.focus();
	});
	register_login.blur(function() {
		if (this.value == "") {
			register_login.hide();
			register_loginDefault.show();
		}
	});
});

function showAdditionals() {
	document.getElementById('additionalTable').style.display = 'block';
	document.getElementById('additionalHint').style.display = 'none';
}

function hideAdditionals() {
	document.getElementById('additionalTable').style.display = 'none';
	document.getElementById('additionalHint').style.display = 'block';
}

function checkPwdRepresentation() {
	if (document.getElementById('pwdCheck').checked) {
		document.getElementById('register_password').style.display = 'block';
		document.getElementById('password_confirm').style.display = 'block';
		document.getElementById('register_passwordText').style.display = 'none';
		document.getElementById('password_confirmText').style.display = 'none';
	} else {
		document.getElementById('register_password').style.display = 'none';
		document.getElementById('password_confirm').style.display = 'none';
		document.getElementById('register_passwordText').style.display = 'block';
		document.getElementById('password_confirmText').style.display = 'block';
	}
}

function copyValue(elem) {
	var elemId = elem.id;
	var targerElemId = "";
	if (elemId.indexOf('Text') >= 0) {
		targerElemId = elemId.substring(0, elemId.indexOf('Text'));
	} else {
		targerElemId = elemId + 'Text';
	}
	document.getElementById(targerElemId).value = elem.value;
}

/**
* function called by flash
*/
function openZahlartenShadowbox(url) {
	openShadowbox(url, 700, 540);
}
function openShadowbox(url, width, height) {
	Shadowbox.open({
        content: url,
        player:  "iframe",
        height:  width,
        width:   height
    });
}


function showLayer(selektor) {
	$(selektor).show();
}
function hideLayer(selektor) {
	$(selektor).hide();
}


/**
* @section Popups
*/
function popup(pname) {
	return window.open('',pname,getpopupOptions(pname));
}

function popupToURL(sUrl,pname) {
	return window.open(sUrl,pname,getpopupOptions(pname));
}

function popupToOptions(pname,poptions) {
	return window.open('', pname, poptions);
}  

function popupToURLOptions(sUrl,pname,poptions) {
	return window.open(sUrl, pname, poptions);
}

function comparePopup() {
	pname = 'produktvergleich';
	return window.open('',pname,getpopupOptions(pname));
}

function openComparison() {
	if (numberCompareProducts > 1) {
		return comparePopup();
	}
	else {
		return false;
	}
}

function getpopupOptions(pname) {
	var popupOptionen = "";
	switch(pname) {
		case "produktvergleich":
		popupOptionen='width=1024, height=800, scrollbars=yes, status=no, toolbar=no, resizable=yes, menubar=no, location=no';
		break;
		case "product_recommendation":
		popupOptionen='menubar=no,scrollbars=yes ,toolbar=no,resizable=no,location=no,directories=no,status=no,width=600,height=720,top=10,left=20';
		break;
		case "product_recommendation_confirm":
		popupOptionen='menubar=no,scrollbars=no,toolbar=no,resizable=no,location=no,directories=no,status=no,width=550,height=380,top=10,left=20';
		break;
/*
		case "packstationfinder":
		popupOptionen='menubar=no,scrollbars=yes ,toolbar=no,resizable=no,location=no,directories=no,status=no,width=600,height=720,top=10,left=20';
		break;

*/

		case "promotionMessages":
		popupOptionen='menubar=no,scrollbars=yes,toolbar=no,resizable=no,location=no,directories=no,status=no,width=560,height=250';
		break;
		case "hilfe":
		popupOptionen='menubar=no,scrollbars=yes,toolbar=no,resizable=no,location=no,directories=no,status=no,width=680,height=550,top=10,left=20';
		break;
		case "orderdetail":
		popupOptionen='menubar=no,scrollbars=yes,toolbar=no,resizable=no,location=no,directories=no,status=no,width=680,height=800,top=10,left=20';
		break;
		case "newsletter":
		popupOptionen='menubar=no,scrollbars=yes,toolbar=no,resizable=no,location=no,directories=no,status=no,width=620,height=700,top=50,left=50';
		break;
		case "installmentsApplication":
		popupOptionen='menubar=yes,scrollbars=yes,toolbar=no,resizable=yes,location=no,directories=no,status=no,width=700,height=800,top=50,left=50';
		break;
		case "installmentsInfo":
		popupOptionen='menubar=no,scrollbars=yes,toolbar=no,resizable=no,location=no,directories=no,status=no,width=600,height=700,top=50,left=50';
		break;
		case "citibankAGB":
		popupOptionen='menubar=yes,scrollbars=yes,toolbar=no,resizable=no,location=no,directories=no,status=no,width=520,height=610,top=50,left=50';
		break;
		case "wishlist_recommendation":
		popupOptionen='menubar=no,scrollbars=no,toolbar=no,resizable=no,location=no,directories=no,status=no,width=570,height=600,top=50,left=50';
		break;
		case "checksumInfo":
		popupOptionen='menubar=no,scrollbars=yes,toolbar=no,resizable=no,location=no,directories=no,status=no,width=570,height=600,top=50,left=50';
		break;
		case "infoBasket":
		popupOptionen='menubar=no,scrollbars=yes,toolbar=no,resizable=no,location=no,directories=no,status=no,width=680,height=620,top=10,left=20';
		break;
		case "faq":
		popupOptionen='menubar=no,scrollbars=yes,toolbar=no,resizable=no,location=no,directories=no,status=no,width=680,height=620,top=10,left=20';
		break;
		case "medionfaq":
		popupOptionen='menubar=no,scrollbars=yes,toolbar=no,resizable=no,location=no,directories=no,status=no,width=680,height=620,top=10,left=20';
		break;
		case "print_order":
		popupOptionen='menubar=no,scrollbars=yes,toolbar=no,resizable=no,location=no,directories=no,status=no,width=700,height=600,top=10,left=20';
		break;
		case "print_product":
		popupOptionen='menubar=no,scrollbars=yes,toolbar=no,resizable=no,location=no,directories=no,status=no,width=600,height=600,top=50,left=50';
		break;
		case "footer_help":
		popupOptionen='menubar=no,scrollbars=yes,toolbar=no,resizable=no,location=no,directories=no,status=no,width=620,height=700,top=50,left=50';
		break;
		case "footer_privacy_protection":
		popupOptionen='menubar=no,scrollbars=yes,toolbar=no,resizable=no,location=no,directories=no,status=no,width=620,height=700,top=50,left=50';
		break;
		default:
		alert("Popup noch nicht definiert");
		break;
	}

	return popupOptionen;
}

function getCookie(cookiename) {
	var cookiestring = "" + document.cookie;
	var index1 = cookiestring.indexOf(cookiename);
	if (index1 == -1 || cookiename == "")
		return "";
	var index2 = cookiestring.indexOf(';', index1);
	if (index2 == -1)
		index2 = cookiestring.length;
	var index0 = index1 + ((""+cookiename).length) + 1;
	return cookiestring.substring(index0, index2);
}

function setCookie(name, value) {
	var d = location.hostname;
	var dReg = "^[0-9]{1,3" + String.fromCharCode(125) + "\.[0-9]{1,3"
			+ String.fromCharCode(125) + "\.[0-9]{1,3"
			+ String.fromCharCode(125) + "\.[0-9]{1,3"
			+ String.fromCharCode(125) + "$";
	if (d.search(dReg) == -1) {
		d = location.hostname.split(".");
		d = d[d.length - 2] + "." + d[d.length - 1];
	}
	;
	var c;
	c = name + "=" + escape(value) + ";domain=" + d + ";path=/;expires="
				+ getexpirydate(1000);
	document.cookie = c;
}

function closePopover(pTime) {
	window.setTimeout("document.getElementById('aldi-layer').style.display = 'none'", pTime);
}

function checkPopover(duration, showCount, showEvery, cookieName){
	var cookieLastShown = getCookie(cookieName+"last");
	if (showCount > 0) {
		var cookieCount = getCookie(cookieName+"count");
		if (cookieCount == "" || cookieCount <= showCount) {
			if (showEvery > 0) {
				if ((cookieLastShown == "" || cookieLastShown < getMillisBeforeDays(showEvery))) {
					document.getElementById('aldi-layer').style.display = 'block';
					cookieCount = (cookieCount * 1) + 1;
					setCookie(cookieName+"count", cookieCount);
					setCookie(cookieName+"last", getNowMillis());
				}
			} else {
				document.getElementById('aldi-layer').style.display = 'block';
				cookieCount = (cookieCount * 1) + 1;
				setCookie(cookieName+"count", cookieCount);
			}
		}
	} else {
		if (showEvery > 0) {
			if ((cookieLastShown == "" || cookieLastShown < getMillisBeforeDays(showEvery))) {
				document.getElementById('aldi-layer').style.display = 'block';
				setCookie(cookieName+"last", getNowMillis());
			}
		} else {
			document.getElementById('aldi-layer').style.display = 'block';
		}
	}
	if (duration > 0) {
		window.setTimeout("document.getElementById('aldi-layer').style.display = 'none'", duration * 1000);		
	}
}

function getMillisBeforeDays(days) {
	var Today = new Date();
	var nowmilli = Date.parse(Today);
	return nowmilli - (days * 24 * 60 * 60 * 1000);
}

function getNowMillis() {
	var Today = new Date();
	return Date.parse(Today);
}

function getexpirydate(days) {
	var UTCstring;
	var Today = new Date();
	var nomilli = Date.parse(Today);
	Today.setTime(nomilli + days * 24 * 60 * 60 * 1000);
	UTCstring = Today.toUTCString();
	return UTCstring;
}


/* ************************************************************************** */

/* Funktion zum �ndern von Bildern ****************************************** */
function changeImage(imageName,idName) {
	$('#'+idName).attr('src', imageName);
	// also change the NonFlash Version
	$('#'+idName + 'NonFlash').attr('src', imageName);
}
/* ************************************************************************** */

function checkPassword(pCurrentValue) {
	var valueLength = pCurrentValue.length;
	if (valueLength >= 6 && valueLength <= 8) {
		document.getElementById('lengthOK').style.display = "block";
		document.getElementById('lengthWrong').style.display = "none";
	} else {
		document.getElementById('lengthOK').style.display = "none";
		document.getElementById('lengthWrong').style.display = "block";		
	}
	var RE_PWD_CAP_UML = /[A-Z,Ä,Ö,Ü,É,È,Ú,Ù,Í,Ì,Ó,Ò,Á,À,Ý]+/;
	var RE_PWD_SMALL_UML = /[a-z,ä,ö,ü,é,è,ú,ù,í,ì,ó,ò,á,à,ý]+/;
	var RE_PWD_CAP = /[A-Z]+/;
	var RE_PWD_SMALL = /[a-z]+/;
	var RE_PWD_NUM = /[0-9]+/;
	
	try {
		if (RE_PWD_CAP_UML.test(pCurrentValue)) {
			document.getElementById('capitalOK').style.display = "block";
			document.getElementById('capitalWrong').style.display = "none";
		} else {
			document.getElementById('capitalOK').style.display = "none";
			document.getElementById('capitalWrong').style.display = "block";		
		}
		if (RE_PWD_SMALL_UML.test(pCurrentValue)) {
			document.getElementById('lowerCaseOK').style.display = "block";
			document.getElementById('lowerCaseWrong').style.display = "none";
		} else {
			document.getElementById('lowerCaseOK').style.display = "none";
			document.getElementById('lowerCaseWrong').style.display = "block";		
		}
	} catch (e) {
		if (RE_PWD_CAP.test(pCurrentValue)) {
			document.getElementById('capitalOK').style.display = "block";
			document.getElementById('capitalWrong').style.display = "none";
		} else {
			document.getElementById('capitalOK').style.display = "none";
			document.getElementById('capitalWrong').style.display = "block";		
		}
		if (RE_PWD_SMALL.test(pCurrentValue)) {
			document.getElementById('lowerCaseOK').style.display = "block";
			document.getElementById('lowerCaseWrong').style.display = "none";
		} else {
			document.getElementById('lowerCaseOK').style.display = "none";
			document.getElementById('lowerCaseWrong').style.display = "block";		
		}
	}
	if (RE_PWD_NUM.test(pCurrentValue)) {
		document.getElementById('numberOK').style.display = "block";
		document.getElementById('numberWrong').style.display = "none";
	} else {
		document.getElementById('numberOK').style.display = "none";
		document.getElementById('numberWrong').style.display = "block";		
	}
	checkConfirm();
}

function checkConfirm() {
	var confirmValue = document.getElementById('password_confirm').value;
	if (confirmValue != '' && document.getElementById('register_password').value == confirmValue) {
		document.getElementById('compareOK').style.display = "block";
		document.getElementById('compareWrong').style.display = "none";		
	} else {
		document.getElementById('compareOK').style.display = "none";
		document.getElementById('compareWrong').style.display = "block";		
	}
	
}

function checkPasswordOld(pCurrentValue)
{
	if ( pCurrentValue != '' )
	{
		var valueLength = pCurrentValue.length;
		var minValueLength = 6 - valueLength;
		//document.getElementById('passwordMessage').style.display = 'block';
		document.getElementById('passwordCheckTable').style.display = 'block';
		if (valueLength == 8) {
			document.getElementById('passwordMessage').style.color = "#000000";
			document.getElementById('passwordMessage').innerHTML = document.getElementById('pwdLenthCheckMaximumAchieved').innerHTML;			
		} else if (minValueLength > 0 ) {
			document.getElementById('passwordMessage').style.color = "#FF0000";
			document.getElementById('passwordMessage').innerHTML = document.getElementById('pwdLenthCheckPleaseEnter').innerHTML
					+ minValueLength + document.getElementById('pwdLenthCheckTo').innerHTML + (8 - valueLength)
					+ document.getElementById('pwdLenthCheckCharacters').innerHTML;			
		} else {
			document.getElementById('passwordMessage').style.color = "#000000";
			document.getElementById('passwordMessage').innerHTML = document.getElementById('pwdLenthCheckYouCan').innerHTML 
					+ (8 - valueLength) + document.getElementById('pwdLenthCheckEnterCharacters').innerHTML;			
		}
		if (valueLength >= 6) {
			var RE_PWD_CAP_UML = /[A-Z,Ä,Ö,Ü,É,È,Ú,Ù,Í,Ì,Ó,Ò,Á,À,Ý]+/;
			var RE_PWD_SMALL_UML = /[a-z,ä,ö,ü,é,è,ú,ù,í,ì,ó,ò,á,à,ý]+/;
			var RE_PWD_CAP = /[A-Z]+/;
			var RE_PWD_SMALL = /[a-z]+/;
			var RE_PWD_NUM = /[0-9]+/;
			
			try {
				if (RE_PWD_CAP_UML.test(pCurrentValue)
						&& RE_PWD_SMALL_UML.test(pCurrentValue)
						&& RE_PWD_NUM.test(pCurrentValue)) {
					document.getElementById('passwordCheck').style.color = "#000000";
					document.getElementById('passwordCheck').innerHTML = document
							.getElementById('pwdCheckOk').innerHTML;
				} else {
					document.getElementById('passwordCheck').style.color = "#FF0000";
					document.getElementById('passwordCheck').innerHTML = document
							.getElementById('pwdCheckNotOk').innerHTML;
				}
			} catch (e) {
				if (RE_PWD_CAP.test(pCurrentValue)
						&& RE_PWD_SMALL.test(pCurrentValue)
						&& RE_PWD_NUM.test(pCurrentValue)) {
					document.getElementById('passwordCheck').style.color = "#000000";
					document.getElementById('passwordCheck').innerHTML = document
							.getElementById('pwdCheckOk').innerHTML;
				} else {
					document.getElementById('passwordCheck').style.color = "#FF0000";
					document.getElementById('passwordCheck').innerHTML = document
							.getElementById('pwdCheckNotOk').innerHTML;
				}
			}
		} else {
			document.getElementById('passwordCheck').style.color = "#FF0000";
			document.getElementById('passwordCheck').innerHTML = document.getElementById('pwdCheckNotOk').innerHTML;		
		}
	} else {
		//document.getElementById('passwordMessage').style.display = 'none';
		document.getElementById('passwordCheckTable').style.display = 'none';
	}
}
//MedionFAQ Area /////////////////////

var xhrMedionFAQ;

function closeFAQ() {
	// abort previous XMLHttpRequest
	if (xhrMedionFAQ && xhrMedionFAQ.readyState  > 0)
		xhrMedionFAQ.abort();
	UnTip();
}

function loadFAQ(url) {

 // reset tooltip
 //document.getElementById("MedionFAQDiv").innerHTML = '';
	//TagToTip('MedionFAQDiv',WIDTH,0, FOLLOWMOUSE,true, DELAY,0, LEFT,false, BORDERCOLOR,'#000',BGCOLOR,'#fff',FONTCOLOR,'#001e4b');

	// abort previous XMLHttpRequest
	if (xhrMedionFAQ) {
		xhrMedionFAQ.abort();
		xhrMedionFAQ = null;
	}

	// create new XMLHttpRequest
	if (window.XMLHttpRequest) {
	    xhrMedionFAQ = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
	    xhrMedionFAQ = new ActiveXObject("Microsoft.XMLHTTP");
	}

	// set event handler for XMLHttpRequest
	xhrMedionFAQ.onreadystatechange  = function() {
		if(xhrMedionFAQ.readyState == 4) {
			try {
   			if (xhrMedionFAQ.status == 200) {
					// show tooltip
					var respText = xhrMedionFAQ.responseText;
					if (respText !== null) {
						if (respText.length > 0) {
							document.getElementById("MedionFAQDiv").innerHTML = xhrMedionFAQ.responseText;
							TagToTip('MedionFAQDiv',WIDTH,200,FOLLOWMOUSE,true,DELAY,0,BORDERCOLOR,'#000000',BGCOLOR,'#ffffff',FONTCOLOR,'#000000',OPACITY,100);
						}
					}
				}
		    } catch(e) {
			}
		}
 };

	// open url
	xhrMedionFAQ.open("GET", url,  true);
	xhrMedionFAQ.send(null);
}

function openDailyOfferFlash() {
	openShadowbox($("#dailyOffer_flash_lightbox").attr("href"), 634, 740);
	Shadowbox.options.onClose = function() {location.reload()} 
}

jQuery.fn.extend({
	  selectText: function() {
	    var text = $(this)[0];
	    if ($.browser.msie) {
	      var range = document.body.createTextRange();
	      range.moveToElementText(text);
	      range.select();
	    } else if ($.browser.mozilla || $.browser.opera) {
	      var selection = window.getSelection();
	      var range = document.createRange();
	      range.selectNodeContents(text);
	      selection.removeAllRanges();
	      selection.addRange(range);
	    } else if ($.browser.safari) {
	      var selection = window.getSelection();
	      selection.setBaseAndExtent(text, 0, text, 1);
	    }
	    return $(this);
	  }
	})
	
function closeMe( newURL ) {
	parent.location.href = newURL;
	parent.Shadowbox.options.onClose = function() {};
	parent.Shadowbox.close();
}

var domWrite = (function(){            // by Frank Thuerigen
	 // private 

	 var dw = document.write,              // save document.write()
	          myCalls = [],                // contains all outstanding Scripts
	          t = '';                      // timeout
	 
	 function startnext(){                 // start next call in pipeline
	  if ( myCalls.length > 0 ) {
	   if ( Object.watch ) console.log( 'next is '+myCalls[0].f.toString() );
	   myCalls[0].startCall();
	   }
	  }

	 function evals( pCall ){            // eval embedded script tags in HTML code
	  var scripts = [],
	      script,
	      regexp = /<script[^>]*>([\s\S]*?)<\/script>/gi;
	  while ((script = regexp.exec(pCall.buf))) scripts.push(script[1]);
	  scripts = scripts.join('\n');
	  if (scripts) {
	   eval(scripts);
	   }
	  }

	 function finishCall( pCall ){
	   pCall.e.innerHTML = pCall.buf;             // write output to element
	   evals( pCall );
	   document.write=dw;                        // restore document.write()
	   myCalls.shift();
	   window.setTimeout( startnext, 50 );
	   }

	 function testDone( pCall ){
	   var myCall = pCall;
	   return function(){
	    if ( myCall.buf !== myCall.oldbuf ){
	     myCall.oldbuf = myCall.buf;
	     t=window.setTimeout( testDone( myCall ), myCall.ms );
	     }
	    else {
	     finishCall( myCall );
	     }
	    }
	   }  
	   
	 function MyCall( pDiv, pSrc, pFunc ){                    // Class
	  this.e = ( typeof pDiv == 'string' ? 
	             document.getElementById( pDiv ) :
	             pDiv ),                     // the div element
	  this.f = pFunc || function(){},
	  this.stat = 0,                         // 0=idle, 1=waiting, 2=running, 3=finished
	  this.src = pSrc,                       // script source address
	  this.buf = '',                         // output string buffer
	  this.oldbuf = '',                      // compare buffer
	  this.ms = 100,                         // milliseconds
	  this.scripttag;                        // the script tag 
	  }
	 
	 MyCall.prototype={
	  startCall: function(){
	   this.f.apply( window );                 // execute settings function
	   this.stat=1;
	   var that = this;                            // status = waiting
	   document.write = (function(){
	    var o=that,
	        cb=testDone( o ),
	        t;
	    return function( pString ){            // overload document.write()
	     window.clearTimeout( t );
	     o.stat=2;                             // status = running
	     window.clearTimeout(t);
	     o.oldbuf = o.buf;
	     o.buf += pString;                     // add string to buffer
	     t=window.setTimeout( cb, o.ms );
	     };
	    })();
	   var s=document.createElement('script');
	   s.setAttribute('language','javascript');
	   s.setAttribute('type','text/javascript');
	   s.setAttribute('src', this.src);
	   document.getElementsByTagName('head')[0].appendChild(s);
	   }
	  }
	  
	 return function( pDiv, pSrc, pFunc ){  // public
	  var c = new MyCall( pDiv, pSrc, pFunc );
	  myCalls.push( c );
	  if ( myCalls.length === 1 ){
	   startnext();
	   }
	  }
	 })();

