function g(Id) {
	return document.getElementById(Id);
}

function ValidateForm(callback) {
	returnValue = callback();
	if(typeof(returnValue) == 'undefined') {
		returnValue = true;
	}
	if(window.event) {
		window.event.returnValue = returnValue;
	}
	else {
		return returnValue;
	}
}

function IsWysiwygEditorEmpty(contents) {
	var contents = contents.replace(/(&nbsp;|<br>|<br\s?\/>|<p><\/p>|\s)/gi,'');
	if(contents == '') {
		return true;
	}
	return false;
}

function ShowHelp(img, title, desc)
{
	img = document.getElementById(img);
	div = document.createElement('div');
	div.id = 'help';

	div.style.display = 'inline';
	div.style.position = 'absolute';
	div.style.width = '350';

	div.style.backgroundColor = '#FEFCD5';
	div.style.border = 'solid 1px #E7E3BE';
	div.style.padding = '10px';
	div.innerHTML = '<span class=helpTip><strong>' + title + '<\/strong><\/span><br /><img src=images/1x1.gif width=1 height=5><br /><div style="padding-left:10; padding-right:5" class=helpTip>' + desc + '<\/div>';

	img.parentNode.appendChild(div);
	var parent = img.parentNode;
	if(img.nextSibling)
	{
		parent.insertBefore(div, img.nextSibling);
	} else {
		parent.appendChild(div);
	}
 
}


	function HideQuickHelp(p)
	{
		if (jQuery("#help").length) {
			jQuery("#help").css('display','none');
			setTimeout('RemoveHelp()', 1);
		}
	}

	function RemoveHelp() {
		jQuery("#help").remove();
	}


	function HideHelp(img)
	{
		if (jQuery("#help").length) {
			jQuery("#help").css('display','none');
			setTimeout('RemoveHelp()', 1);
		}
	}
	
function display_error(id,message,timeout){
	if($('#'+id+' .MessageBox').get() != "") {
		$('#'+id).fadeOut('slow');
		$('#'+id).html('<div class="MessageBox MessageBoxInfo">'+message+'</div>').fadeIn('slow');
	}
	else {
		$('#'+id).hide().html('<div class="MessageBox MessageBoxInfo">'+message+'</div>').show('slow');
	}
	if(timeout > 0) {
		window.setTimeout(function() { $('#'+id).hide('slow'); }, timeout);
	}
}

function display_success(id,message,timeout){
	if($('#'+id+' .MessageBox').get() != "") {
		$('#'+id).fadeOut('slow');
		$('#'+id).html('<div class="MessageBox MessageBoxSuccess">'+message+'</div>').fadeIn('slow');
	}
	else {
		$('#'+id).hide().html('<div class="MessageBox MessageBoxSuccess">'+message+'</div>').show('slow');
	}
	if(timeout > 0) {
		window.setTimeout(function() { $('#'+id).hide('slow'); }, timeout);
	}
}

function AJAX_fetch_populate(div,file,method,params_string) {
	$.ajax({
		type: method,
		url: file,
		data: params_string,
		timeout: 20000,
		error: function (XMLHttpRequest, textStatus, errorThrown) {
			AJAX_error(XMLHttpRequest, textStatus, errorThrown);
		},
		success: function(html){
			$("#" + div).html(html);
			AJAX_success();
		}
	});
}

function AJAX_success() {
	document.body.style.cursor = "auto";
	HideLoadingIndicator();
}

function AJAX_error(XMLHttpRequest, textStatus, errorThrown) {
	alert("I'm sorry there has been an error trying to grab remote data.\n\nPlease try again later.");
}

function ShowLoadingIndicator() {
	if (typeof(disableLoadingIndicator) != 'undefined' && disableLoadingIndicator) {
		return;
	}
	var windowWidth = $(window).width();
	var scrollTop;
	if(self.pageYOffset) {
		scrollTop = self.pageYOffset;
	}
	else if(document.documentElemet && document.documentElement.scrollTop) {
		scrollTop = document.documentElement.scrolTop;
	}
	else if(document.body) {
		scrollTop = document.body.scrollTop;
	}
	$('#AjaxLoading').css('position', 'absolute');
	$('#AjaxLoading').css('top', scrollTop+'px');
	$('#AjaxLoading').css('left', parseInt((windowWidth-150)/2)+"px");
	$('#AjaxLoading').show();
}

function HideLoadingIndicator() {
	$('#AjaxLoading').hide();
}


jQuery(document).ready(function() {
	$('html').ajaxStart(function() {
		ShowLoadingIndicator();
	});

	$('html').ajaxComplete(function() {
		HideLoadingIndicator();
	});
	$('.InitialFocus').focus();
});
