/*
    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/09/17 20:24:29 $"
	Revision #  : "$Revision: 1.4 $"
*/

function getPopLeft(iPrefWidth) {
    var iResult=50;
    if (screen.availWidth) {
        iResult=(screen.availWidth-iPrefWidth)/2;
    }
    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));
}


function popItem(iItemID, iSpecificDate,bIntegral) {
    window.open("ViewItem.html?integral="+(bIntegral ? 1 : 0)+"&detail=1&cal_item_id="+iItemID+
					(iSpecificDate < 0 ? '' : '&dtwhen=' + iSpecificDate),
                    "ViewItemWin_"+(new Date().getTime()),"scrollbars=yes,resizable=yes,status=no,location=no,menubar=no,toolbar=no,width=700,height=500,left="+getPopLeft(700)+",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));
}
