function form_update(elm, update_elm_id) {
	url = location.href;
	url = url + (url[url.length - 1] == '/' ? '?' : '&') + "v=json&ajax=form_update&form_update=" + update_elm_id;

	new Ajax.Request(url, {
		parameters : elm.form.serialize(true),
		onSuccess : function(transport, json) {
			var update_elm = $(update_elm_id);
			var response = transport.responseText.evalJSON();

			update_elm.options.length = 0;
			for (var key in response) {
				if (typeof(response[key]) == 'string') {
					update_elm.options[update_elm.options.length] = new Option(response[key], key, false);
				}
			}
		},
		onFailure: function() {
			alert('Something went wrong...')
		}
	 });
}

function refresh_main(delay)
{ 
	var isIE =     !!(window.attachEvent && !window.opera);
   var isOpera = !!window.opera;
   var isWebKit = (navigator.userAgent.indexOf('AppleWebKit/') > -1);//Chrome also
   
   if (isIE || isOpera || isWebKit){
	    var loc = document.location.href;
	    var qstring ="";
	    if (loc.indexOf("?") > 0) qstring = "&" + loc.substring(loc.indexOf("?")+1);
	    //var url = "?v=ajax&"+ qstring;
	    var url = "?v=ajax"+ qstring;
	    
	    url = url + "&sid=" + Math.random();
	   
	    new Ajax.Request(url, {
			parameters : null,
			onSuccess : function(transport, json) {
				if ((typeof shouldDoRefresh == 'function' && shouldDoRefresh())
					|| (typeof shouldDoRefresh != 'function')) {
					var update_elm = $('main');
					var response = transport.responseText.evalJSON();
					update_elm.innerHTML = response['response'];
				}
			},
			onFailure: function() {
				alert('Something went wrong in refresh_main()')
			}
		 });
		if (typeof shouldDoRefresh == 'function' && shouldDoRefresh()) { 
			setTimeout('refresh_main(' + delay + ')', delay);
		}
	}else{
		if (typeof shouldDoRefresh == 'function' && shouldDoRefresh()) {
			setTimeout('window.location.reload()', delay);
		}
	}
}

		


