try {
	document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}

/**
 * JavaScript on DOM-Load: Shopcode-Box in left navigation; plus other useful things
 */
$(document).ready(function(){
	rr = new Image;
	rr.src = "/$WS/idg/websale7_shop-idg/benutzer/templates/images/shopcode/shopcode_re_button_1.gif";
	$("#box_shopcode input#submit").hover(function(){
		this.src = "/$WS/idg/websale7_shop-idg/benutzer/templates/images/shopcode/shopcode_re_button_1.gif";
	},function(){
		this.src = "/$WS/idg/websale7_shop-idg/benutzer/templates/images/shopcode/shopcode_re_button_0.gif";
	});
	$("#box_shopcode input#shopcode").click(function(){
		this.value = "";
	});
	// template "Aktuelle Ausgabe": fill empty product quantity input fields with value 1
	var pq = $("#aktuelleausgabe :text[name='input_qty_1']").val();
	if (pq=='') $("#aktuelleausgabe :text[name='input_qty_1']").val('1');
	
	// colorbox via websale-js-library
	if ($().colorbox) {
		$("a.tt_cbox_01").colorbox({initialWidth:"80px", initialHeight:"60px"});
		$("a.tt_cbox_02").colorbox({initialWidth:"80px", initialHeight:"60px", innerWidth:"570px", innerHeight:"350px", scrolling:true, iframe:true});
	}
});

/* Popup für Inquiries */
function inquiry(p_url) {
	var u = p_url;
	var p = ",left=200,top=100,resizable=yes,scrollbars=yes,menubar=no,location=yes,status=yes,toolbar=no,directories=no";
	var w = 630;
	var h = 650;
	nw = window.open(u, "pw", "width=" + w + ",height=" + h + p);
	nw.focus();
	return false;
}

/* tell which browser */
function sniff() {
	if (navigator.vendor == 'KDE' || (document.childNodes && (!document.all || navigator.accentColorName) && !navigator.taintEnabled)) { 
		return "IE";	// für unsere Zwecke reicht es, Safari mit IE gleichzusetzen.
	} else if (navigator.product == 'Gecko' && !navigator.savePreferences) {
		return "FF";
	} else {
		return "IE";
	}
};

/* Öffnet ein Popup und lädt die angegebene HTML-Datei (URL relativ zum template-Verzeichnis) */
function sp(p_url,p_width,p_height,p_scroll) {
	var u=(p_url.toLowerCase().indexOf('http://')!=-1 || p_url.toLowerCase().indexOf('/$ws/')!=-1) ? p_url : "/$WS/idg/websale7_shop-idg/benutzer/templates/" + p_url;
	var p=",left=200,top=100,resizable=yes";
	var w=(p_width) ? p_width : 400;
	var h=(p_height) ? p_height : 500;
	if (p_scroll===false) {
		p=p+",scrollbars=no";
	} else {
		p=p+",scrollbars=yes";
	}
	pw=window.open(u,"pw","width="+w+",height="+h+p);
	pw.focus();
//	return false;
};

/* Öffnet ein Popup-Fenster mit der Prämien-HTML-Datei (die in ../gross) liegt ODER einem Standard-Popup, in das per JS die Bilddatei nachgeladen wird */
function pp(cat_lasttopindex, cat_name, pr_largeimage) {
	/*
	if (hasNoLargeImage(cat_lasttopindex, cat_name)) return;
	if (hasNoHTMLPopup(cat_lasttopindex, cat_name)) {
		p (cat_lasttopindex, cat_name, pr_largeimage);
		return;
	}
	*/
	var u = pr_largeimage.slice(0,pr_largeimage.lastIndexOf("."))+".html";
	var b = 868;
	var h = 484;
	// if (sniff()==="IE") h = 504;
	p=window.open(u,"pw","width="+b+",height="+h+",left="+Math.round((window.screen.availWidth-b)/2)+",top="+Math.round((window.screen.availHeight-h)/2)+",resizable=yes,scrollbars=no");
	p.focus();
}

/* Öffnet ein Popup (das wiederum per JS das Large-Image nachlädt) und übergibt die URL des zu ladenden Bilds im Querystring */
function p(cat_lasttopindex, cat_name, pr_largeimage) {
	var w=530, h=680;
	if (hasNoLargeImage(cat_lasttopindex, cat_name)) return;
	window.open("/$WS/idg/websale7_shop-idg/produkte/medien/bilder/gross/popup.html?img="+pr_largeimage,"pw","width="+w+",height="+h+",left=200,top=100,resizable=yes");
}

/* Prüft, ob es sich um ein Abo ohne Popup handelt */
function hasNoLargeImage(cat_lasttopindex, cat_name) {
	cat_lasttopindex = cat_lasttopindex.toLowerCase();
	cat_name = cat_name.toLowerCase();
	if (cat_lasttopindex == 'computerwoche') {
		if (cat_name.indexOf('jahres')!=-1) return false;
		if (cat_name.indexOf('geschenk')!=-1) return false;
		if (cat_name.indexOf('branchenmonitor')!=-1) return true;
		if (cat_name.indexOf('mittelstand')!=-1) return true;
		if (cat_name.indexOf('gratis testen')!=-1) return true;
	}
	if (cat_name.indexOf('halbjahresabo')!=-1) return false;
	if (cat_name.indexOf('gratisheft')!=-1) return true;
	if (cat_name.indexOf('archiv-cd')!=-1) return true;
	if ((cat_name.indexOf('abo')!=-1)) {
		if (cat_name.indexOf('jahres')!=-1 || cat_name.indexOf('student')!=-1 || cat_name.indexOf('geschenk')!=-1 || cat_name.indexOf('kombi')!=-1 || cat_name.indexOf('premium')!=-1 || cat_name.indexOf('ipod')!=-1 || cat_name.indexOf('sonderheft')!=-1 || cat_name.indexOf('linux')!=-1 || cat_name.indexOf('dev')!=-1) {
			return true;		// z.B. Jahresabo hat kein LargeImage
		} else return false;	// z.B. Miniabo hat eines
	}
	return false;				// z.B. Archiv hat eines
}

/* Prüft, ob es sich um Angebot ohne eigene Popup-HTML-Datei handelt, z.B. Einzelhefte und Sonderhefte */
function hasNoHTMLPopup(cat_lasttopindex, cat_name) {
	cat_name = cat_name.toLowerCase();
	if ((cat_name.indexOf('044')!=-1) || (cat_name.indexOf('20')!=-1) || (cat_name.indexOf('sonderheft')!=-1) || (cat_name.indexOf('linux')!=-1) || (cat_name.indexOf('spezial')!=-1) || (cat_name.indexOf('archiv')!=-1) || (cat_name.indexOf('nmag')!=-1)) {
		return true;
	} else {
		return false;
	}
}

/* versteckt den Link, wenn es keine vergrößerte Abbildung gibt. */
function stealthlink(cat_lasttopindex, cat_name, id) {
	if (hasNoLargeImage(cat_lasttopindex, cat_name)) {
		if (document.getElementById) {
			if (document.getElementById(id).style) {
				document.getElementById(id).style.cursor = "default";
			}
		}
		window.status = " ";
	}
}
function clearstealthlink() {
	window.status = "";
}

/* ---------- Check Input Skripte ---------- */

// prüft @ und . und Mindestlänge der Einzelstrings
function isValidEMail(s) {
	if (s.length>5 && s.indexOf("@")!=-1 && s.slice(0,s.indexOf("@")).length>0) {
		var u=s.slice(s.indexOf("@")+1);
		if (u.indexOf(".")!=-1 && u.slice(0,u.lastIndexOf(".")).length>0 && u.slice(u.lastIndexOf(".")+1).length>=2) return true;
	}
	return false;
}

function check_input_premium() {
	
	/*
	
	// Texteingabefelder (manuell ermittelt) "E-Mail":
	if (document.forms["product"].elements["input_text_56-2193_1_1"]) {				// PC-WELT
		var mail = "input_text_56-2193_1_1";									
	} else if (document.forms["product"].elements["input_text_MWP_1_1"]) {			// Macwelt
		var mail = "input_text_MWP_1_1"; 										
	} else if (document.forms["product"].elements["input_text_MPJGR_1_1"]) {		// Macwelt Premium Macbay
		var mail = "input_text_MPJGR_1_1"; 										
	} else if (document.forms["product"].elements["input_text_13-2907_1_1"]) {		// Macwelt Premium 4 Wochen gratis testen (2/08)
		var mail = "input_text_13-2907_1_1"; 										
	} else if (document.forms["product"].elements["input_text_GSPREMIUM_1_1"]) {	// GameStar
		var mail = "input_text_GSPREMIUM_1_1";									
	} else if (document.forms["product"].elements["input_text_TC-3976_1_1"]) {		// TecChannel Privatkunden
		var mail = "input_text_TC-3976_1_1";									
	} else if (document.forms["product"].elements["input_text_TC-3975_1_1"]) {		// TecChannel Studenten
		var mail = "input_text_TC-3975_1_1";									
	} else if (document.forms["product"].elements["input_text_TC-3974_1_1"]) {		// TecChannel Firmen
		var mail = "input_text_TC-3974_1_1";									
	} else if (document.forms["product"].elements["input_text_3-2909_1_1"]) {		// TecChannel Mailing 045
		var mail = "input_text_3-2909_1_1";									
	} else if (document.forms["product"].elements["input_text_14-3000_1_2"]) {		// TecChannel Shopcode 082 Kombiabo DE
		var mail = "input_text_14-3000_1_2";									
	} else if (document.forms["product"].elements["input_text_15-3000_1_2"]) {		// TecChannel Shopcode 082 Kombiabo AT
		var mail = "input_text_15-3000_1_2";									
	} else if (document.forms["product"].elements["input_text_16-3000_1_2"]) {		// TecChannel Shopcode 082 Kombiabo CH
		var mail = "input_text_16-3000_1_2";									
	} else if (document.forms["product"].elements["input_text_17-3000_1_2"]) {		// TecChannel Shopcode 082 Kombiabo EU
		var mail = "input_text_17-3000_1_2";									
	} else if (document.forms["product"].elements["input_text_5-2932_1_1"]) {		// TecChannel Aktion Download
		var mail = "input_text_5-2932_1_1";									
	} else if (document.forms["product"].elements["input_text_5-2958_1_1"]) {		// TecChannel Mailing 049
		var mail = "input_text_5-2958_1_1";									
	} else if (document.forms["product"].elements["input_text_TC-3979_1_2"]) {		// TecChannel Kombiabo DE
		var mail = "input_text_TC-3979_1_2";									
	} else if (document.forms["product"].elements["input_text_TC-3977_1_2"]) {		// TecChannel Kombiabo AT
		var mail = "input_text_TC-3977_1_2";										
	} else if (document.forms["product"].elements["input_text_TC-3968_1_2"]) {		// TecChannel Kombiabo CH
		var mail = "input_text_TC-3968_1_2";									
	} else if (document.forms["product"].elements["input_text_TC-3966_1_2"]) {		// TecChannel Kombiabo EU
		var mail = "input_text_TC-3966_1_2";									
	} else if (document.forms["product"].elements["input_text_CW-4329_1_5"]) {		// Computerwoche DE
		var mail = "input_text_CW-4329_1_5";									
	} else if (document.forms["product"].elements["input_text_CW-4326_1_1"]) {		// Computerwoche AT
		var mail = "input_text_CW-4326_1_1";									
	} else if (document.forms["product"].elements["input_text_CW-4327_1_1"]) {		// Computerwoche CH
		var mail = "input_text_CW-4327_1_1";									
	} else if (document.forms["product"].elements["input_text_CW-4328_1_1"]) {		// Computerwoche EU
		var mail = "input_text_CW-4328_1_1";									
	} else {																		// FALLBACK
		var mail = $("table.pr_text_input_field_table input:first").attr("name");
	}
	
	// Texteingabefeld E-Mail-Wiederholung
	if (document.forms["product"].elements["input_text_56-2193_2_1"]) {				// PC-WELT
		var mailcheck = "input_text_56-2193_2_1";								
	} else if (document.forms["product"].elements["input_text_MWP_2_1"]) {			// Macwelt
		var mailcheck = "input_text_MWP_2_1"; 									
	} else if (document.forms["product"].elements["input_text_MPJGR_3_1"]) {		// Macwelt Premium Macbay
		var mailcheck = "input_text_MPJGR_3_1"; 										
	} else if (document.forms["product"].elements["input_text_13-2907_2_1"]) {		// Macwelt Premium 4 Wochen gratis testen (2/08)
		var mailcheck = "input_text_13-2907_2_1"; 										
	} else if (document.forms["product"].elements["input_text_GSPREMIUM_2_1"]) {	// GameStar
		var mailcheck = "input_text_GSPREMIUM_2_1";								
	} else if (document.forms["product"].elements["input_text_TC-3976_2_1"]) {		// TecChannel Privatkunden
		var mailcheck = "input_text_TC-3976_2_1";								
	} else if (document.forms["product"].elements["input_text_TC-3975_2_1"]) {		// TecChannel Studenten
		var mailcheck = "input_text_TC-3975_2_1";								
	} else if (document.forms["product"].elements["input_text_TC-3974_2_1"]) {		// TecChannel Firmen
		var mailcheck = "input_text_TC-3974_2_1";								
	} else if (document.forms["product"].elements["input_text_3-2909_2_1"]) {		// TecChannel Mailing 045
		var mailcheck = "input_text_3-2909_2_1";									
	} else if (document.forms["product"].elements["input_text_14-3000_2_2"]) {		// TecChannel Shopcode 082 Kombiabo DE
		var mailcheck = "input_text_14-3000_2_2";									
	} else if (document.forms["product"].elements["input_text_15-3000_2_2"]) {		// TecChannel Shopcode 082 Kombiabo AT
		var mailcheck = "input_text_15-3000_2_2";									
	} else if (document.forms["product"].elements["input_text_16-3000_2_2"]) {		// TecChannel Shopcode 082 Kombiabo CH
		var mailcheck = "input_text_16-3000_2_2";									
	} else if (document.forms["product"].elements["input_text_17-3000_2_2"]) {		// TecChannel Shopcode 082 Kombiabo EU
		var mailcheck = "input_text_17-3000_2_2";									
	} else if (document.forms["product"].elements["input_text_5-2932_2_1"]) {		// TecChannel Aktion Download
		var mailcheck = "input_text_5-2932_2_1";									
	} else if (document.forms["product"].elements["input_text_5-2958_2_1"]) {		// TecChannel Mailing 049
		var mailcheck = "input_text_5-2958_2_1";									
	} else if (document.forms["product"].elements["input_text_TC-3979_2_2"]) {		// TecChannel Kombiabo DE
		var mailcheck = "input_text_TC-3979_2_2";								
	} else if (document.forms["product"].elements["input_text_TC-3977_2_2"]) {		// TecChannel Kombiabo AT
		var mailcheck = "input_text_TC-3977_2_2";								
	} else if (document.forms["product"].elements["input_text_TC-3968_2_2"]) {		// TecChannel Kombiabo CH
		var mailcheck = "input_text_TC-3968_2_2";								
	} else if (document.forms["product"].elements["input_text_TC-3966_2_2"]) {		// TecChannel Kombiabo EU
		var mailcheck = "input_text_TC-3966_2_2";								
	} else if (document.forms["product"].elements["input_text_CW-4329_2_5"]) {		// Computerwoche DE
		var mailcheck = "input_text_CW-4329_2_5";								
	} else if (document.forms["product"].elements["input_text_CW-4326_2_1"]) {		// Computerwoche AT
		var mailcheck = "input_text_CW-4326_2_1";								
	} else if (document.forms["product"].elements["input_text_CW-4327_2_1"]) {		// Computerwoche CH
		var mailcheck = "input_text_CW-4327_2_1";								
	} else if (document.forms["product"].elements["input_text_CW-4328_2_1"]) {		// Computerwoche EU
		var mailcheck = "input_text_CW-4328_2_1";								
	} else {																		// FALLBACK
		var mailcheck = $("table.pr_text_input_field_table input:last").attr("name");
	}
	
	if(document.forms["product"].elements[mail].value==""){
		alert("Bitte geben Sie Ihre E-Mail-Adresse an.");
		document.forms["product"].elements[mail].focus();
		return false;
	}
	if(document.forms["product"].elements[mailcheck].value==""){
		alert("Bitte wiederholen Sie Ihre E-Mail-Adresse im darunter liegenden Feld.");
		document.forms["product"].elements[mailcheck].focus();
		return false;
	}
	if(document.forms["product"].elements[mailcheck].value!=document.forms["product"].elements[mail].value){
		alert("Die beiden E-Mail-Adressen stimmen nicht \u00FCberein.\nBitte \u00FCberpr\u00FCfen Sie Ihre Angaben.");
		document.forms["product"].elements[mailcheck].focus();
		return false;
	}
	// E-Mail-Adresse prüfen
	if (!isValidEMail(document.forms["product"].elements[mail].value)) {
		alert("Bitte geben Sie eine gültige E-Mail-Adresse ein.");
		document.forms["product"].elements[mail].focus();
		return false;
	}
	
	*/

	// Nutzungsbedingungen akzeptiert?
	if(document.forms["product"].elements["nutzungsbedingungen"] && !document.forms["product"].elements["nutzungsbedingungen"].checked){
		alert("Sie müssen die Nutzungsbedingungen akzeptieren, um bestellen zu k\u00F6nnen.");
		document.forms["product"].elements["nutzungsbedingungen"].focus();
		return false;
	}
	
	return true;
}

function check_input() {
	// return (check_perso() && check_premium() && check_gi());	// 2010-05-26 Premium-E-Mail-Adresse entfernt
	return (check_perso() && check_ipd() && check_gi());
}

function check_perso() {
	var pn = $(":text[maxlength='36']").val();
	if (!pn) return true;
	if(pn.length < 36){
		alert("Personalausweisnummer fehlt oder ist unvollständig!");
		return false;
	} else if (pn=='1220000016D<<6408125<1110078<<<<<<<4') {
		alert("Bitte geben Sie Ihre g\u00FCltige Personalausweisnummer ein!");
		return false;
	}
	return true;
};

/*
function check_premium() {
	var cq = $("form#product :text[maxlength='128']");
	if (cq.size()==2) {
		var e1 = cq.eq(0).val();
		var e2 = cq.eq(1).val();
		if (e1.length==0){
			alert("Bitte geben Sie Ihre E-Mail-Adresse an.");
			cq.eq(0).focus();
			return false;
		} else if (e2.length==0) {
			alert("Bitte wiederholen Sie Ihre E-Mail-Adresse im darunter liegenden Feld.");
			cq.eq(1).focus();
			return false;
		} else if (e1!=e2) {
			alert("Die beiden E-Mail-Adressen stimmen nicht \u00FCberein.\nBitte \u00FCberpr\u00FCfen Sie Ihre Angaben.");
			cq.eq(1).focus();
			return false;
		}
	}
	return true;
};
*/

/*
function check_gravur() {
	var pn = $(":text[maxlength='28']").val();
	if (!pn) return true;
	if (pn.match(/[<>&]+/)) {
		alert("Folgende Zeichen sind leider nicht erlaubt: < > &\nBitte geben Sie stattdessen andere Zeichen ein.");
		return false;
	}
	return true;
};
*/

function check_ipd() {
	var ipd = $(":text[maxlength='30']").val();
	if (ipd===undefined) return true;
	if (ipd.length==0) {
		alert("Passwort fehlt oder ist unvollst\u00E4ndig.");
		return false;
//	} else if (ipd.match(/[<>&]+/)) {
	} else if (!ipd.match(/^[0-9a-zA-ZäöüÄÖÜß_§$%(){}=+#:;,\!\?\[\]\-\.\*]+$/)) {
//		alert("Folgende Zeichen sind leider nicht erlaubt: < > &\nBitte geben Sie stattdessen andere Zeichen ein.");
		alert("Ihr eingegebenes Passwort enth\u00E4lt leider ein oder mehrere ung\u00FCltige Sonderzeichen.\nErlaubt sind folgende Sonderzeichen: +-=!?_§$%#.,:;*. Bitte \u00E4ndern Sie Ihre Eingabe.");
		return false;
	}
	return true;
};

function check_gi() {
	var gi = $(":text[maxlength='9']").val();
	if (gi===undefined) return true;
	if (gi.length==0) {
		alert("GI-Mitgliedsnummer fehlt oder ist unvollst\u00E4ndig.");
		return false;
	} else if (!gi.match(/^(GI-)?([0-9]){1,6}$/)) {
		alert("Die eingegebene GI-Mitgliedsnummer ist unvollst\u00E4ndig oder nicht korrekt.\nBitte korrigieren Sie Ihre Eingaben.");
		return false;
	}
	return true;
};

/* ---------- temporary ---------- */
function check_input_080421() {
	if(!document.forms["address"].elements["datenschutzerklaerung"].checked) {
		alert("Zur Bestellung ist es notwendig, dass Sie die Datenschutzerkl\u00E4rung akzeptieren.");
		document.forms["address"].elements["datenschutzerklaerung"].focus();
		return false;
	}
	return true;
}

/* ----------- Bookshop ------------- */
// JS-Over-States f. manuelles Prod.-Menü
function highlightSecondaryNavigation(catindex) {
	var s = "li." + catindex + ">a";
	$(document).ready(function(){
    	$(s).addClass("selected");
	});
}

// WS-Prod.-Menü per JS teilen
$(document).ready(function(){
//	$("li.gsbookshop:first").insertAfter($("div#cat_ul:first")).wrap('<div id="cat_ul_2"><ul class="level1"></ul></div>');
	$("li.bookshop:first").insertAfter($("div.box_rounded:first")).wrap('<div class="box_rounded"><div class="content"><div id="productmenu"><div id="cat_ul_2"><ul class="level2"></ul></div></div></div></div>');
	// $("div#cat_ul_2").before("<br>Bookshop");
});

/* ---------- Websale ------------------ */
function SubmitSelection() {
	document.forms['product'].js_dep_var.value = "on";
	document.forms['product'].submit();
}

/* ---------- Legacy Stuff ------------- */
function winopen() {
	window.open('/$WS/idg/websale7_shop-idg/benutzer/templates/images/service/personalausweisnummer.html', 'nw', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=400,height=450,left=100,top=100')
}
function opwdvdplus() {
	window.open('/$WS/idg/websale7_shop-idg/benutzer/templates/tt_gamestar/images/popups/dvdplus.html', 'dnw', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=400,height=450,left=100,top=100')
}


