//====_ Root-Sea, Inc. JavaScript Library _====//
/*-----------------------------------------------------
== Window Control  Library == [2001/10/1]
2001-2002 (C) Root-Sea, Inc. All Rights Reserved.
Author : yoshihiro fujita

[2001.10.20 added]
isOpener

[2001.12.22 added]
getWinSize
-----------------------------------------------------*/

//::::Custom Window Open (ua_lib.js is required before performing this function) [2002.08.19 modify]
/*---
Argument...
+ uri = Link url
+ winName = Open window name
+ w = Open window width(w = 0:with no specification)
+ h = Open window height(h = 0:with no specification)
+ which = 'disp' or 'del'
+ stName = directries, status, scrollbars, location, menubar, resizable
---*/
function windowOpen(uri, winName, w, h, which, stName) {
	var stVal0, stVal1;
	var setW = parseInt(w);
	var setH = parseInt(h);
	var winStatus, winSize, winValue;
	var wOpen;

// Set Status Value(1 or 0)
	if (which == 'disp') {
		stVal0 = 0;
		stVal1 = 1;
	}
	if (which == 'del') {
		stVal0 = 1;
		stVal1 = 0;
	}

// Set default Status Value
	var directoriesVal = stVal0;
	var statusVal = stVal0;
	var scrollbarsVal = stVal0;
	var toolbarVal = stVal0;
	var locationVal = stVal0;
	var menubarVal = stVal0;
	var resizableVal = stVal0;
	stName.indexOf('directories') != -1 ? directoriesVal = stVal0 : directoriesVal = stVal1;
	stName.indexOf('status') != -1 ? statusVal = stVal0 : statusVal = stVal1;
	stName.indexOf('scrollbars') != -1 ? scrollbarsVal = stVal0 : scrollbarsVal = stVal1;
	stName.indexOf('toolbar') != -1 ? toolbarVal = stVal0 : toolbarVal = stVal1;
	stName.indexOf('location') != -1 ? locationVal = stVal0 : locationVal = stVal1;
	stName.indexOf('menubar') != -1 ? menubarVal = stVal0 : menubarVal = stVal1;
	stName.indexOf('resizable') != -1 ? resizableVal = stVal0 : resizableVal = stVal1;
	winStatus =
		'directories=' + directoriesVal +
		',status=' + statusVal +
		',scrollbars=' + scrollbarsVal +
		',toolbar=' + toolbarVal +
		',location=' + locationVal +
		',menubar=' + menubarVal +
		',resizable=' + resizableVal + 
		',top=0' + 
		',left=0';

// Window width & height adjust
	if (setW + setH > 0) {
		//Status : YES
		if (statusVal == 1) {
			//IE4 for Mac
			if (gPlf == 'MAC'  && gBrw == 'IE' && gVer == 4) {
				setH += 16;
			}
		}
		//Scroll : YES
		if (scrollbarsVal == 1) {
			//IE4 for Mac
			if (gPlf == 'MAC'  && gBrw == 'IE' && gVer == 4) {
				setW -= 1;
			}
			//NN4 for Mac
			if (gPlf == 'MAC' && gBrw == 'NN' && gVer == 4) {
				setW += 15;
			}
			//IE5 for Win
			else if (gPlf == 'WIN' && gBrw == 'IE' && gVer >= 4) {
				setW += 16;
			}
		}
		//Location : YES
		if (locationVal == 1) {
			//IE4 for Mac
			if (gPlf == 'MAC'  && gBrw == 'IE' && gVer == 4) {
				setH += 24;
			}
		}
		//Menu : YES
		if (menubarVal == 1) {
			//IE4 for Mac
			if (gPlf == 'WIN' && gBrw == 'IE' && gVer >= 4) {
				setH -= 19;
			}
		}
	}

	if (h != 0) {
		winSize = 'width=' + setW;
	}
	else if (w != 0) {
		winSize = 'height' + setH;
	}
	if (w != 0 && h != 0) {
		winSize = 'width=' + setW + ',height=' + setH;
	}
	if (setW + setH > 0) {
		winValue = winStatus + ',' + winSize;
	}
	else {
		winValue = winStauts;
	}
	winOpen = window.open(uri,winName,winValue);
}

//::::Get Window Open
/*---
Return value of 'flag'...
+ 0 = Parent window close (No window object)
+ 1 = Parent window open (Be window object)
+ 2 = Parent window close (Be window object)
+ default flag = 0
---*/
function isOpener() {
	var flag = 0;
	var ua = navigator.userAgent;
	// Check Window Object
	if (!!window.opener) {
		// Check Parent Window
		if ( ua.indexOf('MSIE 4') != -1 && ua.indexOf('Win') != -1) {
			if (!window.opener.closed) {
				flag = 1;
			}
			else {
				flag = 2;
			}
		}
		else {
			if (typeof window.opener.document  == 'object') {
				flag = 1;
			}
			else {
				flag = 2;
			}
		}
	}
	else {
		flag = 0;
	}
	return flag;
}


//::::Get Window Scroll Point [2001.12.22 modify]
/*---
Argument...
+ winName = Window Name (Frame window name)
---*/
function getWinOffset(winName) {
	var winObj, t, w, offset;
	if (!winName) {
		winObj = window;
	}
	else {
		winObj = parent.frames[winName];
	}
	if (document.all) {
		w = winObj.document.body.scrollLeft;
		t = winObj.document.body.scrollTop;
	}
	else if (document.layers || document.getElementById) {
		w = winObj.pageXOffset;
		t = winObj.pageYOffset;
	}
	offset = w + "-" + t;
	return offset.split("-");
}


//::::Get Window Size [2002.5.9 modify]
/*---
Argument...
+ which = 'width' or 'height'
+ 'width' = When get window width size
+ 'height' = When get window height size
---*/
function getWinSize(which) {
	var size;
	if (which == "width") {
		if (document.all) {
			size = parseInt(document.body.clientWidth);
		}
		else if (document.layers) {
			size = parseInt(window.innerWidth);
		}
		else if (document.getElementById) {
			size = parseInt(window.innerWidth);
		}
	}
	else if (which == "height") {
		if (document.all) {
			size = parseInt(document.body.clientHeight);
		}
		else if (document.layers) {
			size = parseInt(window.innerHeight);
		}
		else if (document.getElementById) {
			size = parseInt(window.innerHeight);
		}
	}
	return size;
}


//::::Reload At The Time Of Resizing
function resizeHandle(){
	rflag = !(document.layers && parseFloat(navigator.appVersion) < 4.5 && document.height > window.innerHeight);
	window.onresize = new Function("if (rflag) { location.reload() } else { rflag = true }");
}
