function keepSessionAlive(imgName) {
	myImg = document.getElementById(imgName);
	if (myImg) {
		myImg.src = myImg.src.replace(/\?.*$/, '?' + Math.random());
	}
}
window.setInterval("keepSessionAlive('keepAliveIMG')", 13*60*1000);
// <img id="keepAliveIMG" width="1" height="1" src="<c:url value="/keepalive.gif"/>" />

function changeAction(action) {
	document.forms[0].action = action;
}

function currLocation() {
	alert(location);
}

function changeLocation(newLocation) {
	document.location = newLocation;
}

function changeElemValById(id, value) {
	if (document.getElementById) {
		var field = document.getElementById(id);
		field.value = value;
	} else {
		alert("Den webbläsare som du använder är tyvärr för gammal och stöds inte av tidbokningstjänsten. Det som du ville utföra kan inte utföras korrekt och vi rekommenderar att du inte fortsätter att använda tidbokningstjänsten med denna webbläsare.");
	}
}

function submitForm(formId) {
	var form = document.getElementById(formId);
	form.submit();
}

// Set cursor focus
function focusById(id) {
	var field = document.getElementById(id);

	/*
	 * I am using "window.preventFocusById" instead of just "preventFocusById". This works 
	 * because all variables are also defined as properties of the window object. 
	 * It is safer to use "window.preventFocusById" which will not result in an error 
	 * if the variable hasn't been declared.
	 */
	
	if (field && !window.preventFocusById) {
		if (field.style.display != 'none' 
				&& field.style.visibility != 'hidden') {
			field.focus();
		}
	}
}

function showElementById(id) {
	var element = document.getElementById(id);
	if (element) {
		element.style.visibility = "visible";
	}
}

function hideElementById(id) {
	var element = document.getElementById(id);
	if (element) {
		element.style.visibility = "hidden";
	}
}

function tbToggleDisplay(initState, obj, id1, id2, idImg) {
	if (obj.disp == undefined) obj.disp = initState;
	
	if (obj.disp == 'none') {
		tbSetDisplay('block', obj, id1, id2, idImg);
	} else {
		tbSetDisplay('none', obj, id1, id2, idImg);
	}

	if (obj.disp == 'block') return true; 
	return false;
}

function tbSetDisplay(state, obj, id1, id2, idImg) {
	obj.disp = state;
	var id1 = document.getElementById(id1); 
	var id2 = document.getElementById(id2); 
	var idi = document.getElementById(idImg); 

	if (obj.disp == 'block') idi.src='../images/buttons/arrow_down.gif';
	if (obj.disp == 'none') idi.src='../images/buttons/arrow_right.gif';

	id1.style.display = obj.disp;

	if (id2 != undefined) id2.style.display = obj.disp; 

	if (obj.disp == 'block') return true; 
	return false;
}

function displayElementById(id) {
	var element = document.getElementById(id);
	if (element) {
		element.style.display = "none";
	}
}

// Set cursor focus
function focusField() {
   var form;
   var field;

   // login form
   form = document.forms.loginform;
   if (form)
   {
	  field = form.password;
	  if (field)
	  {
		 field.focus();
	  }
   }
}

// Enables submit button if any checkbox is checked.
function tbEnableSubmit(submitButton) {
	var submitButton = document.getElementById(submitButton);
	var i = 0;
	while (true) {
		var cb = document.getElementById('checkbox' + i++);
		if (cb == undefined) {
			break;
		} else {
			if (cb.checked) {
				submitButton.disabled = false;
				return;
			}
		}
	}

	if (submitButton != undefined) {
		submitButton.disabled = true;
	}
}

// Checks or unchecks all checkboxes.
function tbSetAllCheckboxes(value) {
	var i = 0;
	while (true) {
		var cb = document.getElementById('checkbox' + i++);
		if (cb == undefined) {
			break;
		} else {
			cb.checked = value;
		}
	}
}

// Show help tooltip
function tbShowHelp(fieldname, text) {
	tbShowHelp(fieldname, text, RIGHT);
}

// Show help tooltip
function tbShowHelp(fieldname, text, position) {
	return coolTip(text, position, WIDTH, 200, DELAY, 300, VAUTO, CAPTION, fieldname, 
				   CSSW3C, DIVCLASS, 'tb-cooltip-help-div', BODYCLASS, 'tb-cooltip-help-body', 
				   CAPTIONCLASS, 'tb-cooltip-help-caption', CLOSECLASS, 'tb-cooltip-help-close');
}

// Show help tooltip wider
function tbShowHelpWide(fieldname, text) {
	return coolTip(text, RIGHT, WIDTH, 450, BORDER, DELAY, 300, VAUTO, CAPTION, fieldname, 
				   CSSW3C, DIVCLASS, 'tb-cooltip-help-div', BODYCLASS, 'tb-cooltip-help-body', 
				   CAPTIONCLASS, 'tb-cooltip-help-caption', CLOSECLASS, 'tb-cooltip-help-close');
}

function tbShowHelpSuperWide(fieldname, text) {
	return coolTip(text, RIGHT, WIDTH, 760, BORDER, DELAY, 300, VAUTO, CAPTION, fieldname, 
				   CSSW3C, DIVCLASS, 'tb-cooltip-help-div', BODYCLASS, 'tb-cooltip-help-body', 
				   CAPTIONCLASS, 'tb-cooltip-help-caption', CLOSECLASS, 'tb-cooltip-help-close');
}

/**
 * Sets the height of a div with id 'scrolldiv'.
 */
function setScrolldivStyle(boolValue, tbContentHeight, tbBodyId, height, scrolldiv) {
	/* No standard way to get style from css. IE uses currentStyle, Firefox doesn't. 
	   Setting tbContentHeight in LoginResolveFilter instead although it's ugly :-) */
	if (boolValue && tbContentHeight == '') {
		var tbBodyEl = document.getElementById(tbBodyId);
		var scrolldiv = document.getElementById(scrolldiv);
		if (tbBodyEl.style.height == '') {
			scrolldiv.style.height = height;
			scrolldiv.style.overflow = 'auto';
		}
	}
}

/* Open Cube function for setting the current menu choice highlighted */
function mvtGetRef(str) {
	return (document.all) ? document.all[str] : document.getElementById(str);
}

function mvtSetClass(strId, strClass) {
	var obj = mvtGetRef(strId);
	if(obj != null && typeof(obj) != "undefined") obj.className = strClass;
}

function mvtSetHighlightClass(str) {
	mvtSetClass(str, 'Undermenymuspekning');
}

function MHTGetRef(str) {
	if(document.all)
		return document.all[str];
	else
		return document.getElementById(str);
}

function MHTSetClass(strID, strClass) {
	var obj = MHTGetRef(strID);
	if(obj != null && typeof(obj) + "" != "undefined")
		obj.className = strClass;
	var obj = MHTGetRef(strID + "_second");
	if(obj != null && typeof(obj) + "" != "undefined")
		obj.className = strClass;
}

