function report(string) {
	$.jGrowl(string, { sticky: false });
}

function goto(url) {
	window.location.href = url;
}

function bufferImages(img_array) {
	for (i = 0; i < img_array.length; i++) {
		img = new Image();
		img.src = "images/"+img_array[i];
	}
}

function prepareServicePage() {
	$(document).ready(function(){
		bufferImages(pics);
		$('.service_tbl tr').each(
			function(i) {
				$(this).hover(
					function(){
						$(this).find("td").css("backgroundColor", "#b5d6e6");
						$('#service_img').css("display","none");
						$('#service_img').attr("src","images/"+pics[i+1]);
						$('#service_img').fadeIn(anispeed);
					},
					function(){
						$(this).find("td").css("backgroundColor", "");
						$('#service_img').css("display","none");
						$('#service_img').attr("src","images/"+pics[0]);
						$('#service_img').fadeIn(anispeed);
					}
				);
			}
		)
	})
}

function checkEmail(email) {
	regexp = /[A-Za-z0-9.-_]+\@[A-Za-z0-9-.]+\.(com|org|net|lu|be|fr|de|uk|nl|pt|es|eu)$/i;
	return regexp.test(email);
}

function TestCookie() {
	if (!document.cookie) {
		document.cookie = "";
		if (!document.cookie) {
			if (lang == "fr")
				report('Erreur: Cookies ne sont pas accept&eacute; par votre navigateur!');
			else if (lang == "de")
				report('Fehler: Cookies werden von Ihrem Browser nicht angenommen!');
		}
	}
}

function UpdateDOM() {
	$(document).ready(function(){
		TestCookie();
		$('.popup').nyroModal({ minWidth:100, minHeight:100 });
		$('input.main_email_sub').nyroModal({ minWidth:100, minHeight:100 });
		$('#card_screen').serialScroll({
			items: 'li',
			axis: 'x',
			duration: anispeed
		});
		$('#about_screen, #partner_screen').serialScroll({
			items: 'li',
			axis: 'x',
			duration: anispeed
		});
		$('#sort_subcat').serialScroll({
			items: 'li',
			axis: 'y',
			duration: anispeed/4
		});
		$('.sort_logos').hover(
			function(){ $(this).addClass('sort_logos_hover'); },
			function(){ $(this).removeClass('sort_logos_hover'); }
		);
		$('.sort_articles').hover(
			function(){ $(this).addClass('sort_articles_hover'); },
			function(){ $(this).removeClass('sort_articles_hover'); }
		);
		$('.new_articles').hover(
			function(){ $(this).addClass('new_articles_hover'); },
			function(){ $(this).removeClass('new_articles_hover'); }
		);
		$("#page_body").stop().fadeIn(anispeed,function(){
			$.ifixpng("images/pixel.gif");
			$('img').ifixpng();
		});
		if ($('#main_slideshow').size() > 0) {
			$('#main_slideshow').showcase({
				titleBar: {
					enabled:false
				},
				animation: {
					type: "fade"
				},
				navigator: {
					position:"bottom-left",
					showNumber:true,
					css: {
						marginBottom:"7px",
						marginLeft:"9px"
					},
					item: {
						css: {
							backgroundColor: "yellow",
							color: "black",
							width:"24px",
							height:"16px",
							fontWeight: "bold",
							textAlign: "center",
							"-moz-border-radius": "0px",
							"-webkit-border-radius": "0px",
							paddingTop:"4px"
						},
						cssSelected: {
							backgroundColor: "black",
							color: "yellow"
						}
					}
				}
			});
			$('.slidemodal').nyroModal();
		}
		if (document.cookie.indexOf("ticker_vis=0") == -1)
			setTimeout("$('#ticker_img').slideToggle("+anispeed+")", 750);
		else
			$('#ticker_link img').attr("src", "images/ouvrir_"+lang+".png");
	});
}

function ToggleTicker() {
	date = new Date();
	date.setTime(date.getTime()+(1*24*60*60*1000));
	if (!document.cookie)
		ticker_vis_val = 1;
	else if (document.cookie.indexOf("ticker_vis=0") == -1)
		ticker_vis_val = 0;
	else if (document.cookie.indexOf("ticker_vis=1") == -1)
		ticker_vis_val = 1;
	document.cookie = 'ticker_vis='+ticker_vis_val+'; expires='+date.toGMTString();
	$('#ticker_img').slideToggle(anispeed, function(){
		act_img = $('#ticker_link a img').attr("src");
		if (act_img == "images/fermer_"+lang+".png")
			$('#ticker_link img').attr("src", "images/ouvrir_"+lang+".png");
		else
			$('#ticker_link img').attr("src", "images/fermer_"+lang+".png");
	});
}

function checkSortSearch() {
	switch (lang) {
		case "de": rep = "Bitte geben Sie eine Marke mit mindestens 3 Buchstaben ein"; break;
		case "fr": rep = "Veuillez ins&eacute;rer une marque avec au moins 3 lettres"; break;
	}
	if ($('#i_search').val() == "") { report(rep); return false; }
	return true;
}

function showSubCat(n) {
	$('#sort_subcat').trigger('goto',[n+1]);
}

function openPub(i,n,w,h) {
	posX = screen.width/2 - w/2;
	posY = screen.height/2 - h/2 - 35;
	h = h + 35;
	p = "width="+w+",height="+h+",";
	p += "status=no,menubar=no,scrollbars=no,resizable=no,location=no,toolbar=no,";
	p += "left="+posX+",top="+posY;
	window.open("popups/pub_page.php?i="+i+"&n="+n,"pub",p);
}

function openSpecial(w,h) {
	posX = screen.width/2 - w/2;
	posY = screen.height/2 - h/2;
	p = "width="+w+",height="+h+",";
	p += "status=no,menubar=no,scrollbars=no,resizable=no,location=no,toolbar=no,";
	p += "left="+posX+",top="+posY;
	window.open("popups/special_action.php","special",p);
}

function openWindow(f, w, h) {
	posX = screen.width/2 - w/2;
	posY = screen.height/2 - h/2;
	p = "width="+w+",height="+h+",";
	p += "status=no,menubar=no,resizable=no,location=no,toolbar=no,scrollbars=yes,";
	p += "left="+posX+",top="+posY;
	window.open(f, "jobs", p);
}

function nyroModalClose() {
	$.nyroModalRemove();
}

function writeEmail(place) {
	if (place == "strassen") addr = "st900ml";
	if (place == "foetz") addr = "st902ml";
	if (place == "ingeldorf") addr = "st901ml";
	email = addr+"@"+"praktiker"+"."+"com";
	document.write("<a href=\"mailto:"+email+"\">Email</a>");
}

function OpenEmailWin(usr, dom, subj) {
	window.location.href = "mailto:"+usr+"@"+dom+"?subject="+subj;
}

function upperCase(obj) {
	obj.value = obj.value.toUpperCase()
}

function moreInfo(img,usr,dom,subject) {
	h = '<a href="mailto:'+usr+'@'+dom+'?subject='+subject+'">';
		h += '<img src="'+img+'" />';
	h += '</a>'
	document.write(h);
}

function correctLink(obj) {
	if (obj.value.indexOf("?b=") != -1) return;
	else if (obj.value.indexOf("[special]") != -1) return;
	else if (obj.value.indexOf("http://") == -1) obj.value = "http://"+obj.value;
}
