/**
 post对象相关信息
*/
function postRefInfo(target,postId) {
	var postData = "postId="+postId;
	new Ajax.Updater(target, '/tags.do?method=postTagItemsJS', {method:'post',postBody:postData,asynchronous:true, evalScripts:true});
}

/**
 相册相关信息
*/
function albumRefInfo(target,postId) {
	var postData = "postId="+postId;
	new Ajax.Updater(target, '/tags.do?method=albumTagItemsJS', {method:'post',postBody:postData,asynchronous:true, evalScripts:true});
}

/**
 party对象相关信息
*/
function partyRefInfo(target,partyId) {
	var postData = "partyId="+partyId;
	new Ajax.Updater(target, '/tags.do?method=partyTagItemsJS', {method:'post',postBody:postData,asynchronous:true, evalScripts:true});
}

/**
 sight对象相关信息
*/
function refInfo(target,tagName,targetType,objectId) {
	var postData = "tagName="+tagName;
	if(objectId!=null) {
		postData = postData + "&" + targetType+"Id=" + objectId;
	}
	new Ajax.Updater(target, '/tags.do?method='+targetType+'TagItemsJS', {method:'post',postBody:postData,asynchronous:true, evalScripts:true});
}

/**
 添加post对象的标签
*/
function addPostTags(target,input,postId) {
	if($F(input).Trim() != "") {
		if(!hasSameTag($F(input).Trim(),$(target).innerHTML.split(' '))) {
			var postData = "postId="+postId+"&tagName="+$F(input).Trim();
			new Ajax.Updater(target, '/tags.do?method=tagPost', {method:'post',postBody:postData,asynchronous:true, evalScripts:true});
		} else {
			alert("已经存在相同的标签项");
		}
	} else {
		alert("请输入标签值");
	}
}


/**
 添加hotel对象的标签
*/
function addHotelTags(target,input,hotelId) {
	if($F(input).Trim() != "") {
		if($F(input).split(' ').length > 1) {
			alert('一次只可以输出一个标签!');
			return false;
		}
		if(!hasSameTag($F(input).Trim(),$(target).innerHTML.split(' '))) {
			var postData = "hotelId="+hotelId+"&tagName="+$F(input).Trim();
			new Ajax.Updater(target, '/tags.do?method=tagHotel', {method:'post',postBody:postData,asynchronous:true, evalScripts:true});
		} else {
			alert("已经存在相同的标签项");
		}
	} else {
		alert("请输入标签值");
	}
}

var inputEle;
var targetEle;
/**
 添加标签
*/
function addTags(target,input,tagObjectId,tagType) {
	inputEle = $(input);
	targetEle = $(targetEle);
	//alert(tagType);
	//return false;
	if($F(input).Trim() != "") {
		if($F(input).split(' ').length > 1) {
			alert('一次只可以输出一个标签!');
			return false;
		}
		if(!hasSameTag($F(input).Trim(),$(target).innerHTML.split(' '))) {
			$('tag-loading').show();
			var postData = "tagObjectId="+tagObjectId+"&tagName="+$F(input).Trim();
			new Ajax.Updater(target, '/tags.do?method=tag'+tagType, {onComplete:function(){setTimeout("hideTagLoading()",200);},method:'post',postBody:postData,asynchronous:true, evalScripts:true});
		} else {
			alert("已经存在相同的标签项");
		}
	} else {
		alert("请输入标签值");
	}
}

function hideTagLoading() {
	inputEle.value = "";
	$('tag-loading').hide();
	
}

function hasSameTag(tag,tagArray) {
	for(i=0;i<tagArray.length;i++) {
		if(tag == tagArray[i]) {
			return true;
		}
	}
	return false;
}
/**
读取post对象标签
*/
function loadPostTag(target,postId) {
	new Ajax.Updater(target, '/tags.do?method=loadPostTag&postId=' + postId, {method:'post',asynchronous:true, evalScripts:true});
}
