/**
 * Various JavaScripts
 */
/*
 * --------------------------------
 * 検索画面で製品選択時、画面を再描画
 */
function refresh(){
	var frm = document.forms[0];
	try{
		frm.fromYear.options[frm.fromYear.selectedIndex].value = null;
		frm.toYear.options[frm.toYear.selectedIndex].value = null;
		frm.publicityDate.value = "";
		uncheckAll(frm.chkmaker);
		uncheckAll(frm.chkrank);
		uncheckAll(frm.searchMode);
	}catch(e){
		//ignore errors
	}
	frm.action = "search.jsp";
	frm.submit();
}
/*
 * Postしつつページ移動
 */
function backto(url){
	var frm = document.forms[0];
	frm.action = url;
	frm.submit();
}
/*
 * --------------------------------
 * checkbox を全部チェック/チェックを外す 
 */ 
function checkAll(field){
	for (i = 0; i < field.length; i++){
		field[i].checked = true ;
	}
	if (field.checked != null){
		field.checked = true ;
	}
}
function uncheckAll(field){
	for (i = 0; i < field.length; i++){
		field[i].checked = false ;
	}
	if (field.checked != null){
		field.checked = false ;
	}
}
/*
 * 検索モード制御
 */
function changeMode(turnon){
//function searchMode(turnon){
	if(turnon){
		document.forms[0].publicityDate.value='';
		document.forms[0].publicityDate.disabled=true;
	}else{
		document.forms[0].publicityDate.disabled=false;
	}
}
/*
 * --------------------------------
 * 検索実行 
 */
function doSearch(){
	var frm = document.forms[0];
	//入力チェック
	//1. 製造年は、【終了年】＞【開始年】
	var fyear=eval("frm.fromYear.options[frm.fromYear.selectedIndex].value");
	var tyear=eval("frm.toYear.options[frm.toYear.selectedIndex].value");
	if (fyear>tyear && tyear!=0){
		alert("製造年（終了年）は開始年より後の年を選択してください");
		frm.toYear.focus();
		return false;
	}
	//2. 【差分検索】日付形式
	var pdate = frm.publicityDate.value;
	var da = pdate.split('/');
	var y = da[0];
	var m = da[1];
	var d = da[2];
	var date = new Date(y, m - 1, d);
	if (pdate==null||pdate==""){
		//ok
	}else if (date.getFullYear() == y && date.getMonth() + 1 == m && date.getDate() == d){
		//valid date
		if(date < new Date(2009, 3, 1)){
			alert("差分検索の日付は、2009/4/1以降の日付のみ入力可能です。");
			frm.publicityDate.focus();
			return false;
		}
	}else{
		alert("日付が正しくありません。差分検索の日付は[年/月/日]の形式で入力してください。");
		frm.publicityDate.focus();
		return false;
	}
	//check ok
	frm.submit();
}

/*
 * --------------------------------
 * QRコード生成
 */
function createQR(){
	var frm = document.forms[0];
	ids = frm.id;
	isChecked = false;
	//選択チェック
	for (i = 0; i < ids.length; i++){
		if(ids[i].checked){
			isChecked = true;
			break;
		}
	}
	if (ids.checked != null){
		if(ids.checked){
			isChecked = true;
		}
	}
	if (isChecked == false){
		alert("製品を選択してください");
		return false;
	}
	frm.submit();
}
/*
 * --------------------------------
 * 検索結果のソート 切り替え
 */
function sortResult(key){
	var frm = document.forms[0];
	frm.sortkey.value = key;
	frm.action = "searchresult.jsp";
	frm.submit();
	return false;
}
