// **********************************************************************************
//	e3 : h_src06.htm用 JavaScript
// **********************************************************************************
//**************************************************
// 半角英字の大文字変換
//**************************************************
function upperMe(field) {
	field.value=field.value.toUpperCase()
}


//**************************************************
// 半角文字を半角文字に変換
//**************************************************
function z2h_ascii(src, exc) {
  var str = new String;
  var len = src.length;
  for (var i = 0; i < len; i++) {
    var c = src.charCodeAt(i);
    if (exc.indexOf(src.charAt(i)) > -1) {
      str += src.charAt(i); /* 除外 */
    } else if (c >= 65281 && c <= 65374 && c != 65340) {
      str += String.fromCharCode(c - 65248);
    } else if (c == 8217) {
      str += String.fromCharCode(39);
    } else if (c == 8221) {
      str += String.fromCharCode(34);
    } else if (c == 12288) {
      str += String.fromCharCode(32);
    } else if (c == 65507) {
      str += String.fromCharCode(126);
    } else if (c == 65509) {
      str += String.fromCharCode(92);
    } else {
      str += src.charAt(i);
    } 
  }
  return str;
}

//**************************************************
// 検索文字項目のonChangeイベント
//**************************************************
function onChangeWord(field) {
	
	//全角文字を半角文字に変換
	field.value = z2h_ascii(field.value, "");
	
	//半角小文字を半角大文に変換
	field.value=field.value.toUpperCase()

}

//**************************************************
// 地域のコンボボックス変更 2009.11.30
// Combo 2:国リスト作成
// Combo 4:都市リスト作成
//**************************************************
function changeCombo(ComboNo, autoCode) {
	if (ComboNo==1){
		dispNameList(null, ComboNo, autoCode);
	} else if (ComboNo==2){
		dispNameList(document.quform.areacd.value, ComboNo, autoCode);
	} else if (ComboNo==4) {
		dispNameList(document.quform.natcd.value, ComboNo, autoCode);
	} else if (ComboNo==5) {
		dispNameList(document.quform.citycd.value, ComboNo, autoCode);
	} else {
		alert("コンボボックス番号が間違っています。");
	}
	return true;
}
function dispNameList(selcode, ComboNo, autoCode) {

	//非同期通信を行うためのXMLHttpRequestオブジェクトを生成
	try{
		xmlReq = new ActiveXObject("Microsoft.XMLHTTP");
	}catch(e){
		xmlReq = new XMLHttpRequest();
	}

	//サーバーからの応答時の処理を定義
if (/Gecko/.test(navigator.userAgent) && /Firefox/.test(navigator.userAgent)) {
	xmlReq.onload = function() {
		if (ComboNo==1) {
			var combo_area = document.getElementById("area");
		} else if (ComboNo==2) {
			var combo_area = document.getElementById("nation");
		} else if (ComboNo==4) {
			var combo_area = document.getElementById("city");
		} else if (ComboNo==5) {
			var combo_area = document.getElementById("zone");
		} else {
			var combo_area = document.getElementById("city");
		}
		if(xmlReq.readyState==4){
			if(xmlReq.status==200){
				combo_area.innerHTML = xmlReq.responseText;
				return true;
				
			}
			else{
				combo_area.innerHTML =
				 "<FONT color='#336699' size='5'>通信に失敗しました。</FONT>";
			}
		}
		else{
			combo_area.innerHTML = "<FONT color='#336699' size='5'></FONT>";
		}
	}
}else{
	xmlReq.onreadystatechange = function(){
		if (ComboNo==1) {
			var combo_area = document.getElementById("area");
		} else if (ComboNo==2) {
			var combo_area = document.getElementById("nation");
		} else if (ComboNo==4) {
			var combo_area = document.getElementById("city");
		} else if (ComboNo==5) {
			var combo_area = document.getElementById("zone");
		} else {
			var combo_area = document.getElementById("city");
		}
		if(xmlReq.readyState==4){
			if(xmlReq.status==200){
				combo_area.innerHTML = xmlReq.responseText;
				return true;
				
			}
			else{
				combo_area.innerHTML =
				 "<FONT color='#336699' size='5'>通信に失敗しました。</FONT>";
			}
		}
		else{
			combo_area.innerHTML = "<FONT color='#336699' size='5'></FONT>";
		}
	}
}
	//ajax.phpプログラムへデータを送信
	xmlReq.open("POST","../h/arealist.php",false);
	xmlReq.setRequestHeader("content-type",
			"application/x-www-form-urlencoded;charset=UTF-8");
	xmlReq.send("arecode=" + encodeURI(selcode) + "&arekbn=" + encodeURI(ComboNo) + "&autocode=" + encodeURI(autoCode));
}
//**************************************************
// 検索ボタン
//**************************************************
function clickSearch() {
	var strLocation = "";
	var strPara = "";
	var strKey  = trimAll(document.quform.keyword.value.toUpperCase());

	if ( document.quform.areacd.value == "" && document.quform.natcd.value == ""  &&  strKey.length == 0){
		alert("検索項目を入力してください");	
		return false;
	}
		
	if ( document.quform.roomtype.value*document.quform.total_room.value > 9){
		alert("ご指定の条件が9名または9室を超えています。");	
		return false;
	}
//	var w_checkin_date = document.quform.checkin_date.value;
//	var now          = new Date();
//	var w_today      = formatDate(now, "yyyy/MM/dd");
//	if ( w_today >= w_checkin_date ) {
//		alert("チェックイン日は明日以降の日付を入力してください。");
//		document.quform.checkin_date.value = w_today;
//		return false;
//	}
		//ロケーション
		strLocation = '../h/h_src09.php';
		
		//パラメータ受け渡し用変数に値を設定
		strPara = '';
		if ( document.quform.citycd.value != "") {
			strPara = strPara + '?citycd='  + document.quform.citycd.value.trim();
		} else if ( document.quform.natcd.value != "") {
			strPara = strPara + '?natcd='  + document.quform.natcd.value.trim();
		} else if ( document.quform.areacd.value.trim() != "") {
			strPara = strPara + '?areacd=' + document.quform.areacd.value.trim();
		}
		if ( document.quform.zonecd.value != "") {
			strPara = strPara + '&zonecd='  + document.quform.zonecd.value.trim();
		}
		if (strPara != ""){
			strPara = strPara + '&';
		}else{
			strPara = strPara + '?';
		}
//		strPara = strPara + 's_type=' + '50';
		strPara = strPara + 'keyword=' + encodeURI(strKey);

//		alert(document.quform.zonecd.value);
		document.quform.action = strLocation + strPara;
		document.quform.method="post";
		document.quform.target="_self";
		document.quform.submit();	
	
}

// 半角英文字チェック
function check_englishstring(str) {
	//半角スペースを削除
	str = str.replace(' ' ,'');
	//全角スペースを削除
	str = str.replace('　' ,'');

	var i = 0;
	var len = str.length;

	// Null OK
	if (len==0 || len==null)
		return true
	// 英文字(a-z,A-Z)以外はfalse
	for (i=0; i<len; i++) {
		if ( (str.substring(i,i+1)<'a' || 'z'<str.substring(i,i+1))
			 && (str.substring(i,i+1)<'A' || 'Z'<str.substring(i,i+1)) )
				return false;
	}
	return true;
}

//全角であるかをチェックします。
function checkIsZenkaku(str) {

	//半角スペースを削除
	str = str.replace(' ' ,'');
	for (var i = 0; i < str.length; ++i) {
		var c = str.charCodeAt(i);
		//  半角カタカナは不許可
		if (c < 256 || (c >= 0xff61 && c <= 0xff9f)) {
			return false;
		}
	}
	return true;
}

function trimAll(sString) {
	while (sString.substring(0,1) == ' '){
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' '){
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}
function clearFormAll() {
    for (var i=0; i<document.forms.length; ++i) {
        clearForm(document.forms[i]);
    }
}
function clearForm(form) {
    for(var i=0; i<form.elements.length; ++i) {
        clearElement(form.elements[i]);
    }
	document.getElementById("max_price").value = "";
	document.getElementById("min_price").value = "";
}
function clearElement(element) {
    switch(element.type) {
        case "checkbox":
            element.checked = false;
            return;
        default:
    }
}

//**************************************************
// 空室照会カテゴリー直接リンク
//**************************************************
function clickCtgryVacant(ps_jhcno, ps_ctgcd) {
	var strLocation = "";
	var strLinkPara = "";

	strLocation = '../h/h_inf01.php';

	strLinkPara = '?jhcno=' + ps_jhcno;
	strLinkPara = strLinkPara + '&sel_ctgry=' + ps_ctgcd;
	strLinkPara = strLinkPara + '&checkin_date=' + document.vacant.checkin_date.value;
	strLinkPara = strLinkPara + '&sel_stay=' + document.quform.stay_days.value;

	document.vacant.action = strLocation + strLinkPara;
	document.vacant.method="post";
	document.vacant.target="_self";
	document.vacant.submit();	

}

