/* Å¬¶óÀÌ¾ðÆ® Á¤º¸ °¡Á®¿À´Â Object Start */
var getClientInfo = function() {
    this.getOS = function() {
        return (navigator.platform);
    };
    this.getScreenWidth = function() {
        return screen.width;
    };
    this.getScreenHeight = function() {
        return screen.height;
    };
    this.getBrowser = function() {
        return (navigator.userAgent);
    };

    var client_info = this;

    this.getOSType = function(type) {
        if (!type || type == 'undefined') {
            type = client_info.getOS();
        }
        var chk_type = type.toLowerCase();
        if (chk_type.indexOf('win') != -1) {
            return ("WIN");
        } else if (chk_type.indexOf('mac') != -1) {
            return ("MAC");
        } else if (chk_type.indexOf('linux') != -1) {
            return ("LINUX");
        } else {
            return ("ETC");
        }
    };
    this.getScreenSize = function() {
        return (client_info.getScreenWidth()+"x"+client_info.getScreenHeight());
    };
    this.getMobileOS = function() {
        var mobileKeyWords = new Array('iPhone', 'iPod', 'BlackBerry', 'Android', 'Windows CE', 'LG', 'MOT', 'SAMSUNG', 'SonyEricsson');
        for (var word in mobileKeyWords){
            if (navigator.userAgent.match(mobileKeyWords[word]) != null){
                return client_info.getOS();
                break;
            }
        }
        return false;
    };
    this.getMobile = function() {
        var mobileKeyWords = new Array('iPhone', 'iPod', 'BlackBerry', 'Android', 'Windows CE', 'LG', 'MOT', 'SAMSUNG', 'SonyEricsson');
        for (var i=0; i<mobileKeyWords.length; i++){
            if (navigator.userAgent.match(mobileKeyWords[i]) != null){
                return true;
                break;
            }
        }
        return false;
    };
    this.getBrowserType = function(type) {
        if (!type || type == 'undefined') {
            type = client_info.getBrowser();
        }
        var chk_type = type.toLowerCase();
        if (chk_type.indexOf('msie') != -1) {
            return ("EXPLORER");
        } else if (chk_type.indexOf('safari') != -1) {
            return ("SAFARI");
        } else if (chk_type.indexOf('firefox') != -1) {
            return ("FIREFOX");
        } else if (chk_type.indexOf('opera') != -1) {
            return ("OPERA");
        } else {
            return ("ETC");
        }
    };

    this.ParamsValue = new Array();
    this.GetParameter = function() {
        var strURL = document.location.search; 
        var tmpParam = strURL.substring(1).split("&");
        if (strURL.substring(1).length > 0) {
            var Params = new Array();
            for (i=0;i< tmpParam.length ; i++) {
                Params = tmpParam[i].split("=");
                var params_name = decodeURI(Params[0]);
                var params_value = Params[1];
                client_info.ParamsValue[params_name] = params_value;
            }
        }
    };
    this.getOrderType = function() {
        switch(client_info.ParamsValue['srt']) {
            case "sian" :
                return "SIA";
                break;
            case "crd" : default :
                return "CRD";
                break;
        }
    };
    this.getImageType = function() {
        switch(client_info.ParamsValue['sOptions[typP]']+client_info.ParamsValue['sOptions[typF]']) {
            case "P" :
                return "RM";
                break;
            case "F" :
                return "RF";
                break;
            case "PF" : default :
                return "ALL";
                break;
        }
    };
    this.getKeywordCount = function() {
        var kwd_count = new Array();
        var TRIM_PATTERN = /(^\s*)|(\s*$)/g; // ³»¿ëÀÇ °ªÀ» ºó°ø¹éÀ» trimÇÏ±â À§ÇÑ°Í(¾Õ/µÚ)
        String.prototype.trim = function() {
             return this.replace(TRIM_PATTERN, "");
        }

        var kwdstrs = document.getElementById('keywordStr').value.trim();
        if (kwdstrs) {
            var kwd_split = kwdstrs.split(' ');
            for (var v=0; v<kwd_split.length; v++) {
                if (kwd_split[v]) {
                    kwd_count.push(kwd_split[v]);
                }
            }
            return (kwd_count.length);
        } else {
            return false;
        }
    };
};

var getMobile = function() {
    var clientInfo = new getClientInfo(); //Object »ý¼º
    return clientInfo.getMobile();
}

var getInfo = function() {
    var clientInfo = new getClientInfo(); //Object »ý¼º
    var os_type = clientInfo.getOSType(); //½Ã½ºÅÛ ÄÚµå Á¤º¸
    var browser_type = clientInfo.getBrowserType(); //ºê¶ó¿ìÀú Á¤º¸
    var screen_size = clientInfo.getScreenSize(); //½ºÅ©¸° »çÀÌÁî
    //JSON »ç¿ëÇÏ¿© ¸®ÅÏ
    var return_value = {
        "OS" : os_type,
        "BROWSER" : browser_type,
        "DIMENSION" : screen_size
        };
    return return_value;
};

var getSearchInfo = function() {
    var searchInfo = new getClientInfo(); //Object »ý¼º
    searchInfo.GetParameter();
    var order_type = searchInfo.getOrderType();
    var image_type = searchInfo.getImageType();
    var return_value = {
        "ORDER" : order_type,
        "IMAGE" : image_type
    }
    return return_value;
};

var getKeywordCnt = function() {
    var searchInfo = new getClientInfo(); //Object »ý¼º
    var kwd_cnt = searchInfo.getKeywordCount();
    if (kwd_cnt != false) {
        var return_value = {
            "KWD_CNT" : kwd_cnt 
        }
        return return_value;
    } else {
        return false;
    }
};
/* Å¬¶óÀÌ¾ðÆ® Á¤º¸ °¡Á®¿À´Â Object End */

