/* What to do when a project property is updated */
function projectUpdated() {
	if(typeof($('project_update_url')) != "undefined") {
		new Ajax.Request($('project_update_url').innerHTML.strip(),
		      {asynchronous:true,
			     evalScripts:true,
			     onComplete:function(request){Element.hide('loading_icon')},
			     onFailure:function(request){ajaxUpdateError(request);},
			     onLoading:function(request){Element.show('loading_icon')}
			    });
	}
}


/* What to do when a project version property is updated */
function versionUpdated() {
	if(typeof($('version_update_url')) != "undefined") {
		new Ajax.Request($('version_update_url').innerHTML.strip(),
		      {asynchronous:true,
			     evalScripts:true,
			     onComplete:function(request){Element.hide('loading_icon')},
			     onFailure:function(request){ajaxUpdateError(request);},
			     onLoading:function(request){Element.show('loading_icon')}
			    });
	}
}

/* What to do when there's a ajaxiliscious error */
function ajaxUpdateError(transport) {
  alert(transport.responseText);
}

/* Load additional javascript functions after page load is complete */
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

/* Set focus to the given field, if it exists */
function setFocus(elementId) {
	$(elementId).focus();
	$(elementId).select();
}