/***************************************************************************
// ビルドインクラスの拡張（IE5対応）
***************************************************************************/

if (!Array.prototype.push) {
	
	Array.prototype.push = function() {
		
		var leng = this.length;
		for (var i=leng; i<leng+arguments.length; i++) {
			this[i] = arguments[i-leng];
		}
		return this.length;
	};
}


if (!Array.prototype.unshift) {
	
	Array.prototype.unshift = function() {
		
		this.length = this.length+arguments.length-1;
		for (var i = this.length; i>=arguments.length; i--) {
			this[i] = this[i-arguments.length];
		}
		for (var i = 0; i<arguments.length; i++) {
			this[i] = arguments[i];
		}
		return this.length;
	};
}


if (!Function.prototype.apply) {
	
	Function.prototype.apply = function(obj, arg) {
		
		var result;
		var tmpObj = (obj == null) ? window : obj;
		var tmpArg = Array.prototype.slice(arguments, 0).toString();
		tmpObj.func = this;
		result = eval('tmpObj.func ('+tmpArg+')');
		delete tmpObj.func;
		return result;
	};
}


/***************************************************************************
// フォーム：プルダウンに関するもの
***************************************************************************/


// 数字と単位の組合せでプルダウンリストを返す
function createDbList(leng, unitName, startNum, extra) {
	
	var dbList = new Array();
	var v;
	var t; 
	
	var index = (typeof startNum == "undefined") ? 1: startNum;
	for (i=index; i<=leng; i++) {	
		v = (typeof extra != "undefined" && i < 10) ? "0" + i: i;
		t = i+unitName;
		dbList.push({value:v, text:t});	
	}
	
	return dbList;
}


// 指定された長さの月を抜き出して返す
function getSliceMonth(leng){

    var date  = new Date();
	var months = [];
   	var month = date.getMonth();
    
    for (var i = 0; i < leng; i++) {
        var num = (month + i) % 12;
        months[months.length] = month_list[num];
	}
	
	return months;
}


// その月が何日あるかを返す
function getDaylength(month) {
	
	var dayNum = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
    var date  = new Date();
	var year = date.getFullYear();
	var mon  = date.getMonth() + 1;
	if (mon > 2) {
		year++;
	}
   	if (typeof month == "undefined") month = date.getMonth() + 1;	
	var lastDay = dayNum[month-1];
	
	if (month == 2) {//閏年の確認
		lastDay += (year%4 == 0 && year%100 != 0 || year%400 == 0);
	}
	
	return lastDay;
}


// 月日を返す（現在の日付を基準とする）
function getOffsetDate(offsetDay) {
	
	var date = new Date();
	var currentTime = date.getTime();
	var offsetTime = offsetDay * 1000 * 60 * 60 * 24;
	
	date.setTime(currentTime + offsetTime);
	
	return date;
}


// 月が変更された時の日付のチェック（3月30日　=>　2月28日など）
function getDayIndex(targetMonth, targetDay) {
	
	var tempIndex = getSelectedValue(targetDay)*1;
	var dayMax = getDaylength(getSelectedValue(targetMonth));
	
	return (tempIndex > dayMax) ? dayMax: tempIndex;
}


// 選択されている値を返す
function getSelectedValue(target) {
	
	return target.options[target.options.selectedIndex].value;
}



/***************************************************************************
// フォーム：その他
***************************************************************************/

// YYMMDD形式で返す
function getyymmdd(m, d){

	var nowDate = new Date();
	var tgtDate = new Date();
	var year = nowDate.getFullYear();
	
	tgtDate.setYear(year);
	tgtDate.setMonth(m);
	tgtDate.setDate(d);

	var y = (nowDate > tgtDate) ? year + 1 : year;
	
	return y + m + d;
}

/***************************************************************************
// その他
***************************************************************************/

// onload時のイベント追加
function addLoadEvent(func) {
	
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}



