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;
?}
};