// htmlhead.js

// Generates content urls, for usage by other js functions
function buildContentURL(key) {

	if (requestType == 'statictml' || requestType == 'null') {
		return "";
	}


	if (mediaKeyMode == 1) {
		if (key != null) {
			return WGPPath + "/" + myLayout + "/" + key + "." + myMedium;
		}
		else {
			return WGPPath + "/" + myLayout + "." + myMedium;
		}
	}
	else {
		if (key != null) {
			return WGPPath + "/" + myMedium + "/" + myLayout + "/" + key;
		}
		else {
			return WGPPath + "/" + myMedium + "/" + myLayout;
		}
	}
}

// Loads content of the given key
function loadContent(key) {

	location.href = buildContentURL(key);

	
}

function callAction(actionLink) {

	if (actionLink.indexOf('/') == -1) {
		location.href = buildContentURL(myContentKey) + "?$action=" + actionLink;
	}
	else {
		var divider = actionLink.indexOf('/');
		var formID = actionLink.substring(0, divider);
		var realActionLink = actionLink.substring(divider + 1);
		var form = document.forms[formID];
		if( !form || !form.$formaction){
			alert("Error while calling action. TMLForm \"" + formID + "\" not found.");
			return false;
		}
		form.$formaction.value = realActionLink;
		form.submit();
	}
	return true;
}