
function isPayform(oForm){
	var retval = false;
	for(var i=0;i<oForm.elements.length;i++){
		if(oForm.elements[i].name == 'SMPAYMETHOD_SELECTOR'){
			retval = true;
			break;
		};
	};
	return(retval);
};

function setActiveForm(formname){
	formname = formname?formname:document.forms[0].name;
	for(var i=0;i<document.forms.length;i++){
		if(isPayform(document.forms[i])){
			if(document.forms[i].name == formname){
				document.forms[i].SMPAYMETHOD_SELECTOR.checked = true;
			} else {
				document.forms[i].SMPAYMETHOD_SELECTOR.checked = false;
			};
		};
	};
};

function totalPayMethodCount(){
	var formCount = 0;
	for(var i=0;i<document.forms.length;i++){
		if(isPayform(document.forms[i])){
			formCount++;
		};
	};
	return(formCount);
};

function hideExclMethods(){
	var relCountryCode = '';
	var relShipToCountryCode = '';
	var relBillToCountryCode = SMShop.getFormValue('BILLTO','BILLTO_COUNTRY', true).toUpperCase();
	var usingShipToAddress = (SMShop.getFormElement("BILLTO", "BILLTO_SHIPTO_DIFFERS") != null);
	var relSelectedItemId = SMShop.getActivePayMethodId();
	var exclMethods = oSMPayMethods.exclMethods, arrExcl = null;
	var sId = '', bAdd = true, sRelId = sSelectFormName = '';
	var iActiveCount = totalPayMethodCount();
	var sErrDesc = getVar('errdesc');

	if(usingShipToAddress){
		usingShipToAddress = cbool(SMShop.getFormValue("BILLTO", "BILLTO_SHIPTO_DIFFERS", true));
	};
	if(usingShipToAddress){
		relShipToCountryCode = SMShop.getFormValue('SHIPTO','SHIPTO_COUNTRY', true).toUpperCase();
	};

	if(sErrDesc.length > 0){
		$('SMPAYERRDESC').innerHTML = sErrDesc;
		$('SMPAYERRDESC').style.display = '';
	} else {
		$('SMPAYERRDESC').style.display = 'none';
	};
	for(var pkid in m_exclPayMethodRegions){
		if(isNaN(pkid)) continue;
		if(usingShipToAddress && oSMPayMethods.payMethods[pkid].isShipCountryBased){
			relCountryCode = relShipToCountryCode;
		} else {
			relCountryCode = relBillToCountryCode;
		};

		if((m_exclPayMethodRegions[pkid].toUpperCase() + ',').indexOf(relCountryCode + ',') > -1){
			arrExcl = exclMethods.split(','); bAdd = true;
			for(var i=0;i<arrExcl.length;i++){
				if(parseInt(arrExcl[i]) == parseInt(pkid)){
					bAdd = false; break;
				};
			};
			if(bAdd){
				if(exclMethods.length > 0) exclMethods += ',';
				exclMethods += pkid.toString();
			};
		};
	};

	if(exclMethods.length > 0){
		arrExcl = exclMethods.split(',');
		for(var j=0;j<arrExcl.length;j++){
			sId = 'SMPAYMETHOD' + arrExcl[j];
			if($(sId)){
				$(sId).style.display = 'none';
				iActiveCount--;
			};
		};
	};

	if(iActiveCount > 0){
		for(var i=0;i<document.forms.length;i++){
			if(isPayform(document.forms[i])){
				sRelId = 'SMPAYMETHOD' + document.forms[i].SMPAYMETHOD_SELECTOR.value;
				if($(sRelId)){
					if($(sRelId).style.display != 'none'){
						sSelectFormName = document.forms[i].name;
						break;
					};
				};
			};
		};
		if(relSelectedItemId.length > 0){
			sRelId = 'SMPAYMETHOD' + relSelectedItemId;
			if($(sRelId)){
				if($(sRelId).style.display != 'none'){
					sRelId = 'SMPAYMETHOD_SELECTOR' + relSelectedItemId;
					if($(sRelId)){
						sSelectFormName = $(sRelId).form.name.toString();
					};
				};
			};
		};
		setActiveForm(sSelectFormName);
	} else {
		if($('SMPAYACTION')){
			$('SMPAYACTION').style.display = 'none';
		};
		if($('SMPAYNOTE')){
			$('SMPAYNOTE').style.display = '';
		};
	};
};

function SMPayMethods_saveRedirect(){
	var oSelectedForm = null, sId = '';
	var oActiveMethod = null, sVerify = '';

	for(var i=0;i<document.forms.length;i++){
		if(isPayform(document.forms[i])){
			if(document.forms[i].SMPAYMETHOD_SELECTOR.checked){
				oSelectedForm = document.forms[i];
				sId = document.forms[i].SMPAYMETHOD_SELECTOR.value;
				oActiveMethod = oSMPayMethods.payMethods[sId];
				oActiveMethod.payForm = oSelectedForm;
				break;
			}
		}
	};

	sVerify = 'SMFRMVerify_' + oSelectedForm.name;
	if(window[sVerify] != null){
		if(window[sVerify]() == false){
			return(false);
		};
	};

	if(SMShop.setPayMethod(oActiveMethod)){
		location.href = SMGetCheckoutStep('SM_RESERVED_DATA_ENTRY_PAYMENT', false);
	};
	return(false);
};

function SMPayMethods_goBack(){
	location.href = SMGetCheckoutStep('SM_RESERVED_DATA_ENTRY_PAYMENT', true);
};

function SMPayMethods(){
	var SMPrice = new cSMPrice(), totalPrice = 0;
	SMPrice.decode(SMShop.basket.getAttribute(_SMADSubTotal));

	this.payMethods = new Array();
	this.exclMethods = SMShop.getActiveShipMethodExclusions();
	this.relTotalPrice = SMShop.getAttribute(_SMAOutGross)!="1" ? SMPrice.net : SMPrice.gross;

	this.addPayMethod = SMPayMethods_addMethod;
	this.addExclMethod = SMPayMethods_addExclMethod;
};

function SMPayMethod(){
	this.id = '';
	this.publicId = '';
	this.name = '';
	this.desc = '';
	this.thumb = '';
	this.chargeType = 0;
	this.chargeValue = 0;
	this.taxkey = 0;
	this.payForm = null;
	this.isShipCountryBased = false;
};

function SMPayMethods_addExclMethod(pkid){
	var arrExcl = null, bAdd = true;
	arrExcl = this.exclMethods.split(',');
	for(var i=0;i<arrExcl.length;i++){
		if(parseInt(arrExcl[i]) == parseInt(pkid)){
			return;
		};
	};
	if(this.exclMethods.length > 0) this.exclMethods += ',';
	this.exclMethods += pkid.toString();
};

function SMPayMethods_addMethod(values){
	var arr = values.split(';');
	var sOrderValue = arr[7];
	var arrOrderValue = null;
	var fromValue = maxValue = 0;

	if(sOrderValue.length > 0){
		arrOrderValue = sOrderValue.split(',');
		fromValue = parseFloat(arrOrderValue[0]);
		maxValue = parseFloat(arrOrderValue[1]);
		if(this.relTotalPrice < fromValue || (maxValue > 0 && this.relTotalPrice > fromValue && this.relTotalPrice > maxValue)){
			this.addExclMethod(arr[0].toString());
			return;
		};
	};

	var oMethod = new SMPayMethod();
	oMethod.id = SX_uEsc(arr[0]);
	oMethod.name = SX_uEsc(arr[1]);
	oMethod.desc = SX_uEsc(arr[2]);
	oMethod.thumb = SX_uEsc(arr[3]);
	oMethod.chargeType = parseFloat(arr[4]);
	oMethod.chargeValue = parseFloat(arr[5]);
	oMethod.taxkey = parseInt(arr[6]);
	oMethod.publicId = SX_uEsc(arr[8]);
	oMethod.isShipCountryBased = cbool(arr[9]);

	this.payMethods[arr[0].toString()] = oMethod;

};

var m_exclPayMethodRegions = new Array();
var oSMPayMethods = new SMPayMethods();

m_exclPayMethodRegions[16] = 'AT';oSMPayMethods.addPayMethod('16;Vorkasse;Versand_20der_20Bestellung_20erfolgt_20nach_20Eingang_20des_20Rechnungsbetrags_20auf_20unser_20Konto_X3_20(Die_20Bankdaten_20finden_20Sie_20in_20der_20Bestellbest_C3_A4tigung_20unten_20rechts)_0D_0A_0D_0A;;1;-3;1;;P_X201015;1');if(SMShop.basket.payMethodInfo.xml.getAttribute(_SMAUniqueID)==""){SMShop.setPayMethod(oSMPayMethods.payMethods[(16).toString()]);};oSMPayMethods.addPayMethod('25;Sofort_C3_BCberweisung;Online_X2_C3_9Cberweisung_20mit_20T_C3_9CV_20gepr_C3_BCftem_20Datenschutz_20ohne_20Registrierung_X3_20Bitte_20halten_20Sie_20Ihre_20Online_X2Banking_X2Daten_20(PIN_X4TAN)_20bereit_X3_20Dienstleistungen_X4Waren_20werden_20bei_20Verf_C3_BCgbarkeit_20SOFORT_20geliefert_20bzw_X3_20versendet!;;0;0;1;;P_X201021;0');if(SMShop.basket.payMethodInfo.xml.getAttribute(_SMAUniqueID)==""){SMShop.setPayMethod(oSMPayMethods.payMethods[(16).toString()]);};m_exclPayMethodRegions[2] = 'AT';oSMPayMethods.addPayMethod('2;Nachnahme;Bezahlen_20Sie_20die_20Rechnung_20bequem_20bei_20Erhalt_20der_20Ware_20per_20Nachnahme_20bei_20Ihrem_20Paketboten_X3_20Minestbestellwert_20200_20Euro_X3_20Der_20Nachnahmebetrag_20entspricht_204_25_20vom_20Bestellwert_20und_20ist_20ein_20Gewichtsspezifischer_20Mittelwert_20der_20Spedition_X4Paketdienst_X3;;1;4;1;200,0;PM_X201002;1');if(SMShop.basket.payMethodInfo.xml.getAttribute(_SMAUniqueID)==""){SMShop.setPayMethod(oSMPayMethods.payMethods[(16).toString()]);};m_exclPayMethodRegions[11] = 'AT';oSMPayMethods.addPayMethod('11;Treuhand;Bezahlen_20Sie_20an_20einen_20Treuh_C3_A4nder_X3_20Wie_20das_20genau_20funktioniert_20lesen_20Sie_20_3Ca_20href=_22http:_X4_X4www_X3iloxx_X3de_X4webprodukte_X4safetrade_X4safetrade_X3asp?sid=34_X7uid=0_22_20target=_22_X5blank_22_3Ehier_3C_X4a_3E;;0;8;1;;P_X201011;1');if(SMShop.basket.payMethodInfo.xml.getAttribute(_SMAUniqueID)==""){SMShop.setPayMethod(oSMPayMethods.payMethods[(16).toString()]);};m_exclPayMethodRegions[5] = 'AT';oSMPayMethods.addPayMethod('5;Rechnung;NUR_20f_C3_BCr_20Beh_C3_B6rden,_20Schulen,_20Universit_C3_A4ten_20oder_20sonst_X3_20_C3_B6ffentliche_20Einrichtungen_X3;;0;0;1;;PM_X201005;1');if(SMShop.basket.payMethodInfo.xml.getAttribute(_SMAUniqueID)==""){SMShop.setPayMethod(oSMPayMethods.payMethods[(16).toString()]);};oSMPayMethods.addPayMethod('13;Moneybookers_20(Lastschrift,_20Kreditkarte,_20giropay);Schnelle_20und_20sichere_20Zahlung_20mit_20Kreditkarte,_20Lastschrift_20oder_20giropay_20_C3_BCber_20Moneybookers_X3_20Ihre_20Daten_20werden_20in_20einem_20eigenen_20Terminal_X2Fenster_20_C3_BCber_20eine_20sichere_20Verbindung_20zu_20Moneybookers_20erfasst_X3;media_X4images_X4moneybookers_X3gif;0;0;1;;P_X201012;0');if(SMShop.basket.payMethodInfo.xml.getAttribute(_SMAUniqueID)==""){SMShop.setPayMethod(oSMPayMethods.payMethods[(16).toString()]);};oSMPayMethods.addPayMethod('22;PayPal;PayPal_20ist_20der_20Online_X2Zahlungsservice,_20mit_20dem_20Sie_20in_20Online_X2Shops_20sicher,_20einfach_20und_20schnell_20bezahlen_20?_20und_20das_20kostenlos_X3;media_X4images_X4paypal_X2logo_X3gif;0;0;1;;P_X201020;0');if(SMShop.basket.payMethodInfo.xml.getAttribute(_SMAUniqueID)==""){SMShop.setPayMethod(oSMPayMethods.payMethods[(16).toString()]);};m_exclPayMethodRegions[23] = 'DE';oSMPayMethods.addPayMethod('23;Vorkasse;Versand_20der_20Bestellung_20erfolgt_20nach_20Eingang_20des_20Rechnungsbetrags_20auf_20unser_20Konto_X3_20(Die_20Bankdaten_20finden_20Sie_20in_20der_20Bestellbest_C3_A4tigung_20unten_20rechts);;0;0;1;;P_X201021;0');if(SMShop.basket.payMethodInfo.xml.getAttribute(_SMAUniqueID)==""){SMShop.setPayMethod(oSMPayMethods.payMethods[(16).toString()]);};