//////////////////////////////////////////////////////////////////////////////////
/***** ÆË¾÷ ÄíÅ° ********/
function fnGetCookie(name) 
{ 
        var nameOfCookie = name + "="; 
        var x = 0; 
        while ( x <= document.cookie.length ) 
        { 
                var y = (x+nameOfCookie.length); 
                if ( document.cookie.substring( x, y ) == nameOfCookie ) { 
                        if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 ) 
                                endOfCookie = document.cookie.length; 
                        return unescape( document.cookie.substring( y, endOfCookie ) ); 
                } 
                x = document.cookie.indexOf( " ", x ) + 1; 
                if ( x == 0 ) 
                        break; 
        } 
        return ""; 
} 

//////////////////////////////////////////////////////////////////////////////////

var NUM = "0123456789";	
var SALPHA = "abcdefghijklmnopqrstuvwxyz";
var ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"+SALPHA;
var EMAIL = "@.-_"+NUM+ALPHA;
var PASSWORD = "!@.#,$%^*&_-" + ALPHA + NUM;
var COLR = "#abcdefABCDEF" + NUM;
var ERRORMSG = "";
var RejHTML = '<>"\'';
var REJWORDS = "|~`!@#$%^&*\?;,.'\"";
var DOMAIN = NUM+ALPHA+"/.-_";
var RejFileName = "\\:,*?\"<>|";

//////////////////////////////////////////////////////////////////////////////////

function util_posY(nh) {
	var bh	= document.body.clientHeight;
	var sh = document.body.scrollTop
	var pos	= (sh+bh)-nh;
	if (pos > sh+event.clientY) pos = sh+event.clientY;
	return pos;
}

//////////////////////////////////////////////////////////////////////////////////

function util_posX(nw) {
	var bw	= document.body.clientWidth;
	var pos	= bw-nw;
	if (pos>event.clientX) pos=event.clientX;
	return pos;
}

//////////////////////////////////////////////////////////////////////////////////

function util_centX(nw) {
	var nx = (screen.availWidth-nw)/2;
	return nx;
}

//////////////////////////////////////////////////////////////////////////////////

function util_centY(nh) {
	var ny = (screen.availHeight-nh)/2;
	return ny;
}

//////////////////////////////////////////////////////////////////////////////////

function util_keyCheck(e)
{
	var keyValue = e.keyCode;
	if ( ((keyValue >= 48) && (keyValue <= 57)) || keyValue == 8 || keyValue == 13)
		return true;
	else return false
}

//////////////////////////////////////////////////////////////////////////////////

function util_lenChar(s)
{
	if (!s) return 0;
	var len = 0;
	for(var i=0; i<s.length; i++){
		if(s.charCodeAt(i) > 255) len += 2;
		else len++;
	}
	return len;
}

//////////////////////////////////////////////////////////////////////////////////

function util_CheckType(s,spc)
{
	if(!s || s == '') return true;
	for(var i=0; i<s.length; i++) {
		if (spc.indexOf( s.substring(i, i+1)) < 0) return false;
	}

	return true;
}

//////////////////////////////////////////////////////////////////////////////////

function util_CheckRType(s,spc)
{
	if (!s || s == '') return true;
	for(var i=0; i<s.length; i++) {
		if (spc.indexOf( s.substring(i, i+1)) >= 0) { return false;}
	}
	return true;
}

//////////////////////////////////////////////////////////////////////////////////

function util_lrtrim(s)
{
	if (!s) return "";
	s=s.replace(/^\s*/,'');
	return s.replace(/\s*$/,'');
}

//////////////////////////////////////////////////////////////////////////////////

function util_strcut(words,sz)
{
	var len = 0;
	for (var i=0; i<words.length && len<sz; i++){
		len += (words.charCodeAt(i)>255)?2:1;
		len += (words.charCodeAt(i)>65 && words.charCodeAt(i)<=90)?0.5:0;
	}

	return (words.length-1>i)?words.substring(0,i)+'...':words;
}

//////////////////////////////////////////////////////////////////////////////////

function util_htmlEncode(str)
{
	str = str.replace(/</gi,"&lt;").replace(/>/gi,"&gt;");

	return str;
}

//////////////////////////////////////////////////////////////////////////////////

function util_radio(theForm,node)
{
	for(var i=0; i<theForm.elements.length; i++) {
		if (theForm.elements[i].name == node && theForm.elements[i].checked) {
			return theForm.elements[i].value;
		}
	}
	return false;
}

//////////////////////////////////////////////////////////////////////////////////



function util_checkstring(s, sWords, rWords, nMin, nMax, bIsConsonant)
{
	var nStrSize = util_lenChar(s);
	var cPostN, cPostL;

	if (bIsConsonant) {
		cPostL = "À»";
		cPostN = "Àº";
	} else {
		cPostL = "¸¦";
		cPostN = "´Â";
	}

	if(sWords.length > 0) {
		if(!util_CheckType(s, sWords)) {
			ERRORMSG = s + "¿¡ Àß¸øµÈ ¹®ÀÚ°¡ ÀÖ½À´Ï´Ù.\n\n»ç¿ë°¡´ÉÇÑ ±ÛÀÚ[" + sWords + "]";
			return false;
		}
	}
	if(s.length > 0 && rWords.length > 0) {
		if(!util_CheckRType(s, rWords)) {
			ERRORMSG = s + "¿¡ Àß¸øµÈ ¹®ÀÚ°¡ ÀÖ½À´Ï´Ù.\n\n»ç¿ëÇÒ ¼ö ¾ø´Â ±ÛÀÚ[" + rWords + "]";
			return false;
		}
	}
	if (nStrSize == 0 && nMin > 0) {
		ERRORMSG = cPostL + "  ÀÔ·ÂÇØ ÁÖ½Ê½Ã¿À.";
		return false;
	}
	if (nMin == 0 && nStrSize > nMax) {
		ERRORMSG = cPostN + " " + nMax +
			"ÀÚ ÀÌÇÏ·Î ÀÔ·ÂÇØ ÁÖ½Ê½Ã¿À.\n\nÇöÀç ÀÔ·ÂµÈ ±æÀÌ : " +
			nStrSize + "ÀÚ";
		return false;
	}
	if (nStrSize < nMin || nStrSize > nMax) {
		ERRORMSG = cPostN + " " + nMin +
			"ÀÚ ÀÌ»ó, " + nMax +
			"ÀÚ ÀÌÇÏ·Î ÀÔ·ÂÇØ ÁÖ½Ê½Ã¿À.\n\nÇöÀç ÀÔ·ÂµÈ ±æÀÌ : " +
			nStrSize + "ÀÚ";
		return false;
	}

	return true;
}

//////////////////////////////////////////////////////////////////////////////////

function util_checkemail(str)
{
	if (!util_checkstring(str, EMAIL, '',6, 50, 0)) return false;
	var a = str.indexOf('@');
	if (a <=0 || a == str.length - 1) {
		ERRORMSG = "´Â aaa@ccc.com µîÀÇ ÇüÅÂ·Î ÀÔ·ÂÇÏ¼Å¾ß ÇÕ´Ï´Ù.";
		return false;
	}
	return true;
}

//////////////////////////////////////////////////////////////////////////////////

function util_popup(nw,nh) {
	var opt,args = util_popup.arguments;
	opt = "width="+nw+",height="+nh+",scrollbars=auto,resizable=yes"+
		( (args.length>2)?",left="+args[2]:"")+
		( (args.length>3)?"top="+args[3]:"");
	return window.open("about:blank","",opt);
}

//////////////////////////////////////////////////////////////////////////////////

function util_formatnumber(n) {
	var str = String(n);
	var len = str.length;

	var share = Math.floor(len/3);
	var rest = len%3;
	if(rest==0) {rest=3;share--}
	var tmp = str.substr(0,rest);

	for(i=0;i<share;i++)
	tmp += ","+str.substr(3*i+rest,3)

	return tmp;
}

//////////////////////////////////////////////////////////////////////////////////

function util_checked_add(theForm,ele_name) {
	var ele,arg = "";
	for(var i=0; i<theForm.elements.length; i++) {
		ele = theForm.elements[i];
		if(ele.name == ele_name && ele.checked) arg+=(arg=="")?ele.value:"|"+ele.value;
	}
	return arg;
}

//////////////////////////////////////////////////////////////////////////////////

function image_view(mode,file_name){
	var popupLeftPosition = (window.top.screen.width-700)/2;
	var popupTopPosition = (window.top.screen.height-700)/2;
	window.open("/lib/asp/image_view.asp?mode="+mode+"&file_name="+file_name,"","left="+popupLeftPosition+",top="+popupTopPosition+",scrollbars=no,menubar=no,width=100,height=100,resizeable=yes");
}

function file_view(mode,file_name){
	var popupLeftPosition = (window.top.screen.width-700)/2;
	var popupTopPosition = (window.top.screen.height-700)/2;
	location.href= "/lib/asp/download.asp?tn="+mode+"&sFileName="+file_name;
	//window.open("/lib/asp/download.asp?tn="+mode+"&file_name="+file_name,"","left="+popupLeftPosition+",top="+popupTopPosition+",scrollbars=no,menubar=no,width=100,height=100,resizeable=yes");
}

//°ø¹é¹®ÀÚµµ ÀÎ½ÄÇØ¼­ ¹®ÀÚ±æÀÌ¸¦ ¾Ë¾Æ³»´Â ÇÔ¼ö
function CheckStr(strOriginal, strFind, strChange){
	var position, strOri_Length;
	position = strOriginal.indexOf(strFind);
	
	while(position !=-1){
		strOriginal = strOriginal.replace(strFind,strChange);
		position = strOriginal.indexOf(strFind);
	}
		
	strOri_Length = strOriginal.length;
	return strOri_Length;
}	

//¼ýÀÚ¸¸ ÀÔ·Â
function CheckNumber(){
	 if (!(event.keyCode>=48 && event.keyCode<=57 || event.keyCode>=96 && event.keyCode<=105 || event.keyCode==8 || event.keyCode==9 || event.keyCode==37 || event.keyCode==39 || event.keyCode==46  || event.keyCode==109 || event.keyCode==189)){ event.returnValue=false;}
}

function f_chk(obj,lbl)
{
	if(CheckStr(obj.value," ","") == 0)	{
		alert('Ç×¸ñ [' + lbl + ']À»(¸¦) ÀÔ·ÂÇÏ¼¼¿ä.');
		obj.focus(); 
		return true;   
	}
	return false; 
}

function view(what) { 
var imgwin = window.open("",'WIN','scrollbars=no,status=no,toolbar=no,resizable=no,location=no,menu=no,width=10,height=10'); 
imgwin.focus(); 
imgwin.document.open(); 
imgwin.document.write("<html>\n"); 
imgwin.document.write("<head>\n"); 
imgwin.document.write("<title>ÀÌ¹ÌÁö</title>\n"); //¿ÀÇÂÃ¢ Å¸ÀÌÆ² ÀÌ¸§ ÁöÁ¤ÇÏ´Â ºÎºÐ 

imgwin.document.write("<sc"+"ript>\n"); 
imgwin.document.write("function resize() {\n"); 
imgwin.document.write("pic = document.il;\n"); 
//imgwin.document.write("alert(eval(pic).height);\n"); 
imgwin.document.write("if (eval(pic).height) { var name = navigator.appName\n"); 
imgwin.document.write(" if (name == 'Microsoft Internet Explorer') { myHeight = eval(pic).height + 35; myWidth = eval(pic).width + 12;\n"); 
imgwin.document.write(" } else { myHeight = eval(pic).height + 19; myWidth = eval(pic).width + 9; }\n"); 
imgwin.document.write(" clearTimeout();\n"); 
imgwin.document.write(" var height = screen.height;\n"); 
imgwin.document.write(" var width = screen.width;\n"); 
imgwin.document.write(" var leftpos = width / 2 - myWidth / 2;\n"); 
imgwin.document.write(" var toppos = height / 2 - myHeight / 2; \n"); 
imgwin.document.write(" self.moveTo(leftpos, toppos);\n"); 
imgwin.document.write(" self.resizeTo(myWidth, myHeight);\n"); 
imgwin.document.write("}else setTimeOut(resize(), 100);}\n"); 
imgwin.document.write("</sc"+"ript>\n"); 

imgwin.document.write("</head>\n"); 
imgwin.document.write('<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0" bgcolor="#FFFFFF">\n'); 

imgwin.document.write("<img border=0 src="+what+" xwidth=100 xheight=9 name=il onload='resize();'>\n"); 
imgwin.document.write("</body>\n"); 
imgwin.document.close(); 
}

//ÇØ´ç ¿ÀÇÁÁ§Æ®¸¦ Ã£¾Æ¼­ ¹ÝÈ¯
function __MM_findObj__(n, d) {
	var p,i,x;
	if(!d) d = document;
	if((p=n.indexOf("?"))>0 && parent.frames.length){
		d=parent.frames[n.substring(p+1)].document;
		n=n.substring(0,p);
	}
	if(!(x=d[n]) && d.all){
		x=d.all[n];
	}
	for (i=0; !x && i<d.forms.length; i++){
		x=d.forms[i][n];
	}
	for(i=0; !x && d.layers && i<d.layers.length; i++){
		x=__MM_findObj__(n,d.layers[i].document);
	}
	if(!x && document.getElementById) x=document.getElementById(n); return x;
}

//ÀÏ¹Ý¼ýÀÚ¸¦ È¯À²ÇüÀ¸·Î Ä¡È¯ÇÑ´Ù.
function formatNumberJS(srcNumber) {
	var txtNumber = '' + srcNumber;
	var rxSplit = new RegExp('([0-9])([0-9][0-9][0-9][,.])');
	var arrNumber = txtNumber.split('.');
	arrNumber[0] += '.';
	do {
		arrNumber[0] = arrNumber[0].replace(rxSplit, '$1,$2');
	} while (rxSplit.test(arrNumber[0]));
	if (arrNumber.length > 1) {
		return arrNumber.join('');
	}
	else {
		return arrNumber[0].split('.')[0];
	}
}
//È¯À²ÇüÀ» ÀÏ¹Ý ¼ýÀÚ·Î¸¸ º¯°æ
function unFormatNumberJS(strNum){
  var itemNum ="";
  
  for (i=0; i < strNum.length; i++) {
  	str = strNum.substring(i,i+1);
  	
  	if (str != ",") {
  		itemNum += str;
  	}
  }
   return itemNum;
}

//¼ö·®º¯°æ½Ã º¯È¯ÇÊµå ¼öÁ¤
function ChangeIt(item){
	var theForm = document.form;
	var itemTempEA = parseInt(theForm.itemEA.value);
	var objNULLChk = __MM_findObj__("memberPrice");
	var chkNULL = objNULLChk.innerHTML;

	if(chkNULL != "-"){
		if(item == 1){
			theForm.itemEA.value = itemTempEA + 1;	
		}else if(item == 2){
			if(itemTempEA > 1){
			theForm.itemEA.value = itemTempEA - 1;
			}
		}
	summeryNumber();
	}

}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// calendar
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
function reserveCalendar(look, inputName, position) {

	var getObjDate = __MM_findObj__("getdate1");
  getObjDate.innerHTML = inputName;

  document.all['calendar'].style.top = position+'px';

  if (look == 'off') document.all['calendar'].style.visibility = 'hidden'
  else if (look == 'on') {
    setCalendar1();
    document.all['calendar'].style.visibility = 'visible';
  }
  //if (document.all['calendar'].style.visibility == 'hidden') document.all['calendar'].style.visibility = 'visible';
  //else if (document.all['calendar'].style.visibility == 'visible') document.all['calendar'].style.visibility = 'hidden';
}

function getDate(year, month, day, type) {
  var day_of_week   = new Array('ÀÏ','¿ù','È­','¼ö','¸ñ','±Ý','Åä');
  var month_of_year = new Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);

  if (year == undefined) var newdate = new Date();
  else var newdate = new Date(year, month-1, day);

  var year  = newdate.getFullYear();
  var month = newdate.getMonth();
  var day   = newdate.getDate();
  var wday  = newdate.getDay();

  if (type == 'small') str = year +'-'+ eval(month_of_year[month]) +'-'+ day;
  else str = year +'³â '+ eval(month_of_year[month]) +'¿ù '+ day +"ÀÏ "+ day_of_week[wday] +"¿äÀÏ";

  return str;
}





function reserveCalendar2(look, inputName, position) {

	var getObjDate = __MM_findObj__("getdate1");
  getObjDate.innerHTML = inputName;

  document.all['calendar'].style.top = position+'px';
  document.all['calendar'].style.left = '850px';

  if (look == 'off') document.all['calendar'].style.visibility = 'hidden'
  else if (look == 'on') {
    setCalendar1();
    document.all['calendar'].style.visibility = 'visible';
  }
  //if (document.all['calendar'].style.visibility == 'hidden') document.all['calendar'].style.visibility = 'visible';
  //else if (document.all['calendar'].style.visibility == 'visible') document.all['calendar'].style.visibility = 'hidden';
}

function getDate(year, month, day, type) {
  var day_of_week   = new Array('ÀÏ','¿ù','È­','¼ö','¸ñ','±Ý','Åä');
  var month_of_year = new Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);

  if (year == undefined) var newdate = new Date();
  else var newdate = new Date(year, month-1, day);

  var year  = newdate.getFullYear();
  var month = newdate.getMonth();
  var day   = newdate.getDate();
  var wday  = newdate.getDay();

  if (type == 'small') str = year +'-'+ eval(month_of_year[month]) +'-'+ day;
  else str = year +'³â '+ eval(month_of_year[month]) +'¿ù '+ day +"ÀÏ "+ day_of_week[wday] +"¿äÀÏ";

  return str;
}








function setCalendar1(year, month, day) {
  var day_of_week   = new Array('ÀÏ','¿ù','È­','¼ö','¸ñ','±Ý','Åä');
  var month_of_year = new Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);

  if (year == undefined) var newdate = new Date();
  else var newdate = new Date(year, month-1, day);

  var year    = newdate.getFullYear();
  var month = newdate.getMonth();
  var day     = newdate.getDate();
  var wday  = newdate.getDay();
  var nowday = new Date();

  var days_of_week  = 7;
  var days_of_month = 31;
  var cal;

  newdate.setDate(1);
  newdate.setMonth(month);

  var tr_start = '<TR ALIGN="CENTER">';
  var tr_end   = '</TR>';
  var select_start = '<TD STYLE="background-color: limegreen; color: white"><B>';
  var select_end   = '</B></TD>';
  var td_start = '<TD>';
  var td_end   = '</TD>';

  cal  = '<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="3" STYLE="width: 144px; background-color: white; border: 1px solid silver">' + tr_start;
  cal += '<TD COLSPAN="' + days_of_week + '" BGCOLOR="lightcyan" NOWRAP><CENTER>';
  cal += '<A HREF="javascript:setCalendar1('+ eval(year-1) +', '+ month_of_year[month] +', '+ day +')" STYLE="font-size: 9px">¢¸</A> ' + year + '³â ';
  cal += '<A HREF="javascript:setCalendar1('+ eval(year+1) +', '+ month_of_year[month] +', '+ day +')" STYLE="font-size: 9px">¢º</A> ';
  cal += '<A HREF="javascript:setCalendar1('+ year +', '+ eval(month_of_year[month]-1) +', '+ day +')" STYLE="font-size: 9px">¢¸</A> ' + month_of_year[month] + '¿ù ';
  cal += '<A HREF="javascript:setCalendar1('+ year +', '+ eval(month_of_year[month]+1) +', '+ day +')" STYLE="font-size: 9px">¢º</A> <A HREF="javascript:reserveCalendar(\'off\', \'\', 0);">[x]</A>' + td_end + tr_end;
  cal += tr_start;

  for(index = 0; index < days_of_week; index++)
  cal += td_start + day_of_week[index] + td_end;

  cal += td_end + tr_end;
  cal += tr_start;

  for(index = 0; index < newdate.getDay(); index++)
  {
    if (month > 0) tmpdate = new Date(year, month, index+1 - newdate.getDay());
    else tmpdate = new Date(year-1, 12, index+1 - newdate.getDay());

    cal += td_start +'<A HREF="javascript:getCalendar('+ tmpdate.getFullYear() +', '+ month_of_year[tmpdate.getMonth()] +', '+ tmpdate.getDate() +')" STYLE="color:silver">'+ tmpdate.getDate() +'</A>'+ td_end;
  }

  for(index = 0; index < days_of_month; index++)
  {
    if(newdate.getDate() > index)
    {
      week_day = newdate.getDay();
      if(week_day == 0) cal += tr_start;

      if(week_day != days_of_week)
      {
      var days = newdate.getDate();
        if(day == newdate.getDate())
          //cal += select_start + days + select_end;
          cal += select_start +'<A HREF="javascript:getCalendar('+ year +', '+ month_of_year[month] +', '+ days +')" STYLE="color:blue">'+ days +'</A>'+ select_end;
        else
        switch (week_day) {
          case 0 :
// 2005.2.6ÀÏ °ü·Ã Ã³¸®
//            cal += td_start +'<FONT STYLE="color:red">'+ days +'</FONT>'+ td_end;
            cal += td_start +'<A HREF="javascript:getCalendar('+ year +', '+ month_of_year[month] +', '+ days +')" STYLE="color:red">'+ days +'</A>'+ td_end;
			break;
          case 6 :
            //if (newdate.getDate() < eval(nowday.getDate())+2) cal += td_start +'<FONT STYLE="color:blue">'+ days +'</FONT>'+ td_end;
            //else
            cal += td_start +'<A HREF="javascript:getCalendar('+ year +', '+ month_of_year[month] +', '+ days +')" STYLE="color:blue">'+ days +'</A>'+ td_end;
            break;
          default :
            //if (newdate.getDate() < eval(nowday.getDate())+2) cal += td_start +'<FONT STYLE="color:gray">'+ days +'</FONT>'+ td_end;
            //else
            cal += td_start +'<A HREF="javascript:getCalendar('+ year +', '+ month_of_year[month] +', '+ days +')">'+ days +'</A>'+ td_end;
        }
      }
      if(week_day == days_of_week)
        cal += tr_end;
    }
    newdate.setDate(newdate.getDate()+1);
  }

  for(index = 0; index < 6 - week_day; index++)
  {
    if (month < 11) tmpdate = new Date(year, month_of_year[month], index+1);
    else tmpdate = new Date(year+1, 0, index+1);

    cal += td_start +'<A HREF="javascript:getCalendar('+ tmpdate.getFullYear() +', '+ month_of_year[tmpdate.getMonth()] +', '+ tmpdate.getDate() +')" STYLE="color:black">'+ tmpdate.getDate() +'</A>'+ td_end;
  }

  cal += '</TD></TR></TABLE>';

  calendar.innerHTML = cal;
//  return cal;
}

