function calculate(ot_module, cost, value, title, tax, string) {

	// Notwenig für die Formatierung bzw. zur Ermittlung des Zahlenwertes aus
	// dem Text
	arr = string.split(';');
	
	// arr ist folgendermaßen aufgebaut
	// 0 1 2
	// 'symbol_right','decimal_point','decimal_places'

	// für den Modultext
	document.getElementById(ot_module + '_title').innerHTML = title;
	//Der Warenwert
	var warenwert = get_value(document.getElementById('ot_subtotal_text').innerHTML);
	
	if (ot_module == 'ot_shipping') {

		// für Gesamtsumme
		// Warenwert plus Versandkosten
		var neu_total = warenwert + value;
		
		// das Ganze formatieren
		var string = format(neu_total, arr);
		
		// und in die Seite einbauen
		document.getElementById('ot_total_text').innerHTML = '<b>' + string + '</b>';
		// für den Modulbetrag
		document.getElementById(ot_module + '_text').innerHTML = format(value,arr);
		
	}

	if (ot_module == 'ot_payment') {
		
		document.getElementById(ot_module + '_title').innerHTML = title;

		var rabatt = value * warenwert;
		var shipping = get_value(document.getElementById('ot_shipping_text').innerHTML);	
		var neu_total = warenwert + cost + shipping - rabatt;
		
		document.getElementById(ot_module + '_text').innerHTML = '<span style="color:#de371c;"> -' + format(rabatt + cost, arr) + '</span>';
				
		if (rabatt == 0)
			document.getElementById(ot_module + '_text').innerHTML = '<b>' + format(cost, arr) + '</b>';
					
		document.getElementById('ot_total_text').innerHTML = '<b>' + format(neu_total, arr) + '</b>';
		
		//die UmSt. neu berechnen und anzeigen	
		if(cost == 0){
			var tax = neu_total / (1 + tax / 100) * (tax / 100);
		}else {
			var tax = neu_total / (1 + tax / 100) * (tax / 100);		
		}
		document.getElementById('ot_tax_text').innerHTML = format(tax, arr);
				
	}
	


	 
}

function get_value(string) {

	if(string.indexOf('-,--')!= -1)return 0;
	string = string.toLowerCase();
	string = string.replace('<b>', '').replace('</b>', '')
	string = string.replace('<span style="color: #de371c">','').replace('<span style="color: rgb(222, 55, 28);">','').replace('</span>', '');
	string = string.replace('.', '');
	
	if (string.indexOf(',') >= 0)
		value = string.replace(',', '.');

	return parseFloat(value);
}

function format(value, arr) {

	var result = value.toFixed(arr[2]);

    var nullen = ' ';
    
    if(result.indexOf('.') == -1)nullen =',00 ';
    backvalue = result.replace('.', arr[1]) + nullen + arr[0];
	return backvalue

}

function redirect(url){
//setTimeout('location.href ='+url,100);
	
	
}


/*  *************************** */

function createXmlHttpRequestObject() {
	var xmlHttp;
	try {
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
				"MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0",
				"MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP");
		for ( var i = 0; i < XmlHttpVersions.length && !xmlHttp; i++) {
			try {
				xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
			} catch (e) {
			}
		}
	}
	if (!xmlHttp)
		alert("Erzeugung XmlHttpRequest Objekt fehlgeschlagen!");
	else
		return xmlHttp;
}

function set_session(key, shipping, select, backlink) {
	
	var xmlHttp = createXmlHttpRequestObject();
	if (!xmlHttp)
		return;

	try {

		var url = "/ax.php?key=" + key + "&name="+ shipping + "&select=" + select;
		
		xmlHttp.open('GET', url, true);
		xmlHttp.send(null);
		
		//Auswahlseite Versand angeklickt
		if(select == 'shipping'){
			//und Auswahl der Selbstanholung
			if (shipping == 'selfpickup_selfpickup') {
				if($("#cod").position()){
					if(document.getElementById('radio_cod').checked == true){
//						Diese Zahlungsweise im Container Calculate wieder rückgängig machen
						document.getElementById('ot_payment_title').innerHTML = '<span style="color:#de371c;">Bitte Zahlungsweise wählen!</span>';
						$oldpaymentvalue = get_value(document.getElementById('ot_payment_text').innerHTML);
						$oldtotalvalue = get_value(document.getElementById('ot_total_text').innerHTML);

						$newtotalvalue =  $oldtotalvalue -  $oldpaymentvalue;
						document.getElementById('ot_total_text').innerHTML = format($newtotalvalue, arr);
						document.getElementById('ot_payment_text').innerHTML = '-,-- '+arr[0];
						alert("Bei Selbstabholung ist Ihre gewählte Bezahlart nicht möglich!");
					}	
				
				$('#cod').hide("fast");

				}
				if($("#paypal").position()){
					if(document.getElementById('radio_paypal').checked == true){
//						Diese Zahlungsweise im Container Calculate wieder rückgängig machen
						document.getElementById('ot_payment_title').innerHTML = '<span style="color:#de371c;">Bitte Zahlungsweise wählen!</span>';
						$oldpaymentvalue = get_value(document.getElementById('ot_payment_text').innerHTML);
						$oldtotalvalue = get_value(document.getElementById('ot_total_text').innerHTML);

						$newtotalvalue =  $oldtotalvalue -  $oldpaymentvalue;
						document.getElementById('ot_total_text').innerHTML = format($newtotalvalue, arr);
						document.getElementById('ot_payment_text').innerHTML = '-,-- '+arr[0];
						alert("Bei Selbstabholung ist Ihre gewählte Bezahlart nicht möglich!");
					}
					
					$('#paypal').hide("fast");
				}
				
				if($("#invoice").position()){
					if(document.getElementById('radio_invoice').checked == true){
//						Diese Zahlungsweise im Container Calculate wieder rückgängig machen
						document.getElementById('ot_payment_title').innerHTML = '<span style="color:#de371c;">Bitte Zahlungsweise wählen!</span>';
						$oldpaymentvalue = get_value(document.getElementById('ot_payment_text').innerHTML);
						$oldtotalvalue = get_value(document.getElementById('ot_total_text').innerHTML);
						
						$newtotalvalue =  $oldtotalvalue -  $oldpaymentvalue;
						document.getElementById('ot_total_text').innerHTML = format($newtotalvalue, arr);
						document.getElementById('ot_payment_text').innerHTML = '-,-- '+arr[0];
						alert("Bei Selbstabholung ist Ihre gewählte Bezahlart nicht möglich!");
					}
					
					$('#invoice').hide("fast");
				}
				
				if($("#cash").position()){
//					$('#cash').show("fast");
				}
				
			}else {  //wenn nicht Selbabholer
				if($("#cash").position()){
					if(document.getElementById('radio_cash').checked == true){
//						Diese Zahlungsweise im Container Calculate wieder rückgängig machen
						document.getElementById('ot_payment_title').innerHTML = '<span style="color:#de371c;">Bitte Zahlungsweise wählen!</span>';
						$oldpaymentvalue = get_value(document.getElementById('ot_payment_text').innerHTML);
						$oldtotalvalue = get_value(document.getElementById('ot_total_text').innerHTML);

						$newtotalvalue =  $oldtotalvalue -  $oldpaymentvalue;
						document.getElementById('ot_total_text').innerHTML = format($newtotalvalue, arr);
						document.getElementById('ot_payment_text').innerHTML = '-,-- '+arr[0];
					}	
					$('#cash').hide("fast");
				}
			
				if($("#cod").position()){
//					$('#cod').show("fast");
				}
				if($("#paypal").position()){
//					$('#paypal').show("fast");
				}
			
			}
			setTimeout('location.href="'+backlink+'"',100);
		}//Ende Versandart gewählt
		
		//Wurde Bezahlart gewählt
		if(select == 'payment'){
//			alert(key+', '+shipping+', '+select);			
		}	
		
	} catch (e) {
		alert("ERROR");
	}
}