function isDigitString(data) {
	for ( i = 0 ; i < data.length ; i++ ) {
		if (!( ( data.charAt(i) <= '9' ) && ( data.charAt(i) >= '0' ) )) {
			return false;
		}
	}
	return true ;
}


function checkPostCDFormat(data) {
	if ( data.length != 7 ) { return false ;}
	
	if ( !isDigitString(data) ) { return false ;}
	
	return true ;
}


function checkTelFormat(data) {
	var hcnt = 0 ;
	
	for ( i = 0 ; i < data.length ; i++ ) {
		if ( data.charAt(i) == '-' ) {
			hcnt++ ;
			if ( hcnt > 2 ) { return false ;}
		} else {
			if ( ( data.charAt(i) > '9' ) || ( data.charAt(i) < '0' ) ) {
				return false ;
			}
		}
	}
	
	return true ;
}


function checkDateFormat(data) {
	var year = 0 ;
	var month = 0 ;
	var day = 0 ;
	

	if ( data.length != 10 ) { return false ;}
	

	if ( ( data.charAt(4) != '/') || ( data.charAt(7) != '/') ) { return false ;}
	

	if ( !isDigitString(data.substr(0,4)) ) { return false ;}
	if ( !isDigitString(data.substr(5,2)) ) { return false ;}
	if ( !isDigitString(data.substr(8,2)) ) { return false ;}
	

	year  = eval(data.substr(0,4)) ;
	month = eval(data.substr(5,2)) ;
	day   = eval(data.substr(8,2)) ;
	if ( ( month < 1 ) || ( month > 12 ) ) { return false ;}
	if ( ( day < 1 ) || ( day > getLastDay(year,month) ) ) { return false ;}
	
	return true ;
}


function isLeapYear(year) {
	return ( ( ((year%4) == 0) && ((year%100)!=0)) || ((year%400)==0) ) ;
}


function getLastDay(year,month) {
	var months = new Array(13) ;
	months[1]  = 31 ;
	months[2]  = 28 ;
	months[3]  = 31 ;
	months[4]  = 30 ;
	months[5]  = 31 ;
	months[6]  = 30 ;
	months[7]  = 31 ;
	months[8]  = 31 ;
	months[9]  = 30 ;
	months[10] = 31 ;
	months[11] = 30 ;
	months[12] = 31 ;
	
	if ( isLeapYear(year) ) months[2] = 29 ;
	
	return months[month] ;
}




function checkMailAddrFormat(data) {
	var atFlag = false   ;
	var dotcnt = 0       ;
	var adjacent = false ;
	

	if ( data.length <= 2 ) { return false ;}
	

	atFlag = false ;
	for ( i=0 ; i<data.length ; i++ ) {
		if ( data.charAt(i) == '@' ) {
			if ( i == 0 ) { return false ;}
			if ( atFlag ) {
				return false ;
			} else {
				atFlag = true ;
				adjacent = true ;
				continue ;
			}
		}
		
		if ( atFlag ) {
			if ( data.charAt(i) == '.' ) {
				if ( adjacent ) {
					return false ;
				} else {
					if ( i == (data.length -1) ) { return false ;}
					
					dotcnt++ ;
					adjacent = true ;
				}
			} else {
				adjacent = false ;
			}
		}
	}
	
	if ( dotcnt == 0 ) { return false ;}
	
	return true ;
}


function getDaysFromBase(day) {

	bd = new Date() ;
	bd.setYear(1990) ; bd.setMonth(0) ; bd.setDate(1) ;
	bd.setHours(0) ; bd.setMinutes(0) ; bd.setSeconds(0) ;
	

	dd = new Date() ;
	dd.setYear(eval(day.substr(0,4))) ; dd.setMonth(eval(day.substr(5,2))-1) ; dd.setDate(eval(day.substr(8,2))) ;
	dd.setHours(0) ; dd.setMinutes(0) ; dd.setSeconds(0) ;
	
	if ( eval(bd) > eval(dd) ) { return 0 ;}
	
	ye = dd.getYear();      if (ye < 1900) ye += 1900;
	mo = dd.getMonth() + 1; 
	da = dd.getDate();      
	
	days = 0 ;
	for ( i = 1990 ; i<ye ; i++ ) {
		for ( j=1 ; j<=12 ; j++ ) {
			days = days + getLastDay(i,j) ;
		}
	}
	for ( i=1 ; i<mo ; i++ ) {
		days = days + getLastDay(ye,i) ;
	}
	days = days + da ;
	
	return days ;
}


function convertDaysToDate(days) {
	ye = 1990 ;
	mo = 1    ;
	
	while (days > getLastDay(ye,mo)) {
		days = days - getLastDay(ye,mo) ;
		mo++ ;
		if ( mo > 12 ) {
			mo = 1 ;
			ye++ ;
		}
	}
	
	if (ye < 1900) ye += 1900;
	
	rd = new Date() ;
	rd.setYear(ye) ;
	rd.setMonth(mo-1) ;
	rd.setDate(days) ;
	rd.setHours(0) ;
	rd.setMinutes(0) ;
	rd.setSeconds(0) ;
	
	return (rd) ;
}


function addDays(date,day) {
	base = getDaysFromBase(date) ;
	base = eval(base) + day ;
	
	return (convertDaysToDate(base)) ;
}

