var __BubbleAllowed = true;

function RowOnClick(EntityName, Id) {
	if (__BubbleAllowed) {
		// alert('A_' + EntityName + '_' + Id);
		var El = document.getElementById('A_' + EntityName + '_' + Id);
		document.location = El.href;
	}

	__BubbleAllowed = true;
}

function CancelBubble() {
	__BubbleAllowed = false;
}

function SCBTC(Obj, Id) {
	Els = document.getElementsByName(Obj.name);
	for ( var i = 0; i < Els.length; i++) {
		if (!Els[i].disabled
				&& Els[i].getAttribute('ParentIds').indexOf(',' + Id + ',') > -1) {
			Els[i].checked = Obj.checked;
		}
	}
}

var __popupChildren = {};
function OpenPopUp(Link, Params) {
	if (!Params) {
		Params = {};
	}

	try {
		Width = Params['W'] > 0 ? Params['W'] : 790;
		Height = Params['H'] > 0 ? Params['H'] : 700;

		var Left = (screen.availWidth - Width) / 2;
		var Top = (screen.availHeight - Height) / 2;

		var Options = 'scrollbars=1,resizable=1,width=' + Width + ',height='
				+ Height + ',left=' + Left + ',top=' + Top;
		// alert(Link.href + '-----------' + Link.id + ' ------------ ' +
		// Options);
		if (!Link.target) {
			Link.target = '1';
		}

		if (__popupChildren[Link.href]) {
			__popupChildren[Link.href].close();
		}

		var Win = window.open(Link.href, Link.target, Options, true);
		__popupChildren[Link.href] = Win;

		Win.focus();
		// Win.alert(__popupChildren[Link.href]);

		return Win;

	} catch (E) {
		// alert(E.message);
		return null;
	}
}

function __Pop(Link, Params) {
	return OpenPopUp(Link, Params) == null;
}

function SetupDialog(ElementId) {
	// alert(ElementId + ', ' + GetCookie(ElementId));
	if (GetCookie(ElementId) != 1) {
		$(document).ready(function() {
			$("#" + ElementId).hide().dialog( {
				modal : true,
				buttons : {
					"Ok" : function() {
						$(this).dialog("close");
					}
				}
			});
		});
	}
}

function SetupHelp() {
	$(document).ready(function() {
		if (GetCookie("Help2") == 1) {
			$("#Help2").hide();
			$('#HelpButton2').show();
		} else {
			$("#Help2").show();
			$('#HelpButton2').hide();
		}
	
		$('#HelpButton2').bind("click", function() {
			if ($("#Help2:hidden").attr('tagName')) {
				$(this).hide();
				$("#Help2").slideDown('fast');
				SetCookie("Help2", 0, 0);
			} else {
				$("#Help2").slideUp('fast');
				$(this).show();
				SetCookie("Help2", 1, 100);
			}
		});
		
		$('#Help2').bind("click", function(e) {
			var offset = $(this).offset();
			var x = e.pageX - offset.left - 5;
			var y = e.pageY - offset.top - 5;
			
			if((this.offsetWidth - x) <= 25 && y <= 25){
				$('#HelpButton2').click();
			}
		});
	});
}

