function add_onload(element, new_function) {
	var old_onload = element.onload;
	if (typeof old_onload != 'function') {
		old_onload = function(){};
	}
	element.onload = function (){
		old_onload();
		new_function();
	}
}
function add_onunload(element, new_function) {
	var old_onunload = element.onunload;
	if (typeof old_onunload != 'function') {
		old_onunload = function(){};
	}
	element.onunload = function (){
		old_onunload();
		new_function();
	}
}
function add_onfocus(element, new_function) {
	var old_onfocus = element.onfocus;
	if (typeof old_onfocus != 'function') {
		old_onfocus = function(){};
	}
	element.onfocus = function (){
		old_onfocus();
		new_function();
	}
}
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
//====== SlideDown Script ============//
var ds_slide = {
	current: "",
	forms: new Array(),
	toggleForm: function(id) {
		if (document.getElementById){
			var nextForm = document.getElementById(id);
			var currentForm = ds_slide.getCurrentForm();
			if (nextForm == currentForm){
				ds_slide.hideForm(nextForm);
			} else if(!currentForm) {
				ds_slide.showForm(nextForm);
			} else {
				ds_slide.swapForms(currentForm, nextForm);
			}
		}
	}, 
	getCurrentForm: function(){
		var ret = false;
		if(document.getElementById){
			ds_slide.forms[0] = document.getElementById('login'),
			ds_slide.forms[1] = document.getElementById('subscribe'),
			ds_slide.forms[2] = document.getElementById('search')
			for(x in ds_slide.forms){
				if (ds_slide.forms[x].style && ds_slide.forms[x].style.visibility && ds_slide.forms[x].style.visibility == "visible"){
					ret = ds_slide.forms[x];
				}
			}
		}
		return ret;
	},
	hideForm: function(x,y){
		if (!y) {
			ds_slide.current = setInterval("ds_slide.close('"+x.id+"')", 5);
		} else {
			ds_slide.current = setInterval("ds_slide.close('"+x.id+"','"+y.id+"')", 5);
		}
	},
	showForm: function(x){
		x.style.visibility = "visible";
		ds_slide.current = setInterval("ds_slide.open('"+x.id+"')", 5);
	},
	swapForms: function(x,y){
		ds_slide.hideForm(x,y);
	},
	open: function(x){
		x = document.getElementById(x);
		var currentHeight = x.parentNode.style.height.match(/-?\d+/);
		var nextHeight = Number(currentHeight) + 2;
		if (nextHeight > 60){
			clearInterval(ds_slide.current);
		} else {
			x.parentNode.style.height = nextHeight+"px";
		}
	},
	close: function(x, y) {
		x = document.getElementById(x);
		var currentHeight = x.parentNode.style.height.match(/-?\d+/);
		var nextHeight = Number(currentHeight) - 2;
		if (nextHeight < 0){
			clearInterval(ds_slide.current);
			x.style.visibility = "hidden";
			if (y){
				ds_slide.showForm(document.getElementById(y));
			}
		} else {
			x.parentNode.style.height = nextHeight+"px";
		}
	}
}
