String.prototype.trim = function() {
	return this.replace(/^\s*(\b.*\b|)\s*$/,"$1");
}

function Length(str) {
	return (str.length+(escape(str)+"%u").match(/%u/g).length-1);
}

function addDay(strDate, addedDay) {
	var strDate8 = strDate.split('-');
	var inputDate = new Date(parseInt(strDate8[0],10),parseInt(strDate8[1],10)-1,parseInt(strDate8[2],10),6,0,0);	
	if (!inputDate) return "";
	var millis = 86400000 * addedDay;
	inputDate = new Date(inputDate.getTime() + millis);
	with (inputDate) {
		var month = inputDate.getMonth() + 1;
		if (month < 10) {
			month = '0' + month;
		}
		var day = inputDate.getDate();
		if (day < 10) {
			day = '0' + day;
		}
		return (inputDate.getFullYear() + '-' + month + '-' + day);
	}
}

function calDayGap(fromDate, toDate) {
	var fromDate8 = fromDate.split('-');
	var fDate = new Date(parseInt(fromDate8[0],10),parseInt(fromDate8[1],10)-1,parseInt(fromDate8[2],10),6,0,0);	
	if (!fDate) return "";

	var toDate8 = toDate.split('-');
	var tDate = new Date(parseInt(toDate8[0],10),parseInt(toDate8[1],10)-1,parseInt(toDate8[2],10),6,0,0);	
	if (!tDate) return "";

	return (tDate - fDate) / 86400000;
}

function getKeyEvent(event) {
	if (event.keyCode)
		return event.keyCode;
	if (event.which)
		return event.which;
	return 0;
}

function editKey(event,delimiters) {
	var key=getKeyEvent(event);
	if (key==8 || key==9) return true;
	var chr=String.fromCharCode(key);
	if (delimiters==null)
		delimiters='/\\d/';
	var exp=eval(delimiters);
	return chr.match(exp)!=null;
}

function checkEmail(obj) {
	var val = obj.value;
	var emailPat = /^(.+)@(.+)$/;
	var specialChars = "\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
	var validChars = "\[^\\s" + specialChars + "\]";
	var quotedUser = "(\"[^\"]*\")";
	var atom = validChars + '+';
	var word = "(" + atom + "|" + quotedUser + ")";
	var userPat = new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat = new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray = val.match(emailPat);

	if (val == "") {
		alert("E-Mail 주소를 입력하여 주십시오.");
		obj.focus();
		return false;
	}

	if (matchArray == null) {
		alert("E-mail 주소 형식에 문제가 있습니다.\n\n E-mail를 확인하여 주십시오.");
		obj.focus();
		return false;
	}

	var user   = matchArray[1];
	var domain = matchArray[2];

	if (user.match(userPat) == null) {
		alert("E-mail의 ID 부분 형식에 문제가 있습니다.\n\n E-mail를 확인하여 주십시오.");
		obj.focus();
		return false;
	}

	var domainArray = domain.match(domainPat);

	if (domainArray == null) {
		alert("E-mail 주소의 도메인명이 틀립니다.\n\n E-mail를 확인하여 주십시오. ");
		obj.focus();
		return false;
	}

	var atomPat = new RegExp(atom,"g")
	var domArr  = domain.match(atomPat)
	var len     = domArr.length

	if (domArr[domArr.length-1].length < 2 || domArr[domArr.length-1].length > 3) {
		alert("E-mail 주소의 도메인명이 틀립니다.\n\n E-mail를 확인하여 주십시오.");
		obj.focus();
		return false;
	}

	if (len < 2) {
		alert("E-mail 주소의 호스트명이 틀립니다.\n\n E-mail를 확인하여 주십시오.");
		obj.focus();
		return false;
	}

	return true;
}

function ChgLeftImg(xObj, xImg)
{
	xObj.src = xImg;
}

function IfMenuSel(xNum)
{
	var xObj = eval("document.all.leftBanM");
	for(var i= 2; i <= 4; i++)
	{
		eval("document.all.leftBanM" + i).src = '/images/left_now_M' + i + '.gif';
		
	}
	eval("document.all.leftBanM" + xNum).src = '/images/left_now_M' + xNum + '_on.gif';
}

function cpMenuSel(xNum, skinType)
{
	var xObj = eval("document.all.topMenu");
	for(var i= 1; i <= 5; i++)
	{
		eval("document.all.topMenu" + i).src = '/images/cp/'+skinType+'top_menu0' + i + '.gif';
		
	}
	eval("document.all.topMenu" + xNum).src = '/images/cp/'+skinType+'top_menu0' + xNum + '_over.gif';
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL + "?decorator=popup&confirm=true",winName,features);
}
function MM_openBrWindow_02(theURL,winName,features, param) { //v2.0
  window.open(theURL + "?decorator=popup&confirm=true"+param,winName,features);
}
function checkNum(obj) {
	var textword = /^[0-9]+$/;
	var objVal = obj.value;
	if (objVal != "") {
		if (!textword.test(objVal)) {
			return false;
		}
	}
	return true;
}

function checkEng(obj) {
	var textword = /^[A-Za-z]+$/;
	var objVal = obj.value;
	if (objVal != "") {
		if (!textword.test(objVal)) {
			return false;
		}
	}
	return true;
}

function checkEngNum(obj) {
	var textword = /^[A-Za-z0-9]+$/;
	var objVal = obj.value;
	if (objVal != "") {
		if (!textword.test(objVal)) {
			return false;
		}
	}
	return true;
}

function changePriceRange(currency, priceRangeSelect) {
	while(priceRangeSelect.options.length > 0) {
		priceRangeSelect.options.remove(0);
	}

	if(currency == "USD") {
		var option = document.createElement("OPTION");
		option.value = "*";
		option.text = "모두";
		priceRangeSelect.add(option);

		option = document.createElement("OPTION");
		option.value = "1";
		option.text = "50$ 미만";
		priceRangeSelect.add(option);

		option = document.createElement("OPTION");
		option.value = "2";
		option.text = "50~100$";
		priceRangeSelect.add(option);

		option = document.createElement("OPTION");
		option.value = "3";
		option.text = "100~150$";
		priceRangeSelect.add(option);

		option = document.createElement("OPTION");
		option.value = "4";
		option.text = "150~200$";
		priceRangeSelect.add(option);
		
		option = document.createElement("OPTION");
		option.value = "5";
		option.text = "200~300$";
		priceRangeSelect.add(option);

		option = document.createElement("OPTION");
		option.value = "6";
		option.text = "300$ 이상";
		priceRangeSelect.add(option);
	}		
	if(currency == "EUR") {
		var option = document.createElement("OPTION");
		option.value = "*";
		option.text = "모두";
		priceRangeSelect.add(option);

		option = document.createElement("OPTION");
		option.value = "1";
		option.text = "50€ 미만";
		priceRangeSelect.add(option);

		option = document.createElement("OPTION");
		option.value = "2";
		option.text = "50~100€";
		priceRangeSelect.add(option);

		option = document.createElement("OPTION");
		option.value = "3";
		option.text = "100~150€";
		priceRangeSelect.add(option);

		option = document.createElement("OPTION");
		option.value = "4";
		option.text = "150~200€";
		priceRangeSelect.add(option);
		
		option = document.createElement("OPTION");
		option.value = "5";
		option.text = "200~300€";
		priceRangeSelect.add(option);

		option = document.createElement("OPTION");
		option.value = "6";
		option.text = "300€ 이상";
		priceRangeSelect.add(option);
	}		
	if(currency == "JPY") {
		var option = document.createElement("OPTION");
		option.value = "*";
		option.text = "모두";
		priceRangeSelect.add(option);

		option = document.createElement("OPTION");
		option.value = "1";
		option.text = "10000￥ 미만";
		priceRangeSelect.add(option);

		option = document.createElement("OPTION");
		option.value = "2";
		option.text = "10000~15000￥";
		priceRangeSelect.add(option);

		option = document.createElement("OPTION");
		option.value = "3";
		option.text = "15000~20000￥";
		priceRangeSelect.add(option);

		option = document.createElement("OPTION");
		option.value = "4";
		option.text = "20000~25000￥";
		priceRangeSelect.add(option);

		option = document.createElement("OPTION");
		option.value = "5";
		option.text = "25000~30000￥";
		priceRangeSelect.add(option);
		
		option = document.createElement("OPTION");
		option.value = "6";
		option.text = "30000￥ 이상";
		priceRangeSelect.add(option);
	}		
}

function checkPaste(keyCode) {
	if(keyCode == 17) {
		alert("Ctrl 키는 사용할 수 없습니다.");
		return false;
	}
	
	return true;
}

function submitNewsLetterUserView() {
	var width = 420;
	var height = 300;
	winpos = "left="+((window.screen.width-width)/2)+",top="+(((window.screen.height-height)/2)-20);
	winstyle="width=" + width + ",height=" + height + ",status=yes,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=no,copyhistory=no," + winpos;
	var newspopupWindow = window.open("/user/newsLetterUserAddView.do?decorator=popup&confirm=true", "newspopupWindow", winstyle);
}

function alertMessage(msg){
	alert(msg);
	return;
}


function winOpen(url, name, width, height, top, left, scroll){
	window.open(url, name,"height="+height+",width="+width+", top="+top+" , left="+left+", menubar=no,directories=no,resizable=no,status=no,scrollbars="+scroll);
}


function HotelDetailViewPopup(itemId, itemCode) {
	if(itemId == "") {
		return;
	}
	mainForm.itemId.value = itemId;
	mainForm.itemCode.value = itemCode;
	
	mainForm.decorator.value = "popup";
	mainForm.confirm.value = "true";
	
	var width = 690;
	var height = 620;
	winpos = "left="+((window.screen.width-width)/2)+",top="+(((window.screen.height-height)/2)-20);
	winstyle="width=" + width + ",height=" + height + ",status=yes,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=no,copyhistory=no," + winpos;
	var dpopupWindow = window.open("", "dpopupWindow", winstyle);

	mainForm.action = "${ctxPath}/hotel/detailInfoView.do";
	mainForm.method = "POST";

	mainForm.target = dpopupWindow.name;
	dpopupWindow.opener = self;
	mainForm.submit();
	mainForm.focus();
	window.name = 'index';
}	
