var RESET_PWD="666666";
var BTN_DIV_MARGIN_WIDTH = 10;
var DIV_BTN_HEIGHT = 50;
var DIV_BTN_WIDTH = 70;
var state=false;
function setTitle() {
//top.document.title = document.title;
}
//页面跳转共通方法
function Go(url, name){
var form = document.getElementById("JumpForm");
form.action=url;
form.target=name;
form.submit();
}
setTitle();
//全选/取消
//checkAll(comId,flag)
// comId 代表控件的名称
// flag 调用方法一时1为全选状态0为取消状态;调用方法checkAll("checkbox1","1")
// 调用方法二时 flag 没有用处
function checkAll(comId,flag)
{
var blnFlag=false;
var a=document.getElementsByName(comId);
var n=a.length;
if(flag=='1'||flag=='0'){
if(flag=='1'){
blnFlag=true;
}
if(n>0){
for(var i=0;i<n;i++){
a[i].checked=blnFlag;
}
}
}else{
//var b=document.getElementsByName(flag);
if(n>0){
for(var i=0;i<n;i++){
a[i].checked=window.event.srcElement.checked;
}
}
}
}
//加载IE打印组件
//loadWebBrowser();
//打印预览函数
// strType 操作类型,6是打印,7是打印预览,8是打印页面设置
// strIds 要隐藏或显示的页面ID字符串,其ID之间以","分割
function btPrint(strType,strIds){
//Web.ExecWB(4,1) 保存网页
//wb.ExecWB(6,1) 打印
//wb.ExecWB(7,1) 打印预览
//wb.ExecWB(8,1) 打印页面设置
//wb.ExecWB(10,1) 查看页面属性
//wb.ExecWB(15,1) 好像是撤销,有待确认
//wb.ExecWB(17,1) 全选
//wb.ExecWB(22,1) 刷新
//wb.ExecWB(45,1) 关闭窗体无提示
//显示页面元素
idDisplay("none",strIds)
wb.ExecWB(strType,1);
//显示页面元素
idDisplay("block",strIds)
}
//将ID隐藏显示
function idDisplay(strStyleType,strIds){
if(strIds!=""){
var strIdAarry=strIds.split(",");
for(var i=0;i<strIdAarry.length;i++){
var strId=document.all(strIdAarry[i]);
strId.style.display=strStyleType;
}
}
}
//加载IE打印组件
function loadWebBrowser(){
var wbId= '<OBJECT ID=\"wb\" name=\"wb\" WIDTH=0 HEIGHT=0 CLASSID=\"CLSID:8856F961-340A-11D0-A96B-00C04FD705A2\"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd',wbId);
}
//××××××××××级联地址框提示处理××××××××××××××
//定义 select 原值
//var oldValue,oldText,
var oldSelectedIndex;
//select下拉框的onkeydown事件,修改下拉框的值
function catch_keydown(sel)
{
switch(event.keyCode)
{
case 13: //回车键
event.returnValue = false;
break;
case 27: //Esc键
//sel.options[sel.selectedIndex].text = oldText;
//sel.options[sel.selectedIndex].value = oldValue;
sel.selectedIndex = oldSelectedIndex;
event.returnValue = false;
break;
case 8: //空格健
var s = sel.options[sel.selectedIndex].text;
s = s.substr(0,s.length-1);
if (sel.options[sel.selectedIndex].value==sel.options[sel.selectedIndex].text)
{
sel.options[sel.selectedIndex].value=s;
sel.options[sel.selectedIndex].text=s;
}
event.returnValue = false;
break;
}
if (!event.returnValue && sel.onchange)
sel.onchange(sel)
}
//select下拉框的onkeypress事件,修改下拉框的值
function catch_press(sel){
if(sel.selectedIndex>=0){
var s = sel.options[sel.selectedIndex].text + String.fromCharCode(event.keyCode);
if (sel.options[sel.selectedIndex].value==sel.options[sel.selectedIndex].text)
{
sel.options[sel.selectedIndex].value=s;
sel.options[sel.selectedIndex].text=s;
}
event.returnValue = false;
if (!event.returnValue && sel.onchange)
sel.onchange(sel)
}
}
//select下拉框的onfocus事件,保存下拉框原来的值
function catch_focus(sel) {
// oldText = sel.options[sel.selectedIndex].text;
// oldValue = sel.options[sel.selectedIndex].value;
oldSelectedIndex = sel.selectedIndex;
}
//恢复select下拉列表当前选中的值
function LoadSelect(obj,value)
{
for (var i=0; i< obj.options.length; i++)
if (obj.options[i].value == value)
{
obj.selectedIndex = i;
break;
}
}
function adjustDivPos(div) {
with(div) {
style.display = "";
style.left = document.body.scrollLeft+event.clientX + 16;
style.top = document.body.scrollTop +event.clientY;
}
//document.body.scrollIntoView=document.body.scrollTop +event.clientY;
}
//select 选择框鼠标上移时提示选择的内容
function selMouseOver(obj)
{
state=!state;
var DivRef = document.getElementById('div_hint');
var IfrRef = document.getElementById('DivShim');
if(IfrRef==null){
IfrRef = document.createElement('iframe');
IfrRef.style.display = "none";
IfrRef.style.position = "absolute";
IfrRef.setAttribute('id','DivShim');
document.body.appendChild(IfrRef);
}
if(state)
{
with (DivRef)
{
innerText = obj.options[obj.selectedIndex].text;
if (innerText.length > 0)
{
innerText = " " + innerText + " ";
style.display = "block";
style.left = document.body.scrollLeft+event.clientX + 16;
style.top = document.body.scrollTop +event.clientY;
}
}
DivRef.style.display = "block";
IfrRef.style.width = DivRef.offsetWidth;
IfrRef.style.height = DivRef.offsetHeight;
IfrRef.style.top = DivRef.style.top;
IfrRef.style.left = DivRef.style.left;
IfrRef.style.zIndex = DivRef.style.zIndex - 1;
IfrRef.style.display = "block";
}
}
//select 选择框鼠标移开时消失
function selMouseOut(obj)
{
document.getElementById('div_hint').style.display = "none";
document.getElementById('DivShim').style.display = "none";
}
//初始化页面BtnDiv
function initBtnDiv(div, btnNum) {
div.style.display = "none";
adjustDivWidth(div,btnNum);
}
//根据Div内的内容调整显示宽度
function adjustDivWidth(div, btnNum) {
var NoneDispBtnNum = 0;
var buttons = div.getElementsByTagName("input");
for (i=0;i<buttons.length;i++) {
if (buttons[i].style.display == "none" && buttons[i].type == "button") {
NoneDispBtnNum = NoneDispBtnNum + 1;
}
}
var divWidth = div.style.width;
var width = divWidth.substr(0, divWidth.length-2);
//div.style.width = width - (parseInt(div.style.width) - BTN_DIV_MARGIN_WIDTH * 2) / btnNum * NoneDispBtnNum;
div.style.width = (btnNum - NoneDispBtnNum) * DIV_BTN_WIDTH + BTN_DIV_MARGIN_WIDTH * 2;
div.style.height = DIV_BTN_HEIGHT;
}
//返回年龄段OPTION
function getOptions(strBari){
var strValue="";
var strLable="";
if(strBari==""){
document.write("<option selected value=''>----</option>");
}else{
document.write("<option value=''>----</option>");
}
if(strBari=='0-1'){
document.write("<option selected value='0-1'>0~1</option>");
}else{
document.write("<option value='0-1'>0~1</option>");
}
if(strBari=='1-5'){
document.write("<option selected value='1-5'>1~5</option>");
}else{
document.write("<option value='1-5'>1~5</option>");
}
for(var i=1;i<=16;i++){
strValue=i*5+"-"+(i+1)*5;
strLable=i*5+"~"+(i+1)*5;
if(i==16){
if(strBari=="80"){
document.write("<option selected value='80'>80以上</option>");
}else{
document.write("<option value='80'>80以上</option>");
}
}else{
if(strBari==strValue){
document.write("<option selected value='"+strValue+"'>"+strLable+"</option>");
}else{
document.write("<option value='"+strValue+"'>"+strLable+"</option>");
}
}
}
}
//显示生成的层及IFROM
//strModle="" OR "1" 是数据查询
//strModle="2" 是报表
function Fun_showSearch(strModle){
var strType="1";
if(strModle=="undefined"||strModle==""){
}else{
strType=strModle;
}
// 生成DIV
var s=window.document.createElement("DIV");
s.id="divFrm";
s.name="divFrm";
s.style.position="absolute";
s.style.left=(window.screen.width-600)/2+"px" ;
s.style.top=(window.screen.height)/2+15+"px";
s.style.width="300px";
s.style.height="40px";
s.style.border="black 0px solid";
//s.style.backgroundColor="red";
s.style.zIndex=10000;
// 生成iframe
var f=document.createElement("IFRAME");
f.name="frmDiv";
f.id="frmDiv";
f.width=s.style.width;
f.height=s.style.height;
f.scrolling="no";
f.frameBorder=0;
f.style.zIndex=s.style.zIndex-1;
f.src="javascript:false;";
// 附加f到s
s.appendChild(f);
// 显示s
document.body.appendChild(s);
// 创建层
var t=document.createElement("DIV");
t.name="divShowFind";
t.id="divShowFind";
t.style.visibility="visible";
t.style.position="absolute";
t.style.left=s.style.left;
t.style.top=s.style.top;
t.style.width=s.style.width;
t.style.height=s.style.height;
t.style.border="solid 1px #FF5706";
//t.style.backgroundColor="blue";
t.style.zIndex=s.style.zIndex+1;
var strMsgTxt="系统提示:数据正在请求之中,请稍侯";
if(strType=="1"){
strMsgTxt="系统提示:数据正在查询之中,请稍侯";
}else if(strType=="2"){
strMsgTxt="系统提示:数据正在上传之中,请稍侯";
}else if(strType=="3"){
strMsgTxt="系统提示:数据正在生成之中,请稍侯";
}else{
strMsgTxt="系统提示:数据正在请求之中,请稍侯";
}
// 定义要显示的内容
var tableTxt="<table width=\"100%\" height=\"100%\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#ffffff\">"
tableTxt=tableTxt+"<tr><td align=\"center\" style=\"color:red;font-size:9pt\">"
tableTxt=tableTxt+strMsgTxt+"<img src='/jxhealth/image/waiting.gif' onerror=\"if (!this.times){this.times=1;};if (this.times<=10){src='/jxhealth/image/waiting.gif';this.times++}else{}\">";
tableTxt=tableTxt+"</td>";
//tableTxt=tableTxt+"<td width=15 align=\"center\" style=\"color:red;font-size:9pt\"><font style='cursor:hand' onclick='closeDiv()'>×</font></td>";
tableTxt=tableTxt+"</tr></table>";
t.innerHTML =tableTxt;
// 显示层
document.body.appendChild(t);
// 循环将按钮置为不可用
var a = document.all;
for(var i=0; i<a.length; i++){
if(a[i].type=="button"||a[i].type=="reset"){
a[i].disabled=true;
}
}
}
//关闭层
function closeDiv(){
var objDiv1=document.getElementById('divFrm');
objDiv1.removeNode(true);
var objDiv2=document.getElementById('divShowFind');
objDiv2.removeNode(true);
var a = document.all;
for(var i=0; i<a.length; i++){
if(a[i].type=="button"||a[i].type=="reset"){
a[i].disabled=false;
}
}
}
//按钮变灰
function buttonDisabled(){
var a = document.all;
for(var i=0; i<a.length; i++){
if(a[i].type=="button"||a[i].type=="reset"){
a[i].disabled=true;
}
}
}
//键盘回车事件转化为tab事件
//text中的Readonly不进入焦点
//radio中的checked=false不进入焦点
function movetoNext(){
if(event.keyCode==13){//当按回车的时候
try{
if(document.activeElement.type=="textarea"){//当运到是textarea时不跳到下一个组件
if(document.activeElement.readOnly==true){//只读的话就跳下去
event.keyCode=9;
}
return true;
}else{
if (event.srcElement.type == "button"){
event.keyCode=9;
if(event.srcElement.value == "查询" || event.srcElement.value == "保存" || event.srcElement.value == "下一步" || event.srcElement.value == "登录" ){//|| event.srcElement.value == "检测编号"
event.srcElement.onclick();
}
}else{
var nextIndex=getItemIndex();
if (document.all.item(nextIndex).type == "text" || document.all.item(nextIndex).type == "textarea"){
if(document.all.item(nextIndex).readOnly==true){
getNextIndex(nextIndex);
}else{
event.keyCode=9;
}
//getNextItem();
}else{//下一个不是text
if(document.all.item(nextIndex).disabled==true){
getNextIndex(nextIndex);
}else{
if(document.all.item(nextIndex).type=="radio"){
//document.all.item(nextIndex).focus();
///*每一个radio都进入焦点
if(document.all.item(nextIndex).checked==true){
event.keyCode=9;
}else{
getNextIndex(nextIndex);
}
//*/
}else{
event.keyCode=9;
}
}
}
}
}
}catch(e){
alert("未知异常");
event.keyCode=9
}
return true;
}else{
return false;
}
}
function getItemIndex(){
var index;//当前的sourceIndex
var nextIndex;//下一个sourceIndex
index=window.event.srcElement.sourceIndex;
index+=1;
with (document.all){
var aTab = new Array(length);
for ( var i=index;i<length;i++) {
if(item(i).type=="text" || item(i).type=="textarea" || item(i).type=="checkbox" || item(i).type=="radio" || (item(i).type=="select" && item(i).disabled==false ) || ( item(i).type=="select-one" && item(i).disabled==false ) ){
nextIndex = item(i).sourceIndex;
break;
}
}
}
return nextIndex;
}
function getNextIndex(argindex){
var index;//当前的sourceIndex
var nextIndex;//下一个sourceIndex
index=document.all.item(argindex).sourceIndex;
index+=1;
with (document.all){
var aTab = new Array(length);
for (var i=index;i<length;i++) {
if(item(i).type=="text" || item(i).type=="textarea" || item(i).type=="checkbox" || item(i).type=="radio" || (item(i).type=="select" && item(i).disabled==false ) || ( item(i).type=="select-one" && item(i).disabled==false ) ){
nextIndex = item(i).sourceIndex;
break;
}
}
}
if (document.all.item(nextIndex).type == "text" || document.all.item(nextIndex).type == "textarea"){
if(document.all.item(nextIndex).readOnly==true){
getNextIndex(nextIndex);
}else{
document.all.item(nextIndex).focus();
}
}else{
if(document.all.item(nextIndex).type==undefined){
event.keyCode=9;
}
if(document.all.item(nextIndex).disabled==true){
getNextIndex(nextIndex);
}else{
if(document.all.item(nextIndex).type=="radio"){
if(document.all.item(nextIndex).checked==true){
document.all.item(nextIndex).focus();
}else{
getNextIndex(nextIndex);
}
}else{
document.all.item(nextIndex).focus();
}
}
}
return true;
}
//基础js
// =========================================================
// 项目:嘉兴市民健康信息系统
// 描述:AJAX控制模块脚本
// 路径:$Archive: $
// 版本:$Version: $ $Date: $
// =========================================================
// ---------------------------------------------------------
// 请求就绪状态
// ---------------------------------------------------------
// 请求尚未初始化
RS_UNINITIALIZED = 0;
// 请求已经建立,但仍未发送
RS_NOT_SENT = 1;
// 请求已经发送,服务器尚未反馈
RS_SENT = 2;
// 服务器已经对请求进行响应,已返回了部分数据
RS_IN_PROCESS = 3;
// 请求处理结束
RS_COMPLETE = 4;
// ---------------------------------------------------------
// HTTP状态码分类
// ---------------------------------------------------------
// 信息(1xx)
SC_PREFIX_INFO = 1;
// 客户端请求成功(2xx)
SC_PREFIX_SUCCESS = 2;
// 请求转发,需要后续指示(3xx)
SC_PREFIX_REDIRECT = 3;
// 客户端请求错误(4xx)
SC_PREFIX_INCOMPLETE = 4;
// 服务器错误(5xx)
SC_PREFIX_ERROR = 5;
// ---------------------------------------------------------
// HTTP状态码常量
// ---------------------------------------------------------
// 信息(1xx)
SC_CONTINUE = 100;
SC_SWITCHING_PROTOCOLS = 101;
// 客户端请求成功(2xx)
SC_OK = 200;
SC_CREATED = 201;
SC_ACCEPTED = 202;
SC_NON_AUTHORITATIVE_INFORMATION = 203;
SC_NO_CONTENT = 204;
SC_RESET_CONTENT = 205;
SC_PARTIAL_CONTENT = 206;
// 请求转发,需要后续指示(3xx)
SC_MULTIPLE_CHOICES = 300;
SC_MOVED_PERMANENTLY = 301;
SC_MOVED_TEMPORARILY = 302;
SC_FOUND = 302;
SC_SEE_OTHER = 303;
SC_NOT_MODIFIED = 304;
SC_USE_PROXY = 305;
SC_TEMPORARY_REDIRECT = 307;
// 客户端请求错误(4xx)
SC_BAD_REQUEST = 400;
SC_UNAUTHORIZED = 401;
SC_PAYMENT_REQUIRED = 402;
SC_FORBIDDEN = 403;
SC_NOT_FOUND = 404;
SC_METHOD_NOT_ALLOWED = 405;
SC_NOT_ACCEPTABLE = 406;
SC_PROXY_AUTHENTICATION_REQUIRED = 407;
SC_REQUEST_TIMEOUT = 408;
SC_CONFLICT = 409;
SC_GONE = 410;
SC_LENGTH_REQUIRED = 411;
SC_PRECONDITION_FAILED = 412;
SC_REQUEST_ENTITY_TOO_LARGE = 413;
SC_REQUEST_URI_TOO_LONG = 414;
SC_UNSUPPORTED_MEDIA_TYPE = 415;
SC_REQUESTED_RANGE_NOT_SATISFIABLE = 416;
SC_EXPECTATION_FAILED = 417;
// 服务器错误(5xx)
SC_INTERNAL_SERVER_ERROR = 500;
SC_NOT_IMPLEMENTED = 501;
SC_BAD_GATEWAY = 502;
SC_SERVICE_UNAVAILABLE = 503;
SC_GATEWAY_TIMEOUT = 504;
SC_HTTP_VERSION_NOT_SUPPORTED = 505;
// ---------------------------------------------------------
// 根据客户端浏览器类型,建立一个新的XML HTTP请求对象,并设置回调方法。
//
// 参数:
// param 在回调方法中要用到的参数对象
// 返回:
// XML HTTP请求对象,或者null(如果浏览器不支持的话)
// ---------------------------------------------------------
function createXMLHttpRequest(param) {
var httpRequest = null;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
httpRequest = createInMozilla();
} else if (window.ActiveXObject) { // IE
httpRequest = createInIE();
}
if (httpRequest == null) {
try {
// 浏览器不支持AJAX
ajaxUnsupported();
return;
} catch (e) {
throw new Error("Initialization fails!");
}
}
// 设置回调方法
httpRequest.onreadystatechange = function() {
readyStateChanged(httpRequest, param);
};
return httpRequest;
}
// ---------------------------------------------------------
// 在Mozilla中建立并返回一个新的XML HTTP请求对象。
//
// 参数: 无
// 返回:
// XML HTTP请求对象
// ---------------------------------------------------------
function createInMozilla() {
var mozInstance = null;
mozInstance = new XMLHttpRequest();
if (mozInstance.overrideMimeType) {
mozInstance.overrideMimeType("text/xml");
}
return mozInstance;
}
// ---------------------------------------------------------
// 在IE中建立并返回一个新的XML HTTP请求对象。
//
// 参数: 无
// 返回:
// XML HTTP请求对象
// ---------------------------------------------------------
function createInIE() {
var name = ["Msxml3.XMLHTTP", "Msxml2.XMLHTTP", "Microsoft.XMLHTTP"];
for (var i = 0; i < name.length; i++) {
try {
return new ActiveXObject(name[i]);
} catch (e) {
}
}
}
// ---------------------------------------------------------
// XML HTTP请求对象的事件处理流程控制方法。
// 该方法会在请求对象的就绪状态发生变更的时候被自动调用。
// 流程控制中所调用的方法如非必须,可以不定义,这并不会影响其他方法的调用。
//
// 参数:
// httpRequest XML HTTP请求对象
// param 在回调方法中要用到的参数对象
// 返回: 无
// ---------------------------------------------------------
function readyStateChanged(httpRequest, param) {
try {
// 具体事件处理方法调用之前的共通前期处理
preProcessReadyStateChanged(httpRequest, param);
} catch (e) {
}
try {
// 根据不同的状态,分别调用不同的处理方法
switch (httpRequest.readyState) {
case RS_UNINITIALIZED:
// 请求尚未初始化
readyStateUninitialized(httpRequest, param);
break;
case RS_NOT_SENT:
// 请求已经建立,但仍未发送
readyStateNotSent(httpRequest, param);
break;
case RS_SENT:
// 请求已经发送,服务器尚未反馈
readyStateSent(httpRequest, param);
break;
case RS_IN_PROCESS:
// 服务器已经对请求进行响应,已返回了部分数据
readyStateInProcess(httpRequest, param);
break;
case RS_COMPLETE:
// 请求处理结束
readyStateComplete(httpRequest, param);
break;
}
} catch (e) {
}
try {
// 具体事件处理方法调用之后的共通后期处理
postProcessReadyStateChanged(httpRequest, param);
} catch (e) {
}
}
//ajax
/*--------------------------------------------------|
| dTree 2.05 | www.destroydrop.com/javascript/tree/ |
|---------------------------------------------------|
| Copyright (c) 2002-2003 Geir Landr? |
| |
| This script can be used freely as long as all |
| copyright messages are intact. |
| |
| Updated: 17.04.2003 |
|--------------------------------------------------*/
// Node object
function Node(id, pid, name, url, title, target, icon, iconOpen, open) {
this.id = id;
this.pid = pid;
this.name = name;
this.url = url;
this.title = title;
this.target = target;
this.icon = icon;
this.iconOpen = iconOpen;
this._io = open || false;
this._is = false;
this._ls = false;
this._hc = false;
this._ai = 0;
this._p;
};
// Tree object
function dTree(objName) {
this.config = {
target : null,
folderLinks : false,
useSelection : false,
useCookies : false,
useLines : false,
useIcons : false,
useStatusText : true,
closeSameLevel : true,
inOrder : false
}
this.icon = {
root : 'js/img/base.gif',
folder : 'js/img/folder.gif',
folderOpen : 'js/img/folderopen.gif',
node : 'js/img/page.gif',
empty : 'js/img/empty.gif',
line : 'js/img/line.gif',
join : 'js/img/join.gif',
joinBottom : 'js/img/joinbottom.gif',
plus : 'js/img/plus.gif',
plusBottom : 'js/img/plusbottom.gif',
minus : 'js/img/minus.gif',
minusBottom : 'js/img/minusbottom.gif',
nlPlus : 'js/img/nolines_plus.gif',
nlMinus : 'js/img/nolines_minus.gif'
};
this.obj = objName;
this.aNodes = [];
this.aIndent = [];
this.root = new Node(-1);
this.selectedNode = null;
this.selectedFound = false;
this.completed = false;
};
// Adds a new node to the node array
dTree.prototype.add = function(id, pid, name, url, title, target, icon, iconOpen, open) {
this.aNodes[this.aNodes.length] = new Node(id, pid, name, url, title, target, icon, iconOpen, open);
};
// Open/close all nodes
dTree.prototype.openAll = function() {
this.oAll(true);
};
dTree.prototype.closeAll = function() {
this.oAll(false);
};
// Outputs the tree to the page
dTree.prototype.toString = function() {
var str = '<div class="dtree">\n';
if (document.getElementById) {
if (this.config.useCookies) this.selectedNode = this.getSelected();
str += this.addNode(this.root);
} else str += 'Browser not supported.';
str += '</div>';
if (!this.selectedFound) this.selectedNode = null;
this.completed = true;
return str;
};
// Creates the tree structure
dTree.prototype.addNode = function(pNode) {
var str = '';
var n=0;
if (this.config.inOrder) n = pNode._ai;
for (n; n<this.aNodes.length; n++) {
if (this.aNodes[n].pid == pNode.id) {
var cn = this.aNodes[n];
cn._p = pNode;
cn._ai = n;
this.setCS(cn);
if (!cn.target && this.config.target) cn.target = this.config.target;
if (cn._hc && !cn._io && this.config.useCookies) cn._io = this.isOpen(cn.id);
if (!this.config.folderLinks && cn._hc) cn.url = null;
if (this.config.useSelection && cn.id == this.selectedNode && !this.selectedFound) {
cn._is = true;
this.selectedNode = n;
this.selectedFound = true;
}
str += this.node(cn, n);
if (cn._ls) break;
}
}
return str;
};
// Creates the node icon, url and text
dTree.prototype.node = function(node, nodeId) {
var str = '<div class="dTreeNode">' + this.indent(node, nodeId);
if (this.config.useIcons) {
if (!node.icon) node.icon = (this.root.id == node.pid) ? this.icon.root : ((node._hc) ? this.icon.folder : this.icon.node);
if (!node.iconOpen) node.iconOpen = (node._hc) ? this.icon.folderOpen : this.icon.node;
if (this.root.id == node.pid) {
node.icon = this.icon.root;
node.iconOpen = this.icon.root;
}
str += '<img id="i' + this.obj + nodeId + '" src="' + ((node._io) ? node.iconOpen : node.icon) + '" alt="" />';
}
if (node.url) {
str += '<a id="s' + this.obj + nodeId + '" class="' + ((this.config.useSelection) ? ((node._is ? 'nodeSel' : 'node')) : 'node') + '" href= "javascript:submitForm(\'menu'+node.id+'\''+',\''+node.url+'\')"';
if (node.title) str += ' title="' + node.title + '"';
if (node.target) str += ' target="' + node.target + '"';
if (this.config.useStatusText) str += ' onmouseover="window.status=\'\';return true;" onmouseout="window.status=\'\';return true;" ';
if (this.config.useSelection && ((node._hc && this.config.folderLinks) || !node._hc))
str += ' onclick="javascript: ' + this.obj + '.s(' + nodeId + ');"';
str += '>';
}
else if ((!this.config.folderLinks || !node.url) && node._hc && node.pid != this.root.id)
str += '<a href="javascript: ' + this.obj + '.o(' + nodeId + ');" class="node">';
str += node.name;
if (node.url || ((!this.config.folderLinks || !node.url) && node._hc)) str += '</a>';
str += '</div>';
if (node._hc) {
str += '<div id="d' + this.obj + nodeId + '" class="clip" style="display:' + ((this.root.id == node.pid || node._io) ? 'block' : 'none') + ';">';
str += this.addNode(node);
str += '</div>';
}
this.aIndent.pop();
return str;
};
// Adds the empty and line icons
dTree.prototype.indent = function(node, nodeId) {
var str = '';
if (this.root.id != node.pid) {
for (var n=0; n<this.aIndent.length; n++)
str += '<img src="' + ( (this.aIndent[n] == 1 && this.config.useLines) ? this.icon.line : this.icon.empty ) + '" alt="" />';
(node._ls) ? this.aIndent.push(0) : this.aIndent.push(1);
if (node._hc) {
str += '<a href="javascript: ' + this.obj + '.o(' + nodeId + ');"><img id="j' + this.obj + nodeId + '" src="';
if (!this.config.useLines) str += (node._io) ? this.icon.nlMinus : this.icon.nlPlus;
else str += ( (node._io) ? ((node._ls && this.config.useLines) ? this.icon.minusBottom : this.icon.minus) : ((node._ls && this.config.useLines) ? this.icon.plusBottom : this.icon.plus ) );
str += '" alt="" /></a>';
} else str += '<img src="' + ( (this.config.useLines) ? ((node._ls) ? this.icon.joinBottom : this.icon.join ) : this.icon.empty) + '" alt="" />';
}
return str;
};
// Checks if a node has any children and if it is the last sibling
dTree.prototype.setCS = function(node) {
var lastId;
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n].pid == node.id) node._hc = true;
if (this.aNodes[n].pid == node.pid) lastId = this.aNodes[n].id;
}
if (lastId==node.id) node._ls = true;
};
// Returns the selected node
dTree.prototype.getSelected = function() {
var sn = this.getCookie('cs' + this.obj);
return (sn) ? sn : null;
};
// Highlights the selected node
dTree.prototype.s = function(id) {
if (!this.config.useSelection) return;
var cn = this.aNodes[id];
if (cn._hc && !this.config.folderLinks) return;
if (this.selectedNode != id) {
if (this.selectedNode || this.selectedNode==0) {
eOld = document.getElementById("s" + this.obj + this.selectedNode);
eOld.className = "node";
}
eNew = document.getElementById("s" + this.obj + id);
eNew.className = "nodeSel";
this.selectedNode = id;
if (this.config.useCookies) this.setCookie('cs' + this.obj, cn.id);
}
};
// Toggle Open or close
dTree.prototype.o = function(id) {
var cn = this.aNodes[id];
this.nodeStatus(!cn._io, id, cn._ls);
cn._io = !cn._io;
if (this.config.closeSameLevel) this.closeLevel(cn);
if (this.config.useCookies) this.updateCookie();
};
// Open or close all nodes
dTree.prototype.oAll = function(status) {
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n]._hc && this.aNodes[n].pid != this.root.id) {
this.nodeStatus(status, n, this.aNodes[n]._ls)
this.aNodes[n]._io = status;
}
}
if (this.config.useCookies) this.updateCookie();
};
// Opens the tree to a specific node
dTree.prototype.openTo = function(nId, bSelect, bFirst) {
if (!bFirst) {
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n].id == nId) {
nId=n;
break;
}
}
}
var cn=this.aNodes[nId];
if (cn.pid==this.root.id || !cn._p) return;
cn._io = true;
cn._is = bSelect;
if (this.completed && cn._hc) this.nodeStatus(true, cn._ai, cn._ls);
if (this.completed && bSelect) this.s(cn._ai);
else if (bSelect) this._sn=cn._ai;
this.openTo(cn._p._ai, false, true);
};
// Closes all nodes on the same level as certain node
dTree.prototype.closeLevel = function(node) {
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n].pid == node.pid && this.aNodes[n].id != node.id && this.aNodes[n]._hc) {
this.nodeStatus(false, n, this.aNodes[n]._ls);
this.aNodes[n]._io = false;
this.closeAllChildren(this.aNodes[n]);
}
}
}
// Closes all children of a node
dTree.prototype.closeAllChildren = function(node) {
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n].pid == node.id && this.aNodes[n]._hc) {
if (this.aNodes[n]._io) this.nodeStatus(false, n, this.aNodes[n]._ls);
this.aNodes[n]._io = false;
this.closeAllChildren(this.aNodes[n]);
}
}
}
// Change the status of a node(open or closed)
dTree.prototype.nodeStatus = function(status, id, bottom) {
eDiv = document.getElementById('d' + this.obj + id);
eJoin = document.getElementById('j' + this.obj + id);
if (this.config.useIcons) {
eIcon = document.getElementById('i' + this.obj + id);
eIcon.src = (status) ? this.aNodes[id].iconOpen : this.aNodes[id].icon;
}
eJoin.src = (this.config.useLines)?
((status)?((bottom)?this.icon.minusBottom:this.icon.minus):((bottom)?this.icon.plusBottom:this.icon.plus)):
((status)?this.icon.nlMinus:this.icon.nlPlus);
eDiv.style.display = (status) ? 'block': 'none';
};
// [Cookie] Clears a cookie
dTree.prototype.clearCookie = function() {
var now = new Date();
var yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24);
this.setCookie('co'+this.obj, 'cookieValue', yesterday);
this.setCookie('cs'+this.obj, 'cookieValue', yesterday);
};
// [Cookie] Sets value in a cookie
dTree.prototype.setCookie = function(cookieName, cookieValue, expires, path, domain, secure) {
document.cookie =
escape(cookieName) + '=' + escape(cookieValue)
+ (expires ? '; expires=' + expires.toGMTString() : '')
+ (path ? '; path=' + path : '')
+ (domain ? '; domain=' + domain : '')
+ (secure ? '; secure' : '');
};
// [Cookie] Gets a value from a cookie
dTree.prototype.getCookie = function(cookieName) {
var cookieValue = '';
var posName = document.cookie.indexOf(escape(cookieName) + '=');
if (posName != -1) {
var posValue = posName + (escape(cookieName) + '=').length;
var endPos = document.cookie.indexOf(';', posValue);
if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos));
else cookieValue = unescape(document.cookie.substring(posValue));
}
return (cookieValue);
};
// [Cookie] Returns ids of open nodes as a string
dTree.prototype.updateCookie = function() {
var str = '';
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n]._io && this.aNodes[n].pid != this.root.id) {
if (str) str += '.';
str += this.aNodes[n].id;
}
}
this.setCookie('co' + this.obj, str);
};
// [Cookie] Checks if a node id is in a cookie
dTree.prototype.isOpen = function(id) {
var aOpen = this.getCookie('co' + this.obj).split('.');
for (var n=0; n<aOpen.length; n++)
if (aOpen[n] == id) return true;
return false;
};
// If Push and pop is not implemented by the browser
if (!Array.prototype.push) {
Array.prototype.push = function array_push() {
for(var i=0;i<arguments.length;i++)
this[this.length]=arguments[i];
return this.length;
}
};
if (!Array.prototype.pop) {
Array.prototype.pop = function array_pop() {
lastElement = this[this.length-1];
this.length = Math.max(this.length-1,0);
return lastElement;
}
};