var rowcnt = 0;

function insertOLEvent(date, name, dic, arr, url, compId, ed, led, flags) {
	var compDate = new Date()
	compDate.setFullYear(date.substr(0,4),date.substr(5,2)-1,date.substr(8,2));
	compDate.setHours(23);
	compDate.setMinutes(59);
	if (rowcnt++ % 2 == 1) {  
		document.write("<tr class=\"odd\">"); 
	}
	else {
		document.write("<tr class=\"evan\">"); 
	}
	var dayName;
	switch(compDate.getDay()) {
		case 0: dayName = "S&ouml;n"; break;
		case 1: dayName = "M&aring;n"; break;
		case 2: dayName = "Tis"; break;
		case 3: dayName = "Ons"; break;
		case 4: dayName = "Tor"; break;
		case 5: dayName = "Fre"; break;
		case 6: dayName = "L&ouml;r"; break;
	}
	if (compDate.getDay()==0) document.write("<td class=\"cdate sunday\">");
	else document.write("<td class=\"cdate\">");
//	document.write(compDate.getDate());
	document.write("<A title=\"" + dayName + "\">" + compDate.getDate() + "</A>");
	document.write("</td> <td  class=\"catIcon\">")
	if (dic.length > 0) {
		switch (dic) {
			case "l":
			case "L":
			case "L&Aring;NG":
				document.write("<IMG BORDER=\"0\" SRC=\"img/l6.png\" title=\"långdistans\" WIDTH=\"13\" HEIGHT=\"13\"\/>");
				break;
			case "m":
			case "M":
			case "MED":
				document.write("<IMG BORDER=\"0\" SRC=\"img/m6.png\" title=\"medeldistans\" WIDTH=\"13\" HEIGHT=\"13\"\/>");
				break;
			case "s":
			case "S":
			case "SP":
				document.write("<IMG BORDER=\"0\" SRC=\"img/s6.png\" title=\"sprint\" WIDTH=\"13\" HEIGHT=\"13\"\/>");
				break;
			case "b":
			case "STAF":
				document.write("<IMG BORDER=\"0\" SRC=\"img/b6.png\" title=\"budkavle\" WIDTH=\"13\" HEIGHT=\"13\"\/>");
				break;
			case "n":
			case "NATT":
				document.write("<IMG BORDER=\"0\" SRC=\"img/n6.png\" title=\"natt\" WIDTH=\"13\" HEIGHT=\"13\"\/>");
				break;
			case "u":
			case "ULTRA":
			case "UL":
				document.write("<IMG BORDER=\"0\" SRC=\"img/u6.png\" title=\"ultralång\" WIDTH=\"13\" HEIGHT=\"13\"\/>");
				break;
			case "f":
			case "F":
				document.write("<IMG BORDER=\"0\" SRC=\"img/f6.png\" title=\"flerdagars\" WIDTH=\"13\" HEIGHT=\"13\"\/>");
				break;
			case "p":
			case "P":
				document.write("<IMG BORDER=\"0\" SRC=\"img/p6.png\" title=\"patrull\" WIDTH=\"13\" HEIGHT=\"13\"\/>");
				break;
		}
	}

	var today = new Date();
	var ordDate = new Date();
	var lateDate = new Date();
	var frist = 0; // 0:innan anm, 1:ord, 2:efteranm, 3:efter_tävl
	if (today>compDate) frist = 3;
	else if (compId.length > 0) {
		ordDate.setFullYear(ed.substr(0,4),ed.substr(5,2)-1,ed.substr(8,2));
		if (ed.length > 15) {
			ordDate.setHours(ed.substr(11,2));
			ordDate.setMinutes(ed.substr(14,2));
		}
		else {
			ordDate.setHours(23);
			ordDate.setMinutes(59);
		}
		if (today<ordDate) frist = 1;
		else {
			lateDate.setFullYear(led.substr(0,4),led.substr(5,2)-1,led.substr(8,2));
			if (led.length > 15) {
				lateDate.setHours(led.substr(11,2));
				lateDate.setMinutes(led.substr(14,2));
			}
			else {
				lateDate.setHours(23);
				lateDate.setMinutes(59);
			}
			if (today<lateDate) frist = 2;
		}
	}
	if (flags.indexOf("C") >= 0) document.write("</td> <td class=\"name canceled\">")
  else if (frist==3) document.write("</td> <td class=\"name past_name\">")
	else document.write("</td> <td  class=\"name\">")
	if (url.length > 0) {
    	if (flags.indexOf("B") >= 0) document.write("<strong>");
    	document.write(" <A HREF=\"" + url + "\" TARGET=\"_blank\" title=\"" + arr + "\">" + name + "</A>");
    	if (flags.indexOf("B") >= 0) document.write("</strong>");
	}
	else {//document.write(name);
    	if (flags.indexOf("B") >= 0) document.write("<strong>");
    	document.write(" <A title=\"" + arr + "\">" + name + "</A>");
			document.write("</td> <td class=\"entryLink\">")
    	if (flags.indexOf("B") >= 0) document.write("</strong>");
  }
		if (compId.length > 0) {
			var es = new String();
//			if (compId.length<=6) es = "http://eventor.orientering.se/Entry?eventIds=" + compId;
			if (compId.length<=6) es = "http://eventor.orientering.se/Events/Show/" + compId;
			else es = compId;
			if (frist==1) {
//			    document.write("<A HREF=\"http://www.svenskidrott.se/Entry.asp?WCI=wiPublicEntry&WCE=ceMoreInfo&Orgelementid=43150&CompId=");
//    			document.write(compId + "\" TARGET=\"_blank\">");
			    document.write(" <A HREF=\"" + es + "\" TARGET=\"_blank\">");
				document.write("anm</A> (" + ordDate.getDate() + "/" + (ordDate.getMonth()+1));
				if (ed.length > 15) {
					document.write(" " + mk2dig(ordDate.getHours()) + ":" + mk2dig(ordDate.getMinutes()));
				}
				document.write(")");
			} 
			else {
				if (frist==2) {
//					document.write("<A HREF=\"http://www.svenskidrott.se/Entry.asp?WCI=wiPublicEntry&WCE=ceMoreInfo&Orgelementid=43150&CompId=");
//					document.write(compId + "\" TARGET=\"_blank\">");
			    document.write(" <A HREF=\"" + es + "\" TARGET=\"_blank\">");
					document.write("efteranm</A>(" + lateDate.getDate() + "/" + (lateDate.getMonth()+1));
					if (led.length > 15) {
						document.write(" " + mk2dig(lateDate.getHours()) + ":" + mk2dig(lateDate.getMinutes()));
					}
					document.write(")");
				}
			}
	}
	document.write("</td></tr>");
}

function insertEventMonth(name) {
	rowcnt = 0;
	document.write("<tr>"); 
	document.write("<td class=\"month_pad\" colspan=2></td>");
	document.write("<td class=\"month\" colspan=2>");
	document.write(name +" </td>");
	document.write("</tr>");
}

function insertEventFooter() {
	document.write("<tr>"); 
	document.write(" <td class=\"footer\" colspan=4></td>");
	document.write("</tr>");
}

function mk2dig(inNr) {
	if (inNr.toString().length > 1) return inNr;
	else return "0" + inNr;
}



    function insertDate(background, date, weekday, activity, time, loc, comment) {
      if ( background == "" ) {
        if ( weekday == "S&ouml;" ) {
          background = "orangered"
        }
        else {
          background = "skyblue";
          if ( date % 2 ) {
            background = "lightblue";
          }
        }
      }
 
      document.write("<tr bgcolor=" + background + ">");
      document.write(" <td width=38>  <font size=1 face=\"Verdana, Arial, Helvetica, sans-serif\">" + date + "</font></td>");
      document.write(" <td width=24>  <font size=1 face=\"Verdana, Arial, Helvetica, sans-serif\">" + weekday + "</font></td>");
      document.write(" <td width=140> <font size=1 face=\"Verdana, Arial, Helvetica, sans-serif\">" );
      if (activity.length = 0) {
        document.write("&nbsp;</font></td>");
      }
      else document.write( activity + "</font></td>" );

      document.write(" <td width=78> <font size=1 face=\"Verdana, Arial, Helvetica, sans-serif\">" );
      if (time.length = 0) {
        document.write("&nbsp;</font></td>");
      }
      else document.write( time + "</font></td>" );

      document.write(" <td width=120> <font size=1 face=\"Verdana, Arial, Helvetica, sans-serif\">" );
      if (loc.length = 0) {
        document.write("&nbsp;</font></td>");
      }
      else document.write( loc + "</font></td>" );

      document.write(" <td width=240><font size=1 face=\"Verdana, Arial, Helvetica, sans-serif\">" );

      if (comment.length = 0) {
        document.write("&nbsp;</font></td>");
      }
      else document.write( comment + "</font></td>" );

      document.write("</tr>");
    }
