var usrname = getCookie('usrname');
var sid = getCookie('sessionid');


var tag_ary = new Array();

function tag_post(type) {
	
	if (!check_is_login()) {
		return;
	}

	var content = document.getElementById("add_tags_content").value;
	if (content == ""){
		alert("标签不能为空");
		return;
	}
	if (!is_tag_content(content)){
		alert("标签中不能含有<>`~、!@#$%^&*(){}[]（）《》?+等特殊字符");
		return;
	}
	
	patrn = /[\s]+/g;
	content = content.replace(patrn, " ");
	if (type == 3){
		var id = albumid;
	} else if (type == 4){
		var id = artistid;
	}

	set_tag_record(type, id, sid, content);
	
	document.getElementById('add_tags').style.display='none';	
	document.getElementById("add_tags_content").value = "";
	
	alert("提交成功！");
}

function set_tag_record(type, id, sid, content) {
	var tmp = new Image();			
	var str = 'type='+type+'&id='+id+'&sid='+sid+'&content='+content;
	tmp.src='http://rating.movie.xunlei.com/set_tag.php?'+encodeURI(str)+'&cache='+rand(9999999);	
}

function tag_init() {
	var tag_show_str = '';
	
	var show_max = tag_ary.length;
	if (tag_ary.length>10) {// 最多显示10个标签
		show_max = 10
	}
	for (i=0; i<show_max; i++) {	
		if (true) {
			tag_show_str += '<a href="http://music.xunlei.com/search/all/'+encodeURI(tag_ary[i])+'" target="_blank">'+tag_ary[i]+'</a> ';
			//tag_show_str += tag_ary[i]+' ';
		}
	}
	document.getElementById("tag_show").innerHTML = tag_show_str ;
}

function check_is_login() {
	t_usrname = getCookie('usrname');
	if (t_usrname == "" || sid=="") {
		if (confirm("您还没有登录，点击\"确定\"登录")) {
			setTimeout("window.location.href='http://i.xunlei.com/login.html?u1="+location.href+"'", 500);		
			//location.href="http://i.xunlei.com/login.html?u1="+location.href;
		}
		return false;
	} 
	return true;
}

function is_tag_content(content) {
	var patrn=/[`~!@#\$%\^&\*\(\)\（\）\+\{\}\\、<>\《\》\?\-\[\]\|\.]/;   
	if (patrn.exec(content)) {
		return false;
	}
	return true;
}