/**
 * @author ellen ellen@nhncorp.com
 * @version 1.0
 * @since 2008.4.10
 * @sdoc ./sdoc/da.sdoc
 */

/** @id Agent */
var Agent = function () {
    var a = navigator.userAgent;
    if (new RegExp(/Windows/).test(a)) {
        this.isWin = true;
    } else if (new RegExp(/Macintosh/).test(a)) {
        this.isMac = true;
    }
    if (new RegExp(/MSIE/).test(a)) {
        this.isIE = true;
        var m = new RegExp(/MSIE ([0-9\.]+)/).exec(a);
        var v = parseFloat(m[1]);
        if (6 <= v && v < 7) {
            this.isIE6 = true;
            return;
        } else if (7 <= v && v < 8) {
            this.isIE7 = true;
            return;
        } else if (5.5 <= v && v < 6) {
            this.isIE55 = true;
            return;
        } else if (v < 5.5) {
            this.isIE5 = true;
            return;
        } else if (8 <= v) {
            this.isIE8 = true;
            return;
        }
    } else if (new RegExp(/Firefox/).test(a)) {
        this.isFF = true;
        return;
    } else if (new RegExp(/Safari/).test(a)) {
        this.isSF = true;
        return;
    } else if (window.opera !== null) {
        this.isOP = true;
        return;
    } else if (new RegExp(/Konqueror/).test(a)) {
        this.isKQ = true;
        return;
    }
};

/** @id Flash */
var Flash = function (sSwfUrl, iWidth, iHeight, sWmode) {
    this.params = {};
    this.vals = {};
    this.atts = {};
    if (sSwfUrl) {
        this.setAtt("src", sSwfUrl);
        this.setParam("movie", sSwfUrl);
    }
    if (iWidth) {
        this.setAtt("width", iWidth);
    }
    if (iHeight) {
        this.setAtt("height", iHeight);
    }
    if (sWmode) {
        this.setParam("wmode", sWmode);
    }
    this.setAtt("classid", "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000");
    this.setAtt("type", "application/x-shockwave-flash");
    this.setAtt("codebase", "http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0");
    this.setParam("quality", "high");
    this.setParam("allowScriptAccess", "always");
    this.setParam("swliveconnect", "true");
};

Flash.prototype = {
    /** @id Flash.setAtt */
    setAtt : function (sName, vValue) {
        this.atts[sName] = vValue;
    },
    /** @id Flash.getAtt */
    getAtt : function (sName) {
        return this.atts[sName];
    },
    /** @id Flash.setVal */
    setVal : function (sName, vValue) {
        this.vals[sName] = vValue;
    },
    /** @id Flash.getVal */
    getVal : function (sName) {
        return this.vals[sName];
    },
    /** @id Flash.setValByArray */
    setValByArray : function (aName, aValue) {
        if (aName !== null && aValue !== null && aName.length === aValue.length)  {
            for (var i = 0, n = aName.length ; i < n ; i++){
                this.setVal(aName[i], aValue[i]);
            }
        }
    },
    /** @id Flash.setParam */
    setParam : function (sName, vValue) {
        this.params[sName] = vValue;
    },
    /** @id Flash.getParam */
    getParam : function (sName) {
        return this.params[sName];
    },
    /** @id Flash.getHTML */
    getHTML : function () {
        var a = [];
        var i;
        for (i in this.vals) {
            if (this.vals.hasOwnProperty(i)) {
                a.push(i + "=" + this.vals[i]);
            }
        }
        var v = a.join("&");
        if (v!==null && v.length > 0) {
            this.setParam("flashvars", v);
        }
        var s = "";
        var k;
        if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) {
            s = "<embed ";
            for (k in this.atts) {
                if (this.atts.hasOwnProperty(k)) {
                    s += k;
                    s += "=\"";
                    s += this.atts[k];
                    s += "\" ";
                }
            }
            for (k in this.params) {
                if (this.params.hasOwnProperty(k)) {
                    s += k;
                    s += "=\"";
                    s += this.params[k];
                    s += "\" ";
                }
            }
            s += "/>";
        } else {
            s = "<object ";
            for (k in this.atts) {
                if (this.atts.hasOwnProperty(k)) {
                    s += k;
                    s += "=\"";
                    s += this.atts[k];
                    s += "\" ";
                }
            }
            s += ">\n";
            for (k in this.params) {
                if (this.params.hasOwnProperty(k)) {
                    s += "<param name=\"";
                    s += k;
                    s += "\" value=\"";
                    s += this.params[k];
                    s += "\" />";
                }
            }
            s += "</object>";
        }
        return s;
    }
};


/** @id Da */
var Da = {
    /** @id Da.$ */
    $ : function (sIDValue) {
        return document.getElementById(sIDValue);
    },
    /** @id Da.$$ */
    $$ : function (sIDValue) {
        return parent.document.getElementById(sIDValue);
    },
    /** @id Da.SH */ 
    SH : function (oElement, sHTML) {
        oElement.innerHTML = sHTML;
    },
    /** @id Da.CE */
    CE : function (oElement, sTag, oAttributes, sStyle, sHTML) {
        var o = parent.document.createElement(sTag);
        var k;
        for (k in oAttributes) {
            if (oAttributes.hasOwnProperty(k)) {
                o.setAttribute(k, oAttributes[k]);
            }
        }
        if (sStyle!==null) {
            o.style.cssText = sStyle;
        }           
        oElement.appendChild(o);
        if (sHTML !== null) {
            o.innerHTML = sHTML;
        }       
    },      
    /** @id Da.CS */
    CS : function (sText) { 
        var o = parent.document.createElement("script");
        o.type = "text/javascript"; 
        o.defer = true;  
        o.text = sText;  
        o.charset = "euc-kr";
        parent.document.getElementsByTagName('head')[0].appendChild(o);
    },          
    /** @id Da.EF */
    EF : function (sText) {
        return sText.replace(/\&/g, "%26").replace(/\?/g, "%3F").replace(/\"/g, "%22");
    },  
    /** @id Da.RE */
    RE : function (oElement) {
        setTimeout(function() {
            oElement.innerHTML = "";
            oElement.parentNode.removeChild(oElement);
        }, 0);
    },
    W : function (sText) {
        document.write(sText);
    }
};  
    
/** @id Nimp */
var Nimp = function (aNimp) {
    this.aLists = aNimp;
    this.iSize = aNimp.length;
};      
    
Nimp.prototype = {
    /** @id Nimp.log */
    log : function (iIdx) {
        iIdx--;
        if (iIdx >= 0 && iIdx < this.iSize) {
            var u = this.aLists[iIdx];
            if (u.indexOf("?") > 0) {
                u += "&dummy=";
                u += Math.random();
            } else {
                u += "?dummy=";
                u += Math.random();
            }
            var o = new Image();
            o.src = u;
        }
    }
};

/** @id Cookie */
var Cookie = {
    /** @id Cookie.set */
    set : function (sCookieName, sCookieValue, iExpireDays, sDomain) {
        if (!iExpireDays) {
            iExpireDays = 1;
        }
        if (!sDomain) {
            sDomain = "ijji.com";
        }
        var d = new Date();
        d.setTime(d.getTime() + (86400000 * parseFloat(iExpireDays)));
        var c = escape(sCookieName);
        c += "=";
        c += escape(sCookieValue);
        c += "; expires=";
        c += d.toGMTString();
        c += "; domain=";
        c += sDomain;
        document.cookie = c;
    },
    /** @id Cookie.get */
    get : function (sCookieName) {
        var aC = document.cookie.match(new RegExp("(^|;)\\s*" + escape(sCookieName) + "=([^;\\s]+)"));
        return (aC ? unescape(aC[2]) : null);
    },
    /** @id Cookie.exist */
    exist : function (sCookieName) {
        var v = Cookie.get(sCookieName);
        if (!v) {
            return false;
        }
        return (v.toString() !== "");
    }

};

/** @id openWindow */
function openWindow(sURL, sWindowName, iWidth, iHeight, sScroll) {
    var x = (screen.width - iWidth) / 2;
    var y = (screen.height - iHeight) / 2;
    if (sScroll === null) {
        sScroll = "no";
    }
    var s = "";
    s += "toolbar=no, channelmode=no, location=no, directories=no, resizable=no, menubar=no";
    s += ", scrollbars=";
    s += ", left=";
    s += x;
    s += ", top=";
    s += y;
    s += ", width=";
    s += iWidth;
    s += ", height=";
    s += iHeight;
    var win = window.open(sURL, sWindowName, s);
    return win;
}

/** @id openURL */
function openURL(url) {
    window.open(url, "_blank");
}

/** @id parseNumber */
function parseNumber(vValue, iDefault) {
    if (isNaN(parseInt(vValue))) {
        return iDefault;
    } else {
        return Number(vValue);
    }
}
/** @id setLoginLevel */
function setLoginLevel(iLevel) {
    if (parent.document.getElementById("loginframe") !== null) {
        parent.loginframe.checkAd(iLevel);
    }
}
