
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();

oSMPayMethods.addPayMethod('4;Credit_20card;Please_20enter_20your_20credit_20card_20details_X3_20The_20data_20will_20be_20submitted_20to_20us_20following_20the_20order_20process_X3;_X3_X3_X4media_X4images_X4kreditkarten_X3jpg;0;0;1;20,0;P0002;0');if(SMShop.basket.payMethodInfo.xml.getAttribute(_SMAUniqueID)==""){SMShop.setPayMethod(oSMPayMethods.payMethods[(4).toString()]);};oSMPayMethods.addPayMethod('16;PayPal;Secure_20and_20Easy_20Order_20Processing_20_X2_20Worldwide_X3_20Your_20data_20is_20recorded_20in_20a_20_3Cb_3Eseparate_20terminal_20by_20a_20secure_20connection_20to_20PayPal_X3_20After_20you_20finished_20your_20payment_20on_20PayPal,_20you_20will_20be_20redirected_20to_20the_20shop_20and_20the_20order_20will_20be_20carried_20out_X3_3C_X4b_3E;_X3_X3_X4media_X4images_X4paypal_X2eng_X3jpg;0;0;1;;P0003;0');if(SMShop.basket.payMethodInfo.xml.getAttribute(_SMAUniqueID)==""){SMShop.setPayMethod(oSMPayMethods.payMethods[(4).toString()]);};oSMPayMethods.addPayMethod('1;Prepayment_20to_20our_20bank_X2account;Please_20transmit_20the_20money_20to:_20_3Cbr_3Eabsolutely_20Special_X2Trade_20GmbH_3Cbr_3EHypoVereinsbank,_20Nuremberg,_20Germany_3Cbr_3EIBAN:_20DE16_207602_200070_200307_206474_2000_20_3Cbr_3ESWIFT_X4BIC:_20HYVEDEMM460;_X3_X3_X4media_X4images_X4eu_X2standardueberweisung_X3jpg;0;0;1;;P0001;0');if(SMShop.basket.payMethodInfo.xml.getAttribute(_SMAUniqueID)==""){SMShop.setPayMethod(oSMPayMethods.payMethods[(4).toString()]);};oSMPayMethods.addPayMethod('12;International_20Money_X2_X4_20Postal_X2Order_20_X4_20Cheque;Please_20send_20to:_20_3Cbr_3Eabsolutely_20Special_X2Trade_20GmbH_3Cbr_3ESendelbacher_20Weg_206,_2090482_20Nuremberg,_20Germany;_X3_X3_X4media_X4images_X4cheque_X3jpg;0;12.899999618530273;1;;P0006;0');if(SMShop.basket.payMethodInfo.xml.getAttribute(_SMAUniqueID)==""){SMShop.setPayMethod(oSMPayMethods.payMethods[(4).toString()]);};oSMPayMethods.addPayMethod('11;Cash_20in_20registered_20letter;Please_20send_20the_20total_20amount_20to:_3Cbr_3Eabsolutely_20_20Special_X2Trade_20GmbH_3Cbr_3ESendelbacher_20Weg_206,_2090482_20Nuremberg,_20Germany;_X3_X3_X4media_X4images_X4bar_X3jpg;0;0;1;;P0008;0');if(SMShop.basket.payMethodInfo.xml.getAttribute(_SMAUniqueID)==""){SMShop.setPayMethod(oSMPayMethods.payMethods[(4).toString()]);};m_exclPayMethodRegions[8] = 'AU,AR,BE,BA,BR,BG,CA,CL,CN,HR,CY,CZ,DK,EE,FI,FR,EL,GL,HK,HU,IS,IN,IE,IL,IT,JP,KW,LV,LI,LT,LU,MY,MT,MC,NL,NZ,NO,PL,PT,RO,RU,SM,SA,CS,SG,SK,SI,ZA,ES,SE,CH,TH,TR,UA,AE,GB,US,VA,BT';oSMPayMethods.addPayMethod('8;Immediate_20credit_X2transfer;Fast_20and_20secure_20payment_20with_20Paynet_20Payment_20Services_X3_20Your_20data_20will_20be_20transferred_20securely_20to_20the_20Paynet_20Terminal_X3;_X3_X3_X4media_X4images_X4sofortueberweisung_X3jpg;0;0;1;;P0004;0');if(SMShop.basket.payMethodInfo.xml.getAttribute(_SMAUniqueID)==""){SMShop.setPayMethod(oSMPayMethods.payMethods[(4).toString()]);};m_exclPayMethodRegions[13] = 'AU,CA,CY,CZ,EE,FI,FR,EL,GL,HK,HU,IS,IN,IE,IT,JP,LV,LI,LT,MT,MC,NZ,NO,PL,PT,RO,RU,SM,SA,SG,SK,SI,ZA,ES,SE,TR,UA,GB,US,VA';oSMPayMethods.addPayMethod('13;Payment_20during_20collection;Payment_20during_20collection;_X3_X3_X4media_X4images_X4abholung_X2e_X2neu_X3jpg;0;0;1;;P0007;0');if(SMShop.basket.payMethodInfo.xml.getAttribute(_SMAUniqueID)==""){SMShop.setPayMethod(oSMPayMethods.payMethods[(4).toString()]);};