//JavaScript °¡¼ÓÈ­(DOM Á¢±Ù), documentÀÇ ·¹ÆÛ·±½º¸¦ ÅëÇØ¼­ Á¢±Ù½Ã 5~10¹è ºü¸§
/*@cc_on _d=document; eval('var document=_d; var getEl=_d.getElementById;')@*/
// ============================ Cookie °ü·Ã ÇÔ¼ö =============================0
    function delCookie(name,value,expires,path,domain,secure) {
      document.cookie = name + "=" + escape (value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
    }

    function setCookie (name,value,expires,path,domain,secure) {
      document.cookie = name + "=" + escape (value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
    }

    function getCookieVal (offset) {
      var endstr = document.cookie.indexOf (";", offset);
      if (endstr == -1)
        endstr = document.cookie.length;
      return unescape(document.cookie.substring(offset, endstr));
    }

    function getCookie (name) {
        var arg = name + "=";
        var alen = arg.length;
        var clen = document.cookie.length;
        var i = 0;
        while (i < clen) {
            var j = i + alen;
            if (document.cookie.substring(i, j) == arg)
                return getCookieVal (j);
            i = document.cookie.indexOf(" ", i) + 1;
            if (i == 0) break;
        }
        return null;
    }


	function setCookieA(name,name2,value,expire,domain){
		var string=getCookie(name);
		if(string==null) string="";

		var newStr = "";
		var flag=string.indexOf(name2 + '=');
		if (flag == -1){
			newStr= string + "&" + name2 + "=" + escape(value);
		}else{
			var cookieArr = string.split("&");
			for(i=0;i<cookieArr.length;i++){
				if(i>0) newStr += "&";
				if(cookieArr[i].split("=")[0]==name2)
					newStr += name2 + "=" + escape(value);
				else{
					newStr += cookieArr[i].split("=")[0] + "=" + escape(cookieArr[i].split("=")[1]);
				}
			}
		}

		document.cookie = name + "=" + newStr  //ÄíÅ°ÀúÀå
			+ ((expire) ? ";expires=" + expire.toGMTString() : "")
			+ ((domain) ? "; domain=" + domain : "");
	}


    function getCookieA(uName,uName2){		//ÄíÅ°¿­ Áß¿¡ uName2ÀÇ °ªÀ» ±¸ÇÑ´Ù
    	var string = getCookie(uName);
    	if(string==null) string="";

		var cookieArr = string.split("&");
		for(i=0;i<cookieArr.length;i++){
			if(cookieArr[i].split("=")[0]==uName2)
				return unescape(cookieArr[i].split("=")[1]);
		}
		return "";
    }
// ============================ Cookie °ü·Ã ÇÔ¼ö =============================0


    // Hashtable
    function Hashtable(){
        this.i = 0;
        this.itemName  = new Array();
        this.itemValue = new Array();
        this.count = 0;

        this.add = function () {
    	    var txtName = arguments[0];
    	    var txtValue = arguments[1];
    	    this.itemName[this.count]  = txtName;
    	    this.itemValue[this.count] = txtValue;
    	    this.count++;
        };

        this.get = function () {
    	    var txtName = arguments[0];
    	    var i;
    	    for(i=0;i<this.count;i++){
    	        if(this.itemName[i]==txtName){
    	            return this.itemValue[i];
    	        }
    	    }
    	    return null;
        };

        this.clear = function () {
    	    this.itemName = new Array();
    	    this.itemValue = new Array();
    	    this.count = 0;
        };
    }




// ============================ ±âÅ¸ À¯Æ¿ ÇÔ¼ö =============================
    // 9. ÁÂÃø °ø¹é Á¦°Å ÇÔ¼ö
    function Ltrim(strValue){
        while (strValue.length>0){
    		if(strValue.charAt(0)==' '){
    			strValue=strValue.substring(1,strValue.length);
    		}
    		else
    			return strValue;
        }
    	return strValue;
    }


    // 10. ¿ìÃø °ø¹é Á¦°Å ÇÔ¼ö
    function Rtrim(strValue){
        while (strValue.length>0){
    		if(strValue.charAt(strValue.length-1)==' '){
    			strValue=strValue.substring(0,strValue.length-1);
    		}
    		else
    			return strValue;
    	}
    	return strValue;
    }


    // 11. ¾çÂÊ °ø¹é Á¦°Å ÇÔ¼ö
    function Trim(strValue){
       strValue = Ltrim(strValue);
       strValue = Rtrim(strValue);
       return strValue;
    }

	// ReplaceÇÔ¼ö
    function replace(str,otxt,rtxt){
    	if(otxt==rtxt) return str;
    	while(str.indexOf(otxt)>0){
    		str = str.replace(otxt,rtxt);
    	}
    	return str;
    }

	String.prototype.trim = function(){
		return this.replace(/(^\s*)|(\s*$)/gi, "");
    }
	String.prototype.replaceAll = function(str1, str2){
		var temp_str = "";

		if(this.trim() != "" && str1 != str2){
			temp_str = this.trim();
	        while (temp_str.indexOf(str1) > -1){
				temp_str = temp_str.replace(str1, str2);
			}
		}
		return temp_str;
    }


    // select boxÀÇ ¿É¼Çµé ¾ø¾Ö±â
    function DelOption(objname){
    	var obj = document.getElementById(objname);
    	while (obj.length>=1)
    		obj.options[0]=null;
    }

    // select box¿¡ option Ãß°¡
    function AddOption(objname,value,strtext){
    	var obj = document.getElementById(objname);
    	var optobj = new Option(strtext,value,true);
        obj.options[obj.length]=optobj;
    }

    // select boxÀÇ Æ¯Á¤ option ¼±ÅÃ
    function SetSelectOption(objname,selectvalue){
    	var obj = document.getElementById(objname);
    	var i;

    	for(i=0;i<obj.length;i++){
    		if(obj.options[i].value==selectvalue){
    			obj.options[i].selected = true;
    			return;
    		}
    	}
    }



    // ÆË¾÷Ã¢ ¶ç¿ì±â
    function popupWindow(Url,windowName,Width,Height,scroll){
       if((scroll==null) || (scroll=="")){
    	   scroll = "no";
       }
       var win = window.open(Url,windowName,"toolbar=no,location=no,directory=no,status=no,menubar=no,scrollbars="+ scroll +",resizable=no,top=50,left=50,width="+ Width +",height="+ Height);
       if(win!=null) win.focus();
    }

    // ÆË¾÷Ã¢ ¶ç¿ì±â(top, left Ãß°¡)
    function popupWindow2(Url,windowName,Top,Left,Width,Height,scroll){
       if((scroll==null) || (scroll=="")){
    	   scroll = "no";
       }
       var win = window.open(Url,windowName,"toolbar=no,location=no,directory=no,status=no,menubar=no,scrollbars="+ scroll +",resizable=no,top="+Top+",left="+Left+",width="+ Width +",height="+ Height);
       if(win!=null) win.focus();
    }


    // ¿øº»¹®ÀÚ¿­¿¡¼­ ÁöÁ¤ÇÑ ¹®ÀÚ¿­ÀÇ °¹¼ö
    function StringCount(sourceStr,findstr){
    	var result = 0;
    	var tmp = "";
    	tmp = sourceStr;
    	while(tmp.indexOf(findstr)>=0){
    		result++;
    		tmp = tmp.substring(tmp.indexOf(findstr)+1,tmp.length);
    	}
    	return result;
    }


	// Ã¢ ´Ý±â (IE7¿¡¼­µµ ÀÛµ¿)
	function thisClose(){
		top.window.opener = top;
		top.window.open('','_parent','');
		top.window.close();
	}



    // ¹ÙÀÌÆ® Æ÷ÇÔ ±æÀÌÃ¼Å©
    function chkLen(obj,maxlen){
        var str,msg;
        var len = 0;
        var temp;
        var count = 0;
    	var k;

        msg = obj.value;
        str = new String(msg);
        len = str.length;
        for (k=0 ; k<len ; k++){
            temp = str.charAt(k);
            if (escape(temp).length > 4){
                count += 2;
            }else if (temp == 'r' && str.charAt(k+1) == 'n') { // rnÀÏ °æ¿ì
                count += 2;
            }else if (temp != 'n') {
                count++;
            }
    		if(count>=maxlen){
    			alert(maxlen + "Byte±îÁö¸¸ ÀÔ·Â°¡´ÉÇÕ´Ï´Ù");
    			obj.value = str.substring(0,k);
    			return;
    		}
        }
    }

    // ¹ÙÀÌÆ® ¼ö
    function getByte(strtext){
        var str = new String(strtext);
        var len = str.length;
    	var k,temp,count=0;

    	for (k=0 ; k<len ; k++){
            temp = str.charAt(k);
            if (escape(temp).length > 4){
                count += 2;
            }else if (temp == 'r' && str.charAt(k+1) == 'n') { // rnÀÏ °æ¿ì
                count += 2;
            }else if (temp != 'n') {
                count++;
            }
    	}
    	return count;
    }


    function CheckEssential(formobj, obj){
        var i;
        var tmpcnt;

    	if((obj.type=="text") || (obj.type=="hidden") || (obj.type=="textarea") || (obj.type=="password")){
    		if(Trim(obj.value)=='')
    			return false;
    		else
    			return true;
    	}else if(obj.type=="select-one"){
    		if(obj.value=='')
    			return false;
    		else
    			return true;

        }else if(obj.type=="radio"){
            tmpcnt = getObjCnt(formobj, obj.name);
            if(tmpcnt==1){
                return obj.checked;
            }else if(tmpcnt>1){
                for(i=0;i<tmpcnt;i++){
                    if(eval("document." + formobj.name + "." + obj.name + "[" + i + "]").checked){
                        return true;
                    }
                }
                return false;
            }
            return true;
        }
    }

    function CheckMaxLen(obj,maxlen){
    	if(getByte(obj.value)>maxlen)
    		return false;
    	else
    		return true;
    }

    function CheckNumeric(obj){
    	obj.value = ClearComma(obj.value);
    	if(isNaN(obj.value))
    		return false;
    	else
    		return true;
    }

    function CheckValid(formobj,obj){
    	var tmpstr = '';
    	var r_objname = '';
    	var r_maxlen  = 0;
    	var r_essent  = false;
    	var r_numeric = false;

    	var txtvalid = obj.getAttribute("valid");
    	for(var i=0;i<txtvalid.split("|").length;i++){
    		tmpstr = txtvalid.split("|")[i];
    		if(tmpstr.substring(0,1)=="T"){        // ÀÔ·Â°ª ¸í
    			r_objname = tmpstr.split("=")[1];
    		}else if(tmpstr.substring(0,1)=="M"){  // ÃÖ´ë±æÀÌ
    			r_maxlen = tmpstr.split("=")[1];
    		}else if(tmpstr.substring(0,1)=="E"){  // ÇÊ¼öÇ×¸ñÀÓ
    			r_essent = true;
    		}else if(tmpstr.substring(0,1)=="N"){  // ¼ýÀÚ¸¸ ÀÔ·Â°¡´É
    			r_numeric = true;
    		}
    	}
    	if(r_essent){
    		if(!CheckEssential(formobj,obj)){
    			alert( '"' + r_objname + '" Àº(´Â) ÇÊ¼ö Ç×¸ñÀÔ´Ï´Ù ');
    			obj.focus();
    			return false;
    		}
    	}
    	if(parseInt(r_maxlen)>0){
    		if(!CheckMaxLen(obj,r_maxlen)){
    			alert('"' + r_objname + '" Àº(´Â) ÃÖ´ë '+ r_maxlen+' byte ±îÁö ÀÔ·Â°¡´ÉÇÕ´Ï´Ù.\n\nÇöÀç±æÀÌ: ' + getByte(obj.value) + ' byte');
    			obj.focus();
    			return false;
    		}
    	}
    	if(r_numeric){
    		if(!CheckNumeric(obj)){
    			alert('"' + r_objname + '" Àº(´Â) ¼ýÀÚ¸¸ ÀÔ·Â°¡´ÉÇÕ´Ï´Ù.');
    			obj.focus();
    			return false;
    		}
    	}
    	return true;
    }


    // ÀÔ·Â°ªµé Ã¼Å©ÈÄ¿¡ true,false ¸®ÅÏ
    function checkForm(frmobj){
    	with(frmobj){
    		for(var i=0; i<elements.length; i++) {
				var valid = elements[i].getAttribute("valid");
    			if(valid!=null){
    				var ret = CheckValid(frmobj,elements[i]);
    				if(ret==false) return ret;
    			}
    		}
			return true;
    	}
    }


    function ReplaceString(sTxt,sFindTxt1,sFindTxt2,sReplaceStr){
    	var iLoc1 = sTxt.indexOf(sFindTxt1);
    	if(iLoc1 < 0){
    		return sTxt;
    	}
    	var	sTmp1 = sTxt.substring( 0,iLoc1 + sFindTxt1.length);
    	var	sTmp2 = sTxt.substring(iLoc1+sFindTxt1.length );

    	var	iCnt = sTmp2.indexOf(sFindTxt2);
    	if(iCnt < 0 ){
    		return sTxt;
    	}

    	var	sTmp3 = sTmp2.substring(iCnt);
    	var	sTmp2 = sTmp2.substring(0,iCnt);
    	return sTmp1 + sReplaceStr + sTmp3;
    }

    function getStrBetween(sTxt,sStartTag,sEndTag){
      	var iLoc1 = sTxt.indexOf(sStartTag);
      	var iLoc2 = sTxt.indexOf(sEndTag);

        return sTxt.substring(iLoc1,iLoc2-iLoc1+1);

    }


    function flash(url, width, height){
		document.write("<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' width='"+ width +"' height='"+ height +"' align='middle'>");
		document.write("<param name='allowScriptAccess' value='always' />");
		document.write("<param name='movie' value='"+ url +"' />");
		document.write("<param name='quality' value='high' />");
		document.write("<param name='wmode' value='transparent' />");
		document.write("<param name='bgcolor' value='#ffffff' />");
		document.write("<embed src='"+ url +"' quality='high' wmode='transparent' bgcolor='#ffffff' width='"+ width +"' height='"+ height +"' name='' allowScriptAccess='always' align='middle' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />");
		document.write("</object>");
    }



	function displayLayer(id, pCtrlID, leftmargin, topmargin){
		this.fGetXY = function (aTag){
			var oTmp = aTag;
			var pt = new Point(0,0);
			do{
				pt.x += oTmp.offsetLeft;
				pt.y += oTmp.offsetTop;
				oTmp = oTmp.offsetParent;
			}while(oTmp.tagName!="BODY");
			return pt;
		}

		this.Point = function(iX, iY){
			this.x = iX;
			this.y = iY;
		}

		var layerPoint = this.fGetXY(document.getElementById(pCtrlID));
		with (document.getElementById(id).style) {
			left = layerPoint.x + leftmargin;
			top  = layerPoint.y + document.getElementById(pCtrlID).offsetHeight + topmargin;
			display = 'block';
		}
	}


//#############################################################
// ajax°ü·Ã ¸ðµâ
//#############################################################
    function createHttpRequest(){
        if(window.ActiveXObject){
            try{
                return new ActiveXObject("Msxml2.XMLHTTP");
            }catch(e){
                try{
                    return new ActiveXObject("Microsoft.XMLHTTP");
                }catch(e2){
                    return null;
                }
            }
        }else if(window.XMLHttpRequest){
            /*
            try{
                netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserRead');
            } catch (e){
                alert('Permission UniversalBrowserRead denied.');
            }
            */
            return new XMLHttpRequest();
        }else{
            return null;
        }
    }


	function getPageHtml(url){
		var xmlObj = createHttpRequest();
		if(!xmlObj) return "Your browser is not supported";

		xmlObj.open("GET", url, false);
		xmlObj.send(null);
		if(xmlObj.readyState == 4){
			if(xmlObj.status == 200){
				return xmlObj.responseText;
			}
		}else
			exit;
	}

	function getPage(url, targetDiv){
		var xmlObj = createHttpRequest();
		if(!xmlObj) return "Your browser is not supported";

		xmlObj.onreadystatechange = function(){
			if(xmlObj.readyState == 4) {
				if(xmlObj.status == 200) {
					document.getElementById(targetDiv).innerHTML = xmlObj.responseText;
				}
			}
		}
		xmlObj.open("GET", url);  // ºñµ¿±â¸ðµå
		xmlObj.send(null);
	}


	function getAjaxPage(url, targetDiv, callBackFuc){
		var myAjax = new Ajax.Updater(
			{success: targetDiv},
			url, {
				method: 'get',
				evalScripts: true,
				onComplete: callBackFuc
			}
		);
	}

	function getXMLDOM(httpObj) {
		var xmlDoc;
		if(window.ActiveXObject) {
			xmlDoc = httpObj.responseXML;
		} else {
			var parser = new DOMParser();
			xmlDoc = parser.parseFromString(httpObj.responseText, "text/xml");
		}
		return xmlDoc;
	}

	var xmlHttpObj = null;
	function loadXml(url, funcObj){
		xmlHttpObj = createHttpRequest();
		if(!xmlHttpObj) return "Your browser is not supported";

		xmlHttpObj.onreadystatechange = function(){
			if(xmlHttpObj.readyState == 4) {
				if(xmlHttpObj.status == 200) {
					eval(funcObj);
				}
			}
		}
		xmlHttpObj.open("GET", url);  // ºñµ¿±â¸ðµå
		xmlHttpObj.send(null);
	}

//#############################################################


	// the date format prototype
	Date.prototype.format = function(f){
		if (!this.valueOf())
			return ' ';

		var d = this;

		return f.replace(/(yyyy|mmmm|mmm|mm|dddd|ddd|dd|hh|nn|ss|a\/p)/gi,
			function($1){
				switch ($1.toLowerCase()){
					case 'yyyy': return d.getFullYear();
					case 'mm':   return ((d.getMonth() + 1)<10 ? '0'+ (d.getMonth() + 1) : (d.getMonth() + 1));
					case 'dd':   return (d.getDate()<10 ? '0'+ d.getDate() : d.getDate());
					case 'hh':   return ((h = d.getHours() % 12) ? h : 12);
					case 'nn':   return d.getMinutes();
					case 'ss':   return d.getSeconds();
				}
			}
		);
	}


	function printNow(formatstr){
		document.write((new Date()).format(formatstr));
	}


	function checkLogin(){
		if(getCookieA("member","id")==""){
			alert("·Î±×ÀÎÀ» ÇÏ¼Å¾ß ÇÕ´Ï´Ù");
			location = "http://www.koreadaily.com/member/login.asp?BackURL="+ escape(location.href);
			return false;
		}
		return true;
	}