var site_url=document.scripts;
site_url=site_url[site_url.length-1].src.substring(0,site_url[site_url.length-1].src.lastIndexOf("/statics/js/")+1);
$(function(){
	$(":text, :password").focus(function(){
		$(this).attr("class","input_focus");
	}).blur(function(){
        $(this).removeClass("input_focus");
	});
	$("textarea").focus(function(){
		$(this).attr("class","textarea_focus");
	}).blur(function(){
        $(this).removeClass("textarea_focus");
	});
	$(":radio").attr("class","radio");
	//tabs切换
	$('.tabs li').hover(function(){
		$(this).addClass('active').siblings().removeClass('active');
		$('#'+$(this).parent().attr('id')+'_'+$(this).index()).show().siblings().hide();
    });
	//是否登录
	var username = $.cookie('mb_159f32d4e0a8c7_username');
	if (username != null) {
		// 在登录页面,自动跳转到会员中心
		if ($('#pass_loginLite_forward').val()) {
			redirect($('#pass_loginLite_forward').val());
		}
		var tmp = $('#top_login_2').html();
		if (tmp) {
			tmp = tmp.replace('{username}', username);
			$('#top_login_2').html(tmp).show();
		}
		tmp = $('#app_login_2').html();
		if (tmp) {
			tmp = tmp.replace('{username}', username);
			$('#app_login_2').html(tmp).show();
		}
	} else {
		$('#top_login_1').show();
		$('#app_login_1').show();
	}
});
function change_captcha(obj){
	obj.src = site_url + 'index.php?c=common&a=captcha&'+Math.random();
}
function redirect(url){
	location.href = url;
}
//添加收藏夹
function myAddPanel(){
	var title = document.title;
    var url = window.location;
	try {
		window.external.addFavorite(url, title);
    }
    catch(e){
		try {
			window.sidebar.addPanel(title, url, "");
        }
        catch(e){
            alert("加入收藏失败，有劳您手动添加。");
        }
    }
}
function homePage(obj) {
    var url = window.location;
    try {

        obj.style.behavior = 'url(#default#homepage)';
        obj.setHomePage(url);
    }
    catch(e) {
        if (window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }
            catch(e) {
                alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。");
            }
            var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
            prefs.setCharPref('browser.startup.homepage', url);
        }
    }
}
function confirmurl(url,message)
{
	if(confirm(message)) redirect(url);
}

function confirmform(form,message)
{
	if(confirm(message)) form.submit();
}
function ContentSize(size)
{
	var obj=document.getElementById("endtext");
	obj.style.fontSize=size+"px";
}
function copyToClipBoard(){
	var clipBoardContent='';
	clipBoardContent+=document.title;
	clipBoardContent+="\r\n"+window.location.href;
	window.clipboardData.setData("Text",clipBoardContent);
	alert("您已复制标题及链接，请粘贴到QQ/MSN等发给好友!");
}
function showday(name){
	var el = $('#'+name+'day');
	var day = el.val();
	el.empty();
	el.append('<option value="">日</option>');
	var year = $('#'+name+'year').val();
	var tmp;
	if (year == '') {
		tmp = new Date();
		year = tmp.getFullYear();
	}
	var month = parseInt($('#'+name+'month').val(),10)+1;
    tmp = new Date(year+'/'+month+'/0');
	tmp = tmp.getDate();
	for(var i=1;i<=tmp;i++){
		if(day == i)el.append('<option value="'+i+'" selected="selected">'+i+'</option>');
		else el.append('<option value="'+i+'">'+i+'</option>');
	}
}

function collect(id, moduleid){
	if ($.cookie('mb_159f32d4e0a8c7_username') == null) {
		login('请您登录后再次提交');
		return false;
	}
	$.post(site_url+'index.php?c=collect&a=add', 'id='+id+'&moduleid='+moduleid, function(data){
		if(data[0] == 1){
			$('#a-collect').html('收藏&nbsp;&nbsp;'+data[2]);
		} else {
			if(data[2]) $data[1] = '<a href="'+data[2]+'">'+data[1]+'</a>';
		}
		$(window).jx-box(data[1],{drag:1,modal:1,pos:5,button:1});
	}, 'json');
}
function login(msg){
	$.jxbox(site_url+'index.php?a=login_box', {model:'simple',type:'ajax',modal:1,onokclose:0,onok:function(){
		var usernameObj = $('#login_box_username'),
			username = $.trim(usernameObj.val()),
			passwordObj = $('#login_box_password'),
			password = $.trim(passwordObj.val()),
			captcha = $.trim($('#login_box_verifycode').val());
		if (username == '') {
			$('#login_box_info').html('请输入账户');
			usernameObj.focus();
			return false;
		}
		if (password == '') {
			$('#login_box_info').html('请输入密码');
			passwordObj.focus();
			return false;
		}
		$.post($('#login_box_action').val(), 'username='+username+'&password='+password+'&captcha='+captcha+'&submit=1', function(data){
			if(data[0] == 1){
				$('#login_box_info').html(data[1]);
				// 头部登录状态
				var tmp = $('#top_login_2').html();
				if (tmp) {
					tmp = tmp.replace('{username}', username);
					$('#top_login_2').html(tmp).show();
					$('#top_login_1').hide();
				}
				// 其他应用登录状态
				tmp = $('#app_login_2').html();
				if (tmp) {
					tmp = tmp.replace('{username}', username);
					$('#app_login_2').html(tmp).show();
					$('#app_login_1').hide();
				}
				setTimeout(function(){$.jxbox.close()}, 500);
			} else {
				$('#login_box_info').html(data[1]);
				usernameObj.val('');
				passwordObj.val('');
			}
		}, 'json');
	}});
	$('#login_box_info').html(msg);
}