function isSpace(str) {
	var i;

	for(i = 0; i < str.length; i++) {
		if (str.charAt(i) != ' ' && str.charAt(i) != '　') return false;
	}
	return true;
}

function isNumber(str, point) {
	if (point) {
		if (str.match(/^[0-9\.]+$/)) return true;
	} else {
		if (str.match(/^[0-9]+$/)) return true;
	}
	return false;
}

function isTelNum(str) {
	if (str.match(/^[0-9-]+$/)) return true;
	return false;
}

function isURL(str) {
	var tmp, ary;

	if (str.toLowerCase().substr(0, 7) == 'http://') {
		tmp = str.substr(7);
	} else if (str.toLowerCase().substr(0, 8) == 'https://') {
		tmp = str.substr(8);
	} else {
		tmp = str;
	}
	if (tmp.indexOf('/') >= 0) {
		ary = tmp.split('/');
		tmp = ary[0];
	} else if (tmp.indexOf('?') >= 0) {
		ary = tmp.split('?');
		tmp = ary[0];
	} else {
		tmp = tmp;
	}
	if (tmp.match(/^[\w\.-]+\.\w{2,}$/)) return true;
	return false;
}

function isEmail(str) {
	if (str.match(/^[\w_\.-]+@[\w\.-]+\.\w{2,}$/)) return true;
	return false; 
}

function isCmail(str) {
	cmail = str.toLowerCase();
	len = cmail.length;
	if (cmail.substr(len - 12) == "docomo.ne.jp") return true;
	if (cmail.substr(len - 11) == "ezweb.ne.jp") return true;
	if (cmail.substr(len - 14) == "softbank.ne.jp") return true;
	if (cmail.substr(len - 11) == "softbank.jp") return true;
	if (cmail.substr(len - 14) == "vodafone.ne.jp") return true;
	if (cmail.substr(len - 9) == "pdx.ne.jp") return true;
	if (cmail.substr(len - 8) == "wm.dx.jp") return true;
	if (cmail.substr(len - 12) == "wm.pdx.ne.jp") return true;
	if (cmail.substr(len - 12) == "disney.ne.jp") return true;
	
	return false;
}

function isPWD(str) {
	if (str.length < 4 || str.length > 20) return false;
	if (str.match(/^[\w_]+$/)) return true;
	return false;
}

function openPhoto(did, width, height) {
	param = 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, width=' + width + ', height=' + height;
	window.open('photo.php?DID=' + did, 'photo', param);
}

function openGraph(visitorid) {
	param = 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, width=420, height=230';
	window.open('graph.php?visitorid=' + visitorid, 'graph', param);
}

function openImage(rid, width, height) {
	param = 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, width=' + width + ', height=' + height;
	window.open('rimage.php?RID=' + rid, 'rimage', param);
}

function openBBSPhoto(cid, tid, width, height) {
	param = 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, width=' + width + ', height=' + height;
	window.open('bphoto.php?CID=' + cid + '&TID=' + tid, 'bbsphoto', param);
}

function fncLogin() {
	if (isSpace(document.loginform.email.value)) {
		alert('メールアドレスを指定してください。');
		document.loginform.email.focus();
	} else if (!isEmail(document.loginform.email.value)) {
		alert('メールアドレスの指定に誤りがあります。');
		document.loginform.email.focus();
	} else if (isSpace(document.loginform.pwd.value)) {
		alert('パスワードを指定してください。');
		document.loginform.pwd.focus();
	} else {
		return true;
	}

	return false;
}

function fncAlert() {
	alert('ログイン後、ご利用ください。');
}

function openAlert(pid) {
	param = 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, width=600, height=815';
	window.open('/alert.php?PID=' + pid, 'alert', param);
}

var dmtime = setTimeout("", 1)
var dmlen = 0;
var dmloc = 0;

function fncMessage() {
	if (dmloc + 52 <= dietmessage.length) {
		msg = dietmessage.substr(dmloc, 52);
	} else {
		len = dmloc + 52 - dietmessage.length;
		msg = dietmessage.substr(dmloc, 52 - len) + dietmessage.substr(0, len);
	}
	document.getElementById('dietmessage').innerHTML = msg;
	dmloc++;
	if (dmloc > dietmessage.length) dmloc = 0;
	clearTimeout(dmtime);
	dmtime = setTimeout("fncMessage()", 200);
}

function fncWebSearch() {
	if (isSpace(document.websearchform.keyword.value)) {
		alert('キーワードを指定してください。');
		document.websearchform.keyword.focus();
	} else {
		return true;
	}

	return false;
}
