﻿//==========================================================
// GAM-22のメモ
// http://gmr.blog.shinobi.jp/
//==========================================================

	var root = 'http://file.gmr.blog.shinobi.jp/';

//----------------------------------------------------------
// 動画検索窓 http://gmr.blog.shinobi.jp/Entry/510/
//----------------------------------------------------------
	function VideoSearch(from, action) {
		location.href = action.replace("word",from.parentNode.parentNode.search.value);
		return;
	}

//----------------------------------------------------------
// YouTube変換 http://gmr.blog.shinobi.jp/Entry/455/
//----------------------------------------------------------
	function YouTubeConvert(from) {
		document.getElementById("view").innerHTML = from.text.value;
		var e = document.getElementById('view').getElementsByTagName('object')[0].getElementsByTagName('embed')[0];
		var src = e.getAttribute('src').replace(/&/g, '&amp;'), width = e.getAttribute('width'), height = e.getAttribute('height');
		from.text.value = '<object data="' + src + '" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '"><param name="movie" value="' + src +'" /><param name="wmode" value="transparent" />YouTube</object>';
		return;
	}
	function YouTubeConvertSelect(from) {
		from.form.search.value = from.value;
		from.form.search.className = from.form.search.className.replace(/ondes/, '');
	}

//----------------------------------------------------------
// TEXTAREA や INPUT の初期値をクリックで消す
// http://gmr.blog.shinobi.jp/Entry/527/
//----------------------------------------------------------

/*

	名称が思い浮かばない、ClearDefaultValue とか長すぎる。
	なぜか「説明」という意味の、Description を略して、Des になった。
*/

	function setupDes() {
		// 種付け作業
		var textarea = document.getElementsByTagName('textarea');
		for (i = 0; i < textarea.length; i++) {
			if (textarea[i].className.search("nodes") < 0) {
				if (textarea[i].value == textarea[i].defaultValue) {textarea[i].className += " ondes"; }
				textarea[i].onfocus = function() {offDes(this); }
				textarea[i].onblur = function() {onDes(this); }
			}
		}
		var input = document.getElementsByTagName('input');
		for (i = 0; i < input.length; i++) {
			if ((input[i].className.search("nodes") < 0) && ((input[i].getAttribute("type") == "text")||(input[i].getAttribute("type") == null))) {
				if (input[i].value == input[i].defaultValue) {input[i].className += " ondes"; }
				input[i].onfocus = function() {offDes(this); }
				input[i].onblur = function() {onDes(this); }
			}
		}
		return;
	}

	function offDes(from) {
		if (from.className.search("ondes") < 0) {return 0;}
		from.className = from.className.replace(/ondes/, "");
		from.value = "";
		return 1;
	}
	function onDes(from) {
		if (from.value != "") {return 0;}
		from.className += " ondes";
		from.value = from.defaultValue;
		return 1;
	}

	function subDes(from) {
		var textarea = from.getElementsByTagName('textarea');
		for (i = 0; i < textarea.length; i++) {
			if (textarea[i].className.search('ondes') >= 0) {
				alert("未入力項目があります。");
				return false;
			}
		}
		var input = from.getElementsByTagName('input');
		for (i = 0; i < input.length; i++) {
			if (input[i].className.search('ondes') >= 0) {
				alert("未入力項目があります。");
				return false;
			}
		}
		return ture;
	}

//----------------------------------------------------------
// 13日の金曜日を計算 
// http://gmr.blog.shinobi.jp/Entry/546/
//----------------------------------------------------------

	function Fri13(from) {
 		var date = new Date(from.form.since.value, 1, 13);
 		var list="";
		for (i = 0; i < from.form.max.value*12; i++) {
			if (date.getDay()==5){
				list += "<li>" + date.getFullYear() + "/" + (date.getMonth()+1) + "/13 (Fri)</li>\n";
			}
			date.setMonth(date.getMonth()+1);
		}
		document.getElementById("fri13").innerHTML = list;
		return;
	}