//JS调用FLASH的函数
function thisMovie(movieName)
{
	return (navigator.appName.indexOf("Microsoft") != -1) ? document.getElementById(movieName) : document[movieName];
}
//搜索类型状态
var searchTypePop = false;
$(document).ready(function(){
	//
	$("#my_searchaction").click(function(){
		$("#my_searchtype").toggle();
	});
	$("#my_searchtype a").click(function(){
		if($(this).text() == '音乐')
		{
			$("#type").val('music');
			if ( $("#search").val() == '请输入会员名称' || $("#search").val() == '请输入您感兴趣的词' )
			{
				$("#search").val('请输入音乐名称');
			}
		}
		else if($(this).text() == '会员')
		{
			$("#type").val('user');
			if ( $("#search").val() == '请输入音乐名称' || $("#search").val() == '请输入您感兴趣的词' )
			{
				$("#search").val('请输入会员名称');
			}
		}
		else if($(this).text() == '标签')
		{
			$("#type").val('tag');
			if ( $("#search").val() == '请输入音乐名称' || $("#search").val() == '请输入会员名称' )
			{
				$("#search").val('请输入您感兴趣的词');
			}
		}
		$("#my_searchaction").text($(this).text());
		$("#my_searchtype").hide();
	});
	$("#my_searchaction").mouseover(function(){
		searchTypePop = false;
	});
	$("#my_searchaction").mouseout(function(){
		searchTypePop = true;
	});
	$("#my_searchaction li a").mouseover(function(){
		searchTypePop = false;
	});
	$("#my_searchaction li a").mouseout(function(){
		searchTypePop = true;
	});
	
	$("#search").focus(function(){
		if ( $(this).val() == '请输入音乐名称' ||
			$(this).val() == '请输入会员名称' ||
			$(this).val() == '请输入您感兴趣的词')
			{
			$(this).val('');
		}
	});
	$("#search").blur(function(){
		if ( $(this).val() == '' || $.trim($(this).val()) == '' )
		{
			if ( $("#type").val() == 'music' )
			{
				$(this).val('请输入音乐名称');
			}
			else if ( $("#type").val() == 'user' )
			{
				$(this).val('请输入会员名称');
			}
			else if ( $("#type").val() == 'tag' )
			{
				$(this).val('请输入您感兴趣的词');
			}
		}
	});
  
	//ENTER键好使
	$("#search").keydown(function(e){
		var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
		if(keyCode == 13)
		{
			$("#resultSearch").click();
		}
	});
	//搜索按钮
	$("#resultSearch").click(function(){
		$("#search_type").val($("#my_searchaction").text());
		var search = $.trim($("#search").val());
		if (search == "" || search == "请输入音乐名称" || search == "请输入会员名称" || search == "请输入您感兴趣的词")
		{
			alertBackground('search');
			return false;
		}
		else
		{
			setTimeout(function(){
				$("#searchForm").submit();
			},0);
		}
	});
	//登陆后需要的操作
	var idclass = GetCookie("idclass");

	if ( idclass && idclass.length > 0 )
	{
		//调用FLASH grid的方法
		if(idclass.indexOf("grid_") == -1)
		{
			//调用图片墙flash里的方法
			DelCookie('idclass');
			if ( (func_pos = idclass.indexOf('func_')) > -1 )
			{
				func_pos += 5;
				if ( (argv_pos = idclass.indexOf('__')) > -1 )
				{
					func = idclass.substring(func_pos, argv_pos);
					argv_pos += 2;
					argv = idclass.substr(argv_pos);
					if ( argv.indexOf('_') > -1 )
					{
						argv = argv.replace('_', ',');
					}
				}
				else
				{
					func = idclass.substr(func_pos);
				}
				eval(func+'('+argv+')');
			}
			else if ( $("#"+idclass).length > 0 )
			{
				$("#"+idclass).click();
			}
			else if ( $("."+idclass).length > 0 )
			{
				$("."+idclass).click();
			}
		}
	}
	
});
$(document).click(function ()
{
	//收回搜索类型菜单
	if( searchTypePop )
	{
		$("#my_searchtype").hide();
	}
});


//消息检测
var g_detect = setInterval(updateMessageNum, 10000);
var g_blinkid = 0;
var g_blinkswitch = 0;
var g_title = document.title;
function updateMessageNum()
{
	$.ajax({
		type: "GET",
		url: "/messages",
		data: "getMessageNum=true",
		success: function(msg) {
			var num = parseInt(msg);
			if ( num > 0 )
			{
				$("#messageNum").text(num);
				if ($("#myMessageNum").length > 0) $("#myMessageNum").text(num);
				clearInterval(g_blinkid);
				g_blinkid = setInterval(blinkNewMsg, 1000);
			}
			else if ( num == -1 )
			{
				clearInterval(g_detect);
			}
			else
			{
				$("#messageNum").text("0");
				if ($("#myMessageNum").length > 0) $("#myMessageNum").text("0");
				stopBlinkNewMsg();
			}
		}
	});
}
//新消息提示
function blinkNewMsg()
{
	if ( g_blinkswitch % 2 )
	{
		top.document.title = "【新消息】 - " + g_title;
		$("#message").removeClass("message2").addClass("message");
	}
	else
	{
		top.document.title = "【　　　】 - " + g_title;	//&#12288
		$("#message").removeClass("message").addClass("message2");
	}
	g_blinkswitch++;
}
//停止新消息提示
function stopBlinkNewMsg()
{
	if (g_blinkid)
	{
		clearInterval(g_blinkid);
		g_blinkid = 0;
		$("#message").removeClass().addClass("message");
		top.document.title = g_title;
	}
}
//回复底部显示回复框 id格式  “#nameID”(带#号)；
function scrollToBottom(id)
{
	scroll(0, $(id).offset().top - document.documentElement.clientHeight/2);
}
//判断控件ID是否存在
function GetID(id)
{
	return ($("#"+id).length > 0) ? true : false;
}
//等待几秒后跳转到指定地址
function redirect(url, seconds)
{
	setTimeout(function(){
		location.href=url;
	}, seconds*1000);
}
//等待几秒后执行指定代码
function invoke(code, seconds)
{
	setTimeout(function(){
		eval(code)
	}, seconds*1000);
}
//设定Cookie值
function SetCookie(name, value)
{
	var expdate = new Date();
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 ));
	document.cookie = name + "=" + escape(value) +((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
	+((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
	+((secure == true) ? "; secure" : "");
}
//获得Cookie的原始值
function GetCookie(name)
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen)
	{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return GetCookieVal(j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}
//删除Cookie
function DelCookie(name)
{
	var exp = new Date();
	exp.setTime(exp.getTime() - 1);
	document.cookie = name + "=;expires="+exp.toGMTString()+";path=/";
}
//获得Cookie解码后的值
function GetCookieVal(offset)
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}
//限制最多字数，由此对象的“maxlength”决定
//使用方法：
//<textarea maxlength="10"></textarea>
function limit_input(tagName)
{
	$(tagName + "[maxlength]").live("input", function(){
		var mlength = $(this).attr("maxlength");
		var mvalue = $(this).val();
		if (mvalue.length > mlength) $(this).val(mvalue.substring(0, mlength));
	});
	$(tagName + "[maxlength]").bind("propertychange", function(){
		var mlength = $(this).attr("maxlength");
		var mvalue = $(this).val();
		if (mvalue.length > mlength) $(this).val(mvalue.substring(0, mlength));
	});
}
$(document).ready(function(){
	limit_input("textarea");
});
//试听
function play(mid, obj)
{
	var idname = "play_" + mid;
	var playhtml = '<div id="' + idname + '"><a href="http://www.adobe.com/go/getflashplayer"><img src="/swf/get_flash_player.gif" alt="Get Adobe Flash player" /></a></div>';
	$(obj).html(playhtml);
	$(obj).attr("onclick", "");
	var flashvars = {};
	var params = {};
	var attributes = {};
	params.wmode = "transparent";
	params.allowScriptAccess="always";
	attributes.id = mid;
	attributes.name = idname;
	attributes.align = "absmiddle";
	flashvars.mid = mid;
	swfobject.embedSWF("/swf/audition.swf", idname, "18", "18", "10.0.0", "/swf/expressInstall.swf", flashvars, params, attributes);
}
/**
 * method:	invest
 * @param:	price  投资价格
 * @option:	参与推广投资弹出层
 * @return	null
 */
var invest_obj = "";
function invest(e, mid, tzType)
{
	var idclass = "";
	invest_obj = e ? e : null;
	if(e == null)
	{
		idclass = "grid_invest_"+mid;
	}
	else
	{
		idclass = $(e).attr('class').split(" ")[0];
	}
	
	var tzItTitle = '参与音乐推广';
	$.ajax({
		type:"POST",
		url:"/smallpage.php",
		data:"type=tzit&mid="+mid+"&tzType="+tzType+"&idclass="+idclass,
		success:function(msg)
		{
			tipsWindown(tzItTitle,msg,608,350,'windows','tz');
			$.ajax({
				type:"POST",
				url:"/music/0",
				data:"promotion_detail="+mid,  //显示投资收益详细介绍
				success:function(msg){
					var mess = '<li>您推广给<b class="red">1</b>人下载，您将赚得<b class="red">' + add_commas(msg * 1, 2) + '</b>元；</li>';
					mess+='<li>您推广给<b class="red">10</b>人下载，您将赚得<b class="red">' + add_commas(msg * 10, 2) + '</b>元；</li>';
					mess+='<li>您推广给<b class="red">100</b>人下载，您将赚得<b class="red">' + add_commas(msg * 100, 2) + '</b>元；</li>';
					mess+='<li>您推广给<b class="red">500</b>人下载，您将赚得<b class="red">' + add_commas(msg * 500, 2) + '</b>元；</li>';
					mess+='<li>……</li>';
					$("#tzGetPrice").html(mess);
				}
			});
		}
	});
}
function invest_more(mid)
{
	closeTipWindow();
	if($(".invest_bar_"+mid).attr('class').indexOf('work') > -1)
	{
		invest_pointer(mid);
		scroll(0, 345);
	}
	else
	{
		SetCookie('idclass', 'func_invest_pointer__'+mid, 86400 * 30, '/');
		redirect('/music/'+mid);
	}
}
function invest_pointer(mid)
{
	$("#promotion_no_tips").hide();
	$("#promotiontips").fadeIn("slow");
	//去掉事件
	// $(".invest_bar_"+mid).attr("onclick", "");
	// $(".invest_bar_"+mid).attr("style", "cursor: default;");
	//去掉抢字
	// $(".invest_bar_"+mid).prev("i").hide();
	// $(".invest_bar_"+mid).removeClass().addClass("work hot_w").html("");
}
//For Grid
var invest_from_grid = false;
function grid_invest(mid, price)
{
	invest_from_grid = true;
	invest(null, mid, 0);
}
/**
 * method:	investMusic
 * @param:	price  投资价格
 * @option:	投资这个作品
 * @return	null
 */
function investMusic(mid, price, tzType)
{
	var curNo = $("#curNo").html();
	$.ajax({
		type:"POST",
		url:"/music/0",
		data:"tzprice="+price+"&mid="+mid+"&curNo="+curNo,
		success:function(msg){
			if(msg.indexOf('TRUE') > -1)
			{
				//头部减钱
				// $("#header_outlay").text(add_commas($("#header_outlay").text().replace(/,/g, "")-price, 2));
				get_balance();
				if (invest_obj)
				{
					//去掉事件
					$(invest_obj).attr("onclick", "");
					$(invest_obj).attr("style", "cursor: default;");
					//去掉抢字
					$(invest_obj).prev("i").hide();
					//添加下载剩余次数 详细页
					if ( tzType == 1 )
					{
						var remain_times = parseInt($(invest_obj).parent().next().find('a span').text());
						remain_times += 5;
						$("#download_button span").text(remain_times);
						$("#download_button").removeClass("load").addClass("buy_ed");
						$("#download_button").next().addClass("blue");
						$("#download_button").next().find('p').html('您还可以免费下载<span id="music_remain_times_' + mid + '" class="red bold">' + remain_times + '</span>次');
						$.ajax({
							type:"POST",
							url:"/music/0",
							data:"decode_mid="+mid,
							success:function(msg){
								$('#sharechat').val(msg);
							}
						});
					}
					else
					{
						var remain_times = parseInt($(invest_obj).next().find('span').text());
						remain_times += 5;
						$(invest_obj).next().find('span').text(remain_times);
						//music_bar里的下载状态
						if ( $('.download_bar_'+mid).length > 0 )
						{
							$('.download_bar_'+mid).removeClass('down').addClass("down_ed").attr('title', '还可以免费下载'+remain_times+'次');
							$('.download_bar_'+mid+' span').text(remain_times);
						}
					}
					//设置投资按钮样式
					if($(invest_obj).attr('class').indexOf('mon_') > -1)
					{
						$(invest_obj).removeClass().addClass("mon_ cooping_").html("成功").attr('title', '您正在推广');
					}
					else if($(invest_obj).attr('class').indexOf('mon') > -1)
					{
						$(invest_obj).removeClass().addClass("mon cooping");
					}
					else if($(invest_obj).attr('class').indexOf('work') > -1)
					{
						$(invest_obj).removeClass().addClass("work hot_w").html("");
						$("#promotion_no_tips").fadeOut("slow");
						$("#promotiontips").fadeIn("slow");
					}
				}
				//music_bar里的下载状态
				if ( $('.download_bar_'+mid).length > 0 )
				{
					$('.download_bar_'+mid+' span').text(parseInt($('.download_bar_'+mid+' span').text())+5);
					$('.download_bar_'+mid).removeClass('down').addClass("down_ed").attr('title', '还可以免费下载'+parseInt($('.download_bar_'+mid+' span').text())+'次');
				}
				if ( $('.invest_bar_'+mid).length > 0 )
				{
					$('.invest_bar_'+mid).removeClass().addClass('invest_bar_'+mid+' mon_ cooping_').html('成功').attr('title', '您正在推广');
				}
				tz_success(mid, tzType);
			}
			else
			{
				$("#tzMess").html(msg);
			}
		}
	});
}
/**
 * method:	tz_success
 * @param:	tzType  投资类型  mid 投资的ID
 * @option:	投资成功了
 * @return	null
 */
function tz_success(mid, tzType)
{
	$.ajax({
		type:"POST",
		url:"/smallpage.php",
		data:"type=tzsucc&mid="+mid,
		success:function(msg){
			if(tzType == 1)
			{
				tipsWindown("恭喜您！加盟成功",msg,608,350,'windows','tzsucc');
			}
			else
			{
				tipsWindown("恭喜您！加盟成功",msg,608,350,'windows','tzothersucc');
			}
		}
	});
	//通知Grid
	if (invest_from_grid)
	{
		var obj = thisMovie('grid');
		if (obj)
		{
			invest_from_grid = false;
			obj.invest_success_callback();
		}
	}
	else
	{
		if ( $('#grid').length > 0 )
		{
			var obj = thisMovie('grid');
			if (obj)
			{
				obj.invest_success(mid);
			}
		}
	}
}
function invest_agree(mid)
{
	var agree = $("input[name=agree]:checked").val();
	$.ajax({
		type: 'POST',
		url: '/music/0',
		data: 'invest_agree='+agree+'&mid='+mid,
		success:function(msg){
			closeTipWindow();
		}
	});
}
var g_remain_times_obj=null;
/**
 * method:	download
 * @param:	price  下载价格
 * @return	null
 */
function download(mid, price, obj, r_times)
{
	var remain_times = obj ? parseInt($(obj).find("span").text()) : r_times;
	//作者免费下载
	if ( remain_times == 99 )
	{
		downloadFile(mid);
		return;
	}
	//购买者或投资人剩余下载次数
	else if ( remain_times > 0 )
	{
		downloadFile(mid);
		var remain_time = GetCookie('remain_time_'+mid);
		if ( (remain_time != null) && (remain_time < time()) )
		{
			//do nothing
			return;
		}
		else
		{
			remain_times = remain_times - 1
		}
		//详细页里的的红字
		if ( $('#music_remain_times_'+mid).length > 0 )
		{
			$('#music_remain_times_'+mid).text(remain_times);
		}
		//我投资页里的的红字
		if ( $('#invest_remain_times_'+mid).length > 0 )
		{
			$('#invest_remain_times_'+mid).text(remain_times);
		}
		//我下载页里的的红字
		if ( $('#download_remain_times_'+mid).length > 0 )
		{
			$('#download_remain_times_'+mid).text(remain_times);
		}
		if ($('#tips_remain_times_'+mid).length > 0)
		{
			$('#tips_remain_times_'+mid).text(remain_times);
			$(obj).find("span").text(remain_times);
			$(g_remain_times_obj).find("span").text(parseInt($(g_remain_times_obj).find("span").text())-1);
		}
		else
		{
			$(obj).find("span").text(remain_times);
		}
		//music_bar下载状态
		if ( $('.download_bar_'+mid).length > 0 )
		{
			if ( remain_times > 0 )
			{
				$('.download_bar_'+mid).removeClass('down').addClass("down_ed").attr('title', '还可以免费下载'+remain_times+'次');
			}
			else
			{
				$('.download_bar_'+mid).removeClass('down_ed').addClass("down").attr('title', '必须购买才可以下载');
			}
		}
		//详细页
		if ( (remain_times == 0) && $('#download_button').length > 0 )
		{
			$("#download_button").next().removeClass("blue");
			$("#download_button").next().find('p').html('<a href="/faq#b-1">为什么付费下载而不免费？</a>');
			$("#download_button").removeClass("buy_ed").addClass("load");
		}
		return;
	}
	//购买才能下载
	else
	{
		//在小页点出来的购买页
		if ( $('#tips_remain_times_'+mid).length > 0 )
		{
			g_remain_times_obj = obj;
		}
		else
		{
			g_remain_times_obj = null;
		}
		//购买
		var downType=0;
		if ($("#musicDetailPage").length > 0)
		{
			downType=1;
		}
		var downItTitle = '感谢您支持原创作品！';
		var idclass = "";
		if(obj == null)
		{
			idclass = "grid_download_"+mid;
		}
		else
		{
			idclass = $(obj).attr('class').split(" ")[0];
		}
		$.ajax({
			type:"POST",
			url:"/smallpage.php",
			data:"type=buyit&price="+price+"&mid="+mid+"&downType="+downType+"&idclass="+idclass,
			success:function(msg){
				tipsWindown(downItTitle,msg,608,350,'windows','down');
			}
		});
	}
}
//For Grid
var download_from_grid = false;
function grid_download(mid, price, remain_times)
{
	download_from_grid = true;
	download(mid, price, null, remain_times);
}
/**
 * method:	show_waiting
 * @param:	price  下载价格
 * @option:	快速支付
 * @return	null
 */
function quick_online_pay(mid,price,downType)
{
	var title = '快速支付';
	$.ajax({
		type:"POST",
		url:"/smallpage.php",
		data:"type=onlinepaya&mid="+mid+"&price="+price+"&downType="+downType,
		success:function(msg){
			tipsWindown(title,msg,718,350,'pay_windows','pay');
		}
	});
}
//取帐户金额
function get_balance()
{
	$.ajax({
		type:"POST",
		url:"/account.php",
		data:"get_balance=true",
		success:function(msg){
			msg = msg.split('|');
			$("#header_outlay").text(msg[0]);
			$("#header_income").text(msg[1]);
		}
	});
}
/**
 * method:	downloadMusic
 * @param:	price  下载价格
 * @option:	开始下载这个作品了
 * @return	null
 */
function downloadMusic(mid, price, downType)
{
	if($(":radio:checked").val() == 2)
	{
		quick_online_pay(mid,price,downType);
	}
	else
	{
		$.ajax({
			type:"POST",
			url:"/music/0",
			data:"buy_music="+mid,
			beforeSend: function(){
				$("#down_btn_win").attr("disabled", "disabled");
			},
			success:function(msg){
				if(msg.indexOf('TRUE') > -1)
				{
					if ( msg.indexOf('promotion') > -1 )
					{
						down_success(mid, downType, 'promotion');
					}
					else
					{
						down_success(mid, downType, '');
					}
					//头部减钱
					// $("#header_outlay").text(add_commas($("#header_outlay").text().replace(/,/g, "")-price, 2));
					get_balance();
					var remain_times = 5;
					//链接内的数字
					if ( $(g_remain_times_obj).length > 0 )
					{
						remain_times += parseInt($(g_remain_times_obj).find("span").text());
						$(g_remain_times_obj).find("span").text(remain_times);
					}
					//小页的红字
					if ( $('#tips_remain_times_'+mid).length > 0 )
					{
						$('#tips_remain_times_'+mid).text(remain_times);
					}
					//详细页里的的红字
					if ( $('#music_remain_times_'+mid).length > 0 )
					{
						$('#music_remain_times_'+mid).text(remain_times);
					}
					//我投资页里的的红字
					if ( $('#invest_remain_times_'+mid).length > 0 )
					{
						$('#invest_remain_times_'+mid).text(remain_times);
					}
					//我下载页里的的红字
					if ( $('#download_remain_times_'+mid).length > 0 )
					{
						$('#download_remain_times_'+mid).text(remain_times);
					}
					//music_bar里的下载状态
					if ( $('.download_bar_'+mid).length > 0 )
					{
						$('.download_bar_'+mid).removeClass('down').addClass("down_ed").attr('title', '还可以免费下载'+remain_times+'次');
						$('.download_bar_'+mid+' span').text(remain_times);
					}
					//详细页
					if ( $('#download_button').length > 0 )
					{
						$("#download_button").removeClass("load").addClass("buy_ed");
						$("#download_button span").text(remain_times);
						$("#download_button").next().addClass("blue");
						$("#download_button").next().find('p').html('您还可以免费下载<span id="music_remain_times_' + mid + '" class="red bold">' + remain_times + '</span>次');
					}
				}
				else if(msg.indexOf('免费') > -1)
				{
					$("#downMess").text(msg);
				}
				else
				{
					$("#downMess").text(msg);
					$("#down_btn_win").attr("disabled", "");
				}
			}
		});
		
	}
}
//真正下载文件
function downloadFile(mid)
{
	if ( $('#downloadCode').length == 0 )
	{
		$('body').append('<div id="downloadCode" style="display:none;"></div>');
	}
	var download_iframe = '<iframe name="download_iframe" id="download_iframe" style="display:none;"></iframe>';
	var download_form = '<form action="/music/' + mid + '/download" method="post" id="download_form" target="download_iframe"></form>';
	$('#downloadCode').html(download_iframe + download_form);
	$('#download_form').submit();
	//通知Grid
	if (download_from_grid)
	{
		var obj = thisMovie('grid');
		if (obj)
		{
			download_from_grid = false;
			obj.download_success_callback();
		}
	}
	else
	{
		if ( $('#grid').length > 0 )
		{
			var obj = thisMovie('grid');
			if (obj)
			{
				obj.download_success(mid);
			}
		}
	}
}
/**
 * method:	downloadMusic
 * @param:	price  下载价格
 * @option:	开始下载这个作品了
 * @return	null
 */
function down_success(mid, downType, promotion)
{
	$.ajax({
		type:"POST",
		url:"/smallpage.php",
		data:"type=downsucc&mid="+mid,
		success:function(msg){
			if(downType == 1)
			{
				tipsWindown("下载成功",msg,608,350,'windows','downsucc');
			}
			else
			{
				tipsWindown("下载成功",msg,608,350,'windows','downothersucc');
			}
		}
	});
	//通知Grid
	if (download_from_grid)
	{
		var obj = thisMovie('grid');
		if (obj)
		{
			download_from_grid = false;
			obj.purchase_success_callback();
		}
	}
	else
	{
		if ( $('#grid').length > 0 )
		{
			var obj = thisMovie('grid');
			if (obj)
			{
				obj.purchase_success(mid, promotion);
			}
		}
	}
}
/**
 * method:	memberLogin
 * @param:	
 * @option:	会员登陆弹出小页
 * @return	null
 */
function memberLogin()
{
	var title = "用户登录";
	$.ajax({
		type:"POST",
		url:"/smallpage.php",
		data:"type=login",
		success: function(msg){
			tipsWindown(title,msg,608,125,'windows','login');
			$("#saveSessionWin").click(function(){
				var i = $(this).attr("value");
				$(this).attr("value", 1-i);
			});
		}
	});
}
//登陆
function login_submit_win()
{
	var content = $("#login_form_win").serialize();
	$.ajax({
		type:"POST",
		url:"/login",
		data:content,
		beforeSend: function(){
			$("#login_btn_win").attr("disabled", "disabled");
			$("#login_response_win").removeClass().addClass("response_loading").html("正在登录中，请稍候... ").show("slow");
		},
		success: function(msg){
			msg = msg.split("|");
			if (msg[0].indexOf("成功") > -1)
			{
				$("#login_response_win").removeClass().addClass("response_success").html(msg[0]).show("slow");
				location.reload();
			}
			else
			{
				$("#login_response_win").removeClass().addClass("response_error").html(msg[0]).show("slow");
				$("#email").focus();
				$("#login_btn_win").attr("disabled", "");
			}
		}
	});
}
//用户列表关注用户
function attention(e,uid)
{
	$.ajax({
		type:"POST",
		url:"/user/0",
		data:"attention_uid="+uid+"&idclass="+$(e).attr("id"),
		success:function(msg){
			if (msg.indexOf("SUCC") > -1)
			{
				alart('关注成功！',true);
				if($("#attentionTimes").length > 0)
				{
					$(e).removeClass().addClass("attentioned").html("");
				}
				else
				{
					$(e).removeClass('attentioned').addClass("atted").html("已关注Ta").attr('onclick','');
				}
				if ($('#now_user_attention').length > 0)
				{
					$('#now_user_attention').attr('onclick', '').attr('title', '已关注Ta').removeClass('w_attion').addClass('w_attion_');
				}
			}
			else if(msg.indexOf("NOLOGIN") > -1)
			{
				memberLogin();
			}
			else
			{
				alart(msg,false);
			}
		}
	});
}
//加为好友
function addFriend(uid,obj)
{
	$.ajax({
		type:"POST",
		url:"/user/0",
		data:"friend_uid="+uid+"&idclass="+$(obj).attr("class"),
		success:function(msg){
			if (msg.indexOf("SUCC") > -1)
			{
				alart('好友请求已发送！',true);
				if ($('#now_user_friend').length > 0)
				{
					$('#now_user_friend').attr('onclick', '').attr('title', '等待确认').removeClass('w_friend').addClass('w_friend_');
				}
			}
			else if(msg.indexOf("NOLOGIN") > -1)
			{
				memberLogin();
			}
			else
			{
				alart(msg,false);
			}
		}
	});
}
//提示框
//boolen true 为成功提示 flase 为失败提示
//content 为内容
function alart(content,boolen)
{
	var this_css = (boolen == true) ? 'alert_ok' : 'alert_wrong';
	tipsWindown('提示',content,300,150,this_css,'alert');
}
function alertBackground(id)
{
	$("#" + id).css("background-color", "#FFAEAA").focus();
	setTimeout(function(){
		$("#" + id).css("background-color", "#FFF").focus();
	}, 2000);
}
//添加千分位
function add_commas(number, num)
{
	if ( !number ) return;
	num = num >= 0 ? num : 2;
	//转字符串
	number += '';
	//分割
	number = number.split('.');
	//处理整数部分
	var integer = number[0] ? number[0] : 0;
	var rgx = /([0-9]+)([0-9]{3})/;
	while ( rgx.test(integer) )
	{
		integer = integer.replace(rgx, '$1' + ',' + '$2');
	}
	//处理小数部分
	var decimal = '';
	if ( num > 0 )
	{
		if ( number.length > 1 )
		{
			if ( num > number[1].length )
			{
				decimal = '.' + number[1] + rightPad('', num - number[1].length, '0');
			}
			else
			{
				decimal = '.' + number[1].substr(0, num);
			}
		}
		else
		{
			decimal = '.' + rightPad('', num, '0');
		}
	}
	return integer + decimal;
}
function leftPad(val, size, ch)
{
	var result = String(val);
	if(!ch)
	{
		ch = " ";
	}
	while (result.length < size)
	{
		result = ch + result;
	}
	return result;
}
function rightPad(val, size, ch)
{
	var result = String(val);
	if(!ch)
	{
		ch = " ";
	}
	while (result.length < size)
	{
		result = result + ch;
	}
	return result;
}
//返回类型
function getScript(type)
{
	return text = $("#share"+type).val();
}
