var oElement = "";
//各種ポップアップウィンドウ幅・高さ
var new_win_width = "800";
var new_win_height = "750";
//ファイルアップロード様ウィンドウ幅・高さ
var new_win_upload_width = "500";
var new_win_upload_height = "50";
var obj_action_type = "";
var obj_kisyu_type = "";
var obj_search_mode = "";

//	ユーザページ用
function createHttpRequest() {
	if(window.ActiveXObject) {
		try {
			return new ActiveXObject("Msxml2.XMLHTTP") ;
		} catch (e) {
			try {
				return new ActiveXObject("Microsoft.XMLHTTP") ;
			} catch (e) {
				return null ;
 			}
 		}
	} else if(window.XMLHttpRequest){
		return new XMLHttpRequest() ;
	} else {
		return null ;
	}
}

function sendRequest(callback,data,method,url,async) {
	var obj = createHttpRequest();
	if( obj == null ) return null;

	//ブラウザ判定
	var ua = navigator.userAgent;
	var safari	= ua.indexOf("Safari")!=-1;
	var konqueror = ua.indexOf("Konqueror")!=-1;
	var mozes	 = ((a=navigator.userAgent.split("Gecko/")[1] ) ?a.split(" ")[0]:0) >= 20011128 ;

	//受信処理
	if(window.opera || safari || mozes){
		obj.onload = function () { callback(obj); }
	} else {
		obj.onreadystatechange =function () {
			if (obj.readyState == 4) {
				if (obj.status == 200) {
					callback(obj);
				} else {
			//		alert("非同期通信に失敗しました。\nCODE："+obj.status);
				}
			}
		}
	}

	//URLエンコード
	if(method == 'GET') {
		var encdata = '';
		var datas = data.split('&');
		for(i=0;i<datas.length;i++) {
			var dataq = datas[i].split('=');
			encdata += '&'+encodeURI(dataq[0])+'='+encodeURI(dataq[1]);
		}
		url=url + encodeURI(data);
	}

	//open メソッド
	obj.open(method,url,async);

	//ヘッダセット
	if(method == 'POST') {
		if(!window.opera)
			obj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	} 

	//send メソッド
	obj.send(data);
}

function get_zip(area_id) {
	dataFileName = '/user/get_zip.php';
	if (area_id == "c") {
//		zip_obj = new String(main_form.company_zip.value);
		zip_obj = document.getElementById('company_zip').value;
		if (zip_obj.length<3) {
			alert('郵便番号を入力してください');
			return false;
		} else if (zip_obj.length>3) {
			alert('郵便番号の入力が不正です');
			return false;
		} else {
			zip_1 = document.getElementById('company_zip').value;
		}
//		zip2_obj = new String(main_form.company_zip2.value);
		zip2_obj = document.getElementById('company_zip2').value;
		if (zip2_obj.length > 4) {
			alert('郵便番号の入力が不正です');
			return false;
		} else if (zip2_obj.length <= 4) {
			zip_2 = document.getElementById('company_zip2').value;
			for (i=0;i<(4 - zip2_obj.length);i++) {
				zip_2 += "0";
			}
		}
		data = "&zip="+zip_1+zip_2;
		sendRequest(receive_company_address,data,'POST',dataFileName,true)
	} else if (area_id == "t") {
//		zip_obj = new String(main_form.tenpo_zip.value);
		zip_obj = document.getElementById('tenpo_zip').value;
		if (zip_obj.length<3) {
			alert('郵便番号を入力してください');
			return false;
		} else if (zip_obj.length>3) {
			alert('郵便番号の入力が不正です');
			return false;
		} else {
			zip_1 = document.getElementById('tenpo_zip').value;
		}
//		zip2_obj = new String(main_form.tenpo_zip2.value);
		zip2_obj = document.getElementById('tenpo_zip2').value;
		if (zip2_obj.length > 4) {
			alert('郵便番号の入力が不正です');
			return false;
		} else if (zip2_obj.length <= 4) {
			zip_2 = document.getElementById('tenpo_zip2').value;
			for (i=0;i<(4 - zip2_obj.length);i++) {
				zip_2 += "0";
			}
		}
		data = "&zip="+zip_1+zip_2;
		sendRequest(receive_tenpo_address,data,'POST',dataFileName,true)
	}
}

function receive_company_address(res) {
	var resdata = res.responseText;
	var datas = resdata.split(',');
	if (datas[3]) {
		if(document.getElementById('company_prf').selectedIndex == 0) {
			document.getElementById('company_prf').selectedIndex = datas[3];
		}
	}
	if (datas[4] != "以下に掲載がない場合") { city_data = datas[4]; }
	if (datas[6] != "以下に掲載がない場合") { city_data += datas[6]; }
	if (city_data) { document.getElementById('company_city').value = city_data; }
}

function receive_tenpo_address(res) {
	var resdata = res.responseText;
	var datas = resdata.split(',');
	if (datas[3]) {
		if(document.getElementById('tenpo_prf').selectedIndex == 0) {
			document.getElementById('tenpo_prf').selectedIndex = datas[3];
		}
	}
	if (datas[4] != "以下に掲載がない場合") { city_data = datas[4]; }
	if (datas[6] != "以下に掲載がない場合") { city_data += datas[6]; }
	if (city_data) { document.getElementById('tenpo_city').value = city_data; }
}

function get_zip_tenpo(tenpo_num) {
	dataFileName = '/admin/get_zip.php';

	var zip1 = 'tenpo_zip__'+tenpo_num;
	zip_obj = document.getElementById(zip1).value;
	if (zip_obj.length<3) {
		alert('郵便番号を入力してください');
		return false;
	} else if (zip_obj.length>3) {
		alert('郵便番号の入力が不正です');
		return false;
	} else {
		zip_1 = zip_obj;
	}
	var zip2 = 'tenpo_zip2__'+tenpo_num;
	zip2_obj = document.getElementById(zip2).value;
	if (zip2_obj.length > 4) {
		alert('郵便番号の入力が不正です');
		return false;
	} else if (zip2_obj.length <= 4) {
		zip_2 = zip2_obj;
		for (i=0;i<(4 - zip2_obj.length);i++) {
			zip_2 += "0";
		}
	}
	data = "&zip="+zip_1+zip_2;
	data += "&tenpo_num="+tenpo_num;
	sendRequest(receive_tenpo_address2,data,'POST',dataFileName,true);
	return false;
}

function receive_tenpo_address2(res) {
	var resdata = res.responseText;
	var datas = resdata.split(',');
	if (datas[8]) {
		var prf = 'tenpo_prf__'+datas[8];
		var city = 'tenpo_city__'+datas[8];
	}
	if (datas[3]) {
		if(document.getElementById(prf).selectedIndex == 0) {
			document.getElementById(prf).selectedIndex = datas[3];
		}
	}
	if (datas[4] != "以下に掲載がない場合") { city_data = datas[4]; }
	if (datas[6] != "以下に掲載がない場合") { city_data += datas[6]; }
	if (city_data) { document.getElementById(city).value = city_data; }
}

function form_disabled(check,target){
	var check_obj = document.getElementById(check);
	var oElement = document.getElementById(target);
	var input_parts = oElement.getElementsByTagName("input");
	var select_parts = oElement.getElementsByTagName("select");
	if (check_obj.checked) {
		var para = "true";
	} else {
		var para = "false";
	}
	for (i = 0; i < input_parts.length; i++) {
		if (i == 0) { continue; }
		input_parts[i].disabled = eval(para);
	}
	for (i = 0; i < select_parts.length; i++) {
		select_parts[i].disabled = eval(para);
	}
}

function form_display(key,target){
	var oElement = document.getElementById(target);
	if (key) {
		para = "none";
	} else {
		para = "block";
	}
	oElement.style.display = para;
}

function get_article_area(company_num,kisyu_type,state,page,action_type) {
	dataFileName = '/user/get_mypage_article.php';
	data = "&company_num="+company_num;
	data += "&kisyu_type="+kisyu_type;
	data += "&state="+state;
	data += "&action_type="+action_type;
	data += "&page="+page;
	sendRequest(receive_article_table,data,'POST',dataFileName,true)
	obj_kisyu_type = kisyu_type;
	obj_search_mode = "mypage";
	obj_action_type = action_type;
//	get_search_area('mypage',kisyu_type);

	return false;
}

function sort_article_area(company_num,kisyu_type,state,sort_key) {
	dataFileName = '/user/get_mypage_article.php';
	data = "&company_num="+company_num;
	data += "&kisyu_type="+kisyu_type;
	data += "&state="+state;
	data += "&sort_key="+sort_key;
	data += "&page=1";
	sendRequest(receive_article_table,data,'POST',dataFileName,true)
	obj_kisyu_type = kisyu_type;
	obj_search_mode = "mypage";
	obj_action_type = "";

	return false;
}

function get_search_article_area(kisyu_type,page) {
	dataFileName = '/user/get_search_article.php';
	data = "&kisyu_type="+kisyu_type;
	data += "&page="+page;

	sendRequest(receive_article_table,data,'POST',dataFileName,true)
	obj_kisyu_type = kisyu_type;
	obj_search_mode = "search";
	if (page != "1") { obj_action_type = "page"; }
	else { obj_action_type = "menu"; }
	return false;
}

function sort_search_article_area(kisyu_type,sort_key) {
	dataFileName = '/user/get_search_article.php';
	data = "&kisyu_type="+kisyu_type;
	data += "&sort_key="+sort_key;
	data += "&page=1";

	sendRequest(receive_article_table,data,'POST',dataFileName,true)
	obj_kisyu_type = kisyu_type;
	obj_search_mode = "search";
	obj_action_type = "page";

	return false;
}

function get_company_article_area(company_num,kisyu_type,page,action_type) {
	dataFileName = '/user/get_company_article.php';
	data = "&company_num="+company_num;
	data += "&kisyu_type="+kisyu_type;
	data += "&action_type="+action_type;
	data += "&page="+page;

	sendRequest(receive_article_table,data,'POST',dataFileName,true)
	obj_kisyu_type = kisyu_type;
	obj_search_mode = "search";
	obj_action_type = action_type;

	return false;
}

function sort_company_article_area(company_num,kisyu_type,sort_key) {
	dataFileName = '/user/get_company_article.php';
	data = "&kisyu_type="+kisyu_type;
	data += "&sort_key="+sort_key;
	data += "&page=1";

	sendRequest(receive_article_table,data,'POST',dataFileName,true)
	obj_kisyu_type = kisyu_type;
	obj_search_mode = "search";
	obj_action_type = "page";

	return false;
}

function receive_article_table(res) {
	var referer_name = "";
	var resdata = res.responseText;
	document.getElementById('article_list').innerHTML = resdata;

	if (document.getElementById('referer_name')) { referer_name = document.getElementById('referer_name').value; }
	else { referer_name = ""; }
	if (obj_action_type != "page" || referer_name == "prev") {
		if (referer_name == "prev") { document.getElementById('referer_name').value = ""; }
		get_search_area(obj_search_mode,obj_kisyu_type);
	}
}

function set_object_search_mode (mode) {
	obj_search_mode = mode;
}

function get_search_area(mode,kisyu_type) {
	dataFileName = '/user/get_search_area.php';
	data = "&mode="+mode;
	data += "&kisyu_type="+kisyu_type;
	sendRequest(receive_search_table,data,'POST',dataFileName,true)

	return false;
}

function receive_search_table(res) {
	var resdata = res.responseText;
	document.getElementById('search_area').innerHTML = resdata;
	set_kisyu_list(document.getElementById('maker_num').options[document.getElementById('maker_num').options.selectedIndex].value,obj_kisyu_type);
	if (obj_search_mode == "search") {
		set_login_info();
	}
}

function keisai_form(mode,company_num,kisyu_type,key) {
	FileName = '/user/keisai.php';
	var target = "keisai_form";
	var keisai = window.open(FileName,target,'width='+new_win_width+',height='+new_win_height+',scrollbars=yes,resizable=yes');

	// formを生成
	var form = document.createElement("form");
	form.action = FileName;
	form.target = target;
	form.method = 'post';
	// input-hidden生成と設定
	var input = document.createElement("input");
	input.setAttribute('type','hidden');
	input.setAttribute('name','mode');
	input.setAttribute('value',mode);
	form.appendChild(input);
	var input = document.createElement("input");
	input.setAttribute('type','hidden');
	input.setAttribute('name','action');
	input.setAttribute('value','keisai');
	form.appendChild(input);
	var input = document.createElement("input");
	input.setAttribute('type','hidden');
	input.setAttribute('name','company_num');
	input.setAttribute('value',company_num);
	form.appendChild(input);
	var input = document.createElement("input");
	input.setAttribute('type','hidden');
	input.setAttribute('name','kisyu_type');
	input.setAttribute('value',kisyu_type);
	form.appendChild(input);
	var input = document.createElement("input");
	input.setAttribute('type','hidden');
	input.setAttribute('name','key');
	input.setAttribute('value',key);
	form.appendChild(input);
	// formをbodyに追加して、サブミットする。その後、formを削除
	var body = document.getElementsByTagName("body")[0];
	body.appendChild(form);
	form.submit();
	body.removeChild(form);

	keisai.focus();
}

function kisyu_check(num) {
	var kisyu_id = "keisai_kisyu_num";
	var syubetu_id = "keisai_syubetu";
	if (num !== "") {
		kisyu_id += "__"+num;
		syubetu_id += "__"+num;
	}
	oElement = document.getElementById(kisyu_id);
	var option_num = oElement.options.selectedIndex;
	var kisyu_name = oElement.options[option_num].innerHTML;
	if (kisyu_name.match(/(の枠)/)) {
		document.getElementById(syubetu_id).value = 3;
	} else { document.getElementById(syubetu_id).value = 1; }
	syubetu_check(num);
}

function zansai_check(num) {
	var zansai_id = "keisai_zansai";
	var zansai_date_id = "zansai_date_area";
	if (num !== "") {
		zansai_id += "__"+num;
		zansai_date_id += "_"+num;
	}
	oElement = document.getElementById(zansai_id);
	var zansai_num = oElement.options.value;
	var zansai = "hidden";
	if (zansai_num == 2) { zansai = "visible"; }

	document.getElementById(zansai_date_id).style.visibility = zansai;
}

function tekyo_check(num,key) {
	var tekyo_date_id = "tekyo_date_area";
	if (num !== "") {
		tekyo_date_id += "_"+num;
	}
	var tekyo = "hidden";
	if (key == 0) { tekyo = "visible"; }

	document.getElementById(tekyo_date_id).style.visibility = tekyo;
}

function price_value_chenge(num,type) {
	var ousoudan_id = "keisai_ousoudan";
	var price_id = "keisai_price";
	var para = "";
	var price = "";
	if (num !== "") {
		ousoudan_id += "__"+num;
		price_id += "__"+num;
	}
	oElement = document.getElementById(ousoudan_id);
	if (oElement.checked) { para = "true"; price = "応相談"; }
	else {
		para = "false";
		if (type == "check") { price = ""; }
		else { price = document.getElementById(price_id).value; }
	}
//	document.getElementById(price_id).disabled = eval(para);
	document.getElementById(price_id).readOnly = eval(para);
	document.getElementById(price_id).value = price;
}

function syubetu_check(num) {
	var syubetu_id = "keisai_syubetu";
//	var sell_gara_id = "sell_gara_area";
	var sell_text_id = "sell_text_area";
//	var wakuiro_id = "wakuiro_area";
	var wakusel_id = "wakusel_area";
//	var cylin_td_1_id = "cylin_td_1";
	var cylin_td_2_id = "cylin_td_2";
//	var glass_td_1_id = "glass_td_1";
	var glass_td_2_id = "glass_td_2";
	if (num !== "") {
		syubetu_id += "__"+num;
//		sell_gara_id += "_"+num;
		sell_text_id += "_"+num;
//		wakuiro_id += "_"+num;
		wakusel_id += "_"+num;
//		cylin_td_1_id += "_"+num;
		cylin_td_2_id += "_"+num;
//		glass_td_1_id += "_"+num;
		glass_td_2_id += "_"+num;
	}

	oElement = document.getElementById(syubetu_id);
	syubetu_num = oElement.value;
//	if (document.getElementById(sell_gara_id).innerHTML !="") { sell_gara_in = document.getElementById(sell_gara_id).innerHTML; }
	if (document.getElementById(sell_text_id).innerHTML !="") { sell_text_in = document.getElementById(sell_text_id).innerHTML; }
//	if (document.getElementById(wakuiro_id).innerHTML !="") { wakuiro_in = document.getElementById(wakuiro_id).innerHTML; }
	if (document.getElementById(wakusel_id).innerHTML !="") { wakusel_in = document.getElementById(wakusel_id).innerHTML; }
//	if (document.getElementById(cylin_td_1_id).innerHTML !="") { cylin_td_1_in = document.getElementById(cylin_td_1_id).innerHTML; }
	if (document.getElementById(cylin_td_2_id).innerHTML !="") { cylin_td_2_in = document.getElementById(cylin_td_2_id).innerHTML; }
//	if (document.getElementById(glass_td_1_id).innerHTML !="") { glass_td_1_in = document.getElementById(glass_td_1_id).innerHTML; }
	if (document.getElementById(glass_td_2_id).innerHTML !="") { glass_td_2_in = document.getElementById(glass_td_2_id).innerHTML; }

//	document.getElementById(sell_gara_id).innerHTML = sell_gara_in;
	document.getElementById(sell_text_id).innerHTML = sell_text_in;
//	document.getElementById(wakuiro_id).innerHTML = wakuiro_in;
	document.getElementById(wakusel_id).innerHTML = wakusel_in;
//	document.getElementById(cylin_td_1_id).innerHTML = cylin_td_1_in;
	document.getElementById(cylin_td_2_id).innerHTML = cylin_td_2_in;
//	document.getElementById(glass_td_1_id).innerHTML = glass_td_1_in;
	document.getElementById(glass_td_2_id).innerHTML = glass_td_2_in;
	if (syubetu_num == 3) {
//		document.getElementById(sell_gara_id).innerHTML = "";
		document.getElementById(sell_text_id).innerHTML = "";
	} else if (syubetu_num == 2) {
//		document.getElementById(cylin_td_1_id).innerHTML = "";
		document.getElementById(cylin_td_2_id).innerHTML = "";
//		document.getElementById(glass_td_1_id).innerHTML = "";
		document.getElementById(glass_td_2_id).innerHTML = "";
//		document.getElementById(wakuiro_id).innerHTML = "";
		document.getElementById(wakusel_id).innerHTML = "";
	}
}

function get_wakuiro_list(num) {
	dataFileName = '/user/get_keisai_item.php';
	var maker_id = "keisai_maker_num";
	if (num !== "") {
		maker_id += "__"+num;
	}

	oElement = document.getElementById(maker_id);
	data = "&array_type=wakuiro";
	data += "&num="+num;
	data += "&maker_num="+oElement.value;

	sendRequest(receive_wakuiro_list,data,'POST',dataFileName,true);
}

function receive_wakuiro_list(res) {
	var resdata = res.responseText;
	var datas = resdata.split(',');
	var num = datas[0];
	var wakuiro_id = "wakuiro_select_area";
	if (num !== "") {
		wakuiro_id += "_"+num;
	}
	if (document.getElementById(wakuiro_id)) {
		document.getElementById(wakuiro_id).innerHTML = datas[1];
	}
}

function get_kisyu_list(num,kisyu_type) {
	dataFileName = '/user/get_keisai_item.php';
	var maker_id = "keisai_maker_num";
	var syubetu_id = "keisai_syubetu";
	if (num !== "") {
		maker_id += "__"+num;
		syubetu_id += "__"+num;
	}
	if(document.getElementById(syubetu_id)) { document.getElementById(syubetu_id).value = 1; syubetu_check(num); }
	oElement = document.getElementById(maker_id);
	data = "&array_type=kisyu";
	data += "&num="+num;
	data += "&maker_num="+oElement.value;
	data += "&kisyu_type="+kisyu_type;
	sendRequest(receive_kisyu_list,data,'POST',dataFileName,true);
}

function receive_kisyu_list(res) {
	var resdata = res.responseText;
	var datas = resdata.split(',');
	var num = datas[0];
	var kisyu_id = "kisyu_select_area";
	if (num !== "") {
		kisyu_id += "_"+num;
	}
	document.getElementById(kisyu_id).innerHTML = datas[1];
}

function option_form_display(num,type) {
	var option_id = "keisai_option_display";
	var table_id = "option_table";
	if (num !== "") {
		option_id += "__"+num;
		table_id += "_"+num;
	}

	oElement = document.getElementById(option_id);
	if (oElement.value == "") { oElement.value = "none"; }
	if (type == "chenge") {
		if (oElement.value == "none") { para = "block"; }
		else if (oElement.value == "block") { para = "none"; }
	} else {
		var para = oElement.value;
	}
	document.getElementById(table_id).style.display = para;
	oElement.value = para;
}

function article_action(key,action){
	dataFileName = '/user/get_mypage_article.php';

	if (key == "check") {
		var keys = new Array();
		var j = 0;
		check_obj = document.main_form.bukken_box;
		if (check_obj.value) {
			keys = check_obj.getAttribute("value");
		} else {
			for (i = 0; i < check_obj.length; i++) {
				if (check_obj[i].checked) { keys[j] = check_obj[i].value; j++; }
			}
		}
		if (keys == "") { alert('チェックボックスが選択されていません。'); return false; }
		data = "&key="+keys;
	} else {
		data = "&key="+key;
	}
	data += "&action="+action;
	if (action == "delete") {
		var msg = "本当に削除してもよろしいですか？";
	} else if (action == "uptime") {
		var msg = "本当に更新してもよろしいですか？";
	} else if (action == "seiyaku") {
		var msg = "本当に成約にしてもよろしいですか？";
	} else if (action == "souko") {
		var msg = "本当に倉庫にしてもよろしいですか？";
	} else if (action == "keisai") {
		var msg = "本当に掲載してもよろしいですか？";
	} else if (action == "update") {
		var msg = "本当に変更してもよろしいですか？";
		var daisu = document.getElementById('keisai_daisu__'+key).value;
		var price = document.getElementById('keisai_price__'+key).value;
		if (document.getElementById('keisai_buyer__'+key)) {
			var buyer = document.getElementById('keisai_buyer__'+key).value;
		} else { var buyer = ""; }
		if (document.getElementById('keisai_memo__'+key)) {
			var memo = document.getElementById('keisai_memo__'+key).value;
		} else { var memo = ""; }
		if (daisu == "") { alert('台数が未入力です。'); return false; }
		else if (!daisu.match(/[0-9]/)) { alert('台数は半角数字で入力して下さい。'); return false; }
		else if (daisu < 1) { alert('台数の入力が不正です。0以下は設定できません。'); return false; }
		if (price == "") { alert('希望価格が未入力です。'); return false; }
		else if (!price.match(/[0-9]|(応相談)/)) { alert('希望価格は半角数字か応相談で入力してください。'); return false; }
		else if (price < 1) { alert('希望価格の入力が不正です。0以下は設定できません。'); return false; }
		if (buyer.length > 30) { alert('売り先の入力が不正です。30字以内で記述して下さい。'); return false; }
		if (memo.length > 50) { alert('メモの入力が不正です。50字以内で記述して下さい。'); return false; }
		data += "&daisu="+daisu;
		data += "&price="+price;
		data += "&buyer="+buyer;
		data += "&memo="+memo;
	}
	if (confirm(msg)) { sendRequest(receive_article_table,data,'POST',dataFileName,true) }
}

function check_set_all() {
	var para = document.getElementById('all_check').checked;
	var check_obj = document.main_form.bukken_box;

	if (check_obj.value) {
		document.getElementById(check_obj.getAttribute("id")).checked = para;
	} else {
		for (i = 0; i < check_obj.length; i++) {
			check_obj[i].checked = eval(para);
		}
	}
}

function check_set_box() {
	var check_obj = document.main_form.bukken_box;

	var para = "true";
	if (check_obj.value) {
		para = document.getElementById(check_obj.getAttribute("id")).checked;
	} else {
		for (i = 0; i < check_obj.length; i++) {
			if (!check_obj[i].checked) {
				para = "false";
				break;
			}
		}
	}
	document.getElementById('all_check').checked = eval(para);
}

function search_action(mode) {
	dataFileName = '/user/get_'+mode+'_article.php';
	if (mode == "company") {
		var search_word = document.getElementById('search_word').value;
		if (search_word == "通称名・型式名の一部を入力して下さい。") { search_word = ""; }
		data = "&action=search";
		data += "&search_word="+search_word;
	} else {
		var maker_num = document.getElementById('maker_num').value;
		var kisyu_name = document.getElementById('kisyu_name').value;
		var price = document.getElementById('price').value;
		if (document.getElementById('syubetu')) {
			var syubetu = document.getElementById('syubetu').value;
		} else { var syubetu = ""; }
		var bukken_num = document.getElementById('bukken_num').value;
		var view_num = document.getElementById('view_num').value;
		if (document.getElementById('secchi')) {
			var secchi = document.getElementById('secchi').value;
		} else { var secchi = ""; }
		if (document.getElementById('daisu_min')) {
			var daisu_min = document.getElementById('daisu_min').value;
		} else {
			var daisu_min = "";
		}
		if (document.getElementById('daisu_max')) {
			var daisu_max = document.getElementById('daisu_max').value;
		} else {
			var daisu_max = "";
		}
		if (daisu_min == 0) { daisu_min = ""; }
		if (daisu_max.match(/\D/gi)) { alert("台数設定は数字で入力してください。"); return false; }
		if (daisu_max == 0) { daisu_max = ""; }
		if (daisu_min.length > 0 && daisu_max.length > 0) {
			if (daisu_min - daisu_max > 0) { alert("台数設定の入力が不正です。"); return false; }
		}

		data = "&action=search";
		data += "&maker_num="+maker_num;
		data += "&kisyu_name="+kisyu_name;
		data += "&price="+price;
		data += "&syubetu="+syubetu;
		data += "&bukken_num="+bukken_num;
		data += "&view_num="+view_num;
		data += "&secchi="+secchi;
		data += "&daisu_min="+daisu_min;
		data += "&daisu_max="+daisu_max;
	}

	sendRequest(receive_article_table,data,'POST',dataFileName,true);
}

function document_form(win_name,mode,key,kisyu_type) {
	FileName = '/user/'+win_name+'.php';
	var target = "document_form";
	var doc_window = window.open(FileName,target,'width='+new_win_width+',height='+new_win_height+',scrollbars=yes,resizable=yes');

	// formを生成
	var form = document.createElement("form");
	form.action = FileName;
	form.target = target;
	form.method = 'post';
	// input-hidden生成と設定
	var input = document.createElement("input");
	input.setAttribute('type','hidden');
	input.setAttribute('name','mode');
	input.setAttribute('value',mode);
	form.appendChild(input);
	var input = document.createElement("input");
	input.setAttribute('type','hidden');
	input.setAttribute('name','action');
	input.setAttribute('value',win_name);
	form.appendChild(input);
	var input = document.createElement("input");
	input.setAttribute('type','hidden');
	input.setAttribute('name','key');
	input.setAttribute('value',key);
	form.appendChild(input);
	var input = document.createElement("input");
	input.setAttribute('type','hidden');
	input.setAttribute('name','kisyu_type');
	input.setAttribute('value',kisyu_type);
	form.appendChild(input);
	// formをbodyに追加して、サブミットする。その後、formを削除
	var body = document.getElementsByTagName("body")[0];
	body.appendChild(form);
	form.submit();
	body.removeChild(form);

	doc_window.focus();
}

function open_win_comp_action() {
	if (!window.opener.document.getElementById('hyo_tt')) { return false; }

	dataFileName = '/user/get_mypage_article.php';
	data = "&action_type=page";

	sendRequest(close_receive_article_table,data,'POST',dataFileName,true);
}

function close_receive_article_table(res) {
	var resdata = res.responseText;
	window.opener.document.getElementById('article_list').innerHTML = resdata;
}

function inquiry_form(mode,key,kisyu_type,toiawase_type) {
	FileName = '/user/inquiry.php';
	var target = "inquiry_form";
	var inq_window = window.open(FileName,target,'width='+new_win_width+',height='+new_win_height+',scrollbars=yes,resizable=yes');
	var html = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">';
	html += '<html lang="ja">';
	html += '<head>';
	html += '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">';
	html += '<meta http-equiv="Content-Style-Type" content="text/css">';
	html += '<title></title>';
	html += '</head>';
	html += '<body>';
	html += '</body>';
	html += '</html>';
	inq_window.document.open();
	inq_window.document.write(html);
	inq_window.document.close();

	// formを生成
	var form = document.createElement("form");
	form.action = FileName;
	form.target = target;
	form.method = 'post';
	// input-hidden生成と設定
	var input = document.createElement("input");
	input.setAttribute('type','hidden');
	input.setAttribute('name','mode');
	input.setAttribute('value',mode);
	form.appendChild(input);
	var input = document.createElement("input");
	input.setAttribute('type','hidden');
	input.setAttribute('name','action');
	input.setAttribute('value','inquiry');
	form.appendChild(input);
	var input = document.createElement("input");
	input.setAttribute('type','hidden');
	input.setAttribute('name','key');
	input.setAttribute('value',key);
	form.appendChild(input);
	var input = document.createElement("input");
	input.setAttribute('type','hidden');
	input.setAttribute('name','kisyu_type');
	input.setAttribute('value',kisyu_type);
	form.appendChild(input);
	var input = document.createElement("input");
	input.setAttribute('type','hidden');
	input.setAttribute('name','toiawase_type');
	input.setAttribute('value',toiawase_type);
	form.appendChild(input);
	// formをbodyに追加して、サブミットする。その後、formを削除
	var body = document.getElementsByTagName("body")[0];
	body.appendChild(form);
	form.submit();
	body.removeChild(form);

	inq_window.focus();
}

function trade_flg_change(key){
	dataFileName = '/user/set_trade_flg.php';

	data = "&trade_flg="+key;

	sendRequest(receive_trade_flg,data,'POST',dataFileName,true)
}

function receive_trade_flg(res) {
	var resdata = res.responseText;
	if (resdata) { document.getElementById('error_area').innerHTML = resdata; }
	
}

function auto_win_close(time) {
	setTimeout('self.close()',time);
}

function get_member_menu_area(company_num) {
	dataFileName = '/user/get_member_menu.php';
	data = "&company_num="+company_num;

	sendRequest(receive_member_menu_area,data,'POST',dataFileName,true)

	return false;
}

function receive_member_menu_area(res) {
	var resdata = res.responseText;
	document.getElementById('member_menu_area').innerHTML = resdata;
}

function hidebutton(mode) {
	var mode_id = mode + '_tt';
	var mode_btn = mode + '_btn';
	document.getElementById(mode_id).style.visibility = "hidden";
	document.getElementById(mode_id).style.display = "none";
	document.getElementById(mode_btn).style.visibility = "hidden";
	document.getElementById(mode_btn).style.display = "none";
}

function showbutton(mode) {
	var mode_id = mode + '_tt';
	var mode_btn = mode + '_btn';
	document.getElementById(mode_id).style.visibility = "visible";
	document.getElementById(mode_id).style.display = "block";
	document.getElementById(mode_btn).style.visibility = "visible";
	document.getElementById(mode_btn).style.display = "block";
}

function search_reset(id,mode) {
	document.getElementById(id).value = "";

	set_textbox(id);
	search_action(mode);

	return false;
}

function get_hensin_list(company_num) {
	dataFileName = '/user/get_hensin_item.php';
	oElement = document.getElementById('toiawase_user_num');
	data = "&company_num="+company_num;
	data += "&user_num="+oElement.value;
	sendRequest(receive_hensin_list,data,'POST',dataFileName,true);
}

function receive_hensin_list(res) {
	var resdata = res.responseText;
	var datas = resdata.split(',');

	document.getElementById('tel_type_list').innerHTML = datas[0];
	document.getElementById('mail_type_list').innerHTML = datas[1];
}

function limit_flg_change(){
	dataFileName = '/user/set_limit_flg.php';
	oElement = document.getElementById('limit_flg');
	var limit_flg = oElement.options[oElement.options.selectedIndex].value;

	data = "&limit_flg="+limit_flg;

	sendRequest(receive_trade_flg,data,'POST',dataFileName,true)
}

function receive_trade_flg(res) {
	var resdata = res.responseText;
	if (resdata) { document.getElementById('error_area').innerHTML = resdata; }
	
}

function limit_company_search() {
	FileName = '/user/limit_company_search.php';
	var company_name = document.getElementById('limit_company_name').value;

	if (company_name == "") {
		alert('検索内容が入力されていません。\n検索したい会社名または会社名の一部を入力して下さい。');
		return;
	}
	var target = "limit_company_search";
	var search_window = window.open(FileName,target,'width='+new_win_width+',height='+new_win_height+',scrollbars=yes,resizable=yes');

	// formを生成
	var form = document.createElement("form");
	form.action = FileName;
	form.target = target;
	form.method = 'post';
	// input-hidden生成と設定
	var input = document.createElement("input");
	input.setAttribute('type','hidden');
	input.setAttribute('name','mode');
	input.setAttribute('value','limit_company_search');
	form.appendChild(input);
	var input = document.createElement("input");
	input.setAttribute('type','hidden');
	input.setAttribute('name','action');
	input.setAttribute('value','set_search');
	form.appendChild(input);
	var input = document.createElement("input");
	input.setAttribute('type','hidden');
	input.setAttribute('name','company_name');
	input.setAttribute('value',company_name);
	form.appendChild(input);
	// formをbodyに追加して、サブミットする。その後、formを削除
	var body = document.getElementsByTagName("body")[0];
	body.appendChild(form);
	form.submit();
	body.removeChild(form);

	search_window.focus();
}

function set_limit_company(sendaction,formname,key) {
	var company_name = document.getElementById('company_'+key).innerHTML;
	var msg = company_name+"を制限しますか？";
	if (confirm(msg)) { set_action(sendaction,formname,key); }
}

function get_limit_company_list(key,action,window_name){
	dataFileName = '/user/get_limit_company_list.php';

	data = "&limit_list=load";
	data += "&key="+key;
	data += "&action="+action;

	if (window_name == "main") { sendRequest(receive_limit_company_list,data,'POST',dataFileName,true) }
	else if (window_name == "open") { sendRequest(close_receive_limit_company_list,data,'POST',dataFileName,true) }
}

function receive_limit_company_list(res) {
	var resdata = res.responseText;
	document.getElementById('limit_company_list').innerHTML = resdata;
}

function close_receive_limit_company_list(res) {
	var resdata = res.responseText;
	window.opener.document.getElementById('limit_company_list').innerHTML = resdata;
}

function limit_company_delete(key,action) {
	var company_name = document.getElementById('company_'+key).innerHTML;
	var msg = company_name+"の制限を解除しますか？";
	if (confirm(msg)) { get_limit_company_list(key,action,'main'); }
}

function file_manage_list() {
	FileName = '/user/file_manage.php';
	var target = "file_manage_list";
	var list_window = window.open(FileName,target,'width='+new_win_width+',height='+new_win_height+',scrollbars=yes,resizable=yes');

	// formを生成
	var form = document.createElement("form");
	form.action = FileName;
	form.target = target;
	form.method = 'post';
	// input-hidden生成と設定
	var input = document.createElement("input");
	input.setAttribute('type','hidden');
	input.setAttribute('name','mode');
	input.setAttribute('value','file_manage');
	form.appendChild(input);
	var input = document.createElement("input");
	input.setAttribute('type','hidden');
	input.setAttribute('name','action');
	input.setAttribute('value','file_manage');
	form.appendChild(input);
	// formをbodyに追加して、サブミットする。その後、formを削除
	var body = document.getElementsByTagName("body")[0];
	body.appendChild(form);
	form.submit();
	body.removeChild(form);

	list_window.focus();
}

function change_display(key) {
	var disp_id = "file_list_" + key;
	var folder_id = "folder_" + key;
	var img_id = "img_" + key;
	if (!document.getElementById(disp_id)) { return; }
	if (!document.getElementById(disp_id).style.display) {
		document.getElementById(disp_id).style.display = "none";
	}
	if (document.getElementById(disp_id).style.display == "inline") {
		document.getElementById(disp_id).style.display = "none";
		document.getElementById(folder_id).src = "/images/folder_close.gif";
	} else {
		document.getElementById(disp_id).style.display = "inline";
		document.getElementById(folder_id).src = "/images/folder_open.gif";
	}
}

function file_upload_form(key,forder_num,php_self,mode,capacity_max) {
	var body = document.getElementsByTagName("body")[0];
	var value_name = document.getElementById('share_'+forder_num).innerHTML;
	var xScroll, yScroll;
	var xscrWidth, yscrHeight;
	var windowWidth, windowHeight;

	if (window.innerHeight && window.scrollMaxY) {	
		xscrWidth = window.innerWidth + window.scrollMaxX;
		yscrHeight = window.innerHeight + window.scrollMaxY;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			yscrHeight = document.body.scrollHeight;
		} else {
			yscrHeight = document.body.offsetHeight;
		}
		if (document.body.scrollWidth > document.body.offsetWidth){ // all but Explorer Mac
			xscrWidth = document.body.scrollWidth;
		} else {
			xscrWidth = document.body.offsetWidth;
		}
	}
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	if(xscrWidth < windowWidth){ viewWidth = windowWidth; }
	else { viewWidth = xscrWidth; }
	if(yscrHeight < windowHeight){ viewHeight = windowHeight; }
	else { viewHeight = yscrHeight; }
	xScroll = document.documentElement.scrollLeft || document.body.scrollLeft;
	yScroll = document.documentElement.scrollTop || document.body.scrollTop;
	var half_height = (windowHeight / 3) + yScroll;

	var main_obj = document.createElement("div");
	main_obj.setAttribute('id','upload_area');
	main_obj.style.zIndex="1";
	main_obj.style.width=viewWidth+'px';
	main_obj.style.height=viewHeight+'px';
	body.appendChild(main_obj);
	var in_obj = document.createElement("div");
	in_obj.setAttribute('id','fup_in2');
	in_obj.style.marginTop = half_height+'px';
	main_obj.appendChild(in_obj);

	var mb_max = Math.floor(capacity_max / 1000000);
	var html = '<div id="error_log_area"></div>\n';
	html += value_name+' にアップロードします。\n';
	html += '<form action="./get_file_upload.php" method="post" name="upload_form" id="upload_form" enctype="multipart/form-data" target="upload_frame">\n';
	html += '<input type="hidden" name="mode" value="'+mode+'" />\n';
	html += '<input type="hidden" name="action" value="upload" />\n';
	html += '<input type="hidden" name="company_num" value="'+key+'" />\n';
	html += '<input type="hidden" name="MAX_FILE_SIZE" value="'+capacity_max+'">\n';
	html += 'ファイル：<input type="file" name="up_file" id="up_file" size="50" class="sec_form_btn" /><br />\n';
	html += '<input type="submit" value="アップロード" class="sec_form_btn" />\n';
	html += '<input type="button" value="戻る" class="sec_form_btn" onclick="close_file_upload_form(); return false;" />\n';
	html += '</form>\n';
	html += '※ファイル容量は、'+mb_max+'Mbyteまでです。<br />\n';
	html += '※ファイル名に機種依存文字を利用されていると、ダウンロードされる方の環境によって文字化けする可能性があります。\n';
	html += '<iframe name="upload_frame" src="" style="width:0px;height:0px;border:0px;"></iframe>\n';
	document.getElementById('fup_in2').innerHTML = html;
}

function close_file_upload_form() {
	var body = document.getElementsByTagName("body")[0];
	var upload_form = document.getElementById('upload_area');
	body.removeChild(upload_form);
}

function set_file_upload_action(mode,sendaction,formname,key) {
	var value_name = "";
	var msg = "";
	if (mode == "add") {
		value_name = document.getElementById('company_'+key).innerHTML;
		msg = value_name + "のフォルダーを作成しますか？";
	} else if (mode == "share_del") {
		value_name = document.getElementById('share_'+key).innerHTML;
		msg = value_name + "のフォルダーを削除しますか？";
	} else if (mode == "file_del") {
		value_name = document.getElementById('uplog_'+key).innerHTML;
		msg = value_name + "のファイルを削除しますか？";
	}
	if (confirm(msg)) { set_action(sendaction,formname,key); }
}

function file_share_delete_action(share_num) {
	dataFileName = '/user/get_file_share_delete.php';
	data = "&share_num="+share_num;

	value_name = document.getElementById('share_'+share_num).innerHTML;
	msg = value_name + "のフォルダーを削除しますか？";

	if (confirm(msg)) { sendRequest(receive_file_share_delete,data,'POST',dataFileName,true); }
}

function receive_file_share_delete(res) {
	var resdata = res.responseText;;
	data = resdata.split("<>");

	if (data[0] === "0") {
		return;
	} else {
		var dir_list = document.getElementById('dir_list_area');
		var del_area = document.getElementById('dir_area_'+data[0]);
		dir_list.removeChild(del_area);
	}
}

function file_delete_action(company_num,upload_num) {
	dataFileName = '/user/get_file_delete.php';
	data = "&company_num="+company_num;
	data += "&upload_num="+upload_num;

	value_name = document.getElementById('uplog_'+company_num+'_'+upload_num).innerHTML;
	msg = value_name + "のファイルを削除しますか？";

	if (confirm(msg)) { sendRequest(receive_file_delete,data,'POST',dataFileName,true); }
}

function receive_file_delete(res) {
	var resdata = res.responseText;;
	data = resdata.split("<>");

	if (data[0] === "0") {
		return;
	} else {
		upload_file_list(data[1],data[0]);
	}
}

function receive_file_upload(res) {
	var resdata = res;
	data = resdata.split("<>");

	if (data[0] === "0") {
		 window.parent.document.getElementById("error_log_area").innerHTML = data[1];
	} else {
		window.parent.upload_file_list('other',data[0]);
		window.parent.close_file_upload_form();
	}
}

function upload_file_list(action,company_num) {
	dataFileName = '/user/get_file_list.php';
	data = "&action="+action;
	data += "&company_num="+company_num;

	sendRequest(receive_upload_file_list,data,'POST',dataFileName,true);
}

function receive_upload_file_list(res) {
	var resdata = res.responseText;
	var style_disp = "";
	data = resdata.split("<>");
	
	if (data[1] === "0") { style_disp = "inline"; }
	else if (data[1] === "1") { style_disp = "none"; }
	if (style_disp && data[1] != 2) {
		document.getElementById('folder_del_btn_'+data[0]).style.display = style_disp;
	}
	document.getElementById('file_list_'+data[0]).innerHTML = data[2];
}

// -- oz--
function set_kisyu_list(maker_num,kisyu_type) {
	dataFileName = '/user/get_kisyu.php';
	data = "&maker_num="+maker_num;
	data += "&kisyu_type="+kisyu_type;
	sendRequest(get_search_kisyu_list,data,'POST',dataFileName,true);
}

function get_search_kisyu_list(res) {
	var resdata = res.responseText;
//alert(resdata);
	if (resdata == "") {
		document.getElementById("kisyu").innerHTML = "";
		document.getElementById("kisyu").options[0] = new Option("選択してください", "");
		return;
	}
	data = resdata.split("<>");
	var selectbox = document.getElementById("kisyu");
	document.getElementById("kisyu").innerHTML = "";
	document.getElementById("kisyu").options[0] = new Option("選択してください", "");
	for (i=0;i<data.length;i++) {
		document.getElementById("kisyu").options[i+1] = new Option(data[i],data[i]);
	}
}

function select_text_box(id,val) {
	document.getElementById(id).parentNode.nextSibling.value=val;
}
function company_form() {
	FileName = '/user/company_form.php';
	target = 'company';
	doc_window = window.open(FileName,target,'width='+new_win_width+',height='+new_win_height+',scrollbars=yes,resizable=yes');

	// formを生成
	var form = document.createElement("form");
	form.action = FileName;
	form.target = target;
	form.method = 'post';
	// formをbodyに追加して、サブミットする。その後、formを削除
	var body = document.getElementsByTagName("body")[0];
	body.appendChild(form);
	form.submit();
	body.removeChild(form);

	doc_window.focus();
}

function check_id(id_num,key) {
	if (id_num) { id = "user_login_id__" + id_num; }
	else { id = "user_login_id"; }
	if (document.getElementById(id).value === "") { return; }
	dataFileName = '/user/check_id.php';
	data = "&login_id="+document.getElementById(id).value;
	data += "&key="+key;
	sendRequest(result_id,data,'POST',dataFileName,true);
}

function result_id(res) {
	var resdata = res.responseText;
	alert(resdata);
//document.getElementById(id).value += resdata;
}

function set_login_info() {
	dataFileName = '/user/get_login_info.php';
	data = "";
	sendRequest(get_login_info,data,'POST',dataFileName,true);
}
function get_login_info(res) {
	var resdata = res.responseText;
	document.getElementById("tln_logoin").innerHTML = resdata;
}

// テキストボックス内メッセージロールオーバー
function clear_textbox(id) {
	var def_msg = "通称名・型式名の一部を入力して下さい。";
	if (document.getElementById(id).value == def_msg) {
		document.getElementById(id).value = "";
	}
	return false;
}
function set_textbox(id) {
	var def_msg = "通称名・型式名の一部を入力して下さい。";
	if (document.getElementById(id).value == "") {
		document.getElementById(id).value = def_msg;
	}
	return false;
}
function clear_textarea(id) {
	var def_msg = "*";
	if (document.getElementById(id).innerHTML == def_msg) {
		document.getElementById(id).innerHTML = "";
	}
	return false;
}
function set_textarea(id) {
	var def_msg = "*";
	if (document.getElementById(id).innerHTML == "") {
		document.getElementById(id).innerHTML = def_msg;
	}
	return false;
}
// -------