
// フォームクリア
function clearForm(form) {
	$(':input', form).each(function() {
	var type = this.type;
	var tag = this.tagName.toLowerCase(); // normalize case
	if (type == 'text' || type == 'password' || tag == 'textarea')
		this.value = "";
	else if (type == 'checkbox' || type == 'radio')
		this.checked = false;
	else if (tag == 'select')
		this.selectedIndex = 0;
	});
};

// 実行
function doSubmit(prm){
	if(prm==undefined){
		document.form.action = "./submit.php";
	}else{
		document.form.action = prm;
	}
	document.form.submit();
}

// 確認
function doConfirm(prm){
	if(prm==undefined){
		document.form.action = "./confirm.php";
	}else{
		document.form.action = prm;
	}
	document.form.submit();
}

// リセット
function doReset(){
	clearForm(document.form);
}

// 戻る
function goBack(url){
	if(url){
		document.form.action = url;
		document.form.submit();
	}else{
		window.history.back();
	}
}

// 削除
function doDel(no,prm){
	if(window.confirm('削除します。よろしいですか？')){
		document.getElementById("no").setAttribute("value",no);
		document.getElementById("prm").setAttribute("value","del");
//		if(prm.length==1){
//			document.getElementById("cat").setAttribute("value",prm);
//		}
		if(prm==undefined){
			document.form.action = "./submit.php";
		}else{
			if(prm.length==1){
				document.form.action = "./submit.php";
			}else{
				document.form.action = prm;
			}
		}
		document.form.submit();
	}
}

// 詳細
function doContent(no,prm){
		document.getElementById("no").setAttribute("value",no);
		document.getElementById("prm").setAttribute("value","new");
		if(prm==undefined){
			document.form.action = "./content.php";
		}else{
			if(prm.length==1){
				document.form.action = "./content.php";
			}else{
				document.form.action = prm;
			}
		}
		document.form.submit();
}

// 並べ替え
function doSort(prm,mode,cat,url){
		document.getElementById("prm").setAttribute("value",prm);
		document.getElementById("mode").setAttribute("value",mode);
		document.getElementById("cat").setAttribute("value",cat);
		if(url==undefined){
			document.form.action = "./index.php";
		}else{
			document.form.action = url;
		}
		document.form.submit();
}

// 検索
function doSarch(prm,mode){
		document.getElementById("prm").setAttribute("value",prm);
		document.getElementById("mode").setAttribute("value",mode);
		document.form.action = "./index.php";
		document.form.submit();
}

// 選択
function goSELECT(){
		document.form.action = "./index.php";
		document.form.submit();
}

// Enterキー
function submitStop(e){ 
		if (!e) var e = window.event;
		if(e.keyCode == 13)
			goSELECT();
			//return false;
}

// 一覧
function doList(no){
		document.getElementById("no").setAttribute("value",no);
		document.form.action = "./list.php";
		document.form.submit();
}

// 追加
function doInport(no){
		document.getElementById("no").setAttribute("value",no);
		document.getElementById("prm").setAttribute("value","new");
		document.getElementById("mode").setAttribute("value","nest");
		document.form.action = "./content.php";
		document.form.submit();
}

// 追加詳細
function doSubContent(no){
		document.getElementById("no").setAttribute("value",no);
		document.getElementById("prm").setAttribute("value","");
		document.getElementById("mode").setAttribute("value","nest");
		document.form.action = "./content.php";
		document.form.submit();
}

// アップロード
function subMit(prm,pid,psel){
	//var addr = prm.value;
	var addr = prm;
	
	if(pid == 'img'){
		if(addr.match(/\.(jpg|jpg)$/i)){}
		else{
			//var obj = document.getElementById(pid);
			//var stO = obj.innerHTML;
			//obj.innerHTML = stO;
			alert('登録できる画像の拡張子は jpg です。');
		}
	} else if (pid == 'pdf'){
		if(psel==0){
			if(addr.match(/\.(jpg|jpg)$/i)){}
			else{
				//var obj = document.getElementById(pid);
				//var stO = obj.innerHTML;
				//obj.innerHTML = stO;
				alert('登録できる画像の拡張子は jpg です。');
			}
		}else{
			if(addr.match(/\.(pdf|pdf)$/i)){}
			else{
				//var obj = document.getElementById(pid);
				//var stO = obj.innerHTML;
				//obj.innerHTML = stO;
				alert('登録できるファイルの拡張子は pdf です。');
			}
		}
	}
}

// 新着詳細遷移
function doNewsContent(no,prm){
		document.getElementById("no").setAttribute("value",no);
		if(prm=='news'){
		document.form.action = "/news/details.php";
		}else if(prm=='ir'){
		document.form.action = "/ir/details.php";
		}else if(prm=='csr'){
		document.form.action = "/csr/detail.php";
		}else{
		document.form.action = "/index.php";
		}
		document.form.submit();
}

// 新着一覧遷移
function doNewsList(no,prm){
		document.getElementById("no").setAttribute("value",no);
		if(prm=='I'){
		document.form.action = "./index.php";
		}else if(prm=='O'){
		document.form.action = "./oshirase.php";
		}else if(prm=='N'){
		document.form.action = "./news.php";
		}else if(prm=='C'){
		document.form.action = "./calender.php";
		}else if(prm=='S'){
		document.form.action = "./syoken.php";
		}else if(prm=='K'){
		document.form.action = "./kessan.php";
		}else if(prm=='I'){
		document.form.action = "./otehr_ir.php";
		}else if(prm=='R'){
		document.form.action = "./c_news.php";
		}else{
		document.form.action = "/index.php";
		}
		document.form.submit();
}

// カテゴリページ遷移
function doPageContent(no){
		document.getElementById("no").setAttribute("value",no);
		document.form.action = "./index.php";
		document.form.submit();
}

