/// ¿¡·¯¸Þ½ÃÁö Æ÷¸ä Á¤ÀÇ ///
var NO_BLANK = "{name+Àº´Â} ÇÊ¼öÇ×¸ñÀÔ´Ï´Ù";
var NOT_VALID = "{name+ÀÌ°¡} ¿Ã¹Ù¸£Áö ¾Ê½À´Ï´Ù";
//var TOO_LONG = "{name}ÀÇ ±æÀÌ°¡ ÃÊ°úµÇ¾ú½À´Ï´Ù (ÃÖ´ë {maxbyte}¹ÙÀÌÆ®)";


/// ½ºÆ®¸µ °´Ã¼¿¡ ¸Þ¼Òµå Ãß°¡ ///
String.prototype.trim = function(str) {
	str = this != window ? this : str;
	return str.replace(/^\s+/g,'').replace(/\s+$/g,'');
}

String.prototype.hasFinalConsonant = function(str) {
	str = this != window ? this : str;
	var strTemp = str.substr(str.length-1);
	return ((strTemp.charCodeAt(0)-16)%28!=0);
}

String.prototype.bytes = function(str) {
	str = this != window ? this : str;
	var len=0;
	for(j=0; j<str.length; j++) {
		var chr2 = str.charAt(j);
		len += (chr2.charCodeAt() > 127) ? 2 : 1;
	}
	return len;
}

function FormCheck(form) {

	for (i = 0; i < form.elements.length; i++ ) {
		var el = form.elements[i];
		if (el.tagName == "FIELDset") continue;
		if (el.tagName == "EMBED") continue;
		if (el.tagName == "OBJECT") continue;
		//alert(el.tagName + " :: " + el.name);
		el.value = el.value.trim();

		var minbyte = el.getAttribute("MINBYTE");
		var maxbyte = el.getAttribute("MAXBYTE");
		var option = el.getAttribute("OPTION");
		var match = el.getAttribute("MATCH");
		var glue = el.getAttribute('GLUE');

		if (el.getAttribute("REQUIRED") != null) {
			if (el.type.toLowerCase() == "radio" || el.type.toLowerCase() == "checkbox") {
				if(!chkRadio(this,el)) return doError(el,NO_BLANK);
			}
			if (el.value == null || el.value == "") {
				return doError(el,NO_BLANK);
			}
		}

		if (el.getAttribute("REQUIRED") != null) {
			if (el.value == null || el.value == "") {
				return doError(el,NO_BLANK);
			}
		}


		if (minbyte != null && el.value != "") {
			var len = 0;
			if (el.value.bytes() < parseInt(minbyte)) {
				return doError(el,"{name+Àº´Â} ÃÖ¼Ò "+minbyte+"¹ÙÀÌÆ® ÀÌ»ó ÀÔ·ÂÇØ¾ß ÇÕ´Ï´Ù.");
			}
		}

		if (maxbyte != null && el.value != "") {
			var len = 0;
			if (el.value.bytes() > parseInt(maxbyte)) {
				return doError(el,"{name}ÀÇ ±æÀÌ°¡ ÃÊ°úµÇ¾ú½À´Ï´Ù (ÃÖ´ë "+maxbyte+"¹ÙÀÌÆ®)");
			}
		}

		if (match && (el.value != form.elements[match].value)) return doError(el,"{name+ÀÌ°¡} ÀÏÄ¡ÇÏÁö ¾Ê½À´Ï´Ù");

		if (option != null && el.value != "") {
			if (el.getAttribute('SPAN') != null) {
				var _value = new Array();
				for (span=0; span<el.getAttribute('SPAN');span++ ) {
					_value[span] = form.elements[i+span].value;
				}
				var value = _value.join(glue == null ? '' : glue);
				if (!funcs[option](el,value)) return false;
			} else {
				if (!funcs[option](el)) return false;
			}
		}
	}
	return true;
}

function InputBgImg(imgurl) {
		for (var i = 0; i < document.forms.length; i++)  {
				for (var j = 0; j < document.forms[i].elements.length; j++)  {
						// ÇÊ¼ö ÀÔ·ÂÀÏ °æ¿ì´Â * ¹è°æÀÌ¹ÌÁö¸¦ ÁØ´Ù.
						if (document.forms[i].elements[j].getAttribute("required") != null)  {
								document.forms[i].elements[j].style.backgroundImage = "url("+imgurl+")";
								document.forms[i].elements[j].style.backgroundPosition = "top right";
								document.forms[i].elements[j].style.backgroundRepeat = "no-repeat";
						}
				}
		}
}

function josa(str,tail) {
	return (str.hasFinalConsonant()) ? tail.substring(0,1) : tail.substring(1,2);
}

function doError(el,type,action) {
	var pattern = /{([a-zA-Z0-9_]+)\+?([°¡-Èþ]{2})?}/;
	var name = (hname = el.getAttribute("HNAME")) ? hname : el.getAttribute("NAME");
	pattern.exec(type);
	var tail = (RegExp.$2) ? josa(eval(RegExp.$1),RegExp.$2) : "";
	alert(type.replace(pattern,eval(RegExp.$1) + tail));
	if (action == "sel") {
		el.select();
	} else if (action == "del")	{
		el.value = "";
	}
	el.focus();
	return false;
}

/// Æ¯¼ö ÆÐÅÏ °Ë»ç ÇÔ¼ö ¸ÅÇÎ ///
var funcs = new Array();
funcs['email'] = isValidEmail;
funcs['phone'] = isValidPhone;
funcs['userid'] = isValidUserid;
funcs['hangul'] = hasHangul;
funcs['number'] = isNumeric;
funcs['engonly'] = alphaOnly;
funcs['jumin'] = isValidJumin;
funcs['bizno'] = isValidBizNo;
//funcs['domain'] = isValidDomain;

/// ÆÐÅÏ °Ë»ç ÇÔ¼öµé ///
function isValidEmail(el,value) {
	var value = value ? value : el.value;
	var pattern = /^[_a-zA-Z0-9-\.]+@[\.a-zA-Z0-9-]+\.[a-zA-Z]+$/;
	return (pattern.test(value)) ? true : doError(el,NOT_VALID);
}

function isValidUserid(el) {
	var pattern = /^[a-zA-Z]{1}[a-zA-Z0-9_]{4,14}$/;
	return (pattern.test(el.value)) ? true : doError(el,"{name+Àº´Â} 4ÀÚÀÌ»ó 13ÀÚ ¹Ì¸¸ÀÌ¾î¾ß ÇÏ°í,\n ¿µ¹®,¼ýÀÚ, _ ¹®ÀÚ¸¸ »ç¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù");
}

function hasHangul(el) {
	var pattern = /[°¡-Èþ]/;
	return (pattern.test(el.value)) ? true : doError(el,"{name+Àº´Â} ¹Ýµå½Ã ÇÑ±ÛÀ» Æ÷ÇÔÇØ¾ß ÇÕ´Ï´Ù");
}

function alphaOnly(el) {
	var pattern = /^[a-zA-Z]+$/;
	return (pattern.test(el.value)) ? true : doError(el,NOT_VALID);
}

function isNumeric(el) {
	var pattern = /^[0-9]+$/;
	return (pattern.test(el.value)) ? true : doError(el,"{name+Àº´Â} ¹Ýµå½Ã ¼ýÀÚ·Î¸¸ ÀÔ·ÂÇØ¾ß ÇÕ´Ï´Ù");
}

function isValidJumin(el,value) {
	var pattern = /^([0-9]{6})-?([0-9]{7})$/;
	var num = value ? value : el.value;
	if (!pattern.test(num)) return doError(el,NOT_VALID);
	num = RegExp.$1 + RegExp.$2;

	var sum = 0;
	var last = num.charCodeAt(12) - 0x30;
	var bases = "234567892345";
	for (var i=0; i<12; i++) {
		if (isNaN(num.substring(i,i+1))) return doError(el,NOT_VALID);
		sum += (num.charCodeAt(i) - 0x30) * (bases.charCodeAt(i) - 0x30);
	}
	var mod = sum % 11;
	return ((11 - mod) % 10 == last) ? true : doError(el,NOT_VALID);
}

function isValidBizNo(el, value) {
	var sum = 0;
	var getlist =new Array(10);
	var chkvalue =new Array("1","3","7","1","3","7","1","3","5");
	for(var i=0; i<10; i++) { getlist[i] = el.value.substring(i, i+1); }
	for(var i=0; i<9; i++) { sum += getlist[i]*chkvalue[i]; }
	sum = sum + parseInt((getlist[8]*5)/10);
	sidliy = sum % 10;
	sidchk = 0;
	if(sidliy != 0) { sidchk = 10 - sidliy; }
	else { sidchk = 0; }
	return (sidchk != getlist[9]) ? doError(el,NOT_VALID) : true;
	/*
   var pattern = /([0-9]{3})-?([0-9]{2})-?([0-9]{5})/;
	var num = value ? value : el.value;
    if (!pattern.test(num)) return doError(el,NOT_VALID);
    num = RegExp.$1 + RegExp.$2 + RegExp.$3;
    var cVal = 0;
    for (var i=0; i<8; i++) {
        var cKeyNum = parseInt(((_tmp = i % 3) == 0) ? 1 : ( _tmp  == 1 ) ? 3 : 7);
        cVal += (parseFloat(num.substring(i,i+1)) * cKeyNum) % 10;
    }
    var li_temp = parseFloat(num.substring(i,i+1)) * 5 + '0';
    cVal += parseFloat(li_temp.substring(0,1)) + parseFloat(li_temp.substring(1,2));
    return (parseInt(num.substring(9,10)) == 10-(cVal % 10)%10) ? true : doError(el,NOT_VALID);
		*/
}

function isValidPhone(el,value) {
	var pattern = /^([0]{1}[0-9]{1,2})-?([1-9]{1}[0-9]{2,3})-?([0-9]{4})$/;
	var num = value ? value : el.value;
	if (pattern.exec(num)) {
		if(RegExp.$1 == "011" || RegExp.$1 == "016" || RegExp.$1 == "017" || RegExp.$1 == "018" || RegExp.$1 == "019") {
			if (!el.getAttribute('SPAN')) el.value = RegExp.$1 + "-" + RegExp.$2 + "-" + RegExp.$3;
		}
		return true;
	} else {
		return doError(el,NOT_VALID);
	}
}

function chkRadio(str){
	for (j=0;j<str.length;j++) {
		if (str[j].checked) return true
	}
	return false;
}

function mouseOver(f){ f.className='over_tr'; }
function mouseOut(f){ f.className='over_tr_02'; }
function mouseOver2(f){ f.className='over_tr2'; }
function mouseOut2(f){ f.className='over_tr2_02'; }

/***********
*      allblur     *
***********/

var myAnchors=document.all.tags("A");
function allBlur(){
	for (i=0;i<myAnchors.length;i++){
	myAnchors[i].onfocus=new Function("myAnchors["+i+"].blur()");
	}
}

function ScrollMenu(){
	var bNetscape4plus = (navigator.appName == "Netscape" && navigator.appVersion.substring(0,1) >= "4");
	var bExplorer4plus = (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.substring(0,1) >= "4");
	var menuFrom, menuTo, timerCheck, offset;
	var iMenu;
	if ( bNetscape4plus ) {
		iMenu	= document.getElementById("inteliMenu");
	}
	else if ( bExplorer4plus ) {
		iMenu	= inteliMenu;
	}
	menuFrom	= parseInt (iMenu.style.top, 10);
	menuTo		= document.body.scrollTop + 250;
	timerCheck = 500;
	if ( menuFrom != menuTo ) {
			offset = Math.ceil( Math.abs( menuTo - menuFrom ) / 10 );
			if ( menuTo < menuFrom )
				offset = -offset;
			iMenu.style.top = parseInt (iMenu.style.top, 10) + offset;
			timerCheck = 10;
	}
	setTimeout ("ScrollMenu()", timerCheck);
}

// Visualeditor ¿¡¼­ »ç¿ëÇÔ..
function set_tag_support(obj, prefix, postfix) {
	if( obj.style.display == "none" ) {
			var oRng = document.selection.createRange();
			if( oRng.text == "" )
					window.alert("\nº»¹®¿¡¼­ ÅÂ±×¸¦ Ãß°¡ÇÒ ¿µ¿ªÀ» ¼±ÅÃÇØ ÁÖ¼¼¿ä.\t\n\n(¸¶¿ì½º µå·¡±× ¶Ç´Â shift + ¹æÇâÅ°)");
			else
					oRng.pasteHTML(prefix + oRng.htmlText + postfix);
	}
	else
			window.alert("¼Ò½ºº¸±â »óÅÂ¿¡¼­´Â ÅÂ±×¸¦ ³ÖÀ» ¼ö ¾ø¾î¿ä >.<");
}

function layer_toggle(obj) {
	if (obj.style.display == 'none') obj.style.display = 'block';
	else if (obj.style.display == 'block') obj.style.display = 'none';
}

function open_set(val) {
	layer_toggle(document.getElementById(val));
}

function close_color_set(obj, col1) {
	layer_toggle(document.getElementById('color_set'));
	set_tag_support(obj, '<font color=' + col1 + '>', '</font>');
}

function close_mark_set(obj, col1, col2) {
	layer_toggle(document.getElementById('mark_set'));
	set_tag_support(obj, '<span style="color:'+col1+';background-color:'+col2+';padding:4 5 1 3">', '</span>');
}

// ¿©±â±îÁö Visualeditor ¿¡¼­ »ç¿ëÇÔ..

function tick() {
	var month,date,hours, minutes, seconds, ap;
	var intYear,intDate,intMon,intHours, intMinutes, intSeconds;
	var today;
	today = new Date();
	intYear = today.getYear();
	intDate = today.getDate();
	intMon = today.getMonth()+1;
	intHours = today.getHours();
	intMinutes = today.getMinutes();
	intSeconds = today.getSeconds();
	(intMon < 10) ? month = "0"+intMon : month = intMon;
	(intDate < 10) ? date = "0"+intDate  : date = intDate;
	if (intHours == 0) {
		 hours = "12:";
		 ap = "AM";
	} else if (intHours < 12) {
		 hours = intHours + ":";
		 ap = "AM";
	} else if (intHours == 12) {
		 hours = "12:";
			ap = "PM";
	} else {
		 intHours = intHours - 12;
		 hours = intHours + ":";
		 ap = "PM";
	}
	(intMinutes < 10) ? minutes = "0"+intMinutes+":" : minutes = intMinutes+":";
	(intSeconds < 10)  ? seconds = "0"+intSeconds : seconds = intSeconds;
	timeString = intYear + "-" + month +"-"+ date +" / "+hours+minutes+seconds+" "+ap;
	Clock.innerHTML = timeString;
	window.setTimeout("tick();", 1000);
}

function checkName(ele) {
	if(ele.value.length ==0 ) {
		alert("ÀÌ¸§À» ÀÔ·ÂÇÏ¼¼¿ä!");
		ele.focus();
		return false;
	} else if (ele.value.indexOf(" ") != -1) {
		alert("ÀÌ¸§¿¡ °ø¹éÀ» ÀÔ·ÂÇÒ¼ö ¾ø½À´Ï´Ù.");
		ele.focus();
		return false;
	}
	for (var i=0; i<ele.value.length; i++) {
		var ch = ele.value.charAt(i);
		if( (ch>="a" && "z">=ch) || ch=="-" || ch=="_" || (ch>="0" && "9">=ch) || (ch>="a" && "z">=ch) || (ch>="A" && "Z">=ch) || ch=="!" || ch=="@" || ch=="$" || ch=="%" || ch=="^" || ch=="&" || ch=="*" ) {
			alert("ÀÌ¸§¿¡´Â ¹®ÀÚ " +ch+ " ¸¦ »ç¿ëÇÒ ¼ö ¾ø½À´Ï´Ù");
			ele.focus();
			return false;
		}
	}
	return true;
}

function isNumerics(str) {
  var checkStr = str.value;
  var checkOK = "0123456789";
  var isnumeric = false;
  for (i = 0;  i < checkStr.length;  i++) {
     ch = checkStr.charAt(i);
     isnumeric = false;
     for (j = 0;  j < checkOK.length;  j++) {
       if (ch == checkOK.charAt(j)) {
           isnumeric = true;
       }
     }
     if ( isnumeric == false )
         return false;
  }
  return true;
}

// ¼ýÀÚ¸¸ ÀÔ·Â¹Þ±â-_-
//onkeyPress="if ((event.keyCode<48) || (event.keyCode>57)) event.returnValue=false;" style="ime-mode:disabled"

function checkall(formname,checkname,flag) {
	var frm=eval("document.forms."+formname)
	for(var i=0; i<frm.elements.length; i++) {
		if(frm.elements[i].name == checkname){
			frm.elements[i].checked = flag;
		}
	}
}

function frm_up_qty(frm){
	old_qty = parseInt(frm.stock.value);
	frm.stock.value = old_qty + 1;
	return;
}
function frm_down_qty(frm){
	old_qty = parseInt(frm.stock.value);
	if(old_qty > 1 ){
		if( old_qty > 0 ){
			frm.stock.value = old_qty - 1;
		}
	}
	return;
}

function host_chk()	{
	var frm = document.frm;
	if (frm.email_host.value!="") {
		frm.email2.value=frm.email_host.value;
		frm.email2.readOnly=true;
	} else {
		frm.email2.value="";
		frm.email2.readOnly=false;
		frm.email2.focus();
	}
}

// ¿ìÆí¹øÈ£ Ã£±âµîÀÇ ·¹ÀÌ¾î
var select_obj;
function MFDLayerView(name,status) {
	var obj=document.all[name];
	var _tmpx,_tmpy, marginx, marginy;
	_tmpx = event.clientX + parseInt(obj.offsetWidth);
	_tmpy = event.clientY + parseInt(obj.offsetHeight);
	_marginx = document.body.clientWidth - _tmpx;
	_marginy = document.body.clientHeight - _tmpy ;
	if(_marginx < 0)
		_tmpx = event.clientX + document.body.scrollLeft + _marginx ;
	else
		_tmpx = event.clientX + document.body.scrollLeft ;
	if(_marginy < 0)
		_tmpy = event.clientY + document.body.scrollTop + _marginy +20;
	else
		_tmpy = event.clientY + document.body.scrollTop ;
	document.all.iframe1.style.posLeft=_tmpx-0;
	document.all.iframe1.style.posTop=_tmpy-0;
	obj.style.posLeft=_tmpx-0;
	obj.style.posTop=_tmpy-0;
	if(status=='visible') {
		if(select_obj) {
			document.all.iframe1.style.visibility='hidden';
			select_obj.style.visibility='hidden';
			select_obj=null;
		}
		select_obj=obj;
	}else{
		select_obj=null;
	}
	document.all.iframe1.style.visibility=status;
	obj.style.visibility=status;
}

function print_MFDLayer(name,title,page,content,widthis,heightis,frmmode) {
	var printMain="";
	if(frmmode==1 && page!=""){
		printMain = "<tr><td><iframe src='"+page+"' width="+widthis+" height="+heightis+" frameborder=0 border=0 style='border:0;'></iframe></td></tr>";
	}else{
		printMain = "<tr><td>"+content+"</td></tr>";
	}
	var printHeader = "<iframe id=iframe1 style='width:"+(parseInt(widthis)+2)+"; height:"+(parseInt(heightis)+26)+"; border:0 solid #ff0000; left:10px; top:25px; position:absolute; visibility:hidden;' border=0 frameborder=0></iframe><div id='"+name+"' name='"+name+"' style='position:absolute; left:10px; top:25px; width:"+widthis+"; height:"+heightis+"; z-index:9999; visibility: hidden'><table border=0 cellpadding=0 cellspacing=0 align=top><tr><td class='t_bg_LeftMenu'><font style='font-size:12px;font-family:dotum;color:ffffff;font-weight:normal;'>"+title+"</font></td></tr><tr><td><table border='0' cellspacing='1' cellpadding='0' bgcolor='black' width=100% height=100%><tr><td valign=top bgcolor=white><table border=0 cellspacing=0 cellpadding=0 width=100% height=100% align=top>";
	var printFooter = "</table></td></tr></table></td><td width=5 rowspan=2>&nbsp;</td></tr><tr><td colspan=3 height=10></td></tr></table></div>";

	document.writeln(printHeader+printMain+printFooter);
}
function MFDLayerHide(name){
	document.all[name].style.visibility='hidden';
}
function reSizeFrame(fname,fwidth,fheight){
  var ifrm = document.getElementById(fname);
  ifrm.style.height = fwidth+5;
  ifrm.style.height = fheight+5;
 }

function openModal(obj, file_name, width, height) {
	height=height+20;
	var rand = Math.random() * 4;
	window.showModalDialog(file_name + '?rand=' + rand, obj, 'dialogWidth=' + width + 'px;dialogHeight=' + height + 'px;resizable=0;status=0;scroll=0;help=0');
}


// Input Date //
function InputDate(formname,opt1,opt2) {
	today=new Date();
	now_year=today.getYear();
	now_month=today.getMonth()+1;
	now_day=today.getDate();

	(opt1=='d') ? opt_day=now_day-opt2 : opt_day=now_day;
	(opt1=='m') ? opt_month=now_month-opt2 : opt_month=now_month;
	(opt1=='y') ? opt_year=now_year-opt2 : opt_year=now_year;

	theDate =new Date(opt_year, opt_month-1, opt_day+1, 0,0,0);

	the_year=theDate.getYear();
	the_month=theDate.getMonth()+1;
	the_day=theDate.getDate();

	if(the_year < 1000) the_year = "19"+the_year;
	if(now_month<10) now_month='0'+now_month;
	if(now_day<10) now_day='0'+now_day;
	if(the_month<10) the_month='0'+the_month;
	if(the_day<10) the_day='0'+the_day;

	the_date=the_year+''+the_month+''+the_day;
	formname.sdate.value=the_date;
	now_date=now_year+''+now_month+''+now_day;
	formname.edate.value=now_date;
}

