<!--

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

/*------------------------------------------
   COMMON
------------------------------------------*/
String.prototype.trim = function()
{
    return this.replace(/^\s+|\s+$/, "");
}

Array.prototype.indexOf = function(item, start) 
{ 
	for (var i = (start || 0); i < this.length; i++) 
	{ 
		if (this[i] == item) 
		{ 
			return i; 
		} 
	} 
	return -1; 
}

/*
 * Gets all the Elements by given Class Name. 
 * 
 * @param string searchClass - Name of the css class to look for.
 * @param object node - (optional) The node you want to start from. Defaults to 'document' if none is specified. 
 * @param string tagName - (optional) Limit  results by adding a tagName. Defaults to '*' if none is specified.
 * 
 * @returns array - Returns an array containing all the nodes given by the specified className.
 */ 
function getElementsByClass(searchClass, node, tagName)
{
	var	classElements =	new	Array();
	if (node == null)
		node = document;
	if (tagName ==	null)
		tagName	= '*';
	
	var	els	= node.getElementsByTagName(tagName);
	var	elsLen = els.length;
	
	for	(i = 0,	j =	0; i < elsLen; i++)
	{
		if (hasClass(els[i], searchClass))
		{
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function getClasses(element)
{
	return element.className.trim().split(/\s+/);
}

function hasClass(element, className)
{
	return getClasses(element).indexOf(className) != -1;
}

function addClass(element, className)
{
    var classes = getClasses(element);
    
    if (classes.indexOf(className) == -1)
    {
        classes.push(className);
        element.className = classes.join(' ');
    }
}

function removeClass(element, className)
{
    var classes = getClasses(element);
    var index = classes.indexOf(className);
    
    if (index != -1)
    {
        classes.splice(index, 1);
        element.className = classes.join(' ');
    }
}



/*------------------------------------------
   COOKIES
------------------------------------------*/
function setCookie(name, value, expiredays) { 
	var expire = new Date();	
	expire.setTime(expire.getTime() + (expiredays * 24 * 3600 * 1000));
	document.cookie = name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + expire.toGMTString()) + ";path=/";
}

function getCookie(check_name) {		
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ ) {
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
				
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name ) {
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 ) {
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
		    }		
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ) {
		return null;
	}
}

/*------------------------------------------
   PANEL ENTRY HIGHLIGHTS
------------------------------------------*/

function Highlight(e){	
	document.getElementById(e.id).className = 'highlight';
}

function UnHighlight(e){
	document.getElementById(e.id).style.backgroundColor= '';
	document.getElementById(e.id).className = '';
}

/*------------------------------------------
   TEAM FORM
------------------------------------------*/
function ee() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}

function ToggleForm(obj) {
	var el = ee(obj);
	el.style.visibility = (el.style.visibility != 'hidden' ? 'hidden' : 'visible' );
	ajaxpack.getAjaxRequest("/ajax/toggle_teamform.asp","status=" + (el.style.visibility == 'hidden' ? 'hidden' : 'visible' )  , processAjax, "txt")		
	
	
	el =document.getElementById('pos_change');
	el.style.visibility = (el.style.visibility != 'hidden' ? 'hidden' : 'visible' );
	
	
	//ee('form_toggle').innerHTML = (el.style.display == 'none' ? 'show form' : 'hide form' );
	
	
	return false;
}


/*------------------------------------------
   Y FACILS
------------------------------------------*/

function ToggleFacilityFeature(id) {
	var el = document.getElementById(id);
	el.style.display = (el.style.display != 'none' ? 'none' : 'block' );	
	return false;
}



/*------------------------------------------
   
------------------------------------------*/
function processAjax() {
}


function ChangeLeague(page, game, type) {				
	var sel_league;
	for (var i=0;i < document.form1.league_list.length; i++) {		
			if (document.form1.league_list[i].selected) {sel_league = document.form1.league_list[i].value;}		
		}				
	var address=page + '.asp?g=' + game + "&l=" + sel_league + "&d=1&type=" + type;		
	var target='_top';
	window.open(address,target);
}
/*------------------------------------------
   MISC
------------------------------------------*/

function focusInput() {
    var isfocused = false;
    var elms = ['user','pass'];
    
    for(var i=0;i<elms.length;i++){
        var elm = document.getElementById(elms[i]);
        if(elm !== undefined){
            if(elm.value != elm.defaultValue){
                isfocused = true;
            }
        }
    }
    if(isfocused != true){
        document.getElementById('user').focus();
    }
}    



function redirect(address) {	
   	var name='_top';   	
	window.open(address,name);		
}	

function padlength(what){
	var output=(what.toString().length==1)? "0"+what : what
	return output
}

function displaytime(){
	serverdate.setSeconds(serverdate.getSeconds()+1)	;
	var	timestring=padlength(serverdate.getHours())+":"+padlength(serverdate.getMinutes())+":"+padlength(serverdate.getSeconds());
	document.getElementById("servertime").innerHTML=timestring;
	
	if(document.getElementById("timeleft")) {
		show_timeleft();
	}
}





function show_timeleft(){
	var timeleft = (processdate - serverdate)/1000;
	var display	 = "";
		
	if (timeleft <=0) {
		display = "<span style=\"color: #F00;font-weight: bold;\">Game processing is due to begin at any moment!<br/>You may be booted out without warning.</span>";
	}
	else {
		var seconds	= timeleft;
		var minutes = seconds / 60;
		var hours	= minutes / 60;
		var days	= hours / 24;
		
		seconds = Math.floor(seconds) % 60;
		minutes = Math.floor(minutes) % 60;
		hours	= Math.floor(hours) % 24;
		days	= Math.floor(days);
		
		if (seconds == 1) {
			display = "1 second";
		} else {
			display = seconds + " seconds";
		}
		if (minutes == 1) {		
			display = "1 minute and " + display;
		}
		else if (days > 0 || hours > 0 || minutes > 0){
			display = minutes + " minutes and " + display;
		}
		if (hours == 1) {		
			display = "1 hour, " + display;
		}
		else if (days > 0 || hours > 0) {
			display = hours + " hours, " +display;
		}
		
		if (days == 1) {		
			display = "1 day, " + display;
		}
		else if (days > 1) {
			display = days + " days, " +display;
		}
		
		display += " until the game is next processed";
		
		//display += serverdate;
		//display += processdate;
	}			
	document.getElementById("timeleft").innerHTML=display;
}



function CheckboxClamp(formname, fieldname, limit) {
    this.state = new Array;
    this.seq    = 1;
    this.limit  = limit;
    this.fname  = formname;
    this.field  = fieldname;

    //alert('limit' + limit);
    this.check = function (n) {
        var f = document.forms[this.fname];
        this.state [n] = (f.elements[this.field][n].checked == true)
                ? this.seq++
                : 0;

        var nr     =  0; // how many have been clicked
        var oldest = -1; // offset of oldest checked
        var i;
        for (i=0; i < this.state.length; ++i) {
            if (this.state[i] > 0) {
                ++nr;
                if (oldest < 0 || this.state[oldest] < this.state[i]) {
                    oldest = i;
                }
            }
        }
        //alert(nr);
        // more than combo limit, uncheck oldest
        if (nr > this.limit) {
            this.state[oldest] = 0;
            f.elements[this.field][oldest].checked = false;
        }
        return true;
    }
}
//-----------------------------------------------------------
// Events
//-----------------------------------------------------------
var event_ticker = null;
var event_scroller = null;

function updateEvents(element_id) {
    var myajax		= ajaxpack.ajaxobj;
	var myfiletype	= ajaxpack.filetype;
	
	if (myajax.readyState == 4){ 			
		if (myajax.status==200 || window.location.href.indexOf("http")==-1) { 			
			if (myfiletype=="txt") {
				//alert(myajax.responseText);
				var response_text = myajax.responseText;
				var my_data = response_text.split('@');
				//alert(response_text);
				var pausecontent2 = new Array();
				for (var i = 0; i < my_data.length-1; i++ )
				{			
				    var pre = my_data[i].split('#')[0];	    
				    var post = my_data[i].split('#')[1];
                    pausecontent2[i]='<a href="javascript:void(0);" style="color: #000; text-decoration: none;" title="' + pre + '">'+  post + '</a>';				    
				}				
				event_scroller.update(pausecontent2);               
			}			
		}
		startEventUpdates(10000);
	}    	
}

function ajaxUpdateEvents()
{		
	ajaxpack.getAjaxRequest("/ajax/get_events.asp", "", updateEvents, "txt")		
}

function startEventUpdates(delay)
{    
    event_ticker = setTimeout( ajaxUpdateEvents, delay);
}

function stopEventUpdates()
{
    clearTimeout(event_ticker)
}

//addLoadEvent( function(){startEventUpdates(10000);} );

//-----------------------------------------------------------
// Scroller
//-----------------------------------------------------------
function pausescroller(content, divId, divClass, delay){
    
    this.content=content //message array content
    this.tickerid=divId //ID of ticker div to display information
    this.delay=delay //Delay between msg change, in miliseconds.
    this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
    this.hiddendivpointer=1 //index of message array for hidden div
    document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>')    
    var scrollerinstance=this
    if (window.addEventListener) //run onload in DOM2 browsers
        window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
    else if (window.attachEvent) //run onload in IE5.5+
        window.attachEvent("onload", function(){scrollerinstance.initialize()})
    else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
        setTimeout(function(){scrollerinstance.initialize()}, 500)
}
// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------

pausescroller.prototype.initialize=function(){    
    this.tickerdiv=document.getElementById(this.tickerid)
    this.visiblediv=document.getElementById(this.tickerid+"1")
    this.hiddendiv=document.getElementById(this.tickerid+"2")
    this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv))

    //set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
    this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
    this.getinline(this.visiblediv, this.hiddendiv)
    this.hiddendiv.style.visibility="visible"
    var scrollerinstance=this
    document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
    document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}
    if (window.attachEvent) //Clean up loose references in IE
        window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
    setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}


// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------

pausescroller.prototype.animateup=function(){
    var scrollerinstance=this
    if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+5)){
        this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-5+"px";
        this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-5+"px";
        setTimeout(function(){scrollerinstance.animateup()}, 50);
    } else {
        this.getinline(this.hiddendiv, this.visiblediv);
        this.swapdivs();
        setTimeout(function(){scrollerinstance.setmessage()}, this.delay);
    }
}

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

pausescroller.prototype.swapdivs=function(){
    var tempcontainer=this.visiblediv;
    this.visiblediv=this.hiddendiv;
    this.hiddendiv=tempcontainer;
}

pausescroller.prototype.getinline=function(div1, div2){
    div1.style.top=this.visibledivtop+"px";
    div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px";
}

pausescroller.prototype.update=function(content){
    this.content=content //message array content
}

// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

pausescroller.prototype.setmessage=function(){
    var scrollerinstance=this
    if (this.mouseoverBol==1) { //if mouse is currently over scoller, do nothing (pause it)
        setTimeout(function(){scrollerinstance.setmessage()}, 100);
    } else {
        var i=this.hiddendivpointer;
        var ceiling=this.content.length;
        this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1;
        this.hiddendiv.innerHTML=this.content[this.hiddendivpointer];
        this.animateup();
    }
}

pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
    if (tickerobj.currentStyle)
        return tickerobj.currentStyle["paddingTop"]
    else if (window.getComputedStyle) //if DOM2
        return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
    else
        return 0
}



/*------------------------------------------
   COMMON
------------------------------------------*/
function popup_squad() {			
	var address='/squad.asp';
   	var name='popup_squad';
   	var features='menubar=no,status=no,titlebar=no,left=0,top=0,width=710,height=450,scrollbars=yes';
	window.open(address,name,features);			
}

function popup_help2() {			
	var address='/help/index.asp';
   	var name='popup_help';
   	var features='menubar=no,status=no,titlebar=no,left=0,top=0,width=600,height=500,scrollbars=yes,resizable=yes';
	window.open(address,name,features);			
}
	
function openWindow(url) {
  popupWin = window.open(url, 'new_page', 'width=400,height=400');
}

//-->