var kana =
	"BuvAE@BDFHb[ACEGIJLNPR" +
	"TVXZ\^`cegijklmnqtwz}~" +
	"";
var dakuon =
	"EEEEEEEEEEEEEEEEEEEEEKMOQS" +
	"UWY[]_adfhEEEEEorux{EEEEE" +
	"EEEEEEEEEE";
var handakuon =
	"EEEEEEEEEEEEEEEEEEEEEEEEEE" +
	"EEEEEEEEEEEEEEEpsvy|EEEEE" +
	"EEEEEEEEEE";
var fm_symbol =
	"@CDFGHILMO]^`efghijklmnopqr" +
	"{|\";
var symbol_len = 42;
var to_symbol =
	" ,.:;?!'`^-/~''\"\"()[][]{}<>" +
	"+-=<>'\"\\$%#&*@-";
var c_num = new Array(
	"(1)", "(2)", "(3)", "(4)", "(5)", "(6)", "(7)", "(8)", "(9)", "(10)",
	"(11)", "(12)", "(13)", "(14)", "(15)", "(16)", "(17)", "(18)", "(19)",
	"(20)");
var rc_num = new Array(
	"I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X");
var rs_num = new Array(
	"i", "ii", "iii", "iv", "v", "vi", "vii", "viii", "ix", "x");
var fm_unique =
	"_`abcdefghijklmn" +
	"opqrstu~" +
	"ΰίηγΫΪζΏΎ";
var unique_len = 53;
var to_unique = new Array(
	"~", "L", "Z`", "[g", "O", "g", "A[",
	"wN^[", "bg", "bg","J[", "h", "Zg",
	"p[Zg", "~o[", "y[W",
	"mm", "cm", "km","mg", "kg", "cc", "m^2",
	"½¬", "’","v", "No.", "K.K.", "TEL",
	"(γ)", "()","(Ί)", "(Ά)", "(E)",
	"()", "(L)", "(γ)", "Ύ‘", "ε³", "Ίa",
	"?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?"
	);
var kanji_map = new Array(
	0x43f36f8b,0x9b462542,0xe3e0e82c,0x400a0004,0xdb365f65,0x4497977,
	0xe3f0ecd7,0x18c5603a,0x3403e60b,0x37518000,0x7eebe0c8,0x98698200,
	0x2d56ad48,0x8060e803,0xad93661c,0xc568c03a,0xc656aa60,0x2403f7e,
	0x146183cd,0x21751020,0x7122021,0x40bc3000,0x4562a624,0xa3060a8,
	0x85740217,0x9c840402,0x14157ffb,0x11e27f34,0x22efb665,0x60ff1f75,
	0x38403a70,0x676336c3,0x20b24dd9,0xfc946b0,0x4850bc98,0xa03f8638,
	0x98162388,0x5232be49,0xeba422ab,0xc72c00dd,0x26e1a1e7,0x8f0a841b,
	0x559e27eb,0x89bfc241,0x85480014,0x84d6361,0xaad07f0c,0x5cfff3e,
	0xa803ff1a,0x7b407a41,0x80024745,0x38eb0500,0x1005dc51,0x710c9b34,
	0x1000397,0xa4046366,0x5180d0,0x430ac000,0x30c89071,0x58000008,
	0xf7000ed9,0x415f80,0x941000b0,0x62800018,0x9d00240,0x1568200,
	0x8015004,0x5101d10,0x1084c1,0x10504025,0x4d8a410f,0xa60d4009,
	0x914cab19,0x98121c0,0x203c485,0x80000672,0x80b04,0x9141d,
	0x905c49c9,0x16900009,0x22200c65,0x24338412,0x47960c03,0x42250a04,
	0xd0880028,0x4f0c4900,0xd3aa14a2,0x3e87d830,0x1f618e04,0x41867ea4,
	0x2dbbc390,0x211857ad,0x2a48241e,0x4e041138,0x161b0a40,0x88400d60,
	0x9502020a,0x10608221,0x4000243,0x80001444,0xc040000,0x70000000,
	0xc11a06,0xc00024a,0x401a00,0x40451404,0xbdf30029,0x52b0a78,
	0xbfa0bba9,0x8379407c,0xe91d12fd,0xc5695bf6,0x444aeff6,0xff022115,
	0x402bed63,0x242d033,0x131000,0x5dca1b42,0x20000a0,0x2c61a703,
	0x8ff24880,0x284,0x100d5804,0x48b200,0x20011894,0x37805004,
	0x684d3200,0x68be49ea,0x2e42184c,0x21c9a820,0x80b050b9,0xff7c001e,
	0x14e0849a,0x1e028c1,0xac49870e,0xdddb130f,0x89fbbe1a,0x51b2a2e2,
	0x32ca5522,0x928b3ec6,0x438f1dbf,0x32986703,0x73c03028,0xa9230811,
	0x3a65c000,0x4028fe3,0xa6252c4e,0xa1bf3d,0x8cd43e3a,0x317c06c9,
	0xd52a00e0,0xedf018b,0x8c22e34b,0xf0911183,0xa7287d94,0x40fbc9ac,
	0x7534484,0x44445a90,0x13fc8,0xf5d40048,0xec5f7701,0x891dc442,
	0x49286b83,0xd2424109,0x59fe061d,0x3a221840,0x3b9fb7e4,0xc0eaf003,
	0x82021386,0xe4008980,0x10a1b200,0xcc44b80,0x8944d309,0x48341faf,
	0xc458259,0x470420a,0x10c8a040,0x44503140,0x1004004,0x5408281,
	0x642c0108,0x1a056a30,0x51460a6,0x645690cf,0x31000021,0xcbf09c18,
	0x63e2e120,0x1b5104c,0x9a83538c,0x3281b8b2,0xa84987a,0xc0233e7,
	0xd038d6cd,0x9872e1b1,0xe2848a1e,0x459c3f4,0x23c2439a,0xd3144845,
	0x36400292,0xffbd0241,0xe8f0eb09,0xa5d27dc0,0xd24bc242,0xd0afa47f,
	0x34a11aa0,0xbd88247,0x651bc453,0xc83ad294,0x40c8001e,0x33140e06,
	0xb21f615f,0xc0d00088,0xa898a02a,0x166ba1c5,0x85b4af50,0x604c08b,
	0x1e04f933,0xa251056e,0x76380400,0x73b8ed07,0x19324406,0xc8164081,
	0x63097c8a,0xaa042984,0xca9c1c24,0x27614e0e,0x830009d0,0xc10c0846,
	0x10816011,0x908540d,0xcc0a000e,0xc000514,0xa0440430,0x6784008b,
	0x8a195288,0x8b18865e,0x41602e59,0x9cbe8c10,0x895c6861,0x89800,
	0x89a8100,0xc1900018,0xf4a14007,0x640d8505,0xe4d314e,0xff0a4806,
	0x2ea81632,0xb852e,0xca841810,0x696c0e20,0x16000032,0x390d658,
	0x1a6851a0,0x11249000,0x432698e1,0x1fae5d52,0xae280fa0,0x5700fafb,
	0x99406408,0xc044c880,0xb1419005,0xa4c48424,0x603a1a34,0xc1949000,
	0x3a8246,0xc106180d,0x99100022,0x1511e050,0x824157,0x22a041a,
	0x8930004f,0x446ad813,0xed228aa2,0x400511c0,0x1021000,0x31018808,
	0x2044620,0xf08f800,0xa2008900,0x22020000,0x16108210,0x10400042,
	0x126052c0,0x200052f4,0x82308510,0x42021100,0x80b5430a,0xda2070e1,
	0x8012040,0xfc653500,0xab0419c1,0x62140286,0x440087,0x42469085,
	0xa85405c,0x33803207,0xb8c00400,0xc0d0ce30,0x80c030,0xda50508,
	0x400a90,0x280c0200,0x40446705,0x41226429,0x2e8,0x847c4664,
	0xde200002,0x4049861d,0xc0000a08,0x20010084,0x10108400,0x1c742cd,
	0xd52a703a,0x1d8f9968,0x3e12be50,0x81d9aef5,0x2412cec4,0x732e0828,
	0x4b3424ac,0xd41d020c,0x80002a02,0x8110097,0x114411c4,0x7d451786,
	0x5e4949dd,0x87914040,0xd8c4254c,0x491444ba,0xc8001b92,0x15800271,
	0xc0000c1,0xc200096a,0x40024800,0xba493021,0x1c802080,0x1008e2ac,
	0x341004,0x841400e3,0x20004020,0x14149810,0x4aa70c2,0x54208688,
	0x4130c62,0x20109180,0x2064082,0x54011c40,0xe4e90383,0x84802125,
	0x2810e433,0xe60944c0,0x81260a03,0x80112da,0x97906901,0xf8864001,
	0x81e24d,0xa6510a0e,0x81ec011a,0x8441c600,0xb62eadb8,0x8741acef,
	0x4b028d54,0x2681161,0x2057bb60,0x43350a0,0xf7b4a8c0,0x1122402,
	0x20009ad3,0xc82271,0x809e2081,0xe1800c8a,0x8151b009,0x40281031,
	0x89a52a0e,0x620e69b6,0xd1444425,0x4d548085,0x1fb12c75,0x862dd807,
	0x5841d97c,0x226e414e,0x9e088200,0xedb7f80d,0x75668c80,0x8149313,
	0xc8040e32,0x6ea6484e,0x66742c4a,0xba0126c0,0x185dd70c,0x0,
	0x0,0x0,0x0,0x5400000,0x813370a0,0x3a54f81,
	0x641055ec,0x2344c31a,0x341462,0x1a090a43,
	0x13a5187b,0xa8480102,0xc5440440,0xe2dd8106,0x2d481af0,0x416b626,
	0x6e405058,0x31128032,0xc0007e4,0x420a8208,0x803b4840,0x87134860,
	0x3428850d,0xe5290319,0x870a2345,0x5c1825a9,0xd9c577a6,0x3e85e00,
	0xa7000081,0x41c6cd54,0xa2042800,0x2b0ab860,0xda9e0020,0xe1a08ea,
	0x11c0427e,0x3768908,0x1058621,0x98a80004,0xc44846a0,0x20220d05,
	0x914854a2,0x28d78a01,0x87898,0x31221605,0x8804340,0x6a2fa4e,
	0x92110814,0x9b142002,0x16432e52,0x90105000,0x85ba0041,0x20203042,
	0x7a84f0b,0x40802f08,0x1a930591,0x601df50,0x3021a202,0x4e800630,
	0x4c80cc4,0x8001a004,0xd4316000,0xa020880,0x281c00,0x418e18,
	0xca106ad0,0x4b00f210,0x1506274d,0x88900220,0x82a85a00,0x81504549,
	0x80002004,0x2c088804,0x508d1,0x4ac48001,0x62e0a0,0xa42008e,
	0x6a8c3055,0xe0a5090e,0x42c42906,0x80b34814,0xb330803e,0x733c0102,
	0x700d1494,0x9400c20,0xc040301a,0xc094a451,0x5c88dca,0xa40c96c2,
	0x34040001,0x11000c8,0xa9cd550d,0x1cda2428,0x48370142,0x120f7a4d,
	0x452a32b4,0xd20531fb,0xdc44b894,0x45ca68d7,0x2ed15097,0x42081943,
	0x9d48d202,0xa0979840,0x64d5409,0x0,0x0,0x0,
	0x0,0x84800000,0x4215542,0x17001c06,0x61107624,0xb9ddff87,
	0x5c0a659f,0x3c11245d,0x5dadb0,0x0,0x0,0xdb28d0,
	0x2000422,0x44080108,0xac409804,0x90288d0a,0xe0018700,0x310400,
	0x82211794,0x10540019,0x21a2cb2,0x40039c02,0x8804bd60,0x7900080c,
	0xba3c1628,0xcb088640,0x90807274,0x1e,0xd8000000,0x9c87e188,
	0x4124034,0x2791ae64,0xe6fbe86b,0x5366408f,0x537feea6,0xb5e4e3ab,
	0x2869f,0x1228548,0x48004402,0x20a02116,0x2240004,0x52080,
	0x1547e00,0x1ac162c,0x10852a84,0x5308c14,0xfdc3fbc3,0x906060fa,
	0x40336440,0x96901200,0x4e834b31,0x418200d4,0x1d6a0129,0x2802080,
	0x2ad8000,0x9f0c2691,0x67018044,0xc24d96f,0x18d02910,0x50215001,
	0x4d01000,0x2017090,0x61c30148,0x1000132,0x7190088,0x5620802,
	0x4c0e0132,0xf0a10405,0x2,0x0,0x0,0x0,
	0x0,0x0,0x0,0x800000,0x35e8e8d,0x5a0421bd,
	0x11703488,0x26,0x10000000,0x8804c502,0xf801b815,0x25ed147c,
	0x3bb0ed60,0x1bd78589,0x1a627af3,0xac50d0c,0x524ae5d1,0x6b0d0490,
	0x5266a35c,0x16122b57,0x1101a872,0x182949,0x10080948,0x886c6000,
	0x58f916e,0x39903012,0x49b0f840,0x1b88a0,0x0,0x428500,
	0x98000058,0x7014ea04,0x611d1628,0x60005193,0xa71a24,0x0,
	0x43c00000,0x10187120,0xa9270172,0x89066004,0x20cc022,0x40810900,
	0x8ca0602d,0xe34,0x0,0x11012100,0xd31a8011,0x892ec4c,
	0x85000040,0x1806c7ac,0x512e03e,0x348000,0x80cec008,0xa126d01,
	0x8568641,0x27011e,0x83d3751,0x4e05e032,0x48401c0,0x1400081,
	0x0,0x0,0x0,0x591aa0,0x882443c8,0xc8001d48,
	0x72030152,0x4059813,0x4008280,0xd148a10,0x2088056,0x2704a040,
	0x4e000000,0x0,0x0,0xa3200000,0xa0ae1902,0xdf002660,
	0x7b17f010,0x3ad08121,0x284180,0x48001003,0x8014cc00,0xc414cf,
	0x30202000,0x1,0x0,0x0
	);

function Normalize(in_str){
	var shift, current, code, flag, conv_flag;
	var rem_str = in_str;
	var out_str = "";

	conv_flag = false;

	while(rem_str != ""){
		current = rem_str.substr(0, 1);
		rem_str = rem_str.substr(1);
		code = current.charCodeAt(0);

		if(code < 128 
			|| "" <= current && current <= ""
			|| isNaN(code));

		else if("O" <= current && current <= "X")
			current = String.fromCharCode(code
					- "O".charCodeAt(0) + "0".charCodeAt(0));

		else if("`" <= current && current <= "y")
			current = String.fromCharCode(code
					- "`".charCodeAt(0) + "A".charCodeAt(0));

		else if("" <= current && current <= "")
			current = String.fromCharCode(code
					- "".charCodeAt(0) + "a".charCodeAt(0));

		else if(0x4e00 <= code && code <= 0x9fff){
			if(!(kanji_map[(code - 0x4e00) >> 5] & (1 << (code & 0x1f)))){
				current = "?";
				conv_flag = true;
			}

		}else if(0x3400 <= code && code < 0xff00){
			conv_flag = true;
			current = "?";

		}else if("‘" <= current && current <= "έ"){
			shift = code - "‘".charCodeAt(0);
			current = kana.substr(shift, 1);

			if(rem_str != "" &&
					rem_str.substr(0, 1) == "ή" &&
					dakuon.substr(shift, 1) != "E"){
				current = dakuon.substr(shift, 1);
				rem_str = rem_str.substr(1);
			}else if(rem_str != "" &&
					rem_str.substr(0, 1) == "ί" &&
					handakuon.substr(shift, 1) != "E"){
				current = handakuon.substr(shift, 1);
				rem_str = rem_str.substr(1);
			}

		}else if("@" <= current && current <= "S")
			current = c_num[code - "@".charCodeAt(0)];

		else if("T" <= current && current <= "]")
			current = rc_num[code - "T".charCodeAt(0)];

		else if("ϊ@" <= current && current <= "ϊI")
			current = rs_num[code - "ϊ@".charCodeAt(0)];

		else{
			flag = true;
			for(shift = 0; shift < symbol_len; shift++)
				if(fm_symbol.substr(shift, 1) == current){
					current = to_symbol.substr(shift, 1);
					flag = false;
					break;
				}

			if(flag)
				for(shift = 0; shift < unique_len; shift++)
					if(fm_unique.substr(shift, 1) == current){
						current = to_unique[shift];
						break;
					}
		}

		out_str += current;
	}

	out_str = Trimming(out_str);

	if(conv_flag)
		window.alert(
			"Windows VistaΜuΒ«ΛΆΆvΘΗA]VXe/tHgΖέ·«\nΜΘ’ΆπuHvΙΟ·΅ά΅½B\n°κόθά·ͺAόΝΙίθAέ·«Μ ιΆΙC³΅Δ­Ύ³’B");

	return out_str;
}

function NormalizeKana(in_str){
	var shift, current, code, conv_flag;
	var rem_str = in_str;
	var out_str = "";

	conv_flag = false;

	while(rem_str != ""){
		current = rem_str.substr(0, 1);
		rem_str = rem_str.substr(1);
		code = current.charCodeAt(0);

		if(code < 128
			|| "" <= current && current <= ""
			|| "O" <= current && current <= "X"
			|| "`" <= current && current <= "y"
			|| "" <= current && current <= "");

		else if(0x4e00 <= code && code <= 0x9fff){
			if(!(kanji_map[(code - 0x4e00) >> 5] & (1 << (code & 0x1f)))){
				current = "?";
				conv_flag = true;
			}

		}else if(0x3400 <= code && code < 0xff00){
			conv_flag = true;
			current = "?";

		}else if("‘" <= current && current <= "έ"){
			shift = code - "‘".charCodeAt(0);
			current = kana.substr(shift, 1);

			if(rem_str != "" &&
					rem_str.substr(0, 1) == "ή" &&
					dakuon.substr(shift, 1) != "E"){
				current = dakuon.substr(shift, 1);
				rem_str = rem_str.substr(1);
			}else if(rem_str != "" &&
					rem_str.substr(0, 1) == "ί" &&
					handakuon.substr(shift, 1) != "E"){
				current = handakuon.substr(shift, 1);
				rem_str = rem_str.substr(1);
			}

		}else if("@" <= current && current <= "S")
			current = c_num[code - "@".charCodeAt(0)];

		else if("T" <= current && current <= "]")
			current = rc_num[code - "T".charCodeAt(0)];

		else if("ϊ@" <= current && current <= "ϊI")
			current = rs_num[code - "ϊ@".charCodeAt(0)];

		else{
			for(shift = 0; shift < unique_len; shift++)
				if(fm_unique.substr(shift, 1) == current){
					current = to_unique[shift];
					break;
				}
		}

		out_str += current;
	}

	if(conv_flag)
		window.alert(
			"Windows VistaΜuΒ«ΛΆΆvΘΗA]VXe/tHgΖέ·«\nΜΘ’ΆπuHvΙΟ·΅ά΅½B\n°κόθά·ͺAόΝΙίθAέ·«Μ ιΆΙC³΅Δ­Ύ³’B");
	return out_str;
}

function Trimming(s){
	var p, l;

	l = s.length;
	for(p = 0; l > p && (s.charAt(p) == " " || s.charAt(p) == "@"); p++);
	for(; l > p && (s.charAt(l - 1) == " " || s.charAt(l - 1) == "@"); l--);
	return s.substring(p, l);
}

function IsNum(in_str){
	var current;
	var len = in_str.length;
	for(var i = 0; i < len; i++){
		current = in_str.substr(i, 1);
		if(!("0" <= current && current <= "9"))
			return false;
	}

	return true;
}

function IsZip(in_str){
	var current;
	var len = in_str.length;
	if(len != 8)
		return false;
	for(var i = 0; i < len; i++){
		current = in_str.substr(i, 1);
		if(i == 3){
			if(current != "-")
				return false;
		}else{
			if(!("0" <= current && current <= "9"))
				return false;
		}
	}
	return true;
}

function IsTel(in_str){
	var current;
	var len = in_str.length;
	for(var i = 0; i < len; i++){
		current = in_str.substr(i, 1);
		if(!("0" <= current && current <= "9" || current == "-"))
			return false;
	}

	return true;
}

function IsMailList(in_str){
	if(in_str.len == 0)
		return true;

	var list = in_str.split(";");
	for(var i = 0; i< list.length; i++)
		if(!IsMail(Normalize(list[i])))
			return false;
	return true;
}

function IsMail(in_str){
	var current;
	var len = in_str.length;

	if(len == 0)
		return true;

	for(var i = 0; i < len; i++){
		current = in_str.substr(i, 1);
		if(current == "@")
			break;
		else if(current == ";" || current == "," || current == " ")
			return false;
	}

	if(i >= len - 1)
		return false;

	for(i++; i < len; i++){
		current = in_str.substr(i, 1);
		if(!("0" <= current && current <= "9" ||
				"a" <= current && current <= "z" ||
				"A" <= current && current <= "Z" ||
				current == "-" || current == "."))
			return false;
	}

	return true;
}

function LenCheck(str, field, acceptnull, length){
	if(!acceptnull && str == "")
		return field + "πόΝ΅Δ­Ύ³’B\n";
	else if(getLength(str) > length)
		return field + "Ν" + length + "Ά(SpΕΝ" + Math.floor(length / 2) + "Ά)π΄¦Θ’ζ€Ι΅Δ­Ύ³’B\n";
	else
		return "";
}

function getLength(str){
	var i, count = 0;

	for(i = 0; i < str.length; i++){
		if(escape(str.charAt(i)).length > 4)
			count++;
		count++;
	}
	return count;
}
