$(document).ready(function(){
	$("#ms-to-submit").click(function(){
		convert(1);
		return false;
	});	
	
	$("#to-ms-submit").click(function(){
		convert(2);
		return false;
	});
	
	$("#ms-to-type").change(function(){
		$("#ms-to").val("");
		$("#ms-to-result").html("0");
		
		type = $("#ms-to-type").val();
		if(type == "usd" || type == "cad" || type == "aud"){
			$("#ms-to-symbol").html("$");
		}
		else if(type == "gbp"){
			$("#ms-to-symbol").html("&pound;");
		}
		else if(type == "eur"){
			$("#ms-to-symbol").html("&euro;");
		}
		else if(type == "jap"){
			$("#ms-to-symbol").html("&yen;");
		}
	});
	
	$("#to-ms-type").change(function(){
		$("#to-ms").val("");
		$("#to-ms-result").html("0");
		
		type = $("#to-ms-type").val();
		if(type == "usd" || type == "cad" || type == "aud"){
			$("#to-ms-symbol").html("$");
		}
		else if(type == "gbp"){
			$("#to-ms-symbol").html("&pound;");
		}
		else if(type == "eur"){
			$("#to-ms-symbol").html("&euro;");
		}
		else if(type == "jap"){
			$("#to-ms-symbol").html("&yen;");
		}
	});
});

function convert(mode){
	if(mode == 1){
		value = $("#ms-to").val();
		if(!isNaN(value) && value != ""){
			type = $("#ms-to-type").val();
			
			$.ajax({
		   		type: "POST",
		   		url: "/mspcalc/mspcalc.php",
		   		data: "value="+value+"&type="+type+"&mode="+1,
		   		success: function(msg){
		     		$("#ms-to-result").html(msg);
		   		}
		 	});
	 	}
 	}
 	else if(mode == 2){
 		value = $("#to-ms").val();
		if(!isNaN(value) && value != ""){
			type = $("#to-ms-type").val();
			
			$.ajax({
		   		type: "POST",
		   		url: "/mspcalc/mspcalc.php",
		   		data: "value="+value+"&type="+type+"&mode="+2,
		   		success: function(msg){
		     		$("#to-ms-result").html(msg);
		   		}
		 	});
	 	}
 	}
}


