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 - 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;
}

function timeoutCheck() {
}

function httpRequest(target_url, functionReference) {
	var useragent = navigator.userAgent.toLowerCase();

	try {
		if (window.XMLHttpRequest) {
			httpObj = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			httpObj = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			httpObj = false;
		}
	} catch (e) {
		httpObj = false;
		
	}
	if (!httpObj) {
		httpObjGenerateFail();
	}
	
	timerId = setInterval('timeoutCheck()', 1000);

	httpObj.open("GET", target_url, true);
	if (useragent.indexOf("firefox") != -1 || useragent.indexOf("opera") != -1 || useragent.indexOf("safari") != -1) {
		httpObj.onload = function() {
			functionReference(httpObj.responseText);
		}
	} else {
		httpObj.onreadystatechange = function() {
			if (httpObj.readyState == 4) {
				clearInterval(timerId);
				if (httpObj.status == 200) {
					functionReference(httpObj.responseText);
				} else {
					return false;
				}
			}
		}
	}
	
	httpObj.send('');
}

function httpRequestSync(target_url) {
	var response = '';
	var useragent = navigator.userAgent.toLowerCase();

	try {
		if (window.XMLHttpRequest) {
			httpObj = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			httpObj = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			httpObj = false;
		}
	} catch (e) {
		httpObj = false;
	}
	if (!httpObj) {
		httpObjGenerateFail();
	}

	httpObj.open("GET", target_url, false);
	if (useragent.indexOf("firefox") != -1 || useragent.indexOf("opera") != -1 || useragent.indexOf("safari") != -1) {
		httpObj.onload = function() {
			response = httpObj.responseText;
		}
	} else {
		httpObj.onreadystatechange = function() {
			if (httpObj.readyState == 4) {
				if (httpObj.status == 200) {
					response = httpObj.responseText;
				}
			}
		}
	}

	httpObj.send('');
	
	return response;
}

