function $(e){return document.getElementById(e);}
function $$(s){return document.getElementsByTagName(s);}


function processX1924s() {
	var a = getElementsByClassName('x1924','span');
	var n = a.length;
	
	for(var i=n-1;i>=0;i--)
	{
		var show = a[i].innerHTML.split('|')[1];
		var s = a[i].innerHTML.split('|')[0];
			s = s.replace('#','@').split('').reverse().join('');
		var maxlen = getVagueC(a[i],'len');
		if (!show)
			show = (s.length<=maxlen) ? s : s.substring(0,maxlen-4) + '...';
		
		var z = document.createElement('a');
		z.href = 'ma'+'il'+''+'to'+''+""+':'+s;
		z.innerHTML = show;
		a[i].parentNode.insertBefore(z,a[i]);
		a[i].parentNode.removeChild(a[i]);
		a[i].style.visibility='visible';
		a[i].style.display='inline';
	}
}
addE(window,'load',processX1924s);


function addC(e,c) {
	if(!e.className)
		e.className=c;
	else
		if(!hasC(e,c))
			e.className+=' '+c;
}


function delC(e,c) {
	if(e.className) {
		var a = new Array();
			a = e.className.split(' ');
		
		for (var i=0;i<a.length;i++)
			if (a[i]==c)
				a.splice(i,1);
		
		e.className = a.join(' ');
	}
}


function hasC(e,c) {
	if(e.className)
	{
		cs = e.className.split(' ');
		for(var i=0;i<cs.length;i++)
			if(cs[i]==c) return true;
	}
	return false;
}


function getVagueC(e,c) {
	if(e.className)
	{
		cs = e.className.split(' ');
		for(var i=0;i<cs.length;i++)
			if(cs[i].substring(0,c.length)==c) return cs[i].substring(c.length);
	}
	return false;
}


function toggleClass(e,c) {
	if(hasC(e,c))
		delC(e,c);
	else
		addC(e,c);
}


function isInside(eChild,eParent)
{
	if (eChild===eParent)
		return true;
	else if (eChild===document)
		return false;
	else
		return isInside(eChild.parentNode,eParent);
}


function getElementsByTagNames(s,r) {
	if (!r) r = document;
	
	var e = new Array();
	var a = s.split(' ');
	
	for(var i=0;i<a.length;i++)
	{
		var t = r.getElementsByTagName(a[i]);
		var n = t.length;
		
		for(var j=0;j<n;j++)
			e.push(t[j]);
	}
	
	return e;
}



/* concern, what if fn is very long - "e"+type+fn */
function addE(o,e,f) {
	if (o.addEventListener)
		o.addEventListener(e,f,false);
	else if (o.attachEvent)	{
		o['e'+e+f] = f;
		o[e+f] = function(){o['e'+e+f](window.event);}
		o.attachEvent('on'+e,o[e+f]);
	}
}



function removeEvent( obj, type, fn ) {
  if ( obj.detachEvent ) {
    obj.detachEvent( 'on'+type, obj[type+fn] );
    obj[type+fn] = null;
  } else
    obj.removeEventListener( type, fn, false );
}

/* the old one that doesn't let you use 'this' in IE
function addE(o,e,f) {
	if (o.addEventListener)
		o.addEventListener(e,f,false);
	else if (o.attachEvent)
		o.attachEvent('on'+e,f);
}*/


function getTarget(e) {
	var f=e||window.event;
	return f.target||f.srcElement;
}


function getOffset(elem)
{
	children = elem.parentNode.getElementsByTagName(elem.nodeName);
	
	for(i=0;i<children.length;i++)
		if (children[i]===elem)
			return i;
	
	return false;
}


function initFieldClear(s) {
	var a=s.split(',');
	function nuke() {if(this.value==this.example){this.value='';delC(this,'note');}};
	function rstr() {if(this.value==''){this.value=this.example;addC(this,'note');}};
	
	for(i=0;i<a.length;i++) {
		if ($(a[i]) && hasC($(a[i]),'note'))
		{
			$(a[i]).example=$(a[i]).value;
			$(a[i]).onfocus=nuke;
			$(a[i]).onblur=rstr;
		}
	}
}

function AjaxInstance(u,f)
{
	var r = i();
		r.onreadystatechange = p;
	
	function i()
	{
		if (window.XMLHttpRequest)
			return new XMLHttpRequest();
		else if (window.ActiveXObject)
			return new ActiveXObject('Microsoft.XMLHTTP');
		else
			return NULL;
	}
	
	function p()
	{
		if (r.readyState==4 && r.status==200 && f)
			f(r.responseText);
	}
	
	this.POST = function(s)
	{
		r.open('POST',u,true);
		r.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		r.send(s);
	};
	
	this.GET = function()
	{
		r.open('GET',u,true);
		r.send(null);
	};
}



function getElementsByClassName(c, t, e){
	var e = e || document;
	
	if (e.getElementsByClassName && t=='')
		return e.getElementsByClassName(c);
	else {
		var q = new RegExp("(^|\\s)" + c + "(\\s|$)");
		var t = t || "*";
		var r = [];
		var z;
		
		var a = (t == "*" && e.all)? e.all : e.getElementsByTagName(t);
		var n = a.length;
		
		for(var i=0; i<n; i++){
			z = a[i];
			
			if (q.test(z.className))
				r.push(z);
		}
		
		return r;
	}
}



function initPagingLinks() {
	var a = getElementsByClassName('paging');
	var n = a.length;
	
	var d = document.documentElement;
								
	for(var i=0;i<n;i++) {
		var l = a[i].getElementsByTagName('a');
		var j = l.length;
		
		for(var k=0;k<j;k++) {
			l[k].onclick = function() {
								var s = this.href;
									s = s.substring(0,s.lastIndexOf('#'));
								
								//this convolution needed to fix google chrome bug http://code.google.com/p/chromium/issues/detail?id=2891
								var scrollTop = (d.scrollTop >= document.body.scrollTop) ? d.scrollTop : document.body.scrollTop;
								
								if (scrollTop) {
									s += (s.indexOf('?')>0) ? '&' : '?';
									s += 'y='+scrollTop;
								}
								this.href = s;
							}
		}
	}
	
	
	a = getElementsByClassName('list');
	n = a.length;
	
	for(i=0;i<n;i++) {
		l = a[i].getElementsByTagName('thead')[0].getElementsByTagName('a');
		j = l.length;
		
		for(k=0;k<j;k++) {
			l[k].onclick = function() {
								var s = this.href;
									s = s.substring(0,s.lastIndexOf('#'));
								
								//this convolution needed to fix google chrome bug http://code.google.com/p/chromium/issues/detail?id=2891
								var scrollTop = (d.scrollTop >= document.body.scrollTop) ? d.scrollTop : document.body.scrollTop;
								
								if (scrollTop) {
									s += (s.indexOf('?')>0) ? '&' : '?';
									s += 'y='+scrollTop;
								}
								this.href = s;
							}
		}
	}
	
	a = getElementsByClassName('tablemodifiers');
	n = a.length;
	
	for(i=0;i<n;i++) {
		l = a[i].getElementsByTagName('a');
		j = l.length;
		
		for(k=0;k<j;k++) {
			l[k].onclick = function() {
								var s = this.href;
									s = s.substring(0,s.lastIndexOf('#'));
								
								//this convolution needed to fix google chrome bug http://code.google.com/p/chromium/issues/detail?id=2891
								var scrollTop = (d.scrollTop >= document.body.scrollTop) ? d.scrollTop : document.body.scrollTop;
								
								if (scrollTop) {
									s += (s.indexOf('?')>0) ? '&' : '?';
									s += 'y='+scrollTop;
								}
								this.href = s;
							}
		}
	}
}

function getForm(o) {
	var f=o.parentNode;
	return (f.tagName=='FORM')?f:getForm(f);
}
	

function scrollWindow() {
	if (scrollX || scrollY) window.scrollTo(scrollX,scrollY);
}

function createCookie(name,value,days,domain) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	
	var sDomain = (domain) ? '; domain='+domain : '';
	
	document.cookie = name+"="+value+expires+"; path=/";
	//alert(name+"="+value+expires+"; path=/");
}

function processFilterForm() {
	var f = $('filterform');
	
	if (f) {
		var a = f.getElementsByTagName('input');
		var n = a.length;

		for (var i=0;i<n;i++)
			a[i].onclick = function() {
				if (this.type=='checkbox')
					createCookie(this.name,this.checked,30);
				else
					createCookie(this.name,this.value,30);
				
				getForm(this).submit();
			};
		
		a = f.getElementsByTagName('select');
		n = a.length;

		for (var i=0;i<n;i++)
			a[i].onchange = function() {
				createCookie(this.name,this.value,30);
				getForm(this).submit();
			};
	}
}




function initPage() {
	initFieldClear('q');
	if ($('s')) $('s').focus();
	scrollWindow();
	processFilterForm();
}





addE(window,'load',initPagingLinks);
addE(window,'load',initPage);
