
//----------------------------------------------------------------

function fCommonOnLoad() {
	// Menu
	fMenu();
	fTitle();
	
	// create event handle
	$('txtHelpSearch').onkeyup = fSearchKeyHookEnter;
	
	// ActiveHelp Fix
//	fLaySetFix();
//	fOpacity('divActiveHelp', 0.5);
	fOpacity('divHelp', 0.8);
	fOpacity('divHelpSub', 0.8);
	fOpacity('divBusy', 0);
//	$('divActiveHelp').style.visibility='visible';
//	$('divActiveHelp').innerHTML = 'SID:' + $F('gSSS') + ', RID:' + $F('gRRR') + ', page:' + $F('gPage') + ', mode:' + $F('gMode') + ', type:' + $F('gType') + ', key:' + $F('gKey');
	fLayBusyOff();
	
	return;
}

//----------------------------------------------------------------

function fLaySetFix() {
	fLayFix('divActiveHelp', 'leftBottom', 0, -40);
	return;
}

//----------------------------------------------------------------

function fMessage(vMessage) {
	var i;
	$('divMessage').innerHTML  = '<div id="divMessageTitle"><div class="set_headder">' + vMessage[0] + '</div><br /><br /></div>';
	$('divMessage').innerHTML += '<div id="divMessageItem">';
	for (i=1; i<vMessage.length; i++) {
		$('divMessage').innerHTML += '<div id="divMessageText' + i + '"><table border="0" cellspacing="0" cellpadding="0" class ="setbox"><tr><td>' + vMessage[i] + '</td></tr></table><div class="non"></div></div><br />';
	}
	$('divMessage').innerHTML += '</div></div><br /><br />';
	
	$('divMessage').style.display = 'inline';
	return;
}

function fMessageClear() {
	$('divMessage').style.display = 'none';
	$('divMessage').innerHTML = '';
	return;
}

//----------------------------------------------------------------

function fProgress(vProgress) {
	var i1;
	var i2;
	
	if (vProgress <= 100) {
		i1 = vProgress * 3;
		i2 = 300 - i1;
	}
	
	if (i1 + i2 == 300) {
		document.getElementById("tdProgress1").width = i1;
		document.getElementById("tdProgress2").width = i2;
	}
	
	return;
}

//----------------------------------------------------------------

function fConfirm() {
	$('divConfirm').style.display = 'inline';
	
	// create event handle
	document.onkeyup = fConfirmKeyHookEnter;
	
	return;
}

function fConfirmSubmit() {
	$('btnConfirm').disabled = true;
	fPageMove('top');
	return;
}

function fConfirmKeyHookEnter(vEvent) {
	vEvent = (vEvent) ? vEvent : ((window.event) ? event : null);
	if (vEvent) {
		if (vEvent.keyCode == 13) {
			fConfirmSubmit();
		}
	}
}

//----------------------------------------------------------------

function fPageMove(vPage, vMode, vType, vKey) {
	fLayBusyOn();
	$('gPage').value = vPage;
	$('gMode').value = vMode;
	$('gType').value = vType;
	$('gKey').value  = vKey;
	$('frmNas').submit();
	return;
}

//----------------------------------------------------------------

function fPageParam(vPage, vMode, vType, kKey) {
	var mDate = new Date();
	var vParam = 'gSSS=' + $F('gSSS') + '&gRRR=' + $F('gRRR') + '&gPage=' + vPage + '&gMode=' + vMode + '&gType=' + vType + '&gKey=' + kKey + '&gDummy=' + mDate.getTime();
	return vParam;
}

//----------------------------------------------------------------

function fCursorNormal(tThis) {
	tThis.style.cursor = 'auto';
//	tThis.style.color  = "000000";
}

function fCursorHand(tThis) {
	tThis.style.cursor = 'pointer';
//	tThis.style.cursor = 'hand';
//	tThis.style.color  = "FF0000";
}

function fCursorBusy(tThis) {
	tThis.style.cursor = 'wait';
//	tThis.style.color  = "000000";
}

//----------------------------------------------------------------

function fBackColorNormal(tThis) {
	tThis.style.bgColor = "#FFFFFF";
}

function fBackColorSelect(tThis) {
	tThis.style.bgColor = "#FFFFCC";
}

//----------------------------------------------------------------

function fJumpToTop() {
	scroll(0,0);
}

function fJumpToTail() {
	scroll(0,999999);
}

//----------------------------------------------------------------

function fLayBusyOn() {
	var oBusy = $('divBusy');
	var vHeight;
	
	// ブラウザ判定
	this.ie    = !!document.all;
	this.n4    = !!document.layers;
	this.w3c   = !!document.getElementById;
	this.ua    = navigator.userAgent;
	this.mac45 = ua.indexOf('MSIE 4.5; Mac_PowerPC') != -1;
	this.mac5  = ua.indexOf('MSIE5.0;Mac_PowerPC')   != -1;
	this.macie = ua.indexOf('Mac_PowerPC')  !=-1 && ie
	this.moz   = ua.indexOf('Gecko') !=-1;
	this.opr   = !!window.opera;
	
	// Operaは非対応
	if (this.opr) { return; }
	
	// ウインドウの高さを求める
	if (this.ie && !this.opr) {
//		vHeight = document.body.clientHeight;
		vHeight = document.body.scrollHeight;
	} else {
		vHeight = window.innerHeight;
	}
	
	// divBusyレイヤーの位置を変更
	oBusy.style.top  = "0px";
	oBusy.style.left = "0px";
	
	
	// divBusyレイヤーの高さを変更する
	oBusy.style.height = vHeight;
	oBusy.style.width  = "990px";
	
	// カーソル形状を変更
	oBusy.style.cursor = 'wait';
	
	// 背景色変更
	oBusy.style.bgColor = "#FFFFFF";
	
	// divBusyレイヤーを表示する
	oBusy.style.display = 'inline';
	
	return;
}

function fLayBusyOff() {
	var oBusy = $('divBusy');
	oBusy.style.height = '1px';
	oBusy.style.display = 'none';
	return;
}

//----------------------------------------------------------------

function fCommonInitFileSystem() {
	var vUrl = '/cgi-bin/sync.cgi';
	var vParam = fPageParam('utility', 'init', 'filesystem', 'undefined');
	
	var mAjax = new Ajax.Request(
		vUrl,
		{
			method: 'get',
			parameters: vParam,
			onComplete: _fCommonAjaxFakeRcv
		});
}

function fCommonInitNetwork() {
	var vUrl = '/cgi-bin/sync.cgi';
	var vParam = fPageParam('utility', 'init', 'network', 'undefined');
	
	var mAjax = new Ajax.Request(
		vUrl,
		{
			method: 'get',
			parameters: vParam,
			onComplete: _fCommonAjaxFakeRcv
		});
}

function fCommonInitSyslog() {
	var vUrl = '/cgi-bin/sync.cgi';
	var vParam = fPageParam('utility', 'init', 'syslog', 'undefined');
	
	var mAjax = new Ajax.Request(
		vUrl,
		{
			method: 'get',
			parameters: vParam,
			onComplete: _fCommonAjaxFakeRcv
		});
}

function fCommonInitHostname() {
	var vUrl = '/cgi-bin/sync.cgi';
	var vParam = fPageParam('utility', 'init', 'hostname', 'undefined');
	
	var mAjax = new Ajax.Request(
		vUrl,
		{
			method: 'get',
			parameters: vParam,
			onComplete: _fCommonAjaxFakeRcv
		});
}

function _fCommonAjaxFakeRcv(vRes) {
	return;
}

//----------------------------------------------------------------

function fCommonOpenNewWindow(vUrl) {
	var mDate = new Date();
	var w = window.open(vUrl, mDate.getTime(), "WIDTH=800,HEIGHT=600,SCROLLBARS=1,RESIZABLE=1,TOOLBAR=1,MENUBAR=1,LOCATION=1,STATUS=1");
	return;
}

//----------------------------------------------------------------

function fActiveHelp(vItem) {
	$('divActiveHelp').innerHTML = cActiveHelpMessage[vItem];
	return;
}

cActiveHelpMessage = {
	TopDate: '日付だよ',
	TopHostname: 'ほすとめいだよん',
	TopIp: 'あいぴーあどれすだよ',
	Clear: '&nbsp;'
};

//----------------------------------------------------------------

function fHelpGet() {
	var mDate  = new Date();
	var vUrl   = $F('gPage');
	var vParam = 'gDummy=' + mDate.getTime()
	
	if ( (vUrl == '') || ($F('gSSS') == '') ) { vUrl = 'auth'; }
	
	if (
		(vUrl == 'auth') ||
		(vUrl == 'backup') ||
		(vUrl == 'basic') ||
		(vUrl == 'disk') ||
		(vUrl == 'group') ||
		(vUrl == 'information')||
		(vUrl == 'maintenance') ||
		(vUrl == 'mediaserver') ||
		(vUrl == 'network') ||
		(vUrl == 'printserver') ||
		(vUrl == 'share') ||
		(vUrl == 'top') ||
		(vUrl == 'user') 
	) {
		vUrl = '/help/en/' + vUrl + '.html';
	}
	else {
		vUrl = '/modules/' + vUrl + '/www/help/en/' + vUrl + '.html';
	}
	
	new Ajax.Updater('divHelpContent', vUrl, { method:'get', parameters:vParam });
	return;
}

//----------------------------------------------------------------

function fHelpSearch() {
	if ($F('txtHelpSearch') == '') {
		return;
	}
	
	var vUrl   = '/cgi-bin/search.cgi';
	var vParam = 'phrase=' + encodeURIComponent($F('txtHelpSearch')) + '&perpage=5&attr=&order=&clip=-1';
	
	var mAjax = new Ajax.Request(
		vUrl,
		{
			method: 'get',
			parameters: vParam,
			onComplete: _fHelpSearchRcv
		});
}

function _fHelpSearchRcv(vRes) {
	var regNotFound = /Your search did not match any documents./;
	
	if (vRes.responseText.search(regNotFound) != -1) {
		$('divHelpContent').innerHTML = '<div class="estresult" id="estresult"><p class="note">Your search did not match any documents.</p></div>';
	}
	else {
		$('divHelpContent').innerHTML = vRes.responseText;
	}
	return;
}

///cgi-bin/search.cgi?phrase=%E3%83%90%E3%83%83%E3%82%AF%E3%82%A2%E3%83%83%E3%83%97&perpage=5&attr=&order=&clip=-1


function fSearchKeyHookEnter(vEvent) {
	vEvent = (vEvent) ? vEvent : ((window.event) ? event : null);
	if (vEvent) {
		if (vEvent.keyCode == 13) {
			fHelpSearch();
		}
	}
}

//----------------------------------------------------------------

function fHelpContent(vItem) {
	var url   = '/cgi-bin/sync.cgi';
	var param = 'page=help&mode=' + vItem;
	new Ajax.Updater('divHelpContent', url, { method:'get', parameters:param});
	return;
}

//----------------------------------------------------------------

function fOpacity(vLay, vValue) {
	// Opera
	if (window.opera) { return; }
	
	var ua = navigator.userAgent;
	
	// Safari & KHTML
	if (ua.indexOf('Safari') != -1 || ua.indexOf('KHTML') != -1) {
		document.getElementById(vLay).style.opacity = vValue;
	}
	// Win IE4-IE6
	else if (document.all) {
		document.all(vLay).style.filter = "alpha(opacity=0)";
		document.all(vLay).filters.alpha.Opacity = (vValue * 100);
	}
	// Gecko
	else if (ua.indexOf('Gecko') != -1) {
		document.getElementById(vLay).style.MozOpacity = vValue;
	}
	return;
}

//----------------------------------------------------------------

function fLayFix(vLayID, vPosition, vOffsetX, vOffsetY) {
	var mOffTop;
	var mOffLeft;
	var mX;
	var mY;
	
	// Init
	if (!window.fLayFix[vLayID]) {
		// ブラウザ判定
		this.ie    = !!document.all;
		this.n4    = !!document.layers;
		this.w3c   = !!document.getElementById;
		this.ua    = navigator.userAgent;
		this.mac45 = ua.indexOf('MSIE 4.5; Mac_PowerPC') != -1;
		this.mac5  = ua.indexOf('MSIE5.0;Mac_PowerPC')   != -1;
		this.macie = ua.indexOf('Mac_PowerPC')  !=-1 && ie
		this.moz   = ua.indexOf('Gecko') !=-1;
		this.opr   = !!window.opera;
		
		// mace4.5以外のIE
		if (this.ie && !(this.mac45)) {
			// onscroll,onresize毎に動作
			window.onscroll = window.onresize = fLaySetFix;
		}
		
		// N4
		if (this.n4) {
			window.onresize = function() { location.reload(); }
			window.fLayFix[vLayID] = true;
		}
	}
	
	vOffsetX = parseInt(vOffsetX, 10);
	vOffsetY = parseInt(vOffsetY, 10);
	
	if (vPosition == 'rightTop') {
		if (this.ie && !this.opr) {
			mOffLeft = vOffsetX + document.body.clientWidth;
			mOffTop  = vOffsetY;
		} else {
			mOffLeft = vOffsetX + window.innerWidth;
			mOffTop  = vOffsetY;
		}
	} else if (vPosition == 'rightBottom') {
		if (this.ie && !this.opr) {
			mOffLeft = vOffsetX + document.body.clientWidth;
			mOffTop  = vOffsetY + document.body.clientHeight;
		} else {
			mOffLeft = vOffsetX + window.innerWidth;
			mOffTop  = vOffsetY + window.innerHeight;
		}
	} else if (vPosition == 'leftBottom') {
		if (this.ie && !this.opr) {
			mOffLeft = vOffsetX;
			mOffTop  = vOffsetY + document.body.clientHeight;
		} else {
			mOffLeft = vOffsetX;
			mOffTop  = vOffsetY + window.innerHeight;
		}
	} else if (vPosition == 'center') {
		if (this.ie && !this.opr) {
			mOffLeft = vOffsetX + document.body.clientWidth / 2;
			mOffTop  = vOffsetY + document.body.clientHeight / 2;
		} else {
			mOffLeft = vOffsetX + window.innerWidth / 2;
			mOffTop  = vOffsetY + window.innerHeight / 2;
		}
	} else {
		mOffLeft = vOffsetX;
		mOffTop  = vOffsetY;
	}
	
	mOffLeft = parseInt(mOffLeft, 10);
	mOffTop  = parseInt(mOffTop,  10);
	
	if (document.all && !opr) {
		mX = mOffLeft + document.body.scrollLeft;
		mY = mOffTop  + document.body.scrollTop;
	} else {
		mX = mOffLeft + self.pageXOffset;
		mY = mOffTop  + self.pageYOffset;
		
		var mWidth = document.getElementById(vLayID).style.width;
		mWidth = mWidth.replace(/px/, "");
		
		if (self.innerWidth < mWidth) {
			mY = mY - 20;
		}
	}
	
	// Move layer
	if (document.getElementById) {
//		document.getElementById(vLayID).style.left = mX;
		document.getElementById(vLayID).style.top  = mY;
	} else if (document.all) { // IE4
//		document.all(vLayID).style.pixelLeft = mX;
		document.all(vLayID).style.pixelTop  = mY;
	} else if (document.layers) { // N4
		document.layers[vLayID].moveTo(mX, mY);
	}
	
	if (!(this.ie && !this.mac45) || this.opr) {
		clearTimeout(fLayFix[vLayID]);
		fLayFix[vLayID] = setTimeout("fLayFix('" + vLayID + "', '" + vPosition + "', '" + vOffsetX + "', '" + vOffsetY + "')", 100);
	}
	
	return;
}

//----------------------------------------------------------------
