

function tidyIclearString(value){
	value = value.replace(/::/g , "");
	return(value);
};

function ICLEAR_doPay(oPayForm, bShowWaitForPay){

	var sAction = "https://www.iclear.de/servlets/GenBuyTool";
	var sShopId, sBasketID, sCur, iProductindex, sProducts = "" , sUser_Def = "";

	sShopId = '2000004368';
	sBasketID = SMShop.getAttribute("sid");
	sCur = 'EUR';

	var products = SMShop.basket.xml.selectNodes(_SMPrd), product = null;

	iProductindex = products.length();

	for(var i=0; i < products.length(); i++){
		product = new cSMProduct();
		product.init(products.item(i));

		sProducts += tidyIclearString(product.name) + "::"
			+ tidyIclearString(product.getAttribute(_SMACode)) + "::"
			+ product.getAttribute(_SMAAmount)  + "::"
			+ product.getPrice(true, false)  + "::"
			+ product.getPrice(true, true) + "::"
			+ SMShop.getActiveRegion()[parseInt(product.getAttribute(_SMARegion)) + 2]
			+ ":::";
	};

	//Versandkosten als Artikel anhngen
       	var SMPrice = new cSMPrice();
       	SMPrice.decode(SMShop.basket.shipMethodInfo.xml.getAttribute(_SMAPrice));
       	var mwst = (((SMPrice.gross - SMPrice.net) * 100)/SMPrice.net).toString();
       	var iPos = mwst.indexOf(".");
	mwst = mwst.substring(0, iPos);
       	sProducts += "Versandkosten::99999::1::" + SMPrice.net + "::" + SMPrice.gross + "::" + mwst + ":::";

       	SMPrice = new cSMPrice();
       	SMPrice.decode(SMShop.basket.payMethodInfo.xml.getAttribute(_SMAPrice));
       	mwst = (((SMPrice.gross - SMPrice.net) * 100)/SMPrice.net).toString();
       	var iPos = mwst.indexOf(".");
	mwst = mwst.substring(0, iPos);
       	sProducts += "Zahlartgebühren::99998::1::" + SMPrice.net + "::" + SMPrice.gross + "::" + mwst + ":::";

	sUser_Def = "";

	sAction += "?ShopID=" + sShopId + "&BasketID=" + sBasketID + "&Currency=" + sCur + "&ProductIndex=" + iProductindex + "&Products=" + sProducts + "&User_Def=" + sUser_Def;

	var sFormTarget = 'PaymentTerminal';
	var oWin = null;

	oWin = new SMPopup();
	with(oWin){
		targetName = sFormTarget;
		locationReplace = true;
		showScroll = true;
		showModal = false;
		pWidth = 800;
		pHeight = 560;
		openPage();
	};

	with(oPayForm){
		action = sAction;
		target = sFormTarget;
		submit();
	};

	return(bShowWaitForPay);
};

function ICLEAR_setFieldValue(fieldName, fieldValue){
	return(fieldValue);
};

function ICLEAR_beforeSendOrder(params, cancel){
	return(cancel);
};

function ICLEAR_removePayFormFields(){
	return(true);
};

function ICLEAR_setForwardPayformFieldNames(){
	var sFields = '';
	return(sFields);
};

function ICLEAR_setResponseQueryCaptions(param){
	var sCaption = '';
	switch(param.toLowerCase()){
		case 'ca':
			sCaption = '<br><b>Iclear Kundenadresse</b>';
			break;
		case 'sa':
			sCaption = '<br><b>Iclear Lieferadresse</b>';
			break;
		case 'kundennummer':
			sCaption = '<br><b>IClear Kundennummer</b>';
			break;
		case 'user_def':
			sCaption = '<br><b>Benutzerdefinierte Daten</b>';
			break;
		case 'cname': 
			sCaption = 'Name';
			break;
		case 'cvorname': 
			sCaption = 'Vorname';
			break;
		case 'cfirma1':
			sCaption = 'Firma1';
			break;
		case 'cfirma2':
			sCaption = 'Firma2';
			break;
		case 'cstrasse':
			sCaption = 'Strasse';
			break;
		case 'cplz':
			sCaption = 'PLZ';
			break;
		case 'cort':
			sCaption = 'Ort';
			break;
		case 'cland':
			sCaption = 'Land';
			break;
		case 'ctelefon':
			sCaption = 'Telefon';
			break;
		case 'sname': 
			sCaption = 'Name';
			break;
		case 'svorname': 
			sCaption = 'Vorname';
			break;
		case 'sfirma1':
			sCaption = 'Firma1';
			break;
		case 'sfirma2':
			sCaption = 'Firma2';
			break;
		case 'sstrasse':
			sCaption = 'Strasse';
			break;
		case 'splz':
			sCaption = 'PLZ';
			break;
		case 'sort':
			sCaption = 'Ort';
			break;
		case 'sland':
			sCaption = 'Land';
			break;
		case 'stelefon':
			sCaption = 'Telefon';
			break;

		default:
			sCaption = param;
	};
	return(sCaption);
};
