//-------------------------------------------------------------------------
// !Recursion
// Treval all the parent windows of current window,
// check all frame object, return the first one
// If find nothing, 0 will be returned.
function getFrameByName(ifrmName,idoc)
{
	if(!ifrmName) return 0;
	var theDoc = (idoc?idoc:document);
	var frms = theDoc.frames;
	for(var i=0;i<frms.length;i++)
	{
		//alert("frms[i].name:"+frms[i].name+"\nifrmName:"+ifrmName)
		if(frms[i].name == ifrmName)
			return frms[i];
	}
	// can not find target frame, ready Recur
	if(theDoc==top.document) return 0;
	//alert(theDoc.parentWindow.parent.document.location)
	getFrameByName(ifrmName,theDoc.parentWindow.parent.document);
}
//-------------------------------------------------------------
function getElementById(iid)
{
	return document.getElementById(iid);
}
//-------------------------------------------------------------
function getParentByName(iobj,iname)
{
	if(!iname)return null;
	var me = (iobj?iobj:event.srcElement);
	if(me.parentNode)
		me=me.parentNode;
	while(me.parentNode && me.tagName!="HTML")
	{
		//if(confirm(me.outerHTML))break;
		if(me.tagName.toLowerCase() == iname.toLowerCase())
		{
			//alert("find and return!!\n\n"+me.outerHTML)
			return me;
		}
		me=me.parentNode;
	}
	return null;
}
//-------------------------------------------------------------------------
function link_click(inn)
{
	var linkObj = (inn?inn:event.srcElement);
	if(!linkObj.href) return;
	fire_link(linkObj.href,(linkObj.target?linkObj.target:0));
}
//-------------------------------------------------------------------------
function fire_link(ihref,itarget)
{
	if(!ihref) return false;
	var theHref = ihref;
	// if target is then same as ihref, not to fire the link
	var locate, tWin;
	if(itarget)
	{
		tWin = getFrameByName(itarget);
		if(tWin){
			locate = tWin.document.location.href;
		}else{
			locate = top.document.location.href;
		}
	}else{
		locate = document.location.href;
	}
	//alert("theHref:\t"+theHref+"\nlocate:\t"+locate);
	//alert(locate.indexOf(theHref))
	//if(-1!=locate.indexOf(theHref)) return true;
	// fire the link
	var obj = document.createElement("<a href=\""+ihref+"\" style=\"visibility:hidden;\">");
	if(itarget)
		obj.target = itarget;
	document.body.appendChild(obj);
	obj.click();
	document.body.removeChild(obj);
	return true;
}
//-------------------------------------------------------------------------
function link_mouseover(inn)
{
	inn.className="link_over";	
}
//-------------------------------------------------------------------------
function link_mouseout(inn)
{
	inn.className="link";	
}
//-------------------------------------------------------------------------
function item_mouseover(inn)
{
	if(inn.className.length<=0)return;
	var theName = inn.className +"";
	if(-1==theName.indexOf("_over"))
		inn.className = theName+"_over";
}
//-------------------------------------------------------------------------
function item_mouseout(inn)
{
	if(inn.className.length<=0)return;
	var theName = inn.className +"";
	if(-1!=theName.indexOf("_over"))
		inn.className = theName.substring(0,inn.className.length-5);
}
//------------------------------------------------------------------
function synsData(chk,hdn)
{
	hdn.value = (chk.checked?chk.value:chk.uncheckValue);
}
//------------------------------------------------------------------
function slt_change(iObj){}
//-------------------------------------------------------
function gotoPage(iobj,iForm)
{
	if(!iobj) return;
	var theForm = (iForm?iForm:document.DA);
	theForm.pn.value = iobj.pn;
	theForm.submit();
}
//-------------------------------------------------------
var currentListItem = null;
function highlightListItem(iobj)
{
	window.event.cancelBubble = true;
	lowlightListItem();
	if(!iobj) return;
	var parentTR = getParentByName(iobj,"TR");
	if (parentTR)
	{
		parentTR.style.backgroundColor="#ffff00";
	}
	currentListItem = iobj;
}
//-------------------------------------------------------
function lowlightListItem()
{
	if(currentListItem)
	{
		var parentTR = getParentByName(currentListItem,"TR");
		if (parentTR)
		{
			parentTR.style.backgroundColor="";
		}
		currentListItem = null;
	}
}
//-------------------------------------------------------
function openPicer(iobj)
{
	if(!iobj || !iobj.href || iobj.href.length==0) return;
	var sFeatures = "width=300,height=400,left="+(screen.width/2-200)+",top="+(screen.height/2-200)+",resizable=yes,status=yes";
	window.open(iobj.href,null,sFeatures);
}
//-------------------------------------------------------
function openListEditor(iobj)
{
	if(!iobj || !iobj.href || iobj.href.length==0) return;
	var sFeatures = "width=400,height=500,left="+(screen.width/2-200)+",top="+(screen.height/2-200)+",resizable=yes";
	window.open(iobj.href,null,sFeatures);
}
//--------------------------------------------------------
function setAll(flag,iObj)
{
	var theFlag = (flag?true:false);
	var suitObj = (iObj?iObj:idPicker);
	var objs = suitObj.all.tags("INPUT");
	for(var i=0;i<objs.length;i++)
	{
		if(objs[i].type=="checkbox")
		{
			objs[i].checked = theFlag;
		}
	}
}
//-------------------------------------------------------
function fooLink()
{
	alert("很抱歉，目前您没有访问这个链接的权限。");
}
//-------------------------------------------------------
function isInt(iv)
{
	return iv==parseInt(iv).toString();
}