﻿var profile_url = "";
var profile_servernum = "";
var profile_name = "";
var profile_title = "";
var profile_id = "";

function alertUnlogin(){
	if(confirm('您还没登录笨狗用户系统，无法进行此操作。点击确定登录用户系统>>>')){
		window.open("http://profile.bengou.com/","","fullscreen=1");
	}
}

function typeAddFav(link,servernum,title,cid)
{
	profile_url = link;
	profile_servernum = servernum;
	profile_title = title+" 主页";
	profile_name = title;
	profile_id = cid;
	addFav();
}

function addFav(){
	var profile_ajaxurl = "http://profile.bengou.com/service/setUserCollects?url="+profile_url+"&servernum="+profile_servernum+"&title="+profile_title+"&name="+profile_name+"&id="+profile_id+"&length=48&istype=0&jsoncallback=?";
	//alert(profile_ajaxurl);
	if( MyCookie('password',null,{domains:"bengou.com"}) ) {
		$.getJSON("http://profile.bengou.com/outside/ServiceCheckUser?jsoncallback=?",function(data){
			if(data.msg == 1){
				$.getJSON(profile_ajaxurl,function(data){
					alert(data.msg);
				});
			}
		});
	}else{
		alertUnlogin();
	}
}

function sign_up(vardomain){
	if( MyCookie('sign_'+vardomain) == null) {
		try{
		$.get("http://www.bengou.com/signup/sign.jsp", {type:vardomain}, function(data){
			MyCookie('sign_'+vardomain,"1");
			alert('签到成功，欢迎加入大家庭');
			var signupnum = document.getElementById('signupnum');
			signupnum.innerHTML = signup_num+1;
		});
		}catch(e){
			alert('签到成功，欢迎加入大家庭');
			var signupnum = document.getElementById('signupnum');
			signupnum.innerHTML = signup_num+1;
		}
	}else{
		alert('亲爱的已经签过咯');
	}
}

/*cookie 插件*/
//jQuery.cookie
MyCookie = function(name, value, options) {
    if (typeof value != 'undefined' && value != null) { // name and value given, set cookie
        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(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        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 = 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]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

