﻿try {document.execCommand("backgroundimagecache", false, true)} catch (e) {}

var Cookie={
	set:function(c_name,value) {
		var today = new Date;
		today.setDate(today.getDate()+3650);
		document.cookie=c_name + "=" + escape(value) + ";expires=" + today.toGMTString() + ";path=/";
	},
	get:function(c_name) {
		if (document.cookie.length>0) { 
			c_start=document.cookie.indexOf(c_name + "=");
			if (c_start!=-1) { 
				c_start=c_start + c_name.length+1; 
				c_end=document.cookie.indexOf(";",c_start);
				if (c_end==-1) c_end=document.cookie.length;
				return unescape(document.cookie.substring(c_start,c_end));
			} 
		}
		return null;
	},
	remove:function(c_name) {this.set(c_name,"",-1);}
}


Event.observe(window, "load" ,function() {
	var Expandable = {
		Batchers: $A(),
		Items : $A(),
		BatchState : false,
		duration : 0.3,
		Toggle : function() {
			var container = this.parentNode.parentNode.parentNode;
			var content = this.parentNode.nextSibling;
			if (!container.lock && content) {
				var expanded = arguments.length == 1 && "boolean" == typeof arguments[0] ? !arguments[0] : Element.hasClassName(container, "expanded");
				if (expanded) {
					Effect.BlindUp(content, {duration:Expandable.duration});
					container.lock = setTimeout(function() {
						Element.addClassName(this, "collapsed");
						Element.removeClassName(this, "expanded");
						if (document.getElementsByClassName("expanded").length == 0) {
							Expandable.BatchState = false;
							Expandable.Batchers.each(function(e) {
								Element.cleanWhitespace(e);
								var text = e.firstChild.title.split("/");
								e.firstChild.innerHTML = text[0];
							})
						}
						this.lock = false;
					}.bind(container), Expandable.duration * 1000);
				}
				else {
					Element.addClassName(container, "expanded");
					Element.removeClassName(container, "collapsed");
					Effect.BlindDown(content, {duration:Expandable.duration});
					if (document.getElementsByClassName("collapsed").length == 0) {
						Expandable.BatchState = true;
						Expandable.Batchers.each(function(e) {
							Element.cleanWhitespace(e);
							var text = e.firstChild.title.split("/");
							e.firstChild.innerHTML = text[1];
						})
					}
				};
			};
		},
		Batch : function() {
			Element.cleanWhitespace(this);
			Expandable.BatchState = !Expandable.BatchState;
			Expandable.Items.each(function(e) {
				Expandable.Toggle.apply(e, [Expandable.BatchState]);
			});
		}
	};
	var Redirect = {
		container:{}
	};
	Behaviour.register({
		"button.expander" : function(button) {
			Expandable.Batchers.push(button);
			Event.observe(button, "click", Expandable.Batch.bind(button));
		},
		"a.expander_focus" : function(link) {
			Event.observe(link, "click", function() {
				var anchors = document.getElementsBySelector("a[name="+link.hash.substring(1)+"]");
				if (anchors && anchors[0]) {
					Expandable.Toggle.apply(anchors[0], [true]);
				}
			}.bind(link))
		},
		"div.moduledesc div.bottom h1 a" : function(title) {
			if (title.href.indexOf("javascript:") > -1) {
				Expandable.Items.push(title);
				Element.cleanWhitespace(title.parentNode.parentNode);
				Event.observe(title, "click", Expandable.Toggle.bind(title));
			}
		},
		"ul.contributors a" : function(title) {
			Element.cleanWhitespace(title.parentNode);
			Event.observe(title, "mouseover", function() {
				var popup = title.nextSibling;
				if (popup) Element.addClassName(popup, "visible");
			}.bind(title));
			Event.observe(title, "mouseout", function() {
				var popup = title.nextSibling;
				if (popup) Element.removeClassName(popup, "visible");
			}.bind(title));
		},
		"a[target=_blank]" : function(link) {
			if (link.id != "exiter" && link.id != "help" && !Element.hasClassName(link, "help")) {
				link.redirect = link.href;
				link.href = "javascript://popup: " + link.href;
				link.target = "_self";
				Event.observe(link, "click", function() {
					
					var redirectUrl = Element.hasClassName(this, "internal") ? "" : document.getElementById("outboundRedirect").getAttribute("value") + "?page=";
					var redirectPath = Element.hasClassName(this, "internal") ? this.redirect : escape(this.redirect)
					Redirect.container = window.open(redirectUrl + redirectPath,"","width=400,height=540,resizable=yes");
					Redirect.container.focus();
					return false;
				}.bind(link));
			}
			else if (link.id == "help" || Element.hasClassName(link, "help")){
				link.redirect = link.href;
				link.href = "javascript://popup: " + link.href;
				link.target="_self";
				Event.observe(link, "click", function() {					
					window.open(link.redirect, "","width=800,height=500,scrollbars,status,resizable")
					return false;
				}.bind(link));
			}
			else {
				Event.observe(link, "click", function() {					
					window.close();
					window.open(link.href, "","width=800,height=475,scrollbars,location,status,toolbar,menubar,resizable")
					return false;
				}.bind(link));
			}
		},
		".primarynav a" : function(link){
			if (link.href.indexOf("void(0)") >= 0) Element.addClassName(link,"disablednav");	
		},
		".secondarynav a" : function(link){
			if (link.href.indexOf("void(0)") >= 0) Element.addClassName(link,"disablednav");	
		},
		"input[type=checkbox]" : function(input) {
			if (input.attributes["onpropertychange"]) {
				input._onchange = input.onchange;
				input.onchange = null;
				input.onpropertychange = function() {
					if (window.event && window.event.propertyName=='checked') this._onchange();
				}
			}
		}
	});
	Behaviour.apply();
});

var toggleBox = function(id, status) {
	Element[status ? "removeClassName" : "addClassName"](document.getElementById(id), "nextdisabled");
}

var disableNext = function() {
	toggleBox("buttonNext", false);
}