/*
    This file contains javascript methods used by Connect Daily for 
	Miscellaneous Routines for Popping open Windows.

	Connect Daily Web Calendar Software

	Copyright 2008, MH Software, Inc. All Rights Reserved
	1006 W 104th Ave #500, Northglenn CO 80234-3802
	+1 303 438 9585

	Last Edit By: "$Author: gsexton $"
	Last Checkin: "$Date: 2008/12/20 16:11:22 $"
	Revision #  : "$Revision: 1.5 $"
*/

function getPopLeft(iPrefWidth) {
    var iResult=50;
    if (screen.availWidth) {
	// The availLeft attempts to handle multi-monitor systems cleanly.
        iResult=(screen.availWidth-iPrefWidth)/2+(screen.availLeft==undefined ? 0 : screen.availLeft );
    }
    return iResult;
}
function getPopTop(iPrefHeight){
    var iResult=50;
    if (screen.availHeight) {
        iResult=(screen.availHeight-iPrefHeight)/2;
    }
    return iResult;
}

function popReminder(iItemID,iIntegral) {
    window.open("EditReminder.html?cal_item_id="+iItemID+"&integral="+iIntegral,
                "EditReminder_"+(new Date().getTime()),"scrollbars=yes,status=no,location=no,menubar=no,toolbar=no,width=800,height=400,left="+getPopLeft(800)+",top="+getPopTop(500));
}

/**
* This function pops the view item window. All arguments except for iItemID are optional.
* <BR><BR>
* An attempt will be made to center the window within the display. It works pretty well 
* for single monitor systems, and for dual monitors it works well with Firefox. IE7 is
* sort of broken. Oh well.
*
* @param iItemID the cal_item_id of the event to view.
* @param iSpecificDate The specific instance date of the event to view. 
* Default, -1 which means no specific date.
* @param bIntegral if True, display in integral mode, which gives additional info. Defaut behavior is false.
* @param iDisplayGenerated This is the system time as MilliSeconds since epoch that
* the underlying display was generated. This value can be passed to ViewItem so that
* ViewItem can detect if the underlying event has been changed since the display
* was generated. If this parameter is not defined, and a global variable of
* check_after is defined, that value is used. Default value is undefined.
* @param cStyleSheet Style Sheet that should be used to override the default. If this
* argument is not defined, and a global variable style_sheet is defined, that is used.
*/
function popItem(iItemID, iSpecificDate,bIntegral,iDisplayGenerated,cStyleSheet) {
   if (cStyleSheet==undefined) {
	if (!(typeof style_sheet=="undefined")) {
	cStyleSheet=style_sheet;
	}
	}
    if (iDisplayGenerated==undefined) {
	if (!(typeof checkafter=="undefined")) {
	  	iDisplayGenerated=checkafter;
	}
    }
    if (bIntegral==undefined) {
	if (!(typeof integral=="undefined")) {
		bIntegral=integral;
	}
    }

    
    window.open("ViewItem.html?integral="+(bIntegral==undefined ? 0 : (bIntegral ? 1 : 0))+
	"&detail="+(bIntegral ? 1 : 0)+
	"&cal_item_id="+iItemID+
	(((iSpecificDate==undefined) || (iSpecificDate<0)) ? '' : '&dtwhen=' + iSpecificDate)+
	(cStyleSheet==undefined ? '' : '&style_sheet='+cStyleSheet)+
	(iDisplayGenerated==undefined ? '' : '&checkafter=' + iDisplayGenerated),
        "ViewItemWin_"+(new Date().getTime()),
	"scrollbars=yes,resizable=yes,status=no,location=no,menubar=no,toolbar=no,width=670,height=500,left="+getPopLeft(620)+",top="+getPopTop(500));
}
var pWidth,pHeight,pZ;
function widenDiv(divID){
	var myDiv=document.getElementById(divID);
	if (myDiv) {
		with (myDiv.style) {
			pWidth=width;
			pHeight=height;
			pZ=zIndex;
			zIndex=99;
			width="auto";
			height="auto";
		}
	}
}
function shrinkDiv(divID, iOriginalWidth,iOriginalHeight){
	var myDiv=document.getElementById(divID);
	if (myDiv) {
		with (myDiv.style) {
			zIndex=pZ;
			width=pWidth;
			height=pHeight;
		}
	}
}
function sizeWindow(){
    var myDiv=document.getElementById("ContentDiv");
    var isIE=navigator.userAgent.toLowerCase().indexOf("msie")>0;
    var winWidth=document.body.scrollWidth;
    var winHeight=document.body.scrollHeight;
    var newHeight;

    if (isIE) {
        newHeight=winHeight-document.documentElement.clientHeight+30;
    } else {
        newHeight=winHeight-window.innerHeight+30;
    }
    if (screen.availHeight) {
        if (newHeight>screen.availHeight) {
            newHeight=screen.availHeight;
        }
    }
    // center the window
    if (window.moveTo) 
        window.moveTo((screen.availWidth-winWidth)/2,(screen.availHeight-winHeight)/2);

    window.resizeBy(0,newHeight);

}
function sizeWindowOld() {
    
    var winHeight,winWidth,clWidth,clHeight;
    var isIE=navigator.userAgent.toLowerCase().indexOf("msie")>0;

    if (isIE) {
            clWidth=document.body.clientWidth;
            clHeight=document.body.clientHeight;
            alert(document.body.scrollHeight+" clientHeight="+document.body.scrollHeight);
    } else {
        clHeight=window.innerHeight;
        clWidth=window.innerWidth;
        clHeight=document.body.scrollHeight;
        clWidth=document.body.scrollWidth;

    }
    if (screen.availHeight) {
    }

    // add 30 to the width for a border
    // add 60 to the height to account for a border + the titlebar
   //  alert("WinWidth="+winWidth+" WinHeight="+winHeight);
    window.resizeTo(clWidth+30,clHeight+40);
   
    //center the window
    if (window.moveTo) 
        window.moveTo((screen.availWidth-winWidth)/2,(screen.availHeight-winHeight)/2);
}

function popObjectLogEntries(iObjectType,iObjectID) {
    window.open("ViewLogEntriesForObject.html?object_type_id="+iObjectType+"&object_id="+iObjectID,
                "ViewLEObj_"+(new Date().getTime()),"scrollbars=yes,status=no,location=no,menubar=no,toolbar=no,width=800,height=400,left="+getPopLeft(800)+",top="+getPopTop(500));
}
