
Event.observe(window,'load', function(){
	$$('a.currency').each(function(a){
	
var url = "./";
	a.observe("click", function(){
		$$('a.currency').each(function(a_del){a_del.removeClassName('currency_select');});
		a.addClassName('currency_select');
		var curr = a.rel;
		$$('input.date_update').each(function(input){
			var date = $(input).value;
			var id = $(input).id;
			var currency_id = a.rel; // из какой;
			var x_id = $('currency_id_'+id).value; // в какую;
			var price =  $('price_value_'+id).value;
			var price_one =  $('price_one_value_'+id).value;
			var price_two =  $('price_two_value_'+id).value;
			
			var params = "?ajax_currency=1&date="+date+"&y_cur="+currency_id+"&x_cur=" + x_id + "&price=" + price + "&value_one=" + price_one + "&value_two=" + price_two;
			
			if(currency_id == 0){
				var defaultPrice = $('price_value_'+id).value;
				var defaultCurrency = $('currency_name_'+id).value;
				var defaultPriceOne = $('price_one_value_'+id).value;
				var defaultPriceTwo = $('price_two_value_'+id).value;
				
				if($('price_'+id))
				$('price_'+id).update(defaultPrice);
				if($('price_one_'+id))
				$('price_one_'+id).update(defaultPriceOne);
				if($('price_two_'+id))
				$('price_two_'+id).update(defaultPriceTwo);
				if($('price_'+id+"_name"))
				$('price_'+id+"_name").update(defaultCurrency); 
				if($('price_'+id+"_name2"))
				$('price_'+id+"_name2").update(defaultCurrency); 				
				
				var cookie_date = new Date ( 2020, 01, 15 );
				var end_date = cookie_date.toGMTString();
//  				document.cookie = "currency="+ currency_id +"; expires="+ end_date +"; path=/;";
  				
			} else {
				
			new Ajax.Request(url, {
  				method: 'post',
  				parameters: params,
  				onSuccess: function(t) {
    				var r = t.responseJSON;
  					
  						$('price_'+id).update(r['price']);
  						
  						if($('price_one_'+id))
  						$('price_one_'+id).update(r['value_one']);
  						
  						if($('price_two_'+id))
  						$('price_two_'+id).update(r['value_two']);
  						
  						$('price_'+id+"_name").update(r['currency_name']); 
  						$('price_'+id+"_name2").update(r['currency_name']); 
  					
  					var cookie_date = new Date ( 2020, 01, 15 );
  					var end_date = cookie_date.toGMTString();
//  					document.cookie = "currency="+ currency_id +"; expires="+ end_date +"; path=/;";
				  },
				  onLoaded: function(){
				  	
				  }
			});
			}
		});
	});

	
	if(default_currency){
		//Event.observe(window, "load",function(){
		var curr = default_currency;
		
		$$('input.date_update').each(function(input){
			var date = $(input).value;
			var id = $(input).id;
			var currency_id = default_currency; // из какой;
			var x_id = $('currency_id_'+id).value; // в какую;
			var price =  $('price_value_'+id).value;
			var price_one =  $('price_one_value_'+id).value;
			var price_two =  $('price_two_value_'+id).value;
			
			var params = "?ajax_currency=1&date="+date+"&y_cur="+currency_id+"&x_cur=" + x_id + "&price=" + price + "&value_one=" + price_one + "&value_two=" + price_two;
			
			if(currency_id == 0){
				var defaultPrice = parseInt($('price_value_'+id).value);
				var defaultCurrency = $('currency_name_'+id).value;
				var defaultPriceOne = parseInt($('price_one_value_'+id).value);
				var defaultPriceTwo = parseInt($('price_two_value_'+id).value);
				
				if($('price_'+id))
				$('price_'+id).update(defaultPrice);
				if($('price_one_'+id))
				$('price_one_'+id).update(defaultPriceOne);
				if($('price_two_'+id))
				$('price_two_'+id).update(defaultPriceTwo);
				if($('price_'+id+"_name"))
				$('price_'+id+"_name").update(defaultCurrency); 
				
				var cookie_date = new Date ( 2020, 01, 15 );
				var end_date = cookie_date.toGMTString();
//  				document.cookie = "currency="+ currency_id +"; expires="+ end_date +"; path=/;";
  				
			} else {
				
			new Ajax.Request(url, {
  				method: 'post',
  				parameters: params,
  				onSuccess: function(t) {
    				var r = t.responseJSON;
  					
  						$('price_'+id).update(r['price']);
  						
  						if($('price_one_'+id))
  						$('price_one_'+id).update(r['value_one']);
  						
  						if($('price_two_'+id))
  						$('price_two_'+id).update(r['value_two']);
  						
  						$('price_'+id+"_name").update(r['currency_name']); 
  						$('price_'+id+"_name2").update(r['currency_name']); 
  					
  					var cookie_date = new Date ( 2020, 01, 15 );
  					var end_date = cookie_date.toGMTString();
//  					document.cookie = "currency="+ currency_id +"; expires="+ end_date +"; path=/;";
				  },
				  onLoaded: function(){
				  	
				  }
			});
			}
		})			
		//});
	}
	
	});
})	
	

