function trackURL(URL){

	var turl = 'http://www.apomio.de/trackURL.php?url='+escape(URL);
	var myAjax = new Ajax.Request( turl);
}

/**
 * HIGHLY DECREPEATED
 */
function clickCount(pzn){

	return true;
}

function displayCart(){

  new Ajax.Updater('shoppingcart', '/warenkorb/index', {asynchronous:true, evalScripts:true, onComplete:calculatePrice});
}

function subFromCart(pzn, name, loadfullsite){

	var url = '/warenkorb/sub/pzn/'+escape(pzn)+'/old/false';

	if(loadfullsite) {

		disableWkControl();
		new Ajax.Updater('cart', url, {asynchronous:true, evalScripts:true,  onComplete:function() {reloadWkList(); }});
	} else {

		new Ajax.Updater('cart', url, {asynchronous:true, evalScripts:true, onComplete:calculatePrice});
	}
}

function addToCart(pzn, loadfullsite, redirect){

	var url = '/warenkorb/add/pzn/'+escape(pzn)+'/old/false';
	var element = document.getElementById('shoppingcart');

	if(loadfullsite) {

		//var url = '/warenkorb/add/pzn/'+escape(pzn)+'/old/true';
		disableWkControl();
		new Ajax.Updater('cart', url, {asynchronous:true, evalScripts:true, onComplete:function() {reloadWkList();}});
	} else {

		if(redirect) {

			document.location.href = '/warenkorb/add/pzn/'+escape(pzn)+'/old/true';
		} else {

			new Ajax.Updater('cart', url, {asynchronous:true, evalScripts:true, onComplete:calculatePrice});
			showBestaetigung();
		}
	}
}

function calculatePrice(xmlHttpRequest){

		//var url = 'http://www.apomio.de/index.php?id=2&type=27&tx_stgajaxresponder_pi1[action]=calcPrice';
		//var pars = '';//'action=calcPrice';
		//var myAjax = new Ajax.Request( url, { onComplete:appendToCart, method: 'get', parameters: pars});
}

function appendToCart(originalRequest) {
		var y = $('warenkorb_background');

		y.innerHTML = y.innerHTML+originalRequest.responseText;
}

function showCart(originalRequest) {

	var y = $('shoppingcart');
	y.innerHTML = originalRequest.responseText;
	calculatePrice(originalRequest);
}

function removeFromCart(pzn, loadfullsite){

	var url = '/warenkorb/remove/pzn/'+escape(pzn)+'/old/false';

	if(loadfullsite) {

		disableWkControl();
		var myAjax = new Ajax.Updater( 'cart', url, {asynchronous:true, evalScripts:true, onComplete:function() {reloadWkList();}});
	} else {

		var myAjax = new Ajax.Updater( 'cart', url, {asynchronous:true, evalScripts:true, onComplete:calculatePrice});
	}
}


function redirectFunction(originalRequest){
	urlR = originalRequest.responseText;
	//werbung=window.open(url,'Weiterleitung');
	//if(werbung == NULL)
	//	window.location.href = url;
		window.location.href= urlR;
	//werbung.focus;

}

function disableWkControl() {

	if($('wk_schutz')) {

		document.getElementById('wk_schutz').style.display      = 'block';
		document.getElementById('wk_inner_shutz').style.display = 'block';
	}
}

function enableWkControl() {

	if($('wk_schutz')) {

		document.getElementById('wk_schutz').style.display      = 'none';
		document.getElementById('wk_inner_shutz').style.display = 'none';
	}
}

function reloadWkList() {

	new Ajax.Updater('ajaxLoadCart', '/warenkorb/ajaxLoadList.html', {asynchronous:true, evalScripts:true, onComplete: function() {enableWkControl();}});
}

var ajax_wk_window;

function showBestaetigung() {

	new Ajax.Updater('cart_div', '/warenkorb/ajaxShowBest.html', {asynchronous:true, evalScripts:true, onComplete: function() { $('cart_div').style.display = 'block'; window.setTimeout("closeBestaetigung();", 3000);}});
}

function closeBestaetigung() {

 $('cart_div').style.display = 'none';
}


/*
 * LEGACY FOR USERBACKEND START
 */
function addToCartOld(pzn){

	var url = '/warenkorb/add/pzn/'+escape(pzn)+'/old/true';
	var element = document.getElementById('shoppingcart');
	element.style.display = 'none';
	element.className     = 'in-basket-box';
	element.style.display = 'block';
	new Ajax.Updater('shoppingcart', url, {asynchronous:true, evalScripts:true, onComplete:calculatePrice});
}

function removeFromCartOld(pzn){

	var url = '/warenkorb/remove/pzn/'+escape(pzn)+'/old/true';
	var myAjax = new Ajax.Updater( 'shoppingcart', url, {asynchronous:true, evalScripts:true, onComplete:calculatePrice});
}

function subFromCartOld(pzn){

	var url = '/warenkorb/sub/pzn/'+escape(pzn)+'/old/true';
	new Ajax.Updater('shoppingcart', url, {asynchronous:true, evalScripts:true, onComplete:calculatePrice});
}
/*
 * LEGACY FOR USERBACKEND END
 */
