// Java Objects Script
/*************************************************************************************
*	Date Arrays 　　著作権：ナック･ウェブ
*************************************************************************************/
monthNames = new Array(12);
monthNames[0] = "1月";
monthNames[1] = "2月";
monthNames[2] = "3月";
monthNames[3] = "4月";
monthNames[4] = "5月";
monthNames[5] = "6月";
monthNames[6] = "7月";
monthNames[7] = "8月";
monthNames[8] = "9月";
monthNames[9] = "10月";
monthNames[10] = "11月";
monthNames[11] = "12月";

dayNames = new Array(7);
dayNames[0] = "日曜日";
dayNames[1] = "月曜日";
dayNames[2] = "火曜日";
dayNames[3] = "水曜日";
dayNames[4] = "木曜日";
dayNames[5] = "金曜日";
dayNames[6] = "土曜日";

/************************************************************************************/
function formatFullDateTime(aDate) {
	var theDay = dayNames[aDate.getDay()];
	var theMonth = monthNames[aDate.getMonth()];
	var theYear = aDate.getYear();
	var theHour = aDate.getHours();
	var theMinute = aDate.getMinutes();
	if (theHour > 12) {
		var theAMPM = "PM";
		theHour = theHour - 12;
	} else {
		if (theHour == 12) {
			var theAMPM = "PM";
		} else {
			var theAMPM = "AM";
		}
	}
	if (theMinute < 10) {
		theMinute = "0" + theMinute
	}
	theYear += (theYear < 100 || is_ns) ? 1900 : 0;
/*	return theDay + ", " + theMonth + " " + aDate.getDate() + ", " + theYear + "&nbsp;&nbsp;&nbsp;" + theHour + ":" + theMinute + " " + theAMPM */
	return theYear + "年 " + theMonth + " " + aDate.getDate() + "日( " + theDay + ") " + "&nbsp;&nbsp;&nbsp;" + theHour + ":" + theMinute + " " + theAMPM

}

/************************************************************************************/
var agt		= navigator.userAgent.toLowerCase(); // convert all characters to lowercase to simplify testing 
var version		= parseInt(navigator.appVersion);

var is_ns		= ((agt.indexOf('mozilla') != -1) && (agt.indexOf('spoofer') == -1) 
               	&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera') == -1) 
               	&& (agt.indexOf('webtv') == -1));

var is_ns4		= (is_ns && (version == 4));
var is_ns4up	= (is_ns && (version >= 4));
var is_ns5		= (is_ns && (version == 5));
var is_ns5up	= (is_ns && (version >= 5));

var is_ie		= (agt.indexOf("msie") != -1);
var is_ie5		= (is_ie && (version == 4) && (agt.indexOf("msie 5.0")!=-1) ); 
var is_ie5_5  	= (is_ie && (version == 4) && (agt.indexOf("msie 5.5") !=-1));

var is_opera = (agt.indexOf("opera") != -1);

var is_getElementById   = (document.getElementById) ? "true" : "false";
var is_tabCapable = is_ie && is_getElementById; // tabs allowed for late IE only

/************************************************************************************/
function SaveMinMax(level) {
	var PortList = document.portList.portlet_lst.value;
   	var PortNames = PortList.split(",");
   	var NameValuePairs = "";
   	
	for (var i = 0; i < PortNames.length; i++) {
    	var CookieName = PortNames[i] + "State";
  		if (NameValuePairs != "") { 
			NameValuePairs += "&"; 
		}
  		NameValuePairs += PortNames[i] + "=" + getCookie(CookieName);
  	}
	
	if (level == "root") {
		window.location = "EditMinMax.asp?" + NameValuePairs;
	}
	else if (level == "sub") {
		window.location = "../EditMinMax.asp?" + NameValuePairs;
	}
	return;
}

/************************************************************************************/
function setCookie(name, value, path, domain) {
  var cookie = name + "=" + escape(value) +
  		((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "")
  document.cookie = cookie;
}

/************************************************************************************/
function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
  	if (begin == -1) {
    	begin = dc.indexOf(prefix);
   		if (begin != 0) {
			return null;
		}
  	} 
  	else {
    	begin += 2;
	}
	var end = dc.indexOf(";", begin);
	if (end == -1) {
		end = dc.length;
	}
	return unescape(dc.substring(begin + prefix.length, end));
}

/************************************************************************************/
function deleteCookie(name, path, domain) {
	//to delete a cookie you must set expires to be a date in the past
	var expire = new Date();
	expire.setTime(expire.getTime() - 24 * 60 * 60 * 1000);
	
	if (getCookie(name)) {
    	document.cookie = name + "=" + 
	    ((path) ? "; path=" + path : "") +
	    ((domain) ? "; domain=" + domain : "") +
	    "; expires=" + expire;
	}
}

/************************************************************************************/
function setPortlets(portlets, minmax) {
	if (portlets == "") {
		return true;
	}
	if (is_getElementById) {
		// create arrays from the two params passed in from xml
		var divs = portlets.split(",");
		var states = minmax.split(",");

		for (var i = 0; i < divs.length; i++) {
			var imgName = divs[i] + "MinBtn";
			var divName = divs[i];
			var divState = states[i];
			var cookieStateName = divs[i] + "State";
		
			if (getCookie(cookieStateName) == null) { // cookie does not exist yet
				if (divState == "minimize") { // if portlet has been saved as minimized in xml
					if (document[imgName] != null) {
						document[imgName].src = 'images/portlet_maximize_btn.gif';
						document.getElementById(divName).style.display = 'none';
						setCookie(cookieStateName,'minimize');
					}
				} 
				else {
					if (document[imgName] != null) {
						document[imgName].src = 'images/portlet_minimize_btn.gif';
						document.getElementById(divName).style.display = '';
					}
				}			
			}
			else if (getCookie(cookieStateName) == "minimize") {
				if (document[imgName] != null) {
					document[imgName].src = 'images/portlet_maximize_btn.gif';
					document.getElementById(divName).style.display = 'none';
				}
			}
			else if (getCookie(cookieStateName) == "maximize") {
				if (document[imgName] != null) {
					document[imgName].src = 'images/portlet_minimize_btn.gif';
					document.getElementById(divName).style.display = '';
				}
			}
		}
	}
}

/************************************************************************************/
function setPortletsEx(portlets, minmax) {
	if (portlets == "") {
		return true;
	}
	if (is_getElementById) {
		// create arrays from the two params passed in from xml
		var divs = portlets.split(",");
		var states = minmax.split(",");

		for (var i = 0; i < divs.length; i++) {
			var spanName = "MinMaxSpan_" + divs[i]; //spans for min/max button text
			var divName = divs[i]; //divs for each portlet's main content which is made hidden or visible
			var divState = states[i];
			var cookieStateName = divs[i] + "State";
		
			if (getCookie(cookieStateName) == null) { // cookie does not exist yet
				if (divState == "minimize") { // if portlet has been saved as minimized in xml
					document.getElementById(spanName).innerHTML = '+';
					document.getElementById(divName).style.display = 'none';
					setCookie(cookieStateName,'minimize');
				} 
				else {
					document.getElementById(spanName).innerHTML = document.frmMinMax.hidMinMaxValue.value;
					document.getElementById(divName).style.display = '';
				}			
			}
			else if (getCookie(cookieStateName) == "minimize") {
				document.getElementById(spanName).innerHTML = '+';
				document.getElementById(divName).style.display = 'none';
			}
			else if (getCookie(cookieStateName) == "maximize") {
				document.getElementById(spanName).innerHTML = document.frmMinMax.hidMinMaxValue.value;
				document.getElementById(divName).style.display = '';
			}
		}
	}
}

function MinMax(portlet) {
	var divName = portlet;
	var imgName = portlet + "MinBtn";
	var cookieStateName = portlet + "State";
	
	// portlet is hidden, so restore it
	if (document.getElementById(divName).style.display == 'none') {
		document[imgName].src = 'images/portlet_minimize_btn.gif';
		document.getElementById(divName).style.display = '';
		setCookie(cookieStateName,'maximize');
	}
	// portlet is maximized, so minimize it
	else { 
		document[imgName].src = 'images/portlet_maximize_btn.gif';
		document.getElementById(divName).style.display = 'none';
		setCookie(cookieStateName,'minimize');
	}
}

// extended MinMax function for new CSS buttons instead of images
function MinMaxEx(portlet) {
	var divName = portlet;
	var spanName = "MinMaxSpan_" + portlet;
	var cookieStateName = portlet + "State";
	
	// portlet is hidden, so restore it
	if (document.getElementById(divName).style.display == 'none') {
		// get value from HTML form field in myqualnet.asp since character entity value can't be used directly in JS
		document.getElementById(spanName).innerHTML = document.frmMinMax.hidMinMaxValue.value;
		document.getElementById(divName).style.display = '';
		setCookie(cookieStateName,'maximize');
	}
	// portlet is maximized, so minimize it
	else {
		document.getElementById(spanName).innerHTML = '+'
		document.getElementById(divName).style.display = 'none';
		setCookie(cookieStateName,'minimize');
	}
}

/************************************************************************************/
function OpenStrippedBrowserWindow(url, w, h, windowname) {
	var features =
		'width='        + w +
		',height='      + h +
		',directories=' + 0 +
		',location='    + "no" +
		',menubar='     + 0 +
		',scrollbars='  + "no" +
		',status='      + 0 +
		',toolbar='     + 0 +
		',Resizable='   + 0;

	OpenWindowWrapper(url, w, h, windowname, features);
}

/************************************************************************************/
function OpenWindow(url, w, h, windowname) {
	var features =
		'width='        + w +
		',height='      + h +
		',directories=' + 0 +
		',location='    + "no" +
		',menubar='     + 0 +
		',scrollbars='  + "yes" +
		',status='      + 0 +
		',toolbar='     + 0 +
		',Resizable='   + 1;

	OpenWindowWrapper(url, w, h, windowname, features);
}

/************************************************************************************/
function OpenFullBrowserWindow(url, w, h, windowname) {
	/* compensate for IE's rendering of width and height as the inner window dimensions 
	   when directories is set to 1 */
	if (is_ie) {
		h = (h + 170);
		w = (w + 20);
	}
	var features =
		'width='        + w +
		',height='		 + h +
		',height='	 	 + h +
		',directories=' + 1 +
		',location='    + "yes" +
		',menubar='     + 1 +
		',scrollbars='  + "yes" +
		',status='      + 1 +
		',toolbar='     + 1 +
		',Resizable='   + 1;

	OpenWindowWrapper(url, w, h, windowname, features);
}

/************************************************************************************/
var popUpWin = null;
function OpenWindowWrapper(url, w, h, windowname, features) {
	if (is_ie) {
		var pos_width = (screen.width / 2) - (w / 2);
		var pos_height = (screen.height / 2) - (h / 2);
		features += ',left=' + pos_width + ',top=' + pos_height;
	}
	
/* Debugging alert
	alert("User Agent: " + agt + "\n" +
			"Browser App Version: " + version + "\n" + 
			"Is Netscape: " + is_ns + "\n" + 
			"Is IE: " + is_ie + "\n" + 
			"Is IE5: " + is_ie5 + "\n" + 
			"Is IE5.5: " + is_ie5_5 + "\n");
*/
	
	// if windowname is blank, assume we want to keep same window for everything
	if (windowname == null || windowname == "") { 
		windowname = "MqntPopup";
		if (!popUpWin || popUpWin.closed) {
			popUpWin = window.open(url, windowname, features);
		}
		else {
			popUpWin.location = url;
			popUpWin.focus();
		}
	}
	// window has unique name, so spawn a new window
	else {
		window.open(url, windowname, features);
	}
}

/************************************************************************************/
function OpenNewBrowserWindow(url, w, h) {
	if (is_ie) {
		h = (h + 170);
		w = (w + 20);
	}

	var features =
		'width='        + w +
		',height='		 + h +
		',height='	 	 + h +
		',directories=' + 1 +
		',location='    + "yes" +
		',menubar='     + 1 +
		',scrollbars='  + "yes" +
		',status='      + 1 +
		',toolbar='     + 1 +
		',Resizable='   + 1;
	
	if (is_ie) {
		//center the popup window on user's screen
		var pos_width = (screen.width / 2) - (w / 2);
		var pos_height = (screen.height / 2) - (h / 2);
		features += ',left=' + pos_width + ',top=' + pos_height;
	}
	
	// create random window name so NS opens up diff browsers
	var WinName = new Date();
	WinName = Date.parse(WinName);

	window.open(url, WinName, features);
}

// changes cursor to specified type
function ChangeCursor(obj, type) {
	obj.style.cursor = type;
}

function OpenPortletEditPage(sURL) {
	OpenWindow(sURL, 750, 500, 'EditWin')
}

function IsNumeric(sVal) {
	var sValidChars = "0123456789";
	var sChar;
	var bResult = true;
	
	//  test sVal consists of valid characters listed above
	for (var i=0; i < sVal.length && bResult; i++) {
		sChar = sVal.charAt(i);
		if (sValidChars.indexOf(sChar) == -1) {
			bResult = false;
		}
	}
	return bResult;
}
/************************************************************************************/
function calender(){
	dat = new Date();
	da1 = dat.getYear();
	da2 = dat.getMonth();
	da3 = dat.getDate();
	da4 = dat.getDay();
	haikei = "#ffffff";		//背景色を指定する
	toujitu = "#ff6600";		//今日の日付色を指定する
	heijitu = "#000000";		//平日色を指定する
	poinnto = 2;			//表示文字サイズを指定する
	b_niti = "#ff0000";		//日曜日の文字色を指定する
	b_getu = "#336633";		//月〜金曜日の文字色を指定する
	b_doyo = "#000080";		//土曜日の文字色を指定する	

	to_iro = '<FONT SIZE=' + poinnto + ' color=' + toujitu + '>';
	he_iro = '<FONT SIZE=' + poinnto + ' color=' + heijitu + '>';
	hajime = '<TABLE cellpadding="1" cellspacing="0" border="0" bordercolor="#859ab1" bgcolor="' + haikei + '">';

	iro = '<TD>' + to_iro + da3 + '</FONT></TD>';
	tome = "</TR></TABLE>";
	tuki = da2 + 1;
	if (da1 < 2000){
		da1 = da1 + 1900;
	}
	niti = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	if (da1 % 4 == 0){
		niti[1] = 29;
	}
	kaisuu = niti[da2];

	ha = new Array();
	for (i = 1;i <= kaisuu;i++){
		ha[i] = "<TD>" + he_iro + i + "</TD>";
	}
	ha[da3] = iro;

	dat.setDate(1);
	tuitati = dat.getDay();

	mae = '<TR align="center">';
	for (y = 1;y <= tuitati;y++){
		mae = mae + "<TD></TD>";
	}
	for (k = 7 - tuitati;k <=kaisuu;k = k + 7){
		ha[k] = ha[k] + '</TR><TR align="center">';
	}

	hyouji = mae;
	for (j = 1;j <= kaisuu;j++){
		hyouji = hyouji + ha[j];
	}

	youbimoji = "<TR><TD><FONT SIZE=" + poinnto + " color=" + b_niti + ">日</TD><TD><FONT SIZE=" + poinnto + " color=" + b_getu + ">月</TD><TD><FONT SIZE=" + poinnto + " color=" + b_getu + ">火</TD><TD><FONT SIZE=" + poinnto + " color=" + b_getu + ">水</TD><TD><FONT SIZE=" + poinnto + " color=" + b_getu + ">木</TD><TD><FONT SIZE=" + poinnto + " color=" + b_getu + ">金</TD><TD><FONT SIZE=" + poinnto + " color=" + b_doyo + ">土</TD></TR>";
	saisyuu1 = hajime + "<TR align='center' bgcolor='#859ab1'><TD colspan='7'><B><FONT size=2 color= #FFFFFF>" + da1 + "年<FONT size=2>" + tuki + "<FONT size=2>月</B><BR></FONT></TD></TR>";
	saisyuu2 = youbimoji + hyouji + tome;
	document.write(saisyuu1);
	document.write(saisyuu2);
}
/************************************************************************************/
function IT_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.IT_p) d.IT_p=new Array();
    var i,j=d.IT_p.length,a=IT_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.IT_p[j]=new Image; d.IT_p[j++].src=a[i];}}
}
/************************************************************************************/
function IT_swapImgRestore() { //v3.0
  var i,x,a=document.IT_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
/************************************************************************************/
function IT_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=IT_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
/************************************************************************************/
function IT_swapImage() { //v3.0
  var i,j=0,x,a=IT_swapImage.arguments; document.IT_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=IT_findObj(a[i]))!=null){document.IT_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
/************************************************************************************/
function IT_ShowImage(lId1, x, y)
{
  x = x - 110; y = y + 110;
  var ob;ob=new Array;var lId;var lId;lId = "lay" + lId1;
  var appVer=parseInt(navigator.appVersion);
  var isNC=(document.layers && (appVer >= 4));
  var isIE=(document.all    && (appVer >= 4));
  if (navigator.appName == "Netscape")
  {
      w_str = "document." + lId;ob[lId] = eval(w_str);
      ob[lId].visibility = "show";
      ob[lId].bgColor = "white";
      ob[lId].pageX = x;
      ob[lId].pageY = y;
  } 
  if (isIE)
  {
      w_str = "document.all.item(\"" + lId + "\").style";ob[lId] = eval(w_str);
      ob[lId].visibility = "visible";
      ob[lId].pixelLeft = x;
      ob[lId].pixelTop  = y;
  }
}
/************************************************************************************/
function IT_HidnImage(lId2)
{
  var ob;ob=new Array;var lId;lId = "lay" + lId2;
  var appVer=parseInt(navigator.appVersion);
  var isNC=(document.layers && (appVer >= 4));
  var isIE=(document.all    && (appVer >= 4));
  if (navigator.appName == "Netscape")
  {
      w_str = "document." + lId;ob[lId] = eval(w_str);
      ob[lId].visibility = "hidn";
  }
  if (isIE)
  {
      w_str = "document.all.item(\"" + lId + "\").style";ob[lId] = eval(w_str);
      ob[lId].visibility = "hidden";
  }
}
/************************************************************************************/
function toggleLayer2(id){
  if (document.getElementById) {
      if (document.getElementById(id).style.visibility == "hidden") {
        document.getElementById(id).style.visibility = "visible";
      } else {
        document.getElementById(id).style.visibility = "hidden";
      }
  } else if (document.all) {
    if (document.all(id).style.visibility == "hidden") {
      document.all(id).style.visibility = "visible";
    } else {
      document.all(id).style.visibility = "hidden";
    }
  } else if (document.layers) {
    if (document.layers[id].visibility == "hide") {
      document.layers[id].visibility = "show";
    } else {
      document.layers[id].visibility = "hide";
    }
  } 
}
/************************************************************************************/
function showhide(id){
    if(document.getElementById){
      if(document.getElementById(id).style.display == "block")
        document.getElementById(id).style.display = "none";
      else
        document.getElementById(id).style.display = "block";
    }
}
/************************************************************************************/
function showhidexx (idstr) {
    obj = document.getElementById(idstr);
    if(obj.style.display == "none") obj.style.display = "block";
    else obj.style.display = "none";
}