function subStringElement(e, intLength)
{
	if (e && e.value && e.value.length>intLength)
	{
		var str = e.value;
		str = str.substring(0,intLength);
		e.value = str;
	}
}
function showMakeFriend()
{
	caobox.show_popup("ym_makefriend_outer2");
}
function checkLengthElement(id, maxLength, idChar)
{
	var e = document.getElementById(id);
	if (e)
	{
		var n = maxLength-e.value.length;
		if (n<0)
		{
			subStringElement(e,maxLength);
			n=0;
		}
		document.getElementById(idChar).innerHTML=n;
		if (n<0){ return false; }
		return true;
	}
}
function checkLenghtbb(event, id)
{
	alert(document.getElementById(id).value);
}
function makeFriend()
{
	var eContent = $("#makeFriendContent");
	$("#btSubmitMakeFriend").attr({href:"javascript:void(0);"});
	$.getJSON
	(
		YUME+"/json/invite/makefriend/"+strMember+"?jsoncallback=?",
		function(data)
		{
			var result = data.result;
			switch(result)
			{
				case 0:
					alert(""+strYumerFullname+" đã có trong danh sách bạn bè của bạn.");
					break;
				case 1:
					alert("Bạn và "+strYumerFullname+" đã trở thành bạn bè.");
					break;
				case 2:
					alert("Thực hiện kết bạn thành công.");
					$("#btSubmitMakeFriend").attr({href:"javascript:makeFriend();"});
					break;
				case 3:
					alert(strErrLock);
					break;
				case 4:
					alertSpam();
					$("#btSubmitMakeFriend").attr({href:"javascript:makeFriend();"});
					break;
				case 5:
					alert("Bạn đã kết bạn với "+strYumerFullname+" rồi và đang chờ "+strYumerFullname+" đồng ý.");
					break;
				case 6:
					alert("Số bạn của bạn đã vượt quá giới hạn cho phép.\nBạn không thể tiếp tục kết bạn.");
					break;
				default:break;
			}
			caobox.close_popup();
		}
	);
}
function makeFan()
{
	$.getJSON
	(
		YUME+"/json/invite/makefan/"+strMember+"?jsoncallback=?",
		function(data)
		{
			var result = data.result;
			var membertype = data.membertype;
			switch(result)
			{
				case 0:
				case 1:
				if(membertype==2)
				{
					alert("Bạn đã ủng hộ cho chương trình");
					$('ul.menu_left > li#P_MakeFan').removeClass('item22');
					$('ul.menu_left > li#P_MakeFan').addClass('item33');
					$('ul.menu_left > li#P_MakeFan').html('<a href="javascript:void(0)" class="ym_link" title="Bạn đã ủng hộ cho chương trình"> </a>');
				}
				else
				{
					alert("Bạn đã trở thành Fan của "+strYumerNickname+"");
					$('ul.menu_left > li#P_MakeFan').removeClass('item22');
					$('ul.menu_left > li#P_MakeFan').addClass('item33');
					$('ul.menu_left > li#P_MakeFan').html('<a href="javascript:void(0)" class="ym_link" title="Bạn đã là Fan của '+ strYumerNickname+'"> </a>');
				}
					break;
				default:break;
			}
		}
	);
}
//khoa thanh vien
function addLock()
{
	$("#btSubmitAddLock").attr({href:"javascript:void(0);"});
	$.getJSON
	(
		HOST_APIS+"profile_addlock/"+strYumerUsername+"/?jsoncallback=?",
		function(data)
		{
			var result = data.result;
			switch(result)
			{
				case 3:
					alertSpam();
					break;
				case 2:
					alert(""+strYumerFullname+" đã nằm trong danh sách \"Thành Viên Bị Khóa\" của bạn.");
					break;
				case 0:
					alert("Lỗi thêm khóa.");
					break;
				case -1:
					alert("Lỗi khóa.");
					break;
				case 1:
					alert("Đã thêm "+strYumerFullname+" vào danh sách \"Thành Viên Bị Khóa\" của bạn.");
					$("#btSubmitAddLock").attr({href:"javascript:addLock();"});
					break;
				default:
					break;
			}
			caobox.close_popup();
		}
	);
}
//copy theme
function copyTheme()
{
	var e = document.getElementById("themeYumerId");
	if (e.value)
	{
		var active = document.getElementById("usetheme").checked ? 1 : 0;
		$("#btSubmitCopyTheme").attr({href:"javascript:void(0);"});
		$.getJSON
		(
			HOST_APIS+"profile_copytheme/"+strYumerUsername+"/"+e.value+"/?jsoncallback=?",
			{type:active},
			function(data)
			{
				var result = data.result;
				switch(result)
				{
					case -1:
						alert("Theme muốn copy đang ở trạng thái private (thuộc sở hữu cá nhân) nên bạn không thể copy");
						break;
					case 2:
						alert(strErrLock);
						break;
					case 3:
						alert("Bạn chỉ có thể lưu tối đa "+intLimitThemes+" themes. Nếu muốn tiếp tục copy bạn phải xóa 1 trong "+intLimitThemes+" theme trong thư viện theme của bạn");
						break;
					case 4:
						alertSpam();
						break;
					case 0:
						alert("Lỗi copy theme.");
						break;
					default:
						alert("Copy theme thành công.");
						$("#btSubmitCopyTheme").attr({href:"javascript:copyTheme();"});
						break;
				}
				caobox.close_popup();
			}
		);
	}
}

function newCaptcha()
{
	document.getElementById("imgCaptcha").src = YUME+"/image.php?rand="+(Math.random()*99999999999999999);
}
function displayError(id, bolErr)
{
	var className = (bolErr==1) ? "error_form" : "normal_form";
	$("#div_"+id).removeClass();
	$("#div_"+id).addClass(className);
	if (bolErr)
	{
		$("#err_"+id).show();
	}
	else
	{
		$("#err_"+id).hide();
	}
}

function scrollToApp(id)
{
	var e = document.getElementById(id);
	if(e && e.style.display!="none")
	{
		var offsetLeft = e.offsetLeft;
		var offsetTop = e.offsetTop;
		window.scrollTo(offsetLeft, offsetTop);
	}
}
function saveBoxApp()
{
	ajax_saveBoxApp(ajax.getFormValues("frmapp"), true);
}
function setWaiting(id)
{
	var e = document.getElementById(id);
	if (e)
	{
		e.innerHTML = "Loading...";
		//setTimeout("turnOffWaiting('"+id+"')",gTimeOffWaiting*1000);
	}
}
function subStringElement(e, intLength)
{
	if (e && e.value && e.value.length>intLength)
	{
		var str = e.value;
		str = str.substring(0,intLength);
		e.value = str;
	}
}
function turnOffWaiting(id)
{
	var e = $("#"+id);
	var s1 = e.html().toLowerCase().replace(/"/gi,"");
	s1 = s1.replace(/;/gi,"");
	var s2 = gStrInner.toLowerCase().replace(/"/gi,"");
	s2 = s2.replace(/;/gi,"");
	if ( e && s1==s2 )
	{
		e.html("");
	}
}
function alertSpam()
{
	alert("Vui lòng thực hiện lại chức năng này sau "+imtTimeDeny+" giây.");
}