/*product.js*/
function isIntegertest(value) {
  
 // if ((/^(\d|[0-9]+)(\.[0-9]{0,2})?$/.test(value) ))
if ((/^(\d|[1-9][0-9]+)(\.[0-9]{0,2})?$/.test(value) ))
 {
  return true;
 } 
 else
 {
 return false;
 }
}
   


function integerInRangetest(value, minval, maxval) {
  if (isIntegertest(value)) {
    if (parseInt(value) >= minval && parseInt(value) <= maxval ) {
      return true; 
    } else {
      return false; //not in range
    }
  }
  else {
	  return false;
  }
}
// JavaScript Document
$(document).ready(function() {
	
	 var ermsg = $.trim($('#ermsg').val());
    $('#edit-amount-sell').change(function() {
		var amount = $.trim($('#edit-amount-sell').val());
var langid = $.trim($('#langid').val());
var defamt = $.trim($('#defamt').val());


                var source = $.trim($('#flagTxt1').val());
                var destination = $.trim($('#flagTxt2').val());
       if( integerInRangetest(amount, 100,99000000) ) {
$('#defamt').val(amount);

			$.ajax({  
			  url: "responsesell",
			  data: "amount=" + encodeURI(amount)+"&source="+encodeURI(source)+"&destination="+encodeURI(destination),
			  success: function(msg){
				eval(msg);
			  }
			});
		 
	   }
	   else { 
	   alert(ermsg);
	   $('#edit-amount-sell').val(defamt);

	  
	   }
	  
	});
	
  $('#flagTxt1').change(function() {
var langid = $.trim($('#langid').val());

		var amount = $.trim($('#edit-amount-sell').val());
                var source = $.trim($('#flagTxt1').val());
                var destination = $.trim($('#flagTxt2').val());
   
        $.ajax({ 
  url: "responsesell",
  data: "amount=" + encodeURI(amount)+"&source="+encodeURI(source)+"&destination="+encodeURI(destination),
  success: function(msg){
    eval(msg);
    
  }
});


	});
        
    $('#flagTxt2').change(function() {
var langid = $.trim($('#langid').val());


		var amount = $.trim($('#edit-amount-sell').val());
                var source = $.trim($('#flagTxt1').val());
                var destination = $.trim($('#flagTxt2').val());
 
        $.ajax({ 
  url: "responsesell",
  data: "amount=" + encodeURI(amount)+"&source="+encodeURI(source)+"&destination="+encodeURI(destination),
  success: function(msg){
    eval(msg);
    
  }
});


	});
	
	//for sell form
	
	 $('#edit-amount-buy').change(function() {
var langid2 = $.trim($('#langid2').val());
var defamt2 = $.trim($('#defamt2').val());

		var amount = $.trim($('#edit-amount-buy').val());
                var source = $.trim($('#flagTxt4').val());
                var destination = $.trim($('#flagTxt3').val());
        if( integerInRangetest(amount, 100,99000000) ) {
        $('#defamt2').val(amount);

        $.ajax({  
		  url: "responsebuy",
		  data: "amount=" + encodeURI(amount)+"&source="+encodeURI(source)+"&destination="+encodeURI(destination),
		  success: function(msg){
			eval(msg);
			
		  }
		});
		}
		else {
		 alert(ermsg);
	   
	     $('#edit-amount-buy').val(defamt2);
		}

	});
  $('#flagTxt3').change(function() {
var langid2 = $.trim($('#langid2').val());
		var amount = $.trim($('#edit-amount-buy').val());
                var source = $.trim($('#flagTxt4').val());
                var destination = $.trim($('#flagTxt3').val());
 
        $.ajax({ 
  url: "responsebuy",
  data: "amount=" + encodeURI(amount)+"&source="+encodeURI(source)+"&destination="+encodeURI(destination),
  success: function(msg){
    eval(msg);
    
  }
});


	});
        
    $('#flagTxt4').change(function() {
var langid2 = $.trim($('#langid2').val());
		var amount = $.trim($('#edit-amount-buy').val());
                var source = $.trim($('#flagTxt4').val());
                var destination = $.trim($('#flagTxt3').val());
 
        $.ajax({ 
  url: "responsebuy",
  data: "amount=" + encodeURI(amount)+"&source="+encodeURI(source)+"&destination="+encodeURI(destination),
  success: function(msg){
    eval(msg);
    
  }
});


	});
        
});
