//------------------------------------------------------------------------------
//   爱喜软件　IBSEdu V5.0 客户端接口函数库
//       设计：江龙 (Dragon_jiang@163.net)
//       2002-5 至 2002-8
//   版权所有　引用须注
//　广州市爱喜软件有限公司
//------------------------------------------------------------------------------
 
var nullPhoto="/images/System/No.gif"; //空图片文件名
var curID=null; //当前的层
var curNo=1;       //当前选择的层号
var True=true;
var False=false;
var isInit=false; //页面是否初始化完成

function Select(n)
{
   if(curID==null) curID=divID1;
   curID.style.display='none';
   curID=eval("divID" + n);
   curNo=n;
   curID.style.display='';
   return(false);   
}


function getRadioValue(Name)
{
 var e=document.getElementsByName(Name)
 for(var i=0;i<e.length;i++)
   {
     if(e[i].checked) return(e[i].value);
   }  
 return(""); 
}

function setRadioValue(Name,value)
{
 var e=document.getElementsByName(Name)
 for(var i=0;i<e.length;i++)
    e[i].checked=(e[i].value==value);
}

function showClient(ID)
{
 showDialog("客户档案信息","/School/Equipment/Client/EditClient.asp?ID="+ID,"_blank","dislogTop=50px;dialogWidth=570px;dialogHeight=454px");
 return(false);
}

function showSubject(SubjectID)
{
 window.showModalDialog("/School/Score/Preview/Subject.asp?SubjectID="+SubjectID,"","dialgTop=80px;dialogWidth=580px;dialogHeight=410px;status=no")
 return(false);
}

function showToday()
{
	var today = new Date();
	var centry ;
	var s=new Array("日","一","二","三","四","五","六");
	centry="";
	if(today.getYear()<2000 ) centry = "19" ;
	var date1 = centry + (today.getYear()) + "年" + (today.getMonth() + 1 ) + "月";
	document.write('<table height=102 cellSpacing=0 cellPadding=0 width=120 background=/Images/School/myHome/diary.gif border=0>'+
    '<tbody><tr><td><table height=102 cellSpacing=0 cellPadding=0 width=120 background=/Images/School/myHome/diary.gif border=0>'+
    '<tbody><tr><td><table height=72 cellSpacing=0 cellPadding=0 width=120 border=0><tbody>'+
    '<tr><td height=23 align=center>' +date1+ '</td></tr>'+
    '<tr><td height=24 align=center><font color=#ff0000 face="Arial Black"  style="font-size:12pt">' +today.getDate()+ '</font></td></tr>'+
    '<tr><td height=23 align=center>星 期 '+s[today.getDay()]+  '</td></tr>'+
    '</tbody></table></td></tr></tbody></table></td></tr></tbody></table>');
}                         
 
 
function showDialog(Title,URL,t,Status)
  {
    if(window.showModalDialog("/Lib/showDialog.htm?Title="+escape(trim(Title))+"&URL="+escape(trim(URL)),this,Status+';resizable=no;status=no'))
       this.location.reload();
    return(false);
  }

function editUser(UID)
{if (trim(UID)=="")
   alert("用户ID号错误!");
 else
   switch(UID.charAt(0))
     {
      case "E":
          return(editEmployee(UID));
          break;
      case "S":
          return(editStudent(UID));
          break;
      case "M":
          return(editMinistry(UID));
          break;
      case "P":
          return(editPaterfamilias(UID));
          break;
      default:
          alert("非本校合法用户不能查看其信息!");           
     }
 
}


function previewKQ(LeaveID)
{
   showDialog("请假申请",'/School/KaoQin/Leave/Edit.asp?LeaveID='+LeaveID,'',"dialogTop=20px;dialogWidth=570px;dialogHeight=453px;");
   return(false)
}

function editAccount(UserID)
{ if (trim(UserID)=="")
   alert("用户ID号错误!");
  else
   switch(UserID.charAt(0))
     {
      case "E":
          showDialog("教职工用户设置","/School/System/Employee/Edit.asp?UserID="+UserID,"","dialogWidth=620px;dialogHeight=430px;dialogTop=50px");
          break;
      case "S":
         showDialog("学生用户账号设置","/School/System/Student/Edit.asp?UserID="+UserID,"","dialogWidth=620px;dialogHeight=430px;dialogTop=50px");
         break;
      case "M":
         showDialog("教育局用户设置","/Ministry/System/Employee/Edit.asp?UserID="+UserID,"","dialogWidth=620px;dialogHeight=430px;dialogTop=50px");
          break;
      case "P":
          showDialog("家长用户账号设置","/School/System/Paterfamilias/Edit.asp?UserID="+UserID,"","dialogWidth=620px;dialogHeight=430px;dialogTop=50px");
          break;
      default:
          alert("非本校合法用户不能查看其信息!");           
     }
   return(false);
}

function editEmployee(EmployeeID)
{
 showDialog("教职工档案信息","/School/Employee/basic/Edit.asp?EmployeeID="+EmployeeID,"_blank","dialogTop=0px;dialogWidth=720px;dialogHeight=540px")
 return(false)
}

function editStudent(StudentID)
{
 showDialog("学生档案信息",'/School/Student/basic/Edit.asp?StudentID='+StudentID,'_blank',"dialogTop=30px;dialogWidth=735px;dialogHeight=460px");
 return(false);
}

function editPaterfamilias(ID)
{
 showDialog("学生家长信息",'/School/Student/Family/Edit.asp?ID='+ID,'',"dialogTop=30px;dialogWidth=420px;dialogHeight=350px");
 return(false);
}

function editMinistry(EmployeeID)
{
 showDialog("职工档案信息","/Ministry/Employee/basic/Edit.asp?EmployeeID="+EmployeeID,"_blank","dialogTop=0px;dialogWidth=720px;dialogHeight=540px")
 return(false);
}

function loadMain(content,main)
{
 window.parent.frames[1].location=content;
 window.parent.frames[2].location=main;
 
}
function previewURL(theElement)
{ var s=trim(theElement.value);
  s=s.toLowerCase();
  if(s.indexOf("http://")!=0 || s.length<8) 
    { alert("网址为空或者没有包函“http://”说明!")
      if(!theElement.disabled && theElement.visabled)
      {  theElement.select();
         theElement.focus();
      }   
     }
  else
     window.open(s);     
} 

function previewEmail(theElement)
{ 
  var s=trim(theElement.value);
  if(!isEmail(s)) 
    { alert("Email地址不合法，不能发信!")
       if(!theElement.disabled)
       {theElement.select();theElement.focus();}
     }
  else
     window.open("mailto:"+s);     
}


//上载文件
//CurFileURL:当前上载的文件FileURL
//FileFormat:文件的类别，如"Jpg;gif"(多种类别时,请用;分开)
//FileSize:文件最大大小（以K为单)
//PathFile:上载的文件路径及文件名（无扩展名)
//Method:处理的方法
//        ="post" 转交
//         ToString:上载成功后的处理页面Post到ToString文件中
//　　　   注意：处理页面将会自动加上
//              FileURL=上载后的文件URL
//              FileSize=文件的实际大小
//              FileFormat=文件在类别（扩展名)
//              Title=对文件的描述
//        ="js"
//          将结果按伪JS代码形式写入ToString中
//              {%=FileURL%}=上载后的文件URL
//              {%=FileSize%}=文
//              {%=FileFormat%}=文件在类别（扩展名)
//              {%=Title%}=对文件的描述
//        =其它
//           　 直接将上载后的FileURL写入ToString定义的某个域中
function uploadAttach(ProcessString,Method,PubPers)
{
 if (typeof(ProcessType)=='undefined') ProcessType="";
 if (typeof(PubPers)=='undefined') PubPers="Pub";
 switch(PubPers)
 { case "Pub":
		showDialog("校园公共素材上载","/School/Info/PubFiles/Edit.asp?ProcessString=" + escape(ProcessString) +"&Method=" + Method,"","dialogLeft=90px;dialogTop=50px;dialogWidth=620px;dialogHeight=400px");
		break;
   case "Pers":
	   showDialog("个人素材上载","/school/OA/Person_Affair/PersFiles/Edit.asp?ProcessString=" + escape(ProcessString) +"&Method=" + Method,"","dialogLeft=90px;dialogTop=50px;dialogWidth=620px;dialogHeight=400px");
	   break;
   case "mPub":
	   	showDialog("教育局公共素材上载","/Ministry/Info/PubFiles/Edit.asp?ProcessString=" + escape(ProcessString) +"&Method=" + Method,"","dialogLeft=90px;dialogTop=50px;dialogWidth=620px;dialogHeight=400px");
		break;
	case "mPers":
		 showDialog("教育局个人素材上载","/Ministry/OA/Person_Affair/PersFiles/Edit.asp?ProcessString=" + escape(ProcessString) +"&Method=" + Method,"","dialogLeft=90px;dialogTop=50px;dialogWidth=620px;dialogHeight=400px");
	     break;
  }	     
 return(false);
}

function setNullIPhoto(imgName,textName)
{
 if(window.confirm ("您真想将该图片置空？"))
  {
    imgName.src=nullPhoto;
    textName.value=nullPhoto;
  }
}


//显示管理附件
function showAdminAttach(IFrameName,attachXML,Title,Width,Height,isEdit,PubPers)
{
if (typeof(PubPers)=='undefined') PubPers="Pub";
document.write("<iframe ID="+ IFrameName+" frameborder=0 border=0 width="+Width+" Height="+ Height+ " scrolling=no src=/Lib/adminAttach/default.asp?"+
"Title="+escape(Title)+
"&Width="+Width+
"&Height="+Height+
"&attachXML="+escape(attachXML)+
"&isEdit=" +isEdit+
"&PubPers=" +PubPers+
"></iframe>");
}

function toHTML(s)
{
 s=Replace(s,"&","&amp;")
 s=Replace(s,"<","&lt;")
 s=Replace(s,">","&gt;")
 s=Replace(s,'"',"&quot;")
 s=Replace(s,"'","&apos;")
 return(s);
}
function getAttach(IFrameName)
{
 var s="";
 var e=eval("document.frames['"+IFrameName+"'].listFile.options");
 if(e.length>0)
  {s="<sFile>";
   for(var i=0;i<e.length;i++)
     s+="<File title=\""+toHTML(e[i].text)+"\">"+e[i].value+"</File>";
   s+="</sFile>";
  } 
 return(s); 
}

//查看源文件
function viewCode()
{
  window.location = "view-source:" + window.location.href;
}
  

function N2(n) 
{
  return( n<10? "0"+n:n+"");
}

function Add2AtLine(s)
{
 var t=s.split("\n");
 var ns="";
 var n=t.length;
 for(i=0;i<n;i++)
   { s=trim(t[i]);
     if(t[i]!="")
         ns=ns+"　　"+trim(t[i])+(i<n-1?"\n":"");
     else
         ns=ns+(i<n-1?"\n":"");
   }         
 return(ns);
}

//将对象objElement前面加两个空格

function splitLine(objElement)
{objElement.value=Add2AtLine(objElement.value);
 return(false);
}

function trim(s)
{	 var i,r,j
	 var n=s.length 
	 for(i=0;i<n;i++)
	   { t=s.charAt(i)
	     if(t!=" " && t!='　') break;
	    } 
	 if(i==n) return("");
	 for(j=n-1;j>=0;j--)
	   { t=s.charAt(j)
	     if(t!=" " && t!='　') break;
	   }  
	 r=s.substring(i,j+1);
	 return(r);
}

function isOK(s)
{var n,i;
 var c;
 n=s.length;
 for(i=0;i<n;i++)
 { c=s.charAt(i);
 if(!(c>='a' && c<='z' || c>='A' && c<='Z' || c>='0' && c<='9' || c=='_'))
 return(false);
 }
 if(n>=4) 
   return(true); 
 else
   return(false);
}

function isEmail(s)
 {  var n,i,ErrorChar ,j;
	ErrorChar=" ~!`#$%^&*()+=?<>,{}[]\\/|'\"";
	n=s.length;
	if(n<5) return(false);
	for(i=0;i<n;i++)
	for(j=0;j<ErrorChar.length;j++)
	if(s.indexOf(ErrorChar.charAt(j))>=0) return(0);
	if(s.indexOf(".")<0||s.indexOf("@")<0 || s.charAt(0)=="@" || s.charAt(n-1)==".")
	  return(false);
	else
	  return(true);
 }
 
 function Bookmarkit()
{
  window.external.addFavorite('http://cn.icchina.com','ICChina.com');
}

function random(n)
{
 return(Math.floor(Math.random()*n));
}

function Today()
{
	var today = new Date();
	var centry ;
	var s=new Array("日","一","二","三","四","五","六");
	centry="";
	if(today.getYear()<2000 ) centry = "19" ;
	date1 = centry + (today.getYear()) + "年" + (today.getMonth() + 1 ) + "月" + today.getDate() + "日" ;
	return(date1+"&nbsp;星期"+s[today.getDay()]);
}	


function isDate(y,m,d)
{
  var isLeap;
  y=y+'';
  m=m+'';
  d=d+'';
  
  if(isNaN(y)||isNaN(m)||isNaN(d))
     return(false);
  
  y=parseInt(y,10);
  m=parseInt(m,10);
  d=parseInt(d,10);
  
  if(y<1900 || y>2500 || m<1 || m> 12|| d<1 || d>31 || m==2 && d>29)
      return(false);
  
  isLeap=(y%4==0 && y%100!=0 || y%400==0);
  
  if(m==2 && !isLeap && m>28) retrun(false);
  if(m==2 && isLeap && m>29) return(false);
  
  if((m==4 || m==6 || m==9 || m==11) && d>30)
     return(false);
  else
	 return(true);
}

function isStrDate(s)
{
  s=trim(s);
  var t=s.split("-");
  if(t.length==3)
    return(isDate(t[0],t[1],t[2]));
  else
   { t=s.split(".");
     if(t.length==3)
       return(isDate(t[0],t[1],t[2]));
     else  
       return(false);  
    }   
}

function isYearMonth(y,m)
{
  y=y+'';
  m=m+'';
  if(isNaN(y)||isNaN(m))
     return(false);
  
  y=parseInt(y,10);
  m=parseInt(m,10);
  
  if(y<1900 || y>2500 || m<1 || m> 12)
      return(false);
  else
      return(true);    
}

function isStrYearMonth(s)
{
  s=trim(s);
  var t=s.split("-");
  var n=t.length;
  
  if(n==3)  return(isDate(t[0],t[1],t[2]));
  if(n==2)  return(isYearMonth(t[0],t[1]));
  
  t=s.split(".");
  n=t.length;
  
  if(n==3)  return(isDate(t[0],t[1],t[2]));
  if(n==2)  return(isYearMonth(t[0],t[1]));
  return(false);  
}

function Print()
{
  window.print();
  return(false);
}

function isTime(h,m,s)
{
 h=parseInt(h+'',10);
 m=parseInt(m+'',10);
 if(typeof(s)==undefined)
    return(h>=0 && h<24 && m>=0 && m<60)
 s=parseInt(m+'',10);
 return(h>=0 && h<24 && m>=0 && m<60 && s>=0 && s<60)
  
}

function isStrTime(s)
{
  s=trim(s);
  var t=s.split(":");
  var n=t.length;
  return(isTime(t[0],t[1],t[2]))
}

function isStrDateTime(s)
{
 s=Replace(trim(s+''),'  ',' ');
 var ts=s.split(" ");
 if (ts.length==1) 
	return(isStrDate(s));
 else
	return(isStrDate(ts[0]) && isStrTime(ts[1]))
}

function ShowSelectFor1A(s,Name,cv,w,Title)
{
  var aS=s.split("|")
  var n=aS.length;
  document.write("<select Name="+Name +" style='width:"+w+"'>");
  if(Title!="")
    document.write("<option value=''>"+Title+"</option>");
  for(var i=0;i<n;i++)
   { document.write("<option value="+aS[i]+ (aS[i]==cv?" selected":"")+">"+aS[i]+"</option>");
    }
  document.write("</select>");    
}

function SetHomePage(This)
{
  This.style.behavior='url(#default#homepage)';
  This.setHomePage('http://ibs.aixi.net/Edu50/');
  return(false);
}

//显示二维数组列表
//   s：数组名
//Name：Select Name名
// cv ：当前的值
// w　：当前的列表的宽度
// Title：第一项空白显示的标题，如"(选择民族)"  
// SplitChar：主类与子类的分隔符

function ShowSelectFor2A(s,Name,cv,w,Title,SplitChar)
{ var i,j,mItem,sItem;
  var ts,cC,mC;
  var n=s.length;
  if (typeof(SplitChar)=='undefined') SplitChar="";
  if (typeof(Title)=='undefined') Title="(选择?)";
  document.write("<select name=" + Name + " style='width:"+w+"'>");
  if(Title!="") document.write("<option value=''>"+Title+"</option>");
  for(i=0;i<n;i++)
   { ts=s[i].split(":")
     sItem=ts[1].split("|");
     document.write("<option value=" + ts[0] + (ts[0]==cv?" selected":"") + ">"+((i==n-1)?"└ ":"├ ") + ts[0]+"</option>");
     if(ts[1]!="")
     for(j=0;j<sItem.length;j++)
      { cC=ts[0]+ SplitChar+ sItem[j];
        ss=(i==(n-1)?"　":"│")+(j==(sItem.length-1)?"└ ":"├ ");
        document.write("<option value='"+cC + (cv==cC?"' selected":"'")+">" + ss + sItem[j]+"</option>");
      }
  }
  document.write("</select>");
}

function ShowGrade(Name,cv,w,Title)
{
 var s=new Array(
 "幼儿园:小班|中班|大班",
 "小学:一年级|二年级|三年级|四年级|五年级|六年级",
 "初中:一年级|二年级|三年级|四年级",
 "高中:一年级|二年级|三年级|四年级",
 "中专:一年级|二年级|三年级|四年级",
 "大学:一年级|二年级|三年级|四年级|五年级",
 "其它:");
 ShowSelectFor2A(s,Name,cv,w,Title);
}

function ShowProvince(Name,cv,w,Title) //显示省份名
{
  var Citys="北京|上海|重庆|天津|湖北|吉林|安徽|福建|甘肃|广西|浙江|江苏|江西|宁夏|贵州|海南|河北|云南|辽宁|内蒙古|青海|黑龙江|陕西|西藏|台湾|山东|山西|河南|湖南|广东|四川|新疆|香港|澳门|台湾";
  ShowSelectFor1A(Citys,Name,cv,w,Title)
}

function ShowNation(Name,cv,w,Title) //显示民民族
{
  var s="汉族|回族|藏族|维吾尔|蒙古族|苗族|彝族|壮族|布依族|朝鲜族|满族|侗族|瑶族|白族|土家族|哈尼族|哈萨克族|傣族|黎族|傈僳族|佤族|畲族|高山族|拉祜族|水族|东乡族|纳西族|景颇族|柯尔克孜族|土族|达斡尔族|仫佬族|羌族|布朗族|撒拉族|毛南族|仡佬族|锡伯族|阿昌族|普米族|塔吉克族|怒族|乌孜别克族|俄罗斯族|鄂温克族|德昂族|保安族|裕固族|京族|塔塔尔族|独龙族|鄂伦春族|赫哲族|门巴族|珞巴族|基诺族"
  ShowSelectFor1A(s,Name,cv,w,Title);
}

//'显示学历水平的Select
function ShowLevel(Name,cv,w,Title)
{
 var s="本科|专科|中专|高中|初中|小学|硕士|博士|博士后|文盲";
 ShowSelectFor1A(s,Name,cv,w,Title);
}

//显示上载文件的列表情况
//s : 文件列表情况
//    格式为
//    文件1的描述\t文件1URL\n
//    文件2的描述\t文件2URL\n
//    ...
//    文件n的描述\t文件nURL
//Name:select	列表名
//   w:宽度
//   h:高度
//返回：当前的文件个数
function showFileList(s,Name,w,h)
{ var n=0;
  if(typeof(h)=='undefined') h="20";
  var ts=s.split("\n");
  document.write("<select Name=" +Name+ " style='width:" +w+ ";height:" +h+"'>"); 
  for( var i=0;i<ts.length;i++)
    { if(ts[0]!="")
       { vf=ts[0].split("\t") //分解文件描述 文件URL
         if(vf.length=2 && vf[1]!="")
           {
            n++;
            if(vf[0]=="") vf[0]=vf[1]; //没有文件描述,则使用文件名作描述
            document.write("<option value='" + vf[1] +"'>"+vf[0]+"</option>");
           }
       }
   }    
  document.write("</select>");
}

//取得当前用户上载的文件列表信息,并将写入某个字段域中
function getFileList(objName,objTextName)
{
var s="";
objName=objName.options
for(var i=0;i<objName.length;i++)
   s+=objName[i].text+"\t"+objName[i].value+"\n";
 objTextName.value=s;
}

//取得主文件名
function getFileName(FileURL)
{
 var s=FileURL.split("/");
 if(s.length>0) 
    { ts=s[s.length-1].split(".")
      return(ts[0]);
    }
 else
    return("");     
}

function setClass(t,Type)
{
  t.className =Type;
}

function selectAll(theButton,theForm,checkName)
{ if(typeof(theButton)=="object")
     var s=theButton.checked;
  else
     s=theButton;
  for(i=0;i<theForm.elements.length;i++)
    { var e=theForm.elements[i];
      if(e.name==checkName && !e.disabled) e.checked=s;
    }  
}

function closeWindow()
{var e=document.getElementsByTagName("INPUT")
 for(i=0;i<e.length;i++)
   if(e[i].type=="submit" && !e[i].disabled)
    { if(window.confirm ("您确认放弃当前的编辑?"))
        this.close();
       return(false)
    }
this.close();       
}

//编辑个人资料分类
// Title: 分类说明，如个人Email、个人图库
//tableName:当前使用的表名
function persCategory(Title,tableName,spanName,PubPers)
{if(typeof(spanName)=="undefined") spanName="";
  if(typeof(PubPers)=="undefined") PubPers="Pers";
  if (PubPers!="mPers") PubPers="Pers";
  showDialog(Title+'分类管理',"/Lib/Category/default.asp?PubPers="+PubPers+"&Title="+escape(Title)+"&Kind="+tableName+"&spanName="+spanName,"", "dialogTop=20px;dialogWidth=430px;dialogHeight=390px;");
  return(false);
}

//用户选某个类别
function selectCategory(xmlDoc,selectName)
{
  showDialog("选择分类","/Lib/Category/Select.asp?xmlDoc="+xmlDoc+"&selectName="+selectName,"","dialogLeft=200px;dialogWidth=450px;dialogHeight=400px;dialogTop=100px;")
  return(false);
}  
//编辑学校公共资料分类
// Title: 分类说明，如校园新闻、校园设备
//tableName:当前使用的表名

function pubCategory(Title,tableName,spanName,PubPers)
{ if(typeof(spanName)=="undefined") spanName="";
  if(typeof(PubPers)=="undefined") PubPers="Pub";
  if (PubPers!="mPub") PubPers="Pub";
  showDialog(Title+'分类管理',"/Lib/Category/default.asp?PubPers="+PubPers+"&Title="+escape(Title)+"&Kind="+tableName+"&spanName="+spanName,"", "dialogTop=20px;dialogWidth=430px;dialogHeight=390px;");
  return(false);
}

function showCategorySelect(xmlDoc,Name,cv,w,Title)
{ var node;
  if(typeof(xmlDoc)=="string")
   {
     var fn=xmlDoc;
	 var xmlDoc=new ActiveXObject("Microsoft.XMLDOM")
	 xmlDoc.async = false;
     xmlDoc.load(fn);
   }
  if(xmlDoc!=null) 
     node=xmlDoc.selectSingleNode("/sCategory/Category");
  else
    node=null;  
  s="<select Name="+Name +" style='width:"+w+"'>";
  if(Title!="")
	s+="<option value=''>"+Title+"</option>";
  for(;node!=null;node=node.nextSibling)
    {
      Title=node.getAttribute("Title");
      Description=node.text;
      showChar=node.getAttribute("showChar");
      Category=node.getAttribute("Category");
      Catgeory=Category.replace("'","&apos;")
      Catgeory=Category.replace("\n","")
      s+="<option title='"+ Description +"' value='"+Category+"' "+(Category==cv?" selected":"")+">"+showChar+" "+ Title+"</option>";
    }
s+="</select>";
return(s);
}


function showHtmlEditor(idName,PubPers,initContentField,Width,Height)
{
document.write("<iframe ID=" +idName+ " frameborder=0 border=0 width='"+Width+"' Height='"+ Height+ "' scrolling='no' src=/Lib/htmlEditor/default.asp?"+
"PubPers="+escape(PubPers)+
"&initContentField=" +escape(initContentField)+
"&Width="+Width+
"&Height="+Height+
"></iframe>");
}

function setHtmlEditorStatus(idName,status)
{
 var e=window.frames[idName];
 e.document.setEditStatus(status);
}

function getHtmlEditorContent(idName)
{
 var e=eval("document.frames['"+idName+"'].document")
 var format=e.Editor.document.body.Format;
 if(format=="Html")
   return(e.Editor.document.body.innerText);
 else
   return(e.Editor.document.body.innerHTML); 
}

function setUpDownClass(elementName,className)
{ 
  elementName.className="d"+className;
  return(false);
 }

// Title: 对话框标题
// resultType:结果类别　
//   file或imgFile: 仅是文件/图片文件
//         返回：　file标题\n文件URL
//   link: 连接
//        返回当前的连接HTML代码
//  img :图片连接
//        返回当前的图片连接HTML代码
//　取消时，返回空字符串 

function openResource(Title,resultType,PubPers)
{
 if(typeof(PubPers)=="undefined") PubPers="Pub";
 switch(PubPers)
 { case "Pub":
		var fileName=window.showModalDialog("/School/Resource/selectOpen.asp?Title="+escape(Title)+"&resultType="+resultType,"","dialogHeight: 456px; dialogWidth: 725px; center: Yes; help: No; resizable: No; status: No; scrollbars :no");
		break;
   case "Pers":
		var fileName=window.showModalDialog("/School/OA/Person_Affair/Resource/selectOpen.asp?Title="+escape(Title)+"&resultType="+resultType,"","dialogHeight: 456px; dialogWidth: 725px; center: Yes; help: No; resizable: No; status: No; scrollbars :no");  
		break;
	case "mPub":
		var fileName=window.showModalDialog("/Ministry/Resource/selectOpen.asp?Title="+escape(Title)+"&resultType="+resultType,"","dialogHeight: 456px; dialogWidth: 725px; center: Yes; help: No; resizable: No; status: No; scrollbars :no");
		break;
	case "mPers":
		var fileName=window.showModalDialog("/Ministry/OA/Person_Affair/Resource/selectOpen.asp?Title="+escape(Title)+"&resultType="+resultType,"","dialogHeight: 456px; dialogWidth: 725px; center: Yes; help: No; resizable: No; status: No; scrollbars :no");  
		break;
 }		
 return(fileName)
}

//Title:对话框标题
//Kind:类别，可含如下字符：D 教育组(局)用户 E 学校教工 S 学生用户 P 家长
//isMuli:可否多选 true 可以　false 单选
//返回值:
//　确认时　
//　　　 用户名1\t用户1ID号\n
//       ......
//        用户名n\t用户nID号\n       
// 取消时: 空字符串

function openUser(Title,Kind,isMuli,userName,userStyle)
{
 var s=typeof(userName);
 if(s=="object")
    {s=""
     for(var i=0;i<userName.options.length;i++)
       s+=userName.options[i].text+"<"+ userName.options[i].value+">;"
     }
 else
   if(s=="string")
       s=userName;
   else
      s="";    
 if(typeof(userStyle)=="undefined")
     userStyle=0;
 else    
    if(userStyle!=1 && userStyle!=2) userStyle=0;
 var userList="";  
 switch(userStyle)
 {  case 0:   
       useList=window.showModalDialog("/School/selectUser/default.asp?Title="+escape(Title)+"&Kind="+Kind+"&isMuli="+isMuli+"&UserName="+escape(s),"","dialogHeight: 465px; dialogWidth: 725px; center: Yes; help: No; resizable: No; status: No; scrollbars :no");
       break;
    case 1:  
       useList=window.showModalDialog("/School/selectUser/defaultUser.asp?Title="+escape(Title)+"&Kind="+Kind+"&isMuli="+isMuli+"&UserName="+escape(s),"","dialogHeight: 465px; dialogWidth: 725px; center: Yes; help: No; resizable: No; status: No; scrollbars :no");
       break;
    default:
       useList=window.showModalDialog("/School/selectUser/defaultNoUser.asp?Title="+escape(Title)+"&Kind="+Kind+"&isMuli="+isMuli+"&UserName="+escape(s),"","dialogHeight: 465px; dialogWidth: 725px; center: Yes; help: No; resizable: No; status: No; scrollbars :no");
       break;
  }    
 return(useList);
}


 function showDepartment(ID,w,h,Kind,initValue)
 {
 document.write("<iframe ID=" +ID+ " frameborder=1 border=0 width='"+w+"' Height='"+ h+ "' scrolling=yes src=/School/selectUser/selectDepartment.asp?"+
"Kind="+escape(Kind)+
"&initValue=" +escape(initValue)+
"></iframe>");
 }
 
 function getDepartment(IDIFrame)
 {
 return(IDIFrame.getDepartment());
 }
 
 //禁止窗体内容进行编辑
 // theForm:需要禁止的窗体
 // elseElementNames:哪些元素除外
 function disabledForm(theForm,elseElementNames)
{
 elseElementNames=elseElementNames+"";
 if(elseElementNames=="undefined") elseElementNames="";
 
 elseElementNames=","+elseElementNames+",";
 
 var s="";
 for(var i=0;i< theForm.elements.length;i++)
   { 
	e=theForm.elements[i];
	if(elseElementNames.indexOf(","+e.name+",")==-1)
       {
        s+=e.tagName+","+e.type+"\n";
        switch(e.tagName)
        {
          case "INPUT":
                switch(e.type)
                  {
					case "text":
					      e.style.backgroundColor="#d0d0c8";
					      e.readOnly=true;
					      break;
					case "submit":
					case "reset":
					case "button":
					case "radio":
					case "checkbox":
					case "password":
					case "file":
					     e.disabled=true;
					     break;
                  } 
                 break; 
          case "SELECT":
			   e.style.backgroundColor="#d0d0c8";
               e.disabled=true;
               break;
          case "TEXTAREA":
               e.readOnly=true;
               e.style.backgroundColor="#d0d0c8";
               break;
        }
       }
   }
}

//-------------------------------------------------------------------------------
//
//
//             以下函数用于动态显示目录树
//　使用方法如下
//  <span ID=鼠标点击时的对象
//        type=""
//        src="目录树结构XML文件"
//        subDiv="将目录内容显示到那一层中"
//        onclick="expandMe(this.ID)" 
//        imgClose="收缩时时的显示内容, 空时为默认"
//        imgOpen="展开时的显示同图片内容,空时为默认" 
//        curImgSpan="表示展开或者收缩的内容" 
//        preChar="每一项前面欲加的字符"
//        target="目录地址"
//        href="用户点击目录的某一项后的连接地址"
//    >...</span>
//       <span ID="表示展开或者收缩的内容">...</span>
//  <div ID=欲显示的子目录内容></div>
//
//
//---------------------------------------------------------------------------------
var constSpaceChar="　"; //空白字符
var constMidChar="├";
var constEndChar="└";
var constLineChar="│";
var constSplitChar=":";

var curDivLeftName;
var imgLineChar="<IMG border=0 class=wh16 SRC=/images/System/TreeH.gif>";
var imgSpaceChar="<IMG border=0 class=wh16 SRC=/images/System/TreeSpace.gif>";
var imgItemChar="<IMG border=0 class=wh16 SRC=/images/System/treeClose.gif>";
var imgOpenChar="<IMG border=0 class=wh16 SRC=/images/System/treeOpen.gif>";
var imgCloseChar="<IMG border=0 class=wh16 SRC=/images/System/treeClose.gif>";
var imgPlusChar="<IMG border=0 class=wh16 SRC=/images/System/treePlus.gif>";
var imgSubChar="<IMG border=0 class=wh16 SRC=/images/System/treeSub.gif>";

var imgEndChar="<IMG border=0 class=wh16 SRC=/images/System/tree1_.gif>";
var imgMidChar="<IMG border=0 class=wh16 SRC=/images/System/tree1-.gif>";

function imgSubMidChar(divName)
{ 
  return("<span onclick=expandTree(this,'"+divName+"') style='cursor:hand' type=sub>"+imgSubChar+imgOpenChar+"</span>");
}

function imgPlusMidChar(divName)
{
  return("<span onclick=expandTree(this,'"+divName+"') style='cursor:hand' type=plus>"+imgPlusChar+imgCloseChar+"</span>");
}


function expandTree(theElement,divName)
{
 divE=eval(divName);
 if(theElement.type=="sub")
   {theElement.type="plus";
    theElement.innerHTML=imgPlusMidChar(divName);
    divE.style.display="none";
   }
 else
  {theElement.type="sub";
   theElement.innerHTML=imgSubMidChar(divName);
   divE.style.display="";
  }   
window.event.returnValue=false;
window.event.cancelBubble=true; 
}


function expandMe(curSpan)
{
 var objCurSpan=eval(curSpan);
 var s=showTree(curSpan,objCurSpan.src,objCurSpan.preChar,objCurSpan.href,objCurSpan.target,objCurSpan.isCheck,objCurSpan.initValue);
 if(s=="")
    if(objCurSpan.isEnd=="true")
      objCurSpan.innerHTML=imgEndChar;
    else
      objCurSpan.innerHTML=imgMidChar; 
        
 else
   { var objSubDiv=eval(objCurSpan.subDiv)
     objSubDiv.innerHTML=s;
     plussubNode(curSpan);
   } 
window.event.returnValue=false;
window.event.cancelBubble=true;        
}

//对格式为<span ID="" preChar="" curImgSpan="" subDiv="" imgOpen="" imgClose=""></span>进行展开或者收缩操作
//
function plussubNode(curSpan)
{
  var objCurSpan=eval(curSpan);
  var objCurImgSpan=eval(objCurSpan.curImgSpan);
  var imgClose=objCurSpan.imgClose+"";
  var objSubDiv=eval(objCurSpan.subDiv);
  
  if(imgClose=="" ||imgClose=="undefined") 
     imgClose=imgCloseChar;

  var imgOpen=objCurSpan.imgOpen+"";
  if(imgOpen=="" ||imgOpen=="undefined") 
     imgOpen=imgOpenChar;
  
  
 if(objCurSpan.type=="plus")
    {  objCurSpan.innerHTML="<a href=# onclick=return(plussubNode('" +curSpan+ "'))>"+imgPlusChar+"</a>";
       objCurImgSpan.innerHTML=imgClose;
       objCurSpan.type="sub";
       objSubDiv.style.display="none";
    }
 else
   { objCurImgSpan.innerHTML=imgOpen;
     objCurSpan.type="plus";
     objCurSpan.innerHTML="<a href=# onclick=return(plussubNode('" +curSpan+ "'))>"+imgSubChar+"</a>";
     objSubDiv.style.display="";
   
   }   
}

function Tree_getSubItem(ID,isEnd,preChar,src,imgOpen,imgClose,subHref,curHref,target)
{
if(imgOpen==null || imgOpen=='') 
	imgOpen="/images/System/treeOpen.gif";
if(imgClose==null || imgClose=='')
	imgClose="/images/System/treeClose.gif";
imgOpen="<img border=0 class=wh16 src="+imgOpen+">"
imgClose="<img border=0 class=wh16 src="+imgClose+">"
var s='<span nowrap ID="spanTreeSubItem'+ID+'" '+
	' type=""'+
	' isEnd='+isEnd+
	' onclick=expandMe(\'spanTreeSubItem' +ID+ '\')'+
	' subDiv=div_Tree_' +ID +
	' src='+src+
	' curImgSpan=imgID_'+ID+
	' preChar="'+preChar+'"'+
	' target="'+target+'" '+
	' href="'+subHref+'"'+
	' style="cursor:hand"'+
	' imgOpen="'+imgOpen+'"'+
	' imgClose="'+imgClose+'"'+
    ' ><img src=/images/System/treePlus.gif class=wh16 border=0></span><span ID=imgID_'+ID+'>'+imgClose+'</span></td><td nowrap>'+curHref+'</td></tr></table>'+
    '<span height=0 ID="div_Tree_'+ID+'"></span>';
return(s)
}

function showCategoryTitle(xmlDoc,spanName)
{
  if(typeof(xmlDoc)=="string")
   {
	var fn=xmlDoc;
	xmlDoc = new ActiveXObject( "Microsoft.XMLDOM" );
	xmlDoc.async = false;
	xmlDoc.load(fn);
	}
  
  if(xmlDoc==null) return;
  var e=document.getElementsByTagName("SPAN");
  for(var i=0;i<e.length;i++)
    {
     if(e[i].id==spanName)
	  {
	  s=e[i].innerText;	
	  var node=xmlDoc.selectSingleNode("/sCategory/Category[@Category='"+s+"']");
      if(node!=null)
         e[i].innerText=node.getAttribute("Title");
       }  
    }
}

function showTree(IDName,xmlDoc,preChar,href,target,isCheck,initValue)
{   curDivLeftName=IDName+"_treeItem_";
    var curCheckName="chkName_"+IDName;
    var isAdd=true;
	var s="",ts="";
	var oldLevel=0;
	var showStr="";
	if(typeof(initValue)=="undefined") initValue="";
	if(isCheck!="true") 
	   isCheck=false;
	else
	   isCheck=true;   
	
	initValue=","+initValue+",";
	if(typeof(xmlDoc)=="string")
   {
	var fn=xmlDoc;
	xmlDoc = new ActiveXObject( "Microsoft.XMLDOM" );
	xmlDoc.async = false;
	xmlDoc.load(fn);
	}

  if(xmlDoc!=null) 
     node=xmlDoc.selectSingleNode("/sCategory/Category");
  else
    node=null;
  
  var n=0;
  var nn=0;
  for(;node!=null;node=node.nextSibling,nn++)
	    { text=node.text;
	      text=text.replace("\n","");
	      tc=node.getAttribute("Category");
	      Href			=node.getAttribute("Href");	 
		  if(Href==null|| Href=="")   Href=href;
		          
	      if(isCheck)
	        tHref="<input onclick='clickTreeForCheck(this)' type=checkbox name='"+curCheckName+"' value='"+tc+(initValue.indexOf(","+tc+",")>=0?"' checked ":"'")+"><a title='"+text+"'>"+node.getAttribute("Title")+"</a>";
	      else  
	      {  sHref=Replace(Href,"{%=Category%}",tc);
	         tHref="&nbsp;<a class=L9 href="+sHref+tc+
	             " Title='"+text+"' "+
	             " target="+target+">"+
	             node.getAttribute("Title")+
	             "</a>";
	      }       
          showChar		=node.getAttribute("showChar");
	      hasLeaf		=node.getAttribute("hasLeaf");
	      curLevel		=node.getAttribute("Level");
		  subXMLFile	=node.getAttribute("subXMLFile");
		  if(subXMLFile ==null) 
			 subXMLFile="";
		  
		  subHref		=node.getAttribute("subHref");
		  subImgClose	=node.getAttribute("subImgClose");
		  if(subImgClose==null) subImgClose=""
		  subImgOpen	=node.getAttribute("subImgOpen");
		  if(subImgOpen==null) subImgOpen=""
		  curLevel		=parseInt(curLevel,10);
	      if(curLevel>oldLevel) 
	         t="<span style='display:none' ID="+curDivLeftName+(n++)+"><table  cellspacing=0 cellpadding=0 border=0><tr><td nowrap>";
	      else
	         { t="";
	           for(i=curLevel-oldLevel;i<0;i++)
	               t+="</span>";
			   t+="<table cellspacing=0 cellpadding=0 height=16 border=0><tr><td nowrap>";     
	          }
	      t+=preChar;
	      isAdd=true;
	      for(var i=0;i<showChar.length;i++)
	        { c=showChar.charAt(i);
	          switch(c)
	           { case constSpaceChar:
	                  t+=imgSpaceChar;
	                  break;
	                  
	             case constLineChar:
	                  t+=imgLineChar;
	                  break;
	                  
	             case constMidChar:
	                  if(hasLeaf=="1")
	                    t+=imgPlusMidChar(curDivLeftName+n);
	                  else
	                   { if(subXMLFile=='')
	                       if(subImgClose=="")
		                      t+=imgMidChar+imgItemChar;
		                   else
		                      t+=imgMidChar+"<img border=0 class=wh16 src="+subImgClose+">";
		                 else
		                   { t+=Tree_getSubItem(IDName+nn,'false',preChar+imgLineChar,subXMLFile,subImgOpen,subImgClose,subHref,tHref,target)   
		                     isAdd=false
		                   }
		               }     
	                  break;
	                  
	             case constEndChar:
	                  if(hasLeaf=="1")
	                    t+=imgPlusMidChar(curDivLeftName+n);
	                  else
	                    {
	                    if(subXMLFile=='')
							if(subImgClose=="")
	                          t+=imgEndChar+imgItemChar;
	                        else
	                          t+=imgEndChar+"<img border=0 class=wh16 src="+subImgClose+">"; 
		                else
		                    {  t+=Tree_getSubItem(IDName+nn,'true',preChar+"&lt;img class=wh16 src=/images/16x16/16x16.gif&gt;",subXMLFile,subImgOpen,subImgClose,subHref,tHref,target)
		                       isAdd=false   
		                     }
	                    }
					 break;
	            }
	         }
	    if(isAdd) t+="</td><td nowrap>"+tHref+"</td></tr></table>";
	    showStr+=t;
	    oldLevel=curLevel;
	    }
for(i=0;i<oldLevel;i++)
	showStr+="</span>";	    
return(showStr);
}
function Replace(s,s1,s2)
{
 while(s.indexOf(s1)>=0)
    s=s.replace(s1,s2);
 return(s);   
}

function clickTreeForCheck(theE)
{
 var e=document.getElementsByName(theE.name);
 for(var i=0;i<e.length;i++)
    { 
     var s=e[i].value;
     if(s.indexOf(theE.value+"/")==0)
        e[i].checked=theE.checked;
    }
}

//----------------------------------------------
//      File Funtion
//-----------------------------------------------
function getFileExt(s)
{
 var t=s.split("/");
 if(t.length>0)
    { t=t[t.length-1].split(".");
      if(t.length>1)
         return(t[t.length-1]);
      else
         return("");
    }
 else
   return("");
}

function getFileName(s)
{
 var t=s.split("/");
 if(t.length>0)
    { t=t[t.length-1].split(".");
      if(t.length>0)
         return(t[0]);
      else
         return("");
    }
 else
   return("");
}


function processShowTitle(Name)
{
var e=document.getElementsByName(Name);
for(var i=0;i<e.length;i++)
   if(e[i].tagName=="INPUT")
     e[i].title=e[i].value;
   else
     if(e[i].tagName=="A")  
       e[i].title=e[i].outerText;
       
}

function getHexValue(s)
{
 if(s>="a" && s<="f")
     return(s.charCodeAt(0)-"a".charCodeAt(0)+10)
 else
   if(s>="A" && s<="F")      
      return(s.charCodeAt(0)-"A".charCodeAt(0)+10)
   else
     if(s>="0" && s<="9")      
        return(s.charCodeAt(0)-"0".charCodeAt(0))
     else
        return(-1);
}

function getColorValue(s)
{
 if(s.length!=7)  return(-1);
 if(s.substr(0,1)!="#") return(-1);
 s=s.toLowerCase();
 for(var i=1;i<7;i++)
   { c=s.substr(i,1) 
     if(!(c>="0" && c<="9" || c>="a" && c<="f"))
        return(-1)
   }

 var r=getHexValue(s.charAt(1))*16+getHexValue(s.charAt(2))  
 r=r*256+getHexValue(s.charAt(3))*16+getHexValue(s.charAt(4)) 
 r=r*256+getHexValue(s.charAt(5))*16+getHexValue(s.charAt(6))
 return(r)
}

function GetAttachFile(xmlDoc)
{
  var node=xmlDoc.selectSingleNode("/sFile/File");
  for(;node!=null;node=node.nextSibling)
  {
    title=node.getAttribute("title");
    LinkHref=node.text;
    document.write("<a href="+LinkHref+" target=_blank>"+title+"</a><br>");
  }
}

function BreakItUp(thisobj,thisform)
{
	//Set the limit for field size.
	var FormLimit = 51100

	//Get the value of the large input object.
	var TempVar = new String
	TempVar = thisobj.value

	//If the length of the object is greater than the limit, break it
	//into multiple objects.
	if (TempVar.length > FormLimit)
	{
		thisobj.value = TempVar.substr(0, FormLimit)
		TempVar = TempVar.substr(FormLimit)

		while (TempVar.length > 0)
		{
			var objTEXTAREA = document.createElement("TEXTAREA")
			objTEXTAREA.name = "Description"
			objTEXTAREA.value = TempVar.substr(0, FormLimit)
			thisform.appendChild(objTEXTAREA)

			TempVar = TempVar.substr(FormLimit)
		}
	}
}
