// JavaScript Document
window.onload = function() {
	if(document.getElementById("cpopup")) {
			if(document.getElementById("cpopup").value != 'no') {
				detailSchedule();
			}
	}
	slideShow();
}

function delCheck(title, id) {
	document.getElementById("delCheck").innerHTML = '「' + title + '」<br />を削除します。よろしいですか？';
	document.delarticle.delid.value = id;
	centerAndMiddle('delCheckBox', 300, 50);
}

function closeFunc(dId) {
	document.getElementById(dId).style.visibility = "hidden";
}

function delCancel() {
	closeFunc('delCheckBox');
	return false;
}


//中央表示スクリプト
function centerAndMiddle(ID, W, H) {
	if(W == null || H == null) {
		if(document.getElementById(ID).width || document.getElementById(ID).height) {
			W = document.getElementById(ID).width;
			H = document.getElementById(ID).height;
		}else if(document.getElementById(ID).style.width || document.getElementById(ID).style.height) {
			W = document.getElementById(ID).style.width;
			H = document.getElementById(ID).style.height;
		}else {
			W = 0;
			H = 0;
		}
	}
	var windowWidth, windowHeight;
	//画面の大きさの取得
	if(document.documentElement.clientWidth == 0) {
		widowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}else {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}
	//スクロール量の取得
	if(document.documentElement.scrollTop == 0) {
		posX = document.body.scrollLeft;
		posY = document.body.scrollTop;
	}else {
		posX = document.documentElement.scrollLeft;
		posY = document.documentElement.scrollTop;
	}
	//表示座標の計算
	posX += (windowWidth - W) / 2;
	posY += (windowHeight - H) / 2;
	//表示
	if(document.all) {
		with(document.all(ID).style) {
			top = posY + 'px';
			left = posX + 'px';
			visibility = "visible";
		}
	}else if(document.layers) {
		document.layers[ID].moveTo(posX, posY);
	}else {
		with(document.getElementById(ID).style) {
			top = posY + 'px';
			left = posX + 'px';
			visibility = "visible";
		}
	}
}


function detailSchedule() {
	if(!document.getElementById || !document.getElementsByTagName) return;
	if(!document.getElementById("calendar")) return;
	popBox = document.createElement("span");
	popBox.setAttribute("id", "popupbox");
	popBox.style.position = "absolute";
	document.getElementsByTagName("body")[0].appendChild(popBox);
	days = document.getElementById("calendar").getElementsByTagName("td");
	for(i = 0; i < days.length; i++) {
		makeContents(days[i]);
	}
}

function makeContents(tObj) {
	var data = tObj.getAttribute("title");
	if(data == "") {
		var spans = new Array();
		spans = tObj.getElementsByTagName('span');
		for(t = 0; t < spans.length; t++) {
			if(spans[t].getAttribute('title')) {
				data = spans[t].getAttribute('title');
				spans[t].removeAttribute('title');
			}
		}
		if(data == "") {
			return;
		}
	}else {
		tObj.removeAttribute("title");
	}
	var popup = document.createElement("span");
	popup.className = "popup";
	popup.style.display = "block";
	var tops = document.createElement("span");
	tops.className = "top";
	tops.style.display = "block";
	tops.style.background = "url(./img/box_head.gif) no-repeat top left";
	if(tObj.firstChild.tagName == "a") {
		day = tObj.fiestChild.innerHTML;
	}else {
		day = tObj.firstChild.nodeValue;
	}
	var dayObj = document.createElement("span");
	dayObj.className = "ev_day";
	dayObj.innerHTML = document.getElementById("colHead").innerHTML + day + '日の予定';
	tops.appendChild(dayObj);
	var bodys = document.createElement("span");
	bodys.className = "inbody";
	bodys.style.display = "block";
	bodys.style.background = "url(./img/box_body.gif) repeat-y top left";
	var dayName = new String();
	var evName = new String();
	var detail = new String();
	if(data.indexOf(':::') >= 0) {
		var tips = new Array();
		tips  = data.split(':::');
		dayName = tips[0];
		evName = tips[1];
		detail = tips[2];
	}else if(data.length > 0) {
		dayName = data;
	}
	if(dayName.length > 0) {
		var dayNameObj = document.createElement("span");
		dayNameObj.className = "dayname";
		var inSpan = document.createElement("span");
		inSpan.innerHTML = dayName;
		dayNameObj.innerHTML = "( ";
		dayNameObj.appendChild(inSpan);
		dayNameObj.innerHTML += " )";
		bodys.appendChild(dayNameObj);
	}
	if(evName.length > 0) {
		var evHead = document.createElement("span");
		evHead.className = "ev_head";
		evHead.innerHTML = "▼ 予定名";
		bodys.appendChild(evHead);
		var evNameBody = document.createElement("span");
		evNameBody.className = "ev_body";
		evNameBody.innerHTML = evName;
		bodys.appendChild(evNameBody);
	}
	if(detail.length > 0) {
		var dHead = document.createElement("span");
		dHead.className = "d_head";
		dHead.innerHTML = "▼ 詳細";
		bodys.appendChild(dHead);
		var dBody = document.createElement("span");
		dBody.className = "d_body";
		dBody.innerHTML = detail;
		bodys.appendChild(dBody);
	}
	var bottoms = document.createElement("span");
	bottoms.className = "bottom";
	bottoms.style.display  = "block";
	bottoms.style.background = "url(./img/box_bottom.gif) no-repeat top left";
	bottoms.innerHTML = " ";
	popup.appendChild(tops);
	popup.appendChild(bodys);
	popup.appendChild(bottoms);
	tObj.popup = popup;
	tObj.onmouseover = showPopup;
	tObj.onmouseout = hidePopup;
	if(document.getElementById("cpopup").value == "popup") {
		tObj.onmousemove = Locate;
	}
}

function showPopup(e) {
	document.getElementById("popupbox").appendChild(this.popup);
	Locate(e);
}

function hidePopup(e) {
	var d = document.getElementById("popupbox");
	if(d.innerHTML.length > 0) {
		d.removeChild(d.firstChild);
	}
}

function Locate(e){
var posx=0,posy=0;
if(e==null) e=window.event;
if(e.pageX || e.pageY){
    posx=e.pageX; posy=e.pageY;
    }
else if(e.clientX || e.clientY){
    if(document.documentElement.scrollTop){
        posx=e.clientX+document.documentElement.scrollLeft;
        posy=e.clientY+document.documentElement.scrollTop;
        }
    else{
        posx=e.clientX+document.body.scrollLeft;
        posy=e.clientY+document.body.scrollTop;
        }
    }
document.getElementById("popupbox").style.top=(posy-25)+"px";
document.getElementById("popupbox").style.left=(posx+10)+"px";
}

//ユーザー名のチェック
function checkName() {
	if(document.changenameForm.username.value == "") {
		alert("ユーザー名が未入力です");
		return false;
	}else {
		return confirm("ユーザー名を変更してもよろしいですか？");
	}
}


//パスワードの照合
function checkPass() {
	if(document.changepassForm.pass.value =="" || document.changepassForm.checkpass.value == "") {
		alert("パスワードが未入力です");
		return false;
	}
	if(document.changepassForm.pass.value == document.changepassForm.checkpass.value) {
		return confirm('パスワードを変更してよろしいですか？');
	}else {
		alert('入力パスワードと確認用パスワードが一致していません。入力し直してください。');
		return false;
	}
}

//スライドショー
var slide = 0;
var op = 0;
var opd = 100;
function slideShow() {
	if(!document.getElementById("slideshow")) {
		return;
	}
	if(data[slide] == null) {
		slide = 0;
	}
	document.getElementById("slideshow").style.filter = "alpha(opacity=0)";
	document.getElementById("slideshow").setAttribute("src", data[slide]);
	document.getElementById("slideshow").width = width[slide];
	document.getElementById("slideshow").height = height[slide];
	document.getElementById("slidelink").setAttribute("href", hrefs[slide]);
	document.getElementById("slidelink").setAttribute("title", titles[slide]);
	opacity();
	slide++;
	setTimeout(slideShow, 8000);
	setTimeout(opacityd, 6000)
}

function opacity() {
	op += 5;
	if(op > 100) {
		op = 0;
		return;
	}
	document.getElementById("slideshow").style.filter = "alpha(opacity=" + op +")";
	setTimeout(opacity, 100);
}

function opacityd() {
	opd -= 5;
	if(opd < 0) {
		opd = 100;
		return;
	}
	document.getElementById("slideshow").style.filter = "alpha(opacity=" + opd +")";
	setTimeout(opacityd, 100);
}

//画像の削除確認
function imgDelCheck(flag) {
	if(flag == 1) {
		str = "参照ファイルのある画像を削除するとサイト内で画像が表示されなくなる等の不具合が発生する可能性が高いです。\n本当に削除しますか？";
	}else {
		str = "本当に削除しますか？";
	}
	return confirm(str);
}

