if(!ajaxRequestCollection) var ajaxRequestCollection = new Array();

function addHover(obj, strSuffix)	{
	if(null==strSuffix) strSuffix = '_hover';

	//obj.src=obj.src.replace(new RegExp("("+strSuffix+")*.(\w+)$"), strSuffix+'.$2');
	var rExp = new RegExp('('+strSuffix+')*.(\\w+)$');
	obj.src = obj.src.replace(rExp, strSuffix+'.$2');
}

function remHover(obj, strSuffix)	{
	if(null==strSuffix) strSuffix = '_hover';

	var rExp = new RegExp('('+strSuffix+')*.(\\w+)$');
	obj.src=obj.src.replace(rExp, '.$2');
}

function Tip(){return;}
function UnTip(){return;}

/**
 * Erstellt bzw. entfernt, falls vorhanden, einen Klassenamen von einem Element
 * @param el	Das entsprechende Element, wird übl. mit this übergeben
 * @param cN	Klassenname
 * @return void(0);
 */
function toggle_class(el, cN)	{
	//prüfen ob Klassenname vorhanden:
	var theRegex = new RegExp('\\b'+cN+'\\b','g');
	//console.log(theRegex.test(el.className));
	if(theRegex.test(el.className))	{
		//Klassenname wurde gefunden, also entfernen:
		el.className = el.className.replace(theRegex,'');
	} else {
		//nicht gefunden, hinzufügen:
		el.className+=' '+cN;
	}
}


/**
 * This function is called by an AJAX request when required. used to substitute the dynamic prices.
 * @return void
 */
function substArticlePrices() {
	$$('table.articlelist td.itemprice').each(function(elem, index) {

		//add the event to the textbox to refresh the prices:
		elem.adjacent('td input.amount')[0].observe('keyup', function(event){
			refreshElemPrice(elem);
		});

		//add the AJAX request to the price to retreive it:
		refreshElemPrice(elem);
	});

}

/**
 * Refresh the element price of a single element.
 *
 * @param elem	Element identifier, should be the <td> containing the price.
 * @return void
 */
function refreshElemPrice(elem)	{
	var itemId = parseInt(elem.adjacent('td.itemno span.itemId')[0].firstChild.data);

	var theAmount = parseInt(elem.adjacent('td input.amount')[0].value);
	if(!theAmount || 0==theAmount || isNaN(theAmount)) {
			//theAmount ist keien gültige Zahl, also abbrechen und 'nichts' annehmen
		elem.adjacent('td input.amount')[0].value = '';
		elem.update('&laquo; ' + tx_mevshop_lng.label_fillInQuantitiy);
		return;
	}

	//if(console)console.log('would call index.php?eID=tx_mevshop_dynItemPrice&itemId='+itemId+'&amount='+theAmount);
	//Aufruf: http://schulung.mevaco.de/index.php?eID=tx_mevshop_dynItemPrice&itemId=15396&amount=1

	ajaxRequestCollection.push(new Ajax.Request('index.php',	{
		method:'get',
		parameters: {
			eID: 'tx_mevshop_dynItemPrice',
			'itemId': itemId,
			'amount': theAmount
		},
		onCreate: function()	{
			elem.update('<img src="typo3conf/ext/mevshop/res/img/loadingicon.gif" width="16" height="16" alt="Ladeicon" title="Ihr persönlicher Preis wird geladen..." />');
		},
		onSuccess: function(ajxResp)	{
			if(ajxResp.responseXML && ajxResp.responseXML.getElementsByTagName('errormsg') && ajxResp.responseXML.getElementsByTagName('errormsg')[0])	{
				if(ajxResp.responseXML.getElementsByTagName('errormsg')[0].getAttribute('maxAmount')) {
					Modalbox.show(
						'<span>'+tx_mevshop_lng.errmsg_maxArticleAmount(ajxResp.responseXML.getElementsByTagName('errormsg')[0].getAttribute('maxAmount'))+'</span>'
						,{
							title: tx_mevshop_lng.errmsg_maxArticleAmount_title
						});
				}
				elem.update('..');
			} else if(ajxResp.responseXML && ajxResp.responseXML.getElementsByTagName('itemid') && itemId == parseInt(ajxResp.responseXML.getElementsByTagName('itemid')[0].firstChild.data))	{
				elem.update(ajxResp.responseXML.getElementsByTagName('baseprice')[0].firstChild.data + ' '
							+ ajxResp.responseXML.getElementsByTagName('t3curr')[0].firstChild.data);
			} else {
				elem.update('XX');
			}
		},
		onFailure: function(){ elem.update('XX'); }
	})); //END new ajax.request
}


