if ( Element.Methods[ 'removeChildNodes' ] == null ) {
	Element.addMethods( {
		removeChildNodes:function( ctrl ) {
			ctrl = $( ctrl );
			while ( ctrl.childNodes[ 0 ] ) {
				ctrl.removeChild( ctrl.childNodes[ 0 ] );
			}
			return ctrl;
		}
	} );
}

function teamNav() {
	var w = document.fbTeam.team.selectedIndex;
	var url_add = document.fbTeam.team.options[w].value;
	window.location.href = url_add;
}

function removeChildNodes( ctrl ) {
	while ( ctrl.childNodes[ 0 ] ) {
		ctrl.removeChild( ctrl.childNodes[ 0 ] );
	}
}

function performSearch( which ) {
	if ( document.getElementById( which + '_search_web' ).checked ) {
		document.location = 'http://search.dailyherald.com/results/web/?Query=' + document.getElementById( which + '_search_box' ).value;
	}
	else {
		document.location = 'http://search.dailyherald.com/results/news/?Query=' + document.getElementById( which + '_search_box' ).value;
	}
	return false;
}


function CaspioDataPage( appKey, protocal, args ) {
	this.appKey = appKey;
	this.protocal = protocal;
	this.host = window.location.host;
	this.pathName = window.location.pathname;
	this.search = window.location.search;
	this.args = args;

	if ( this.args != null ) {
		for ( var i in this.args ) {
			this.search += ( this.search.indexOf( '?' ) > -1 ? '&' : '?' ) + i + '=' + args[ i ];
		}
	}
	
	this.load = function() {
		var v_path = this.pathName + this.search;

		if ( ( v_path.toUpperCase().indexOf( "DP.ASP?APPKEY=" ) != -1 ) || ( v_path.toUpperCase().indexOf("DP.ASP?APPSESSION=") != -1) ) { 
			document.write( "<br/><b>Error</b></br>" );
		}
		else {
			if ( this.args[ 'cache' ] ) {
				document.write( "<scri" + "pt type=\"text/javascript\" src=\"" + this.protocal + "//i.dailyherald.com/caspio_cache/?AppKey=" + this.appKey + "&amp;js=true&amp;pathname="+ window.location.protocol + "//" + this.host + this.pathName + "&amp;" + this.search + "\"></scr" + "ipt>" );
			}
			else {
				document.write( "<scri" + "pt type=\"text/javascript\" src=\"" + this.protocal + "//b2.caspio.com/dp.asp?AppKey=" + this.appKey + "&amp;js=true&amp;pathname="+ window.location.protocol + "//" + this.host + this.pathName + "&amp;" + this.search + "\"></scr" + "ipt>" );
			}
		}
	}
}

function loginText() {
	$( 'memberBox' ).removeChildNodes();

	if ( dhUser ) {
		$( 'memberBox' ).insert( new Element( 'span' ).update( 'Welcome,&nbsp;' ) ).insert( new Element( 'a', { 'href':'http://my.dailyherald.com/account/', 'title':'Edit your DailyHerald.com profile', 'class':'loginText' } ).update( dhUser.displayName ) ).insert( new Element( 'span' ).update( '| &nbsp;' ) ).insert( new Element( 'a', { 'href':'http://my.dailyherald.com/account/logout/', 'title':'Log out of DailyHerald.com', 'class':'loginText' } ).update( 'Logout' ) );
	}
	else {
		$( 'memberBox' ).insert( new Element( 'a', { 'href':'http://my.dailyherald.com/account/', 'title':'Create a DailyHerald.com account', 'class':'signUp' } ).update( 'sign up' ) ).insert( new Element( 'span' ).update( '| &nbsp;' ) ).insert( new Element( 'a', { 'href':'http://my.dailyherald.com/account/', 'title':'Sign in to your DailyHerald.com account', 'class':'signIp' } ).update( 'sign in' ) ).insert( new Element( 'span' ).update( ' &nbsp;You are not logged in!' ) );
	}
}
