// thanks mc ;-)
function changeStyle(e,c,i)
{
if (i) e=document.getElementById(e);
e.className=c;
}


function vShowHelpWindow (sHelpUrl)
{
	oWindow = window.open (sHelpUrl, 'helpWindow', 'status=0,toolbar=0,location=0,menubar=0,resizable=1,scrollbars=1');
	oWindow.focus();
}

function swapAccount(id){
	return true;
//	This doesn't do anything right now - disabled
	$.post("/myaccounts/profile-my-accounts.cl",  {action: "setAccount", account_id: id});
	return true;
}

function sGetProperCase(sString) {
	return sString.toLowerCase().replace(/^(.)|\s(.)/g, function($1) { return $1.toUpperCase(); });
}

function vAddAlert (sText, sType) {

	/**
	* Create an alert in the same style as is done by the UserAlert php class, and add it to the DOM
	*/

	/* Types should be lowercase text strings corresponding to those in the UserAlert class, currently the following */
	/* alert, critical, error, warning, notice, information, debug, emergency */

	if (!sType) {
		sType='notice';
	}

	var oContainer = $('#user-alerts-container').get();

	if (!oContainer) {
		alert('useralert container is not present');
		return;
	}

	oDiv = document.createElement('div');
	oDiv.className='user-alerts user-alerts-'+sType;
	oDiv.style.display='none';

	oH2 = document.createElement('h2');
	oTitle = document.createTextNode(sGetProperCase(sType) + ' Message');

	$(oH2).append(oTitle);
	$(oDiv).append(oH2);

	oUL = document.createElement('ul');
	oLI = document.createElement('li');
	oText = document.createTextNode(sText);

	$(oLI).append(oText);
	$(oUL).append(oLI);
	$(oDiv).append(oUL);

	$(oContainer).append(oDiv);
	$(oDiv).show('slow');

}

function vDismissAlert (sMD5, iExpireMinutes) {

	/**
	* Dismiss a user alert
	*/

	$.get("/tools/dismiss-alert.php", {md5: sMD5, expire: iExpireMinutes},
		function (sResponse) {

			aResponse = sResponse.split(' ', 2);

			if (aResponse[0]!='204') {
				alert('Error: ' + aResponse[1]);
			} else {
				$('#'+sMD5).hide();
			}

		}
	)

}

