function loginCallback(json) {
    if (json.err != '') {
        alert(json.err);
    } else {
    location.href = 'main.asp';
    }
}
function setHomepage(src) { src.style.behavior = 'url(#default#homepage)'; src.setHomePage('http://www.p555.com'); }
function bookmark() { window.external.AddFavorite('http://www.p555.com', '性开放俱乐部'); }
var user = {
    logout: function() {
        $.ajax({ type: 'post', url: 'ajax.asp', data: 'op=logout',
            success: function(json) {
                if (json.callback != undefined) {
                    eval(json.callback + '(json)');
                } else {
                    alert('您已经安全离开“p555.com(性开放俱乐部)”！！！');
                    location.href = 'index.asp';
                }
            }
        });
    },
    ckLogin: function(frm) {
        if ($(frm).find('[name=username]').val() == '') {
            alert('请输入会员名！');
            $(frm).find('[name=username]').focus();
            return false;
        }
        if ($(frm).find('[name=pwd]').val().length < 6) {
            alert('请输入会员密码！');
            $(frm).find('[name=pwd]').focus();
            return false;
        }

        return true;
    },
    fetchMessage: function() {
        $.getJSON('ajax.php?op=fetchMessage&_=' + new Date().getTime(),
       function(json) {
           if (json.err == 0) {
               var effect = 0;
               if (json.data == undefined) return;
               for (var cls in json.data) {
                   var jDom = $('.' + cls);
                   if (jDom.length > 0) {
                       effect++;
                       $('.' + cls).html(json.data[cls]);
                   }
               }
               if (effect) setTimeout(user.fetchMessage, 2000);
           }
       });
    },
    _innerWork: function() {
        var ckTimer = ckHlp.gt('autoWorkTimer');

        if (ckTimer == '') {
            var m = Math.floor(Math.random() * 10 + 2); //分钟;
            var dt = new Date(new Date().getTime() + 60000 * m);

            ckHlp.st('autoWorkTimer', dt.toGMTString(), dt.toGMTString());

            var ckFlag = ckHlp.gt('autoWorkFlag');
            if (ckFlag == '') {
                ckHlp.st('autoWorkFlag', '0');
                var max = Math.floor(Math.random() * 5 + 1);
                ckHlp.st('autoWorkMax', max);
                setTimeout(user._innerWork, 30000);
            } else {
                var max = parseInt('autoWorkMax') || 6;
                var v = parseInt(ckFlag) || 0;
                if (v < max) {

                    ckHlp.st('autoWorkFlag', v + 1);
                    $.getJSON('ajax.php?op=autoWork&_=' + +new Date().getTime());
                    setTimeout(user._innerWork, 30000);
                }
            }
        } else {
            setTimeout(user._innerWork, 30000);
        }
    },
    pullWork: function () { if (typeof (user.id) == undefined) return; $.getJSON('ajax.php?op=pull&_=' + new Date().getTime(), function (a) { user._dealWithPull(a) }) }, 
    _dealWithPull: function (a) { for (var i = 0; i < a.length; i++) { if (a[i].code == 0) { if (typeof (a[i].ck) != 'undefined') a[i].ck(a[i]) } } setTimeout(user.pullWork, 20000) }, 
    _pullMsgCk: function (a) { for (var b in a.data) { var c = $('.' + b); c.html(a.data[b]) }; if (a.data.numOfNewMsg > 0) { user._popup('<a href="pm.php?op=ListPm">你有新的站内消息尚未查看！</a>', '消息提醒') } }, 
    _pullVisitorCk: function (a) { user._popup('<a href="whovisitme.php">女会员"' + a.data.un + '"可能对你感兴趣！</a>', '消息提醒') }, 
    _pullGiftCk: function (a) { user._popup('女会员<a href="user.php?uid=' + a.data.uid + '" target="_blank">' + a.data.un + '</a>想要你送她一件礼物，<a href="gift.php?op=send&to=' + a.data.uid + '&id=' + a.data.id + '" target="_blank">立即为她挑选一件博取她的心动</a>。', '消息提醒') }, 
    setIdentity: function (a, b) { this.id = a; this.nickname = b }, 
    _popup: function (h, j) { if (typeof (user._popupMsg) == 'undefined') user._popupMsg = []; function initPopup() { var f = document.getElementById('usr_popup_msg'); if (null == f || undefined == f) { var g = 280, dh = 60; function gotpos() { if (f == undefined) return; if (f.style['display'] == 'none') return; var t = top; var a = document.documentElement; var b = document.body; var c = [t.pageXOffset || (a.scrollLeft || b.scrollLeft), t.pageYOffset || (a.scrollTop || b.scrollTop)]; var d = [t.innerWidth || (a.clientWidth || b.clientWidth), t.innerHeight || (a.clientHeight || b.clientHeight)]; var e = f.style; e['left'] = (c[0] + d[0] - g - 10) + 'px'; e['top'] = (c[1] + d[1] - dh - 10) + 'px' } function autopos() { gotpos(); setTimeout(autopos, 100) } function pop() { f = document.createElement('div'); f.id = 'usr_popup_msg'; try { document.body.insertBefore(f, document.body.firstChild) } catch (eis) { document.body.appendChild(f) }; f.style['width'] = g + 'px'; f.style['height'] = dh + 'px'; f.style['position'] = 'absolute'; f.style['zIndex'] = '9999999'; autopos(); f.innerHTML = '<div id="usr_popup_msg_tlt"><a href="javascript:;" id="usr_popup_msg_prev">上一条</a>&nbsp;<a href="javascript:;" id="usr_popup_msg_next">下一条</a><a href="javascript:;" id="usr_popup_msg_close">X</a></div><div id="usr_popup_msg_cnt"></div>' } pop(); $('#usr_popup_msg_close').click(function () { f.style['display'] = 'none' }); $('#usr_popup_msg_prev').click(function () { var i = parseInt($('#usr_popup_msg').attr('i')) || 0; i--; if (i < 0) i = user._popupMsg.length - 1; $('#usr_popup_msg_cnt').html(user._popupMsg[i]); $('#usr_popup_msg').attr('i', i) }); $('#usr_popup_msg_next').click(function () { var i = parseInt($('#usr_popup_msg').attr('i')) || 0; i++; if (i >= user._popupMsg.length) i = 0; $('#usr_popup_msg_cnt').html(user._popupMsg[i]); $('#usr_popup_msg').attr('i', i) }) } else if (f.style['display'] == 'none') { f.style['display'] = 'block' } }; initPopup(); user._popupMsg.push(h); var k = $('#usr_popup_msg_cnt'); $('#usr_popup_msg').attr('i', user._popupMsg.length - 1); k.html(h) }
}

$(function() {
    $('form.ajaxPost').each(function() {
        $(this).submit(function() {
            var jThis = $(this);
            if (user.ckLogin(this)) {
                if (jThis.attr('loading') != 'true') {
                    jThis.attr('loading', 'true');


                    $.ajax({ type: 'post', url: $(this).attr('action'),
                    data: jThis.serialize(),
                        dataType: 'json',
                        success: function(json) {
                        jThis.removeAttr('loading');
                            if (json.callback != undefined) {
                                eval(json.callback + '(json)');
                            }
                        }
                    });

                } else { alert('数据提交中...'); }
            }
            return false;
        });
    });
});

function onPageLoaded() {
    for (var i = 0; i < onPageFuns.length; i++) {
        onPageFuns[i]();
    }
}

function addLoadFn(fn) {
    if (typeof (onPageFuns) != 'undefined') {onPageFuns.push(fn);} else {$(function() {fn(); });};
}

function getParameter(param) {
  var query = window.location.search;
  var iLen = param.length;
  var iStart = query.indexOf(param);
  if (iStart == -1)
    return "";
  iStart += iLen + 1;
  var iEnd = query.indexOf("&", iStart);
  if (iEnd == -1)
    return query.substring(iStart);
  return query.substring(iStart, iEnd);
}

function getUnionId() {
	var loc = window.location.href;
	var pos = 1+loc.lastIndexOf('/');
	var len = loc.length;
	return loc.substring(pos,len);
}

function getTuijianId() {
	var loc = window.location.href;
	var pos = 3+loc.indexOf('/u-');
	if(pos == -1) return "";
	var len = loc.length;
	return loc.substring(pos,len);
}

