/**
 * 空白チェック
 *
 * @param obj オブジェクト
 */
function isBrank(str) {
	if ( str.length <= 0 ) {
		return true;
	}

	return false;
}

/**
 * 半角数字のみチェック
 *
 * @param obj オブジェクト
 */
function isNumber(str){
	if ( isBrank(str) ) {
		return true;
	}
    return !isNaN(str);
}

/**
 * 文字数チェック
 *
 * @param obj オブジェクト
 * @param len サイズ
 */
function lengthCheck(str, len) {
	if ( str.length == len ) {
		return true;
	}

	return false;
}

/**
 * 日付が有効かどうかチェックする。
 *
 * @param strDate 日付（yyyy/mm/dd形式文字列）
 */
function checkDate(strDate) {
	var dSplit = strDate.split("/");

	if ( dSplit.length != 3 ) {
		return false;
	}

	if ( dSplit[0].length != 4 ) {
		return false;
	}

	if ( dSplit[1].length < 1 || dSplit[1].length > 2 ) {
		return false;
	}

	if ( dSplit[2].length < 1 || dSplit[2].length > 2 ) {
		return false;
	}

	if ( dSplit[0].match(/[^0-9]/) || dSplit[1].match(/[^0-9]/) || dSplit[2].match(/[^0-9]/) ) {
		return false;
	}

	var newdate = new Date(dSplit[0], dSplit[1]-1, dSplit[2]);

	if ( (newdate.getDate() != dSplit[2]) || (dSplit[1] != newdate.getMonth()+1) ) {
		return false;
	}

	return true;
}

/**
 * 2つの日付の大小を比較します。
 * strDate1 > strDate2　の場合falseを返します。
 * 注：日付が有効かどうかはチェックしません。
 *
 * @param strDate1 日付（yyyy/mm/dd形式文字列）
 * @param strDate2 日付（yyyy/mm/dd形式文字列）
 */
function compare(strDate1, strDate2) {
	var date1 = strToDate(strDate1);
	var date2 = strToDate(strDate2);

	if ( date1.getTime() <= date2.getTime() ) {
		return true;
	} else {
		return false ;
	}
}

//////////////////////////////////////////////////////
// 文字列→日付変換
//////////////////////////////////////////////////////
function strToDate(strDate) {
	var array = strDate.split("/");
	var date  = new Date(array[0], array[1]-1, array[2]);

	return date;
}

// this part is for the form field hints to display
// only on the condition that the text input has focus.
// otherwise, it stays hidden.
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

