// the div for defining the popup
////////////////if (document.getElementById || document.all)
////////////////document.write('<div id="popup" class="daypopup"></div>')
// keeps the stupid IE browser from clearing out the calendar when 
if(document.all)
document.execCommand("BackgroundImageCache", false, true)

function getpopup(){
if (document.getElementById)
return document.getElementById("popup")
else if (document.all)
return document.all.popup
}

//function getpopupstyle(){
//if(document.getElementById)
//return document.getElementById("popup").style
//else if(document.all)
//return document.all.popup.style
//}

var popupstyle;

function showpopup(strHTML){
    strHTML = strHTML.replace("listforpopup","listinpopup");
    getpopup().innerHTML=strHTML
    
    popupstyle.display="inline"
    document.onmousemove=followmouse
}

function hidepopup(){
    document.onmousemove=" "
    getpopup().innerHTML=" "
    if(!popupstyle)
    {
        popupstyle=getpopup().style;
    }
    popupstyle.display="none"
}

//----------------------------------------------------------
// for moving the popup
var offsetfrommouse=[10,10] // offset from mouse in pixels...
var docwidth=0;
var docheight=0;

function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}
function getWindowSize(){
	docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)
}
function setVars(){
    popupstyle = document.getElementById("popup").style;
    getWindowSize();
}
function followmouse(e){
	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

		if (typeof e != "undefined"){

		//Determines which side of the cursor the popup should be on
        if((docwidth - xcoord - 270)> e.pageX)
		{
		    xcoord = e.pageX; //Moves to left side
		}
		else
		{
		    xcoord = e.pageX - 270 + xcoord //Moves to right side
		}
		
//		//Determines if the popup should be above or below the cursor
//		ycoord += e.pageY;
		if ((docheight - ycoord - 200) < e.pageY)
		{
		    // set popup y-coord (top left corner) location equal to cursor position minus popup height
		    ycoord = e.pageY - parseInt(document.getElementById("popup").offsetHeight);
		    //move popup up
		} 
		else {ycoord += e.pageY; } //move popup down

		
		
	} else if (typeof window.event != "undefined"){
        //Determines which side of the cursor the popup should be on
		if((docwidth - xcoord - 270)> event.clientX)
		{
		    xcoord = event.clientX;  //Moves to left side
		}
		else
		{
		    xcoord = event.clientX - 270 + xcoord //Moves to right side
		}
		
//		//Determines if the popup should be above or below the cursor
//		ycoord += truebody().scrollTop + event.clientY;
		if ((event.clientY + 200) > docheight)//Determines if popup should be above/below cursor
		   {ycoord = truebody().scrollTop + event.clientY - 200; } // put popup above
		else 
		   {ycoord = truebody().scrollTop + event.clientY; } // put popup below mouse
	}

	if(ycoord < 0) { ycoord = ycoord*-1; }
	//getpopupstyle().left=xcoord+"px"
	popupstyle.left = xcoord+"px";
	//getpopupstyle().top=ycoord+"px"
	popupstyle.top = ycoord+"px";
	}

//-----------------------------------------------------------
function ToggleNotepad()
{
    var btn=document.getElementById("btnNotepad");
    if(!btn){
        return;
    }
    var calendar=document.getElementById("Calendar1");
    if(btn.title=='Turn off notepad'){
        // change the onmouseover event to not show the popup
        for(var i=2;i<calendar.rows.length;i++){
            for(var j=0;j<calendar.rows[i].cells.length;j++){
                if(calendar.rows[i].cells[j].childNodes.length>1){
                    calendar.rows[i].cells[j].onmouseover='hidepopup();';
                }
            }
        }
        btn.title='Turn on notepad';
    }
    else if(btn.title=='Turn on notepad'){
        // change the onmouseover event to show the popup
        for(var i=2;i<calendar.rows.length;i++){
            for(var j=0;j<calendar.rows[i].cells.length;j++){
                if(calendar.rows[i].cells[j].childNodes.length>1){
                    calendar.rows[i].cells[j].onmouseover='showpopup(this.innerHTML);';
                }
            }
        }
        btn.title='Turn off notepad';
    }
}