/*
    Name:    imgPopupCtr
    Args:    image source (path and filename), image width, image height, background color for window,
             title for popup
    Returns: Nothing
    
    Notes:
    For any image on the page, this script will open the image in a new window where the image 
    dimensions are passed in.  It uses the background color and
    title being passed in.  It centers the popup in the center of screen.
    
    There is also a timeout to close the window after X seconds, which be
    replaced with a close button.
    
    ealetso 02.15.2008
*/
function imgPopupCtr(imgSrc, imgW, imgH, myBgcolor, theTitle)
{
	var debug = 0;
	var timeout = 0;  /* timer > 0 will close the window after X seconds */
	var w = 0, h = 0;
	var leftPos = 0, topPos = 0;
	var windowprops = "", text = "";

	var popW = imgW+50, popH = imgH+50;

	if (screen.availWidth > 0 && screen.availHeight > 0)
	{
		w = screen.availWidth;
		h = screen.availHeight;
	}
	else
	{
		w = 480;
		h = 340;
	}

	leftPos = (w-popW)/2;
	topPos = (h-popH)/2;

	windowprops = "scrollbars=no,status=no,toolbar=no,menubar=no,location=no,resizable=no,left=" + leftPos + ",top=" + topPos + ",width=" + (popW) + ",height=" + (popH);

	text = "<html><head><title>" + theTitle + "</title></head><body bgcolor='" + myBgcolor + "'";
	
	if (timeout != 0) text +=" onLoad=\"setTimeout('window.close()', " + timeout*1000 + ");\"";
	text += "><center><img src='" + imgSrc + "'>";

	if (debug) window.alert("img [" + imgSrc + "] img w=" + imgW + " img h=" + imgH + " w= " + w + " h= " + h + " leftPos= " + leftPos + " topPos= " + topPos);

	if (timeout != 0)
	{
		text +="<p><font face='arial, helvetica' size='-1'>Preview closes after " + timeout + " seconds.</font>";
	}
	else
	{
		text += "<p><form>";
		text += "<input type=button value='Close Window' onClick='javascript:window.close();'>";
		text += "</form>";
	}

	text += "</center></body></html>";

	myPopup = window.open("", "_blank", windowprops);
	myPopup.document.open();
	myPopup.document.write(text);
	
	if (timeout != 0) myPopup.document.close();

}  // end imgPopupCtr

/*
    Name:    imgPopupCtrDynamic
    Args:    image source (path and filename), background color for window, title for popup
    Returns: Nothing
    
    Notes:
    For any image on the page, this script will open the image in a new window where the dimensions
    are dynamically sized based on the image it is putting in it.  It uses the background color and
    title being passed in.  It centers the popup in the center of screen.
    
    There is also a timeout to close the window after X seconds, which be
    replaced with a close button.
    
    NOTE: The full-sized image must be displayed on the source page for the dynamic dimensions to work
    
    ealetso 02.15.2008
*/
function imgPopupCtrDynamic(imgSrc, myBgcolor, theTitle)
{
	var debug = 0;
	var timeout = 0;  /* timer > 0 will close the window after X seconds */
	var w = 0, h = 0;
	var leftPos = 0, topPos = 0;
	var windowprops = "", text = "";

	var oImg = new Image();
	oImg.src = imgSrc;
	var popW = oImg.width+50, popH = oImg.height+50;

	if (screen.availWidth > 0 && screen.availHeight > 0)
	{
		w = screen.availWidth;
		h = screen.availHeight;
	}
	else
	{
		w = 480;
		h = 340;
	}

	leftPos = (w-popW)/2;
	topPos = (h-popH)/2;

	windowprops = "scrollbars=no,status=no,toolbar=no,menubar=no,location=no,resizable=no,left=" + leftPos + ",top=" + topPos + ",width=" + (popW) + ",height=" + (popH);

	text = "<html><head><title>" + theTitle + "</title></head><body bgcolor='" + myBgcolor + "'";
	
	if (timeout != 0) text +=" onLoad=\"setTimeout('window.close()', " + timeout*1000 + ");\"";
	text += "><center><img src='" + imgSrc + "'>";

	if (debug) window.alert("img [" + imgSrc + "] img w=" + oImg.width + " img h=" + oImg.height + " w= " + w + " h= " + h + " leftPos= " + leftPos + " topPos= " + topPos);

	if (timeout != 0)
	{
		text +="<p><font face='arial, helvetica' size='-1'>Preview closes after " + timeout + " seconds.</font>";
	}
	else
	{
		text += "<p><form>";
		text += "<input type=button value='Close Window' onClick='javascript:window.close();'>";
		text += "</form>";
	}

	text += "</center></body></html>";

	myPopup = window.open("", "_blank", windowprops);
	myPopup.document.open();
	myPopup.document.write(text);
	
	if (timeout != 0) myPopup.document.close();

}  // end imgPopupCtrDynamic

/*
    NOT FINISHED
    
    Name:    imgPopupCtrInBrowser
    Args:    None
    Returns: Nothing
    
    Notes:
    Same concept as above, except it centers based on the dimensions of the browser.
    
    ealetso 02.15.2008
*/
function imgPopupCtrInBrowser()
{
	var w = 480, h = 340;

	/* centers in browser window */
	if (document.all)
	{
		/* the following is only available after onLoad */
		w = document.body.clientWidth;
		h = document.body.clientHeight;
	}
	else if (document.layers)
	{
		w = window.innerWidth;
		h = window.innerHeight;
	}

	var popW = 300, popH = 200;

	var leftPos = (w-popW)/2, topPos = (h-popH)/2;

	window.alert("document.body.clientWidth = " + document.body.clientWidth + " document.body.clientHeight = " + document.body.clientHeight);
	window.alert("document.all = " + document.all + " document.layers = " + document.layers);
	window.alert("window.innerWidth = " + window.innerWidth + " window.innerHeight = " + window.innerHeight);
	window.alert("w = " + w + " h = " + h + " leftPos = " + leftPos + " topPos = " + topPos);
	//window.open('page,html','popup','width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);
}  // end imgPopupCtrInBrowser

// different width and height values

// total screen
//window.alert("screen.availWidth = " + screen.availWidth + " screen.availHeight = " + screen.availHeight);

// browser
//window.alert("document.body.clientWidth = " + document.body.clientWidth + " document.body.clientHeight = " + document.body.clientHeight);

// browser
//window.alert("window.innerWidth = " + window.innerWidth + " window.innerHeight = " + window.innerHeight);

/*
    Name:    imgPopup
    Args:    image source (path and filename), background color for window, title for popup
    Returns: Nothing
    
    Notes:
    For any image on the page, this script will open the image in a new window where the dimensions
    are dynamically sized based on the image it is putting in it.  It uses the background color and
    title being passed in.  It popups up in a fixed position based on pixels set in function.
    
    There is also a timeout to close the window after X seconds, which be
    replaced with a close button.
    
    NOTE: The full-sized image must be displayed on the source page for the dynamic dimensions to work
    
    ealetso 02.15.2008
*/
function imgPopup(isrc)
{
	var oImg = new Image();
	oImg.src = isrc;

	// window always shows up in fixed position
	windowprops = "scrollbars=no,status=no,toolbar=no,menubar=no,location=no,resizable=no,left=250,top=250,width=" + (oImg.width+50) + ",height=" + (oImg.height+50);

	text = "<html><head><title>Preview</title></head><body bgcolor='#990099'";
	if (timeout != 0) text +=" onLoad=\"setTimeout('window.close()', " + timeout*1000 + ");\"";
	text += "><center><img src='" + isrc + "'>";

	if (timeout != 0)
	{
	text +="<br><font face='arial, helvetica' size='-1'>Preview closes after " + timeout + " seconds.</font>";
	}
	else
	{
	text += "<p><form>";
	text += "<input type=button value='Close Window' onClick='javascript:window.close();'>";
	text += "</form>";
	}

	text += "</center></body></html>";

	myPopup = window.open("", "_blank", windowprops);
	myPopup.document.open();
	myPopup.document.write(text);
	if (timeout != 0)
	{
	myPopup.document.close();
	}
} // end imgPopup

function txtPopupCtr(txtPg, imgW, imgH)
{
	var debug = 0;
	var w = 0, h = 0;
	var leftPos = 0, topPos = 0;
	var windowprops = "";

	var popW = imgW+50, popH = imgH+50;

	if (screen.availWidth > 0 && screen.availHeight > 0)
	{
		w = screen.availWidth;
		h = screen.availHeight;
	}
	else
	{
		w = 480;
		h = 340;
	}

	leftPos = (w-popW)/2;
	topPos = (h-popH)/2;

	windowprops = "scrollbars=yes,status=no,toolbar=no,menubar=no,location=no,resizable=no,left=" + leftPos + ",top=" + topPos + ",width=" + (popW) + ",height=" + (popH);

	window.open(txtPg, "_blank", windowprops);

}  // end txtPopupCtr
