var OldBrowser="no";
if (navigator.appVersion.indexOf("MSIE 4") != -1) {
	OldBrowser="yes";
} else if (navigator.appVersion.indexOf("Mac") !=-1) {
	if(navigator.userAgent.indexOf("MSIE")!=-1) {
		OldBrowser="yes";
	}
}
function _gel(elid) {
	el=document.getElementById(elid);
	return el;
}
/*original script by Don Perkins       */
/*Do not use without written permission*/
/*set daymonth arrays*/
var DDNames = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var DMNames = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var NDays = new Array("31","28","31","30","31","30","31","31","30","31","30","31");
var IsEvPage =document.location.href.indexOf("events/index")!=-1;
if(document.location.href=="http://www.gaucholocos.com/index.html"||document.location.href=="http://www.gaucholocos.com/index2.html"||document.location.href=="http://www.gaucholocos.com/") {
	var IsFront = true;
} else {
	var IsFront = false;
}
var ShowIt;
var OKSports="M. Basketball|Baseball|M. Volleyball|M. Tennis|M. Golf|M. Water Polo|W. Basketball|Softball|M. Soccer|W. Soccer|W. Volleyball"
var rs=0;
var fdet="All Sports";
var fhome=_gel("ShowHome").checked=="on";
var faway=_gel("ShowAway").checked=="on";
var fha="";
switch (_gel("SpFilter").value) {
   case "MenAll":
	OKSports="M. Basketball|Baseball|M. Volleyball|M. Soccer|M. Tennis|M. Golf|M. Water Polo"
	fdet="All Men's Sports"
	break;
   case "WomAll":
	OKSports="W. Basketball|Softball||W. Soccer|W. Volleyball"
	fdet="All Women's Sports"
	break;
   case "WBB":
	OKSports="W. Basketball"
	fdet="W. Basketball"
	break;
   case "Base":
	OKSports="Baseball"
	fdet="Baseball"
	break;
   case "MBB":
	OKSports="M. Basketball"
	fdet="M. Basketball"
	break;
   case "MVB":
	OKSports="M. Volleyball"
	fdet="M. Volleyball"
	break;
   case "WVB":
	OKSports="W. Volleyball"
	fdet="W. Volleyball"
	break;
   case "Soft":
	OKSports="Softball"
	fdet="Softball"
	break;
   case "MS":
	OKSports="M. Soccer"
	fdet="M. Soccer"
	break;
   case "WS":
	OKSports="W. Soccer"
	fdet="W. Soccer"
	break;
   case "MT":
	OKSports="M. Tennis"
	fdet="M. Tennis"
	break;
   case "WT":
	OKSports="W. Tennis"
	fdet="W. Tennis"
	break;
   case "MG":
	OKSports="M. Golf"
	fdet="M. Golf"
	break;
   case "WWP":
	OKSports="W. Water Polo"
	fdet="W. Water Polo"
	break;
   case "MWP":
	OKSports="M. Water Polo"
	fdet="M. Water Polo"
	break;
   case "TF":
	OKSports="Track and Field"
	fdet="Track and Field"
	break;
   case "SWM":
	OKSports="Swimming"
	fdet="Swimming"
	break;
}

function setCalDates(offset,mid) {
   if(OldBrowser=="no") {
	/*fill in calendar dates*/
	var ThisDate=new Date();
	ThisMonth=document.getElementById("month"+mid);
	ThisDate.setDate(1);
	ThisDate.setMonth(ThisDate.getMonth()+offset);
	var Cyear =ThisDate.getYear()<1000? ThisDate.getYear()+1900: ThisDate.getYear();
	ThisMonth.innerHTML=DMNames[ThisDate.getMonth()]+" "+Cyear;
	FirstDate=new Date;
	FirstDate.setDate(1);
	FirstDate.setMonth(FirstDate.getMonth()+offset);
	var CurrentDay=FirstDate.getDay();
	var CurrentCell;
	while (FirstDate.getMonth()==ThisDate.getMonth()) {
		CurrentCell=document.getElementById("m"+mid+"_"+CurrentDay);
		CurrentCell.innerHTML=IsEvPage?"<span class='caldate'>"+FirstDate.getDate()+"</span>":FirstDate.getDate();
		CurrentCell.className+=" thismonth";
		CurrentDay=CurrentDay+1;
		FirstDate.setDate(FirstDate.getDate()+1);
	}
	CurrentCell.parentNode.className=mid==2?"":"lastweek";

	/*assign stylable class to today's date*/
	ThisDate=new Date();
	ThisDay=ThisDate.getDate();
	ThisCal=document.getElementById("calendar");	
	Cyear =ThisDate.getYear()<1000? ThisDate.getYear()+1900: ThisDate.getYear();
	if(ThisCal.innerHTML.indexOf(DMNames[ThisDate.getMonth()]+" "+Cyear)!=-1) {
		AllCells=ThisCal.getElementsByTagName("td");
		var EvCellDate=0;
		for(ac=0;ac<AllCells.length;ac++) {
			if(AllCells[ac].className.indexOf("thismonth")!=-1) {
				AllCellSpans=AllCells[ac].getElementsByTagName("span");
				EvCellDate=IsEvPage?parseInt(AllCellSpans[0].innerHTML):parseInt(AllCells[ac].innerHTML);
				if(EvCellDate==parseInt(ThisDay)) {
					AllCells[ac].className+=" today";
					AllCells[ac].title=IsEvPage?"Today: "+DDNames[ThisDate.getDay()]+", "+DMNames[ThisDate.getMonth()]+" "+ThisDate.getDate()+", "+Cyear:"";
					//AllCells[ac].title="Today: "+ThisDate;
				}
			}
		}
	}
   }
}


/*override link for smaller calendar*/
var overridelink="http://www.gaucholocos.com/events/index.html";
var AddDays=0;


/*event loader*/
function addEvent(month, day, year, link, etime,sport,opp,eloc, loco) {
   if (navigator.appVersion.indexOf("MSIE 4") == -1){
	ShowIt=="no";
	if (loco=="yes") {
	   ShowIt=_gel("ShowHome").checked?"yes":"no";
	} else {
	   ShowIt=_gel("ShowAway").checked?"yes":"no";
	}
	if (OKSports.indexOf(sport)!=-1&&ShowIt=="yes") {
	  eventCycler(month,day, year, link,etime,sport,opp,eloc,"calendar",loco);
	  if(!IsEvPage) {
		eventCycler(month,day, year, link,etime,sport,opp,eloc,"calendar2",loco);
	  }
	  if(IsFront) {
		ThisCal=document.getElementById("calendar");		
		if(ThisCal.innerHTML.indexOf(DMNames[month-1]+" "+year)!=-1 || ThisCal.innerHTML.indexOf(DMNames[month-2]+" "+year)!=-1) {
			ToDate=new Date();
			var EDate=new Date(year,month-1,day);
			if(EDate.getMonth()!=ToDate.getMonth()) {
				AddDays=parseInt(NDays[ToDate.getMonth()]);
			} else {
				AddDays=0;
			}
			DaysDiff=EDate.getDate()-ToDate.getDate();
			DaysDiff=DaysDiff+AddDays;
			if(DaysDiff>=0  && DaysDiff<=6 ) {
				setTd=document.getElementById("td_"+DaysDiff);
				setTd.innerHTML+="<a href='"+link+"' class='7days loco'>"+"<div class='sport'>"+sport+"</div><div class='opp'>Vs. "+opp+"</div><div class='time'>"+etime+","+month+"/"+day+"</div></a>";
			}
		}
	  }
	}
   }
}
function eventCycler(month, day, year, link,etime,sport,opp,eloc,el,loco) {
	ThisCal=document.getElementById(el);
	if(ThisCal.innerHTML.indexOf(DMNames[month-1]+" "+year)!=-1) {
		AllCells=ThisCal.getElementsByTagName("td");
		var CellDate=0;
		var OffMonth=0;
		for(ac=0;ac<AllCells.length;ac++) {
			var ThisCellDay=0;
			CellDate=IsEvPage?"span":"a";
			LinksPresent=AllCells[ac].getElementsByTagName(CellDate);
			ThisCellDay=LinksPresent.length>0? LinksPresent[0].innerHTML:AllCells[ac].innerHTML;
			if(ThisCellDay==day) {
				AllCells[ac].className+=IsEvPage?"":loco=="yes"?" loco": " home";
				if(IsEvPage) {
					if(loco=="yes") {
						AllCells[ac].innerHTML=AllCells[ac].innerHTML+"<p><a href='"+link+"' class='loco'>"+"<span class='sport'>"+sport+"</span><br /><span class='opp'>Vs. "+opp+"</span><br /><span class='time'>"+etime+"</span><br /><span class='location'>"+eloc+"</span></a></p>";
					} else {
						AllCells[ac].innerHTML=AllCells[ac].innerHTML+"<p><a href='"+link+"' class='home'>"+"<span class='sport'>"+sport+"</span><br /><span class='opp'>Vs. "+opp+"</span><br /><span class='time'>"+etime+"</span><br /><span class='location'>"+eloc+"</span></a></p>";
					}
				} else {
					title =etime+" "+sport+": "+opp+" - "+eloc;
					OffMonth=el.substr(el.length-1,1)==2?1:0;
					if(ns6) {
						AllCells[ac].innerHTML=LinksPresent.length>=1?"<a href='"+overridelink+"?+"+OffMonth+"' title='"+LinksPresent[0].title+" and "+title+"'>"+day+"</a>":"<a href='"+overridelink+"?+"+OffMonth+"' title='"+title+"'>"+day+"</a>";
					} else {
						AllCells[ac].innerHTML=LinksPresent.length>=1?"<a href='"+overridelink+"?+"+OffMonth+"' title='"+LinksPresent[0].title+" \n"+title+"'>"+day+"</a>":"<a href='"+overridelink+"?+"+OffMonth+"' title='"+title+"'>"+day+"</a>";
					}
				}
			}
		}
	}
}
/*call to set dates*/
if (OldBrowser=="no"){
  if(IsEvPage) {
	if(document.location.href.match(/\?\+([0-9])+/ig)) {
		var OffMonth=document.location.href.match(/\?\+([0-9])+/ig);
		setCalDates(parseInt(OffMonth[0].substring(2,OffMonth[0].length)),1);
	} else {
		setCalDates(0,1);
	}
  } else {
	if(!IsEvPage) {
		setCalDates(0,1);
		setCalDates(1,2);
	}
  }
}


if (OldBrowser=="no"){
/*show calendar*/
document.write("<style type=\"text/css\">#cal {display:block;margin-left:4px;text-align:left;width=143;}</style>");
CalDiv=document.getElementById("cal");
if(CalDiv) {
	CalDiv.style.textAlign="left";
	CalDiv.parentNode.style.textAlign="left";
	Mo1=document.getElementById("month1");
	Mo1.style.textAlign="center";
	Mo2=document.getElementById("month2");
	Mo2.style.textAlign="center";
}
}

function PRef() {
	_eLine=SHo.checked?"&Home":"";
	_eLine+=SHa.checked?"&Away":"";
	window.location="http://www.gaucholocos.com/GMod/events/index.html?&SpFilter="+OptList[SpFilter.selectedIndex]+_eLine;
}

