// debug through #8

// former "winsize.js" is now "chimepct.js"; thus this file is named 
// winsize2.js to minimize confusion.

var custwin_temp_h = 0;
var custwin_temp_w = 0;

// width, height, top, left
var ws_w, ws_h, ws_t, ws_l;

var hroom;

// molecular image frame width, ChimePct, ChimePctAuto

var chp, chpas, chpa;

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function init_chp()
{
	chp = getCookie("ChimePct");
	chpas = getCookie("ChimePctAuto");
//alert("winsize2.js #7 getCookie chp=|" + chp + "| chpas=|" + chpas + "|");

	if (chp == null)
		chp = "";

	if (chpas == null)
		chpa = true;
	else
		chpa = (chpas == "true");

//alert("winsize2.js #8 PROCESSED getCookie chp=|" + chp + "| chpa=" + chpa);
	
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function note_winsize()
{
	ws_mode = getSelectedValue(top.frames[0].document.force_win.winparams);
	putCookie_year("WinMode", ws_mode);
	if (ws_mode == "c")
	{
		custwin_temp_h = 0;
		custwin_temp_w = 0;

		var wf = "scrollbars=1,menubar=1,width=580,height=440,resizable=1";
		top.CWSWin=window.open("wincust.htm", "CWSWinT", wf);
		top.CWSWin.focus();
	}
//	else
//		must_start_one();
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function set_wininfo() // sets height, width, top, left
{
//	 alert("winsize2.js #1 ws_mode=" + ws_mode);

	// SIZE
	if (ws_mode == "f" || ws_mode == "m") // fullscreen
		set_fullscreen();
	if (ws_mode == "c") // custom size
		set_custom();

	// TOP LEFT CORNER
	set_wintlc();
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function set_wintlc()
{
	if (top.client_mac()) // top.client_os is not defined
	{
		if (screen.width >= 1024)
		{
			ws_t = 30;
			ws_l = 20;
		}
		if (screen.width < 1024 && screen.width >=800)
		{
			ws_t = 20;
			ws_l = 10;
		}
		if (screen.width < 800) //640 x 480
		{
			ws_t = 0;
			ws_l = 0;
		}
	}
	else // Windows
	{
		ws_t = 0;
		ws_l = 0;
	}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function set_fullscreen()
{
	// Cannot open a maximized window (see javascri/wintests.htm)
	// **Negative** top,left values are reset to 0 in NS and ignored by IE.

//	alert("winsize2.js #3");
	var screen_h = screen.height;	
	var screen_w = screen.width;
	var avail_h, avail_w;

	hroom = 94; // 600, 768, and larger
	if (screen_h < 750) hroom = 90; // 480 only

	if (top.client_mac()) // top.client_os is not defined
	{
		avail_h = parseInt(0.8 * screen_h); // 80%
		avail_w = parseInt(screen_w - ((0.1 * screen_w) * (screen_w/1024)));
	}
	else // windows
	{
		avail_w = screen_w - 12; // needed for window edges

// PE 2.1 Alpha did this:
// H 768: NS needs 94; IE needs 30 more for taskbar = 124.
// H 600: Gives NS 87; gives IE 87 + 33 = 120
// H 480: Gives NS 87; gives IE 87 + 28 = 115.

		// because IE covers taskbar;
		// this assumes taskbar is at bottom and is one line high.
		if (top.isIE)
		{
			if (screen_h > 750) // 760 or larger
				hroom += 30;
			else if (screen_h < 750 && screen_h > 500) // 600
				hroom += 33;
			else if (screen_h < 500) // 480
				hroom += 28;
		}

		avail_h = screen_h - hroom;
	}

	ws_w = avail_w;
	ws_h = avail_h;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function set_custom()
{
	var pcth = getCookie("CustWinH");
	var pctw = getCookie("CustWinW");

//	alert("winsize2.js #4 pctw pcth = " + pctw + " " + pcth);

	if (pcth == null)
	{
		pcth = 87;
		pctw = 98;
	}

	var pixh = parseInt(screen.height * (pcth/100.));
	var pixw = parseInt(screen.width  * (pctw/100.));

//	alert("winsize2.js #5 pixw pixh = " + pixw + " " + pixh);

	ws_w = pixw;
	ws_h = pixh;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/*
Obsolete Code from PE 2.1 Alpha (for possible reference)

				var h, w;
				if (top.client_mac()) // top.client_os is not defined
				{
					if (screen.width >= 1024)
					{
						w=920; // -104 = 10%
						h=620; // -148 = 19%
					}
					if (screen.width < 1024 && screen.width >=800)
					{
						w=740; // -60 = 7.5%
						h=480; // -120 = 20%
					}
					if (screen.width < 800) //640 x 480
					{
						w=610; // -30 = 5%
						h=395; // -85 = 18%
					}
				}
				else // Windows
				{
					if (screen.width >= 1024)
					{

						w = 1012;
//						isIE? h = 670: h = 700; // IE only, covers taskbar, 28 pixels!
						top.isIE? h = 644: h = 674; // 26 pixels is enough room
// assumption: taskbar is only one row high.
// 768: NS needs 94; IE needs 30 more for taskbar = 124.

					}
					else if (screen.width == 800)
					{
						w = 788;
//						isIE? h = 505: h = 534;
						top.isIE? h = 480: h = 513;
// H 600: Gives NS 87; gives IE 87 + 33 = 120
					}
					else if (screen.width == 640)
					{
						w = 628;
//						isIE? h = 385: h = 413;
						top.isIE? h = 365: h = 393;
// H 480: Gives NS 87; gives IE 87 + 28 = 115.
					}
				}
			}
*/
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function get_max_h()
{
	// Netscape 4.8 can open a window taller than the screen.
	set_fullscreen(); // calculate hroom
	var max_h = parseInt((100. * (screen.height - hroom))/screen.height);
//	alert("winsize2.js #6 s.h hroom s.h-hroom max_h\n" +
//		screen.height + " " + hroom + " " + (screen.height - hroom)
//		+ " " + max_h);
	return max_h;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
