function openPopup(url,name,width,height,scroll,xpos,ypos) {
	if (scroll == null) scroll = true;
	if (xpos == null) xpos = (screen.width - width) / 2;
	if (ypos == null) ypos = (screen.height - height) / 2;
	var opt = "toolbar=no,alwaysRaised=no,location=no,status=no,menubar=no,scrollbars="+(scroll?"yes":"no")+",width="+width+",height="+height+",resizable=yes,hotkey=no,dependent=no,screenX=0,screenY=0,top="+ypos+",left="+xpos;
	window.open(url,name,opt)
}


function gotoTop() {
    parent.document.body.scrollTop = 0;
    parent.document.documentElement.scrollTop = 0;
}

function showRangeCheck(name, show) {
	var i = 1;

	while (true) {
		var obj = document.getElementById(name + i);
		if (obj == null) break;
		obj.style.display = show ? "" : "none";
		i++;
	}
}

function setReadOnly(name, flag) {
	var i = 1;

	while (true) {
		var obj = document.getElementsByName(name + i);
		if (obj == null) break;
		if (obj[0] == null) break;

		obj[0].readOnly = flag;
		i++;
	}
}

function setDisabled(name, flag) {
	var i = 1;

	while (true) {
		var obj = document.getElementsByName(name + i);
		if (obj == null) break;
		if (obj[0] == null) break;

		obj[0].disabled = flag;
		i++;
	}
}

function setMaxLengthList(name, maxLengthList) {
	var list = maxLengthList.split(",");
	for (var i=1; i<=list.length; i++) {
		setMaxLength(name+i, list[i-1]);
	}
}

function setMaxLength(name, maxLength) {
	try {
		var obj = document.getElementsByName(name);
		obj[0].maxLength = maxLength;
	}
	catch(e) {}
}

function getCheckCount(name) {
	var result = 0;
	var obj = document.getElementsByName(name);

	for (var i=0; i<obj.length; i++) {
		if (obj[i].checked) result++;
	}

	return result;
}

function getRadioSelectObject(name) {
	var result = null;
	var obj = document.getElementsByName(name);

	for (var i=0; i<obj.length; i++) {
		if (obj[i].checked) {
			result = obj[i];
			break;
		}
	}

	return result;
}

function getRadioSelectList(name) {
	var result = "";
	var obj = document.getElementsByName(name);

	for (var i=0; i<obj.length; i++) {
		if (obj[i].checked) {
			if (result != "") result += ",";
			result += obj[i].value;
		}
	}

	return result;
}

function maxLengthMoveNext(varControl, varNext, varName) {
	if(getByte(varControl.value) == varControl.maxLength) {
		var obj = document.getElementsByName(varName);
		obj[parseInt(varNext)].focus();
		try {
			obj[parseInt(varNext)].select();
		}
		catch(e) {;}
	}
}

function checkDefaultValue(obj, value, flag) {
	if (flag && obj.value == value) {
		obj.value = "";
	}
	else if (!flag && obj.value == "") {
		obj.value = value;
	}
}

function setRadioDefaultValue(name, value) {
	try {
		var list = document.getElementsByName(name);
		for (var i=0; i<list.length; i++) {
			if (list[i].type.toUpperCase().indexOf("RADIO") < 0 && list[i].type.toUpperCase().indexOf("CHECKBOX") < 0) continue;
			if (list[i].value == value) {
				list[i].checked = true;
				break;
			}
		}
	}
	catch(e) {}
}

function setSelectDefaultValue(name, value) {
	try {
		var list = document.getElementsByName(name);
		for (var i=0; i<list.length; i++) {
			if (list[i].type.toUpperCase().indexOf("SELECT") < 0) continue;
			list[i].value = value;
			if (list[i].selectedIndex < 0) list[i].selectedIndex = 0;
			break;
		}
	}
	catch(e) {}
}

function disableNextButton() {
	var btn1	= document.getElementById("nextBtn");
	var btn2	= document.getElementById("nextBtn2");

	if (btn1 != null) btn1.style.display = "none";
	if (btn2 != null) btn2.style.display = "none";
}

function getSelectObject(name) {
	var result = null;

	try {
		var list = document.getElementsByName(name);
		for (var i=0; i<list.length; i++) {
			if (list[i].type.toUpperCase().indexOf("HIDDEN") > -1) continue;
			result = list[i];
			break;
		}
	}
	catch(e) {}

	return result;
}

function getCookie(name) {
	var result	= "";
	var list	= document.cookie == null ? new Array("") : document.cookie.split(";");

	for (var i=0; i<list.length; i++) {
		list[i] = trim(list[i]);
		if (list[i].indexOf(name+"=") == 0) {
			result = list[i].substring(name.length+1);
		}
	}

	if (result.indexOf("%") > -1) result = unescape(result);

	return result;
}

function setCookie(name, value, expire) {
	try {
		var expireDate = "";
		if (expire != null) {
			var today = new Date();
			today.setDate(today.getDate() + expire);
			expireDate = today.toGMTString();
		}

		var url = location.href.substring(location.href.indexOf("://") + 3);
		var domain = location.href.indexOf("flyasiana.com") > -1 ? ".flyasiana.com" : ".flyairbusan.com";
		if (url.indexOf(".airbusan.com") > -1 || url.indexOf("airbusan.com") == 0) domain = ".airbusan.com";

		document.cookie = name + "=" + escape(value) 
						+ "; path=/"
						+ "; domain="+domain
						+ (expireDate != "" ? ("; expires=" + expireDate) : "");
	}
	catch (e) {;}
}

function addSelectObjectItem(obj, value, text) {
	try {
		obj.add(new Option(text, value));
	}
	catch(e) {
		try {
			obj.options[obj.options.length] = new Option(text, value);
		}
		catch (e) {}
	}
}

function clearSelectObjectItem(obj) {
	for (var i=obj.length-1; i>=0; i--) {
		obj.remove(i);
	}
}

function checkDefaultValue(obj, value, flag) {
	if (flag && obj.value == value)				obj.value = "";
	else if (!flag && trim(obj.value) == "")	obj.value = value;
}

function setRadioSelectAll(name, value) {
	try {
		var list = document.getElementsByName(name);
		for (var i=0; i<list.length; i++) {
			if (list[i].type.toUpperCase().indexOf("CHECKBOX") < 0) continue;
			list[i].checked = value;
		}
	}
	catch(e) {}
}
