curselectobj = null;

function setonfocustohideselect()
{
	var obj;
	var i;
	if (document.all){
		document.body.onfocus = tryhideselect;
		obj = document.all.tags("table");
		for (i=0;i<obj.length;i++){
			obj.item(i).onfocus = tryhideselect;
		}
		obj = document.all.tags("td");
		for (i=0;i<obj.length;i++){
			obj.item(i).onfocus = tryhideselect;
		}
		obj = document.all.tags("a");
		for (i=0;i<obj.length;i++){
			obj.item(i).onfocus = tryhideselect;
		}
	}
}



function tselectobject(formvarh,formvarv,idon,idoff,selectedindex,nitems)
{
	this.formvarh = formvarh;
	this.formvarv = formvarv;
	this.idon = idon;
	this.idoff = idoff;
	this.selectedindex = selectedindex;
	this.visible = false;
	this.nitems = nitems;
	return this;
}

function toggleselect(selobj)
{
	if(selobj.nitems==0){//当选项为0时返回
		alert("请先设置");
		return;
	}
	//下拉列表中被选中的选项的序号
	var listn=document.all.pomanager_saveform.types.options.selectedindex
	var prefixid =listn;
	//idmindatabase为此选项在xml中的id
	var idindatabase =document.all.pomanager_saveform.types.options[listn].value ;
	//在此函数中调用optionclicked方法，实现页面上select的onchange功能
	optionclicked(selobj,prefixid,idindatabase);
}

function optionclicked(selobj,idx,val)
{   //删除此句
	//var obj = document.all[selobj.idon+"_"+idx];
	//原程序中取出vstr为了给显示的层重新赋值
	var vstr = document.all.pomanager_saveform.types.options[idx].text;
	//alert(vstr);
	vstr = vstr.replace(/^( )+/,"");
	var formobj=null;

	formobj = findformbyvarname(selobj.formvarh);
	setformchanged(formobj);
	if (formobj!=null){
		//eval("formobj."+selobj.formvarv+".value = vstr;");
		eval("formobj."+selobj.formvarh+".value = '"+val+"';");
	}
	selobj.selectedindex = idx;
	
}

function calcselectposition(selobj)
{
	if (document.all){
		var obj = document.all[selobj.idoff];
		var left = 0;
		var top = 0;
		for (; obj!=document.body; obj=obj.offsetparent){
			left += obj.offsetleft;
			top  += obj.offsettop;
		}
		obj = document.all[selobj.idon].style;
		obj.pixelleft = left;
		obj.pixeltop = top+document.all[selobj.idoff].offsetheight+1;
		obj.pixelwidth = document.all[selobj.idoff].offsetwidth;
		if (selobj.nitems<=10){
			obj.pixelheight = selobj.nitems*16+2;
			obj.overflow = "visible";
		}
		else{
			obj.pixelheight = 10*16+2;
			obj.overflow = "auto";
		}
	}
}

function preshowselect(selobj)
{
	obj = document.all[selobj.idon].style;
	obj.overflow = "hidden";
}

function showselect(selobj)
{
	if (document.all){
		
		if (curselectobj!=null)
			hideselect(curselectobj);
		selobj.visible = true;
		
		document.all[selobj.idon].style.visibility="visible";		
		//alert("third");
		calcselectposition(selobj);
		//alert("one");
		//alert(selobj.selectedindex);
		highlightoption(selobj,selobj.selectedindex);
		//alert("two");
		curselectobj = selobj;
	}
}

function hideselect(selobj)
{
	if (document.all){
		//alert("1");
		obj = document.all[selobj.idon].style;
		//alert("2");
		obj.visibility="hidden";
		selobj.visible = false;
		curselectobj = null;
	}
}

function delayhideselect(objname)
{
	settimeout("hideselect("+objname+");",200);
}

function tryhideselect()
{
	if (curselectobj!=null)
		hideselect(curselectobj);
}
tmp_select_vname="type1";
function genselitem(num,k,v)
{
	var sobj = "selobj_"+tmp_select_vname;
	var id = "selon_"+tmp_select_vname;
 	document.write("<option id=\""+id+"_"+num+"\" value=\""+k+"\">"+v+"</option>");
}
function genselitem1(num,k,v)
{
	var sobj = "selobj_"+tmp_select_vname;
	var id = "selon_"+tmp_select_vname;
 	return "<div class=\"selectitem\" id=\""+id+"_"+num+"\" onclick=\"optionclicked("+sobj+","+num+",'"+k+"');\" onmouseover=\"highlightoption("+sobj+","+num+");\" onmouseout=\"normaloption("+sobj+","+num+");\">"+v+"</div>";
}

function findformbyvarname(vname)
{
	for (i=0;i<document.forms.length;i++){
		if (document.forms[i].elements[vname]!=null)
			return document.forms[i];
	}
	return null;
}



function setformchanged(formobj)
{
	if (formobj==null)
		return;
	if (typeof(formobj.tuiformchanged)=="undefined")
		return;
	formobj.tuiformchanged.value = 1;
}

//-----add by linhai----------------------------------------------//
function fnsubmit(form)
{
	 
//innerhtml  不包括标签自身  
//outerhtml  包括标签自已
//decodeuri 方法返回一个字符串值。
//encodeuri 方法返回一个编码的 uri。如果您将编码结果传递给 decodeuri，那么将返回初始的字符串。
//encodeuri 方法不会对下列字符进行编码：":"、"/"、";" 和 "?"。

	
	//strtemp="<onload=\"this.outerhtml=decodeuri(\'"+encodeuri(emailstyleform.innerhtml)+"\');\">";
	strtemp1=encodeuri(emailstyleform.innerhtml);
	//strtemp=strtemp1.outerhtml;
	//alert(strtemp1);
	strtemp=decodeuri(strtemp1);
	//alert(strtemp);
	
	form.thtml.value=strtemp;
	//alert(submitform.transmitemail_thtml.value);
	form.submit();
}





















