
function calculateProfit(){
	
	var priceValue = document.getElementById('price').value;
	
	var users = document.getElementById('users').value;
	
	if(users == ''){
		users = 0;
		document.getElementById('users').value = 0;
	}
	
	if(isInteger(users)){
		
		var txtConv = document.getElementById('txtConversion').value;
		var cardConv = document.getElementById('cardConversion').value;
		
		if(txtConv == ''){
			txtConv = 0;
			document.getElementById('txtConversion').value = 0;
		}
		
		if(cardConv == ''){
			cardConv = 0;
			document.getElementById('cardConversion').value = 0;
		}
		
		if(isInteger(txtConv) && txtConv < 100.1 && isInteger(cardConv) && cardConv < 100.1){
			
			var totalGrossSMS = (((users / 100) * txtConv) * priceValue);
	
			document.getElementById('txtProfit').innerHTML = addCommas(totalGrossSMS.toFixed(2));
			
			var totalGrossCard = (((users / 100) * cardConv) * priceValue);
			
			document.getElementById('cardProfit').innerHTML = addCommas(totalGrossCard.toFixed(2));
			
		}else{
			document.getElementById('users').value = 300;
			document.getElementById('txtConversion').value = 65;
			document.getElementById('cardConversion').value = 7;
		}
		
	}else{
		document.getElementById('users').value = 300;
		document.getElementById('txtConversion').value = 65;
		document.getElementById('cardConversion').value = 7;
	}
}

function addCommas(nStr){
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}


function isInteger(x){
	
   var y = parseInt(x);
   
   if(isNaN(y)){
	   return false;
   }
   
   return x==y && x.toString()==y.toString();
 } 
