function isFirtst(){
	if(document.form_logout.mode.value != "off"){
		document.form_logout.mode.value = "off";
		return true;
	}
	return false;
}

function setContents(contents, defaultContents, defaultPart, rootUrl) {
	var mode = "view_contents";
	$.ajax( {
				type : "POST",
				url : rootUrl + "common/ajaxUtilty.php",
				data : "param=" + contents + "&defaultContents="
						+ defaultContents + "&defaultPart=" + defaultPart
						+ "&mode=" + mode,
				success : function(str) {
					if (str == null || str == "") {
						document.getElementById("tr_part").style.display = "none";
						document.getElementById("partCb").innerHTML = "";
						document.getElementById("contentTypePb").innerHTML = "";
					} else {
						document.getElementById("tr_part").style.display = "";
						strSplit = str.split("=@=");
						if (strSplit.length == 3) {
							if (strSplit[1] == "") {
								document.getElementById("tr_part").style.display = "none";
							}
							document.getElementById("contentTypePb").innerHTML = strSplit[0];
							document.getElementById("partCb").innerHTML = strSplit[1] + strSplit[2];
						}
					}
				}
			});
}

function chgContents(sel,rootUrl){

	var param = sel.options[sel.selectedIndex].value;
	var mode = "view_contents";
	if (param != "00"){

	$.ajax({
		   type: "POST",
		   url: rootUrl + "common/ajaxUtilty.php",
		   data: "param=" + param + "&mode=" + mode,
		   success: function(str){
				if (str == null || str == "") {
					document.getElementById("tr_part").style.display = "none";
					document.getElementById("partCb").innerHTML = "";
					document.getElementById("contentTypePb").innerHTML = "";
				} else {
					document.getElementById("tr_part").style.display = "";
					strSplit = str.split("=@=");
					if (strSplit.length == 3) {
						if (strSplit[1] == "") {
							document.getElementById("tr_part").style.display = "none";
						}
						document.getElementById("contentTypePb").innerHTML = strSplit[0];
						document.getElementById("partCb").innerHTML = strSplit[1] + strSplit[2];
					}
				}
		   }
		 });

	} else {
		document.getElementById("tr_part").style.display = "none";
		document.getElementById("partCb").innerHTML = "";
		document.getElementById("contentTypePb").innerHTML = "";
	}
}

function chgAllPartsCb(sel){

	var cb = document.getElementsByName("parts[]");

	for(i=0; i<cb.length; i++){
		if(sel.checked == true){
			if (sel != cb[i]){
				cb[i].checked = false;
				cb[i].disabled = true;
			}
		}else{
			cb[i].disabled = false;
		}
	}
}

function modeSubmit(md){
	if(!isFirtst()){
		return;
	}
	document.form1.method = "post";
	document.form1.mode.value = md;
	document.form1.submit();
}

/**
 * 応札案件IDを取得して提案のあった会社一覧を差し替える
 *
 * @param matterId 案件ID
 * @param userId ユーザーID
 * @return
 */
function chgClientList(matterTitle,targetId, matterId, userId, rootUrl, mainMatterId) {
	 var doc = null;
	 for (i = 0; true; i++) {
		 doc = document.getElementById("proj" + i);
		 if (doc == null) {
			 break;
		 }
		 doc.className = "proj";
	 }

	 document.getElementById(targetId).className = "proj actv";
	 document.getElementById("matter_title").innerHTML = "【" + matterTitle + "】";

	 // ajax
	$.ajax( {
		type : "POST",
		url : rootUrl + "common/ajaxUtilty.php",
		data : "param1=" + matterId + "&param2=" + userId + "&param3=" + document.shodanForm.view_client_no.value + "&mode=chgClientList" + "&param4=" + mainMatterId,
		success : function(str) {
			document.getElementById("clientlist").innerHTML = str;
		}
	});
}

function jsSubmit(formName) {
	if(!isFirtst()){
		return;
	}
	obj = document.getElementsByName(formName);
	obj[0].method = "post";
	obj[0].submit();
}

function shodanFormSubmit(actionName, matterId, clientId, messageId, messageFlg ,mode) {
	if(!isFirtst()){
		return;
	}
	submitObj = document.getElementsByName("shodanForm")[0];
	submitObj.method = "post";
	submitObj.action = actionName;
	inputMatterObj = document.getElementById("matter_id");
	inputClientObj = document.getElementById("client_no");
	inputMessageObj = document.getElementById("message_id");
	inputMessageFlgObj = document.getElementById("message_flg_user");
	inputModeObj = document.getElementById("mode");
	inputMatterObj.value = matterId;
	inputClientObj.value = clientId;
	inputMessageObj.value = messageId;
	inputMessageFlgObj.value = messageFlg;
	inputModeObj.value = mode;
	submitObj.submit();
}

function file_clear_click(objName) {
	str = document.getElementById(objName).innerHTML;
	document.getElementById(objName).innerHTML = str;
}

function reSelectFile(sel, spanId, inputFileid, inputClearid, tempfileid){
	sel.style.display = "none";
	document.getElementById(inputFileid).style.display = "";
	document.getElementById(inputClearid).style.display = "";
	document.getElementById(spanId).style.display = "none";
	document.getElementById(tempfileid).value = "";
}

function image_auto_resize(this_s, w, h) {
	var _std_height = h;
	var _std_width = w;

	var ta_image = new Image();
	ta_image.src = this_s.src;

	if ((ta_image.width / ta_image.height) < (_std_width / _std_height)) {
		this_s.width = _std_height * (ta_image.width / ta_image.height);
		this_s.height = _std_height;
		var tmp_pad = Math
				.round((_std_width - (_std_height * (ta_image.width / ta_image.height))) / 2)
				+ "px";
		this_s.style.paddingRight = tmp_pad;
		this_s.style.paddingLeft = tmp_pad;
	} else {
		this_s.width = _std_width;
		this_s.height = _std_width * (ta_image.height / ta_image.width);
		var tmp_pad = Math
				.round((_std_height - (_std_width * (ta_image.height / ta_image.width))) / 2)
				+ "px";
		this_s.style.paddingTop = 0;
		this_s.style.paddingBottom = 0;
	}

	ta_image.onload = function() {

		if ((ta_image.width / ta_image.height) < (_std_width / _std_height)) {
			this_s.width = _std_height * (ta_image.width / ta_image.height);
			this_s.height = _std_height;
			var tmp_pad = Math
					.round((_std_width - (_std_height * (ta_image.width / ta_image.height))) / 2)
					+ "px";
			this_s.style.paddingRight = tmp_pad;
			this_s.style.paddingLeft = tmp_pad;
		} else {
			this_s.width = _std_width;
			this_s.height = _std_width * (ta_image.height / ta_image.width);
			var tmp_pad = Math
					.round((_std_height - (_std_width * (ta_image.height / ta_image.width))) / 2)
					+ "px";
			this_s.style.paddingTop = 0;
			this_s.style.paddingBottom = 0;
		}
	}
}

/**
 * リフォームトップページform1用のサブミット
 * @param actionName アクション名
 * @param beforePageId 遷移元（ログイン、ユーザー登録時の完了後に遷移する先となる）
 * @return
 */
function reformTopSubmit(actionName, beforePageId) {
		if(!isFirtst()){
			return;
		}
	obj = document.getElementsByName("form1");
	obj[0].action = actionName;
	obj[0].method = "post";
	inputBeforePageIdObj = document.getElementById("before_page_id");
	inputBeforePageIdObj.value = beforePageId;
	obj[0].submit();
}

 function chgAreaCd(sel, rootUrl, areaTagName, lineTagName, stationTagName) {
	var ua = getUa();

	var area = sel.options[sel.selectedIndex].value;
	$.ajax( {
				type : "POST",
				url : rootUrl + "common/ajaxUtilty.php",
				data : "mode=area_cd_1&area=" + area,
				success : function(str) {
					if (ua == "sf" || ua == "ie") {
						document.getElementsByName(areaTagName)[0].outerHTML = "<select name='"
								+ areaTagName + "'>" + str + "</select>";
					} else {
						document.getElementsByName(areaTagName)[0].innerHTML = str;
					}
				}
			});
	if (lineTagName != "") {
		chgAreaCdForLine(area, rootUrl, lineTagName, stationTagName);
	}
}

 function setAreaCd(rootUrl, areaTagName,areaCd1,areaCd2) {
	 	if(areaCd1 == ""){
	 		return;
	 	}
	 	var ua = getUa();

		$.ajax( {
					type : "POST",
					url : rootUrl + "common/ajaxUtilty.php",
					data : "mode=area_cd_1&area=" + areaCd1,
					success : function(str) {
						if (ua == "sf" || ua == "ie") {
							document.getElementsByName(areaTagName)[0].outerHTML = "<select name='"
									+ areaTagName + "'>" + str + "</select>";
						} else {
							document.getElementsByName(areaTagName)[0].innerHTML = str;

						}
						element = document.getElementsByName(areaTagName)[0].options;
						for(i =0 ; i<element.length ; i++){
							if (element[i].value == areaCd2){
								document.getElementsByName(areaTagName)[0].selectedIndex = i;
							}
						}
		}
				});
	}
 function chgAreaCdForLine(area,rootUrl,lineTagName,stationTagName){
		var ua = getUa();

			$.ajax({
				   type: "POST",
				   url: rootUrl + "common/ajaxUtilty.php",
				   data: "mode=area_cd_1_line&area=" + area,
				   success: function(str){
						if (ua == "sf" || ua == "ie") {
							document.getElementsByName(lineTagName)[0].outerHTML = "<select name='" + lineTagName + "' onChange=\"chgLineCd(this,'" + rootUrl + "','" + stationTagName + "' );\">" + str + "</select>";
						}else{
							document.getElementsByName(lineTagName)[0].innerHTML = str;
						}
				   }
				 });
			clrLineCd(rootUrl,stationTagName);
	}

	function clrLineCd(rootUrl,tagName){
		var ua = getUa();
			$.ajax({
				   type: "POST",
				   url: rootUrl + "common/ajaxUtilty.php",
				   data: "mode=line_cd&line=",
				   success: function(str){
						if (ua == "sf" || ua == "ie") {
							document.getElementsByName(tagName)[0].outerHTML = "<select name='" + tagName + "'>" + str + "</select>";
						}else{
							document.getElementsByName(tagName)[0].innerHTML = str;
						}
				   }
				 });
	}

	function chgLineCd(sel,rootUrl,tagName){
		var ua = getUa();

		var line = sel.options[sel.selectedIndex].value;
		if (line != ""){
			$.ajax({
				   type: "POST",
				   url: rootUrl + "common/ajaxUtilty.php",
				   data: "mode=line_cd&line=" + line,
				   success: function(str){
						if (ua == "sf" || ua == "ie") {
							document.getElementsByName(tagName)[0].outerHTML = "<select name='" + tagName + "'>" + str + "</select>";
						}else{
							document.getElementsByName(tagName)[0].innerHTML = str;
						}
				   }
				 });
		}
	}
function getUa(){
	  var strUA = "";
	  strUA = navigator.userAgent.toLowerCase();

	  if(strUA.indexOf("safari") != -1){
	      return "sf";

	  }else if(strUA.indexOf("firefox") != -1){
		  return "ff";

	  }else if(strUA.indexOf("opera") != -1){
		  return "op";

	  }else if(strUA.indexOf("netscape") != -1){
		  return "nn";

	  }else if(strUA.indexOf("msie") != -1){
		  return "ie";

	  }else if(strUA.indexOf("mozilla/4") != -1){
		  return "nn";
	  }

}

function selectActionSubmit(actionName, md) {
	if(!isFirtst()){
		return;
	}
	document.form1.action = actionName;
	document.form1.method = "post";
	document.form1.mode.value = md;
	document.form1.submit();
}

function shodanFormCancelSubmit(actionName, matterId, shodanTitle) {
	if(!isFirtst()){
		return;
	}
	submitObj = document.getElementsByName("shodanForm")[0];
	submitObj.method = "post";
	submitObj.action = actionName;
	inputMatterObj = document.getElementById("matter_id");
	inputShodanTitleObj = document.getElementById("shodan_title");
	inputMatterObj.value = matterId;
	inputShodanTitleObj.value = shodanTitle;
	submitObj.submit();
}

function clear_click(objName) {
	document.getElementById(objName).value = "";
}

function clear_click_value(objName, value) {
	document.getElementById(objName).value = value;
}

function clear_kojin_info(url) {
	document.getElementById("contact_zip_1").value = "";
	document.getElementById("contact_zip_2").value = "";
	document.getElementById("contact_area_cd_1").selectedIndex = 0;
	document.getElementById("contact_adr_1").value = "";
	document.getElementById("contact_adr_2").value = "";
	setAreaCd(url, 'contact_area_cd_2','00','');
}

function callKojinInfoButtonClick(rootUrl, userId) {

	if (!confirm("登録データを自動で入力します。よろしいですか？")) {
		return;
	}

	var ua = getUa();
	$.ajax( {
				type : "POST",
				url : rootUrl + "common/ajaxUtilty.php",
				data : "mode=kojin_info&user_id=" + userId,
				success : function(str) {
					// 返却値を=で分割
					sq = str.split("=");
					for (i = 0; i < sq.length; i++) {
						sq[i] = decodeURI(sq[i]);
					}
					document.getElementById("family_nm").value = sq[0];
					document.getElementById("last_nm").value = sq[1];
					document.getElementById("family_kn").value = sq[2];
					document.getElementById("last_kn").value = sq[3];
					document.getElementById("article_zip_1").value = sq[4];
					document.getElementById("article_zip_2").value = sq[5];
					document.getElementById("article_adr_1").value = sq[8];
					document.getElementById("article_adr_2").value = sq[9];
					document.getElementById("contact_zip_1").value = sq[10];
					document.getElementById("contact_zip_2").value = sq[11];
					document.getElementById("contact_adr_1").value = sq[14];
					document.getElementById("contact_adr_2").value = sq[15];
					document.getElementById("contact_tel_1").value = sq[16];
					document.getElementById("contact_tel_2").value = sq[17];
					document.getElementById("contact_tel_3").value = sq[18];
					if (sq[6] == "") sq[6] = 0;
					if (sq[12] == "") sq[12] = 0;
					document.getElementById("article_area_cd_1").selectedIndex = sq[6];
					document.getElementById("contact_area_cd_1").selectedIndex = sq[12];
					setAreaCd(rootUrl, 'article_area_cd_2', sq[6], sq[7]);
					setAreaCd(rootUrl, 'contact_area_cd_2', sq[12], sq[13]);
				}
			});
}

function searchZip(rootUrl, kind) {

	tagNameHead = 'article_';
	if (kind == 'contact') {
		tagNameHead = 'contact_';
	} else if (kind == 'send') {
		tagNameHead = 'send_';
	}
	$zip1 = document.getElementById(tagNameHead + 'zip_1').value;
    $zip2 = document.getElementById(tagNameHead + 'zip_2').value;
    if(!isNumeric($zip1) || !isNumeric($zip2) || $zip1.length != 3 || $zip2.length != 4){
		document.getElementById(tagNameHead + 'area_cd_1').selectedIndex = 0;
		document.getElementById(tagNameHead + 'adr_1').value = '';
		setAreaCd(rootUrl, tagNameHead + 'area_cd_2', '00', '');
    	return;
    }
	$.ajax({
		   type: 'POST',
		   url: rootUrl + 'common/ajaxUtilty.php',
		   data: 'mode=search_zip&zip1=' + $zip1 + '&zip2=' + $zip2,
		   success: function(str){
					var area = str.split(',');
					if(area.length == 5){
						document.getElementById(tagNameHead + 'area_cd_1').selectedIndex = area[0];
						document.getElementById(tagNameHead + 'adr_1').value = area[4];
						setAreaCd(rootUrl, tagNameHead + 'area_cd_2', area[0], area[1]);
					} else {
						document.getElementById(tagNameHead + 'area_cd_1').selectedIndex = 0;
						document.getElementById(tagNameHead + 'adr_1').value = '';
						setAreaCd(rootUrl, tagNameHead + 'area_cd_2', '00', '');
					}
		   }
		 });
}

function isNumeric(num){
    if (num.match(/[^0-9]/g)) {
        return false;
    }
    return true;
}

/**
 * 案件IDによってクライアントリストを差し替える
 * @param matter_id 案件ID
 * @param selected 選択クライアントNo
 * @param targetId HTMLを出力するID
 */
function chgShodan(rootUrl, matter_id, selected, targetId) {
	var ua = getUa();
	$.ajax({
		type: "POST",
		url: rootUrl + "common/ajaxUtilty.php",
		data: "mode=serch_client&matter_id=" + matter_id + "&selected=" + selected,
		success: function(str) {
			if (ua == "sf" || ua == "ie") {
				document.getElementById(targetId).outerHTML = '<select name="client_no" id="client_list" onchange="setCancelClientList(\'' + rootUrl + '\', \'' + matter_id + '\', this.value);return false;"><option value="">選択して下さい</option>' + str + '</select>';
			} else {
				document.getElementById(targetId).innerHTML = '<option value="">選択して下さい</option>' + str;
			}
		}
	});
	setCancelClientList(rootUrl, matter_id, selected);
}

function setCancelClientList(rootUrl, matter_id, selected) {
	if (matter_id == "") {
		matter_id = document.form1.matter_id.value;
	}
	var ua = getUa();
	$.ajax({
		type: "POST",
		url: rootUrl + "common/ajaxUtilty.php",
		data: "mode=serch_cancel_client&matter_id=" + matter_id + "&selected=" + selected,
		success: function(str) {
			if (ua == "sf" || ua == "ie") {
				for (i = 1; i < 9; i++) {
					document.getElementById("cancel_client_no_" + i).outerHTML = '<select name="cancel_client_no_' + i + '" id="cancel_client_no_' + i + '"><option value="">選択して下さい</option>' + str + '</select>';
				}
			} else {
				for (i = 1; i < 9; i++) {
					document.getElementById("cancel_client_no_" + i).innerHTML = '<option value="">選択して下さい</option>' + str;
				}
			}
			len = document.forms["form1"].elements["cancel_client_no_1"].length - 1;
			for (j = 1; j <= 8; j++) {
				if (j <= len) {
					document.getElementById("cancel_" + j).style.display = "";
				} else {
					document.getElementById("cancel_" + j).style.display = "none";
				}
			}
		}
	});
}

function setCancelClientListOnload(rootUrl, matter_id, cancel_client_no, selected, i) {
	if (matter_id == "") {
		matter_id = document.form1.matter_id.value;
	}

	var ua = getUa();
	$.ajax({
		type: "POST",
		url: rootUrl + "common/ajaxUtilty.php",
		data: "mode=serch_cancel_client&matter_id=" + matter_id + "&selected=" + selected + "&cancel_client_no=" + cancel_client_no,
		success: function(str) {
			if (ua == "sf" || ua == "ie") {
				document.getElementById("cancel_client_no_" + i).outerHTML = '<select name="cancel_client_no_' + i + '" id="cancel_client_no_' + i + '"><option value="">選択して下さい</option>' + str + '</select>';
			} else {
				document.getElementById("cancel_client_no_" + i).innerHTML = '<option value="">選択して下さい</option>' + str;
			}
			if (i == 8) {
				len = document.forms["form1"].elements["cancel_client_no_1"].length - 1;
				for (j = 1; j <= 8; j++) {
					if (j <= len) {
						document.getElementById("cancel_" + j).style.display = "";
					} else {
						document.getElementById("cancel_" + j).style.display = "none";
					}
				}
			}
		}
	});
}

function callKojinInfoButtonClickHyoka1(rootUrl, userId) {

	if (!confirm("登録データを自動で入力します。よろしいですか？")) {
		return;
	}

	var ua = getUa();
	$.ajax( {
				type : "POST",
				url : rootUrl + "common/ajaxUtilty.php",
				data : "mode=kojin_info&user_id=" + userId,
				success : function(str) {
					// 返却値を=で分割
					sq = str.split("=");
					for (i = 0; i < sq.length; i++) {
						sq[i] = decodeURI(sq[i]);
					}
					document.getElementById("family_nm").value = sq[0];
					document.getElementById("last_nm").value = sq[1];
					document.getElementById("family_kn").value = sq[2];
					document.getElementById("last_kn").value = sq[3];
					document.getElementById("article_zip_1").value = sq[4];
					document.getElementById("article_zip_2").value = sq[5];
					document.getElementById("article_adr_1").value = sq[8];
					document.getElementById("article_adr_2").value = sq[9];
					if (sq[19] == "1") {
						document.getElementsByName("sex")[0].checked = true;
					} else if (sq[19] == "2") {
						document.getElementsByName("sex")[1].checked = true;
					}
					document.getElementsByName("income")[0].value = sq[20];
					document.getElementsByName("age")[0].value = sq[21];
					if (sq[6] == "") sq[6] = 0;
					if (sq[12] == "") sq[12] = 0;
					document.getElementById("article_area_cd_1").selectedIndex = sq[6];
					setAreaCd(rootUrl, 'article_area_cd_2', sq[6], sq[7]);
				}
			});
}

function callKojinInfoButtonClickHyoka2(rootUrl, userId) {

	if (!confirm("登録データを自動で入力します。よろしいですか？")) {
		return;
	}

	var ua = getUa();
	$.ajax( {
				type : "POST",
				url : rootUrl + "common/ajaxUtilty.php",
				data : "mode=kojin_info&user_id=" + userId,
				success : function(str) {
					// 返却値を=で分割
					sq = str.split("=");
					for (i = 0; i < sq.length; i++) {
						sq[i] = decodeURI(sq[i]);
					}
					document.getElementById("send_family_nm").value = sq[0];
					document.getElementById("send_last_nm").value = sq[1];
					document.getElementById("send_family_kn").value = sq[2];
					document.getElementById("send_last_kn").value = sq[3];
					document.getElementById("send_zip_1").value = sq[10];
					document.getElementById("send_zip_2").value = sq[11];
					document.getElementById("send_adr_1").value = sq[14];
					document.getElementById("send_adr_2").value = sq[15];
					if (sq[6] == "") sq[6] = 0;
					if (sq[12] == "") sq[12] = 0;
					document.getElementById("send_area_cd_1").selectedIndex = sq[12];
					setAreaCd(rootUrl, 'send_area_cd_2', sq[12], sq[13]);
				}
			});
}

function chkCount(sel,cntTagId) {
	var text = sel.value
	text = text.replace(/\r\n|\r|\n/g, ' ');
	var num = text.length;

	document.getElementById(cntTagId).innerHTML = num;
}

function jireiColorSelect (tag) {
    color = tag.className;
    for (i = 0 ; i <= 8 ; i ++) {
        if (tag.id == 'select_color_' + i) {
            if (color.match ('actv')) {
                document.getElementById('selectColor').className = 'cell';
                document.getElementById('select_color_' + i).className = document.getElementById('select_color_' + i).className.replace(' actv', '');
                document.getElementById('selectColorHidden').value = '';
            } else if (tag.id == 'select_color_0') {
                document.getElementById('selectColor').className = 'cell';
                document.getElementById('selectColorHidden').value = i;
            } else {
                document.getElementById('selectColor').className = 'cell ' + tag.className;
                document.getElementById('select_color_' + i).className = document.getElementById('select_color_' + i).className + ' actv';
                document.getElementById('selectColorHidden').value = i;
            }
        } else {
            document.getElementById('select_color_' + i).className = document.getElementById('select_color_' + i).className.replace(' actv', '');
        }
    }
}

function jireiSearchInFormName (url, name) {
	if(!isFirtst()){
		return;
	}
    document.form_search.action = url + '?'+ jireiSearchQueryInFormName(name);
    document.form_search.method = "post";
    document.form_search.submit();

}
function jireiSearchQueryInFormName (name) {
    submitObj = document.getElementsByName(name)[0];
    var str = '';
    if (submitObj.a1.value != '') {
        if (str.length != 0) {
            str += '&';
        }
        str += 'a1=' + submitObj.a1.value;
    }
    if (submitObj.pt.value != '00') {
        if (str.length != 0) {
            str += '&';
        }
        str += 'pt=' + submitObj.pt.value;
    }

    kw = jireiSearchCheckBoxInFormName (name);
    if (kw.length != 0) {
        if (str.length != 0) {
            str += '&';
        }
        str += 'kw=' + kw;
    }

    if (submitObj.cn.value != '00') {
        if (str.length != 0) {
            str += '&';
        }
        str += 'cn=' + submitObj.cn.value;
    }
    if (submitObj.ly.value != '00') {
        if (str.length != 0) {
            str += '&';
        }
        str += 'ly=' + submitObj.ly.value;
    }
    if (submitObj.cl.value != '') {
        if (str.length != 0) {
            str += '&';
        }
        str += 'cl=' + submitObj.cl.value;
    }
    if (submitObj.pn.value != '0') {
        if (str.length != 0) {
            str += '&';
        }
        str += 'pn=' + submitObj.pn.value;
    }
    if (submitObj.px.value != '0') {
        if (str.length != 0) {
            str += '&';
        }
        str += 'px=' + submitObj.px.value;
    }
    if (submitObj.yy.value != '00') {
        if (str.length != 0) {
            str += '&';
        }
        str += 'yy=' + submitObj.yy.value;
    }
    if (submitObj.ts.value != '00') {
        if (str.length != 0) {
            str += '&';
        }
        str += 'ts=' + submitObj.ts.value;
    }
    if (submitObj.ty.value != '0') {
        if (str.length != 0) {
            str += '&';
        }
        str += 'ty=' + submitObj.ty.value;
    }
    if (submitObj.st.value != '00') {
        if (str.length != 0) {
            str += '&';
        }
        str += 'st=' + submitObj.st.value;
    }
    for (i = 0 ; i < 4 ; i ++) {
        if (submitObj.bu[i].checked == true) {
            if (str.length != 0) {
                str += '&';
            }
            str += 'bu=' + submitObj.bu[i].value;
        }
    }


    return str;
}
function jireiSearchCheckBoxInFormName (name) {
    submitObj = document.getElementsByName(name)[0];

    var kw = '';
    for (i = 0 ; i < submitObj.kw_h.length ; i ++) {
        if (submitObj.kw_h[i].checked == true) {
            if (kw == '') {
                kw += submitObj.kw_h[i].value;
            } else {
                kw += ',' + submitObj.kw_h[i].value;
            }
        }
    }
    return kw;
}

function pageSubmit(page){
	if(!isFirtst()){
		return;
	}
	document.form1.search_param_page.value = page;
	document.form1.method = "post";
	document.form1.submit();
}

function zipSubmit(zip1, zip2){
	window.opener.document.form1.zip_1.value = zip1;
	window.opener.document.form1.zip_2.value = zip2;
	window.close();
}

function zipSearch(address) {
	$.ajax( {
				type : "POST",
				url : "ajaxUtilty.php",
				data : "mode=zip_info&address=" + address,
				success : function(str) {
					document.getElementById("addresses").innerHTML = str;
				}
			});
}

function yusenFormSubmit(actionName) {
	if(!isFirtst()){
		return;
	}
	document.yusenForm.action = actionName;
	document.yusenForm.method = "post";
	document.yusenForm.submit();
}

function rankingCheckBox() {
	var keepClientNo = "";
	var okiniiriCaseNo = "";
	objCk = document.getElementsByName("ck");
    for (i = 0 ; i < objCk.length ; i ++) {
        if (objCk[i].checked == true) {
            if (keepClientNo == '') {
            	keepClientNo += document.getElementsByName("client_no_" + objCk[i].value)[0].value;
            } else {
            	keepClientNo += ',' + document.getElementsByName("client_no_" + objCk[i].value)[0].value;
            }
            if (okiniiriCaseNo == '') {
            	okiniiriCaseNo += document.getElementsByName("okiniiri_case_no_" + objCk[i].value)[0].value;
            	okiniiriCaseNo += '_' + document.getElementsByName("okiniiri_case_part_" + objCk[i].value)[0].value;
            } else {
            	okiniiriCaseNo += '|' + document.getElementsByName("okiniiri_case_no_" + objCk[i].value)[0].value;
            	okiniiriCaseNo += '_' + document.getElementsByName("okiniiri_case_part_" + objCk[i].value)[0].value;
            }
        }
    }
    document.getElementsByName('keep_client_no')[0].value = keepClientNo;
    document.getElementsByName('okiniiri_case_no')[0].value = okiniiriCaseNo;
}

function checkedMoshikomiSubmit(actionName) {
	rankingCheckBox();
	if (document.getElementsByName('keep_client_no')[0].value == "") {
		return;
	}
	if(!isFirtst()){
		return;
	}
	document.form1.action = actionName;
	document.form1.method = "post";
	document.form1.submit();
}

function registOkiniiriAll(rootUrl, user_id) {
	rankingCheckBox();
	objCk = document.getElementsByName("ck");
	var caseValue = "";
    for (i = 0 ; i < objCk.length ; i ++) {
    	client_no = document.getElementsByName("client_no_" + objCk[i].value)[0].value;
    	okiniiriCaseNo = document.getElementsByName("okiniiri_case_no_" + objCk[i].value)[0].value + "_" + document.getElementsByName("okiniiri_case_part_" + objCk[i].value)[0].value;
    	if (objCk[i].checked == true) {
    		registOkiniiri(rootUrl, client_no, okiniiriCaseNo, user_id);
    	}
    }
}

function registOkiniiri(rootUrl, client_no, okiniiriCaseNo, user_id) {
    if (okiniiriCaseNo == "" || client_no == "" || user_id == "") {
        return "";
    }
    $.ajax( {
        type : "POST",
        url : rootUrl + "common/ajaxUtilty.php",
        data : "mode=registOkiniiri&okiniiri_case_no=" + okiniiriCaseNo + "&client_no=" + client_no + "&user_id=" + user_id,
        success : function(str) {
	    	if (str != "") {
	    		document.getElementById(okiniiriCaseNo).innerHTML = '<p class="btn_fav2">お気に入り登録済み</p>';
	    	} else {
	    		document.getElementById(okiniiriCaseNo).innerHTML = '<p class="btn_fav"><a href="javascript:void(0);" onclick="registOkiniiri(\''+ client_no + '\', \''+ okiniiriCaseNo + '\', \''+ user_id + '\'); return false;">お気に入りに登録する</a></p>';
	    	}
        }
    });
}

function registOkiniiri2(rootUrl, client_no, okiniiriCaseNo, user_id, kensu) {
    if (okiniiriCaseNo == "" || client_no == "" || user_id == "") {
        return "";
    }
    $.ajax( {
        type : "POST",
        url : rootUrl + "common/ajaxUtilty.php",
        data : "mode=registOkiniiri&okiniiri_case_no=" + okiniiriCaseNo + "&client_no=" + client_no + "&user_id=" + user_id,
        success : function(str) {
	    	if (str != "") {
	    		kensu = (kensu + 1);
	    		document.getElementById(okiniiriCaseNo).innerHTML = '<ul><li class="favorite">お気に入り登録済み</li></ul>';
	    		document.getElementById(okiniiriCaseNo + "dw").innerHTML = '<ul><li>お気に入り登録済み</li><li><a href="' + rootUrl + 'jirei/okiniiri/">お気に入りに登録した事例の一覧を見る</a></li></ul>';
	    		document.getElementById('kensu').outerHTML = '<span id="kensu">' + kensu + '</span>';
	    	} else {
	    		document.getElementById(okiniiriCaseNo).innerHTML = '<ul><li class="favorite"><a href="javascript:void(0);" onclick="registOkiniiri2(\''+ client_no + '\', \''+ okiniiriCaseNo + '\', \''+ user_id + '\'); return false;">お気に入りに登録する</a></li></ul>';
	    	}
        }
    });
}

function registOkiniiri3(rootUrl, client_no, okiniiriCaseNo, user_id, kensu) {
    if (okiniiriCaseNo == "" || client_no == "" || user_id == "") {
        return "";
    }
    $.ajax( {
        type : "POST",
        url : rootUrl + "common/ajaxUtilty.php",
        data : "mode=registOkiniiri&okiniiri_case_no=" + okiniiriCaseNo + "&client_no=" + client_no + "&user_id=" + user_id,
        success : function(str) {
	    	if (str != "") {
	    		kensu = (kensu + 1);
	    		document.getElementById(okiniiriCaseNo).innerHTML = '<ul><li class="favorite">お気に入り登録済み</li></ul>';
	    		document.getElementById(okiniiriCaseNo + "dw").innerHTML = '<ul><li>お気に入り登録済み</li><li><a href="' + rootUrl + 'jirei/okiniiri/">お気に入りに登録した事例の一覧を見る</a></li></ul>';
	    		document.getElementById('kensu').outerHTML = '<span id="kensu">' + kensu + '</span>';
	    	} else {
	    		document.getElementById(okiniiriCaseNo).innerHTML = '<ul><li><a href="javascript:void(0);" onclick="registOkiniiri3(\''+ client_no + '\', \''+ okiniiriCaseNo + '\', \''+ user_id + '\'); return false;">お気に入りに登録する</a></li><li><a href="' + rootUrl + 'jirei/okiniiri/">お気に入りに登録した事例の一覧を見る</a></li></ul>';
	    	}
        }
    });
}

function registOkiniiri4(rootUrl, client_no, okiniiriCaseNo, user_id, kensu, case_no) {
    if (okiniiriCaseNo == "" || client_no == "" || user_id == "") {
        return "";
    }
    $.ajax( {
        type : "POST",
        url : rootUrl + "common/ajaxUtilty.php",
        data : "mode=registOkiniiri&okiniiri_case_no=" + okiniiriCaseNo + "&client_no=" + client_no + "&user_id=" + user_id,
        success : function(str) {
	    	if (str != "") {
	    		kensu = (kensu + 1);
	    		document.getElementById(okiniiriCaseNo).innerHTML = '<ul><li class="favorite">お気に入り登録済み</li><li class="all_det"><a href="' + rootUrl + 'jirei/gaiyo_' + case_no + '/">この事例の全体概要を見る</a></li></ul>';
	    		document.getElementById('kensu').outerHTML = '<span id="kensu">' + kensu + '</span>';
	    		document.getElementById(okiniiriCaseNo + "dw").innerHTML = '<ul><li>お気に入り登録済み</li><li><a href="' + rootUrl + 'jirei/okiniiri/">お気に入りに登録した事例の一覧を見る</a></li></ul>';
	    	} else {
	    		document.getElementById(okiniiriCaseNo).innerHTML = '<ul><li class="favorite"><a href="javascript:void(0);" onclick="registOkiniiri4(\''+ client_no + '\', \''+ okiniiriCaseNo + '\', \''+ user_id + '\'); return false;">お気に入りに登録する</a></li><li class="all_det"><a href="' + rootUrl + 'jirei/gaiyo_' + case_no + '/">この事例の全体概要を見る</a></li></ul>';
	    	}
        }
    });
}

function okiniiriSortSubmit(actionName, sort) {
	if (sort == "") {
		sort = "regist";
	}
	document.form1.action = actionName;
	document.form1.method = "post";
	document.form1.sort.value = sort;
	document.form1.submit();
}

function okiniiriDel1Submit(case_no, part, mode) {
	document.form1.mode.value = mode;
	document.form1.method = "post";
	document.form1.del_case_no.value = case_no;
	document.form1.del_part.value = part;
	document.form1.submit();
}

function okiniiriDelAllSubmit(mode) {
	rankingCheckBox();
	if (document.getElementsByName('okiniiri_case_no')[0].value == "") {
		return;
	}
	document.form1.mode.value = mode;
	document.form1.method = "post";
	document.form1.submit();
}

function moshikomiSubmit(actionName) {
	document.form1.action = actionName;
	document.form1.method = "post";
	document.form1.submit();
}

function kaishaJireiSubmit(page, sort) {
	document.form1.method = "post";
	if (page != "") {
		document.form1.page.value = page;
	}
	if (sort != "") {
		document.form1.sort.value = sort;
	}
	document.form1.submit();
}

function kaishaJireiArticleTypeSubmit(article_type) {
	document.form1.method = "post";
	document.form1.page.value = "1";
	document.form1.sort.value = "";
	document.form1.bu[article_type - 1].checked = true;
	document.form1.pt.value = "";
	document.form1.cn.value = "";
	document.form1.pn.value = "";
	document.form1.px.value = "";
	document.form1.yy.value = "";
	document.form1.a1.value = "";
	document.form1.ts.value = "";
	document.form1.ly.value = "";
	document.form1.st.value = "";
	document.form1.ty.value = "";
	k = document.getElementsByName("kw");
	for (i = 0; i < k.length; i++) {
		k[i].checked = false;
	}
	document.form1.submit();
}

function windowOpenTarget(target){
	window.open("about:blank",target,"width=970,height=720,toolbar=no,scrollbars=yes,menubar=no,status=no,resizable=yes");
	document.form1.target = target;
	document.form1.bid_id.value = target;
	document.form1.method = "post";
	document.form1.submit();
}
