
function Page()
{
	this.panels = new Array();
//	this.checkForOutage();
	return this;
}

Page.prototype.rssUrl = "mvnews-rss.cgi";
Page.prototype.mapviewerURL = "maps.cgi";

Page.prototype.initIdList = function(array)
{
	this.idList = new Object();
	if(array)
		for(var n=0;n<array.length;n++)
			this.idList[array[n]] = true;
}

Page.prototype.initDivContent = function(node, mode, idList)
{
	var nodes = getElementNodes(node);
	for(var n=0;n<nodes.length;n++){
		if(nodes[n].nodeName.toLowerCase() == 'div' && n > 0 && nodes[n-1].nodeName.toLowerCase != 'div'){
			var open = mode || idList[nodes[n].id];
			var h = (new DivContainer()).init(nodes[n], nodes[n-1], open);
		}
	}
}

Page.prototype.resetIdCache = function()
{
	if(this.idCache){
		var array = new Array();
		for(var name in this.idList)
			if(this.idList[name])
				array.push(name);
		this.idCache.value = array.join(";");
	}
}
Page.prototype.containerDidCollapse = function(note)
{
	if(note.object.id){
		this.idList[note.object.id] = false;
		this.resetIdCache();
	}
}
Page.prototype.containerDidExpand = function(note)
{
	if(note.object.id){
		this.idList[note.object.id] = true;
		this.resetIdCache();
	}
}

Page.prototype.buildInfoDidLoad = function(note)
{
	var href = Utils.valueForKeyPath.apply(note, ["userInfo.object.urls.guide"]);
	if(href){
		var ul = $("resources");
		var li = $element("li");
		var a = $element("a");
		a.href = href;
		a.appendChild($text("Genome Guide"));
		li.appendChild(a);
		ul.appendChild(li);
	}
	var href = Utils.valueForKeyPath.apply(note, ["userInfo.object.urls.ftp"]);
	var anchor = $("build-ftp");
	if(href && anchor)
		anchor.href = href;
}

Page.PageDidClosePanelsNote = "PageDidClosePanelsNote";
Page.PanelDidCloseNote = "PanelDidCloseNote";

Page.prototype.closeAll = function()
{
	for(var n=0;n<this.panels.length;n++){
		this.panels[n].style.visibility = "hidden";
		Notification.postNotification("ContainerDidCollapse", this.panels[n]);
	}
	Notification.postNotification(Page.PageDidClosePanelsNote, this);
}

Page.prototype.closePanel = function(panel, eventObj)
{
	if(panel && panel.nodeName && panel.nodeName.toLowerCase() == "div"){
		panel.style.visibility = "hidden";
		Notification.postNotification(Page.PanelDidCloseNote, panel);
	}
	if(eventObj){
		if(eventObj.stopPropagation)
			eventObj.stopPropagation();
		else
			eventObj.cancelBubble = true;
	}
}

Page.prototype.initInfoPanel = function()
{
	this.infoPanel = $('info-panel');
	if(this.infoPanel){
		this.panels.push(this.infoPanel);
		if(this.infoPanel.addEventListener)
			this.infoPanel.addEventListener('click', function(eventObj){
					eventObj.cancelBubble = true;
				}, false);
		else if(this.infoPanel.attachEvent)
			this.infoPanel.attachEvent('onclick', function(){
					event.cancelBubble = true;
				});
		if(window.DragController)
			DragController.add(this.infoPanel);
	}
}

Page.prototype.showOutage = function(obj)
{
	var box = $("outage-box");
	if(box){
		var div = $element("div");
		div.innerHTML = obj.text;
		box.appendChild(div);
		box.style.display = "block";
	}
}

Page.prototype.checkForOutage = function()
{
	if(this.shouldCheckForOutage)
		Utils.loadHTMLText("Outage.html", this, this.showOutage, null);
}

function enableGroup(node, flag)
{
	var ctrl = _controlForNode(node);
	if(ctrl && ctrl.enableGroup)
		ctrl.enableGroup(flag, node);
	return false;
}

function enableAll(node, flag)
{
	var ctrl = _controlForNode(node);
	if(ctrl && ctrl.enableAll)
		ctrl.enableAll(flag, node);
	return false;
}

function stringByDeletingTrailingSpaces(str)
{
	var n = str.length;
	while(n > 0 && str.charAt(n-1) == ' ') n -= 1;
	if(n < str.length)
		return str.substr(0, n);
	else
		return str;
}

// copy methods; classObj and superClass point to prototypes
function appendMethods(classObj, superClass)
{
	for(var name in superClass){
		if(!classObj[name])
			classObj[name] = superClass[name];
	}
}

function enableGroupTag(node, flag)
{
	var ctrl = _controlForNode(node);
	if(ctrl && ctrl.enableGroupTag){
		var tag = node.getAttribute("tag");
		if(!tag)
			tag = "group";
		var group = node.getAttribute(tag);
		ctrl.enableGroupTag(tag, group, flag);
	}
	return false;
}

function _controlForNode(node)
{
	while(node && !node.control)
		node = node.parentNode;
	return node? node.control : null;
}

function getElementNodes(node)
{
	if(node){
		var array = new Array();
		for(var n=0;n<node.childNodes.length;n++)
			if(node.childNodes[n].nodeType == 1) // element
				array.push(node.childNodes[n]);
		return array;
	}else
		return null;
}
