// for standard javascript functions see knwebstd-tools.js in knwebstd-tools-client-<VERSION>-web.zip

/*
function setComplexBooleanFromCheckbox(property) {
	var hidden = document.getElementById(property);
	var checkBox = document.forms[0].elements[property + "Checkbox"];
	if(checkBox.checked == 1) {
		hidden.value = true;
	} else {
		hidden.value = false;
    }
}

function setCheckboxFromComplexBoolean(property) {
	var hidden = document.getElementById(property);
	var checkBox = document.forms[0].elements[property + "Checkbox"];
	if(hidden.value == "true") {
		checkBox.checked = 1;
	} else {
		checkBox.checked = 0;
	}
}*/

function showPopup(contents, width, height) {
    x = screen.availWidth/2-width/2;
    y = screen.availHeight/2-height/2;
    var popupWindow = window.open('','KNLogin_Popup','width='+width+',height='+height+',left='+x+',top='+y+',status=no,resizable=yes,scrollbars=yes,toolbar=no');
    popupWindow.document.open();
    popupWindow.document.write(contents);
    popupWindow.document.close(); 
    popupWindow.focus();
}

function toggleBlockVisibility(openElement, closedElement) {
	var displayOpen='';
	var displayClosed='none';
	document.getElementById(openElement).style.display=displayOpen;
	document.getElementById(closedElement).style.display=displayClosed;
}

// Removes the parameter with name given in 'paramName' from the given URL.
function removeParameter(url, paramName){
	var newUrl;
	
	var paramIndex = url.indexOf(paramName);
	if(paramIndex > 0) {
		var begin = url.substring(0, paramIndex); // start - character before first char of paramName
		var tempEnd = url.substring(paramIndex, url.length); // paramName - end
		
		var ampersandIndex = tempEnd.indexOf('&');
		var end = '';
		if(ampersandIndex != -1){
			end = tempEnd.substring(ampersandIndex + 1, tempEnd.length); // & - end or start - end, if '&' not found
		}
		
		newUrl = begin + end;
	} else {
		newUrl = url;
	}

	return newUrl;
}
