/************************************************************************
Common JavaScript File
copyright(c) Nippon System Kaihatsu co., ltd.
*************************************************************************/
//j$(document).ready(function(){
	//*****見積り機能
//});



//--------------------------------------------------------------------------
//3桁カンマ区切り
//--------------------------------------------------------------------------
function number_format(str) {
	var num = new String(str).replace(/,/g, "");
	while(num != (num = num.replace(/^(-?\d+)(\d{3})/, "$1,$2")));
	return num;
}

//--------------------------------------------------------------------------
//Windowを閉じる
//--------------------------------------------------------------------------
function window_request(url,data){
	//url → 開くページのURL
	//data→ 日付け
    window.open(url,data);
    return false;
}

//--------------------------------------------------------------------------
//方面リストの選択変更－＞国リストの表示
//--------------------------------------------------------------------------
function change_area(id, num) {
	var area = document.getElementById(id).value;
	ele = document.getElementById("ArrivalCountryCode@"+num);
	ele.options.length = 1;		//ご選択は残す
	document.getElementById("TourArrivalArrivalCode@"+num).options.length = 1;
	if (area != "") {
		cnt = countries[area]["code"].length;
		for (i=0;i<cnt;i++) {
			ele.options[i+1] = new Option(countries[area]["name"][i],countries[area]["code"][i]);
			if (sel_country[num-1] == countries[area]["code"][i]) {
				ele.selectedIndex = i+1;
			}
		}
	}
	return true;
}


//--------------------------------------------------------------------------
//国リストの選択変更－＞都市リストの表示
//--------------------------------------------------------------------------
function change_country(id, num) {
	country = document.getElementById(id).value;
	ele = document.getElementById("TourArrivalArrivalCode@"+num);
	ele.options.length = 1;		//ご選択は残す
	if (country != "") {
		cnt = arrivals[country]["code"].length;
		for (i=0;i<cnt;i++) {
			ele.options[i+1] = new Option(arrivals[country]["name"][i],arrivals[country]["code"][i]);
			if (sel_arrival[num-1] == arrivals[country]["code"][i]) {
				ele.selectedIndex = i+1;
			}
		}
	}
	return true;
}

var sClassName;


//------------------------------------------------------------------------------------------------
//■料金カレンダーのマウスアウト
//------------------------------------------------------------------------------------------------
function cal_out(id) {
	if (id != "") {
		var ele = document.getElementById(id);
		ele.className = sClassName;
		sClassName = "";
	}
}

//------------------------------------------------------------------------------------------------
//■料金カレンダーのマウスオーバー
//------------------------------------------------------------------------------------------------
function cal_over(id) {
	if (id != "") {
		var ele = document.getElementById(id);
		sClassName = ele.className;
		ele.className += " calOver";
	}
}

//------------------------------------------------------------------------------------------------
//■問い合わせページへの遷移
//------------------------------------------------------------------------------------------------
function mvInquiries(f, url) {
	if (url != ""){
		document.forms[0].target="_new";
		document.forms[0].method="POST";
		document.forms[0].action=url;
		document.forms[0].submit();
	}
}


var FormName = "InquiryConfirmForm";
//------------------------------------------------------------------------------------------------
//■問い合わせ入力ページの選択リスト追加
//------------------------------------------------------------------------------------------------
function AddElement(m) {
	var ele;
	//カウンタ
	n = ++document.forms[FormName].elements["data[Param][DetailCount"+m+"]"].value;
	//1行目を複製
	var element= document.getElementById("DetailRow0"+m).cloneNode(true);
	element.setAttribute("id", "DetailRow" + n + m);

	//全てのform要素の名前を変更
	for (i=0;i<element.childNodes.length;i++) {
		sTag = element.childNodes[i].tagName;
		if (sTag == null || sTag == '' || sTag == undefined) {continue;}
		sTag = sTag.toLowerCase();
		//divの場合は一階層のみ処理


		if (sTag == "div") {
			for (j=0;j<element.childNodes[i].childNodes.length;j++) {
				sTag = element.childNodes[i].childNodes[j].tagName;
				sTag = sTag.toLowerCase();
			if (sTag == "input" || sTag == "select" || sTag == "textarea") {
					node = element.childNodes[i].childNodes[j];
					break;
				}
			}
		} else {
			node = element.childNodes[i];
		}

	if (sTag == "input" || sTag == "select" || sTag == "textarea") {
			sType = node.getAttribute("type");
			sName = node.getAttribute("name");
			sName = sName.replace("[0]", "["+n+"]");
			node.setAttribute("name", sName);
			sId = node.id;
			sId = sId.replace("0", n);
			node.id = sId;
			if (sType == "checkbox") {
				//node.setAttribute("default", false);
				node.setAttribute("checked", false);
				node.removeAttribute("checked");
				s2 = node.onclick + "";
				if (s2 != null) {
					s2 = s2.replace(/0/g, n);
					nPos = s2.indexOf("{");
					if (nPos >= 0) {
						s2 = s2.substring(nPos + 1);
						s2 = s2.replace("}", "");
					}
					node.onclick = new Function(s2);
				}
			} else if (sType == "button" || sType == "hidden") {
				//何もしない

			} else {
				node.value = "";
			}
		} else if (sTag == "a") {
			//「.0」を置き換え対象
			s1 = node.innerHTML;
			s2 = node.onclick + "";
			s2 = s2.replace(/\.0/g, "\."+n);
			nPos = s2.indexOf("{");
			if (nPos >= 0) {
				s2 = s2.substring(nPos + 1);
				s2 = s2.replace("}", "");
			}

			node.innerHTML = s1.replace(".0", "." + n);
			node.onclick = new Function(s2);

		} else if (sTag == "span") {
			sId = node.id;
			sId = sId.replace("0", n);
			node.id = sId;
		}
	}
	//行追加
	document.getElementById("DetailForm"+m).appendChild(element);

}

