var domBlockCity	= new Array();
var intAreaType1	= new Array();
var intAreaType2	= new Array();
var intBlockCity1	= new Array();
var intBlockCity2	= new Array();
var cnt				= 0;

// 국내 도시제한 정보
cnt = 0;
domBlockCity[cnt++] = new blockCityData("KWJ", "1", "GMP,CJU", "");								// 광주
domBlockCity[cnt++] = new blockCityData("GMP", "1", "PUS,CJU,KWJ,USN,KPO,RSU,TAE", "");	// 김포
domBlockCity[cnt++] = new blockCityData("TAE", "1", "GMP,CJU", "");							// 대구
domBlockCity[cnt++] = new blockCityData("PUS", "1", "GMP,ICN,CJU", "");							// 부산
domBlockCity[cnt++] = new blockCityData("RSU", "1", "GMP", "");									// 여수
domBlockCity[cnt++] = new blockCityData("USN", "1", "GMP", "");									// 울산
domBlockCity[cnt++] = new blockCityData("ICN", "1", "PUS,CJU", "");							// 인천
domBlockCity[cnt++] = new blockCityData("CJU", "1", "GMP,ICN,PUS,TAE,KWJ,CJJ,KPO,MWX,HIN", "");				// 제주
domBlockCity[cnt++] = new blockCityData("HIN", "1", "CJU", "");									// 진주
domBlockCity[cnt++] = new blockCityData("CJJ", "1", "CJU", "");									// 청주
domBlockCity[cnt++] = new blockCityData("KPO", "1", "GMP", "");									// 포항
domBlockCity[cnt++] = new blockCityData("MWX", "1", "CJU", "");									// 무안

// 국제 지역 정보 (일반)
cnt = 0
intAreaType1[cnt++]	= new areaData("KR1"	, "한국"			, "Korea"			, ""		, "");
intAreaType1[cnt++]	= new areaData("IJ"		, "일본"			, "Japan"			, ""		, "");
intAreaType1[cnt++]	= new areaData("CN1"	, "중국"			, "China"			, ""		, "");
intAreaType1[cnt++]	= new areaData("IC"		, "중앙아시아"		, "Center Asia"		, ""		, "");
intAreaType1[cnt++]	= new areaData("RU1"	, "러시아"			, "Russia"			, ""		, "");
intAreaType1[cnt++]	= new areaData("IS"		, "동남아"			, "South East Asia"	, "IG"		, "");
intAreaType1[cnt++]	= new areaData("IA"		, "미국"			, "U.S.A"			, ""		, "");
intAreaType1[cnt++]	= new areaData("IH"		, "대양주"			, "Australia"		, ""		, "");
intAreaType1[cnt++]	= new areaData("IE"		, "유럽"			, "Europe"			, ""		, "");

// 국제 지역 정보 (보너스)
cnt = 0;
intAreaType2[cnt++]	= new areaData("KR1"	, "한국"			, "Korea"			, ""		, "");
intAreaType2[cnt++]	= new areaData("IJ"		, "일본"			, "Japan"			, ""		, "");
//intAreaType2[cnt++]	= new areaData("CN1"	, "동북아(중국)"	, "China"			, "RU1,TPE"	, "");
//intAreaType2[cnt++]	= new areaData("IS"		, "동남아"			, "South East Asia"	, "IG,SPN"	, "TPE,DEL");
intAreaType2[cnt++]	= new areaData("CN1"	, "동북아(중국)"	, "China"			, "RU1,TPE"	, "HKG");
intAreaType2[cnt++]	= new areaData("IS"		, "동남아"			, "South East Asia"	, "IG,SPN,HKG,ROR"	, "TPE,DEL");
intAreaType2[cnt++]	= new areaData("IC"		, "서남아"			, "South West Asia"	, "DEL"		, "");
intAreaType2[cnt++]	= new areaData("IA"		, "미국"			, "U.S.A"			, ""		, "");
intAreaType2[cnt++]	= new areaData("IH"		, "대양주"			, "Australia"		, ""		, "SPN,ROR");
intAreaType2[cnt++]	= new areaData("IE"		, "유럽"			, "Europe"			, ""		, "");

// 국제 도시제한 정보 (일반)
cnt = 0;
//intBlockCity1[cnt++]	= new blockCityData("KWJ", "1", "PEK"											, "ICN"	, "CN1");
intBlockCity1[cnt++]	= new blockCityData("GMP", "1", "HND,SHA,KIX"									, ""	, "IJ,CN1");
//intBlockCity1[cnt++]	= new blockCityData("TAE", "1", "PVG"											, "ICN"	, "CN1");
intBlockCity1[cnt++]	= new blockCityData("MWX", "1", "PEK"											, "ICN"	, "CN1");
intBlockCity1[cnt++]	= new blockCityData("PUS", "1", "CAN,PEK,SHE,HGH,PVG,FUK,KIX,MNL,SPN,WEH,HKG"		, "ICN"	, "IJ,CN1,IS,IH");
intBlockCity1[cnt++]	= new blockCityData("ICN", "2", "HND,SHA,SHE"										, ""	, "IJ,CN1,IC,RU1,IS,IA,IH,IE");
intBlockCity1[cnt++]	= new blockCityData("CJU", "1", "FUK"											, "ICN"	, "IJ");
intBlockCity1[cnt++]	= new blockCityData("CJJ", "1", "PEK"											, "ICN"	, "CN1");

// 국제 도시제한 정보 (보너스)
cnt = 0;
//intBlockCity2[cnt++]	= new blockCityData("KWJ", "1", "PEK"											, "ICN"	, "CN1");
intBlockCity2[cnt++]	= new blockCityData("GMP", "1", "HND,SHA,KIX,PEK"									, ""	, "IJ,CN1");
//intBlockCity2[cnt++]	= new blockCityData("TAE", "1", "PVG"											, "ICN"	, "CN1");
intBlockCity2[cnt++]	= new blockCityData("MWX", "1", "PEK"											, "ICN"	, "CN1");
intBlockCity2[cnt++]	= new blockCityData("PUS", "1", "CAN,PEK,SHE,HGH,PVG,FUK,KIX,MNL,SPN,WEH,HKG"		, "ICN"	, "IJ,CN1,IS");
intBlockCity2[cnt++]	= new blockCityData("ICN", "2", "HND,SHA,SHE"										, ""	, "IJ,CN1,IC,IS,IA,IH,IE");
intBlockCity2[cnt++]	= new blockCityData("CJU", "1", "FUK"											, "ICN"	, "IJ");
intBlockCity2[cnt++]	= new blockCityData("CJJ", "1", "PEK"											, "ICN"	, "CN1");

// 지역정보 형태
function areaData(area, korName, engName, addCity, delCity) {
	this.area		= area;
	this.korName	= korName;
	this.engName	= engName;
	this.addCity	= addCity;
	this.delCity	= delCity;
}

// 도시정보 형태
function cityData(city, cityName, ctlval1, ctlval2) {
	this.city		= city;
	this.cityName	= cityName;
	this.ctlval1	= ctlval1;
	this.ctlval2	= ctlval2;
}

// 도시제한정보 형태
function blockCityData(city, checkType, arrCity, targetArrCity, areaList) {
	this.city			= city;
	this.checkType		= checkType;
	this.arrCity		= arrCity;
	this.targetArrCity	= targetArrCity;
	this.areaList		= areaList;
}

// 국내 출발도시 선택
function setDomDepCity(depCityName, arrCityName, defaultDepCity, defaultArrCity) {
	var depCity	= getSelectObject(depCityName);
	var arrCity	= getSelectObject(arrCityName);
	var defaultCity = "";

	try {
		// 도시 정보 표기
		clearSelectItem(depCity);
		//depCity.length = 0;
		//depCity.length = 0;
		for (var i=0; i<domCity.length; i++) {
			var data = domCity[i];
			addSelectItem(depCity, data.city, data.cityName);
			//depCity.length = depCity.length + 1;
			//depCity[depCity.length-1].value	= data.city;
			//depCity[depCity.length-1].text	= data.cityName;
		}

		if (defaultCity != null) {
			depCity.value = defaultDepCity;
			if (depCity.selectedIndex < 0) depCity.selectedIndex = 0;
		}

		setDomArrCity(depCityName, arrCityName, defaultArrCity);
	}
	catch(e) {}
}

// 국내 도착도시 선택
function setDomArrCity(depCityName, arrCityName, defaultArrCity) {
	var depCity	= getSelectObject(depCityName);
	var arrCity	= getSelectObject(arrCityName);
	var depCityValue	= depCity[depCity.selectedIndex].value;
	var arrCityValue	= arrCity.selectedIndex >= 0 ? arrCity[arrCity.selectedIndex].value : "";
	var blockCityData	= "";

	try {
		// 도시제한 정보 체크
		for (var i=0; i<domBlockCity.length; i++) {
			var data = domBlockCity[i];
			if (data.city == depCityValue) {
				blockCityData = data.arrCity;
				break;
			}
		}

		// 도착도시 표기
		clearSelectItem(arrCity);
		//arrCity.length = 0;
		//arrCity.length = 0;
		for (var i=0; i<domCity.length; i++) {
			var data = domCity[i];
			if (blockCityData.indexOf(data.city) < 0) continue;

			addSelectItem(arrCity, data.city, data.cityName);
			//arrCity.length = arrCity.length + 1;
			//arrCity[arrCity.length-1].value	= data.city;
			//arrCity[arrCity.length-1].text	= data.cityName;
		}

		// 기존 선택 도시가 있다면 재선택
		if (defaultArrCity != null && arrCityValue == "") arrCityValue = defaultArrCity;
		arrCity.value = arrCityValue;
		if (arrCity.selectedIndex < 0) arrCity.selectedIndex = 0;
	}
	catch(e) {}
}

// 지역내 정보
function getSelectAreaData(obj, areaList) {
	var result = null;

	try {
		for (var i=0; i<areaList.length; i++) {
			if (obj[obj.selectedIndex].value != areaList[i].area) continue;
			result = areaList[i];
			break;
		}
	}
	catch(e) {}

	return result;
}

// 국제 Block 조건 조회
function getSelectBlockData(city, blockList) {
	var result = null;

	try {
		for (var i=0; i<blockList.length; i++) {
			if (blockList[i].city != city) continue;
			result = blockList[i];
			break;
		}
	}
	catch(e) {}

	return result;
}

// 지역포함 도시 여부 판단
function getEnableAreaCity(area, city, direct) {
	var result		= true;
	var addCityList	= area.addCity.split(",");
	var delCityList	= area.delCity.split(",");

	try {
		// 일반지역 체크
		if (!(city.ctlval1 == area.area || city.ctlval2 == area.area)) {
			result = false;
		}

		// 추가지역 체크
		if (!result) {
			for (var i=0; i<addCityList.length; i++) {
				if (addCityList[i] == "") continue;
				if (addCityList[i] == city.city || addCityList[i] == city.ctlval1 || addCityList[i] == city.ctlval2) {
					result = true;
					break;
				}
			}
		}

		// 제외지역 체크
		if (result) {
			for (var i=0; i<delCityList.length; i++) {
				if (delCityList[i] == "") continue;
				if (delCityList[i] == city.city || delCityList[i] == city.ctlval1 || delCityList[i] == city.ctlval2) {
					result = false;
					break;
				}
			}
		}

		// 직항구간일때 체크
		if (direct && city.ctlval1.substring(2,3) != "1") {
			result = false;
		}
	}
	catch(e) {}

	return result;
}

// 도시내 블럭 정보 체크
function getEnableIntBlockCity(city, blockList, depCity) {
	var result = true;

	try {
		if (city.ctlval1 == "KR1") {
			// 국내 출발인 경우
			if (depCity == "") {
				var blockData = null;
				for (var i=0; i<blockList.length; i++) {
					if (blockList[i].city != city.city) continue;
					blockData = blockList[i];
					break;
				}

				if (blockData == null) result = false;
			}
			// 국내 도착인 경우
			else {
				result = false;
				for (var i=0; i<blockList.length; i++) {
					if (blockList[i].city != city.city) continue;
					if (blockList[i].checkType == "1" && blockList[i].arrCity.indexOf(depCity) > -1) {
						result = true;
						break;
					}
					else if (blockList[i].checkType == "2" && blockList[i].arrCity.indexOf(depCity) < 0) {
						result = true;
						break;
					}
				}
			}
		}
		else {
			// 해외 도착인 경우
			if (depCity != "") {
				var blockData = null;
				for (var i=0; i<blockList.length; i++) {
					if (blockList[i].city != depCity) continue;
					blockData = blockList[i];
					break;
				}

				if (blockData == null) {
					result = false;
				}
				else {
					result = checkBlockCity(city, blockData);
				}
			}
			// 해외 출발인 경우
			else {
			}
		}
	}
	catch(e) {}

	return result;
}

// 블럭 도시 체크
function checkBlockCity(city, blockData) {
	var result	= true;
	var list	= blockData.arrCity.split(",");

	try {
		// 선택 도시 체크
		if (blockData.checkType == "1") {
			result = false;
			for (var i=0; i<list.length; i++) {
				if (city.city == list[i]) {
					result = true;
					break;
				}
			}
		}
		// 제외 도시 체크
		else {
			result = true;
			for (var i=0; i<list.length; i++) {
				if (city.city == list[i]) {
					result = false;
					break;
				}
			}
		}
	}
	catch(e) {}

	return result;
}

// 도시내 가능 지역 체크
function getEnableIntBlockArea(area, blockData) {
	var result		= false;

	try {
		if (blockData == null) return result;
		var areaList	= blockData.areaList.split(",");

		for (var i=0; i<areaList.length; i++) {
			if (area.area == areaList[i]) {
				result = true;
				break;
			}
		}
	}
	catch(e) {}

	return result;
}

// 국제 출발지역 선택
function setIntDepArea(depAreaName, depCityName, arrAreaName, arrCityName, direct, bonus, defaultDepCity, defaultArrCity) {
	var depArea		= getSelectObject(depAreaName);
	var depCity		= getSelectObject(depCityName);
	var arrArea		= getSelectObject(arrAreaName);
	var arrCity		= getSelectObject(arrCityName);
	var areaList	= bonus ? intAreaType2	: intAreaType1;
	var blockList	= bonus	? intBlockCity2	: intBlockCity1;

	if (defaultDepCity == "") defaultDepCity = "ICN";
	if (defaultArrCity == "") defaultArrCity = "NRT";

	try {
		// 국제 출발지역은 한국으로 제한
		clearSelectItem(depArea);
		//depArea.length	= 0;
		//depArea.length	= 0;
		for (var i=0; i<areaList.length; i++) {
			if (!(bonus && !direct) && areaList[i].area != "KR1") continue;
			addSelectItem(depArea, areaList[i].area, (defineLang == "ko" ? areaList[i].korName : areaList[i].engName));
			//depArea.length	= depArea.length+1;
			//depArea[depArea.length-1].value	= areaList[i].area;
			//depArea[depArea.length-1].text	= defineLang == "ko" ? areaList[i].korName : areaList[i].engName;
		}

		setIntDepCity(depAreaName, depCityName, arrAreaName, arrCityName, direct, bonus, defaultDepCity, defaultArrCity);
	}
	catch(e) {}
}

// 국제 출발도시 선택
function setIntDepCity(depAreaName, depCityName, arrAreaName, arrCityName, direct, bonus, defaultDepCity, defaultArrCity) {
	var depArea		= getSelectObject(depAreaName);
	var depCity		= getSelectObject(depCityName);
	var arrArea		= getSelectObject(arrAreaName);
	var arrCity		= getSelectObject(arrCityName);
	var areaList	= bonus ? intAreaType2	: intAreaType1;
	var blockList	= bonus	? intBlockCity2	: intBlockCity1;
	var areaData	= getSelectAreaData(depArea, areaList);
	var tmpDirect	= (bonus && !direct) ? true : direct;

	try {
		// 국제 출발도시 체크
		clearSelectItem(depCity);
		//depCity.length	= 0;
		//depCity.length	= 0;
		for (var i=0; i<intCity.length; i++) {
			if (!getEnableAreaCity(areaData, intCity[i], tmpDirect)) continue;
			if (!getEnableIntBlockCity(intCity[i], blockList, "")) continue;
			addSelectItem(depCity, intCity[i].city, intCity[i].cityName);
			//depCity.length	= depCity.length+1;
			//depCity[depCity.length-1].value	= intCity[i].city;
			//depCity[depCity.length-1].text	= intCity[i].cityName;
		}

		// 기본 도시 선택
		if (defaultDepCity != "") {
			depCity.value = defaultDepCity;
			if (depCity.selectedIndex < 0) depCity.selectedIndex = 0;
		}

		setIntArrArea(depAreaName, depCityName, arrAreaName, arrCityName, direct, bonus, defaultArrCity);
	}
	catch(e) {}
}

// 국제 도착지역 선택
function setIntArrArea(depAreaName, depCityName, arrAreaName, arrCityName, direct, bonus, defaultArrCity) {
	var depArea		= getSelectObject(depAreaName);
	var depCity		= getSelectObject(depCityName);
	var arrArea		= getSelectObject(arrAreaName);
	var arrCity		= getSelectObject(arrCityName);
	var areaList	= bonus ? intAreaType2	: intAreaType1;
	var blockList	= bonus	? intBlockCity2	: intBlockCity1;

	try {
		// 국제 도착지역
		clearSelectItem(arrArea);
		//arrArea.length	= 0;
		//arrArea.length	= 0;
		for (var i=0; i<areaList.length; i++) {
			// 출발지역에 따른 기본 도착지역 체크
			if (depArea[depArea.selectedIndex].value == "KR1" && areaList[i].area == "KR1") continue;
			else if (depArea[depArea.selectedIndex].value != "KR1" && areaList[i].area != "KR1") continue;
			var blockData = getSelectBlockData(depCity[depCity.selectedIndex].value, blockList);
			// 국내 출발 지역인 경우
			if (depArea[depArea.selectedIndex].value == "KR1") {
				if (blockData == null || !getEnableIntBlockArea(areaList[i], blockData)) continue;
			}

			addSelectItem(arrArea, areaList[i].area, (defineLang == "ko" ? areaList[i].korName : areaList[i].engName));
			//arrArea.length	= arrArea.length+1;
			//arrArea[arrArea.length-1].value	= areaList[i].area;
			//arrArea[arrArea.length-1].text	= defineLang == "ko" ? areaList[i].korName : areaList[i].engName;
		}

		// 기본 지역
		if (defaultArrCity == null) defaultArrCity = "";
		if (defaultArrCity != "") {
			var data = null;
			for (var i=0; i<intCity.length; i++) {
				if (intCity[i].city != defaultArrCity) continue;
				data = intCity[i];
				break;
			}

			if (data != null) {
				for (var i=0; i<arrArea.length; i++) {
					if (arrArea[i].value == data.ctlval1 || arrArea[i].value == data.ctlval2) {
						arrArea.selectedIndex = i;
						break;
					}
				}
			}
		}

		setIntArrCity(depAreaName, depCityName, arrAreaName, arrCityName, direct, bonus, defaultArrCity);
	}
	catch(e) {}
}

// 국제 도착도시 선택
function setIntArrCity(depAreaName, depCityName, arrAreaName, arrCityName, direct, bonus, defaultArrCity) {
	var depArea		= getSelectObject(depAreaName);
	var depCity		= getSelectObject(depCityName);
	var arrArea		= getSelectObject(arrAreaName);
	var arrCity		= getSelectObject(arrCityName);
	var areaList	= bonus ? intAreaType2	: intAreaType1;
	var blockList	= bonus	? intBlockCity2	: intBlockCity1;
	var areaData	= getSelectAreaData(arrArea, areaList);
	var tmpDirect	= (bonus && !direct) ? true : direct;

	try {
		// 기존 도시 체크 여부
		if (defaultArrCity == null) defaultArrCity = "";
		if (defaultArrCity == "" && arrCity != null) {
			if (depCity[depCity.selectedIndex].value == "GMP" && arrCity[arrCity.selectedIndex].value == "NRT")			defaultArrCity = "HND";
			else if (depCity[depCity.selectedIndex].value == "GMP" && arrCity[arrCity.selectedIndex].value == "PVG")	defaultArrCity = "SHA";
			else if (depCity[depCity.selectedIndex].value == "ICN" && arrCity[arrCity.selectedIndex].value == "HND")	defaultArrCity = "NRT";
			else if (depCity[depCity.selectedIndex].value == "ICN" && arrCity[arrCity.selectedIndex].value == "SHA")	defaultArrCity = "PVG";
			else defaultArrCity = arrCity[arrCity.selectedIndex].value;
		}

		// 국제 도착도시 체크
		if (arrCity != null) {
			clearSelectItem(arrCity);
			//arrCity.length	= 0;
			//arrCity.length	= 0;
			for (var i=0; i<intCity.length; i++) {
				if (!getEnableAreaCity(areaData, intCity[i], tmpDirect)) continue;
				if (!getEnableIntBlockCity(intCity[i], blockList, depCity[depCity.selectedIndex].value)) continue;
				addSelectItem(arrCity, intCity[i].city, intCity[i].cityName);
				//arrCity.length	= arrCity.length+1;
				//arrCity[arrCity.length-1].value	= intCity[i].city;
				//arrCity[arrCity.length-1].text	= intCity[i].cityName;
			}

			// 기본 도시 선택
			if (defaultArrCity != "") {
				arrCity.value = defaultArrCity;
				if (arrCity.selectedIndex < 0) arrCity.selectedIndex = 0;
			}
		}
		else {
			var list	= new Array();
			var cnt		= 0;
			for (var i=0; i<intCity.length; i++) {
				if (!getEnableAreaCity(areaData, intCity[i], tmpDirect)) continue;
				if (!getEnableIntBlockCity(intCity[i], blockList, depCity[depCity.selectedIndex].value)) continue;
				list[cnt++] = intCity[i];
			}
			setCityList(list);
		}
	}
	catch(e) {}
}

function addSelectItem(obj, value, text) {
	try {
		obj.options[obj.options.length] = new Option(text, value);
		//obj.add(new Option(text, value));
	}
	catch(e) {}
}

function clearSelectItem(obj) {
	for (var i=obj.length-1; i>=0; i--) {
		obj.remove(i);
	}
}
