//Global Variables
var popupDivObj;

// Detect Browser
if (document.layers) navigator.family = "nn4";
if (document.all) navigator.family = "ie4";
if (window.navigator.userAgent.toLowerCase().match("gecko")) navigator.family = "gecko";

//  PopUp Box
function popupBox(currMonth, events) 
{
    var divW, divH;
    
    //Format Popup HTML
	var popupHTML = "<table cellpadding=1 cellspacing=0 class=\"cal-popup\">"
				    +"	<tr><th class=\"cal-popup\" nowrap>" + currMonth + "</th></tr>"
				    +"	<tr><td class=\"cal-popup\">"
				    +"		<table class=\"cal-month-day-events\">"
				    +			events
				    +"		</table>"
				    +"	</td></tr>"
				    +"</table>";
      
	//Popup Placement
	var popupDivStyleObj, tempTop, tempLeft;
	
	if (typeof popupDivObj == 'undefined')
	{	
		popupDivObj = document.createElement('DIV');
		document.body.appendChild(popupDivObj);
		popupDivObj.style.display = 'none';
		popupDivObj.style.position = 'absolute';
		popupDivObj.style.visibility = 'hidden';
	}
	
	if(navigator.family == "nn4") 
	{
	    //popupDivObj = document.popupDiv;
	    popupDivStyleObj = popupDivObj;
		popupDivObj.document.write(popupHTML);
		popupDivObj.document.close();
	    divW = popupDivObj.offsetWidth;
	    divH = popupDivObj.offsetHeight;
    }
	else if(navigator.family == "ie4") 
	{	    
	    popupDivStyleObj = popupDivObj.style;
	    popupDivStyleObj.left = 0;
	    popupDivStyleObj.top = 0; 	    
  		popupDivStyleObj.display = "block";	    
  		popupDivObj.innerHTML = popupHTML;
        divW = popupDivObj.offsetWidth;
	    divH = popupDivObj.offsetHeight;
	    popupDivStyleObj.display = "none";
	}
	else if(navigator.family == "gecko") 
	{	
	    popupDivStyleObj = popupDivObj.style;		
  		popupDivObj.innerHTML = popupHTML;
	    popupDivStyleObj.left = 0;
	    popupDivStyleObj.top = 0;  		
  		popupDivStyleObj.display = "block";
  	    divW = popupDivObj.offsetWidth;
	    divH = popupDivObj.offsetHeight;
	    popupDivStyleObj.display = "none";
	}
 
	var exWR, exWL, exHB, exHT;
	exWR = (divW + x + 20 >= winWR);    //Popup will go beyond right window border if placed to the right of the cursor.
	exWL = (winWL >= x - divW);         //Popup will go beyond left window border if placed to the left of the cursor.
	exHB = (divH + y + 20 >= winHB);    //Popup will go beyond bottom window border if placed below the cursor.    
	exHT = (winHT >= y - (divH + 20));  //Popup will go beyond top window border if placed above the cursor.  	        
	    
	//Horizontal Placement
    if(exWR)
        if(exHB)
            if(exWL)
                tempLeft = winWL + "px";
            else
                tempLeft = (x - divW - 10) + "px";
        else if(exWL)
            tempLeft = winWL + "px";
        else
	        tempLeft = (winWR - divW - 20) + "px";
    else
	    tempLeft = (x + 10) + "px";

    //Vertical Placement		    
    if(exHB)
        if(exWR)
            if(exHT)
                tempTop = winHT + "px";
            else
		        tempTop = (y - divH - 10) + "px";
	    else
		    tempTop = (winHB - divH - 20) + "px";
    else
	    tempTop = (y + 10) + "px";	
	    
	popupDivStyleObj.left = tempLeft;
	popupDivStyleObj.top = tempTop;
	
	popupDivStyleObj.display = "block";
	popupDivStyleObj.visibility = "visible";

    if (navigator.family == "ie4")
    {
        //IE Does not allow divs to be placed on top of WindowControls (<select> elements, java applets, etc...) 
        //An IFrame can be however, so we must place an Iframe of the same width/height directly behind the div.
	    /*
	    popupDivStyleObj.zIndex = 1000;
	    document.getElementById("popupDivShim").style.display = "block";
	    document.getElementById("popupDivShim").style.width = divW + "px";
	    document.getElementById("popupDivShim").style.height = divH + "px";
	    document.getElementById("popupDivShim").style.top = popupDivStyleObj.top;
	    document.getElementById("popupDivShim").style.left = popupDivStyleObj.left;
	    document.getElementById("popupDivShim").style.zIndex = popupDivStyleObj.zIndex - 1;
	    */
	    CreateDivShim(popupDivObj);
	}
}

function TitlePopupBox(eventTitle) 
{
    var divW, divH;
    
    //Format Popup HTML
	var popupHTML = "<span style=\"font-size:8pt; background-color:#CCCCCC;padding:2px;\">" + eventTitle + "</span>";
      
	//Popup Placement
	var popupDivObj, popupDivStyleObj, tempTop, tempLeft;
	
	if(navigator.family == "nn4") 
	{
	    popupDivObj = document.popupDiv;
	    popupDivStyleObj = document.popupDiv;
		popupDivObj.document.write(popupHTML);
		popupDivObj.document.close();
	    divW = popupDivObj.offsetWidth;
	    divH = popupDivObj.offsetHeight;
    }
	else if(navigator.family == "ie4") 
	{	    
	    popupDivObj = popupDiv;
	    popupDivStyleObj = popupDivObj.style;
	    popupDivStyleObj.left = 0;
	    popupDivStyleObj.top = 0; 	    
  		popupDivStyleObj.display = "block";	    
  		popupDivObj.innerHTML = popupHTML;
        divW = popupDivObj.offsetWidth;
	    divH = popupDivObj.offsetHeight;
	    popupDivStyleObj.display = "none";
	}
	else if(navigator.family == "gecko") 
	{	
	    popupDivObj = document.getElementById("popupDiv");
	    popupDivStyleObj = document.getElementById("popupDiv").style;		
  		popupDivObj.innerHTML = popupHTML;
	    popupDivStyleObj.left = 0;
	    popupDivStyleObj.top = 0;  		
  		popupDivStyleObj.display = "block";
  	    divW = popupDivObj.offsetWidth;
	    divH = popupDivObj.offsetHeight;
	    popupDivStyleObj.display = "none";
	}
 
	var exWR, exWL, exHB, exHT;
	exWR = (divW + x + 20 >= winWR);    //Popup will go beyond right window border if placed to the right of the cursor.
	exWL = (winWL >= x - divW);         //Popup will go beyond left window border if placed to the left of the cursor.
	exHB = (divH + y + 20 >= winHB);    //Popup will go beyond bottom window border if placed below the cursor.    
	exHT = (winHT >= y - (divH + 20));  //Popup will go beyond top window border if placed above the cursor.  	        
	    
	//Horizontal Placement
    if(exWR)
        if(exHB)
            if(exWL)
                tempLeft = winWL + "px";
            else
                tempLeft = (x - divW - 10) + "px";
        else if(exWL)
            tempLeft = winWL + "px";
        else
	        tempLeft = (winWR - divW - 20) + "px";
    else
	    tempLeft = (x + 10) + "px";

    //Vertical Placement		    
    if(exHB)
        if(exWR)
            if(exHT)
                tempTop = winHT + "px";
            else
		        tempTop = (y - divH - 10) + "px";
	    else
		    tempTop = (winHB - divH - 20) + "px";
    else
	    tempTop = (y + 10) + "px";	
	    
	popupDivStyleObj.left = tempLeft;
	popupDivStyleObj.top = tempTop;
	
	popupDivStyleObj.display = "block";
	popupDivStyleObj.visibility = "visible";

    if (navigator.family == "ie4")
    {
        //IE Does not allow divs to be placed on top of WindowControls (<select> elements, java applets, etc...) 
        //An IFrame can be however, so we must place an Iframe of the same width/height directly behind the div.
	    popupDivStyleObj.zIndex = 1000;	
	    document.getElementById("popupDivShim").style.display = "block";
	    document.getElementById("popupDivShim").style.width = divW + "px";
	    document.getElementById("popupDivShim").style.height = divH + "px";
	    document.getElementById("popupDivShim").style.top = popupDivStyleObj.top;
	    document.getElementById("popupDivShim").style.left = popupDivStyleObj.left;
	    document.getElementById("popupDivShim").style.zIndex = popupDivStyleObj.zIndex - 1;
	}
}

//Delete PopUp Box
function hidePopupBox()
{
	if(navigator.family == "nn4")
		eval(document.popupDiv.top = "-1000");
	else if(navigator.family == "ie4")
	{
		popupDivObj.style.display = "none";
		popupDivObj.style.visibility = "hidden";
		
		RemoveDivShim(popupDivObj);
    }
	else if(navigator.family == "gecko") 
	{
		popupDivObj.style.display = "none";
		popupDivObj.style.visibility = "hidden";
	}
}

//Mouse Position
var isNav = (navigator.appName.indexOf("Netscape") != -1);
var x, y, winWL, winWR, winHB, winHT;

function get_coords(e) 
{
	if(isNav)
	{
	        x = parseInt(e.pageX);
	        y = parseInt(e.pageY);
	        winWR = parseInt(window.innerWidth) + parseInt(window.pageXOffset);
  	        winWL = window.pageXOffset;	
  		    winHB = window.innerHeight + window.pageYOffset;
	        winHT = window.pageYOffset;
	}
	else
	{
        if (typeof document.documentElement == "object" && (document.documentElement.clientHeight > 0 || document.documentElement.clientWidth > 0))
        {   
            //IE6 uses differnent values for documentElement instead of body if DOCTYPE is set...
	        x = event.clientX + document.documentElement.scrollLeft;
	        y = event.clientY + document.documentElement.scrollTop;
	        winWR = document.documentElement.offsetWidth + document.documentElement.scrollLeft;
  		    winWL = document.documentElement.scrollLeft;
  		    winHB = document.documentElement.offsetHeight + document.documentElement.scrollTop;	       
	        winHT = document.documentElement.scrollTop;
	    }
        else
        {   
            //IE not using DOCTYPE  
	        x = event.clientX + document.body.scrollLeft;
	        y = event.clientY + document.body.scrollTop;
	        winWR = document.body.clientWidth;
	        winWL = document.body.scrollLeft;
  		    winHB = document.body.clientHeight + document.body.scrollTop;  
  		    winHT = document.body.scrollTop;
	    }	
	}
}

if (isNav) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = get_coords;

function miniCalClicked(strDate, ReDirect)
{
    if (typeof document.calControlForm == "object")
    {
        document.calControlForm.calControlTextDate.value = strDate;
        calControlSubmitting(ReDirect);
        document.calControlForm.submit();
        return false;
    }
    else
        return true;
}