/*
* Filename	: common.js
* Function	:
* Comment		:
* History		: 2003/05/09, jerry, setup
*						
* Version		:	1.0
* Author		:	Copyright (c) 2005 by JC Square Inc. All Rights Reserved.
*/

//var IE = document.all;
var IE = navigator.appName.toUpperCase().indexOf("MICROSOFT") > -1 ? true : false;
var NS = navigator.appName.toUpperCase().indexOf("NETSCAPE") > -1 ? true : false;
var NS4 = document.layers;
var NS6 = !IE && document.getElementById != null ? true : false;
var doc = (IE ? document.all : document);

/* open window */
function __openWindow(url, popupName, scrollFlag, resizeFlag, width, height, left, top) {
	popupName = popupName == null ? "popup" : popupName;
	scrollFlag = scrollFlag == null ? "no" : scrollFlag;
	resizeFlag = resizeFlag == null ? "no" : resizeFlag;
	width = width == null ? 300 : width;
	height = height == null ? 300 : height;
	left = left == null ? 50 : left;
	top = top == null ? 50 : top;
	
	window.open(url, popupName, "scrollbars=" + scrollFlag + ", resizable=" + resizeFlag + ", width=" + width + ", height=" + height + ", left=" + left + ", top=" + top + ", status=no");
}

function openWindow(url, width, height, popupName) {
	__openWindow(url, popupName, "no", "yes", width, height);
}

function openWindowFixed(url, width, height, popupName) {
	__openWindow(url, popupName, "no", "no", width, height);
}

function openWindowScroll(url, width, height, popupName) {
	__openWindow(url, popupName, "yes", "yes", width, height);
}

function openWindowPos(url, width, height, popupName, left, top) {
	__openWindow(url, popupName, "no", "yes", width, height, left, top);
}

function openWindowFixedPos(url, width, height, popupName, left, top) {
	__openWindow(url, popupName, "no", "no", width, height, left, top);
}

function openWindowScrollPos(url, width, height, popupName, left, top) {
	__openWindow(url, popupName, "yes", "yes", width, height, left, top);
}

/* get IE version */
function getIEVersion() {
	var IEVersion = 0;
//var browserName = navigator.appName;
	var idx = navigator.appVersion.indexOf("MSIE");

	if (idx > -1) {IEVersion = parseFloat(navigator.appVersion.substr(idx + 4));}

	return IEVersion;
}

/* get object */
function getObjectByName(objName) {
	var obj = null;
	if (IE) {obj = document.all[objName];}
	else {obj = document.getElementById(objName);}
	return obj;
}

/* make array SET(eliminate duplication) */
function makeSet(array){
	var arrayLength = array.length;
	var ary = new Array();
	var size = 0;
	ary[0] = array[0];
	var unique = true;
	for (i = 0; i < arrayLength; i++) {
		unique = true;
		size = ary.length;
		for (j = 0; j < size; j++){
			if (array[i] == ary[j]) {
				unique = false;
				break;
			}
		}
		if(unique){ary[size] = array[i];}
	}
	return ary;
}

/* Merge two Array (concatenate two array)*/
function mergeArray(iArray, jArray){
	var iSize = iArray.length;
	var jSize = jArray.length;
	var mArray = new Array();
	var mSize = 0;
	var unique = true;
	
	mArray[0] = iArray[0];
	for (i = 0; i < iSize; i++) {
		mSize = mArray.length;
		mArray[mSize] = iArray[i];
	}
	
	for (j = 0; j < jSize; j++){
		mSize = mArray.length;
		mArray[mSize] = jArray[j];
	}
	var nArray = makeSet(mArray);
	
	return nArray;
}

/* Array to String with seperator */
function arrayToString(array, sep){
	var size = array.length;
	var str = "";
	for (i = 0; i < size; i++) {
		if (array[i].length > 0) {str = str+array[i]+sep;}
	}
	return str;
}
