/* スクリプト */
var holiday = new Array(
	new Date("2008","0","1"),	// 元日
	new Date("2008","0","14"),	// 成人の日
	new Date("2008","1","11"),	// 建国記念の日
	new Date("2008","2","20"),	// 春分の日
	new Date("2008","3","29"),	// 昭和の日
	new Date("2008","4","3"),	// 憲法記念日
	new Date("2008","4","4"),	// みどりの日
	new Date("2008","4","5"),	// こどもの日
	new Date("2008","4","6"),	// みどりの日(振り替え休日)
	new Date("2008","6","21"),	// 海の日
	new Date("2008","8","15"),	// 敬老の日
	new Date("2008","8","23"),	// 秋分の日
	new Date("2008","9","13"),	// 体育の日
	new Date("2008","10","3"),	// 文化の日
	new Date("2008","10","23"),	// 勤労感謝の日
	new Date("2008","10","24"),	// 勤労感謝の日(振り替え休日)
	new Date("2008","11","23"),	// 天皇誕生日
	new Date("2009","0","1"),	// 元日
	new Date("2009","0","12"),	// 成人の日
	new Date("2009","1","11"),	// 建国記念の日
	new Date("2009","2","20"),	// 春分の日
	new Date("2009","3","29"),	// 昭和の日
	new Date("2009","4","3"),	// 憲法記念日
	new Date("2009","4","4"),	// みどりの日
	new Date("2009","4","5"),	// こどもの日
	new Date("2009","4","6"),	// 憲法記念日(振り替え休日)
	new Date("2009","6","20"),	// 海の日
	new Date("2009","8","21"),	// 敬老の日
	new Date("2009","8","22"),	// 敬老の日と秋分の日に挟まれた国民の休日
	new Date("2009","8","23"),	// 秋分の日
	new Date("2009","9","12"),	// 体育の日
	new Date("2009","10","3"),	// 文化の日
	new Date("2009","10","23"),	// 勤労感謝の日
	new Date("2009","11","23")	// 天皇誕生日
);

window.onload = function(){
	setFrameRoundCorner();
	setContentsRoundCorner();
}

function setFrameRoundCorner() {
	/*
	The new 'validTags' setting is optional and allows
	you to specify other HTML elements that curvyCorners
	can attempt to round.
	
	The value is comma separated list of html elements
	in lowercase.
	
	validTags: ["div", "form"]
	
	The above example would enable curvyCorners on FORM elements.
	*/
	logoSetting = {
		tl: { radius: 15 },
		tr: { radius: 15 },
		bl: { radius: 15 },
		br: { radius: 15 },
		antiAlias: true,
		autoPad: true,
		validTags: ["div"]
	};

	menuTitleSetting = {
		tl: { radius: 7 },
		tr: { radius: 7 },
		bl: { radius: 1 },
		br: { radius: 1 },
		antiAlias: true,
		autoPad: true,
		validTags: ["div"]
	};
	
	menuBodySetting = {
		tl: { radius: 1 },
		tr: { radius: 1 },
		bl: { radius: 7 },
		br: { radius: 7 },
		antiAlias: true,
		autoPad: true,
		validTags: ["div"]
	};

	/*
	Usage:
	
	newCornersObj = new curvyCorners(settingsObj, classNameStr);
	newCornersObj = new curvyCorners(settingsObj, divObj1[, divObj2[, divObj3[, . . . [, divObjN]]]]);
	*/
	var logoDiv = new curvyCorners(logoSetting, "logo-area");
	logoDiv.applyCornersToAll();
	var menuTitle = new curvyCorners(menuTitleSetting, "menu-title");
	menuTitle.applyCornersToAll();
	var menuBody = new curvyCorners(menuBodySetting, "menu-body");
	menuBody.applyCornersToAll();
}

function setContentsRoundCorner() {
	/*
	The new 'validTags' setting is optional and allows
	you to specify other HTML elements that curvyCorners
	can attempt to round.
	
	The value is comma separated list of html elements
	in lowercase.
	
	validTags: ["div", "form"]
	
	The above example would enable curvyCorners on FORM elements.
	*/

	menuTitleSetting = {
		tl: { radius: 7 },
		tr: { radius: 7 },
		bl: { radius: 1 },
		br: { radius: 1 },
		antiAlias: true,
		autoPad: true,
		validTags: ["div"]
	};
	
	menuBodySetting = {
		tl: { radius: 1 },
		tr: { radius: 1 },
		bl: { radius: 7 },
		br: { radius: 7 },
		antiAlias: true,
		autoPad: true,
		validTags: ["div"]
	};

	/*
	Usage:
	
	newCornersObj = new curvyCorners(settingsObj, classNameStr);
	newCornersObj = new curvyCorners(settingsObj, divObj1[, divObj2[, divObj3[, . . . [, divObjN]]]]);
	*/
	var menuBody = new curvyCorners(menuTitleSetting, "contents-title");
	menuBody.applyCornersToAll();
	var menuBody = new curvyCorners(menuBodySetting, "contents-body");
	menuBody.applyCornersToAll();
}

function getDateString(date) {
	var day = date.getDay();
	
	switch(day) {
		case 0:
			return '(日)';
		case 1:
			return '(月)';
		case 2:
			return '(火)';
		case 3:
			return '(水)';
		case 4:
			return '(木)';
		case 5:
			return '(金)';
		case 6:
			return '(土)';
	}
}

function nextWeekday(date) {
	var year = date.getFullYear();
	var month = date.getMonth();
	var day = date.getDate();
	
	for(var i=0; i < holiday.length; i++) {
		var h = holiday[i];
	
		if(date.getFullYear() == h.getFullYear() && date.getMonth() == h.getMonth() && date.getDate() == h.getDate()) {
			date.setTime(date.getTime() + (24 * 60 * 60 * 1000) * 1);
		}
	}
	
	return date;
}

function postYamato(action) {
	var orderDate = document.getElementById('ORDER_PARA_DATE').value;
	
	var year = orderDate.substring(0, 4);
	var month = orderDate.substring(5, 7);
	var day = orderDate.substring(8, 10);
	
	var date = new Date(year, month - 1, day);

	if(orderDate == '') {
		return;
	}
	
	var now = new Date();
	
	if(now.getHours() >= 19) {
		date.setTime(date.getTime() + (24 * 60 * 60 * 1000) * 1);
	}

//	// 土日の場合は、月曜日にカウントUP
//	if(date.getDay() == 6) {
//		date.setTime(new Date(year, month - 1, day).getTime() + (24 * 60 * 60 * 1000) * 2);
//	}　else if(date.getDay() == 0){
//		date.setTime(new Date(year, month - 1, day).getTime() + (24 * 60 * 60 * 1000) * 1);
//	}
//	// 国民の休日以降の日付にカウントUP
//	date = nextWeekday(date);
	alert('GLASS GIREの注文確認日は' + (date.getMonth() + 1) + '/' + date.getDate() + getDateString(date) + 'です。');

	// 注文確認でカウントUP
	date.setTime(date.getTime() + (24 * 60 * 60 * 1000) * 1);
	
//	// 土日の場合は、月曜日にカウントUP
//	if(date.getDay() == 6) {
//		date.setTime(date.getTime() + (24 * 60 * 60 * 1000) * 2);
//	}　else if(date.getDay() == 0){
//		date.setTime(date.getTime() + (24 * 60 * 60 * 1000) * 1);
//	}
//	// 国民の休日以降の日付にカウントUP
//	date = nextWeekday(date);
	alert('GLASS GIREの入金確認日は、最短で' + (date.getMonth() + 1) + '/' + date.getDate() + getDateString(date) + 'です。');

	// 入金確認でカウントUP
	date.setTime(date.getTime() + (24 * 60 * 60 * 1000) * 1);
	
	// 土日の場合は、月曜日にカウントUP
	if(date.getDay() == 6) {
		date.setTime(date.getTime() + (24 * 60 * 60 * 1000) * 2);
	}　else if(date.getDay() == 0){
		date.setTime(date.getTime() + (24 * 60 * 60 * 1000) * 1);
	}
	// 国民の休日以降の日付にカウントUP
	date = nextWeekday(date);
	
	var date2 = new Date(date);
	date2.setTime(date.getTime() - (24 * 60 * 60 * 1000) * 1);
	var date2String = (date2.getMonth() + 1) + '/' + date2.getDate() + getDateString(date2);
	
	alert('商品の発送日は、最短で' + (date.getMonth() + 1) + '/' + date.getDate() + getDateString(date) + 'です。\n(' + date2String+ ' 19:00 までに入金されている必要があります。)');

	document.getElementById('PARA_YEAR').value = date.getFullYear();
	document.getElementById('PARA_MONTH').value = date.getMonth() + 1;
	document.getElementById('PARA_DAY').value = date.getDate();

	document.getElementById('deliveryForm').action = "http://date.kuronekoyamato.co.jp/date/" + action;
	document.getElementById('deliveryForm').submit();
}