function isKanaCode(code)
{
	return ((0xFF70 <= code && code <= 0xFF9D) || (0xFF66 <= code && code <= 0xFF6F) || isMarkCode(code) || (code == 0x20));
}

function isMarkCode(code)
{
	return ((0xFF61 <= code && code <= 0xFF65) || (0xFF9E <= code && code <= 0xFF9F) || (0x40 == code));
}

function isAlphaCode(code)
{
	return ((0x41 <= code && code <= 0x5A) || (0x61 <= code && code <= 0x7A));
}

function isKanjiCode(code)
{
	return ((0x4E00 <= code && code <= 0x9FA5) || (0xF929 <= code && code <= 0xFA2D));
}

function isKataZenkakuCode(code)
{
	return (0x30A1<= code && code <= 0x30FA || code ==0x30FC || code==0x3001);
}

function isHiraZenkakuCode(code)
{
	return (0x3041 <= code && code <= 0x3094 || code==0x3001);
}

function isVietUniCode(code)
{
	return ((code == 32) || (65 <= code && code <= 90) || (97 <= code && code <= 122) || (192 <= code && code <= 195) || (200 <= code && code <= 202) || (204 <= code && code <= 205) || (210 <= code && code <= 213) || (217 <= code && code <= 218) || (code == 221) || (224 <= code && code <= 227) || (232 <= code && code <= 234) || (236 <= code && code <= 237) || (242 <= code && code <= 245) || (249 <= code && code <= 250) || (code == 253) || (258 <= code && code <= 259) || (272 <= code && code <= 273) || (296 <= code && code <= 297) || (360 <= code && code <= 361) || (416 <= code && code <= 417) || (431 <= code && code <= 432) || (7840 <= code && code <= 7929));
}

function checkNumeric(str)
{
	var samplestr = "1234567890"
	str = str.toString();
		if (str.length >0)
		{
			for (var a=0; a<samplestr.length; a++)
			{
				if (samplestr.indexOf(str.charAt(a),0)==-1)
				{
				return false;
				}
			}
		}
	return true;	
}

function get_last_day_of_month(year,month)
{
	if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
	{
		return 31;
	}
	else if (month == 4 || month == 6 || month == 9 || month == 11)
	{
		return 30;
	}
	else if (month == 2)
	{
		if(((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
		{
			if(year == 2000 || year == 2100 || year ==2200)
			{
				return 28;
			}  
			else    
			{
				return 29;
			}
		}  
		else    
		{
			return 28;
		}
	}
}

function checkDate(y,m,d)
{
	y = y.toString();
	m = m.toString();
	d = d.toString();

	if( y=="" && m=="" && d=="")
		return false;

	if (!checkNumeric(y) || !checkNumeric(m) || !checkNumeric(d))
		return false;

	if (m.length == 1)
		m = "0" + m;

	if (d.length == 1)
		d = "0" + d;

	if (y.length != 4 || m.length != 2 || d.length != 2)
		return false;

	y = y.valueOf();
	m = m.valueOf();
	d = d.valueOf();

	if (y < 1900 || y > 2100)
		return false;
	
	if (m < 1 || m > 12)
		return false;

	if(d < 1 || d > get_last_day_of_month(y,m))   
		return false;

	return true;
}

function checkTime(h,m,s)
{
	h = h.toString();
	m = m.toString();
	s = s.toString();

	if( h=="" && m=="" && s=="")
	{return false;}

	if (!checkNumeric(h) || !checkNumeric(m) || !checkNumeric(s))
	{return false;}

	if (h.length==1)
	{h="0"+h;}
	
	if (m.length==1)
	{m="0"+m;}

 	if (s.length==1)
	{s="0"+s;}

	h = h.valueOf();
	m = m.valueOf();
	s = s.valueOf();

	if ( !(h.length == 2) || !(m.length == 2) || !(s.length == 2) )
    {return false;}

    if (h < 0 || h > 23)
	{return false;}
	
    if (m < 0 || m > 59)
	{return false;}

    if (s < 0 || s > 59)
	{return false;}
	return true;
}

function checkByte(str, len)
{
	var n = 0;
	var i;

	for(i=0; i<str.length; i++)
		n+= is_ie_zenkaku(str.charAt(i)) ? 2:1;
	if( len >= n)
		return true;
	return false;
}

function getByte(str)
{
	var n = 0;
	var i;

	for(i=0; i<str.length; i++)
		n+= is_ie_zenkaku(str.charAt(i)) ? 2:1;
	return n;
}

function isKana(str)
{
	var n = 0;
	var i;

	for(i=0; i<str.length; i++)
		n+= isKanaCode(str.charCodeAt(i)) ? 0:1;
	if( n == 0)
		return true;
	return false;
}

function isKanji(str)
{
	var n = 0;
	var i;

	for(i=0; i<str.length; i++)
		n+= isKanjiCode(str.charCodeAt(i)) ? 0:1;
	if( n == 0)
		return true;
	return false;
}

function isKataZenkaku(str)
{
	var n = 0;
	var i;

	for(i=0; i<str.length; i++)
		n+= isKataZenkakuCode(str.charCodeAt(i)) ? 0:1;
	if( n == 0)
		return true;
	return false;
}

function isHiraZenkaku(str)
{
	var n = 0;
	var i;

	for(i=0; i<str.length; i++)
		n+= isHiraZenkakuCode(str.charCodeAt(i)) ? 0:1;
	if( n == 0)
		return true;
	return false;
}

function isZenkaku(str)
{
	var n = 0;
	var i;

	for(i=0; i<str.length; i++)
		n+= is_ie_zenkaku(str.charAt(i)) ? 0:1;
	if( n == 0)
		return true;
	return false;
}

function isVietUni(str)
{
	var n = 0;
	var i;

	for(i=0; i<str.length; i++)
		n+= isVietUniCode(str.charCodeAt(i)) ? 0:1;
	if( n == 0)
		return true;
	return false;
}

function is_ie_zenkaku(c) 
{ 
	var code;
	if (c==" ")
	{
		return false;
	}
	if(escape(c).charAt(1) == "u" ) 
		return true;
	else 
		if(escape(c).charAt(1) != "")
		return true;
	else
		return false; 
}

function isTelNo(str)
{
var samplestr = "1234567890-"
	if (str.length >0)
	{
		for (var a=0; a<samplestr.length; a++)
		{
			if (samplestr.indexOf(str.charAt(a),0)==-1)
			{
			return false;
			}
		}
	}
return true;	
}

function isEmailAddr(str)
{
var samplestr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.1234567890@"
	if (str.length > 0)
	{
		for(var a=0; a<samplestr.length; a++)
		{
			if (samplestr.indexOf(str.charAt(a),0) == -1)
			{
			return 1;//Ｅメールアドレスの入力が正しくありません！
			}
		}
		
		if(str.match(/@/i) != "@")
		{
			return 2;//Ｅメールアドレスの入力に《@》がありません！
		}
	}
return 0;	
}

function isURLAddr(str)
{
var samplestr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.1234567890/:~"
	if (str.length > 0)
	{
		for(var a=0; a<samplestr.length; a++)
		{
			if (samplestr.indexOf(str.charAt(a),0) == -1)
			{
				return 1;//URLアドレスの入力が正しくありません！
			}
		}

		if(str.lastIndexOf(".")==-1)
		{
			return 2;//URLアドレスの入力に《.》がありません！
		}
		else
		{
			if (str.lastIndexOf(".")==str.length-1)
			{
				return 1;
			}
			if (!isAlphaCode(str.charCodeAt(str.lastIndexOf(".")+1)))
			{
				return 1;
			}
		}
	}
return 0;	
}


function isUsernameOrPassword(str)
{
var samplestr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.1234567890"
	if (str.length >0)
	{
		for (var a=0; a<samplestr.length; a++)
		{
			if (samplestr.indexOf(str.charAt(a),0)==-1)
			{
			return false;
			}
		}
	}
return true;	
}

function isEisuu(str)
{
var samplestr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"
	if (str.length > 0)
	{
		for(var a=0; a<samplestr.length; a++)
		{
			if (samplestr.indexOf(str.charAt(a),0) == -1)
			{
			return false;
			}
		}
	}
return true;	
}

function checkHankakuSuuji(str)
{
var samplestr = "０１２３４５６７８９"
	if (str.length > 0)
	{
		for(var a=0; a<samplestr.length; a++)
		{
			if (samplestr.indexOf(str.charAt(a),0) > 0)
			{
			return false;
			}
		}
	}
return true;	
}

function trim(s)
{
	low = 0;
	while (low < s.length)
	{
		if(s.charAt(low)==' ' || s.charAt(low)=='　' || s.charAt(low)=='\n' || s.charAt(low)=='\r')++low;
		else break;
	}
		
	if (low == s.length)return '';
	
	up = s.length-1;
	while (up > -1)
	{
		if(s.charAt(up)==' ' || s.charAt(up)=='　' || s.charAt(up)=='\r' || s.charAt(up)=='\n')--up;
		else break;
	}
	
	if (up == -1)return '' ;

	
	strim='';
	for (i=low;i<=up;i++)
	{
		strim=strim+s.charAt(i);
	}	
	return strim;
}

function IsAllSpace(s)
{
	if(trim(s)="")
	{
		return false;
	}
	return true;
}

//郵便番号のチェック、型：ｘｘｘ−ｘｘｘｘ、 作成日：2000/10/25、作成者：ター
function isZipCode(s)
{
	if (s.length!=8)
	{
		return false;
	}
	else
	{
		if (!isTelNo(s))
		{
			return false;
		}
		else
		{
			if (s.charAt(3)!="-")
			{
				return false;
			}

		}
	}
	return true;
}

//開始日と終了日の大小関係のチェック、作成日：2000/12/07、作成者：ター
//日付が正しいかをチェックしないのでこの関数の利用の前に必ずCheckDate（）関数を使用するようにする
function isDateDiff(beginyear,beginmonth,beginday,endyear,endmonth,endday)
{
	if (beginmonth.length==1) {beginmonth="0"+beginmonth;}
	if (beginday.length==1) {beginday="0"+beginday;}
	if (endmonth.length==1) {endmonth="0"+endmonth;}
	if (endday.length==1) {endday="0"+endday;}

	var begindate=beginyear+beginmonth+beginday;
	var enddate=endyear+endmonth+endday;

	if (begindate == enddate)	{return 1;}
	if (begindate < enddate)	{return 2;}
	if (begindate > enddate)	{return 3;}

}
