
var  nTimeout = 500;
var	 nFlag = 0;
var	 strInfo = "请在此输入评论...";
var  bIsEditing = false;

var OldCmtHeight = 0;
var OldMesTop = 0;


function AddComment(strUser, strID, strTime, strComment)
{

/*
	<div class="li" id="guid3">
		<div class="icon1"></div>
		<div class="icon2"></div>
		<div class="icon3"></div>
		<div class="icon4"></div>
		<div class="icondel" title="删除"  onmouseover="this.className='icondel icondel_over'"   onmousedown="this.className='icondel icondel_down'"  onmouseout="this.className='icondel'"></div>
		<div class="libg">
			<div class="name"><div class="names">未命名</div>09-10-23 10:30</div>
			<div class="jg">这个东西很不错啊，强力推荐这个东西很不</div>
		</div>
	</div>
*/
	var objCmtArea = document.getElementById('comment_area');
	if ( !objCmtArea )
	{
		return;
	}
	
	var objDiv = document.createElement("div");
	objCmtArea.appendChild(objDiv);		//
	objDiv.className = "li";
	objDiv.setAttribute("id", strID);		//guid作为ID
	
	for(var i = 0; i < 4; i ++)
	{
		var objIcon = document.createElement("div");
		objDiv.appendChild(objIcon);
		objIcon.className = "icon" + i;
	}
	
	var objDel = document.createElement("div");
	objDiv.appendChild(objDel);
	objDel.className = "icondel";
	objDel.setAttribute("title", "删除");
	objDel.onmouseover = "this.className='icondel icondel_over'";
	objDel.onmousedown="this.className='icondel icondel_down'";
	objDel.onmouseout="this.className='icondel'";
	
	
	var objCmnt = document.createElement("div");
	objDiv.appendChild(objCmnt);
	objCmnt.className = "libg";
	
	var objName = document.createElement("div");
	objCmnt.appendChild(objName);
	objName.className = "name";
	objName.innerHTML = '<div class="names" title='
			+ strUser 
			+ '>'
			+ strUser				//"未命名";		//这里显示用户名
			+ '</div>'
			+ strTime;			//这里显示评论时间
	
	var objContent = document.createElement("div");
	objCmnt.appendChild(objContent);
	objContent.className = "jg";
	objContent.innerText = strComment;		//这里显示评论内容

}

function onFocusInput(A)
{
	bIsEditing = true;
	if (A.innerHTML == strInfo)	
	{
		A.innerHTML = "";
	}
	
	//改变显示区大小
	var objCmtView = document.getElementById("comment_area");
	if( !objCmtView )
		return;
	nOldCmtHeight = objCmtView.offsetHeight;	
	
	var objMesView = document.getElementById("input_area");
	if( !objMesView )
		return;
	OldMesTop = objMesView.offsetTop;
		
	objCmtView.style.height = nOldCmtHeight - 20*2;
	objCmtView.scrollHeight -= 20*2;
	
	//改变输入区大小
	var nOldMesHeight = objMesView.offsetHeight;	
	objMesView.style.height = nOldMesHeight + 20*2;
	objMesView.style.top = OldMesTop - 20*2;

//	alert("top=" + nTop);
//	return objMesView.offsetHeight;
	
	
}

function onBlurInput(A)
{
	if (A.innerHTML == "")
	{
		nFlag =  window.setInterval("RestoreHtml()", nTimeout);
	}
	
	//改变显示区大小
	var objCmtView = document.getElementById("comment_area");
	if( !objCmtView )
		return;
	
	var newCmtHeit = objCmtView.offsetHeight + 20*2;
	objCmtView.style.height = newCmtHeit;	//OldCmtHeight;	//objMesView.offsetTop - objCmtView.offsetTop - 3;	
	
	//改变输入区大小
	var objMesView = document.getElementById("input_area");
	if( !objMesView )
		return;
	
//	var nOldBottom = objMesView.offsetTop + objMesView.offsetHeight;	
//	objMesView.style.top = objMesView.offsetTop + 20*2; //nOldBottom - 23;
	objMesView.style.top = objCmtView.offsetTop + newCmtHeit + 2; //nOldBottom - 23;
	objMesView.style.height = 23;
	
}

function RestoreHtml()
{
	bIsEditing = false;

	if (nFlag == 0)
	{
		return;
	}
	clearInterval(nFlag);
	nFlag = 0;
	var B = document.getElementById('input_comment');
	if (B != null)
	{
		B.innerHTML = strInfo;
	}
}

function insertImg(imgFile)
{
	if (nFlag != 0)
	{
		clearInterval(nFlag);
		nFlag = 0;
	}
	var	 strImg = '<img src="';
	strImg += imgFile;
	strImg += '">';
	var B = document.getElementById('input_comment');
	if (B != null)
	{
		if (B.innerHTML == "" || B.innerHTML == strInfo)
		{
			B.innerHTML	= strImg;
			return ;
		}
		B.focus();
		var C = document.selection.createRange();
		if(C && C.pasteHTML)
		{
			C.pasteHTML(strImg);
		}
	}
}

function onKeyDownInput(e)
{
	var keynum;

	if (window.event)
	{
		keynum = e.keyCode;
	}
	else if (e.which)
	{
		keynum = e.which;
	}
	if (13 == keynum)
	{
		if (e.ctrlKey)
		{
		}
		else if (!e.shiftKey)
		{
			var C = document.selection.createRange();
			if(C && C.pasteHTML)
			{
				C.pasteHTML('<br>');
			}
			
			e.returnValue = false;
			return false;
		}
	}	
	return true;
}

function InputAreaPosTop(dvInputArea)
{
	//计算top位置
	var nHeight = 23;
	if( bIsEditing )
	{
		nHeight = nHeight + 20 * 2;
	}
	var nTop = document.body.clientHeight -  nHeight - 8;
//	alert("输入parentheight="+dvInputArea.parentElement.clientHeight);
	alert("输入top="+nTop );
	return nTop;
}


function InputAreaPosHeight(dvInputArea)
{
	//计算高度
	var nHeight = 23;
	if( bIsEditing )
	{
		nHeight = nHeight + 20 * 2;
	}
//	alert("height=" + nHeight);
	return nHeight;
}

function onMouseDownExpress(dvExpr)
{
	dvExpr.className='face face_down';
}

function onMouseDownAdd(dvBtn)
{
	dvBtn.className='btn btn_down';
	var strComment = document.getElementById("input_comment").innerHTML;
	AddComment("中文测试账号", "1D236900-355D-4B90-99B5-E7283BF41E41", "09-10-23 10:30", strComment);
}

function CommentViewPosHeight(dvCmtView)
{
	//计算高度
	var nHeight = 23;
//	var dvMesInput = dvCmtView.nextSibling;
	if( bIsEditing )
	{
		nHeight = nHeight + 20 * 2;
	}
	var nCmtViewHeight = /* dvCmtView.offsetParent.clientTop +  */ dvCmtView.parentElement.clientHeight -  nHeight - 8 - dvCmtView.offsetTop;
//	alert("评论height="+nCmtViewHeight);
	return nCmtViewHeight;
}



function InsertFace(strIcon)
{
}

function DeleteComment()
{
}


function ClearAll()
{
}

