function ClearSetValue(objField, blnClear) {
	if (blnClear) {
		if (objField.value == objField.defaultValue) objField.value = '';
	}
	else {
		if (objField.value == '') objField.value = objField.defaultValue;
	}
}
function LaunchEditor(strForm, strField, strAction, intMode) {
	if (document.forms[strForm]) {
		if (!intMode) intMode = 0;
		Popup('/events/assets/editor/?form=' + strForm + '&field=' + strField + '&action=' + escape(strAction) + '&mode=' + intMode, 'editor', 632, 510, 'no', 'no');
	}
}
function Popup(strURL, strName, intWidth, intHeight, strStatus, strScroll, strResize, strToolbar, strMenu, intTop, intLeft) {
	if (!strURL) {
		alert('A link must be specified when using the Popup function.');
	}
	else {
		window.name = 'popupopener';
		var strTop, strLeft;
		if (!strName) strName = 'popup';
		if (!intWidth) intWidth = 600;
		if (intWidth > (window.screen.width - 25)) intWidth = (window.screen.width - 25);
		if (!intHeight) intHeight = 400;
		if (intHeight > (window.screen.height - 125)) intHeight = (window.screen.height - 125);
		if (!strStatus) strStatus = 'yes';
		if (!strScroll) strScroll = 'yes';
		if (!strResize) strResize = 'yes';
		if (!strToolbar) strToolbar = 'no';
		if (!strMenu) strMenu = 'no';
		if (intTop && !isNaN(intTop)) strTop = ',top=' + intTop;
		if (intLeft && !isNaN(intLeft)) strLeft = ',left=' + intLeft;
		var objWindow = window.open(strURL, strName, 'width=' + intWidth + ',height=' + intHeight + ',status=' + strStatus + ',scrollbars=' + strScroll + ',resizable=' + strResize + ',toolbar=' + strToolbar + ',menubar=' + strMenu + strTop + strLeft);
		objWindow.focus();
	}
}

function Popdown(strURL, blnLeaveOpen) {
	if (!strURL) {
		alert('A link must be specified when using the Popdown function.');
	}
	else {
		if (top.opener) {
			var objParent = top.opener;
			objParent.location.href = strURL;
			if (!blnLeaveOpen) {
				objParent.focus();
				top.close();
			}
		}
		else {
			alert('Unfortunately the link could not be followed.\nThe window that opened this page may have\nbeen closed, or your browser may not\nsupport this function.');
		}
	}
}

function Opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("setOpacity(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("setOpacity(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function setOpacity(opacity, id) {
    var object = document.getElementById(id).style;
    object.display = "block";
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 

function getTimeBetweenFades() {
	return 1000 * 11; // seconds
}

function initiliseFadeAnnouncments() {
	if (window.addEventListener) //DOM method for binding an event
		window.addEventListener("load", initiliseFadeAnnouncmentsOnLoad, false)
	else if (window.attachEvent) //IE exclusive method for binding an event
		window.attachEvent("onload", initiliseFadeAnnouncmentsOnLoad)
	else if (document.getElementById) //support older modern browsers
		window.onload=initiliseFadeAnnouncmentsOnLoad
	
}

function initiliseFadeAnnouncmentsOnLoad() {
	setTimeout("fadeAnnouncments(1)", getTimeBetweenFades() / 2);
}

function fadeAnnouncments(i) {
	var id = "announcment_" + i;
		
	Opacity(id, 100, 0, 500); // hide
	
	i++;
	

	if ( document.getElementById("announcment_" + i) == null ) {
		i = 1;
	}
	id = "announcment_" + i;

	
	Opacity(id, 0, 100, 500); // show

	setTimeout("fadeAnnouncments(" + i + ")", getTimeBetweenFades());
}


function addEventHandler(elementObject, eventName, functionObject)
{
	if(document.addEventListener)
		elementObject.addEventListener(eventName, functionObject, false);
	else
		if(document.attachEvent)
			elementObject.attachEvent("on" + eventName, functionObject);
}
