 
function imageResize(obj) { if(obj.width > 635) { obj.width = 635; }  }

function imageResize2(obj) { if(obj.width > 570) { obj.width = 570;	}  }

function imageAutoThumbs(obj)
{
	if(obj.width > obj.height) 
	{
		obj.height = parseInt( 88 * obj.height / obj.width, 10);
		obj.style.marginTop = (88-obj.height)/2 + "px";
		obj.width = 88;
	}
	else {
		obj.width = parseInt( 88 * obj.width / obj.height, 10);
		obj.height = 88;
	}
}

function imageAutoThumbs2(obj)
{
	if(obj.width > obj.height) 
	{
		obj.height = parseInt( 94 * obj.height / obj.width, 10);
		obj.style.marginTop = (94-obj.height)/2 + "px";
		obj.width = 94;
	}
	else {
		obj.width = parseInt( 94 * obj.width / obj.height, 10);
		obj.height = 94;
	}
}

function insertText(obj,str) 
{
	obj.value += str;
}

function lastChar()
{
	var str = $("#cContent").val();
	if(str.length < 1) return "";
	return str.substr(str.length - 1, 1);
}

function MagicSubmit(obj, url)
{
	var title = "";
	if($("#cTitle").length > 0) title = SingleLine($("#cTitle").val());
	var stone = "";
	if($("#cStone").length > 0) {
		stone = SingleLine($("#cStone").val()).Trim();
		if(stone.length > 32) { alert("里程碑文字不要超过32个字"); return; }
	}
	var content = SingleLine($("#cContent").val()).Trim();
	if(stone.length + content.length < 1) {
		alert("您想说大白话？不行！\nPlease say something!");
		return;
	}
	var from = $("#from").val();
	var idstyle = $("#idstyle").val();

	var predate = "";
	if($("#predate").length > 0) { predate = $("#predate").html(); }

	if(idstyle == "2") {
		if(from=="0") {
			alert("请先选择项目!\nPlease first select a project.");
			return;
		}
	}

	$("#cContent").val("");

	obj.style.border = "solid 1px #AAAAAA";
	obj.innerHTML = "<img src=\"/images/ajax-loader.gif\">";
	obj.onclick = null;

	$.ajax({
		url: "/Utility/WritePrc.aspx",
	    data : { rnd : Math.random(), from : from, cTitle : title, cStone : stone, cContent : content, idstyle : idstyle, predate : predate },
		type : 'POST',
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			alert(XMLHttpRequest.status + " " + XMLHttpRequest.readyState + " " + textStatus);
        },
		success : function(result){
			if(result.length <= 5) {
				setTimeout("window.location='" + url + "'; ",1000);
			}
			else {
				alert(result);
			}
		}
	});
}

function Magic2Submit()
{
	var from = $("#from").val();
	var idstyle = $("#idstyle").val();
	var create = $("#create").val();
	var content = SingleLine($("#cContent").val());
	if(content.length < 1) {
		alert("您想说大白话？不行！\nPlease say something.");
		return;
	}

	$.ajax({
		url: "/Utility/WritePrc.aspx",
	    data : { rnd : Math.random(), from : from, cContent : content, idstyle : idstyle, create : create },
		type : 'POST',
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			alert(XMLHttpRequest.status + " " + XMLHttpRequest.readyState + " " + textStatus);
        },
		success : function(result){
			if(result.length <= 5) {
				window.location.reload();
			}
			else {
				alert(result);
			}
		}
	});
}

function MarksSubmit(obj, url)
{
	var style = $("#cStoneStyle").val();

	var stone = "";
	if($("#cStone").length > 0) {
		stone = SingleLine($("#cStone").val());
	}
	if(stone.length < 1) {
		alert("请输入里程碑名称\nPlease input milestone name.");
		return;
	}
	if(stone.length > 32) {
		alert("里程碑名称太长了,不能超过32个字!\nMilestone name too long!");
		return;
	}
	var create = $("#mark_year").val() + "-" + $("#mark_month").val() + "-" + $("#mark_day").val();
	var from = $("#from").val();

	$("#cStone").val("");

	obj.style.border = "dotted 1px #CCCCCC";
	obj.innerHTML = "<img src=\"/images/ajax-loader.gif\">";
	obj.onclick = null;

	$.ajax({
		url: "/Utility/MarksPrc.aspx",
	    data : { rnd : Math.random(), style : style, stone : stone, project : from, create : create },
		type : 'POST',
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			alert(XMLHttpRequest.status);
			alert(XMLHttpRequest.readyState);
			alert(textStatus);
        },
		success : function(result){
			setTimeout("window.location='" + url + "'; ",1000);
		}
	});
}

function FileDownload(s)
{
	window.open(s);
}

function SayTo(obj,id,name)
{
	var str = $("#cContent").val();
	if(str.indexOf("@" + name) < 0) {
		insertText(document.getElementById("cContent")," @" + name + " ");
		obj.style.display = "none";
	}
}

function Huati(obj,name)
{
	var str = $("#cContent").val();
	if(str.indexOf("#" + name + "#") < 0) {
		if(lastChar() == "#") {
			insertText(document.getElementById("cContent"),name + "# ");
		}
		else {
			insertText(document.getElementById("cContent")," #" + name + "# ");
		}
		if(obj!=null) obj.style.display = "none";
	}
}

function AddEmotion(img)
{
	insertText(document.getElementById("cContent"),"[EM]" + img + "[/EM] ");
}

function UploadEcho()
{
	$.get("/Utility/UploadEcho.aspx", { rnd : Math.random() }, function(result) {
		if($("#echo_img_count").length > 0) {
			$("#echo_img_count").html(result);
		}
	});
}

function FocusAction(obj, idx, chk)
{
	var opr = obj.getAttribute("title");
	if(opr == "create") {
		$.get("/Utility/FocusCreate.aspx", { rnd : Math.random(), id : idx, checksum : SingleLine(chk) }, function(result) {
			if(result == "OK") {
				obj.innerHTML = (obj.innerHTML=="Focus") ? "Unfocus" : "取消关注";
				obj.setAttribute("title", "delete");
			}
			else {
				alert(result);
			}
		});
	}

	if(opr == "delete") {
		$.get("/Utility/FocusErase.aspx", { rnd : Math.random(), id : idx, checksum : SingleLine(chk) }, function(result) {
			if(result == "OK") {
				obj.innerHTML = (obj.innerHTML=="Unfocus") ? "Focus" : "关注";
				obj.setAttribute("title", "create");
			}
			else {
				alert(result);
			}
		});
	}
}

function BlogEcho(id,cmd)
{
	$.get("/Utility/BlogInfo.aspx", { rnd : Math.random(), id : id, cmd : cmd }, function(result) {
		DropClear();
		if(cmd==0) $("#dis_count_" + id).html(result);
		if(cmd==1) $("#tran_count_" + id).html(result);
	});
}

function BlogDelete(id,md5)
{
   if (confirm("确定要删除这个文章吗？\nReally want to delete this blog?") == true)
   {
      $.get("/Utility/BlogDelete.aspx" , { rnd : Math.random(), id : id, checksum : SingleLine(md5) }, function(result) { 
         if(result == "OK")
         {
			 $("div.blog_panel_" + id).css("display", "none");
         }
		 else
		 {
			alert(result);
		 }
      });
   }
}

function GetMessages()
{
	$.get("/Utility/Messages.aspx", { rnd : Math.random() }, function(result) {
		$("#msg_pad").html(result);
		if(result.length > 1) {
			$(".right_msg").css("display", "");
			$(".right_msg").animate({height:55},"slow");
			Sound();
		}
		else {
			//$("#msg_pad").html("");
			//$(".right_msg").css("display", "none");
			//$(".right_msg").animate({height:0},"fast");
		}
	});
}

function GetMessages_Mobile()
{
	$.get("/Utility/Messages.aspx", { rnd : Math.random() }, function(result) {
		$("#msg_pad").html(result);
		if(result.length > 1 && msg_length == 0) {
			msg_length = 1;
			$("#msg_pad").animate({height:50},"slow");
			Sound();
		}
		if(result.length <= 1) {
			msg_length=0;
			$("#msg_pad").animate({height:0},"fast");
		}
	});
}

function GetFresh()
{
	$.get("/Utility/Fresh.aspx", { rnd : Math.random(), cmd : 0 }, function(result) {
		if(result.length > 1) {
			$("#blog_first").html(result);
			$(".right_msg").css("display", "");
			$(".right_msg").animate({height:56},"slow");
			Sound();
		}
		else {
			//$("#blog_first").html("");
			//$(".right_msg").css("display", "none");
			//$(".right_msg").animate({height:0},"fast");
		}
	});
}

function LoopDown()
{
	DropAjax( $('#icon_pad')[0], $('#writer_down_1')[0], 636, 185, '/Utility/Information.aspx', 'ajax', 'middle');
}

function TimeAction(obj)
{
	$.get("/Utility/Time.aspx", { rnd : Math.random(), control : obj.id, value : obj.options[obj.selectedIndex].value }, function(result) { $("#predating").html(result); });
}

function SchaduleAction(v)
{
	$.get("/Utility/Time.aspx", { rnd : Math.random(), control : "schadule", value : v }, function(result) { $("#predating").html(result); });
}
