window.addEvent('domready', function() 
{	
	$('annuityplan_calculate').addEvent('click', function(e) 
	{
		e = new Event(e).stop();
		
		// clear validation
		$('validation_text').set('text','');
		
		var val = $('credit_value').get('value');
		if (!val) 
		{
			$('credit_value').showerror('1px solid #f00').focus();
			$('validation_text').set('text','Visina kredita je obavezno polje.');
			return; 
		}
		
		val = $('credit_interest_rate').get('value');
		if (!val || val == 0) 
		{
			$('credit_interest_rate').showerror('1px solid #f00').focus();
			$('validation_text').set('text','Kamatna stopa je obavezno polje.');
			return; 
		}

		val = $('credit_months_period').get('value');
		if (!val || val == 0) 
		{
			$('credit_months_period').showerror('1px solid #f00').focus();
			$('validation_text').set('text','Broj meseci otplate je obavezno polje.');
			return; 
		}
		
		
		
		$('ajaxloader').style.display = '';
		
		
		var myRequest = new Request.HTML(
		{	
			url: "http://www.kredit-kalkulator.com/annuity.php?" + $('annuitycalc').toQueryString(),
			method: 'GET',
		 	onSuccess: function(html)
		 	{
		 		$('annuity_plan').set('text','');
		 		$('annuity_plan').adopt(html);
				$('ajaxloader').style.display = 'none';	 
		 	}
		}).send();
	});
	
});
	
function FilterAlphaNumeric(e)
{
	var allowed = ['1','2','3','4','5','6','7','8','9','0'];
	var keycodes = [8,9,35,36,37,38,39,40,46,96,97,98,99,100,101,102,103,104,105,110,188,190];
	var flag = false;

	
	allowed.each(function(item,index)
	{
		if(String.fromCharCode(e.keyCode) == item && e.shiftKey != 1) flag = true;
	});
	
	keycodes.each(function(item,index)
	{
		if(e.keyCode == item) flag = true;
	});
	
	return flag;
}