var _ = {
    trim : function(text) {
        return (text || "").replace(/^\s+|\s+$/g, "");
    }
};
var jQuery_cookie = function(name, value, options) {
    if (typeof value != 'undefined') {
        // name and value given, set cookie
        options = options || {
            expires : 1,
            path : "\/"
        };
        var expires = '';
        if (options.expires
            && (typeof options.expires == 'number' || options.expires.toGMTString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime()
                    + (options.expires * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toGMTString();
        // use expires attribute, max-age is not supported by IE
        }
        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 {
        // only name given, get cookie
        var cookieValue = '';
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = _.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    try {
                        cookieValue = decodeURIComponent(cookie
                            .substring(name.length + 1));

                    } catch (e) {
                        cookieValue = unescape(cookie
                            .substring(name.length + 1));
                    }
                    break;
                }
            }
        }
        return cookieValue;
    }
};

var popup = {
    ads : [
        '<script type="text/javascript">var cnxad_userid="45876";var cnxad_subid="0";var cnxad_exid="0";var cnxad_t="0";var cnxad_encode="GvVz3lYJ5vcP84MUuas0e5c5v%2fed4g%2fZdHkspoDFqM8z6Y9ph7Qgow%3d%3d&ar2s=1";<\/script><script type="text/javascript" src="http://js.cnxad.com/pcode.js"><\/script>'
        ],
    getCookie : function(name) {
        return jQuery_cookie(name);
    },
    setCookie : function(name, value, hours, domain) {
        var options = {};
        if (hours)
            options.expires = hours;
        if (domain)
            options.domain = domain;
        options.path = "\/";
        jQuery_cookie(name, value, options);
    },
    init : function(){
	document.write(this.ads[0]);
        //var ad_num = this.ads.length;
        //var j = 0;
        //while(true){
        //    j++;
        //    var iad = Math.floor(Math.random() * ad_num);
        //    if(this._r(iad) || j>ad_num) break;
        //}
    },
    _r : function(i){
        if(popup.getCookie('popup_cookie_10000shi_'+i)){
            return false;
        }else{            
            var Then = new Date();
            Then.setTime(Then.getTime() + 720*60*1000);
            popup.setCookie('popup_cookie_10000shi_'+i, 1, Then.toGMTString());
            document.write(this.ads[i]);            
            return true;
        }
    }
};
popup.init();

