



// Add Event
var _isIE = (document.all) ? true : false;

function addEvent(element, event, callback) {
	if (!element) return;
	if (_isIE)	element.attachEvent('on'+event, callback);
	else		element.addEventListener(event, callback, true);
}

function removeEvent(element, event, callback) {
	if (!element) return;
	if (_isIE)	element.detachEvent('on'+event, callback);
	else		element.removeEventListener(event, callback, true);
}

function eventCancel(e) {
	if (_isIE && !e)
		e=window.event;
	if (e.preventDefault)
		e.preventDefault();
	else
		e.returnValue= false;
	return false;
}


function notLogin() {
	alert("·Î±×ÀÎ ÈÄ ÀÌ¿ëÇÏ¼¼¿ä");
}



/* roll over-out image */
function menuOver() {this.src = this.src.replace(".gif", "_on.gif");}
function menuOut()  {this.src = this.src.replace("_on.gif", ".gif");}

function initImgEffect(ImgEls,SelImg) {
	if (SelImg && SelImg > 0) SelImg = SelImg -1;
	else return;

	MenuImg = document.getElementById(ImgEls).getElementsByTagName("img");
	MenuImgLen = MenuImg.length;
	for (i=0; i<MenuImgLen; i++) {
		MenuImg[i].onmouseover = menuOver;
		MenuImg[i].onmouseout = menuOut;
		if (i == SelImg) {
			MenuImg[i].onmouseover();
			MenuImg[i].onmouseover = null;
			MenuImg[i].onmouseout = null;
		}
	}
}



// Flash Embed ½ºÅ©¸³Æ® -- »ç¿ë¿¹ : <script>swf("/images/flash/a.swf", 100, 50)</script>
function swf(src, w, h) {
	var src_arr = src.split("/");
	var src_file = src_arr[src_arr.length -1]
	var src_id = src_file.substr(0,src_file.length-4);
	//alert(src_id);

	html = '';
	html += '<object type="application/x-shockwave-flash" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="'+src_id+'" width="'+w+'" height="'+h+'">';
	html += '<param name="movie" value="'+src+'">';
	html += '<param name="quality" value="high">';
	html += '<param name="bgcolor" value="#ffffff">';
	html += '<param name="swliveconnect" value="true">';	
	html += '<embed src="'+src+'" quality=high bgcolor="#ffffff" width="'+w+'" height="'+h+'" swliveconnect="true" id="'+src_id+'" name="'+src_id+'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"><\/embed>';
	html += '<\/object>';
	document.write(html);
}


// Flash Embed ½ºÅ©¸³Æ® -- »ç¿ë¿¹ : <script>swf_tran("/images/flash/a.swf", 100, 50)</script>  -- Å¾¸Þ´º 
function swf_tran(src, w, h, v) {
	var src_arr = src.split("/");
	var src_file = src_arr[src_arr.length -1]
	var src_id = src_file.substr(0,src_file.length-4);
	//alert(src_id);

	html = '';
	html += '<object type="application/x-shockwave-flash" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="'+src_id+'" width="'+w+'" height="'+h+'">';
	html += '<param name="movie" value="'+src+'">';
	html += '<param name="quality" value="high">';
	html += '<param name="bgcolor" value="#ffffff">';
	html += '<param name="wmode" value="transparent">';

	if (v != "") {
		html += '<param name="FlashVars" value="'+v+'">';
	}

	html += '<param name="swliveconnect" value="true">';
	html += '<embed src="'+src+'" quality=high bgcolor="#ffffff" width="'+w+'" height="'+h+'" swliveconnect="true" id="'+src_id+'" name="'+src_id+'" wmode="transparent"  type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"><\/embed>';
	html += '<\/object>';
	document.write(html);
}




// ÆÄÀÏ Ã·ºÎ½Ã ÆÄÀÏÃ·ºÎ µÆ´ÂÁö Ã¼Å©
function att_field_isNotnull() {
	var rtn = true;
	var iframe_att = document.getElementById("attach_iframe");
	if (iframe_att) {
		fDoc = iframe_att.contentWindow || iframe_att.contentDocument;
		if (fDoc.document.getElementById("pfile") && fDoc.document.getElementById("pfile").value) {
			alert("¸ÕÀú Ã·ºÎÇÏ±â ¹öÆ°À» Å¬¸¯ÇÏ¿© ÆÄÀÏÃ·ºÎ¸¦ ¿Ï·áÇØ ÁÖ¼¼¿ä.");
			rtn = false;
		}
	}
	return rtn;
}

/*----- Form ÀÇ input type="text" ÀÎ element ÀÇ value¸¦ strip -------*/
function form_strip(f) {
	var elList = f.getElementsByTagName("input");
	for (i=0;i<elList.length;i++ ){
		if (elList[i].type.toLowerCase() == "text" || elList[i].type.toLowerCase() == "textarea"){
			elList[i].value = elList[i].value.strip();
		}
	}
}

/* -------------------------- ÇÊ¼ö ÀÔ·Â ÇÊµåÀÇ ÀÔ·Â°ª Ã¼Å© ÇÔ¼ö START ----------------------------------*/
/*
	field ID ¿Í ÇÊµåÀÌ¸§À» Àü´ÞÇÑ´Ù.
	checkbox´Â msg¿¡ ÀüÃ¼ °æ°í¹®±¸¸¦ Àü´ÞÇÑ´Ù.
	radio ¹öÆ°Àº null_chk_field°¡ ¾Æ´Ñ radio_chk_field ¸¦ ÀÌ¿ëÇÏ¿© Ã¼Å©ÇÑ´Ù.

	»ç¿ë¿¹ )
		function chk_f(f) {
			return (
					null_chk_field ("a_id"  , "Admin ID")
				&&  null_chk_field ("a_pass", "Password")
				&&  null_chk_field ("sel", "¼¿·ºÆ®¹Ú½º")
				&&  radio_chk_field (f.radio_fld_name, "¶óµð¿À¹öÆ°.")
				&&  null_chk_field ("chk", "Ã¼Å©¹Ú½º¸¦ Ã¼Å©ÇÏ¼¼¿ä")
			);
		}
*/

// filed  null check (field : filed ID, msg : ¹ÌÀÔ·Â½Ã message)
function null_chk_field(field, msg) {

	// input type¿¡µû¶ó 
	if ($(field))
	{
		switch ($(field).type.toLowerCase()) {
			case 'select-one': // 1°³¸¸ ¼±ÅÃ°¡´ÉÇÑ Select box 
				if($F(field) == '' || $F(field) == '¼±ÅÃ' || $F(field) == null) {
					alert (msg+" : ÇÊ¼öÀÔ·Â »çÇ×ÀÔ´Ï´Ù.");
					$(field).activate();
					return false;
				}
				break;


			case 'checkbox': // Checkbox, msg¿¡¼­ °æ°í¹®±¸ ÀüÃ¼¸¦ ¹Þ´Â´Ù.
				if(!$(field).checked) {
					alert (msg);
					$(field).activate();
					return false;
				}
				break;


			default :	// text, textarea ÇÊµå
				if($F(field) == '' || $F(field) == null) {
					alert (msg+" : ÇÊ¼öÀÔ·Â »çÇ×ÀÔ´Ï´Ù.");
					//$(field).activate();
					if (field != 'content') $(field).activate(); // editor¿¡¼­ field¸íÀÌ contentÀÏ°æ¿ì¸¦À§ÇØ content´Â Á¦¿Ü,,
					return false;
				}

				if ($(field).getAttribute("check") && $(field).getAttribute("check").toLowerCase() != "") { // check Ç×¸ñÀÌ ÀÖÀ»°æ¿ì

					switch ($(field).getAttribute("check").toLowerCase()) {

						case "email" :	// ÀÌ¸ÞÀÏÃ¼Å©
							if (!chk_mail($F(field))) {
								alert ("¿Ã¹Ù¸¥ ¸ÞÀÏÁÖ¼Ò°¡ ¾Æ´Õ´Ï´Ù.");
								$(field).activate();
								return false;
							}
							break;

						
						case "number" : // ¼ýÀÚ¸¸ ÀÔ·Â.
							if (!chk_num1($F(field))) {
								alert (msg+" : ¼ýÀÚ¸¸ ÀÔ·Â °¡´ÉÇÕ´Ï´Ù..");
								$(field).activate();
								return false;
							}
							break;

						case "chk_engnum" : // ¿µ¹®, ¼ýÀÚ, ¾ð´õ¹Ù(_)
							if (!chk_hangul2($F(field))) {
								alert (msg+" : ¿µ¹®, ¼ýÀÚ, ¾ð´õ¹Ù(_)¸¸ ÀÔ·Â °¡´ÉÇÕ´Ï´Ù..");
								$(field).activate();
								return false;
							}
							break;

						case "min_len" :	// ÃÖ¼Ò ¸î±ÛÀÚ ÀÌ»ó?
							if ($(field).getAttribute("min_len")) {
								if ($F(field).length < Number($(field).getAttribute("min_len"))) {
									alert (msg+" : "+$(field).getAttribute("min_len")+" ±ÛÀÚ ÀÌ»óÀ¸·Î ÀÔ·ÂÇÏ¼¼¿ä.");
									$(field).activate();
									return false;
								}
							}
							break;

						
						// case Ãß°¡,,,,,,,,,,,,,,,,,,,,,,,,,,,,
					}
				}
		}
	}

	return true;
}

// radio null check (field : filed name, msg : ¹ÌÀÔ·Â½Ã message)
function radio_chk_field(field, msg) {

	var TF = false;

	for(i=0; i<field.length; i++) {
		
		if (field[i].checked) {
			TF = true;
			break;
		}
	}
	
	if(!TF) alert (msg+" : ¼±ÅÃÇÑ °ªÀÌ ¾ø½À´Ï´Ù.");
	return TF;
}
/* -------------------------- ÇÊ¼ö ÀÔ·Â ÇÊµåÀÇ ÀÔ·Â°ª Ã¼Å© ÇÔ¼ö END ---------------------------------- */




 
// number_format()
function number_format(num) {
	var num_str = num.toString()
	var result = ''

	for(var i=0; i<num_str.length; i++) {
		var tmp = num_str.length-(i+1)
		if(i%3==0 && i!=0) result = ',' + result
		result = num_str.charAt(tmp) + result
	}

	return result
}
 

// °ø¹é check(space Ã³¸®)
// null => true
function chk_null(toCheck) 
{
    for (var i = 0; i < toCheck.length; i++)
        if (toCheck.substring(i, i+1) != " ") return false;
        
    return true;
}

// °ø¹é check (°ªÀÌ ¾øÀ»°æ¿ì true)
// null => true
function chk_null2(toCheck)
{
    var chkstr = toCheck + "";
        
    if ((chkstr == "") || (chkstr == null)) 
    {
        return true;
    }

    return false;
}

// ¼ýÀÚ¸¸ ÀÔ·Â¹ÞÀ½
function NumObj(obj) {

	if (event.keyCode >= 48 && event.keyCode <= 57) { //¼ýÀÚÅ°¸¸ ÀÔ·Â
		return true;
	} else {
	event.returnValue = false;
	}
}

// ¼ýÀÚ check
function chk_num1(toCheck) 
{
   for (j = 0; j < toCheck.length ; j++)
   {
      if ( (toCheck.substring(j,j+1) < "0") || (toCheck.substring(j,j+1) > "9") ) return false;
   }
   return true;
}


// ¼ýÀÚ, ".", "-" ¸¸ Á¸ÀçÇÏ¸é true
function chk_num2(toCheck) 
{
   for (j = 0; j < toCheck.length ; j++) 
   {
      if ( (toCheck.substring(j,j+1) < "0") || (toCheck.substring(j,j+1) > "9") ) 
      {
         if ( (toCheck.substring(j,j+1) == ".") || (toCheck.substring(j,j+1) == "-") ) continue;
         return false;
      }
   }
   
   return true;
}

// ¼ýÀÚ, "-" ¸¸ Á¸ÀçÇÏ¸é true

function chk_num3(toCheck) 
{
   for (j = 0; j < toCheck.length ; j++) 
   {
      if ( (toCheck.substring(j,j+1) < "0") || (toCheck.substring(j,j+1) > "9") ) 
      {
         if (toCheck.substring(j,j+1) == "-") continue;
         return false;
      }
   }
   
   return true;
}

// ÇÑ±Û check
function chk_hangul(toCheck) 
{
    var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890`!@#$%^&*()-=_+~[]\{}|,./<>?";
    
    for (i=0; i< toCheck.length; i++)
    {
        idcheck = toCheck.charAt(i);
        
        for ( j = 0 ;  j < str.length ; j++)
        {
        
            if (idcheck == str.charAt(j)) break;
                
            if (j+1 == str.length)
            {
                return false;
            }
        }
    }
    return true;
}

//¿µ¾î,¼ýÀÚ, _ ¸¸ °¡´É
function chk_hangul2(toCheck) 
{
    var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890_";
    
    for (i=0; i< toCheck.length; i++)
    {
        idcheck = toCheck.charAt(i);
        
        for ( j = 0 ;  j < str.length ; j++)
        {
        
            if (idcheck == str.charAt(j)) break;
                
            if (j+1 == str.length)
            {
                return false;
            }
        }
    }
    return true;
}

// ÇÑ±Û, ¿µ¹®¸¸ ÀÔ·Â°¡´É
function chk_hangul3(toCheck) 
{
    var str = "1234567890`!@#$%^&*()-=_+~[]\{}|,./<>?";
    
    for (i=0; i< toCheck.length; i++)
    {
        idcheck = toCheck.charAt(i);
        
        for ( j = 0 ;  j < str.length ; j++)
        {
            if (idcheck == str.charAt(j)){
				return false;
			}                
            if (j+1 == str.length) break;
        }
    }
    return true;
}


// Email check
function chk_mail(toCheck) 
{
    // @Ç¥½Ã È®ÀÎ
    if (toCheck.indexOf('@') == -1 ) 
    { 
        return false; 
    }

    // .Ç¥½Ã È®ÀÎ
    if (toCheck.indexOf('.') == -1 ) 
    { 
        return false; 
    }
    
    // ÇÑ±Û È®ÀÎ
    if ( chk_hangul(toCheck) == false ) 
    { 
        return false; 
    }
    
    return true;
}


// ÁÖ¹Î¹øÈ£ check
function chk_juminno(obj) 
{
	if (obj.length == 14) {
        var calStr1 = "2345670892345", biVal = 0, tmpCal, restCal;

        for (i=0; i <= 12; i++) {
                if (obj.substring(i,i+1) == "-") {
                        tmpCal = 1;
                }
                else {
                        biVal = biVal + (parseFloat(obj.substring(i,i+1)) * parseFloat(calStr1.substring(i,i+1)));
                }
        }

        restCal = 11 - (biVal % 11);

        if (restCal == 11) {
                restCal = 1;
        }

        if (restCal == 10) {
                restCal = 0;
        }
        if (restCal == parseFloat(obj.substring(13,14))) {
                return true;
        }
        else {
                return false;
        }
	}
	else {
		return false;
	}
}



// window ¶ç¿ì±â
function open_win(URL, name, width, height) 
{
    msgWindow=window.open(URL,name,'location=0,toolbar=no,width='+width+',height='+height+',directories=no,status=no,scrollbars=Yes,resizable=no,menubar=no,border=0');
    msgWindow.focus()
}

// window ¶ç¿ì±â, no scroll
function open_win1(URL, name, width, height) 
{
    msgWindow=window.open(URL,name,'location=0,toolbar=no,width='+width+',height='+height+',directories=no,status=no,scrollbars=No,resizable=no,menubar=no,border=0');
    msgWindow.focus()
}

// window ¶ç¿ì±â
function open_win_XY(URL, name, width, height) 
{
    msgWindow=window.open(URL,name,'location=0,toolbar=no,width='+width+',height='+height+',directories=no,status=no,scrollbars=Yes,resizable=Yes,menubar=no,border=0,screenX=0,screenY=0');
    msgWindow.focus()
}

// ±âº» ÆË¾÷Ã¢
function view_open(url,name,features) { 
    window.open(url,name,features);
}


