
//ajax금지어 변환(기본문자->특수문자)
function ReplaceINSERT(Str) {
	var Str = Str.replace(/&/gi,"‡");
	Str = Str.replace(/=/gi,"†");
	Str = Str.replace(/\+/gi,"↕");

	return Str;
}

//ajax금지어 변환(특수문자->기본문자)
function ReplaceVIEW(Str) {
	var Str = Str.replace(/‡lt;/gi,"<");
	Str = Str.replace(/‡gt;/gi,">");
	Str = Str.replace(/‡/gi,"&");
	Str = Str.replace(/†/gi,"=");
	Str = Str.replace(/↕/gi,"+");
	Str = Str.replace(/XXX/gi,"");

	return Str;
}

function fnalert(rs)
{
	alert(rs.responseText);
}


function fnNULL(rs)
{
	return;
}

//통화표시 콤마
function formatnumber(v1,v2){ //숫자와 콤마를 찍을자리수를 매개변수로 받음 
	var str=new Array(); //콤마스트링을 조합할 배열 
	v1=String(v1); //숫자를 스트링으로 변환 
	for(var i=1;i<=v1.length;i++){ //숫자의 길이만큼 반복 
		if(i%v2) str[v1.length-i]=v1.charAt(v1.length-i); //자리수가 아니면 숫자만삽입 
		else  str[v1.length-i]=','+v1.charAt(v1.length-i); //자리수 이면 콤마까지 삽입 
	} 
	return str.join('').replace(/^,/,''); //스트링을 조합하여 반환 
} 

//프레임 리사이즈
function sendSize() {
window.clipboardData.setData('Text', document.body.scrollWidth+"|"+document.body.scrollHeight);
}


// URL Decoding 하는 함수
function URLdecode(str,mode)                               
{
	if (str)
	{
		var decodeStr = decodeURI(str);
	
		if (mode=="space")
		{
			for(i=0; i<3000; i++)
			{
				decodeStr = decodeStr.replace("%20"," ");
			}
		}
		else if (mode=="at")
		{			
			for(i=0; i<3; i++)
			{
				decodeStr = decodeStr.replace("%40", "@");
			}
		}
		else if (mode=="slash")
		{			
			for(i=0; i<100; i++)
			{
				decodeStr = decodeStr.replace("%2F", "/");
			}
		}
		else 
		{
			for(i=0; i<3000; i++)
			{
				decodeStr = decodeStr.replace("%3A", ":");
				decodeStr = decodeStr.replace("%3F", "?");
				decodeStr = decodeStr.replace("%40", "@");
				decodeStr = decodeStr.replace("%23", "#");
				decodeStr = decodeStr.replace("%24", "$");
				decodeStr = decodeStr.replace("%26", "&");
				decodeStr = decodeStr.replace("%2C", ",");
				decodeStr = decodeStr.replace("%3D", "=");
				decodeStr = decodeStr.replace("%2F", "/");
				decodeStr = decodeStr.replace("%20"," ");
				decodeStr = decodeStr.replace("%3B",";");
				decodeStr = decodeStr.replace("%2B","+");
				decodeStr = decodeStr.replace("%24","$");
			}
		}
	}
	else
	{
			decodeStr="";
	}

   return decodeStr;
}

// URL Encoding 하는 함수
function URLencode(str)                                                  
{
   return encodeURIComponent(str);
}

function mouseOnTD(seq, bool)
{

	var oTD = eval("document.all.listID" + seq);
	var len = oTD.length;
	var borderStyle = "1 solid slategray";

	if (bool){
		for(var i =0; i < len ; i++){
			oTD[i].style.borderTop = borderStyle;
			oTD[i].style.borderBottom = borderStyle;
			oTD[i].style.cursor = "default";
		}

	//	oTD[0].style.borderLeft = borderStyle;
		oTD[0].style.backgroundColor = "#F5F9FE";
		oTD[len-1].style.borderRight = borderStyle;

	}else{

		for(var i =0; i < len; i++){
			oTD[i].style.border = "";
		}
		oTD[0].style.backgroundColor = "";
	}

}

function mouseOnTD2(seq, bool, listNm)
{
	var oTD = eval("document.all." + listNm + seq);
	var len = oTD.length;
	var borderStyle = "1 solid slategray";

	if (bool){
		for(var i =0; i < len ; i++){
			oTD[i].style.borderTop = borderStyle;
			oTD[i].style.borderBottom = borderStyle;
			oTD[i].style.cursor = "default";
			oTD[i].style.backgroundColor = "pink";
		}
		oTD[len-1].style.borderRight = borderStyle;
	}else{

		for(var i =0; i < len; i++){
			if (oTD[i].style.backgroundColor == "yellow")
			{
			alert(oTD[i].style.backgroundColor);
			}
			oTD[i].style.backgroundColor = "";
			oTD[i].style.border = "";
		}
	}
}

function mouseOnTR(seq, bool, listNm)
{
	var oTR = eval("document.all." + listNm + seq);
	if (bool){
		oTR.style.cursor = "default";
		oTR.style.backgroundColor = "pink";
	}else{
		if (oTR.style.backgroundColor != 'yellow')
			oTR.style.backgroundColor = "";
	}
}

function getHnC(sentance)
{
	var gH01 = sentance.split(":>");
	var gH02 = gH01[0].split("<:");
	var gC00 = sentance.split("<:"+gH02[1]+":>");

	var gHnC = new Array();
	if (gH02[1])
		gHnC["header"] = gH02[1].replace(/(^\s*)|(\s*$)/g, "");
	else
		gHnC["header"] = "&nbsp;";
	
	if (gC00[1])
		gHnC["content"] = gC00[1].replace(/(^\s*)|(\s*$)/g, "");
	else
		gHnC["content"] = "&nbsp;";

	return gHnC;
}

// 추가 하기
function SelectAdd(selTag, aText, aValue) {
    // OPTION Element 생성
    var opt		= document.createElement("OPTION");
    opt.text	= aText;
    opt.value	= aValue;
    // 생성한 Element를 콤보 박스에 추가
    selTag.add(opt);
}

// 삭제 하기
function SelectDel(selTag, aValue) {
    // 콤보 박스의 크기만큼 반복
    for(i = 0; i < selTag.length; i++) {        // 값이 같을 경우
        if (selTag.options[i].value == aValue)
            selTag.options[i] = null;			// 삭제
    }
}

// 전체 삭제 하기
function SelectDelAll(selTag) {
    // 콤보 박스에 내용이 있을 때만 실행
    if ( selTag.length > 0 ) {
        for (i =0 ; selTag.options.length ; i++)
        {
            var selCh = selTag.children(0);		// 맨 위에 있는 것 갖고 오기
            selTag.removeChild(selCh);
        }
    }
}

// 공백 제거
function fnTrim(chStr) {
	var nStrCheck; 
	nStrCheck = chStr.indexOf(" ");     
	while (nStrCheck != -1) 
	{ 
		chStr = chStr.replace(" ", ""); 
		nStrCheck  = chStr.indexOf(" "); 
	} 
	return chStr;
}

// 로그인
function fnLogin()
{
	var uid = document.getElementById("uid").value;
	var pass = document.getElementById("pass").value;
	var nexturl = document.getElementById("nexturl").value;

	if(uid=="")
	{
		alert("아이디를 입력해 주세요");
		document.getElementById("uid").focus();
		return;
	}

	if(pass=="")
	{
		alert("비밀번호를 입력해 주세요");
		document.getElementById("pass").focus();
		return;
	}
	if(pass.length<4)
	{
		alert("비밀번호는 4~12자로 입력해 주세요");
		document.getElementById("pass").focus();
		return;
	}

	var rUrl = '/member/memberAction.asp';
	var Parms  = '?mode=login';
		Parms += '&uid=' + uid;
		Parms += '&pass=' + pass;

	var res = dynamic.loadText(rUrl + Parms);

	if(res=="OK")
	{
		location.href="/index.html";
//		if(nexturl)
//		{
//			location.href=nexturl;
//		}else{
//			location.href="/index.html";
//		}
		return;
	}else{
		if(res=="OK")
		{
			if(nexturl)
			{
				location.href=nexturl;
			}else{
				location.href="/index.html";
			}
		}else if(res=="ID_error")
		{
			alert("등록되지 않은 아이디입니다.");
			document.getElementById("uid").value = "";
			document.getElementById("uid").focus();
			return;
		}else if(res=="PWD_error")
		{
			alert("비밀번호가 일치하지 않습니다.");
			document.getElementById("pass").value = "";
			document.getElementById("pass").focus();
			return;
		}else if(res=="NOAUTH")
		{
			alert("승인되지 않은 아이디입니다. 관리자에게 문의해 주세요");
			document.getElementById("pass").value = "";
			document.getElementById("pass").focus();
			return;
		}else if(res=="LEAVE")
		{
			alert("탈퇴된 아이디입니다. 관리자에게 문의해 주세요");
			document.getElementById("pass").value = "";
			document.getElementById("pass").focus();
			location.href = '/index.html';
			return;
		}else{
			alert(res);
			return;
		}
	}
}

// 비회원로그인
function fnLogin2()
{
	var e_mail = document.getElementById("e_mail").value;
	var hp = document.getElementById("hp").value;

	if(e_mail=="")
	{
		alert("이메일을 입력해 주세요");
		document.getElementById("email").focus();
		return;
	}

	if (e_mail.indexOf(".")<3) 
	{
		alert("이메일의 형식이 잘못되었습니다. 다시 입력해 주세요")
		document.getElementById("e_mail").value = "";
		document.getElementById("e_mail").focus();
		return;
	}

	if(hp=="")
	{
		alert("휴대폰번호를 입력해 주세요");
		document.getElementById("hp").focus();
		return;
	}

	var rUrl = '/member/memberAction.asp';
	var Parms  = '?mode=unmem_login';
		Parms += '&uid=' + e_mail;
		Parms += '&hp=' + hp;

	var res = dynamic.loadText(rUrl + Parms);

	if(res=="OK")
	{
		location.href="/mypage/reservation.html";
		return;
	}else{
		if(res=="NO")
		{
			alert("예약 내역이 존재하지 않습니다.");
			document.getElementById("e_mail").value = "";
			document.getElementById("e_mail").focus();
			return;
		}else{
			alert(res);
			return;
		}
	}

}

// B2B2C로그인
function fnB2B2CLogin()
{
	var e_mail = document.getElementById("e_mail").value;
	var hp = document.getElementById("hp").value;

	if(e_mail=="")
	{
		alert("이메일을 입력해 주세요");
		document.getElementById("email").focus();
		return;
	}

	if (e_mail.indexOf(".")<3) 
	{
		alert("이메일의 형식이 잘못되었습니다. 다시 입력해 주세요")
		document.getElementById("e_mail").value = "";
		document.getElementById("e_mail").focus();
		return;
	}

	if(hp=="")
	{
		alert("휴대폰번호를 입력해 주세요");
		document.getElementById("hp").focus();
		return;
	}

	var rUrl = '/member/memberAction.asp';
	var Parms  = '?mode=b2b2c_login';
		Parms += '&uid=' + e_mail;
		Parms += '&hp=' + hp;

	var res = dynamic.loadText(rUrl + Parms);

	if(res=="OK")
	{
		location.href="/agent/mypage/reservation.html";
		return;
	}else{
		if(res=="NO")
		{
			alert("예약 내역이 존재하지 않습니다.");
			document.getElementById("e_mail").value = "";
			document.getElementById("e_mail").focus();
			return;
		}else{
			alert(res);
			return;
		}
	}

}

// 로그아웃
function fnLogout()
{
	var rUrl = '/member/memberAction.asp';
	var Parms  = '?mode=logout';
	var res = dynamic.loadText(rUrl + Parms);

	if(res=="OK")
	{
		alert("로그아웃 되었습니다. 감사합니다.");
		location.href="/index.html";
	}else{
		alert("오류가 발생했습니다.");
	}

}

// B2B2C로그아웃
function fnB2B2CLogout()
{
	var rUrl = '/member/memberAction.asp';
	var Parms  = '?mode=logout';
	var res = dynamic.loadText(rUrl + Parms);

	if(res=="OK")
	{
		alert("로그아웃 되었습니다. 감사합니다.");
		location.href="/indexb2b2c.html";
	}else{
		alert("오류가 발생했습니다.");
	}

}

//요일구하기
function weekDay(dt)
{
	var weekNumber = dt.getDay();
	var weekName = "";
	switch (weekNumber)
	{
		case 1 : weekName = "월"; break;
		case 2 : weekName = "화"; break;
		case 3 : weekName = "수"; break;
		case 4 : weekName = "목"; break;
		case 5 : weekName = "금"; break;
		case 6 : weekName = "토"; break;
		default : weekName = "일"; break;
	}
	return weekName;
}

//숫자에 , 넣기
function CommaFormatted(amount)
{
	var delimiter = ",";
	var amount = parseInt(amount);
	if(isNaN(amount)) { return ''; }
	var minus = '';
	if(amount < 0) { minus = '-'; }
	amount = Math.abs(amount);
	var n = new String(amount);
	var a = [];
	while(n.length > 3)
	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
	return minus + n
}

//날짜 더하기
function addDay(yyyy, mm, dd, pDay) // 년, 월, 일, 계산할 일자 (년도는 반드시 4자리로 입력) - 일더하기
{
var oDate; // 리턴할 날짜 객체 선언

dd = dd*1 + pDay*1; // 날짜 계산

mm--; // 월은 0~11 이므로 하나 빼준다

oDate = new Date(yyyy, mm, dd) // 계산된 날짜 객체 생성 (객체에서 자동 계산)

return oDate;
}

// VB 함수
function dateAdd(interval, num, pDate){
	num = new Number(num);
	pDate = pDate.split('-');
	var dt = new Date(pDate[0], pDate[1] + 1, pDate[2]);
	switch(interval.toLowerCase()){
		case "yyyy": {// year
			dt.setFullYear(dt.getFullYear() + num);
			break;
		}
		case "q": {		// quarter
			dt.setMonth(dt.getMonth() + (num*3));
			break;
		}
		case "m": {		// month
			dt.setMonth(dt.getMonth() + num);
			break;
		}
		case "y":		// day of year
		case "d":		// day
			dt.setMonth(dt.getDate() + num);
			break;
		case "w": {		// weekday
			dt.setDate(dt.getDate() + num);
			break;
		}
		case "ww": {	// week of year
			dt.setDate(dt.getDate() + (num*7));
			break;
		}
		case "h": {		// hour
			dt.setHours(dt.getHours() + num);
			break;
		}
		case "n": {		// minute
			dt.setMinutes(dt.getMinutes() + num);
			break;
		}
		case "s": {		// second
			dt.setSeconds(dt.getSeconds() + num);
			break;
		}
		case "ms": {		// second
			dt.setMilliseconds(dt.getMilliseconds() + num);
			break;
		}
		default: {
			return "i'";
		}
	}
	return dt;
}

function dateDiff(interval, pDate1, pDate2){
	pDate1 = pDate1.split('-');
	var dt1 = new Date(pDate1[0], pDate1[1] + 1, pDate1[2]);
	pDate2 = pDate2.split('-');
	var dt2 = new Date(pDate2[0], pDate2[1] + 1, pDate2[2]);
	
	var iDiffMS = dt2.valueOf() - dt1.valueOf();
	var dtDiff = new Date(iDiffMS);

	var nYears  = dt2.getUTCFullYear() - dt1.getUTCFullYear();
	var nMonths = dt2.getUTCMonth() - dt1.getUTCMonth() + (nYears!=0 ? nYears*12 : 0);
	var nQuarters = parseInt(nMonths/3);
	
	var nMilliseconds = iDiffMS;
	var nSeconds = parseInt(iDiffMS/1000);
	var nMinutes = parseInt(nSeconds/60);
	var nHours = parseInt(nMinutes/60);
	var nDays  = parseInt(nHours/24);
	var nWeeks = parseInt(nDays/7);

	var iDiff = 0;		
	switch(interval.toLowerCase()){
		case "yyyy": return nYears;
		case "q": return nQuarters;
		case "m": return nMonths;
		case "y": 	
		case "d": return nDays;
		case "w": return nDays;
		case "ww":return nWeeks;
		case "h": return nHours;
		case "n": return nMinutes;
		case "s": return nSeconds;
		case "ms":return nMilliseconds;
		default: return "invalid interval: '" + interval + "'";
	}
}

// 날짜 차이 구하는 함수
function getDayInterval(time1,time2) {
    var date1 = toTimeObject(time1);
    var date2 = toTimeObject(time2);
    var day   = 1000 * 3600 * 24; //24시간

    return parseInt((date2 - date1) / day, 10);
}

//Time 스트링을 자바스크립트 Date 객체로 변환
function toTimeObject(time) { //parseTime(time)
    var year  = time.substr(0,4);
    var month = time.substr(4,2) - 1; // 1월=0,12월=11
    var day   = time.substr(6,2);
    var hour  = time.substr(8,2);
    var min   = time.substr(10,2);

    return new Date(year,month,day,hour,min);
}

//div tag를 select box 위에 보이게 하기
//iframe을 이용한다.
function DivSetVisible(popDiv, divIf, state)
{
	var DivRef = document.getElementById(popDiv);
	var IfrRef = document.getElementById(divIf);
	if(state)
	{
		DivRef.style.display = "block";
		IfrRef.style.width = DivRef.offsetWidth;
		IfrRef.style.height = DivRef.offsetHeight;
		IfrRef.style.top = DivRef.style.top;
		IfrRef.style.left = DivRef.style.left;
		IfrRef.style.zIndex = DivRef.style.zIndex - 1;
		IfrRef.style.display = "block";
	}
	else
	{
		DivRef.style.display = "none";
		IfrRef.style.display = "none";
	}
}

function onQty2()
{
	if(frmhtlsearch.rmType2.value=="")
	{
		frmhtlsearch.rmQty2.value = 0;
		frmhtlsearch.rmQty2.disabled=true;
	}else{
		frmhtlsearch.rmQty2.value = 1;
		frmhtlsearch.rmQty2.disabled=false;
	}
}
function onQty3()
{
	if(frmhtlsearch.rmType3.value=="")
	{
		frmhtlsearch.rmQty3.value = 0;
		frmhtlsearch.rmQty3.disabled=true;
	}else{
		frmhtlsearch.rmQty3.disabled=false;
	}
}

function pre_view(str)
{
	if (str == null || str == '') {
		if (lyrpre_view) {
			lyrpre_view.opened = false;
			lyrpre_view.style.visibility = "hidden";
			lyrpre_view.style.display = "none";

			clearTimeout(timeoutid);
		}
	}
	else {
		if (lyrpre_view && event && document) {
			lyrpre_view.innerText = str;			
			lyrpre_view.style.pixelTop = event.clientY + document.body.scrollTop;
			lyrpre_view.style.pixelLeft = event.clientX + document.body.scrollLeft + 10;

			lyrpre_view.opened = true;
			lyrpre_view.style.visibility = 'visible';
			lyrpre_view.style.display = 'block';

			timeoutid = setTimeout('pre_view(null)', 100000);
		}
	}
	return;
}

function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

// 셀렉트박스 내용삽입
function fSelOption(url,boxnm,parm) {		//selectbox에 값을 넣는 기능
	var res = dynamic.loadText(url + parm);
	var boxnm = eval(boxnm);
	boxnm.innerHTML = decodeURIComponent(res);
}
