
<!-- 树形控件使用的脚本 -->
function clickTreeSign(srcImg){
     var srcTR=srcImg.parentElement.parentElement;
     var srcTable=srcTR.parentElement;
     if(srcTR.status=="open"){
      srcTR.status="closed";
      srcImg.src=srcImg.src.replace("minus","plus");
    }
    else{
        srcTR.status="open";
        srcImg.src=srcImg.src.replace("plus","minus");
    }
    var childNo=srcTR.rowIndex+1;
    var finished=false;
    while((childNo < srcTable.rows.length) && (!finished)){
        var child=srcTable.rows[childNo];
        var parent=srcTable.children(child.parentid);
        if(isDesendant(srcTR, child)&&(parent!=null)){
            if((parent.status=="open")&&(parent.style.display!="none"))
                child.style.display="";
                else
                child.style.display="none";
        }else{
            finished=true;
        }
          childNo++;
    }
}

/**
 * 内容类别树占位符中使用,hasBlankTR 为 true的时候
 */
function clickTreeSignSPTrue(srcImg,plusPic,minusPic){
     var srcTR=srcImg.parentElement.parentElement;
     var srcTable=srcTR.parentElement;
     if(srcTR.status=="open"){
      srcTR.status="closed";
      srcImg.src=plusPic;
    }
    else{
        srcTR.status="open";
        srcImg.src=minusPic;
    }
    var childNo=srcTR.rowIndex+2;
    var finished=false;
    while((childNo < srcTable.rows.length) && (!finished)){
        var child=srcTable.rows[childNo];
        var parent=srcTable.children(child.parentid);
        if(isDesendant(srcTR, child)&&(parent!=null)){
            if((parent.status=="open")&&(parent.style.display!="none")){
              child.style.display="";
              child.nextSibling.style.display="";
            }
            else{
              child.style.display="none";
              child.nextSibling.style.display="none";
            }
        }else{
            finished=true;
        }
          childNo = childNo+2;
    }
}

/**
 * 内容类别树占位符中使用,hasBlankTR 为 false的时候
 */
function clickTreeSignSPFalse(srcImg,plusPic,minusPic){
     var srcTR=srcImg.parentElement.parentElement;
     var srcTable=srcTR.parentElement;
     if(srcTR.status=="open"){
      srcTR.status="closed";
      srcImg.src=plusPic;
    }
    else{
        srcTR.status="open";
        srcImg.src=minusPic;
    }
    var childNo=srcTR.rowIndex+1;
    var finished=false;
    while((childNo < srcTable.rows.length) && (!finished)){
        var child=srcTable.rows[childNo];
        var parent=srcTable.children(child.parentid);
        if(isDesendant(srcTR, child)&&(parent!=null)){
            if((parent.status=="open")&&(parent.style.display!="none"))
                child.style.display="";
                else
                child.style.display="none";
        }else{
            finished=true;
        }
          childNo++;
    }
}

/**
 * 判断parentTD是否是childTD的父结点
 */
function isDesendant(parentTR, childTR){
    var oTable=parentTR.parentElement;
    var parent=childTR;
    while(parent!=null){
        if(parent.parentid==parentTR.id){
           return true;
        }
        if(parent.parentid==null)
          return false;
        parent=oTable.children(parent.parentid);
    }
    return false;
}
























/*      /////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
以下脚本不再使用
*/
var currSelected='0';
function synTree(frameName,newNodeID){
var doc=window.parent.frames(frameName).document;
var srcTR=doc.getElementById(newNodeID);
var srcTD=srcTR.cells(0);
var parentTable=srcTD;
  while(parentTable.tagName!="TABLE")
  {
    parentTable=parentTable.parentElement;
  }
  var selectedNode=doc.getElementById("selected");
  if(selectedNode != null){
    selectedNode.className="treeUnselected";
    selectedNode.id="";

  }

  srcTD.className="treeSelected";
  srcTD.id="selected";
}


function getTR(table,id,level){
 rows= table.rows;
 for (i = 0 ;i <rows.length; i++){
    if( rows[i].id == id && rows[i].level==level){
        return rows[i];
    }
 }
}

function treeTogSelect(srcTD){
  var parentTable=srcTD;
  while(parentTable.tagName!="TABLE")
  {
    parentTable=parentTable.parentElement;
  }
  var selectedNode=document.getElementById("selected");
  if(selectedNode != null){
    selectedNode.className="treeUnselected";
    selectedNode.id="";

  }

  srcTD.className="treeSelected";
  srcTD.id="selected";
}

function doAction(form, path, msg){
    if(msg == null || msg == ""){
        form.action = path;
        form.submit();
    }else{
        if(window.confirm(msg)){
            form.action = path;
            form.submit();
        }else{
        }
    }
}

function changeRadiobox(field,which) {
     if (which == "up") {
         field[0].checked=true;
         field[1].checked=false;
     }else {
         field[0].checked=false;
         field[1].checked=true;
     }
}
function doLocation(path, msg){
    if(msg == null || msg == ""){
        window.location = path;
        return true;
    }else{
        if(window.confirm(msg)){
            window.location = path;
            return true;
        }else{
            return false;
        }
    }
}

function doShowModalDialog(path, msg, setting){
    if(msg == null || msg == ""){
        showModalDialog(path, window, setting);
        return true;
    }else{
        if(window.confirm(msg)){
            showModalDialog(path, window, setting);
            return true;
        }else{
            return false;
        }
    }
}

var newWindow = null;
function doWindowOpen(path, title, setting){
//	if (!newWindow || newWindow.closed){
		newWindow =  window.open(path, title, setting);
//	}else{
//		newWindow.focus();
//	}
}

function setAction(path)
{
 document.forms[0].action=path;
}


var checkflag = "false";
var checkflag2 = "false";
function selectAll(field) {
     if(field == null) return;
     var flag="false";
     if (checkflag == "false") {
          for (i = 0; i < field.length; i++) {
               field[i].checked = true;
               flag="true";
          }
          checkflag = "true";
     }else {
          for (i = 0; i < field.length; i++) {
             field[i].checked = false;
             flag="true";
          }
          checkflag = "false";
     }
     if ((checkflag2 == "false") && (flag=="false")) {
          field.checked = true;
          checkflag2 = "true";
     }else if ((checkflag2 == "true") && (flag=="false")){
          field.checked=false;
          checkflag2 = "false";
     }
}




/**back placeholder code
 @param src
 @param classid placeholder id
 @param objectid instance id
*/
function returnPh(theWindow, objectID, className, altTitle, altContent){
  var sTable="<IMG ID='" + objectID + "!*!' classname='" + className + "' alt='" + altTitle + "\n" + altContent + "'>";
  dialogArguments.insertHTML(sTable);
  theWindow.returnValue = null;
  theWindow.close();
}

/**check checkbox
*/
function isChecked(name){
  var all = document.getElementsByName(name);
  for(i = 0; i < all.length; i++){
    if(all[i].checked){
      return true;
    }
  }
  return false;
}

/**
@param path
*/
function changeSeq(form,path,chID,textID){
    form.action=path+"?chID="+chID+"&textID="+textID;
    form.submit();
}

/**
check input code
@param evt :event
@param msg : alert Information
*/
function checkInput(evt,msg){
  var charCode = (navigator.appName=="Netscape")?evt.which:evt.keyCode;
  if (charCode>31&&(charCode<48||charCode>57)){
    alert(msg);
	return false;
  }
  return true;
}

/**
@param check checkbox's name
@param alertMsg alert Information
@confirmMsg confirm Information
@path action's path
*/
function Action(check,alertMsg,confirmMsg,path){

//  if(!isChecked(""+check+"")){
//    alert(alertMsg);
 //   return false;
 // }
  if(confirmMsg==null||confirmMsg==""){
     document.forms[0].action=path;
     return true;
  }else{
 	  if(confirm(confirmMsg)){
		 document.forms[0].action=path;
		 return true;
	  }else{
		return false;
	  }
  }
}

function onReload(sign){
  var len=document.forms[0].choose.length;
  for(i=0;i<len;i++){
    var str=document.forms[0].choose[i].text;
    var index=str.indexOf(sign);
 	  if(index>=0){
		eval("document.forms[0].choose[i].disabled=1");
	   }
  }
 }
/**
Use <div>
*/
function onsel(i){
    if(i==1){
       document.all.typeContent[0].style.display='';
       document.all.typeContent[1].style.display='none';
    }
    if(i==2){
       document.all.typeContent[0].style.display='none';
       document.all.typeContent[1].style.display='';
    }
}
/**
*/
function returnFileUrl(msg){
    var selected = 0;
    var curIndex;
    var value;
    if(document.forms[0].selectedFiles.length == null){
        if(document.forms[0].selectedFiles.checked){
            value=document.forms[0].selectedFiles.text;
        }
    }else{
        for(i=0;i<document.forms[0].selectedFiles.length;i++){
            if(document.forms[0].selectedFiles[i].checked){
                selected++;
                curIndex = i;
                if(selected>1){
                    alert(msg);
                    return;
                }
                value=document.forms[0].selectedFiles[curIndex].text;
            }
        }
    }
    window.returnValue =value;
    window.close();
}

/**Add a Option
 @param source  source select'name
 @param target  target select'name
*/
function addAOption(source,target)
{
      var to=document.all.item(target).options;
      var from=document.all.item(source).options;
      moveOption(from,to);
}

/**Add all Options
*  @param source  source select'name
*  @param target  target select'name
*/
function addOptions(source,target)
{
     for(i=0;i<document.all.item(source).options.length;i++)
          {document.all.item(source).options[i].selected=true;}
      var to=document.all.item(target).options;
      var from=document.all.item(source).options;
      moveOption(from,to);
}

/**Delete a Option
*  @param source  source select'name
*  @param target  target select'name
*/
function deleteAOption(source,target)
{
     var from=document.all.item(target).options;
     var to=document.all.item(source).options;
     moveOption(from,to);
}

/**Delete all Options
*  @param source  source select'name
*  @param target  target select'name
*/
function deleteOptions(source,target)
{
    for(i=0;i<document.all.item(target).options.length;i++)
        {document.all.item(target).options[i].selected=true;}
    var from=document.all.item(target).options;
    var to=document.all.item(source).options;
    moveOption(from,to);
}

/**Move Action
*  @param from  source option'name
*  @param to  target select'name
*/
function moveOption(from,to)
{
for(i=from.length-1;i>=0;i--)
 {
   if(from(i).selected)
    {
      var oOption = document.createElement("OPTION");
      to.add(oOption);
      oOption.innerText = from(i).innerText;
      oOption.value = from(i).value;
      oOption.selected=true;
      from.remove(i);
    }
 }
}

/**save button'action
*  @param source  source select'name
*  @param target  target select'name
*/
function saveAllOption(source,target)
{
      for(i=0;i<document.all.item(target).options.length;i++)
          {document.all.item(target).options[i].selected=true;}
}
/**
* change show state of the tree;
*/

/*
function setFocus(id){
  if(document.getElementById(currSelected)!=null){
  document.getElementById(currSelected).className="treeUnselected";
  }
 if(id!=null&&id!=''){
 currSelected=id;
 }else{
 old = getCookie("currSelected");
 if(old!='')
 currSelected=old;
 }
 srcTR=document.getElementById(currSelected);
 if(srcTR==null){
 srcTR=findTR();
 }
 if(srcTR!=null){
 srcTR.className="treeSelected";
 setCookie("currSelected",currSelected);
 var a = srcTR.getElementsByTagName("a")[0];
 if(a!=null)a.click();
// srcTR.scrollIntoView();
 }
 }
*/
function findTR(){
 var trs = document.body.getElementsByTagName("TR");
 for(i=0;i<trs.length;i++){
   if(trs[i].id!=null&&trs[i].id!=""){
    return trs[i];
   }
 }
}

function toggle(source)
{
//clipboardData.setData('text',(document.body.innerHTML));
 srcImg=window.event.srcElement;
 srcTR=window.event.srcElement.parentElement.parentElement;
 srcTable=srcTR.parentElement;
 child=srcTR.nextSibling;
 if(srcTR.status=="open")
{
  newStyle="treeHid";
  srcTR.status="closed";
  srcImg.src=srcImg.src.replace("minus","plus");
}
  else
 {
    newStyle="treeVis";
    srcTR.status="open";
  srcImg.src=srcImg.src.replace("plus","minus");
  }
 toHide=(srcTR.status=="closed");

if( srcTR.id == ''){
 while(child != null)
{
  child.status="closed";
  childImg=child.getElementsByTagName("img")[0];
  if(childImg != null)
	childImg.src=childImg.src.replace("minus","plus");
  if(toHide)
    {
     child.className=newStyle;
    }
  else
  if(child.parentid==null)
     child.className=newStyle;
   child=child.nextSibling;
}

}

if (child==null || child.parentid != srcTR.id ){
writelevel(srcTR);
}
else {
IDs="@"+srcTR.id+"@";
while(child!=null&&IDs.indexOf("@"+child.parentid+"@")>=0)
{
IDs=IDs+"@"+child.id+"@";
child.status="closed";
childImg=child.getElementsByTagName("img")[0];
if(childImg != null)
childImg.src=childImg.src.replace("minus","plus");
if(toHide)
{
child.className=newStyle;
}
else
if(child.parentid==srcTR.id)
child.className=newStyle;
child=child.nextSibling;
}
}
}


function expandAll(parentTable)
{
  var srcTD=document.getElementById("selected");
  var parentTable=srcTD;
  while(parentTable.tagName!="TABLE")
  {
    parentTable=parentTable.parentElement;
  }
  //srcTR=table.rows[0];
  srcTR=parentTable.rows[0];
    while (srcTR != null){
      if(srcTR.status=="closed"){
        srcImg=srcTR.getElementsByTagName("img")[0];
        srcImg.click();
      }
      srcTR = srcTR.nextSibling;
    }
    treeTogSelect(srcTD);
}

function closeAll(parentTable)
{
  while(parentTable.tagName!="TABLE")
  {
    parentTable=parentTable.parentElement;
  }
  //srcTR=table.rows[0];
  srcTR=parentTable.rows[0];
    while (srcTR != null){
      if(srcTR.status=="open"){
        srcImg=srcTR.getElementsByTagName("img")[0];
        srcImg.click();
      }
      srcTR = srcTR.nextSibling;
    }
//    treeTogSelect(srcTR.cells[0]);
}
function collapseChildren(table){
    //var srcTD=table.cells("selected");
    var srcTD=document.getElementById("selected");
    if(srcTD != null){
      while(srcTD.tagName!="TR")
      {
        srcTD=srcTD.parentElement;
      }
      if(srcTD.status=="open"){
        srcImg=srcTD.getElementsByTagName("img")[0];
        srcImg.click();
      }
    }
}
