// Overridden by $PAGE->load_js() if jQuery is not present
function load() {}


function email(code) {
	var arr = code.split('');
	var count = arr.length; 
	var ret = '';
	for(var i=count-1; i>=0; --i)
	{
		var char = arr[i];
		ret += String.fromCharCode(char.charCodeAt(0)+4);
	}
	window.location.href="mailto:"+ret;
}



function toggle(condition, target) {
  if ($("#"+condition).val() > 0)
    $("#"+target).show("normal");
  else
    $("#"+target).hide("fast");
}


function disable(button, form) {
	if (button != null) {
		button.disabled = true;
		button.style.cursor = 'default';
	}
	form.submit();
}



function delete_item(redirect_to, recycle, text) { 
    var action;
    if (text != null)
    	action=confirm(text);    	
    else {
	    if (recycle)
	    	action=confirm("Er du sikker på at du vil legge elementet i papirkurven?");
	    else
	    	action=confirm("Er du sikker på at du vil slette dette elementet for godt?");
    }
    if(action)
    	window.location.href=redirect_to;
    return false;
}



function empty(id, standard_content, textarea) {
	var streng;
	if (textarea)
		streng = document.getElementById(id).innerHTML;
	else
		streng = document.getElementById(id).value;
	
	document.getElementById(id).style.color = '#000000';

	if (streng == standard_content) {
		if (textarea)
			document.getElementById(id).innerHTML = "";
		else
			document.getElementById(id).value = "";
    }
}


//return the value of the radio button that is checked
//return an empty string if none are checked, or
//there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

//set the radio button with the given value as being checked
//do nothing if there are no radio buttons
//if the given value does not exist, all the radio buttons
//are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}