/*
* Filename	: common.js
* Function	:
* Comment	:
* History		: 2003/05/09, jerry, setup
*						
* Version	:	1.0
* Author		:	Copyright (c) 2005 by JcomTech Corp. All Rights Reserved.
*/

var IE = document.all;
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);
}

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;
}

/* We need sort Array */

// --------------------------- daily ------------------------------
function changeYear(year) {
	var form = document.tranMgr;
	form.year.value = year;
	form.submit();
}

function changeMonth(month) {
	var form = document.tranMgr;
	form.month.value = month;
	if (form.week != undefined) {
		form.week.value = "1";
	}
	if (form.day != undefined) {
		form.day.value = "1";
	}
	form.submit();
}

function reflectFront(url) {
	var form = document.tranMgr;

	if (confirm("ショップに適用しますか？"))	{
		form.reflect.value ="ok";
		form.action = url;
		form.submit();
	}
}

function regDaily(day, val) {
	var form = document.tranMgr;
	form.day.value = day;
	form.dailyKey.value = val;
	form.action = "../schedule/reg.html";
	form.submit();
}

function gotoDaily(day, val) {
	var form = document.tranMgr;
	form.day.value = day;
	form.action = "../schedule/" + val + "_daily.html";
	form.submit();
}

function gotoWeekly(week) {
	var form = document.tranMgr;
	form.week.value = week;
	form.submit();
}

function __changeMonth(form, month) {
	form.month.value = month;
	form.submit();
}

function transMonthly(url) {
	var form = document.tranMgr;
	form.action = url;
	form.submit();
}

function transWeekly(url) {
	var form = document.tranMgr;
	form.action = url;
	form.submit();
}

function transDaily(url) {
	var form = document.tranMgr;
	form.action = url;
	form.submit();
}

function gotoReUrl(val) {
	var form = document.tranMgr;
	form.action = val
	form.submit();
}

function getColor(objname){
	var oldcolor = document.all[objname].value;
	var newcolor = showModalDialog("/script/editor/popups/select_color.html", oldcolor, "resizable: no; help: no; status: no; scroll: no;");

	if (newcolor != null) document.all[objname].value = "#"+newcolor;
}


// --------------------------- viewMemDetail ------------------------------
function viewMemDetail(memKey, type){
	var url = "../common/popup_mem_"+type+".jsp?memKey="+memKey;

	openWindowScrollPos(url, 690, 620, 'memDetail', 10, 10);
}

function viewComDetail(compKey, type){
	var url = "../common/popup_com_"+type+".jsp?compKey="+compKey;

	openWindowScrollPos(url, 690, 580, 'comDetail', 10, 10);
}

function viewAgntDetail(agntKey, type){
	var url = "../common/popup_agnt_"+type+".jsp?agntKey="+agntKey;

	openWindowScrollPos(url, 690, 580, 'agntDetail', 10, 10);
}

function viewPartnerDetail(partnerKey, type){
	var url = "../common/popup_partner_"+type+".jsp?partnerKey="+partnerKey;

	openWindowScrollPos(url, 690, 580, 'partnerDetail', 10, 10);
}

// --------------------------- viewMeritDetail ------------------------------
function viewMeritDetail(val, val2, sPayYear, sPayMonth, type){
	var url = "../common/popup_merit_"+type+".jsp?valKey="+val+"&valKey2="+val2+"&sPayYear="+sPayYear+"&sPayMonth="+sPayMonth;

	openWindowScrollPos(url, 890, 580, 'meritDetail', 10, 10);
}

/** Object tag write **/
function writeFlash(flashSrc, wd, ht, paramStr) {
	var objStr = "";
	objStr += "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' width='" + wd + "' height='" + ht + "'>";
	if (paramStr != null && paramStr.length > 0) {
		objStr += paramStr;
	}
	objStr += "	 <param name='movie' value='" + flashSrc + "'>";
	objStr += "	 <param name='quality' value='high'>";
	objStr += "	 <embed src='" + flashSrc + "' quality='high' pluginspage='https://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='" + wd + "' height='" + ht + "'></embed>";
	objStr += "	</object>";

	document.write(objStr);
}


function showOptions(cont) {
	if (eval("document.all."+cont+".style.display == 'none'")) {
		eval("document.all."+cont+".style.display = ''");
	} else {
		eval("document.all."+cont+".style.display = 'none'");
	}
}