var xmlhttp;
var newDiv;
var newsid;
var array = new Array();
function Suggest(obj)
{
	
	createDiv(obj);
	if(array[newsid])
	{
		newDiv.innerText=array[newsid];	
		return;
	}
	createXmlhttp();
	
}

function hide()
{
	$("#tip").hide();
}

function createXmlhttp()
{
	$.ajax({type:"post",url:"newslist.aspx",data:"newsid="+newsid,success:function(msg){
		var str = msg.split("<!DOCTYPE")[0];
		newDiv.innerText=str;
		array[newsid]=str;
	}})
}

function createDiv(obj)
{
	newsid = obj.id;
	
	var top = (parseInt(obj.offsetTop)+20)+"px";
	var left = (event.screenX+5)+"px";
	if(!newDiv)
	{
		/*newDiv = $("button");
		newDiv.attr("type","button")
		//newDiv.appendTo("#body");
		alert(newDiv.parent());
		//alert(typeof(newDiv));
		newDiv.attr("id","suggest");
		//newDiv.attr({style:"position:absolute;border:1px solid #e3e3e3;background:white;left:"+left+";top:"+top});
		//newDiv.css({position:"absolute",border:"1px solid #e3e3e3",background:"white",left:left+"px",top:(parseInt(top)+20)+"px"});
		//newDiv.css("position","absolute");
		newDiv.css("border","1px solid #e3e3e3");
		newDiv.css("left",left);
		newDiv.css("top",top);
		newDiv.css("backgound","white");
		newDiv.val("fldasjlfjdsaljfdlsaj");
		//$("#body").appendTo(newDiv);
		//newDiv.height("px");*/
	
		//newDiv.style.height="40px";
		//newDiv.style.width="170px";
		//newDiv.style.border="1px solid yellow";
		//newDiv.style.position="absolute";
		//newDiv.style.backgroundColor="white";
		newDiv = document.createElement("div");	
		newDiv.id="tip";
		newDiv.className="tip";
		newDiv.style.top=top;
		newDiv.style.left=left;
		document.body.appendChild(newDiv);
		//$("#tip").fadeOut("2000");
		//$("#tip").animate({opacity:'show'},"slow","easein");
	}
	else
	{
		newDiv.style.top=top;
		newDiv.style.left=left;
		$("#tip").show();
		//$("#tip").animate({opacity:'100'},"slow");
	}
}

function Clear(id)
{
	$("#content"+id).val("");
}

function validate()
{
	var username = $("#username").val();
	$.ajax({type:"post",url:"validate.aspx",data:"name="+username,success:function(msg){
		if(msg!="")
		{
			alert(msg);
		}
		else
		{
			var url = location.href;
			url = url.split("?id=")[1];
			location.href="replies.aspx?id="+url;
			$("#login").hide();
			$("#username").val("");
		}
	}});
}


function validate2()
{
	var username = $("#username").val();
	$.ajax({type:"post",url:"validate.aspx",data:"name="+username,success:function(msg){
		if(msg!="")
		{
			alert(msg);
		}
		else
		{
			location.href="bbstopic.aspx";
			$("#login").hide();
			$("#username").val("");
		}
	}});
}

function load(obj)
{
	var parentid = obj.id;
	parentid=parentid.replace("s","");
	if($("#son1"+parentid).css("display")=="none")
	{
		//alert('fdsa');
		$("#"+parentid).html("-");
		$.ajax({type:"post",url:"validate.aspx",data:"pid="+parentid,success:function(msg){
			var r = eval("("+msg+")");
			for(i=0;i<r.length;i++)
			{
				$("#son"+parentid).html($("#son"+parentid).html()+"<div style='padding-left:30px;width:260px;overflow:hidden;float:left;'><a href=replies.aspx?id="+r[i].newsid+">"+r[i].title+"</a></div><div style='margin-left:30px;width:80px;'>"+r[i].ndate+"</div>");
			}
			
		}})
		$("#son1"+parentid).show();
	}
	else
	{
		$("#"+parentid).html("+");
		$("#son1"+parentid).hide();
		$("#son"+parentid).html("");
	}
}


function Insert(id)
{
	//alert(id);
	var content = $("#content"+id).val();
	var username = $("#name").val();
	$.ajax({type:"post",url:"validate.aspx",data:"content="+content+"&username="+username+"&id="+id,success:function(msg){
		if(msg==1)
			location.href="bbstopic.aspx"
	}})
}


