/* ------------------------------------------------------------

	Colorful Board System JavaScript Library
		Programed by ミライいろ。
		Added by Lightning
			http://maruamyu.net/

------------------------------------------------------------ */

/* くっきー保存期間 */
var cookieHold = 30 *24*60*60*1000;

/* ---------------------------------------------------------------------- */
/* くっきーをもらってフォームに入れる */

function getCookie()
{
	var i,j,myCookie,getName,getMail,getColor;
	
	myCookie = document.cookie+';';
	getName = unescape(name2value(myCookie,'NAME'));
	getMail = unescape(name2value(myCookie,'MAIL'));
	getColor = unescape(name2value(myCookie,'COLOR'));
	getIcon = unescape(name2value(myCookie,'ICON'));
	
	for(i=0; i<document.forms.length; i++){
		if(document.forms[i].FROM && document.forms[i].mail){
			document.forms[i].FROM.value = getName;
			document.forms[i].mail.value = getMail;
		}
		
		if(document.forms[i].color){
			for(j=0; j<document.forms[i].color.options.length; j++){
				if(document.forms[i].color.options[j].value == getColor){
					document.forms[i].color.selectedIndex = j;
					break;
				}
			}
		}

		if(document.forms[i].icon){
			for(j=0; j<document.forms[i].icon.options.length; j++){
				if(document.forms[i].icon.options[j].value == getIcon){
					document.forms[i].icon.selectedIndex = j;
					break;
				}
			}
		}
	}
}

/* ---------------------------------------------------------------------- */
/* 名前をキーにして 名前=値 の値を返す */

function name2value(inStr,inName)
{
	var start,end;
	
	start = inStr.indexOf(inName+'=');
	if(start != -1){
		end = inStr.indexOf(';',start);
		return(inStr.substring(start+inName.length+1,end));
	}
	return('');
}

/* ---------------------------------------------------------------------- */
/* フォーム送信時の操作 */

function submitForm(fParam)
{
	var getName,getMail,getColor;
	
	if(fParam.MESSAGE.value === ''){
		alert('本文が入力されていません！');
		fParam.MESSAGE.focus();
		return false;
	}
	
	if(!(confirm('この内容で書き込みますか？'))){return false;}
	
	getName = fParam.FROM.value;
	getMail = fParam.mail.value;
	
	setCookie('NAME',escape(getName));
	setCookie('MAIL',escape(getMail));
	
	if(fParam.color){
		getColor = fParam.color.options[fParam.color.selectedIndex].value;
		setCookie('COLOR',escape(getColor));
	}
	if(fParam.icon){
		getIcon = fParam.icon.options[fParam.icon.selectedIndex].value;
		setCookie('ICON',escape(getIcon));
	}
	
	return true;
}

/* ---------------------------------------------------------------------- */
/* くっきーを食べさせる */

function setCookie(inName,inValue)
{
	var today,forTime,forCookie,forPath,pos;
	
	forPath = location.pathname;
	pos = forPath.indexOf('test/read.cgi');
	if(pos > -1){forPath = forPath.substring(0,pos);}
	else{
		pos = forPath.lastIndexOf('/');
		pos = forPath.lastIndexOf('/',(pos - 1));
		forPath = forPath.substring(0,pos) + '/';
	}
	
	today = new Date();
	today.setTime(today.getTime() + cookieHold);
	
	forTime = today.toGMTString();
	forCookie = ''+inName+'='+inValue+'; expires='+forTime+'; path='+forPath;
	
	document.cookie = forCookie;
}

/* ---------------------------------------------------------------------- */
