/**
*	封装创建HTML对象的通用的操作的类
*	
*	author wx		
*/

var htmlCreator = new Object();
/*
*	生成一个非表单中对象HTML对象；
*	sTag  -- 要生成对象的标签
*	pObj  -- 该对象的父对象
*	id 	  -- 该对象的id
*   style -- 该对象的样式
*/
htmlCreator.creatorHtmlObj = function(sTag,pObj,id,style)
{
	var obj = document.createElement(sTag);
	if(id!=undefined)
		obj.id = id;
	if(style!=undefined)
		obj.className = style;
	if(pObj!=undefined&&pObj!=null&&pObj!="")
		pObj.appendChild(obj);
	return obj;
}

/*
*	生成一个div对象；
*	pObj  -- 该对象的父对象
*	id 	  -- 该div的id
*   style -- 该div的样式
*/
htmlCreator.createDiv = function(pObj,id,style)
{
	var objDiv = document.createElement("div");
	if(id!=undefined)
		objDiv.id = id;
	if(style!=undefined)
		objDiv.className = style;
	if(pObj!=undefined&&pObj!=null&&pObj!="")
		pObj.appendChild(objDiv);
	return objDiv;
}
/*
*  创建一个选择框
*  pObj   --  所在的父对象
*  type   --  类型 checkbox or radio 默认为checkbox
*  id 	  --  对象 id，name
*  value  --  对象的value
*  caption--  选项的描述
*  onclickFun -- 单击时所执行的操作 
*  isbr  --  是否换行
*/
htmlCreator.createCheckBox = function(pObj,type,id,value,caption,onclickFun,isChecked,isbr)
{
	var objLab = document.createElement("label");
	
	var htmlStr ="<input ";
	if(type!=undefined&&(type=="checkbox"||type=="radio"))
		htmlStr += "type=\""+ type +"\" ";
	else
		htmlStr += "type=\"checkbox\" ";
	if(id!=undefined)
	{
		htmlStr += "name=\""+ id +"\" id=\""+id+"\"";
	}
	else
	{
		htmlStr += "name=\"\" id=\"\"";	
	}
	if(isChecked!=undefined&&(isChecked.toLowerCase()=="true"||isChecked==true))
	{
		htmlStr+=" checked";
	}
	if(value!=undefined)
		htmlStr += " value=\""+ value +"\" />";
	else
	    htmlStr += " value=\"\" />";
	var objCheckBox = document.createElement(htmlStr);
	if(onclickFun!=undefined&&onclickFun!=""&&onclickFun!=null)
	{
		objCheckBox.onclick = function()
		{
			onclickFun.call(this);	
		}
	}
	
	objLab.appendChild(objCheckBox);

	if(caption!=undefined)
	{
		var objFont = document.createElement("font");
		objFont.innerText= caption;
		objLab.appendChild(objFont);
	}
	if(isbr==true)
	{
		var objBr = document.createElement("br");
		objLab.appendChild(objBr);
	}
	pObj.appendChild(objLab);
	return objCheckBox;
}
/**
*	创建一个Tr对象
*	objTable -- 表格对象
*   id     -- tr 的id
*   style  -- tr 的样式名
*/
htmlCreator.creatorTr = function(objTable,id,style)
{
	if(objTable!=null&&objTable!=undefined&&objTable!="")
	{
		var objTr = objTable.insertRow();
		if(id!=null&&id!=undefined)
			objTr.id = id;
		if(style!=null&&style!=undefined)
			objTr.className = style;
		return objTr;
	}
}

/**
*	创建一个Tr对象
*	objTr --  要插入td 的tr对象
*   id     -- td 的id
*   style  -- td 的样式名
*/
htmlCreator.creatorTd = function(objTr,id,style)
{
	if(objTr!=null&&objTr!=undefined&&objTr!="")
	{
		var objTd = objTr.insertCell();
		if(id!=null&&id!=undefined)
			objTd.id = id;
		if(style!=null&&style!=undefined)
			objTd.className = style;
		return objTd;
	}
}