// Basic JavaScript

/* 脆弱性対応　emailマッチパターン */
emailPtn = new RegExp("^[a-zA-Z0-9!$&*.=^`|~#%'+\/?_{}-]+@([a-zA-Z0-9_-]+\.)+[a-zA-Z]{2,4}$");

/* OS振分け */
if (navigator.platform.indexOf('Mac') > -1) 
{
	//mac users
	document.write('<link href="/css/mac.css" rel="stylesheet" type="text/css">');
}
else
{
	//windows or others
	document.write('<link href="/css/win.css" rel="stylesheet" type="text/css">');
}


/* センターオープンウィンドウ */
function center_openBrWindow(theURL,winName,wx,wy,features) {
  x = (screen.width  - wx) / 2;
  y = (screen.height - wy) / 2;
  window.open(theURL,winName,features+",left="+x+",top="+y+",width="+wx+",height="+wy);
}


/* アドミン系に使うオープンウィンドウ */

function openSimpleWindow(wnd, url, left, top, width, height) {
	myWindow = window.open(url, wnd, 'resizable=yes,scrollbars=YES,menubar=no,toolbar=no,status=yes,width=' + width + ',height=' + height + ',left=' + left + ',top=' + top);
	myWindow.focus();
}


/* らくらくリクエストの選択フィールド消去 */
function clearValue() {
	for (i = 0; i < clearValue.arguments.length; i++) {
		if (clearValue.arguments[i] && clearValue.arguments[i].value) {
			clearValue.arguments[i].value = "";
		}
	}
}


/* DWのロールオーバー */
function MM_swapImgRestore() {
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


/* クイック検索と詳細検索のセレクトテキスト排他 */
function ch_jyuusyo(){
	document.option_search.rosen_id1.value = "";
	document.option_search.eki_id1.value = "";
	document.option_search.terminal_eki.value = "";
}

function ch_rosen(){
	document.option_search.jyuusyo.value = "";
	document.option_search.eki_id1.value = "";
	document.option_search.terminal_eki.value = "";
}

function ch_eki(){
	document.option_search.rosen_id1.value = "";
	document.option_search.jyuusyo.value = "";
	document.option_search.terminal_eki.value = "";
}

function ch_terminal(){
	document.option_search.rosen_id1.value = "";
	document.option_search.jyuusyo.value = "";
	document.option_search.eki_id1.value = "";
}


/* トップページのクイック検索フォーム必須項目チェック */

function option_search_check(){
var	err_cnt=0;
var	msg = "";

if (document.option_search.jyuusyo.value=="" && document.option_search.rosen_id1.value=="" && document.option_search.eki_id1.value=="" && document.option_search.terminal_eki.value==""){
	msg = "『住所、沿線、駅、ターミナルのどれか一つは選択して下さい』\n"+ msg;
	err_cnt = err_cnt + 1;
	document.option_search.jyuusyo.focus();
}

if (err_cnt==0){
	document.option_search.submit();
}else{
	msg += "\n上記 " + err_cnt + " 項目が未入力です。\nこの項目は必ず入力をお願いします。";
	alert(msg);
	return;
	}
}


/* トップページの物件名検索フォーム必須項目チェック */

function bukken_name_search_check(){
var	err_cnt=0;
var	msg = "";

if (document.bukken_name_search.name_kensaku.value==""){
	msg = "『物件名』\n"+ msg;
	err_cnt = err_cnt + 1;
	document.bukken_name_search.name_kensaku.focus();
}

if (err_cnt==0){
	document.bukken_name_search.submit();
}else{
	msg += "\n上記 " + err_cnt + " 項目が未入力です。\nこの項目は必ず入力をお願いします。";
	alert(msg);
	return;
	}
}


/* 条件検索フォーム必須項目チェック */

function option_search_allcheck(){
var	err_cnt=0;
var	msg = "";

//if (document.option_search.jyuusyo.value=="" && document.option_search.rosen_id1.value=="" && document.option_search.eki_id1.value=="" && document.option_search.terminal_eki.value=="" &&

	if (err_cnt == 0) {
/*
		if (document.option_search.nyukyo_ninzu.value=="" && document.option_search.kenchiku_y.value=="" &&
			document.option_search.new_web_bed_type1.checked==false && document.option_search.new_web_bed_type2.checked==false && document.option_search.new_web_bed_type3.checked==false && 
			document.option_search.hirosa_s.value=="" && document.option_search.hirosa_m.value=="" && document.option_search.yachin_s.value=="" && document.option_search.yachin_m.value=="" && 

			document.option_search.madori1R.checked==false && document.option_search.madori1K.checked==false && document.option_search.madori1DK.checked==false && document.option_search.madori1LDK.checked==false && 
			document.option_search.madori1SLDK.checked==false && document.option_search.madori2K.checked==false && document.option_search.madori2DK.checked==false && document.option_search.madori2LDK.checked==false && 
			document.option_search.madori2SLDK.checked==false && 

			document.option_search.jyouken1.checked==false && document.option_search.campaign.checked==false && document.option_search.jyouken3.checked==false && document.option_search.jyouken4.checked==false && 
			document.option_search.jyouken5.checked==false && document.option_search.jyouken6.checked==false && document.option_search.jyouken7.checked==false && document.option_search.jyouken8.checked==false && 
			document.option_search.jyouken9.checked==false
			){
			msg = "『条件をどれか一つは選択して下さい』\n"+ msg;
			err_cnt = err_cnt + 1;
			//document.option_search.jyuusyo.focus();
		}
*/
	}

	if (err_cnt==0){
		document.option_search.submit();
	}else{
		msg += "\n上記 " + err_cnt + " 項目が未入力です。\nこの項目は必ず入力をお願いします。";
		alert(msg);
		return;
	}
}


/* お問合せフォーム必須項目チェック */

function contact_check(){
var	err_cnt=0;
var	msg = "";

if (document.contact.mail.value=="" && document.contact.tel.value==""){
	msg = "『メール』または『電話』\n"+ msg;
	err_cnt = err_cnt + 1;
	document.contact.mail.focus();
}
//脆弱性修正
else{
	var e = document.contact.mail;
	if(e.value != ""){
		if(!e.value.match(emailPtn)){
			msg = "『メールの形式が不正です』\n" + msg;
			err_cnt = err_cnt + 1;
			e.focus();
		}
	}
}

if (document.contact.toi_name.value==""){
	msg = "『氏名』\n"+ msg;
	err_cnt = err_cnt + 1;
	document.contact.toi_name.focus();
}

if (err_cnt==0){
	document.contact.submit();
}else{
	msg += "\n上記 " + err_cnt + " 項目が未入力です。\nこの項目は必ず入力をお願いします。";
	alert(msg);
	return;
	}
}

/* お問合せフォームリセット */

function contact_reset(){

	document.contact.toi_name.value="";
	document.contact.name_kana.value="";
	document.contact.mail.value="";
	document.contact.tel.value="";
	document.contact.comment.value="";
	
	return;
}

/* お問合せバック */

function contact_back(){

	document.contact.action = "./index.html";
	document.contact.submit();

}

/* お問合せ実行 */

function contact_submit(){

	document.contact.action = "./process.php";
	document.contact.submit();

}

/* リクエストフォームリセット */

function request_reset(){

	document.request_input.kibou_area_text.value="";
	document.request_input.kibou_area_shousai.value="";
	document.request_input.kibou_area_text2.value="";
	document.request_input.kibou_area_shousai2.value="";
	document.request_input.kibou_area_text3.value="";
	document.request_input.kibou_area_shousai3.value="";

	document.request_input.koutsuu_kiten.value="";
	document.request_input.idou_jikan.value="";

	document.request_input.rosen_eki_text1.value="";
	document.request_input.rosen_eki_text2.value="";
	document.request_input.rosen_eki_text3.value="";

	document.request_input.nyuukyo_kiboubi_y.value="";
	document.request_input.nyuukyo_kiboubi_m.value="";
	document.request_input.nyuukyo_kiboubi_d.value="";

	document.request_input.riyou_kikan.value="";
	document.request_input.riyou_ninzuu.value="";
	document.request_input.riyou_heyasuu.value="";

	document.request_input.customer_comment.value="";
	document.request_input.customer_name.value="";
	document.request_input.customer_name_kana.value="";
	document.request_input.tel1.value="";
	document.request_input.tel2.value="";
	document.request_input.fax1.value="";
	document.request_input.fax2.value="";
	document.request_input.email_pc.value="";
	document.request_input.email_mobile.value="";

	return;
}

/* リクエストバック */

function request_back(){

	document.contact.action = "./index.html";
	document.contact.submit();

}

/* リクエスト実行 */

function request_submit(){

	document.contact.action = "./process.php";
	document.contact.submit();

}

/* リクエストフォーム必須項目チェック */

function request_check(){
var	err_cnt=0;
var	msg = "";

if (document.request_input.email_pc.value=="" && document.request_input.email_mobile.value=="" && document.request_input.tel1.value=="" && document.request_input.tel2.value=="" && document.request_input.fax1.value=="" && document.request_input.fax2.value==""){
	msg = "『連絡先』\n"+ msg;
	err_cnt = err_cnt + 1;
	document.request_input.email_pc.focus();
}
//脆弱性修正
else{
	var e = document.request_input.email_pc;
	
	if(e.value != ""){
		if(!e.value.match(emailPtn)){
			msg = "『メールアドレス1の形式が不正です』\n" + msg;
			err_cnt = err_cnt + 1;
			e.focus();
		}
	}
	var e = document.request_input.email_mobile;
	if(e.value != ""){
		if(!e.value.match(emailPtn)){
			msg = "『メールアドレス2の形式が不正です』\n" + msg;
			err_cnt = err_cnt + 1;
			e.focus();
		}
	}
}

if (document.request_input.customer_name.value==""){
	msg = "『氏名』\n"+ msg;
	err_cnt = err_cnt + 1;
	document.request_input.customer_name.focus();
}

if (document.request_input.nyuukyo_kiboubi_y.value=="" || document.request_input.nyuukyo_kiboubi_m.value=="" || document.request_input.nyuukyo_kiboubi_d.value==""){
	msg = "『入居希望日』\n"+ msg;
	err_cnt = err_cnt + 1;
	document.request_input.nyuukyo_kiboubi_y.focus();
}

if (document.request_input.kibou_area_text.value==""){
	msg = "『エリア1』\n"+ msg;
	err_cnt = err_cnt + 1;
	document.request_input.kibou_area_text.focus();
}

if (err_cnt==0){
	document.request_input.submit();
}else{
	msg += "\n上記 " + err_cnt + " 項目が未入力です。\nこの項目は必ず入力をお願いします。";
	alert(msg);
	return;
	}
}


/* 法人会員登録フォーム必須項目チェック */

function houjin_check(){
	err_cnt=0;
	msg = "";

	if (document.houjin_input.tantosya_name_kana.value==""){
		msg = "『ご担当者フリガナ』\n"+ msg;
		err_cnt = err_cnt + 1;
		document.houjin_input.tel.focus();
	}

	if (document.houjin_input.tantosya_name.value==""){
		msg = "『ご担当者名』\n"+ msg;
		err_cnt = err_cnt + 1;
		document.houjin_input.tel.focus();
	}

	if (document.houjin_input.fax.value==""){
		msg = "『ＦＡＸ』\n"+ msg;
		err_cnt = err_cnt + 1;
		document.houjin_input.tel.focus();
	}

	if (document.houjin_input.tel.value==""){
		msg = "『電話』\n"+ msg;
		err_cnt = err_cnt + 1;
		document.houjin_input.tel.focus();
	}

	if (document.houjin_input.mail.value==""){
		msg = "『メール』\n"+ msg;
		err_cnt = err_cnt + 1;
		document.houjin_input.tel.focus();
	}
	//脆弱性修正
	else{
		var e = document.houjin_input.mail;
		if(e.value != ""){
			if(!e.value.match(emailPtn)){
				msg = "『メールの形式が不正です』\n" + msg;
				err_cnt = err_cnt + 1;
				e.focus();
			}
		}
	}

	if (document.houjin_input.corporation_add.value==""){
		msg = "『住所』\n"+ msg;
		err_cnt = err_cnt + 1;
		document.houjin_input.corporation_name.focus();
	}

	if (document.houjin_input.corporation_zip.value==""){
		msg = "『郵便番号』\n"+ msg;
		err_cnt = err_cnt + 1;
		document.houjin_input.corporation_name.focus();
	}

	if (document.houjin_input.corporation_name_kana.value==""){
		msg = "『御社名フリガナ』\n"+ msg;
		err_cnt = err_cnt + 1;
		document.houjin_input.corporation_name.focus();
	}

	if (document.houjin_input.corporation_name.value==""){
		msg = "『御社名』\n"+ msg;
		err_cnt = err_cnt + 1;
		document.houjin_input.corporation_name.focus();
	}

	if (err_cnt==0){
		document.houjin_input.submit();
	}else{
		msg += "\n上記 " + err_cnt + " 項目が未入力です。\nこの項目は必ず入力をお願いします。";
		alert(msg);
		return;
	}
}


/* 反響必須項目チェック */
//============================================================================//
//	日付の形式をチェックする
//============================================================================//
//	引数
//		y       年
//		m       月
//		d       日
//============================================================================//
function checkDate(y, m, d) {
	if ((y.value == "") || (m.value == "") || (d.value == "")) {
		return true;
	}
	else {
		year = "0000" + y.value;
		month = "00" + m.value;
		date = "00" + d.value;
		
		var year1 =  year.substr(year.length - 4, 4);
		var month1 = month.substr(month.length - 2, 2);
		var date1 = date.substr(date.length - 2, 2);
		
		var checkdate = new Date();
		
		checkdate.setDate(1);
		checkdate.setFullYear(year1);
		checkdate.setMonth(month1 - 1);
		checkdate.setDate(date1);
		
		var year2 = checkdate.getFullYear();
		var month2 = checkdate.getMonth() + 1;
		var date2 = checkdate.getDate();
		
		if (month2 < 10) month2 = "0" + month2;  
		if (date2 < 10) date2 = "0" + date2; 
		
		if ("" + year1 + month1 + date1 == "" + year2 + month2 + date2) { 
			y.value = year1; 
			m.value = month1;
			d.value = date1;
			return true;
		}
		else {
			alert("日付が正しくありません");
			d.focus();
			return false;
		}
	}
}

function mousikomi_check(){ 
			
	if (checkDate(document.mousikomi.nyuukyo_kiboubi_y, document.mousikomi.nyuukyo_kiboubi_m, document.mousikomi.nyuukyo_kiboubi_d)==false) return;

	if (checkDate(document.mousikomi.taishutsu_kiboubi_y, document.mousikomi.taishutsu_kiboubi_m, document.mousikomi.taishutsu_kiboubi_d)==false) return;

	err_cnt=0;
	msg="";
		
	if (document.mousikomi.nyuukyo_kiboubi_y.value!="" && document.mousikomi.nyuukyo_kiboubi_m.value!="" && document.mousikomi.nyuukyo_kiboubi_d.value!="" && document.mousikomi.taishutsu_kiboubi_y.value!="" && document.mousikomi.taishutsu_kiboubi_m.value!="" && document.mousikomi.taishutsu_kiboubi_d.value!=""){
		days = document.mousikomi.nyuukyo_kiboubi_y.value + document.mousikomi.nyuukyo_kiboubi_m.value + document.mousikomi.nyuukyo_kiboubi_d.value;
		dayf = document.mousikomi.taishutsu_kiboubi_y.value + document.mousikomi.taishutsu_kiboubi_m.value + document.mousikomi.taishutsu_kiboubi_d.value;
		if (days > dayf){
			msg = "『期間の日付が不正です』\n"+ msg;
			err_cnt = err_cnt + 1;
			document.mousikomi.nyuukyo_kiboubi_y.focus();
			alert(msg);
			return;
		}
	}

	//脆弱性修正
	var e = document.mousikomi.email;
	if(e.value != ""){
		if(!e.value.match(emailPtn)){
			msg = "『メールの形式が不正です』\n" + msg;
			err_cnt = err_cnt + 1;
			e.focus();
		}
	}


	if (document.mousikomi.tel1.value=="" && document.mousikomi.tel2.value=="" && document.mousikomi.email.value==""){
		msg = "『連絡先』\n"+ msg;
		err_cnt = err_cnt + 1;
		document.mousikomi.tel1.focus();
	}

	if (document.mousikomi.customer_name.value==""){
		msg = "『氏名』\n"+ msg;
		err_cnt = err_cnt + 1;
		document.mousikomi.customer_name.focus();
	}

	if (document.mousikomi.taishutsu_kiboubi_y.value=="" || document.mousikomi.taishutsu_kiboubi_m.value=="" || document.mousikomi.taishutsu_kiboubi_d.value==""){
		msg = "『退出希望日』\n"+ msg;
		err_cnt = err_cnt + 1;
		document.mousikomi.taishutsu_kiboubi_y.focus();
	}

	if (document.mousikomi.nyuukyo_kiboubi_y.value=="" || document.mousikomi.nyuukyo_kiboubi_m.value=="" || document.mousikomi.nyuukyo_kiboubi_d.value==""){
		msg = "『入居希望日』\n"+ msg;
		err_cnt = err_cnt + 1;
		document.mousikomi.nyuukyo_kiboubi_y.focus();
	}
	
	

	if (err_cnt==0){
		document.mousikomi.submit();
	}else{
		msg += "\n上記 " + err_cnt + " 項目が未入力です。\nこの項目は必ず入力をお願いします。";
		alert(msg);
		return false;
	}
}


/* 年月日フィールドタイプチェック　*/

function singlebyte(s,file01) {
   cnst="1234567890";
   for (i=0;i<s.length;i++) {
      sw="ng";
      for (j=0;j<cnst.length;j++) {
         if (cnst.charAt(j)==(s.charAt(i))) sw="ok";
      }
      if (sw=="ng") {
         alert("半角数字以外の文字が入力されています。");
         file01.focus();
         break;
      }
   }
}


/* 電話番号フィールドタイプチェック　*/

function singlebyte2(s,file01) {
   cnst="1234567890-";
   for (i=0;i<s.length;i++) {
      sw="ng";
      for (j=0;j<cnst.length;j++) {
         if (cnst.charAt(j)==(s.charAt(i))) sw="ok";
      }
      if (sw=="ng") {
         alert("使用できない文字があります。");
         file01.focus();
         break;
      }
   }
}
