function ce(i)
{
	document.f.e.value = i;
	document.f.target = "_self";
	sv();
	if(document.f.j.checked)
		document.f.submit();
}

function ces(i)
{
	document.f.e.value = i;
	document.f.target = "_blank";
	document.f.w.checked = true;
	document.f.w.value = true;
	sv();
	document.f.submit();
}

function cen(f)
{
	if(f)
		document.f.e.value++;
	else
		document.f.e.value--;
	sv();
	document.f.submit();
}

function rc(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 ""; 
}

function sv()
{
	if (document.f.w.checked)
	{
		document.f.target = "_blank";
		document.f.w.checked = true;
		document.f.w.value = true;
	}
	else
	{
		document.f.target = "_self";
		document.f.w.checked = false;
		document.f.w.value = false;
	}
	
	if (document.f.j.checked)
	{
		document.f.j.checked = true;
		document.f.j.value = true;
	}
	else
	{
		document.f.j.checked = false;
		document.f.j.value = false;
	}
	
	if(!document.f.e.value)
		document.f.e.value = "1";
	
	if(!document.f.c.value)
		document.f.c.value = "0";
	
	var d = new Date();
	d = new Date(d.getTime() + 1000*60*60*24*365);
	document.cookie = "e=" + document.f.e.value + "; expires=" + d.toGMTString() + "; path=/;";
	document.cookie = "q=" + document.f.q.value + "; expires=" + d.toGMTString() + "; path=/;";
	document.cookie = "c=" + document.f.c.value + "; expires=" + d.toGMTString() + "; path=/;";
	document.cookie = "w=" + document.f.w.checked + "; expires=" + d.toGMTString() + "; path=/;";
	document.cookie = "j=" + document.f.j.checked + "; expires=" + d.toGMTString() + "; path=/;";
	
	document.images.ei.src = "/v0.1/i/" + document.f.e.value + ".gif";
	if(typeof(document.images[document.f.e.value]) !== 'undefined')
		document.images.ei.title = document.images[document.f.e.value].title;
}

function sendRequest(id){
	var req;
	try{
		req = window.XMLHttpRequest?new XMLHttpRequest(): 
		new ActiveXObject("Microsoft.XMLHTTP"); 
	} catch (e) {
		//no ajax
	}

	req.onreadystatechange = function() {
		if ((req.readyState == 4) && (req.status == 200)) { 
			document.getElementById('pC' + id).innerHTML = req.responseText;
		}
	};
	//var id = document.getElementById('dropdown').value;
	req.open('post', 'db.php');
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	req.send('x=' + id);
}

function bookmarksite(title, url){
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	}
	else if(document.all)// ie
		window.external.AddFavorite(url, title);
}

function addProvider(url){
	try {
		window.external.AddSearchProvider(url);
	} catch (e) {
		alert("You need to be using IE7 or Firefox2 or higher to add a search engine.\r\nYou can also install search plugins by using the drop down menu to the right of the search box.");
		return;
	}
}

var s;
if (!s) s = {};
if (!s.w) s.w = {};

s.w.p = function(element, opts)
{
	this.element = this.getElement(element);
	this.focusElement = null;
	this.hoverClass = "pTabHover";
	this.openClass = "pOpen";
	this.closedClass = "pClosed";
	this.focusedClass = "pFocused";
	this.enableAnimation = false;
	this.enableKeyboardNavigation = false;
	this.animator = null;
	this.hasFocus = false;
	this.contentIsOpen = true;

	this.openPanelKeyCode = s.w.p.KEY_DOWN;
	this.closePanelKeyCode = s.w.p.KEY_UP;

	s.w.p.setOptions(this, opts);

	this.attachBehaviors();
};

s.w.p.prototype.getElement = function(ele)
{
	if (ele && typeof ele == "string")
		return document.getElementById(ele);
	return ele;
};

s.w.p.prototype.addClassName = function(ele, className)
{
	if (!ele || !className || (ele.className && ele.className.search(new RegExp("\\b" + className + "\\b")) != -1))
		return;
	ele.className += (ele.className ? " " : "") + className;
};

s.w.p.prototype.removeClassName = function(ele, className)
{
	if (!ele || !className || (ele.className && ele.className.search(new RegExp("\\b" + className + "\\b")) == -1))
		return;
	ele.className = ele.className.replace(new RegExp("\\s*\\b" + className + "\\b", "g"), "");
};

s.w.p.prototype.hasClassName = function(ele, className)
{
	if (!ele || !className || !ele.className || ele.className.search(new RegExp("\\b" + className + "\\b")) == -1)
		return false;
	return true;
};

s.w.p.prototype.setDisplay = function(ele, display)
{
	if( ele )
		ele.style.display = display;
};

s.w.p.setOptions = function(obj, optionsObj, ignoreUndefinedProps)
{
	if (!optionsObj)
		return;
	for (var optionName in optionsObj)
	{
		if (ignoreUndefinedProps && optionsObj[optionName] == undefined)
			continue;
		obj[optionName] = optionsObj[optionName];
	}
};

s.w.p.prototype.onTabMouseOver = function(e)
{
	this.addClassName(this.getTab(), this.hoverClass);
	return false;
};

s.w.p.prototype.onTabMouseOut = function(e)
{
	this.removeClassName(this.getTab(), this.hoverClass);
	return false;
};

s.w.p.prototype.open = function()
{
	this.contentIsOpen = true;
	if (this.enableAnimation)
	{
		if (this.animator)
			this.animator.stop();
		this.animator = new s.w.p.pa(this, true, { duration: this.duration, fps: this.fps, transition: this.transition });
		this.animator.start();
	}
	else
		this.setDisplay(this.getContent(), "block");

	this.removeClassName(this.element, this.closedClass);
	this.addClassName(this.element, this.openClass);
};

s.w.p.prototype.close = function()
{
	this.contentIsOpen = false;
	if (this.enableAnimation)
	{
		if (this.animator)
			this.animator.stop();
		this.animator = new s.w.p.pa(this, false, { duration: this.duration, fps: this.fps, transition: this.transition });
		this.animator.start();
	}
	else
		this.setDisplay(this.getContent(), "none");

	this.removeClassName(this.element, this.openClass);
	this.addClassName(this.element, this.closedClass);
};

s.w.p.prototype.onTabClick = function(e)
{
	if (this.isOpen())
		this.close();
	else
		this.open();

	this.focus();

	return this.stopPropagation(e);
};

s.w.p.prototype.onFocus = function(e)
{
	this.hasFocus = true;
	this.addClassName(this.element, this.focusedClass);
	return false;
};

s.w.p.prototype.onBlur = function(e)
{
	this.hasFocus = false;
	this.removeClassName(this.element, this.focusedClass);
	return false;
};

s.w.p.KEY_UP = 38;
s.w.p.KEY_DOWN = 40;

s.w.p.prototype.onKeyDown = function(e)
{
	var key = e.keyCode;
	if (!this.hasFocus || (key != this.openPanelKeyCode && key != this.closePanelKeyCode))
		return true;

	if (this.isOpen() && key == this.closePanelKeyCode)
		this.close();
	else if ( key == this.openPanelKeyCode)
		this.open();
	
	return this.stopPropagation(e);
};

s.w.p.prototype.stopPropagation = function(e)
{
	if (e.preventDefault) e.preventDefault();
	else e.returnValue = false;
	if (e.stopPropagation) e.stopPropagation();
	else e.cancelBubble = true;
	return false;
};

s.w.p.prototype.attachPanelHandlers = function()
{
	var tab = this.getTab();
	if (!tab)
		return;

	var self = this;
	s.w.p.addEventListener(tab, "click", function(e) { return self.onTabClick(e); }, false);
	s.w.p.addEventListener(tab, "mouseover", function(e) { return self.onTabMouseOver(e); }, false);
	s.w.p.addEventListener(tab, "mouseout", function(e) { return self.onTabMouseOut(e); }, false);

	if (this.enableKeyboardNavigation)
	{
		var tabIndexEle = null;
		var tabAnchorEle = null;

		this.preorderTraversal(tab, function(node) {
			if (node.nodeType == 1)
			{
				var tabIndexAttr = tab.attributes.getNamedItem("tabindex");
				if (tabIndexAttr)
				{
					tabIndexEle = node;
					return true;
				}
				if (!tabAnchorEle && node.nodeName.toLowerCase() == "a")
					tabAnchorEle = node;
			}
			return false;
		});

		if (tabIndexEle)
			this.focusElement = tabIndexEle;
		else if (tabAnchorEle)
			this.focusElement = tabAnchorEle;

		if (this.focusElement)
		{
			s.w.p.addEventListener(this.focusElement, "focus", function(e) { return self.onFocus(e); }, false);
			s.w.p.addEventListener(this.focusElement, "blur", function(e) { return self.onBlur(e); }, false);
			s.w.p.addEventListener(this.focusElement, "keydown", function(e) { return self.onKeyDown(e); }, false);
		}
	}
};

s.w.p.addEventListener = function(element, eventType, handler, capture)
{
	try
	{
		if (element.addEventListener)
			element.addEventListener(eventType, handler, capture);
		else if (element.attachEvent)
			element.attachEvent("on" + eventType, handler);
	}
	catch (e) {}
};

s.w.p.prototype.preorderTraversal = function(root, func)
{
	var stopTraversal = false;
	if (root)
	{
		stopTraversal = func(root);
		if (root.hasChildNodes())
		{
			var child = root.firstChild;
			while (!stopTraversal && child)
			{
				stopTraversal = this.preorderTraversal(child, func);
				try { child = child.nextSibling; } catch (e) { child = null; }
			}
		}
	}
	return stopTraversal;
};

s.w.p.prototype.attachBehaviors = function()
{
	var panel = this.element;
	var tab = this.getTab();
	var content = this.getContent();

	if (this.contentIsOpen || this.hasClassName(panel, this.openClass))
	{
		this.addClassName(panel, this.openClass);
		this.removeClassName(panel, this.closedClass);
		this.setDisplay(content, "block");
		this.contentIsOpen = true;
	}
	else
	{
		this.removeClassName(panel, this.openClass);
		this.addClassName(panel, this.closedClass);
		this.setDisplay(content, "none");
		this.contentIsOpen = false;
	}

	this.attachPanelHandlers();
};

s.w.p.prototype.getTab = function()
{
	return this.getElementChildren(this.element)[0];
};

s.w.p.prototype.getContent = function()
{
	return this.getElementChildren(this.element)[1];
};

s.w.p.prototype.isOpen = function()
{
	return this.contentIsOpen;
};

s.w.p.prototype.getElementChildren = function(element)
{
	var children = [];
	var child = element.firstChild;
	while (child)
	{
		if (child.nodeType == 1)
			children.push(child);
		child = child.nextSibling;
	}
	return children;
};

s.w.p.prototype.focus = function()
{
	if (this.focusElement && this.focusElement.focus)
		this.focusElement.focus();
};

s.w.p.pa = function(panel, doOpen, opts)
{
	this.timer = null;
	this.interval = 0;

	this.fps = 60;
	this.duration = 500;
	this.startTime = 0;

	this.transition = s.w.p.pa.defaultTransition;

	this.onComplete = null;

	this.panel = panel;
	this.content = panel.getContent();
	this.doOpen = doOpen;

	s.w.p.setOptions(this, opts, true);

	this.interval = Math.floor(1000 / this.fps);

	var c = this.content;

	var curHeight = c.offsetHeight ? c.offsetHeight : 0;
	this.fromHeight = (doOpen && c.style.display == "none") ? 0 : curHeight;

	if (!doOpen)
		this.toHeight = 0;
	else
	{
		if (c.style.display == "none")
		{
			c.style.visibility = "hidden";
			c.style.display = "block";
		}

		c.style.height = "";
		this.toHeight = c.offsetHeight;
	}

	this.distance = this.toHeight - this.fromHeight;
	this.overflow = c.style.overflow;

	c.style.height = this.fromHeight + "px";
	c.style.visibility = "visible";
	c.style.overflow = "hidden";
	c.style.display = "block";
};

s.w.p.pa.defaultTransition = function(time, begin, finish, duration) { time /= duration; return begin + ((2 - time) * time * finish); };

s.w.p.pa.prototype.start = function()
{
	var self = this;
	this.startTime = (new Date).getTime();
	this.timer = setTimeout(function() { self.stepAnimation(); }, this.interval);
};

s.w.p.pa.prototype.stop = function()
{
	if (this.timer)
	{
		clearTimeout(this.timer);

		this.content.style.overflow = this.overflow;
	}

	this.timer = null;
};

s.w.p.pa.prototype.stepAnimation = function()
{
	var curTime = (new Date).getTime();
	var elapsedTime = curTime - this.startTime;

	if (elapsedTime >= this.duration)
	{
		if (!this.doOpen)
			this.content.style.display = "none";
		this.content.style.overflow = this.overflow;
		this.content.style.height = this.toHeight + "px";
		if (this.onComplete)
			this.onComplete();
		return;
	}

	var ht = this.transition(elapsedTime, this.fromHeight, this.distance, this.duration);

	this.content.style.height = ((ht < 0) ? 0 : ht) + "px";

	var self = this;
	this.timer = setTimeout(function() { self.stepAnimation(); }, this.interval);
};

s.w.pg = function(element, opts)
{
	this.element = this.getElement(element);
	this.opts = opts;

	this.attachBehaviors();
};

s.w.pg.prototype.setOptions = s.w.p.prototype.setOptions;
s.w.pg.prototype.getElement = s.w.p.prototype.getElement;
s.w.pg.prototype.getElementChildren = s.w.p.prototype.getElementChildren;

s.w.pg.prototype.setElementw = function(element, w)
{
	if (!element || !w)
		return;
	if (!element.s)
		element.s = new Object;
	element.s.p = w;
};

s.w.pg.prototype.getElementw = function(element)
{
	return (element && element.s && element.s.p) ? element.s.p : null;
};

s.w.pg.prototype.getPanels = function()
{
	if (!this.element)
		return [];
	return this.getElementChildren(this.element);
};

s.w.pg.prototype.getPanel = function(panelIndex)
{
	return this.getPanels()[panelIndex];
};

s.w.pg.prototype.attachBehaviors = function()
{
	if (!this.element)
		return;

	var cpanels = this.getPanels();
	var numCPanels = cpanels.length;
	for (var i = 0; i < numCPanels; i++)
	{
		var cpanel = cpanels[i];
		this.setElementw(cpanel, new s.w.p(cpanel, this.opts));
	}
};

s.w.pg.prototype.openPanel = function(panelIndex)
{
	sendRequest(panelIndex);
	document.f.c.value = panelIndex;
	var w = this.getElementw(this.getPanel(panelIndex));
	if (w && !w.isOpen())
		w.open();
};

s.w.pg.prototype.closePanel = function(panelIndex)
{
	document.f.c.value = 0;
	var w = this.getElementw(this.getPanel(panelIndex));
	if (w && w.isOpen())
		w.close();
};

s.w.pg.prototype.openAllPanels = function()
{
	var cpanels = this.getPanels();
	var numCPanels = cpanels.length;
	for (var i = 0; i < numCPanels; i++)
	{
		var w = this.getElementw(cpanels[i]);
		if (w && !w.isOpen())
			w.open();
	}
};

s.w.pg.prototype.closeAllPanels = function()
{
	var cpanels = this.getPanels();
	var numCPanels = cpanels.length;
	for (var i = 0; i < numCPanels; i++)
	{
		var w = this.getElementw(cpanels[i]);
		if (w && w.isOpen())
			w.close();
	}
};
