
function ScriptInclude(){
	this.src = "";
	this.args = new Array();
	this.set = ScriptInclude_Set;
};

function ScriptInclude_Set(){
	var tmpHTML = "";
	var tmpArgs = "";
	tmpHTML = "<script type='text\/javascript'"
		+ " src='" + this.src + "?";
	for(var i=0; i<this.args.length; i++){
		tmpArgs += this.args[i].replace("/","\/") + "&";
	};
	tmpHTML += tmpArgs;
	tmpHTML	+= "'><\/script>";
	document.write(tmpHTML);
};

var POCCPayment = null;
POCCPayment = new ScriptInclude();
POCCPayment.src = "plugins/payment/smpaypayonecc/decrypt.php";

var sHash = "";
var oPayForm = document.getElementById('SMPayMethodPluginForm');
var products = SMShop.basket.xml.selectNodes(_SMPrd), product = null;

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

var POCC = {};
POCC.k = 0;

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

	sHash += product.getAttribute("cde");
	sHash += product.getAttribute(_SMAAmount);
	sHash += Math.round(product.getPrice(true, true) * 100);
	sHash += SMShop.getActiveRegion()[fnSMPIt(product.getAttribute(_SMARegion)) + 2];

	POCC.k = i + 1;
	RestSum -= Math.round(product.getPrice(true, true) * product.getAttribute(_SMAAmount) * 100);
};

var SMShippingCost = new cSMPrice();
SMShippingCost.decode(SMShop.basket.shipMethodInfo.xml.getAttribute(_SMAPrice));
var ShippingCost = cprimary.format(SMShippingCost.gross, SM_CNOFORMAT) * 100;

var sRestSumText = "Restsumme";

if (ShippingCost == RestSum) sRestSumText = "Versandkosten";

if (RestSum != 0){
	sHash += sRestSumText + "1" + Math.round(RestSum) + SMShop.getActiveRegion()[3];
}

sHash += "EUR";

POCCPayment.args[0] = "param=" + sHash;
POCCPayment.set();

function PAYONECC_doPay(oPayForm, bShowWaitForPay){
	var sFormTarget = 'PaymentTerminal';
	var oWin = null;

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

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

		if (bd_isIE) var InputElementItemNumber = document.createElement('<input name="id[' + i + ']" />');
		else {
			var InputElementItemNumber = document.createElement('input');
			InputElementItemNumber.name = 'id[' + i + ']';
		}
		InputElementItemNumber.setAttribute("value", product.getAttribute("cde"));
		InputElementItemNumber.type = "hidden";
		oPayForm.appendChild(InputElementItemNumber);

		if (bd_isIE) var InputElementQuantity = document.createElement('<input name="no[' + i + ']" />');
		else {
			var InputElementQuantity = document.createElement('input');
			InputElementQuantity.name = 'no[' + i + ']';
		}
		InputElementQuantity.setAttribute("value", product.getAttribute(_SMAAmount));
		InputElementQuantity.type = "hidden";
		oPayForm.appendChild(InputElementQuantity);

		if (bd_isIE) var InputElementItemAmount = document.createElement('<input name="pr[' + i + ']" />');
		else {
			var InputElementItemAmount = document.createElement('input');
			InputElementItemAmount.name = 'pr[' + i  + ']';
		}
		InputElementItemAmount.setAttribute("value", Math.round(product.getPrice(true, true) * 100));
		InputElementItemAmount.type = "hidden";
		oPayForm.appendChild(InputElementItemAmount);

		if (bd_isIE) var InputElementItemName = document.createElement('<input name="de[' + i + ']" />');
		else {
			var InputElementItemName = document.createElement('input');
			InputElementItemName.name = 'de[' + i  + ']';
		}
		InputElementItemName.setAttribute("value", product.name);
		InputElementItemName.type = "hidden";
		oPayForm.appendChild(InputElementItemName);

		if (bd_isIE) var InputElementVAT = document.createElement('<input name="va[' + i + ']" />');
		else {
			var InputElementVAT = document.createElement('input');
			InputElementVAT.name = 'va[' + i  + ']';
		}
		InputElementVAT.setAttribute("value", SMShop.getActiveRegion()[fnSMPIt(product.getAttribute(_SMARegion)) + 2]);
		InputElementVAT.type = "hidden";
		oPayForm.appendChild(InputElementVAT);
	};

	/*
	Anfang: Restsumme als eigenes Produkt berechnen und übergeben
	*/
	if (RestSum != 0){

		if (bd_isIE) var InputElementItemNumber = document.createElement('<input name="id[' + POCC.k + ']" />');
		else {
			var InputElementItemNumber = document.createElement('input');
			InputElementItemNumber.name = 'id[' + POCC.k + ']';
		}
		InputElementItemNumber.setAttribute("value", sRestSumText);
		InputElementItemNumber.type = "hidden";
		oPayForm.appendChild(InputElementItemNumber);

		if (bd_isIE) var InputElementQuantity = document.createElement('<input name="no[' + POCC.k + ']" />');
		else {
			var InputElementQuantity = document.createElement('input');
			InputElementQuantity.name = 'no[' + POCC.k + ']';
		}
		InputElementQuantity.setAttribute("value", "1");
		InputElementQuantity.type = "hidden";
		oPayForm.appendChild(InputElementQuantity);

		if (bd_isIE) var InputElementItemAmount = document.createElement('<input name="pr[' + POCC.k + ']" />');
		else {
			var InputElementItemAmount = document.createElement('input');
			InputElementItemAmount.name = 'pr[' + POCC.k  + ']';
		}
		InputElementItemAmount.setAttribute("value", Math.round(RestSum));
		InputElementItemAmount.type = "hidden";
		oPayForm.appendChild(InputElementItemAmount);

		if (bd_isIE) var InputElementItemName = document.createElement('<input name="de[' + POCC.k + ']" />');
		else {
			var InputElementItemName = document.createElement('input');
			InputElementItemName.name = 'de[' + POCC.k  + ']';
		}
		InputElementItemName.setAttribute("value", sRestSumText);
		InputElementItemName.type = "hidden";
		oPayForm.appendChild(InputElementItemName);

		if (bd_isIE) var InputElementVAT = document.createElement('<input name="va[' + POCC.k + ']" />');
		else {
			var InputElementVAT = document.createElement('input');
			InputElementVAT.name = 'va[' + POCC.k  + ']';
		}
		InputElementVAT.setAttribute("value", SMShop.getActiveRegion()[3]);
		InputElementVAT.type = "hidden";
		oPayForm.appendChild(InputElementVAT);
	}
	/*
	Ende: Restsumme als eigenes Produkt berechnen und übergeben
	*/

	if (bd_isIE) var InputElementHash = document.createElement('<input name="hsh" />');
	else {
		var InputElementHash = document.createElement('input');
		InputElementHash.name = 'hsh';
	}
	InputElementHash.setAttribute("value", sServerHashCC);
	InputElementHash.type = "hidden";
	oPayForm.appendChild(InputElementHash);



	oWin = new SMPopup();

	with(oWin){
		targetName = sFormTarget;
		targetUrl = "https://secure.pay1.de/frontend/";
		locationReplace = true;
		showScroll = true;
		showModal = false;
		pWidth = 500;
		pHeight = 610;
		openPage();
	};

	with(oPayForm){
		action = 'https://secure.pay1.de/frontend/';
		target = sFormTarget;
		submit();
	};

	return(bShowWaitForPay);
};

function PAYONECC_setFieldValue(fieldName, fieldValue){
	switch(fieldName){

		case 'portalid':
			fieldValue = "2011474";
			break;
		case 'aid':
			fieldValue = "15106";
			break;
		case 'mode':
			fieldValue = "live";
			break;
		case 'request':
			fieldValue = "authorization";
			break;

		case 'amount':
			var oAmount = new cSMPrice();
			oAmount.decode(SMShop.basket.getAttribute(_SMAFinalSum));
			fieldValue = Math.round(cprimary.format(oAmount.gross, SM_CNOFORMAT) * 100);
			break;
		case 'currency':
			fieldValue = "EUR";
			break;
		case 'firstname':
			fieldValue = SMShop.getFormValue("BILLTO", "BILLTO_FIRSTNAME");
			break;
		case 'lastname':
			fieldValue = SMShop.getFormValue("BILLTO", "BILLTO_LASTNAME");
			break;
		case 'company':
			fieldValue = SMShop.getFormValue("BILLTO", "BILLTO_COMPANY");
			break;
		case 'street':
			fieldValue = SMShop.getFormValue("BILLTO", "BILLTO_STREET_1");
			break;
		case 'streetnumber':
			fieldValue = fieldValue;
			break;
		case 'zip':
			fieldValue = SMShop.getFormValue("BILLTO", "BILLTO_POSTCODE");
			break;
		case 'city':
			fieldValue = SMShop.getFormValue("BILLTO", "BILLTO_CITY");
			break;
		case 'country':
			fieldValue = SMShop.getFormValue("BILLTO", "BILLTO_COUNTRY");
			break;
		case 'email':
			fieldValue = SMShop.getFormValue("BILLTO", "BILLTO_EMAIL");
			break;
		case 'telephonenumber':
			fieldValue = SMShop.getFormValue("BILLTO", "BILLTO_PHONE_NUMBER");
			break;

	};
	return(fieldValue);
};

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

function PAYONECC_setForwardPayformFieldNames(){
	var sFields = ''; // semicolon separated string with paymethods formfields to show in ordermail
	return(sFields);
};

function PAYONECC_setResponseQueryCaptions(param){
	var sCaption = '';
	switch(param.toLowerCase()){
		case 'transid': sCaption = 'Transaktionsnr.'; break;
		default: sCaption = param;
	};
	return(sCaption);
};
