﻿var servername = "http://www.gamescampus.eu";


var account = {
    name: 'account',
    signout_url: servername + '/account/meta/user_signout.asp',
    signin_url: servername + '/account/meta/user_signin.asp',
    input_bg: null,
    disable_el: null,

    signout: function() {
        location.href = this.signout_url + '?rtnurl=' + encodeURIComponent(location.href);
    },

    signin: function() {
        var _frm = $("#frm_signin")
        var _uid = $('#uid').val();
        var _pwd = $('#pwd').val();
        var _rtnuri = $('#rtnurl').val();
        var _saveid = $('#saveid:checked').val();

        if (_uid.length <= 0 || _uid == '') {
            alert('Please enter your User ID.');
            $('#uid').focus();
            return false;
        }

        if (_pwd.length <= 0 || _pwd == '') {
            alert('Please enter your Password.');
            $('#pwd').focus();
            return false;
        }

        _frm.attr({ method: "post", action: this.signin_url });
        return true;
    },

    signup: function() {
        //alert('signup');
        $('#btnSubmit').attr("disable", "disable").hide();
        var _frm = arguments[0];
        var _rtnurl = $('#rtnurl').val();
        var _params = $(_frm).serialize();
        _rtnurl = (_rtnurl == '') ? '/' : _rtnurl;

        //alert([account.signup_url, _params]);

        $.post(account.signup_url, _params, function(data) {
            if (data.result == "true") {
                if (data.site == 0) {
                    location.href = "/";
                }
                else {
                    try {
                        after_signup();
                    }
                    catch (e) { }
                }
            }
            else {
                alert(data.message);
                $('#btnSubmit').attr("disable", "enable").show();
            }
        }, 'json');

        return false;
    },

    findinfo: function() {
        $('#myCampus_Wrap').hide().load(servername + '/account/findidpw.asp').show();
    },

    clrbg: function(ele) {
        this.input_bg = $(ele).css('background-image');
        $(ele).css('background-image', 'none');
    },

    resbg: function(ele) {
        if ($(ele).val() == '') {
            $(ele).css('background-image', this.input_bg);
        }
    },

    disable: function() {
        var styles = {
            "position": "absolute",
            "top": "0px",
            "left": "0px",
            "width": "100%",
            "height": "100%",
            "text-align": "center",
            "background-color": "#000000"
        };
        this.disable_el = $("<div/>").attr("id", "login_disalbe").css(styles).fadeTo(10, 0.5).appendTo($('div.gnb .body .sub .signin'));
        $("<img />").attr("src", "http://image.gamescampus.com/global/gnb/waiting.gif").css({ "margin": "50px auto" }).appendTo(this.disable_el);
    }
};

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') {
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString();
        }

        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { 
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
             
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

$.fn.clearForm = function() {
    return this.each(function() {
        $(':input', this).each(function() {
            var type = this.type, tag = this.tagName.toLowerCase();
            if (type == 'text' || type == 'password' || tag == 'textarea')
                this.value = '';
            else if (type == 'checkbox' || type == 'radio')
                this.checked = false;
            else if (tag == 'select')
                this.selectedIndex = -1;
        });
    });
};

var jsload = {
    loaded: [],
    load: function() {
        var sc = $('script[src *= "/js/common.js"]');

        var idx = arguments.length;
        while (idx-- > 0) {
            if ($.inArray(arguments[idx], this.loaded) == -1) {
                this.loaded.push(arguments[idx]);
                sc.after('<script type="text/javascript" src="/js/' + arguments[idx] + '.js"></script>');
            }
        }
    }
};

/************* String Functions *******************/
var Pattern = {
    PARTICULAR: /[$\\@\\\#%\^\&\*\(\)\[\]\+\_\{\}\`\~\=\'\"\|]/
    , ENGLISH: /^([a-zA-Z]+)$/ /* /^(\w[^0-9_]+)$/ */
    , NUMBER: /^(\d+)$/
    , ENGNUM: /^(\w+)$/
    , SPACE: /(^\s*)|(\s*$)/gi
    , EMAIL: /^((\w|[\-\.])+)@((\w|[\-\.])+)\.([A-Za-z]+)$/
    , PHONE: /^(0(\d{1,2}))-(\d{3,4})-(\d{4})$/
    , IDPWD: /^(\w{4,12})$/
    , SSN: /^(\d{13})$/
    , POST: /^((\d{3}))-(\d{3})$/
}
String.prototype.isValues = function() {
    return this.trim().length > 0 && this != null;
}
String.prototype.isValidFormat = function(format) {
    return this.search(format) != -1
}
String.prototype.isWord = function() {
    return this.isValidFormat(Pattern.ENGNUM);
}
String.prototype.isNum = function() {
    return this.isValidFormat(Pattern.NUMBER);
}
String.prototype.isEng = function() {
    return this.isValidFormat(Pattern.ENGLISH);
}
String.prototype.isParticular = function() {
    return this.isValidFormat(Pattern.PARTICULAR);
}
String.prototype.isEmail = function() {
    return this.isValidFormat(Pattern.EMAIL);
}
String.prototype.isSpace = function() {
    return this.isValidFormat(Pattern.SPACE);
}
String.prototype.trim = function() {
    return this.replace(Pattern.SPACE, "");
}
String.prototype.replaceAll = function(replace, string) {
    var tmpStr = this.trim();
    if (tmpStr != "" && replace != string)
        while (tmpStr.indexOf(replace) > -1) { tmpStr = tmpStr.replace(replace, string); }
    return tmpStr;
}
String.prototype.isLen = function(len) {
    return rtn = (len <= this.Length()) ? true : false;
}
String.prototype.Length = function() {
    var bytLen = 0, strSlice = "";
    for (var i = 0; i < this.length; i++) {
        strSlice = this.substring(i, i + 1);
        bytLen += Math.sqrt(Math.abs(escape(strSlice).length - 2));
    }
    return bytLen;
}
String.prototype.Slice = function(len) {
    var bytLen = 0, strSlice = "", strRtn = "";
    for (var i = 0; i < this.length; i++) {
        strSlice = this.substring(i, i + 1);
        bytLen += Math.sqrt(Math.abs(escape(strSlice).length - 2));
        strRtn += strSlice;
        if (bytLen >= len) { return strRtn; break; }
    }
    return strRtn;
}

