
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[1] = 'AL,DZ,AS,AI,AG,AM,AW,BS,BH,BD,BB,BY,BZ,BJ,BM,BO,BV,BR,IO,BN,BF,BI,KH,CM,CV,KY,CF,TD,CX,CC,CO,KM,CG,CD,CK,CR,CI,CU,DJ,DM,DO,EC,EG,SV,GQ,ER,ET,FK,FJ,GF,PF,TF,GA,GM,GE,GH,GI,GL,GD,GP,GU,GT,GN,GW,GY,HM,HN,IR,IQ,JM,JO,KZ,KE,KI,KP,KR,KW,KG,LA,LB,LS,LR,LY,LT,MO,MG,MW,MY,MV,ML,MH,MQ,MR,MU,YT,FM,MN,MS,MM,NR,NP,AN,NC,NU,NF,MP,OM,PK,PW,PS,PE,PH,PN,PR,QA,RE,RO,RW,SH,KN,LC,PM,VC,WS,ST,CS,SC,SL,SB,SO,GS,LK,SR,SJ,SZ,SY,TJ,TL,TK,TO,TT,TM,TC,TV,UM,UZ,VU,VN,VG,VI,WF';oSMPayMethods.addPayMethod('1;Vorkasse;Versand_20der_20Bestellung_20erfolgt,_20wenn_20Ware_20an_20Lager,_20nach_20Eingang_20des_20Rechnungsbetrags_20auf_20unser_20Konto_X3;;1;-3;1;;PM_X201001;0');if(SMShop.basket.payMethodInfo.xml.getAttribute(_SMAUniqueID)==""){SMShop.setPayMethod(oSMPayMethods.payMethods[(1).toString()]);};m_exclPayMethodRegions[8] = 'AX,AL,DZ,AI,AG,BH,BY,BZ,BO,IO,BN,BF,KH,KY,CF,TD,KM,CG,CD,CI,CU,PF,TF,GA,GM,GE,GH,GL,GD,GP,GU,GT,GN,GW,GY,IS,IR,IQ,JO,KZ,KE,KI,LB,LS,LT,MO,MW,ML,YT,MS,MM,NR,AN,NC,NU,OM,PK,PW,PN,PR,QA,RW,SH,KN,LC,PM,VC,SL,SB,SO,GS,SR,SZ,SY,TJ,TL,TK,TO,TT,TM,TV,UZ,VU';oSMPayMethods.addPayMethod('8;WorldPay;Schnelle_20und_20sichere_20Zahlung_20mit_20Kreditkarte_20_C3_BCber_20WorldPay_X3_20Ihre_20Daten_20werden_20in_20einem_20eigenen_20Terminal_X2Fenster_20_C3_BCber_20eine_20sichere_20Verbindung_20zu_20WorldPay_20erfasst_X3_20_3Cb_3E_3Ca_20href=_22http:_X4_X4www_X3gummistiefelstore_X3de_X4how_X2to_X2order_X3htm_22_3EHelp_20how_20to_20order?_20_0D_0A_3C_X4a_3E_3C_X4b_3E;media_X4images_X4worldpay_X3gif;1;1.899999976158142;1;;P_X201009;0');if(SMShop.basket.payMethodInfo.xml.getAttribute(_SMAUniqueID)==""){SMShop.setPayMethod(oSMPayMethods.payMethods[(1).toString()]);};oSMPayMethods.addPayMethod('31;PayPal;Schnelle_20und_20sichere_20Zahlung_20mit_20PayPal_X3_20Ihre_20Daten_20werden_20in_20einem_20eigenen_20Terminal_X2Fenster_20_C3_BCber_20eine_20sichere_20Verbindung_20zu_20PayPal_20erfasst_X3;media_X4images_X4paypal_X3gif;1;1.899999976158142;1;;P_X201028;1');if(SMShop.basket.payMethodInfo.xml.getAttribute(_SMAUniqueID)==""){SMShop.setPayMethod(oSMPayMethods.payMethods[(1).toString()]);};m_exclPayMethodRegions[32] = 'AX,AL,DZ,AS,AI,AQ,AG,AM,AW,BS,BH,BB,BY,BZ,BJ,BO,IO,BN,BF,BI,KH,CM,CV,KY,CF,TD,CX,CC,KM,CG,CD,CK,CI,CU,DJ,DM,ET,PF,TF,GA,GM,GE,GH,GI,GL,GD,GP,GU,GN,GW,GY,HM,HN,IR,IQ,JM,JO,KE,KI,KG,LA,LB,MO,MG,MW,MV,MH,MQ,MR,MU,YT,FM,MD,MN,MS,MM,NR,NP,AN,NC,NU,NF,MP,OM,PW,PS,PH,PN,PR,QA,RE,RW,SH,KN,LC,PM,VC,WS,ST,CS,SC,SL,SB,SO,GS,SR,SJ,SZ,TJ,TL,TK,TO,TT,TN,TM,TC,TV,UM,VU,VG,VI,WF';oSMPayMethods.addPayMethod('32;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_X201029;1');if(SMShop.basket.payMethodInfo.xml.getAttribute(_SMAUniqueID)==""){SMShop.setPayMethod(oSMPayMethods.payMethods[(1).toString()]);};m_exclPayMethodRegions[18] = 'AX,AL,DZ,AS,AD,AI,AQ,AG,AR,AM,AW,AU,BS,BH,BD,BB,BY,BE,BZ,BJ,BM,BO,BA,BV,BR,IO,BN,BG,BF,BI,KH,CM,CA,CV,KY,CF,TD,CL,CN,CX,CC,CO,KM,CG,CD,CK,CR,CI,HR,CU,CY,CZ,DK,DJ,DM,DO,EC,EG,SV,GQ,ER,EE,ET,FK,FO,FJ,FI,FR,GF,PF,TF,GA,GM,GE,GH,GI,EL,GL,GD,GP,GU,GT,GN,GW,GY,HT,HM,HN,HK,HU,IS,IN,ID,IR,IQ,IE,IL,IT,JM,JP,JO,KZ,KE,KI,KP,KR,KW,KG,LA,LV,LB,LS,LR,LY,LI,LT,LU,MO,MK,MG,MW,MY,MV,ML,MT,MH,MQ,MR,MU,YT,MX,FM,MD,MC,MN,MS,MA,MM,NR,NP,NL,AN,NC,NZ,NU,NF,MP,NO,OM,PK,PW,PS,PE,PH,PN,PL,PT,PR,QA,RE,RO,RU,RW,SH,KN,LC,PM,VC,WS,SM,ST,SA,CS,SC,SL,SG,SK,SI,SB,SO,GS,ES,LK,SR,SJ,SZ,SE,SY,TW,TJ,TH,TL,TK,TO,TT,TN,TR,TM,TC,TV,UA,AE,GB,UM,US,UZ,VU,VA,VN,VG,VI,WF';oSMPayMethods.addPayMethod('18;iclear_20Paymentsystem;Schnelle_20und_20sichere_20Zahlung_20mit_20iclear_X3_20Ihre_20Daten_20werden_20in_20einem_20eigenen_20Terminal_X2Fenster_20_C3_BCber_20eine_20sichere_20Verbindung_20zu_20iclear_20erfasst_X3_20Weitere_20Informationen_20zu_20iclear_20erhalten_20Sie_20unter_20www_X3iclear_X3de;media_X4images_X4iclear_X3gif;0;1;1;;P_X201016;1');if(SMShop.basket.payMethodInfo.xml.getAttribute(_SMAUniqueID)==""){SMShop.setPayMethod(oSMPayMethods.payMethods[(1).toString()]);};m_exclPayMethodRegions[20] = 'AT,CH,AX,AL,DZ,AS,AD,AI,AQ,AG,AR,AM,AW,AU,BS,BH,BD,BB,BY,BE,BZ,BJ,BM,BO,BA,BV,BR,IO,BN,BG,BF,BI,KH,CM,CA,CV,KY,CF,TD,CL,CN,CX,CC,CO,KM,CG,CD,CK,CR,CI,HR,CU,CY,CZ,DK,DJ,DM,DO,EC,EG,SV,GQ,ER,EE,ET,FK,FO,FJ,FI,FR,GF,PF,TF,GA,GM,GE,GH,GI,EL,GL,GD,GP,GU,GT,GN,GW,GY,HT,HM,HN,HK,HU,IS,IN,ID,IR,IQ,IE,IL,IT,JM,JP,JO,KZ,KE,KI,KP,KR,KW,KG,LA,LV,LB,LS,LR,LY,LI,LT,LU,MO,MK,MG,MW,MY,MV,ML,MT,MH,MQ,MR,MU,YT,MX,FM,MD,MC,MN,MS,MA,MM,NR,NP,NL,AN,NC,NZ,NU,NF,MP,NO,OM,PK,PW,PS,PE,PH,PN,PL,PT,PR,QA,RE,RO,RU,RW,SH,KN,LC,PM,VC,WS,SM,ST,SA,CS,SC,SL,SG,SK,SI,SB,SO,GS,ES,LK,SR,SJ,SZ,SE,SY,TW,TJ,TH,TL,TK,TO,TT,TN,TR,TM,TC,TV,UA,AE,GB,UM,US,UZ,VU,VA,VN,VG,VI,WF';oSMPayMethods.addPayMethod('20;Rechnung_20mit_20Kundennummer;_3Cbr_3EDie_20Zahlart_20Rechnung_20ist_20nur_20f_C3_BCr_20Bestandskunden_20m_C3_B6glich_X3_20Informationen_20f_C3_BCr_20die_20Voraussetzung_20zur_20Rechnungszahlung_20finden_20Sie_20in_20unseren_20AGB_X3_3Cbr_3E;;0;0.6499999761581421;1;;P_X201017;1');if(SMShop.basket.payMethodInfo.xml.getAttribute(_SMAUniqueID)==""){SMShop.setPayMethod(oSMPayMethods.payMethods[(1).toString()]);};m_exclPayMethodRegions[16] = 'AX,AL,DZ,AS,AD,AI,AQ,AG,AR,AM,AW,AU,BS,BH,BD,BB,BY,BZ,BJ,BM,BO,BA,BV,BR,IO,BN,BG,BF,BI,KH,CM,CA,CV,KY,CF,TD,CL,CN,CX,CC,CO,KM,CG,CD,CK,CR,CI,HR,CU,CY,CZ,DJ,DM,DO,EC,EG,SV,GQ,ER,EE,ET,FK,FO,FJ,GF,PF,TF,GA,GM,GE,GH,GI,GL,GD,GP,GU,GT,GN,GW,GY,HT,HM,HN,HK,IS,IN,ID,IR,IQ,IL,JM,JP,JO,KZ,KE,KI,KP,KR,KW,KG,LA,LV,LB,LS,LR,LY,LT,MO,MK,MG,MW,MY,MV,ML,MT,MH,MQ,MR,MU,YT,MX,FM,MD,MN,MS,MA,MM,NR,NP,AN,NC,NZ,NU,NF,MP,NO,OM,PK,PW,PS,PE,PH,PN,PL,PT,PR,QA,RE,RO,RU,RW,SH,KN,LC,PM,VC,WS,SM,ST,SA,CS,SC,SL,SG,SK,SI,SB,SO,GS,ES,LK,SR,SJ,SZ,SE,SY,TW,TJ,TH,TL,TK,TO,TT,TN,TR,TM,TC,TV,UA,AE,GB,UM,US,UZ,VU,VA,VN,VG,VI,WF';oSMPayMethods.addPayMethod('16;Sofort_C3_BCberweisung;Schnelle_20und_20sichere_20Zahlung_20mit_20Paynet_20Payment_20Services_X3_20Ihre_20Daten_20werden_20in_20einem_20Terminal_X2Fenster_20_C3_BCber_20eine_20sichere_20Verbindung_20erfasst_X3_20_3CSTRONG_3E_3CFONT_20color=#800000_3ESie_20ben_C3_B6tigen_20PIN_20und_20TAN_20f_C3_BCr_20die_20Sofort_C3_BCberweisung_X3_3C_X4FONT_3E_3C_X4STRONG_3E_3CBR_3E;media_X4images_X4sofortbutton5_X3gif;0;0.5;1;;P_X201014;0');if(SMShop.basket.payMethodInfo.xml.getAttribute(_SMAUniqueID)==""){SMShop.setPayMethod(oSMPayMethods.payMethods[(1).toString()]);};m_exclPayMethodRegions[17] = 'AL,DZ,AS,AI,AQ,AG,AR,AM,AW,BS,BH,BD,BB,BY,BZ,BJ,BM,BO,BV,IO,BN,BF,BI,KH,CM,CV,KY,CF,TD,CX,CC,CO,KM,CG,CD,CK,CR,CI,CU,DJ,DM,DO,EC,EG,SV,GQ,ER,ET,FK,FO,FJ,GF,PF,TF,GA,GM,GE,GH,GI,GL,GD,GP,GU,GT,GN,GW,HM,HN,ID,IR,IQ,JM,JO,KZ,KE,KI,KP,KR,KG,LA,LB,LS,LR,LY,LT,MO,MK,MG,MW,MY,MV,ML,MH,MQ,MR,MU,YT,FM,MD,MN,MS,MM,NR,NP,AN,NC,NU,NF,MP,OM,PK,PW,PS,PN,PR,QA,RE,RW,SH,KN,LC,PM,VC,WS,ST,SC,SL,SB,SO,GS,LK,SR,SJ,SZ,SY,TJ,TL,TK,TO,TT,TN,TM,TC,TV,UM,UZ,VU,VN,VG,VI,WF';oSMPayMethods.addPayMethod('17;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_20Sie_20m_C3_BCssen_20f_C3_BCr_20diese_20Zahlart_20bei_20MB_20registriert_20sein!;media_X4images_X4moneybrookers_X2gs_X3gif;1;1;1;15,50;P_X201015;1');if(SMShop.basket.payMethodInfo.xml.getAttribute(_SMAUniqueID)==""){SMShop.setPayMethod(oSMPayMethods.payMethods[(1).toString()]);};