﻿// JScript File



function changeSheets(){
        if(document.styleSheets[0].disabled==true)
        {
            document.styleSheets[0].disabled=false;
            document.styleSheets[1].disabled=true;
            SetCookie('background', 'black', 100);
        }
        else
        {
            document.styleSheets[0].disabled=true;
            document.styleSheets[1].disabled=false;        
            SetCookie('background', 'white', 100);            
        }
      } 
    function expandAll(source)
    {
		for(i = 0; i < 50; i++)
		{
			if(document.getElementById(source + i) != null)
			{
				document.getElementById(source  + i).style.display = 'block';
			}
		}    
    }
    function collapseAll(source)
    {
		for(i = 0; i < 50; i++)
		{
			if(document.getElementById(source + i) != null)
			{
				document.getElementById(source  + i).style.display = 'none';
			}
		}    
    }    
    function toggle(item)
    {
        var desc = document.getElementById(item);
        if(desc.style.display == 'none')
	       document.getElementById(item).style.display = 'block';
        else
            document.getElementById(item).style.display = 'none';	       
    }
    function toggleTree(item)
    {
        var players = document.getElementById(item);
        var plus = document.getElementById('plus'+item);        
        if(players.style.display == 'none')
        {
	       players.style.display = 'block';
	       plus.src = 'images/sm_down.gif';
	       plus.alt = 'Hide ' + item + ' players';
	    }
        else
        {
           players.style.display = 'none';	       
	       plus.src = 'images/sm_up.gif';           
	       plus.alt = 'Show ' + item + ' players';	       
        }
    }    
	function toggleNewsPhoto(num, source)
	{
		for(i = 0; i < 50; i++)
		{
			if(document.getElementById('newsphoto' + source + i) != null)
			{
				document.getElementById('newsphoto' + source  + i).style.display = 'none';
				document.getElementById('newstext' + source  + i).style.display = 'none';							
				document.getElementById('photobut' + source  + i).className = 'newsphotobut';	
			}
		}
		document.getElementById('newsphoto' + source + num).style.display = 'block';
		document.getElementById('newstext' + source + num).style.display = 'block';
		document.getElementById('photobut' + source + num).className = 'newsphotobuton';
	}
	
function more(source)
{
    var next = document.getElementById(source + 'more');
    var more = document.getElementById(source + 'moretext');   
    if(next.style.display == 'none')
    {
        next.style.display = 'block';
        more.innerHTML = 'less articles';        
    }
    else
    {
        next.style.display = 'none';
        more.innerHTML = 'more articles';            
    }
}	
function popitup(url, height, width, name)
{
    x = (640 - width)/2, y = (480 - height)/2;

    if (screen) {
        y = (screen.availHeight - height)/2;
        x = (screen.availWidth - width)/2;
    }
    
    newwindow=window.open(url,name,'height=' + height + ',width=' + width + ',screenX=' + x + ',screenY=' + y + ',top='+y+',left='+x + ',menubar=no,location=no,status=no,toolbar=no,resizable=yes,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
	return false;
}
function showHover(source)
{
    document.getElementById(source).className = 'newsitemhover';
}
function hideHover(source)
{
    document.getElementById(source).className = 'newsitem';
}
function SetCookie(cookieName,cookieValue,nDays) 
{
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName + "=" + cookieValue + ";expires=" + expire.toGMTString();
}

function GetCookie(cookieName) 
{
 var theCookie = "" + document.cookie;
 var ind = theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return ""; 
 var ind1 = theCookie.indexOf(';',ind);
 if (ind1==-1) ind1 = theCookie.length; 
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}
if(GetCookie('background') != null && GetCookie('background') == 'white')
{
            document.styleSheets[0].disabled=true;
            document.styleSheets[1].disabled=false;
}
     



    function hide(name)
    {            
        var lastname=GetCookie('lastName');
        if(document.getElementById('name' + name) != null && document.getElementById('name' + name).className == 'selectedEntity')
        {
            document.getElementById('name' + name).className = 'bar';
            document.getElementById('name' + name).style.backgroundImage = "url('images/bar.gif')";
	    	hide(' ','');
        
        }
        else
        {
		    for(i = 0; i < 400; i++)
		    {
    		
			    if(document.getElementById(i) != null && document.getElementById(i).innerHTML.toLowerCase().indexOf(name.toLowerCase()) < 0)
			    {
			        if(document.getElementById(i).innerHTML.indexOf('blank.gif') > -1)
			        {
                        Spry.Effect.AppearFade(document.getElementById(i), {duration:1500,from:100,to:40,toggle:false});	        
			        }
			        else
			        {
			            Spry.Effect.AppearFade(document.getElementById(i), {duration:1500,from:100,to:40,toggle:false});	        
				    }
			    }
			    else if (document.getElementById(i) != null)
			    {
			        if(document.getElementById(i).innerHTML.indexOf('blank.gif') > -1)
			        {
                        Spry.Effect.AppearFade(document.getElementById(i), {duration:1500,from:100,to:100,toggle:false});			        
			        }
			        else
			        {
                        Spry.Effect.AppearFade(document.getElementById(i), {duration:1500,from:100,to:100,toggle:false});			        
				    }
			    }
		    }    

            if(document.getElementById('name' + lastname) != null)
            {
                document.getElementById('name' + lastname).className = 'bar';
                document.getElementById('name' + lastname).style.backgroundImage = "url('images/bar.gif')";
            }
            var entity = document.getElementById('hiddenEntity').value;
            if(document.getElementById('name' + name) != null)
            {
                document.getElementById('name' + name).className = 'selectedEntity';
                //alert(document.getElementById('name' + name).style.background);
                document.getElementById('name' + name).style.backgroundImage = "url('images/bar2.gif')";
                SetCookie('lastName' ,name,1);
            }

		}
    }
    
   


    function find (name)
    {
        //document.getElementById('txtSearch').value = '"' + name + '"';
        SetCookie('filter',name,1); 
        Form1.submit();
    }
    
var Timer = null;



function ShowDropDowns() {
 if (ComponentArt_Snap_Page_Loaded == true) {
   var DropDowns = document.getElementsByTagName("select");
   for (i = 0; i < DropDowns.length; i++) {
     if (DropDowns[i].style.visibility == "hidden") DropDowns[i].style.visibility = "visible";
   }
   window.clearTimeout(Timer);
 }
}
function StartTimer() { Timer = window.setInterval("ShowDropDowns();",50); }
    
 function resetCookie()
        {
            var loc = window.location.href;
            if(loc.indexOf('s=') == -1 && loc.indexOf('q=') == -1 && loc.indexOf('teamid=') == -1 && loc.indexOf('playerid=') == -1)
            {
                SetCookie('moreInfo','',1);                                              
                //SetCookie('lastEntity','Premiership Football',1);                                      
            }
            //alert(GetCookie('moreInfo'));
        }
        

            var baseAddr = null;

            if( document.getElementsByTagName ) 
            {
                var elems = document.getElementsByTagName( 'base' );
                if( elems.length ) 
                {
                   // baseAddr = elems[ 0 ].href + 'info/';
                    baseAddr = elems[ 0 ].href;
                }
            }
                    
 
        //reset last related info cookie if related not being requested
        var loc = window.location.href;            
        if(loc.indexOf('q=') == -1)
        {
            SetCookie('moreInfo', '', 1);               
        }
        //set search string if s is set
        function setSearch()
        {
            if(loc.indexOf('s=') > -1 && loc.indexOf('id=') == -1)
            {
                document.getElementById('search').value = gup('s');
            }
        }        
        
        function more (name)
        {
            var cVal = GetCookie('moreInfo');
            var q = name;
            if(cVal != "" && cVal != ";")
                var q = cVal + ' AND ' + name;        
        
            var t = document.Form1.lstTeams.selectedIndex;
            var team_text = document.Form1.lstTeams.options[t].text;
            var team_value = document.Form1.lstTeams.options[t].value;            

            if(document.Form1.lstPlayers != null)
            {
                var p = document.Form1.lstPlayers.selectedIndex;
                var player_text = document.Form1.lstPlayers.options[p].text;
                var player_value = document.Form1.lstPlayers.options[p].value;            
            }

            SetCookie('moreInfo', q, 1);       

            var loc = window.location.href;            
            if(loc.indexOf('s=') > -1)
            {
                if(loc.indexOf('id=') > -1)
                    window.location.href = 'info.aspx?id=' + gup('id') + '&s=' + gup('s') + '&q=' + q;
                else
                    window.location.href = 'info.aspx?s=' + gup('s') + '&q=' + q;                
            }
            else if(player_value != null && player_value != 'All')
            {
                window.location.href = 'info.aspx?playerid=' + player_value + '&playername=' + player_text + '&q=' + q;                
            }
            else if(team_value != 'All')
            {
                window.location.href = 'info.aspx?teamid=' + team_value + '&teamname=' + team_text + '&q=' + q;                
            }
            else
            {
                window.location.href = 'info.aspx?q=' + q; 
            }            
            showBox();
            document.getElementById('finding').innerHTML = name;     
        }    
        
        function moreOnly(name)
        {
            //window.location.href = 'info.aspx?s=' + name
            showBox();
            document.getElementById('finding').innerHTML = name;  
        }
        
        function load(page)
        {
            var queryString =  window.location.search.substring(1);
            if(page == "news")
                window.location.href = 'info.aspx?' + queryString;
            else if(page == "blogs")
                window.location.href = 'blogs.aspx?' + queryString;                
            else if(page == "video")
                window.location.href = 'video.aspx?' + queryString;          
            else if(page == "feeds")
                window.location.href = 'feeds.aspx';                                        
        }
        
        function gup( name )
        {
          var regexS = "[\\?&]"+name+"=([^&#]*)";
          var regex = new RegExp( regexS );
          var tmpURL = window.location.href;
          var results = regex.exec( tmpURL );
          if( results == null )
            return "";
          else
            return results[1];
        }             
        
        /****************************************\
* Show Overlay and box
\****************************************/
function showBox(){
    if(navigator.userAgent.indexOf('IE 6') != -1) 
    {
       var DropDowns = document.getElementsByTagName("select");
       for (i = 0; i < DropDowns.length; i++) 
       {
            DropDowns[i].style.visibility = "hidden";
       }
    }

    document.getElementById('overlay').style.display = '';
     //       alert('test');
    overlayReload();

    center('box', '250', '100');// Size of the box
    setTimeout('document.getElementById("ajaximg").src = "images/ajax-loader.gif"', 200);         
    return false;
}
/****************************************\
* Adjust overlay to new window size
\****************************************/
function overlayReload()
{
    if (window.innerHeight && window.scrollMaxY || window.innerWidth && window.scrollMaxX) {    
        yScroll = window.innerHeight + window.scrollMaxY;
        xScroll = window.innerWidth + window.scrollMaxX;
        var deff = document.documentElement;
        var wff = (deff&&deff.clientWidth) || document.body.clientWidth || window.innerWidth || self.innerWidth;
        var hff = (deff&&deff.clientHeight) || document.body.clientHeight || window.innerHeight || self.innerHeight;
        xScroll -= (window.innerWidth - wff);
        yScroll -= (window.innerHeight - hff);
    } else if (document.body.scrollHeight > document.body.offsetHeight || document.body.scrollWidth > document.body.offsetWidth){ // all but Explorer Mac
        yScroll = document.body.scrollHeight;
        xScroll = document.body.scrollWidth;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        yScroll = document.body.offsetHeight;
        xScroll = document.body.offsetWidth;
      }

    $('overlay').style.height = yScroll;
    $('overlay').style.width = xScroll;
}
/****************************************\
* Actually center box
\****************************************/
function center(window_name, _width, _height) {
    var successWin = $(window_name);
    var pagesize = getPageSize();    
    var arrayPageScroll = getPageScrollTop();
    successWin.style.left = (arrayPageScroll[0] + (pagesize[0] - _width)/2) + "px";
    successWin.style.top = (arrayPageScroll[1] + (pagesize[1] - _height)/2) + "px";
    successWin.style.position = 'absolute';     
    successWin.style.zIndex = 99; 
    successWin.style.display = 'block';
}
/****************************************\
*
\****************************************/
function getPageSize(){
    var de = document.documentElement;
    var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
    var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight
    arrayPageSize = new Array(w,h) 
    return arrayPageSize;
}
/****************************************\
*
\****************************************/
function getPageScrollTop(){
    var yScrolltop;
    var xScrollleft;
    if (self.pageYOffset || self.pageXOffset) {
        yScrolltop = self.pageYOffset;
        xScrollleft = self.pageXOffset;
    } else if (document.documentElement && document.documentElement.scrollTop || document.documentElement.scrollLeft ){     // Explorer 6 Strict
        yScrolltop = document.documentElement.scrollTop;
        xScrollleft = document.documentElement.scrollLeft;
    } else if (document.body) {// all other Explorers
        yScrolltop = document.body.scrollTop;
        xScrollleft = document.body.scrollLeft;
    }
    arrayPageScroll = new Array(xScrollleft,yScrolltop) 
    return arrayPageScroll;
}

    function checkEnter(e)
    { //e is event object passed from function invocation
        var character //Code literal character code will be stored in this variable
        if(e && e.which)
        { //if which property of event object is supported (NN4)
            e = e
            characterCode = e.which //character code is contained in NN4's which property
        }
        else
        {
            e = event
            characterCode = e.keyCode //character code is contained in IE's keyCode property
        }

        if(characterCode == 13)
        { //if character code is equal to ascii 13 (if enter key)
            search();
            return false; //return false to the event handler
        }
        else
        {
            return true //return true to the event handler
        } 
    }  
        function search()
        {
            if(document.getElementById('search').value != '')
            {
                window.location.href = 'http://interceder.net/news/' + replaceAll(document.getElementById('search').value.replace(/^\s+|\s+$/g, ''), " ", "-");
                //window.location.href = baseAddr + document.getElementById('search').value;    
                document.getElementById('search').blur();
                showBox();
                //document.getElementById('finding').innerHTML = document.getElementById('search').value;       
                setInnerHTML( document.getElementById('finding'), URLDecode(document.getElementById('search').value), 1 )          
            }
        }         
        
        function goLink(entity)
        {
                //document.getElementById('search').value = URLDecode(entity);
                //document.getElementById('search').blur();
                window.location.href = 'http://interceder.net/news/' + replaceAll(entity, " ", "-");
                //showBox();
                //setInnerHTML( document.getElementById('finding'), URLDecode(entity), 1 )       
            
        }             
        
function replaceAll(text, strA, strB) 
{
    while ( text.indexOf(strA) != -1)
    {
        text = text.replace(strA,strB);
    }
    return text;
}
        
function URLDecode(url) //function decode URL
{
// Replace + with ' '
// Replace %xx with equivalent character
// Put [ERROR] in output if %xx is invalid.
var HEXCHARS = "0123456789ABCDEFabcdef"; 
var encoded = url;
var plaintext = "";
var i = 0;
while (i < encoded.length) {
var ch = encoded.charAt(i);
if (ch == "+") {
plaintext += " ";
i++;
} else if (ch == "%") {
if (i < (encoded.length-2) 
&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
plaintext += unescape( encoded.substr(i,3) );
i += 3;
} else {
alert( 'Bad escape combination near ...' + encoded.substr(i) );
plaintext += "%[ERROR]";
i++;
}
} else {
plaintext += ch;
i++;
}
} // while 

return plaintext;
}; 

function loopCalais ()
{
    for(i = 0; i < 50; i++)
	{
		//try
		//{
		    if(document.getElementById('name' + i) != null)
		    {
		        showimage(document.getElementById('name' + i).innerHTML);
		    }
		//} 
		//catch(e) {}
	}	
}        

 function setInnerHTML( element, html, count ) {     element.innerHTML = html;     if( ! count )         count = 1;     if( html != '' && element.innerHTML == '' && count < 5 ) {         ++count;         setTimeout( function() {             setInnerHTML( element, html, count );         }, 50 );     } }

 function installOpenSearch() { if ((typeof window.external == "object") && ((typeof window.external.AddSearchProvider == "unknown") || (typeof window.external.AddSearchProvider == "function"))) { window.external.AddSearchProvider("http://interceder.net/opensearch.xml"); } else { alert("This plugin requires a browser that supports OpenSearch."); } }