	if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
    }

	function convertCurrency()
	{
		var inCurr = document.getElementById('in_currency').value;
		var outCurr = document.getElementById('out_currency').value;
		var currVal = document.getElementById('amount').value;
		req.open("GET", "pretvornik/convert?in="+inCurr+"&out="+outCurr+"&amount="+currVal,true);
        req.onreadystatechange = process_request;
        req.send(null);
	}
   
    function process_request()
    {
		if (req.readyState == 4)
		{
			try
            {
                if (req.status == 200) {
					document.getElementById('out_amount').value = req.responseText.replace(/^\s*(.*?)\s*$/g, "$1");
                } // IE returns a status code of 0 on some occasions, so ignore this case
                else if (req.status != 0) {
                    alert("There was an error while retrieving the URL: " + req.statusText);
                }
            }
            catch (error) {}
		}
	}

	function invert_selection()
	{
		var tmp = document.getElementById('out_currency').selectedIndex;
		//alert(tmp);
		document.getElementById('out_currency').selectedIndex = document.getElementById('in_currency').selectedIndex;
		document.getElementById('in_currency').selectedIndex = tmp;
		if (document.getElementById('out_amount').value != 0) {
			document.getElementById('amount').value = 0;
			document.getElementById('out_amount').value = 0;
		}
		return false;
	}

	function openwindow(url)
	{
		window.open(url,"popup","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=365,height=445")
	}

	function key_press(event)
	{
		if (event.keyCode == 13) {
			convertCurrency();
		}
	}