function change_form_action(payment_method) {
	if (payment_method == 'bank') {
		document.forms.buckaroo.action = 'https://payment.buckaroo.nl/gateway/machtiging.asp';
	} else if (payment_method == 'ideal') {
		document.forms.buckaroo.action = 'https://payment.buckaroo.nl/gateway/ideal_payment.asp';
	}
}

function validate() {
	var error_name = false;
	var error_amount = false;
	var error_lastname = false;
	var error_address = false;
	var error_zipcode = false;
	var error_city = false;
	var error_email = false;
	if ($F('frm_email') == '') {
		$('label_email').setStyle({ 'color' : 'red' });
		Effect.Pulsate('label_email', { pulses: 6, duration: 3 });
		error_email = true;
	} else {
		var emailRegEx = /^([a-zA-Z0-9])(([a-zA-Z0-9])*([\._-])?([a-zA-Z0-9]))*@(([a-zA-Z0-9\-])+(\.))+([a-zA-Z]{2,4})+$/;
		if($F('frm_email').search(emailRegEx) == -1) {
			$('label_email').setStyle({ 'color' : 'red' });
			Effect.Pulsate('label_email', { pulses: 6, duration: 3 });
			error_email = true;
		} else {
			$('label_email').setStyle({ 'color' : '#000000' });
		}
	}
	if ($F('frm_amount') == '') {
		$('label_amount').setStyle({ 'color' : 'red' });
		Effect.Pulsate('label_amount', { pulses: 6, duration: 3 });
		error_amount = true;
	} else {
		if (!IsNumeric($F('frm_amount'))) {
			$('label_amount').setStyle({ 'color' : 'red' });
			Effect.Pulsate('label_amount', { pulses: 6, duration: 3 });
			error_amount = true;
		} else {
			$('label_amount').setStyle({ 'color' : '#000000' });
		}
	}
	if ($F('frm_name') == '') {
		$('label_name').setStyle({ 'color' : 'red' });
		Effect.Pulsate('label_name', { pulses: 6, duration: 3 });
		error_name = true;
	} else {
		$('label_name').setStyle({ 'color' : '#000000' });
	}
	if ($F('frm_lastname') == '') {
		$('label_lastname').setStyle({ 'color' : 'red' });
		Effect.Pulsate('label_lastname', { pulses: 6, duration: 3 });
		error_lastname = true;
	} else {
		$('label_lastname').setStyle({ 'color' : '#000000' });
	}
	if ($F('frm_zipcode') == '') {
		$('label_zipcode').setStyle({ 'color' : 'red' });
		Effect.Pulsate('label_zipcode', { pulses: 6, duration: 3 });
		error_zipcode = true;
	} else {
		$('label_zipcode').setStyle({ 'color' : '#000000' });
	}
	if ($F('frm_city') == '') {
		$('label_city').setStyle({ 'color' : 'red' });
		Effect.Pulsate('label_city', { pulses: 6, duration: 3 });
		error_city = true;
	} else {
		$('label_city').setStyle({ 'color' : '#000000' });
	}
	if ($F('frm_address') == '') {
		$('label_address').setStyle({ 'color' : 'red' });
		Effect.Pulsate('label_address', { pulses: 6, duration: 3 });
		error_address = true;
	} else {
		$('label_address').setStyle({ 'color' : '#000000' });
	}

	if (error_name || error_lastname || error_email || error_address || error_zipcode || error_city) {
		return false;
	} else {
		return true;
	}
}

function set_amount() {
	var amount = $F('frm_amount');
	var amount_split = amount.split(',');
	if (amount_split[1] != undefined) {
		if (amount_split[1] != '00') {
			amount_split[1] = amount_split[1].substring(0,2);
		} else {
			amount.split[1] = '00';
		}
		var amount = amount_split[0] + amount_split[1];
		$('BPE_Amount').setValue(amount);
	} else if (amount_split[1] == undefined) {
		$('BPE_Amount').setValue(amount + '00');
	}
}

function create_signature(invoice_number, amount) {
	var url = 'http://www.childatventure.org/includes/create_signature.php?invoice_number=' + invoice_number + '&amount=' + amount;
	new Ajax.Request(url, {
		method: 'get',
	  	onSuccess: function(transport) {
			var json = transport.responseText.evalJSON(true);
	    	$('BPE_Signature2').setValue(json.signature);
		}
	});
}

function IsNumeric(sText) {
   var ValidChars = "0123456789,";
   var IsNumber = true;
   var Char;
   for (i = 0; i < sText.length && IsNumber == true; i++) { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) {
      	IsNumber = false;
      }
   }
   return IsNumber;
}


