

function formatprice(value){
	value = value.toString().replace(",",".");
	value = value * 100;
	value = parseFloat(value).toFixed(0);
	if (value < 10) value = "00" + value;
	else if (value < 100) value = "0" + value;
	return(value);
};

function CLICKANDBUY_doPay(oPayForm, bShowWaitForPay){

	var sPrice, sCb_Currency, sCb_Content_Name_Utf, sExternalbdrID;

	var oAmount = new cSMPrice();
	oAmount.decode(SMShop.basket.getAttribute(_SMAFinalSum));
	sPrice = cprimary.format(oAmount.gross, SM_CNOFORMAT);

	sPrice = formatprice(sPrice);

	sCb_Currency = 'EUR';
	sCb_Content_Name_Utf = SMShop.getAttribute("sid");
	sExternalbdrID = SMShop.getAttribute("sid");

	var sMac = hex_md5(sPrice + sExternalbdrID);

	bShowWaitForPay=false;
	oPayForm.action = 'https://eu.clickandbuy.com/newauth/http://premium-63zd70oz1kcby6.eu.clickandbuy.com/redirect.php';
	oPayForm.action += "?price=" + sPrice + "&cb_content_name_utf=" + sCb_Content_Name_Utf + "&externalBDRID=" + sExternalbdrID + "&mac=" + sMac;
	oPayForm.submit();
	return(bShowWaitForPay);

};

function CLICKANDBUY_setFieldValue(fieldName, fieldValue){
	/*
	switch(fieldName){
		case 'price':
			var oAmount = new cSMPrice();
			oAmount.decode(SMShop.basket.getAttribute(_SMAFinalSum));
			fieldValue = cprimary.format(oAmount.gross, SM_CNOFORMAT);
			break;
		case 'cb_currency':
			fieldValue = 'EUR'; break;
		case 'cb_content_name_utf':
			fieldValue = SMShop.getAttribute("sid"); break;
		case 'externalbdrid':
			fieldValue = SMShop.getAttribute("sid"); break;

	};
	return(fieldValue);
	*/
};

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

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

function CLICKANDBUY_setForwardPayformFieldNames(){
	var sFields = 'extbdrid;crn;bdrid;price;currency;timestamp';
	return(sFields);
};

function CLICKANDBUY_setResponseQueryCaptions(param){
	var sCaption = '';
	switch(param.toLowerCase()){
		case 'extbdrid': 
			sCaption = 'Externe BDRID'; 
			break;
		case 'crn': 
			sCaption = 'Kundenreferenznummer'; 
			break;

		case 'bdrid': 
			sCaption = 'BDRID'; 
			break;
		case 'price': 
			sCaption = 'Preis'; 
			break;
		case 'currency': 
			sCaption = 'Währung'; 
			break;
		case 'timestamp': 
			sCaption = 'Transaktionszeit'; 
			break;

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