function getobj(id){return document.getElementById(id);}

function checkobj(v) {
	if(typeof(v)=="string") {
		if(v=getobj(v)) return v;
		else return false; }
	else return v;
}

/*动态添加行
the_table	动态表格id或者对象
the_content	动态添加的控件
the_clss	动态添加行的样式
the_script	动态添加行同时执行的脚本，不需要写<script>,</script>
*/
function add_Row(the_table,the_content,the_class,the_script) {
	the_table=checkobj(the_table);
	var the_row,the_cell;
	var cur_rows=the_table.rows.length; 
	the_row=cur_rows==null?-1:(cur_rows); 
	var i=the_row;
	var tag_id=i==-1?1:i+1;
	the_content=the_content.split("<$td$>")
	var newrow=the_table.insertRow(i);//得到插入位置 
	if (the_class!=null||the_class!="")
	{newrow.className=the_class;}
	for (j=0;j<the_content.length;j++)
	{the_cell=newrow.insertCell(j);
	the_content[j]=the_content[j].replace(/\<\$Quantity\$\>/ig,"@$@"+tag_id);
	the_content[j]=the_content[j].replace(/\<\$Qty\$\>/ig,tag_id);
	the_cell.innerHTML=the_content[j];
	the_cell.name="td@$@@$@td";
	}
	if (the_script!=null||the_script!="")
	{the_script=the_script.replace(/\<\$Quantity\$\>/ig,"@$@"+tag_id);
	the_script=the_script.replace(/\<\$Qty\$\>/ig,tag_id);
	eval(the_script);
	}
}

//动态删除行	the_table需要动态表格id或者对象
function Get_Element(the_ele,the_tag){ 
	the_tag = the_tag.toLowerCase(); 
	if(the_ele.tagName.toLowerCase()==the_tag) 
	return the_ele; 
	while(the_ele=the_ele.offsetParent){ 
	if(the_ele.name==the_tag) 
	return the_ele; 
} 
	return(null); 
} 
function del_Row(the_table,the_autoobj){ 
	the_table=checkobj(the_table);
	var the_cell; 
	the_cell=Get_Element(event.srcElement,"td@$@@$@td"); 
	var index=the_cell.parentElement.rowIndex;
	var the_row,i,j;
	if(the_cell==null) return; 
	if(the_table.rows.length==0) return; 
	the_table.deleteRow(index); 
	var the_childnode;
	if(the_table.rows.length==0) return; 
	if(the_autoobj!=null&&the_autoobj!="")
	{the_autoobj=the_autoobj.split(",")
		for (i=index;i<the_table.rows.length;i++)
		{
	{for (j=0;j<the_autoobj.length;j++)
	{
		if(document.getElementById(the_autoobj[j]+"@$@"+(i+2).toString()))
		{document.getElementById(the_autoobj[j]+"@$@"+(i+2).toString()).innerHTML=document.getElementById(the_autoobj[j]+"@$@"+(i+2).toString()).innerHTML.replace(/\d+/g,(i+1).toString());
		}
	}
	}
	}
	}
	for (i=index;i<the_table.rows.length;i++)
	{for (j=0;j<the_table.rows[i].cells.length;j++)
		{
		the_table.rows[i].cells[j].innerHTML=the_table.rows[i].cells[j].innerHTML.replace(/\@\$\@\d+/g,"@$@"+(i+1).toString());
		}
	}
}

//选择文件
var ActiveAssetInput;
function openAsset(s)
{
	ActiveAssetInput = s
	if(navigator.appName.indexOf('Microsoft')!=-1)
		document.getElementById(ActiveAssetInput).value=modalDialogShow_IE("../assetmanager/default.asp",700,420); //IE	
	else
		modalDialogShow_Moz("../assetmanager/default.asp",700,420); //Moz	
}

function modalDialogShow_IE(url,width,height) //IE
	{
	return window.showModalDialog(url,window,
		"dialogWidth:"+width+"px;dialogHeight:"+height+"px;edge:Raised;center:Yes;help:No;Resizable:Yes;Maximize:Yes");
	}

function modalDialogShow_Moz(url,width,height) //Moz
    {
    var left = screen.availWidth/2 - width/2;
    var top = screen.availHeight/2 - height/2;
    activeModalWin = window.open(url, "", "width="+width+"px,height="+height+",left="+left+",top="+top);
    window.onfocus = function(){if (activeModalWin.closed == false){activeModalWin.focus();};};
}

function setAssetValue(v) //required by the asset manager
{
	document.getElementById(ActiveAssetInput).value = v;
}

function ShowDialog(url, width, height)
	{
	window.showModalDialog(url, window, "dialogWidth:" + width + "px;dialogHeight:" + height + "px;help:yes;scroll:yes;status:yes");
	//showModalDialog创建一个显示指定 HTML 文档的模式对话框。
}

// 操作标签
function selectTag(showContent,selfObj){
	// 操作标签
	var tag = $("#tabs")[0].getElementsByTagName("li");
	var taglength = tag.length;
	for(i=0; i<taglength; i++){
		tag[i].className = "unsub";
	}
	selfObj.parentNode.className = "sub";
	// 操作内容
	for(i=0; j=$("#tagContent"+i)[0]; i++){
		j.style.display = "none";
	}
	$('#'+showContent)[0].style.display = "block";
}