// ---------------------------------------------------------------------
function round(x, n) {
  var a = Math.pow(10, n);
  return (Math.round(x * a) / a);
}
// ---------------------------------------------------------------------
function replaceAll(str, find, rep) {
	var idx = str.indexOf( find );        
	while ( idx > -1 ) {            
		str = str.replace( find, rep );             
		idx = str.indexOf( find );
	}    
	return str;
}
// ---------------------------------------------------------------------
function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ) {
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ) {
      if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ) {
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return strReturn;
}
// ---------------------------------------------------------------------
function raw_popup(url, target, features) {
  if (isUndefined(features)) {
    features = _POPUP_FEATURES;
  }
  if (isUndefined(target)) {
    target = '_blank';
  }
  var theWindow =
    window.open(url, target, features);
  theWindow.focus();
  return theWindow;
}
// ---------------------------------------------------------------------
function link_popup(src, features) {
  return
    raw_popup(src.getAttribute('href'),
    src.getAttribute('target') || '_blank',
    features);
}
// ---------------------------------------------------------------------
function MyTrim(str) {
	return str.replace(/^\s*([^ ]*)\s*$/, '$1');
}
// -------------------------------------------------------------------------
function MyParseFloat(value) {
	return parseFloat(value.replace(/,/, '.'));
}
// --------------------------------------------------------------------------
function toEUR (input)
{
	// Make sure input is a string:
	input += "";
	// Keep original copy of input string:
	var original_input = input;

	// Strip leading dollar sign if necessary:
	if (input . charAt (0) == "$")
		input = input . substring (1, input . length);
	else if
	(
		input . substring (0, 2) == "-$"
	||	input . substring (0, 2) == "+$"
	)
	input = input . charAt (0) + input . substring (2, input . length);

	// Get float value:
	var amount = MyParseFloat (input);

	// Return unmodified input if we weren't able to convert it:
	if (isNaN (amount))
		return original_input;

	// Express amount in pennies, rounded to the nearest penny:
	amount = Math . round (100 * amount);

	// Prepare to add a US currency prefix:
	var prefix = "";
	if (amount < 0)
	{
		prefix = "-" + prefix;
		amount = - amount;
	}

	// Convert amount to string and pad with leading zeros if necessary:
	var string;
	if (amount < 10)
		string = "00" + amount;
	else if (amount < 100)
		string = "0" + amount;
	else
		string = "" + amount;

	// Insert prefix:
	string = prefix + string;
		
	// Insert decimal point before last two digits:
	string =
		string . substring (0, string . length - 2) +
		"," +
		string . substring (string . length - 2, string . length);

	// Return formatted currency string:
	return string;
}
// ---------------------------------------------------------------------
function ClearComboOrList(oList){
	for (var i = oList.options.length - 1; i >= 0; i--){
		oList.options[i] = null;
	}
	oList.options[0] = new Option('die Liste wird geladen...', '0');
	oList.selectedIndex=0;
	if (oList.onchange) oList.onchange();
}
// ---------------------------------------------------------------------
function FillCombobox(oList, arrValue){
	oList.options[0] = new Option('-', '0');
	var m;
	var t;
	var p;
	for (var i = 0; i < arrValue.length; i = i + 1){
		if (arrValue[i] != 'EOF') {
			if (arrValue[i].indexOf(':')>=0) {
				p = arrValue[i].split(':');
				m = p[0];
				if (p[2]=='1') 
				{
					t = p[1];
					oList.options[oList.options.length] = new Option(t, m);
				}
			} else {
				oList.options[oList.options.length] = new Option(arrValue[i], arrValue[i]);
			}
		}
	}
	if (oList.options.length == 1){
		oList.selectedIndex=0;
		if (oList.onchange) oList.onchange();
	}
}
// ---------------------------------------------------------------------
function LieferantDetails(IDProvider, IDSupplier) {
	WAITLAYER.style.pixelTop = (document.body.scrollTop + 250);
	WAITLAYER.style.zIndex = 1000;
	WAITLAYER.style.visibility = "visible"; 

	var sql = 'ecp_get_lieferant ' + IDProvider + ',' + IDSupplier;
	AjaxPro.timeoutPeriod = 15000; 
	Rainbow.DesktopModules.ecpPostbackHandlerControl.TransformEnhancedXSL(sql, 'B2B_LieferantDetail.xsl', LieferantDetails_Response);
}
function LieferantDetails_Response(response)
{
	var s = response.value;
	if (s) {
	} else {
		s = 'Die Lieferantendetails konnten nicht geladen werden...';
	}
	document.getElementById('LieferantDetails').innerHTML = s;
	WAITLAYER.style.visibility = "hidden"; 
	LIEFERANTDETAILSLAYER.style.pixelTop = (document.body.scrollTop + 100);
	LIEFERANTDETAILSLAYER.style.zIndex = 1000;
	LIEFERANTDETAILSLAYER.style.visibility = "visible"; 

	window.status = 'Fertig...';
}
// ---------------------------------------------------------------------
function LieferantDetailsClose()
{
	LIEFERANTDETAILSLAYER.style.visibility = "hidden"; 
}
// ---------------------------------------------------------------------
function ArtikelDetails(IDProvider, IDCustomer, IDItem) {
	window.status = 'Die Artikeldaten werden gelesen...';
	WAITLAYER.style.pixelTop = (document.body.scrollTop + 100);
	WAITLAYER.style.zIndex = 1000;
	WAITLAYER.style.visibility = "visible"; 

	var sql = "ecp_get_product '" + IDProvider + "','" + IDCustomer + "','" + IDItem + "'";
	//window.clipboardData.setData('Text', sql);

	AjaxPro.timeoutPeriod = 30000; 
	Rainbow.DesktopModules.ecpPostbackHandlerControl.TransformEnhancedXSL(sql, 'B2B_ProduktDetail.xsl', ArtikelDetails_Response);
}
function ArtikelDetails_Response(response)
{
	var s = response.value;
	if (s) {
	} else {
		s = 'Die Artikeldetails konnten nicht geladen werden...';
	}
	document.getElementById('ArtikelDetails').innerHTML = s;
	if (document.getElementById('ProductImage')) {
		if (document.getElementById('ProductImage').width>300) {
			document.getElementById('ProductImage').style.width=300;
		}
		if (document.getElementById('ProductImage').height>300) {
			document.getElementById('ProductImage').style.height=300;
		}
	}
	WAITLAYER.style.visibility = "hidden"; 
	DETAILSLAYER.style.pixelTop = (document.body.scrollTop + 100);
	DETAILSLAYER.style.zIndex = 1000;
	DETAILSLAYER.style.visibility = "visible"; 

	if (document.getElementById('ecpDetailMessage')) {
		var message = document.getElementById('ecpDetailMessage').value;
		if (message) {
			ShowMessage(message);
		}
	}
	DETAILSLAYER.focus();
	DETAILSLAYER.onkeypress= ArtikelDetailsClose;
	ArtikelDetailsInit();
	window.status = 'Fertig...';
}
// ---------------------------------------------------------------------
function ArtikelDetailsInit()
{
	if (document.getElementById('ecpIsAngebot')) {
		var isAngebot = document.getElementById('ecpDetailIstAngebot').value;
		if (isAngebot=='true') {
			document.getElementById('ecpIsAngebot').checked = true;
		}
	}
	var ean = document.getElementById('ecpDetailEAN').value;
	AjaxPro.timeoutPeriod = 15000; 
	Rainbow.DesktopModules.ecpPostbackHandlerControl.ItemInfoAdvanced(ean, ArtikelDetailsInfoAdvanced_Response);
	Rainbow.DesktopModules.ecpPostbackHandlerControl.ItemInfoTests(ean, ArtikelDetailsInfoTests_Response);
}
function ArtikelDetailsInfoAdvanced_Response(response)
{
	var s = response.value;
	if (s) {
		var seg = s.split('|');
		var iPreview = seg[2];
		var iDetail  = seg[3];
		var sHead  = seg[4];
		var sShort = seg[5];
		var sLong  = seg[6];
		var sText = '';
		if (iDetail) {
			if (document.getElementById('ecpDetailImagePreview')) { document.getElementById('ecpDetailImagePreview').value = iDetail;}
			if (document.getElementById('ProductImage')) { if (!document.getElementById('ProductImage').src) {document.getElementById('ProductImage').src = iDetail};}
		}
		if (iDetail) document.getElementById('ecpDetailImageDetail').value = iDetail;
		if (sHead) sText = sText + sHead + '<br/>';
		if (sShort) sText = sText + sShort + '<br/>';
		if (sLong) sText = sText + sLong;
		if (sText) {
			document.getElementById('itemDescription').innerHTML = sText;
		}
	}
}
function ArtikelDetailsInfoTests_Response(response)
{
	var s = response.value;
	if (s) {
		var seg = s.split('|');
		var sText = '';
		if (s.indexOf('~') > 0) {
			sText = sText + '<table border="0">';
			sText = sText + '<tr class="SubHead">';
			sText = sText + '<td>' + 'Ausgabe' + '</td>';
			sText = sText + '<td>' + 'Medium' + '</td>';
			sText = sText + '<td>' + 'Gr&#246;sse' + '</td>';
			sText = sText + '<td>' + 'Urteil' + '</td>';
			sText = sText + '</tr>';

			for (var i = seg.length-1; i >=0; i = i - 1) {

				sText = sText + '<tr>';
				sText = sText + '<td colspan=&#034;4&#034;>' + '<hr/>' + '</td>';
				sText = sText + '</tr>';
				var subs = seg[i];
				var sub = subs.split('~');
				var sNr = sub[0];
				var sAusgabe  = sub[1];
				var sMedium  = sub[2];
				var sDimension = sub[3];
				var sUrteil  = sub[4].replace('&#132;','"').replace('&#147;','"').replace('&#148;','"').replace('&#150;','-').replace('&#150;','-');
				sText = sText + '<tr>';
				sText = sText + '<td>' + sAusgabe + '</td>';
				sText = sText + '<td>' + sMedium + '</td>';
				sText = sText + '<td>' + sDimension + '</td>';
				sText = sText + '<td>' + sUrteil + '</td>';
				sText = sText + '</tr>';

			}
			sText = sText + '</table>';
		}
		document.getElementById('itemTests').innerHTML = sText;
	}
}
// --------------------------------------------------------------------------
function ArtikelDetailsClose()
{
	DETAILSLAYER.style.visibility = "hidden"; 
}
// ---------------------------------------------------------------------
function ShowLayImage(imageSrc, imageName)
{
	//alert(imageSrc);
	document.getElementById('Bildtitel').innerText = imageName;
	document.getElementById('Bildtitel').innerHTML = imageName;
	document._ctl2.prevImage.src = imageSrc;
	IMAGELAY.style.pixelTop = (document.body.scrollTop + 200);
	IMAGELAY.style.visibility = "visible"; 
}
// --------------------------------------------------------------------------
function HideLayImage()
{
	IMAGELAY.style.visibility = "hidden"; 
}
// --------------------------------------------------------------------------
function ShowMessage(message)
{
	document.getElementById('Message').innerText = message;
	document.getElementById('Message').firstChild.nodeValue = message;
	MESSAGELAY.style.visibility = "visible"; 
}
// --------------------------------------------------------------------------
function HideMessage()
{
	MESSAGELAY.style.visibility = "hidden"; 
}
// --------------------------------------------------------------------------
function SetAngebotsartikel(isAngebot)
{
	var artnr = document.getElementById('ecpDetailSupplierProductID').value;
	if (isAngebot) {
		AjaxPro.timeoutPeriod = 5000; 
		Rainbow.DesktopModules.ecpPostbackHandlerControl.SetSpecialOfferForItemnumber(artnr, 1, 1, SetAngebotsartikel_Response);
	} else {
		AjaxPro.timeoutPeriod = 5000; 
		Rainbow.DesktopModules.ecpPostbackHandlerControl.SetSpecialOfferForItemnumber(artnr, 0, 1, SetAngebotsartikel_Response);
	}
}
// --------------------------------------------------------------------------
function SetAngebotsartikelEAN(isAngebot)
{
	var artnr = document.getElementById('ecpDetailEAN').value;
	if (isAngebot) {
		AjaxPro.timeoutPeriod = 5000; 
		Rainbow.DesktopModules.ecpPostbackHandlerControl.SetSpecialOfferForItemnumber(artnr, 1, 1, SetAngebotsartikel_Response);
	} else {
		AjaxPro.timeoutPeriod = 5000; 
		Rainbow.DesktopModules.ecpPostbackHandlerControl.SetSpecialOfferForItemnumber(artnr, 0, 1, SetAngebotsartikel_Response);
	}
}
// --------------------------------------------------------------------------
function SetAngebotsartikel_Response(response)
{
	var s = response.value;
	if (s) {
	}
}
// --------------------------------------------------------------------------
function Stockinfo(ean) {
	if (ean.length==0) {
		alert('Es wurde keine gültige Artikelnummer (EAN) abgefragt!');
	} else {
		WAITLAYER.style.pixelTop = (document.body.scrollTop + 250);
		WAITLAYER.style.visibility = "visible"; 

		var sql = "ecpGetStockInfoAdvanced '" + ean + "'";
		AjaxPro.timeoutPeriod = 15000; 
		Rainbow.DesktopModules.ecpPostbackHandlerControl.TransformEnhancedXSL(sql, 'StockinfoDetails.xsl', TransformStockInfo_Response)
	}
}
function TransformStockInfo_Response(response)
{
	WAITLAYER.style.visibility = "hidden"; 
	var s = response.value;
	if (s) {
		STOCKINFOLAYER.style.visibility = "visible"; 
		document.getElementById('Infocontent').innerHTML = s;
	}
}
function HideStockinfo() 
{
	STOCKINFOLAYER.style.visibility = "hidden"; 
}
// -------------------------------------------------------------------------
function KombiAddToCart(IDArtikel, KombiIDArtikel) {
	var sIDs = IDArtikel + '|' + KombiIDArtikel;
	AjaxPro.timeoutPeriod = 10000; 
	Rainbow.DesktopModules.ecpPostbackHandlerControl.CombiAddToCart(sIDs,2, KombiAddToCart_Response);
}
function KombiAddToCart_Response(response)
{
	var s = response.value;
	if (s=='') {
		window.location.href = '/site/302/Warenkorb.aspx';
	} else {
		alert('Beim Einfügen der Artikel in den Warenkorb ist ein Fehler aufgetreten: ' + s);
	}
}
// -------------------------------------------------------------------------
function SendMail(from, to, subject, content) {
	AjaxPro.timeoutPeriod = 10000; 
	Rainbow.DesktopModules.ecpPostbackHandlerControl.MailFormData(from,to,subject,content,SendMail_Response);
}
function SendMail_Response(response)
{
	var s = response.value;
	if (s=='') {
		alert('Ihre Nachricht wurde erfolgreich versendet.');
	} else {
		alert('Ihre Nachricht konnte NICHT erfolgreich versendet werden. Fehler: ' + s);
	}
}
// -------------------------------------------------------------------------

