function trace(x, traceType)  {
    var type = typeof(x), message = '';

    switch (type) {
        case 'object':
            message = traceObj(x, traceType);
            break;
        default:
            message = typeof(x) + ': ' + x + (traceType && traceType == 'alert' ? '\n' : '<br>');
            break;
    }

    if (traceType && traceType == 'alert') {
        alert(message)
    } else {
        document.write(message)
    }

    function traceObj(x, traceType) {
        // 初始化对象属性
        if (traceObj.tabNum === undefined) {
            traceObj.tabNum = 0;
        }

        var notice = '';
        if (traceType && traceType == 'alert') {
            var tab = '\t', br = '\n';
        } else {
            var tab = '&nbsp;&nbsp;&nbsp;&nbsp;', br = '<br>';
        }

        notice += typeof(x) + br;
        for (var t = 0; t <traceObj.tabNum; t++) {
            notice += tab;
        }
        notice += '(' + br;
        for (var i in x) {
            for (var t = 0; t <= traceObj.tabNum; t++) {
                notice += tab;
            }
            if (typeof(x[i]) == 'object') {
                notice += '[' + i + '] => ';
                traceObj.tabNum++; // 增加缩进
                notice += traceObj(x[i], traceType);
                traceObj.tabNum--; // 减少缩进
            } else {
                notice += '[' + i + ']' + ' => ' + typeof(x[i]) + ': ' + x[i] + br;
            }
        }
        for (var t = 0; t <traceObj.tabNum; t++) {
            notice += tab;
        }
        notice += ')' + br;
        return notice;
    }
}

function getDate() {
	var now		= new Date();
	var iYear	= now.getFullYear();
	var iMonth	= now.getMonth() + 1;
	var iDay	= now.getDate();
	var iHour	= now.getHours();
	var iMinute	= now.getMinutes();

	if (iMonth < 10 ) {
		iMonth = "0" + iMonth;
	}
	if (iDay < 10 ) {
		iDay = "0" + iDay;
	}
	if (iHour < 10) {
		iHour = "0" + iHour;
	}
	if (iMinute < 10 ) {
		iMinute = "0" + iMinute;
	}

	return iYear+'-'+iMonth+'-'+iDay+' '+iHour+':'+iMinute;
}
function changeHidden(id, type) {
	if (type) {
		$('#' + id).css('display', type);
	} else {
		if ($('#' + id).css('display') == 'block') {
			$('#' + id).css('display', 'none');
		} else {
			$('#' + id).css('display', 'block');
		}
	}
}
function msgOpenBox() {
	if ($('#messageBox').css('display') == 'none') {
		$.getJSON(WEB_PATH + '/ajax.php?mod=Message&do=getUnRead&' + new Date(), function(rs){
			$('#messageBoxBody').html(rs.data)
		});
		$('#messageNav').css('background-color', '#7BB9D9');
		changeHidden('messageBox', 'block');
	} else {
		$('#messageNav').css('background-color', '');
		changeHidden('messageBox', 'none');
	}
}
function msgFriendAdd(msgId) {
	$.getJSON(WEB_PATH + '/ajax.php?mod=Message&do=allowFriend&msgId=' + msgId + '&' + new Date(), function(rs){
		if (rs.status == 'SUCCESS') {
			$('#messageId_' + msgId).remove();
		} else {
			alert(rs.message);
		}
	});
}
function msgIgnore(msgId, url) {
	$.getJSON(WEB_PATH + '/ajax.php?mod=Message&do=ignore&msgId=' + msgId + '&' + new Date(), function(rs) {
		if (rs.status == 'SUCCESS') {
			$('#messageId_' + msgId).remove();
			if (url) {
				location.href = url;
			}
			$('#msgNum').text($('#msgNum').text() - 1);
		} else {
			alert(rs.message);
		}
	});
}
// 打开登录窗口
function openLoginBox() {
	changeHidden('floatDiv', 'block');
	$('#floatTitle').html('用户登陆');
	$('#floatBody').html($('#loginBox').html());
	$('#loginName').focus();
}
// 执行登陆
function doLogin() {
	var options = {dataType: 'json', success: function(rs){
		if (rs.status == 'SUCCESS') {
			location.reload();
		} else {
			$('#loginError').html(rs.message);
		}
	}};

	$('#loginForm').ajaxSubmit(options);
	return false;
}

function setCursorPosition(object, start, end) {
    if (object.setSelectionRange) {
        object.focus();
        object.setSelectionRange(start, end);
    } else if (object.createTextRange) {
        var range = object.createTextRange();
        range.collapse(true);
        range.moveEnd("character", end);
        range.moveStart("character", start);
        range.select();
    }
}

function showMsg(msg, url) {
	changeHidden('floatDiv', 'block');
	$('#floatTitle').html('提示信息');
	if (url) {
		click = '<br><a href="' + url + '">关闭</a>';
	} else {
		click = '<br><a href="javascript:void(0)"onclick="changeHidden(\'floatDiv\', \'none\')">关闭</a>';
	}
	html = '<div style="text-align:center;width:100%;margin-top:20px">' + msg + click + '</div>';
	$('#floatBody').html(html);
}

function showMessage(id, icon, content, url, time, lock, func) {
	var id = arguments[0] ? arguments[0] : '1';
	var icon = arguments[1] ? arguments[1] : 'succeed';
	var content = arguments[2] ? arguments[2] : '操作成功';
	var url = arguments[3] ? arguments[3] : '';
	var time = arguments[4] ? arguments[4] : '3';
	var lock = arguments[5] ? arguments[5] : false;
	if (id == 1) {
		art.dialog({
			time: time,
		    icon: icon,
			title: '',
		    content: content
		});
	} else if (id == 2) {
		art.dialog({
			time: time,
		    icon: icon,
			title: '',
		    content: content,
			close: function(){
				location.href= url;
			}
		});
	} else if (id == 3) {
		art.dialog({
			lock: lock,
		    icon: icon,
			title: '',
		    content: content,
			button: [
				{
					name: '确定',
					callback: func
				},
				{
					name: '取消'
					//callback: function() {
						//alert('您点了取消');
					//}
				}
			]
		});
	}else if (id == 4) {
		art.dialog({
			lock: lock,
			time: time,
		    icon: icon,
			title: '',
		    content: content,
			button: [
				{
					name: '确定',
					callback: function() {
						location.href= url;
					}
				},
				{
					name: '取消'
					//callback: function() {
						//alert('您点了取消');
					//}
				}
			]
		});
	} else {
		alert('参数错误');
	}
}


