var types = ["Lower-School","Middle-School","Sports","Church", "Afterschool","Arts"];
var type_visible = [true,true,true,true,true,true];
var type_id_count = [0,0,0,0,0,0];
var type_events = [[],[],[],[],[],[]];


var posX=120;
var posY=183;
var all = false;

var ls_events=[];
var ms_events=[];
var as_events=[];
var sports_events=[];
var church_events=[];
var art_events=[];

var today=false;

var calendar=["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""];

function setMouse(x, y){
  posX=x;
  posY=y;
}

function iecompattest(){
  return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function Chip(chipname,width,height){
  this.named=chipname;

}

function updatebox(chipname, day){
    eval("chip="+chipname);
    if(chipname=="quicklinks"){
        document.getElementById(chip.named).style.right="0px";
        document.getElementById(chip.named).style.top="180px";
     document.getElementById(chip.named).innerHTML = "<table border=0 bgcolaor=#E4E4E4><tr><td bgcolor=#E4E4E4 class=td nowrap valign=top>"+day+"</td></tr></table>";

    }
    else if(chipname=="sideboxes"){
        document.getElementById(chip.named).style.right="10px";
        document.getElementById(chip.named).style.top="200px";
      document.getElementById(chip.named).innerHTML = "<table border=1 bgcolor=#E4E4E4><tr><td valign=top>"+day+"</td></tr></table>";
    }
    else {
      if(calendar[day]==undefined){
        alert(day)
      }
      document.getElementById(chip.named).style.left= posX + "px";
      document.getElementById(chip.named).style.top = posY + "px";

        temp = filter_event(calendar[day]);
        document.getElementById(chip.named).innerHTML = "<table border=0 abgcolor=#E4E4E4 style='max-width:200px;min-width:100px;'><tr><td bgcolor=#E4E4E4 valign=top class=td>"+temp+"</td></tr></table>";

    }
}

function filter_event(filter_me){
  if(all) return filter_me;
  
  for(i=0;i<types.size();i++){
    if(!type_visible[i]){
      temp = "<" +types[i] +">";
      splits = new String(filter_me).split(temp);
      var newsplits="";
      
      for(j = 0; j < splits.size();j++){
        if(j%2==0){
          newsplits+=splits[j];
        }
      }
      filter_me=newsplits;
    }
  }
  
  return filter_me;
}

function add_calendar_event(title,day,type,description){
  if(type==undefined){
    calendar[day]=[title];    
  }else{
    increment_id(type,title);
  }
}

function increment_id(type,title){
  for(i=0;i<types.size();i++){
    if(type==types[i]){
      type_id_count[i]+=1;
      type_events[i] = type_events[i].concat(title);
      return;
    }
  }
  alert('couldnt find type : '+type);
}

function toggle_show(index){
  if(index>= types.size() ) alert('index not found - moveobj.js');
  if(index==-1){
    all=!all;
  }
  
  type_visible[index]= !type_visible[index];
  if(type_visible[index])
      add_checked_type(index,type_id_count[index]);
  else
      clear_unchecked_type(index,type_id_count[index]);
}

function clear_unchecked_type(type_index,num){
  for(i = 1 ; i<= num;i++){
    var temp = types[type_index]+i+"_small";
    document.getElementById(temp).innerHTML = "";
  }
}

function add_checked_type(type_index,num){
 for(i = 1 ; i<= num;i++){
   var temp = types[type_index]+i+"_small";
   document.getElementById(temp).innerHTML = type_events[type_index][i-1];
 }
}
