/*Revision 1.0.1 */
(function () {

	// Save reference to earlier defined object implementation (if any)
	var oXMLHttpRequest	= window.XMLHttpRequest;

	// Constructor
	function cXMLHttpRequest() {
		this.object	= oXMLHttpRequest ? new oXMLHttpRequest : new window.ActiveXObject('Microsoft.XMLHTTP');
	}

	// BUGFIX: Firefox with Firebug installed would break pages if not executed
	if (oXMLHttpRequest && oXMLHttpRequest.wrapped)
		cXMLHttpRequest.wrapped	= oXMLHttpRequest.wrapped;

	// Constants
	cXMLHttpRequest.UNSENT	= 0;
	cXMLHttpRequest.OPEN	= 1;
	cXMLHttpRequest.SENT	= 2;
	cXMLHttpRequest.LOADING	= 3;
	cXMLHttpRequest.DONE	= 4;

	// Public Properties
	cXMLHttpRequest.prototype.readyState	= cXMLHttpRequest.UNSENT;
	cXMLHttpRequest.prototype.responseText	= "";
	cXMLHttpRequest.prototype.responseXML	= null;
	cXMLHttpRequest.prototype.status		= 0;
	cXMLHttpRequest.prototype.statusText	= "";

	// Instance-level Events Handlers
	cXMLHttpRequest.prototype.onreadystatechange	= null;

	// Class-level Events Handlers
	cXMLHttpRequest.onreadystatechange	= null;
	cXMLHttpRequest.onopen				= null;
	cXMLHttpRequest.onsend				= null;
	cXMLHttpRequest.onabort				= null;

	// Public Methods
	cXMLHttpRequest.prototype.open	= function(sMethod, sUrl, bAsync, sUser, sPassword) {

		// Save async parameter for fixing Gecko bug with missing readystatechange in synchronous requests
		this._async		= bAsync;

		// Set the onreadystatechange handler
		var self	= this,
			nState	= this.readyState;

		this.object.onreadystatechange	= function() {
			// Synchronize states
			fSynchronizeStates(self);

			// BUGFIX: Firefox fires unneccesary DONE when aborting
			if (self._aborted) {
				// Reset readyState to UNSENT
				self.readyState	= self.constructor.UNSENT;

				// Return now
				return;
			}

			if (self.readyState == self.constructor.DONE) {
				//
				fCleanTransport(self);

				// BUGFIX: IE - cache issue
				if (!self.object.getResponseHeader("Date")) {
					// Save object to cache
					self._cached	= self.object;

					// Instantiate a new transport object
					self.constructor.call(self);

					// Re-send request
					self.object.open(sMethod, sUrl, bAsync, sUser, sPassword);
					self.object.setRequestHeader("If-Modified-Since", self._cached.getResponseHeader("Last-Modified") || new Date(0));
					// Copy headers set
					if (self._headers)
						for (var sHeader in self._headers)
							if (typeof self._headers[sHeader] == "string")	// Some frameworks prototype objects with functions
								self.object.setRequestHeader(sHeader, self._headers[sHeader]);
					self.object.onreadystatechange	= function() {
						// Synchronize states
						fSynchronizeStates(self);

						if (self.readyState == self.constructor.DONE) {
							if (self._aborted) {
								self.readyState	= self.constructor.UNSENT;

								self.responseText	= "";
								self.responseXML	= null;

								// Return
								return;
							}
							else {
								//
								if (self.status == 304) {
									// request = cached
									self.responseText	= self._cached.responseText;
									self.responseXML	= self._cached.responseXML;
								}

								// BUGFIX: IE - Empty documents in invalid XML responses
								if (self.responseXML)
									if (self.responseXML.parseError != 0)
										self.responseXML	= null;

								//
								fReadyStateChange(self);
							}

							// Clean Object
							fCleanTransport(self);
						}
					};
					self.object.send(null);

					// Return now - wait untill re-sent request is finished
					return;
				}

				// BUGFIX: Gecko - Annoying <parsererror /> in invalid XML responses
				// BUGFIX: IE - Empty documents in invalid XML responses
				if (self.responseXML)
					if (("parseError" in self.responseXML && self.responseXML.parseError != 0) || (self.responseXML.documentElement && self.responseXML.documentElement.tagName == "parsererror"))
						self.responseXML	= null;
			}

			// BUGFIX: Gecko - missing readystatechange calls in synchronous requests (this is executed when firebug is enabled)
			if (!self._async && self.constructor.wrapped) {
				self.readyState	= self.constructor.OPEN;
				while (++self.readyState < self.constructor.DONE)
					fReadyStateChange(self);
			}

			// BUGFIX: Some browsers (Internet Explorer, Gecko) fire OPEN readystate twice
			if (nState != self.readyState)
				fReadyStateChange(self);

			nState	= self.readyState;
		}

		// Add method sniffer
		if (this.constructor.onopen)
			this.constructor.onopen.apply(this, arguments);

		this.object.open(sMethod, sUrl, bAsync, sUser, sPassword);

		// BUGFIX: Gecko - missing readystatechange calls in synchronous requests
		if (!bAsync && window.navigator.userAgent.match(/Gecko\//)) {
			this.readyState	= this.constructor.OPEN;

			fReadyStateChange(this);
		}
	};
	cXMLHttpRequest.prototype.send	= function(vData) {
		// Add method sniffer
		if (this.constructor.onsend)
			this.constructor.onsend.apply(this, arguments);

		this.object.send(vData);

		// BUGFIX: Gecko - missing readystatechange events
		if (!this._async && !this.constructor.wrapped)
			while (this.readyState++ < this.constructor.DONE)
				fReadyStateChange(this);
	};
	cXMLHttpRequest.prototype.abort	= function() {
		// Add method sniffer
		if (this.constructor.onabort)
			this.constructor.onabort.apply(this, arguments);

		// BUGFIX: Gecko - unneccesary DONE when aborting
		if (this.readyState > this.constructor.UNSENT)
			this._aborted	= true;

		this.object.abort();
	};
	cXMLHttpRequest.prototype.getAllResponseHeaders	= function() {
		return this.object.getAllResponseHeaders();
	};
	cXMLHttpRequest.prototype.getResponseHeader	= function(sName) {
		return this.object.getResponseHeader(sName);
	};
	cXMLHttpRequest.prototype.setRequestHeader	= function(sName, sValue) {
		// BUGFIX: IE - cache issue
		if (!this._headers)
			this._headers	= {};
		this._headers[sName]	= sValue;

		return this.object.setRequestHeader(sName, sValue);
	};
	cXMLHttpRequest.prototype.toString	= function() {
		return "[object XMLHttpRequest]";
	};
	cXMLHttpRequest.toString	= function() {
		return "[XMLHttpRequest]";
	};

	// Helper function
	function fReadyStateChange(self) {
		// Execute onreadystatechange
		if (self.onreadystatechange)
			self.onreadystatechange.apply(self);

		// Sniffing code
		if (self.constructor.onreadystatechange)
			self.constructor.onreadystatechange.apply(self);
	}

	function fSynchronizeStates(self) {
				self.readyState		= self.object.readyState;
		try {	self.responseText	= self.object.responseText;	} catch (e) {}
		try {	self.responseXML	= self.object.responseXML;	} catch (e) {}
		try {	self.status			= self.object.status;		} catch (e) {}
		try {	self.statusText		= self.object.statusText;	} catch (e) {}
	}

	function fCleanTransport(self) {
		// BUGFIX: IE - memory leak
		self.object.onreadystatechange	= new Function;

		// Delete private properties
		delete self._cached;
		delete self._headers;
	}

	// Internet Explorer 5.0 (missing apply)
	if (!Function.prototype.apply) {
		Function.prototype.apply	= function(self, oArguments) {
			if (!oArguments)
				oArguments	= [];
			self.__func	= this;
			self.__func(oArguments[0], oArguments[1], oArguments[2], oArguments[3], oArguments[4]);
			delete self.__func;
		};
	}

	// Register new object with window
	window.XMLHttpRequest	= cXMLHttpRequest;
	
	function fAsynchronousGet(tagID, thisURL) { 
	var oXMLHttpRequest = new XMLHttpRequest;
	oXMLHttpRequest.open("GET", thisURL, true); 
	oXMLHttpRequest.onreadystatechange = function() { 
		if (this.readyState == XMLHttpRequest.DONE) { 
		p_o(tagID).innerHTML = this.responseText;
		}
	}
	oXMLHttpRequest.send(tagID);
}
})();



p_o = function(input){
	return document.getElementById(input);
}

function fAsynchronousGet(tagID, thisURL) { 
	var oXMLHttpRequest = new XMLHttpRequest;
	oXMLHttpRequest.open("GET", thisURL, true); 
	oXMLHttpRequest.onreadystatechange = function() { 
		if (this.readyState == XMLHttpRequest.DONE) { 
		p_o(tagID).innerHTML = this.responseText;
		}
	}
	oXMLHttpRequest.send(tagID);
}

var F;
var browser=navigator.appName;
var ie ='Microsoft Internet Explorer';


var LoadCalendar = function(){
$('#month0,#month1,#month3,#month4,#month5').datePicker({
    createButton:false,
    showYearNavigation:false,
    verticalOffset:"25px",
    horizontalOffset:"0px",
    showHeader:false,
    setDisplayedMonth:false,
    startDate:'01/01/2007',
    displayClose: true
})
.css('cursor','pointer')
.bind('mouseover', function(){
        $(this).addClass('divToggle')
})
.bind('mouseout', function(){
        $(this).removeClass('divToggle')
})
.bind('click', function()
                {
                            //debugger;
                            //$(this).dpSetDisplayedMonth($(this).attr("value"), myYear($(this).attr("value")));
                            var month = 1;
                            var year = 2008;

                            if(document.getElementById("filterDate")){
                                    var monthStr = document.getElementById("filterDate").value.split('/')[0];
                                    if(monthStr.substring(0,1) == '0')
                                            monthStr=monthStr.substring(1,2);
                                    var yearStr = document.getElementById("filterDate").value.split('/')[2];
                                    month = parseInt(monthStr);
                                    year = parseInt(yearStr); 

                            }
                            month-=1;
                            $(this).dpSetDisplayedMonth(month, year);
                            $(this).dpDisplay();
                            $("a.dp-nav-next-month")[0].innerHTML = "Next&nbsp;&gt;";
                            $("a.dp-nav-prev-month")[0].innerHTML = "&lt;&nbsp;Prev";
                            this.blur();
                            return false;
                    }
    ).bind('dateSelected',
            function(e, selectedDate, $td)
                    {
                            var slctDate = selectedDate;
                            Date.format = "mm/dd/yyyy";
                            slctDate = slctDate.asString();
                            if(document.getElementById("filterDate"))
                                    document.getElementById("filterDate").value = slctDate;
                            //var tabHref = "/"+_trailURL+"/";
                            //location.href = tabHref + slctDate + "?conference="+_selConfAltered;
                            if(typeof(callingFN)!="undefined")
                                    callingFN();
                            return(false);
                    }
    ).bind('blur',function(){$(this).dpClose();return(false);});
    }
    
/****
    Variables/Arrays used to populate
    the position and stat drop down menus 
*/
var posStatus = new Boolean();
var pitcherOption = new Array(
   {txt:"Select", val:"", a:true, b:false}, 
   {txt:"G", val:"G", a:false, b:false},
   {txt:"GS", val:"GS", a:false, b:false},
   {txt:"W", val:"W", a:false, b:false},
   {txt:"L", val:"L", a:false, b:false},
   {txt:"SV", val:"SV", a:false, b:false},
   {txt:"CG", val:"CG", a:false, b:false},
   {txt:"SHO", val:"SHO", a:false, b:false},
   {txt:"IP", val:"IP", a:false, b:false},
   {txt:"H", val:"H", a:false, b:false},
   {txt:"ER", val:"ER", a:false, b:false},
   {txt:"HR", val:"HR", a:false, b:false},
   {txt:"BB", val:"BB", a:false, b:false},
   {txt:"K", val:"K", a:false, b:false},
   {txt:"ERA", val:"ERA", a:false, b:false},
   {txt:"WHIP", val:"WHIP", a:false, b:false},
   {txt:"BAA", val:"BAA", a:false, b:false});
var standardOption = new Array (
    {txt:"Select", val:"", a:true, b:false},
    {txt:"G", val:"G", a:false, b:false},
    {txt:"AB", val:"AB", a:false, b:false},
    {txt:"R", val:"R", a:false, b:false},
    {txt:"H", val:"H", a:false, b:false},
    {txt:"2B", val:"2B", a:false, b:false},
    {txt:"3B", val:"3B", a:false, b:false},
    {txt:"HR", val:"HR", a:false, b:false},
    {txt:"RBI", val:"RBI", a:false, b:false},
    {txt:"BB", val:"BB", a:false, b:false},
    {txt:"K", val:"K", a:false, b:false},
    {txt:"SB", val:"SB", a:false, b:false},
    {txt:"CS", val:"CS", a:false, b:false},
    {txt:"AVG", val:"AVG", a:false, b:false},
    {txt:"OBP", val:"OBP", a:false, b:false},
    {txt:"SLG", val:"SLG", a:false, b:false},
    {txt:"OPS", val:"OPS", a:false, b:false});

var loadPosStats = function (position) {  
var opt = document.mlbStatsFltr; 
	if (position == "Pitcher") {
        for (var i=0; i<pitcherOption.length; i++){
             opt.category[i]=new Option(pitcherOption[i].txt, pitcherOption[i].val, pitcherOption[i].a, pitcherOption[i].b);
         }
         posStatus = false;
	} else {
                if (posStatus == false){
                       for (var i=0; i<standardOption.length; i++){
                        opt.category[i]=new Option(standardOption[i].txt, standardOption[i].val, standardOption[i].a, standardOption[i].b);
                       }
                       posStatus = true;
                }else{
              return false;
          };
         }
}

/**
 * Check expanded state of the search options - mlbPlayerSearchResults.
 * @return {Boolean} isExp
 */
var checkExpanded = function(){
                var isExp = false;
                if($(".expand").length > 0){
                        if($(".expand")[0].style.display == "inline" || $(".expand")[0].style.display == "block"){
                                isExp = true;					
                        }else{
                                isExp = false;										
                        }
                }
                return isExp;
};

/** 
 * Collapse or expand search options based on expanded state via checkExpaned()
 * go through elem[].  If any elem does not have a classname of "visible" then 
 * toggle the elem to a hidden state.
 * Also toggle the expand an collapse links to the opposite of whatever the are. 
 * @param {Array} elem
 * @see checkExpaned()
 */
var searchCollapseExpand = function(elem){
        var isExpanded = checkExpanded();
        $.each(elem, function(i, n){
                if((n).className.indexOf("visible") == -1)
                {
                        $(n).toggle();
                }
        });
        $(".expand").toggle();
        $(".collapse").toggle();
};

var mlbTeamName = "";
function getMlbTeamName(){ 
   if($("#team, #teams").val()){
      mlbTeamName = $("#team, #teams").val(); 
   } else if($(".persInfo .persInfo1 a").length > 0){
      mlbTeamName = $(".persInfo .persInfo1 a")[0].href.substring($(".persInfo .persInfo1 a")[0].href.lastIndexOf("/")+1);
   }
   return mlbTeamName;
}

/* onload functions */
$(window).load(function() {
    mlbTeamName = getMlbTeamName();
    if(mlbTeamName != ""){
       $("#mlbTeamName").html(mlbTeamName.replace(/[_-]/g,' '));
       document.mlbTeamName = mlbTeamName;
    }
    var aList = $("a[@href^=/KOL/KOL]");
    if(aList.length > 0){
        for(ai = 0; ai < aList.length; ai++){
            aHref = aList[ai].href;
            aList[ai].href = aHref.replace(/\/KOL\/KOL/,'/KOL');
        }
    }
/*Actions for standings toggle*/
$(".fltrOptns #bscFltr").addClass("selected");
$('#bscFltr').bind("click", function(){
    if (browser == ie){
        $('table').find('.statPrim').css('display', 'block');
    }else{
        $('table').find('.statPrim').css('display', 'table-cell');
    }
    $('table').find('.statSec').css('display', 'none');
    $('table').find('.statTert').css('display', 'none');
    $(".fltrOptns a").removeClass("selected");
    $(".fltrOptns #bscFltr").addClass("selected");

});

$('#expdFltr').bind("click", function(){
    $('table').find('.statPrim').css('display', 'none');
    if (browser == ie){
        $('table').find('.statSec').css('display', 'block');
    }else{
        $('table').find('.statSec').css('display', 'table-cell');
    }
    $('table').find('.statTert').css('display', 'none');
    $(".fltrOptns a").removeClass("selected");
    $(".fltrOptns #expdFltr").addClass("selected");
});

$('#vsDvsion').bind("click", function(){
    $('table').find('.statPrim').css('display', 'none');
    $('table').find('.statSec').css('display', 'none');
    if (browser == ie){
        $('table').find('.statTert').css('display', 'block');
    }else{
       $('table').find('.statTert').css('display', 'table-cell');
    }
    $(".fltrOptns a").removeClass("selected");
    $(".fltrOptns #vsDvsion").addClass("selected");
});
/* MLB Team Roster events */
$(".mlbRosterFltr #teams").bind("change", function() {
    F=this.form;if(F.teams.value != ''){F.action=F.action+'/'+ F.teams.value ;F.submit();}
});
/* MLB Team Stats events */
$(".mlbTeamStatsFltr #teams").bind("change", function() {
    F=this.form;if(F.teams.value != ''){F.action=F.action+'/'+ F.teams.value ;F.submit();}
});
/* MLB Schedule events */
$(".mlbTeamSchedFltr #month, .mlbTeamSchedFltr #team").bind("change", function() {
    F=this.form;if(F.team.value != ''){F.action=F.action+'/'+ F.team.value ;F.submit();}
});
$(".mlbTeamSchedFltr #calView").bind("click", function() {
var F = document.getElementById('monthSched');if(F.team.value != ''){ F.view.value='cal'; F.action=F.action+'/'+ F.team.value ;F.submit();}
});
$(".mlbTeamSchedFltr #lstView").bind("click", function() {
var F = document.getElementById('monthSched');if(F.team.value != ''){F.view.value='list'; F.action=F.action+'/'+ F.team.value;F.submit();}
});
/* MLB Team Scores events */
$(".mlbTeamScoresFltr #month, .mlbTeamScoresFltr #team").bind("change", function() {
    F=this.form;if(F.team.value != ''){F.action=F.action+'/'+ F.team.value ;F.submit();}
});

/* Prev/Next Form Actions for Calendar Schedule */
$("#prvMonth").bind("click", function() {
var F=document.getElementById('calMonthSched');if($("#monthSched #team").val() != ''){F.month.value=(F.month.value*1)-1; F.action=F.action+'/'+ $("#monthSched #team").val();F.submit();}
});
$("#nxtMonth").bind("click", function() {
var F=document.getElementById('calMonthSched');if($("#monthSched #team").val() != ''){F.month.value=(F.month.value*1)+1; F.action=F.action+'/'+ $("#monthSched #team").val();F.submit();}
});


/* Binds change action to position drop down on MLB stats page*/
$("#position").bind("change", function() {
    F=this.form;loadPosStats(F.position.value);
});

/* Player search text field clears out on focus */
$("#plyrSrch, #playerNameQuery").bind("focus", function () {
(this.value=='Enter Player Name')?this.value='':'';this.style.color='#000';this.style.border='1px solid #7F9DB9';
});

$(".gmtvcov").bind("click", function () {
    var day = "#"+this.id;
    $(day).next(".tvLstng").css('display', 'block');
});
$(".tvLstng").bind("click", function () {
    $(".tvLstng").css('display', 'none');
    });
    
/* View Stats form Search Submision*/
$("#viewStats").bind("click", function(){
        F=this.form;
	var dt=F.season;


        if (F.position.value ==""){
         alert("Please Select a Position From the Filter");
         return false;
        };
        if (F.category.value ==""){
         alert("Please Select a Stat Type From the Filter");
         return false;
        };
         window.location=F.action+"/"+F.season.value+"?position="+F.position.value+'&league='+F.league.value+'&category='+F.category.value;return false;
});

/* Team Stats select actions */
$("#activity").bind("change", function () {
F=this.form;if(F.teams.value != ''){F.action=F.action+'/'+ F.teams.value +'?activity=' + this.value;;F.submit();}
});

/* Validate and submit player search */
$("#srchPlyrs").bind("click", function(){
F=this.form;if(F.playerNameQuery.value =="Enter Player Name" || F.playerNameQuery.value ==""){$("#playerNameQuery").css("border","1px solid #C90202");$("#playerNameQuery").css("color","#C90202");$("#playerNameQuery").val("Enter Player Name");$("#errorEval").text("Please Enter a Name to Search");return false;}else{F.submit();};
});

$("#selectroster").bind("change", function () {
document.location = "/KOL/2/Sports/MLB/player/" + this.value;
});

/* Player Profile Split stats season filter */
$("#selectseason").bind("change", function() {
document.location = document.location.pathname + "?selectedTab=splitStats&season=" + this.value + "#statsNav";
});

/* Events for Scores and Schedules */
$(".mlbScoresSchedFltr #filterDate").bind("keypress", function (e) {

    if (e.which == 13){
    F=this.form;
	var dt=F.filterDate;
	if (isDate(dt.value)==false){
		dt.focus();
		return false;
	};
         if (F.name == 'slctDate'){
             F.action=F.action+"/"+dateFrmtURL;F.submit();return true;

         };
         };
}); 

/* Events for Standings Filter */
$(".mlbStndngsFltr #breakdown").bind("change",function(){
    F=this.form;F.action=F.action+"/"+F.season.value+"?breakdown="+F.breakdown.value;F.submit();return true;
});
$(".mlbStndngsFltr #season").bind("change",function(){
    F=this.form;F.action=F.action+"/"+F.season.value+"?breakdown="+F.breakdown.value;F.submit();return true;
});

    /** look for a collapse-able container on the Player search page */
    if($("form.canCollapse").length)
    {
            $(".expand").toggle();
            searchCollapseExpand($(".mlbPlyrSearch form div"));
    }

    /** bind click to collapse link */
    $(".collapse").bind("click", function(){
            searchCollapseExpand($(".mlbPlyrSearch form div"));
            return false;
    });

    /**  bind click to expand link */
    $(".expand").bind("click", function(){
            searchCollapseExpand($(".mlbPlyrSearch form div"));
            return false;
    });
	
$("#mlbTeamRoster").bind("click", function() {
  if(mlbTeamName != ""){
      window.location="/KOL/2/Sports/MLB/team-roster/"+mlbTeamName;
  }
});
$("#mlbTeamStats").bind("click", function() {
  if(mlbTeamName != ""){
     window.location="/KOL/2/Sports/MLB/team-stats/"+mlbTeamName;
  }
});
$("#mlbTeamSchedule").bind("click", function() {
  if(mlbTeamName != ""){
     window.location="/KOL/2/Sports/MLB/team-schedule/"+mlbTeamName;
  }
});
$("#mlbTeamScores").bind("click", function() {
  if(mlbTeamName != ""){
     window.location="/KOL/2/Sports/MLB/team-scores/"+mlbTeamName;
  }
});
	
    LoadCalendar();
 	if(typeof(refreshBox) != "undefined"){
    	refreshBox();
   }

   // call the tablesorter plugin
    $(".mlbStndngs .sortable").tablesorter({
        headers:{0:{sorter:false},9:{sorter:false},10:{sorter:false}}
    });
   
    $(".mlbTrnsctions .sortable").tablesorter({
        headers:{2:{sorter:false}}
    });
    $(".mlbStats .sortable").tablesorter({
        headers:{0:{sorter:false}, 1:{sorter:false}}
    });
    $(".gameLog .sortable").tablesorter({
        headers:{0:{sorter:false}}
    });
    $(".splitStats .sortable").tablesorter({
        headers:{0:{sorter:false}}
    });
    $(".sitStats .sortable").tablesorter({
        headers:{0:{sorter:false}}
    });
    $(".careerStats .sortable").tablesorter({
        headers:{0:{sorter:false}}
    });
    $(".mlbPlyrSearch .sortable").tablesorter({
      headers:{}
    });
/*    $(".plyrStats .sortable").tablesorter({
      headers:{}
    });*/
    $(".mlbTeamStats .sortable").tablesorter({
      headers:{}
    });
    $(".mlbTeamScores .sortable").tablesorter({headers:{}});
//    $(".mlbRoster .sortable").tablesorter({headers:{}});


});





   // Skin info.
   var animatedSkin = new Array("themecaranim","themebfliesanim","themeflowersanim","themesportsanim","thememusicanim","themedefaultanim","themepilaranim","themeskyanim");
   //Gets the browser specific XmlHttpRequest Object
   function getXmlHttpRequestObject() {
      if (window.XMLHttpRequest) {
         return new XMLHttpRequest(); //Not IE
      } else if(window.ActiveXObject) {
         return new ActiveXObject("Microsoft.XMLHTTP"); //IE
      } else {
         //Display your error message here. 
         //and inform the user they might want to upgrade
         //their browser.
         return null;
      }
   }        

   function changeDisplay(visible, invisible){
      changeVisibility(invisible,false);
      changeVisibility(visible,true);
   }

   function changeVisibility(objId, isVisible){
       var display = "none";
       if(isVisible){
           display = "block";
       }
       getObjectById(objId).style.display = display;
       
   }
   var themeIDs = new Array();
   function addThemeID( id ){
       themeIDs[themeIDs.length] = id;
   }

   function changeStyle(color,id){
      var style = getObjectById("changableStyle");
      if(style){
          style.href="/KOL/css/"+color+".css";
          setCookie('themeColor',color+"~"+id,365,"/");
      }
      var skin = getObjectById("changableSkin");
      if(skin){
         skin.className = "skin_"+id;
         chnageAnimatedSkin(id);
      }
      setCookie('themeColor',color+"`"+id,365,"/");
   }

    function getObjectById(id){
       var obj;
       if(document.getElementById){
          obj = document.getElementById(id);
       } else {
          obj = eval('document.all.'+id);
       }
       return obj;
    }
    
   function getCookie(NameOfCookie){ 
      if (document.cookie.length > 0){ 
         begin = document.cookie.indexOf(NameOfCookie+"=");
         if (begin != -1){ 
            begin += NameOfCookie.length+1;
            end = document.cookie.indexOf(";", begin);
            if (end == -1) end = document.cookie.length;
            return unescape(document.cookie.substring(begin, end)); 
         }
      }
      return null;
   }
   
   
   
   function setCookie(NameOfCookie, value, expiredays, path){ 
      var expireDate = new Date ();
      expireDate.setTime(expireDate.getTime() + (expiredays * 24 * 3600 * 1000));
      document.cookie = NameOfCookie + "=" + escape(value) +
      ((expiredays == null) ? "" : "; expires=" + expireDate.toGMTString()) +
      ((path == null) ? "" : "; path="+path);
   }
   
   
   
   function delCookie (NameOfCookie){ 
      if (getCookie(NameOfCookie)) {
         document.cookie = NameOfCookie + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
      }
   }

   function chnageAnimatedSkin(id){
      var objAni = getObjectById("animation");
      if(objAni){
        var aniFlash = new FlashTag("http://www.aolcdn.com/_media/kol/"+animatedSkin[id - 1]+".swf", "980", "74", "9,0,0,0" );
        aniFlash.setId("animation");
        aniFlash.setAlign("l");
        aniFlash.setQuality("high");
        aniFlash.setWmode("transparent");
        aniFlash.setPlay("true");
        aniFlash.setLoop("false");
        aniFlash.setScale("showall");
        aniFlash.setMenu("true");
        aniFlash.setBgcolor("#ffffff");

        var objStr = aniFlash.toString();
       objAni.innerHTML = objStr;
      }
   }

kolsearch = {
    init:function(){},
    searchTypes:{kol:{action:'/KOL/2/SubPages/Search',target:'_self'},web:{action:'http://search.kids.kol.com/search/search?invocationType=enus-kids-1_-kol-web',target:'_new'}},
    postions:{top:'top',bottom:'bottom'},
    select:function(type, position){
        var id = "";
        for(searchType in this.searchTypes){
           id = "select_"+searchType+"_"+position;
           var liObj = this.getObjectByID(id);
           if(liObj){
               if(searchType == type){
                   liObj.className = "selected";
               } else {
                   liObj.className = "";
               }
           }
        }
        id = position+'Search';
        var formObj = this.getObjectByID(id);
        if(formObj){
            formObj.action = this.searchTypes[type].action;
            formObj.target = this.searchTypes[type].target;
        }
    },
    getObjectByID:function(id){
      var obj;
       if(document.getElementById){
          obj = document.getElementById(id);
       } else {
          obj = eval('document.all.'+id);
       }
       return obj;
     }
}

