document.onmousemove = function(e){
	if(divpopup)
		divpopup.mouseMoving(e);
};

function showProductsOfGroup(id){

	var c = $$(".grp_displayer");

	for(var i = 0; i < c.length; i++){
		c[i].hide();
	}
	$("grp_"+id).show();
}



function printPage() {
	if (window.print) {
		jetztdrucken = 1;//confirm('Seite drucken?');
		if (jetztdrucken) window.print();
	}
}

function mailToIt(param1, linkToIt){
	var title = "Testproduktmail";
	var text = "Produkt: "+param1+"";
	text += "\n"+linkToIt;
	self.location.href = 'mailto:'+"&subject="+title+"&body="+text;
	return false;
}


function volltextsuche(start) {
	$('loadingmini').show();
	//$('volltext_result').innerHTML= '<img src="images/loading_small2.gif" /><img src="images/loading_font.gif" alt="" />';

	new Ajax.Request('ajax/volltextsuche.php?start='+start,	{
		method: 'post',
		parameters: $('volltext_form').serialize(),
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {
		   $('volltext_result').update(t.responseText);
		   $('loadingmini').hide();
		},
		onFailure: function(t) {
			$('volltext_result').update('Error ' + t.status + ' -- ' + t.statusText);
			$('loadingmini').hide();
		}
	});
}

function dlLoad(offset) {
	$('downloads').innerHTML= '<img src="images/loading_small2.gif" /><img src="images/loading_font.gif" alt="" />';

	new Ajax.Request('ajax/downloads.php',
	{
		method: 'get',
		parameters: $('downloadsuche').serialize()+'&offset='+offset,
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {
		   $('downloads').update(t.responseText);
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}
	}
	);
}


function loadSerie(marke, pkat, pukat){
	//$("loading_stelle").show();
	new Ajax.Request("ajax/produkte_serie.php?marke="+marke+"&pkat="+pkat+"&pukat="+pukat, {
		onSuccess: function(t) {
			$("otherprods").show();
			$("otherprods").update(t.responseText);
			//$("loading_stelle").hide();
		},
		onFailure: function(t) {
			$(ziel).update('Error ' + t.status + ' -- ' + t.statusText);
		},
		evalScript: true,
		asynchronous: true
		}
	);
}


function doAjax(method,url,ziel,postform,loadingani,newserialize){
	postform = $(postform);
	$(loadingani).show();
	/*
	var ajaxString = escapeTxt("request('"+method+"','"+url+"','"+ziel+"','"+postform+"','"+loadingani+"',"+newserialize+")");
	if($('hiddenFrame')){
		$('hiddenFrame').src='history.php?request='+ajaxString;
	}
	*/
	if(method=='post' || method=='POST'){
		if(newserialize) var pbody=postform.serialize(true);
		var pbody=postform.serialize();
	}else var pbody="";
	new Ajax.Request(url, {
		method: method,
		postBody: pbody,
		onSuccess: function(t) {
			$(ziel).update(t.responseText);
	$(loadingani).hide();
		},
		onFailure: function(t) {
			$(ziel).update('Error ' + t.status + ' -- ' + t.statusText);
		},
		evalScript: true,
		asynchronous: true
		}
	);
}

function escapeTxt(os){
	var ns='',t,chr='',cc='',tn='';
	for(i=0; i < 256; i++){
		tn = i.toString(16);
		if(tn.length<2)
			tn = "0" + tn;
		cc += tn;
		chr += unescape('%' + tn);
	}
	cc = cc.toUpperCase();
	os.replace(String.fromCharCode(13)+'',"%13");
	for(q = 0; q < os.length; q++){
		t = os.substr(q,1);
		for(i = 0; i < chr.length; i++){
			if(t == chr.substr(i,1)){
				t = t.replace(chr.substr(i,1),"%"+cc.substr(i*2,2));
				i = chr.length;
			}
		}
		ns += t;
	}
	return ns;
}

function d(text){
	if(!$("debug")) document.body.insert("<div id='debug'></div>");
	$("debug").update(text);
	$("debug").setStyle({
		position: "absolute",
		left: "0px",
		top: "0px",
		backgroundColor: "#000000",
		color: "#ffffff",
		zIndex: "111111",
		padding: "1px",
		paddingRight: "3px",
		paddingLeft: "2px"
	});
}


var merkzettel = {
	//merkzettel.add($pkat, $pukat, $grp, $id);
	add: function(id, gid, pukat, pkat, marke){
		new Ajax.Request("/ajax/merkzettel.php?do=add&id="+id+"&gid="+gid+"&pukat="+pukat+"&pkat="+pkat+"&marke="+marke,{
		//new Ajax.Request("ajax/merkzettel.php?do=add&pkat="+pkat+"&pukat="+pukat+"&grp="+grp+"&id="+id+"",{
			method: 'get',
			onSuccess: function(t){
				$("merkzettel").update(t.responseText);
				Effect.Shake($('merkzettel'),{duration:0.2,distance: 3});

			},
			onFailure: function(){
				alert('Something went wrong...')
			}
		});
	},
	remove: function(id, gid, pukat, pkat, marke){
		new Ajax.Request("/ajax/merkzettel.php?do=remove&id="+id+"&gid="+gid+"&pukat="+pukat+"&pkat="+pkat+"&marke="+marke,{
		//new Ajax.Request("ajax/merkzettel.php?do=remove&pkat="+pkat+"&pukat="+pukat+"&grp="+grp+"&id="+id+"",{
			method: 'get',
			onSuccess: function(t){
				$("merkzettel").update(t.responseText);
				Effect.Shake($('merkzettel'),{duration:0.2,distance: 3});
			},
			onFailure: function(){
				alert('Something went wrong...')
			}
		});
	}
};

var termine = {
	loadCalender: function(time){
		var addget = "";
		if(typeof time != "undefined")
			addget = '?go='+time;
		new Ajax.Request('ajax/termine.php'+addget,
		{
			method: 'get',
			onSuccess: function(t){
				$("calender").update(t.responseText);
			},
			onFailure: function(){
				alert('Something went wrong...')
			}
		});
	},
	hideAll: function(){
		$$(".termin_entry").each(function(v,i){
			$(v).removeClassName('termin_entry_on')
		});
	},
	show: function(/*array*/id){
		for(var i = 0; i < id.length; i++){
			e = $("termin_"+id[i]);

			if(e){
				e.addClassName('termin_entry_on')
				//e.down().next(2).show();
			}
		}
	},
	hide: function(/*array*/id){
		for(var i = 0; i < id.length; i++){
			e = $("termin_"+id[i]);

			if(e){
				e.removeClassName('termin_entry_on')
				//e.down().next(2).show();
			}
		}
	}
};

/* whitebox */

var whitebox = {
	alpha: 100,
	visible: 1,
	show: function(){
		$("whitebox_bg").show();
		$("whitebox").show();
		$("whitebox_close").show();
		whitebox.visible = 1;
		whitebox.center();
		$("whitebox_bg").onclick = function(){whitebox.hide()};
	},
	hide: function(){
		$("whitebox_bg").hide();
		$("whitebox_bg").style.left = -100000;
		$("whitebox").hide();
		$("whitebox").style.left    = -100000;
		$("whitebox_close").hide();
		$("whitebox_close").style.left = -100000;
		whitebox.visible = 0;
	},
	toggle: function(){
		if(whitebox.visible)
			whitebox.hide();
		else
			whitebox.show();
	},
	center: function(){
		var w = parseInt($("whitebox").getWidth());
		var h = parseInt($("whitebox").getHeight());
		var b_w = parseInt($("whitebox_bg").getWidth());
		var b_h = parseInt($("whitebox_bg").getHeight());

		$("whitebox").style.left = (b_w/2 - w/2)+"px";
		$("whitebox").style.top = (b_h/2 - h/2)+"px";
		$("whitebox_close").style.left = (b_w/2 - w/2) + w - 84 + "px";
		$("whitebox_close").style.top = (b_h/2 - h/2)+"px";
	},
	setContent: function(t){
		$("whitebox").update(t);
	},
	setLoading: function(){
		whitebox.setContent("loading...");
		whitebox.center();
	},
	loadData: function(what, param){
		whitebox.setLoading();
		whitebox.show();
		document.location.href = document.location.href.replace("#","") + "#"; //im IE prüfen
		switch(what){
			case "mail_empfehlen":{
				new Ajax.Request("ajax/whitebox.php?do="+what+"&"+param,{
					method: 'get',
					onSuccess: function(t){
						whitebox.setContent(t.responseText);
						whitebox.center();
					}
				});
			}break;
		}
	},
	sendData: function(what, param){
		var post = $("whiteboxForm").serialize();
		whitebox.setLoading();
		document.location.href = document.location.href.replace("#","") + "#"; //im IE prüfen
		switch(what){
			case "mail_empfehlen_senden":{
				new Ajax.Request("ajax/whitebox.php?do="+what+"&"+param,{
					method: 'post',
					postBody: post,
					onSuccess: function(t){
						whitebox.setContent(t.responseText);
						whitebox.center();
					}
				});
			}break;
		}
	}
}

