
	function escapehtml(ch) {
    		ch = ch.replace(/&/g,"&amp;") ;
    		ch = ch.replace(/"/g,"&quot;") ;
    		ch = ch.replace(/'/g,"&#039;") ;
    		ch = ch.replace(/</g,"&lt;") ;
    		ch = ch.replace(/>/g,"&gt;") ;
    		return ch ;
	}

	function isASCii(val) {
		for(var i=0 ; i<val.length; i++){
			var code=val.charCodeAt(i);
			if (code<32 || code>127) {
				return false;
			}
		}
		return true;
	}

	function isOKChar(val) {
		for(var i=0 ; i<val.length; i++){
			var code=val.charCodeAt(i);
			// if (code == 92 || code== 39 || code== 34) { // \'" -> NG
			if (code == 60) { // < -> NG
				return false;
			}
		}
		return true;
	}

	function isSpaceCharOnly(val) {
		for(var i=0 ; i<val.length; i++){
			var code=val.charCodeAt(i);
			if (code != 32 && code != 12288 && code != 09 && code != 10 && code != 13) { // TAB, NL, CR
				return false;
			}
		}
		return true;
	}

	function isValidEmail(val) {
		if(val.match(/[!#-9A-~]+@+[a-z0-9]+.+[^.]$/i)) {
			return true;
		}
		return false;
	}

	function check_anitem(val, name, mandatory, length_min, length_max, asciionly) {

		var ret = "";

		if (mandatory) {
			if (isSpaceCharOnly(val)) {
				ret += "・" + name + "を入力してください。\n";
			}
		}

		if (length_min == 0) {
			if (val.length > length_max) {
				ret += "・" + name + "が長すぎます。" + length_max + " 文字以内にしてください。\n";
			}
		} else {
			if ((val.length < length_min) || (val.length > length_max)) {
				ret += "・" + name + "は " + length_min + "文字以上 " + length_max + " 文字以下にしてください。\n";
			}
		}

		if (asciionly) {
			if (!isASCii(val)) {
				ret += "・" + name + "は半角で入力してください。\n";
			}
		}

		if (!isOKChar(val)) {
			ret += "・" + name + "には半角の < は使用できません。\n";
		}

		return ret;

        }

	function check_email(val, name, mandatory, length_min, length_max, asciionly) {

		var errmsg = check_anitem(val, name, mandatory, length_min, length_max, asciionly);
		if (errmsg != "") {
			return errmsg;
		}

		if (val != "") {
			if (!isValidEmail(val)) {
				return "・" + name + "が不正です。\n";
			}
		}

		return "";

        }

	function callPHP(param, url, func) {
		dojo.xhrPost({
			url: url,
        		handleAs: "text",
        		timeout: 10000,
			content: param,
        		handle: function(response, ioArgs){
                		if(response instanceof Error){
                        		if(response.dojoType == "cancel"){
                                		console.debug("Request canceled.");
                        		}else if(response.dojoType == "timeout"){
                                		console.debug("Request timed out.");
                        		}else{
                                		console.error(response);
                        		}
                		}else{
                        		console.debug("Successful server response: " + response);
                        		console.debug("HTTP status code: ", ioArgs.xhr);
                		}
				func(response);
        		}
		});
		return false;
	}

