/************************************************************************************************************ (C) www.dhtmlgoodies.com, October 2005 Update log: December, 19th, 2005 - Version 1.1: Added support for several trees on a page January, 25th, 2006 - Version 1.2: Added onclick event to text nodes. February, 3rd 2006 - Dynamic load nodes by use of Ajax This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website. Terms of use: You are free to use this script as long as the copyright message is kept intact. However, you may not redistribute, sell or repost it without our permission. Thank you! www.dhtmlgoodies.com Alf Magne Kalleland ************************************************************************************************************/ if (niv_cur==0) var idOfFolderTrees = ['dhtmlgoodies_tree']; else if (niv_cur==1) var idOfFolderTrees = ['dhtmlgoodies_tree','dhtmlgoodies_tree2','dhtmlgoodies_tree_botanica','dhtmlgoodies_tree_horticola']; var is_multiple=false; var imageFolder = 'images/'; // Path to images var folderImage = 'spacer.gif'; var plusImage = 'dhtmlgoodies_plus.gif'; var minusImage = 'dhtmlgoodies_minus.gif'; var initExpandedNodes = ''; // Cookie - initially expanded nodes; var useAjaxToLoadNodesDynamically = true; var load_tree_db = false; var load_cauta_db = false; var load_mai_multe_date=false; //var ajaxRequestFile = 'writeNodes.php'; var contextMenuActive = true; // Set to false if you don't want to be able to delete and add new nodes dynamically var ajaxObjectArray = new Array(); var parent_id_caut_arr= new Array(); var ajaxObjectArray2 = new Array(); var treeUlCounter = 0; var nodeId = 1; ajax_run=false; ajax_run_cauta=false; /* These cookie functions are downloaded from http://www.mach5.com/support/analyzer/manual/html/General/CookiesJavaScript.htm */ /*function Get_Cookie(name) { var start = document.cookie.indexOf(name+"="); var len = start+name.length+1; if ((!start) && (name != document.cookie.substring(0,name.length))) return null; if (start == -1) return null; var end = document.cookie.indexOf(";",len); if (end == -1) end = document.cookie.length; return unescape(document.cookie.substring(len,end)); } // This function has been slightly modified function Set_Cookie(name,value,expires,path,domain,secure) { expires = expires * 60*60*24*1000; var today = new Date(); var expires_date = new Date( today.getTime() + (expires) ); var cookieString = name + "=" +escape(value) + ( (expires) ? ";expires=" + expires_date.toGMTString() : "") + ( (path) ? ";path=" + path : "") + ( (domain) ? ";domain=" + domain : "") + ( (secure) ? ";secure" : ""); document.cookie = cookieString; } */ var baza='bibldb'; function expandAll(treeId) { var menuItems = document.getElementById(treeId).getElementsByTagName('LI'); for(var no=0;no0 && subItems[0].style.display!='block'){ showHideNode(false,menuItems[no].id.replace(/[^0-9]/g,'')); } } } function collapseAll(treeId) { var menuItems = document.getElementById(treeId).getElementsByTagName('LI'); for(var no=0;no0 && subItems[0].style.display=='block'){ showHideNode(false,menuItems[no].id.replace(/[^0-9]/g,'')); } } } var parent_id_caut=false; var mod_culticar=false; function getNodeDataFromServer(ajaxIndex,ulId,parentId) { //document.getElementById(ulId).innerHTML = ajaxObjectArray[ajaxIndex].response; var text=ajaxObjectArray[ajaxIndex].response; var text_arr=text.split('ajax_reia_site'); document.getElementById(ulId).innerHTML=text_arr[0]; ajaxObjectArray[ajaxIndex] = false; parseSubItems(ulId,parentId); if ((text_arr[1]!=false)&&(text_arr[1]!=null)&&(text_arr[1]!='')) { text2_arr=text_arr[1].split('^'); parent_id_caut=text2_arr[0];baza=text2_arr[1];dcr_calc_ajax();mai_multe_date_init(); } } function parseSubItems(ulId,parentId) { if(initExpandedNodes){ var nodes = initExpandedNodes.split(','); } var branchObj = document.getElementById(ulId); var menuItems = branchObj.getElementsByTagName('LI'); // Get an array of all menu items for(var no=0;no0)continue; nodeId++; var subItems = menuItems[no].getElementsByTagName('UL'); var img = document.createElement('IMG'); img.src = imageFolder + plusImage; img.onclick = showHideNode; if(subItems.length==0)img.style.visibility='hidden';else{ subItems[0].id = 'tree_ul_' + treeUlCounter; treeUlCounter++; } var aTag = menuItems[no].getElementsByTagName('A')[0]; aTag.onclick = showHideNode; if(contextMenuActive)aTag.oncontextmenu = showContextMenu; menuItems[no].insertBefore(img,aTag); menuItems[no].id = 'dhtmlgoodies_treeNode' + nodeId; var folderImg = document.createElement('IMG'); if(menuItems[no].className){ folderImg.src = imageFolder + menuItems[no].className; }else{ folderImg.src = imageFolder + folderImage; } menuItems[no].insertBefore(folderImg,aTag); var tmpParentId = menuItems[no].getAttribute('parentId'); if(!tmpParentId)tmpParentId = menuItems[no].tmpParentId; if(tmpParentId && nodes[tmpParentId])showHideNode(false,nodes[no]); } } var plus_minus_status=true; function showHideNode(e,inputId) { if(inputId){ if(!document.getElementById('dhtmlgoodies_treeNode'+inputId))return; thisNode = document.getElementById('dhtmlgoodies_treeNode'+inputId).getElementsByTagName('IMG')[0]; }else { thisNode = this; if(this.tagName=='A')thisNode = this.parentNode.getElementsByTagName('IMG')[0]; } if(thisNode.style.visibility=='hidden')return; var parentNode = thisNode.parentNode; inputId = parentNode.id.replace(/[^0-9]/g,''); if(thisNode.src.indexOf(plusImage)>=0){ thisNode.src = thisNode.src.replace(plusImage,minusImage); var ul = parentNode.getElementsByTagName('UL')[0]; ul.style.display='block'; if(!initExpandedNodes)initExpandedNodes = ','; if(initExpandedNodes.indexOf(',' + inputId + ',')<0) initExpandedNodes = initExpandedNodes + inputId + ','; if(useAjaxToLoadNodesDynamically){ // Using AJAX/XMLHTTP to get data from the server var firstLi = ul.getElementsByTagName('LI')[0]; try { var parentId = firstLi.getAttribute('parentId'); if(!parentId)parentId = firstLi.parentId; } catch(e) { } plus_minus_status=false; // aici se executa de fieacre data // var opt_=preia_select('select_unde_'); //if (opt_==0) switch_divs(1,0,0,0,1); // document.getElementById('main_search_content_afis_avans'). document.getElementById('cauta_selector_avans').innerHTML=''; document.getElementById('cauta_info_avans').innerHTML=''; try { document.getElementById('dcr').innerHTML=''; } catch(e){ } if (parent_id_caut_arr[inputId]) { parent_id_caut=parent_id_caut_arr[inputId]; dcr_calc_ajax(); mai_multe_date_init(); } indice_case_plus=inputId; if(parentId){ ajaxObjectArray[ajaxObjectArray.length] = new sack(); var ajaxIndex = ajaxObjectArray.length-1; if (niv_cur==1) { var opt_other=preia_select('select_clasif'); if (opt_other==2) ajaxRequestFile='write_radacina_nav_planta_hort.php'; else ajaxRequestFile='write_radacina_nav_planta.php'; } else ajaxRequestFile='write_radacina_nav_planta.php'; if (adauga_filtru) { ajaxRequestFile='write_caract_nodes_modal.php'; //var div_modal=document.getElementById('DHTMLSuite_modalBox_contentDiv'); //alert(div_modal.innerHTML); } var url=ajaxRequestFile + '?parentId=' + parentId+'&arr='+arg_caract+'&selectat='+selectat+'&id_selectat='+date_selectie; //alert(url); parentId; ajaxObjectArray[ajaxIndex].requestFile =url; ajaxObjectArray[ajaxIndex].onCompletion = function() { getNodeDataFromServer(ajaxIndex,ul.id,parentId); }; // Specify function that will be executed after file has been found ajaxObjectArray[ajaxIndex].runAJAX(); // Execute AJAX function } } }else{ thisNode.src = thisNode.src.replace(minusImage,plusImage); parentNode.getElementsByTagName('UL')[0].style.display='none'; initExpandedNodes = initExpandedNodes.replace(',' + inputId,''); plus_minus_status=true; document.getElementById('main_multe_info').style.display='none'; document.getElementById('cautare_avansata_opt').style.display='block'; } //Set_Cookie('dhtmlgoodies_expandedNodes',initExpandedNodes,500); return false; } var okToCreateSubNode = true; function addNewNode(e) { if(!okToCreateSubNode)return; setTimeout('okToCreateSubNode=true',200); contextMenuObj.style.display='none'; okToCreateSubNode = false; source = contextMenuSource; while(source.tagName.toLowerCase()!='li')source = source.parentNode; /* if (e.target) source = e.target; else if (e.srcElement) source = e.srcElement; if (source.nodeType == 3) // defeat Safari bug source = source.parentNode; */ //while(source.tagName.toLowerCase()!='li')source = source.parentNode; var nameOfNewNode = prompt('Name of new node'); if(!nameOfNewNode)return; uls = source.getElementsByTagName('UL'); if(uls.length==0){ var ul = document.createElement('UL'); source.appendChild(ul); }else{ ul = uls[0]; ul.style.display='block'; } var img = source.getElementsByTagName('IMG'); img[0].style.visibility='visible'; var li = document.createElement('LI'); li.className='dhtmlgoodies_sheet.gif'; var a = document.createElement('A'); a.href = '#'; a.innerHTML = nameOfNewNode; li.appendChild(a); ul.id = 'newNode' + Math.round(Math.random()*1000000); ul.appendChild(li); parseSubItems(ul.id); saveNewNode(nameOfNewNode,source.getElementsByTagName('A')[0].id); } /* Save a new node */ function salveaza_java(id_c,valoare,caract_id,element_bib,baza,tip,user) { window.status = 'Se Salveaza Informatia'; //alert(ajaxRequestFile2 + '?id_c='+id_c+'&valoare='+valoare+'&caract_id='+caract_id+'&element='+element_bib+'&baza='+baza+'&tip='+tip+'&user='+user); ajaxObjectArray2[ajaxObjectArray2.length] = new sack(); var ajaxIndex = ajaxObjectArray2.length-1; var url=ajaxRequestFile2 + '?id_c='+id_c+'&&valoare='+valoare+'&&caract_id='+caract_id+'&&element='+element_bib+'&&baza='+baza+'&&tip='+tip+'&&user='+user; //alert(url); ajaxObjectArray2[ajaxIndex].requestFile = url; ajaxObjectArray2[ajaxIndex].onError = function() { window.status = 'Data nu a fost salvata'; }; ajaxObjectArray2[ajaxIndex].onCompletion = function() { window.status = 'Datale au fost actualizate'; }; // Specify function that will be executed after file has been found ajaxObjectArray2[ajaxIndex].runAJAX(); } function back_up(element,user) { window.status = 'Se Salveaza Informatia'; //alert(ajaxRequestFile2 + '?id_c='+id_c+'&valoare='+valoare+'&caract_id='+caract_id+'&element='+element_bib+'&baza='+baza+'&tip='+tip+'&user='+user); ajaxObjectArray[ajaxObjectArray.length] = new sack(); var ajaxIndex = ajaxObjectArray.length-1; var unde='db_caract.php?element_id='+element+'&ng=1'; ajaxObjectArray[ajaxIndex].requestFile = ajaxRequestFile3 + '?user_id='+user; ajaxObjectArray[ajaxIndex].onError = function() { window.status = 'Data nu a fost salvata'; }; ajaxObjectArray[ajaxIndex].onCompletion = function() { alert('Operatie completata cu succes');window.location=unde; }; // Specify function that will be executed after file has been found ajaxObjectArray[ajaxIndex].runAJAX(); } function saveNewNode(nodeText,parentId) { alert('ok'); self.status = 'Ready to save node ' + nodeText + ' which is a sub item of ' + parentId; // Use an ajax method here to save this new node. example below: /*ajaxObjectArray[ajaxObjectArray.length] = new sack(); var ajaxIndex = ajaxObjectArray.length-1; ajaxObjectArray[ajaxIndex].requestFile = ajaxRequestFile + '?newNode=' + nodeText + '&parendId=' + parentId ajaxObjectArray[ajaxIndex].onCompletion = function() { self.status = 'New node has been saved'; }; // Specify function that will be executed after file has been found ajaxObjectArray[ajaxIndex].runAJAX(); // Execute AJAX function*/ } function deleteNode() { if(!okToCreateSubNode)return; setTimeout('okToCreateSubNode=true',200); contextMenuObj.style.display='none'; source = contextMenuSource; if(!confirm('Click OK to delete the node ' + source.innerHTML))return; okToCreateSubNode = false; var parentLi = source.parentNode.parentNode.parentNode; while(source.tagName.toLowerCase()!='li')source = source.parentNode; var lis = source.parentNode.getElementsByTagName('LI'); source.parentNode.removeChild(source); if(lis.length==0)parentLi.getElementsByTagName('IMG')[0].style.visibility='hidden'; deleteNodeOnServer(source.id); } function deleteNodeOnServer(nodeId) { self.status = 'Ready to delete node' + nodeId; // Use an ajax method here to save this new node. example below: /* ajaxObjectArray[ajaxObjectArray.length] = new sack(); var ajaxIndex = ajaxObjectArray.length-1; ajaxObjectArray[ajaxIndex].requestFile = ajaxRequestFile + '?deleteNodeId=' + nodeId ajaxObjectArray[ajaxIndex].onCompletion = function() { self.status = 'Node has been deleted successfully'; }; // Specify function that will be executed after file has been found ajaxObjectArray[ajaxIndex].runAJAX(); // Execute AJAX function */ } function initTreeLitera(ls,cp) { //change_litere(ls); var the_search_opt_obj=document.getElementById('search_type_'); for(i=0;i0){ if (niv_cur==1) { if(opt_other==1) total_botanica=total; else if (opt_other==2) total_horticola=total; else if (opt_==3) total_familii=total; else total_java=total; } else total_java=total; } else{ if (niv_cur==1) { if(opt_other==1) total=total_botanica; else if (opt_other==2) total=total_horticola; else if (opt_==3) total=total_familii; else total=total_java; } else total=total_java; } if (ls!='~') ls_java=ls; var the_url=url_java+'~~ls='+ls_java+'~~cp='+cp+'~~contr=familii~~the_search_opt='+the_search_opt+'~~the_opt_select='+get_option()+'&selectat='+selectat+'&id_selectat='+date_selectie; if (niv_cur==1) { if(opt_other==1){ var unde='write_radacina_nav_planta.php?limba='+limba_java+'&contr=botanica&ls='+ls_java+'&the_search_opt='+the_search_opt+'&cp='+cp+'&opt='+the_opt+'&limita='+nr_rec_per_page+'&selectat='+selectat+'&id_selectat='+date_selectie+'&url_java='+the_url; //alert(unde); } else if (opt_other==2) { var unde='write_radacina_nav_planta_hort.php?'+'&selectat='+selectat+'&id_selectat='+date_selectie; //alert(selectat) //alert(unde); } else if(opt_==3) var unde='write_radacina_nav_planta.php?limba='+limba_java+'&contr=familii&ls='+ls_java+'&url_java='+the_url+'&the_search_opt='+the_search_opt+'&cp='+cp+'&opt='+the_opt+'&limita='+nr_rec_per_page+'&selectat='+selectat+'&id_selectat='+date_selectie; else var unde='write_radacina_nav_planta.php?limba='+limba_java+'&ls='+ls_java+'&url_java='+the_url+'&the_search_opt='+the_search_opt+'&cp='+cp+'&opt='+the_opt+'&limita='+nr_rec_per_page+'&selectat='+selectat+'&id_selectat='+date_selectie; }else var unde='write_radacina_nav_planta.php?limba='+limba_java+'&ls='+ls_java+'&url_java='+the_url+'&the_search_opt='+the_search_opt+'&cp='+cp+'&opt='+the_opt+'&limita='+nr_rec_per_page+'&selectat='+selectat+'&id_selectat='+date_selectie; // var unde='write_radacina_nav_planta.php?ls='+ls+'&ls_nou=1'; //alert(total); display_page_selector(cp,1,total,pag_curent,selector_div,nr_rec_per_page,nr_page_in_page_selector,0); document.getElementById(selector_div).style.display='block'; load_tree_db.requestFile = unde; load_tree_db.onError = function() {alert(load_tree_db.response);}; load_tree_db.onCompletion = function() { afis_info_tree_litera(opt_,opt_other); }; // Specify function that will be executed after file has been found load_tree_db.runAJAX(); } function afis_info_tree_litera(opt_,opt_other){ var info_text=load_tree_db.response; //load_tree_db = false; load_tree_db.reset(); if (niv_cur==1) { if (opt_other==1) { var tree_progres='tree_progres_botanica'; var tree_info='tree_info_botanica'; var selector_div='selector_div_botanica'; var dhtmlgoodies_tree='dhtmlgoodies_tree_botanica'; } else if (opt_other==2) { var tree_progres='tree_progres_horticola'; var tree_info='tree_info_horticola'; var selector_div='selector_div_horticola'; var dhtmlgoodies_tree='dhtmlgoodies_tree_horticola'; } else if (opt_==3){ var tree_progres='tree_progres_familii'; var tree_info='tree_info_familii'; var selector_div='selector_div_familii'; var dhtmlgoodies_tree='dhtmlgoodies_tree2'; } else { var tree_progres='tree_progres'; var tree_info='tree_info'; var selector_div='selector_div'; var dhtmlgoodies_tree='dhtmlgoodies_tree'; } } else { var tree_progres='tree_progres'; var tree_info='tree_info'; var selector_div='selector_div'; var dhtmlgoodies_tree='dhtmlgoodies_tree'; } var the_tree=document.getElementById(dhtmlgoodies_tree); the_tree.innerHTML=info_text; initTree(dhtmlgoodies_tree); document.getElementById(tree_progres).style.display='none'; document.getElementById(tree_info).style.display='block'; } function initTree(care_arbore) { var dhtmlgoodies_tree = document.getElementById(care_arbore); var menuItems = dhtmlgoodies_tree.getElementsByTagName('LI'); // Get an array of all menu items for(var no=0;no0) total_mai_multe_java=total_cauta; var the_url=url_java+'~~ls='+ls_java+'~~cp='+cp+'~~the_search_opt='+the_search_opt+'~~the_opt_select='+get_option()+'&selectat='+selectat+'&id_selectat='+date_selectie; //var unde='write_cauta_planta.php?the_search_opt='+the_search_opt+'&opt='+the_opt+'&val='+val+'&limita='+nr_rec_per_page_cauta+'&cp='+cp+'&limba='+limba_java; // var unde='write_radacina_nav_planta.php?ls='+ls+'&ls_nou=1'; if (!(parent_id_caut_arr[indice_case_plus])) parent_id_caut_arr[indice_case_plus]=parent_id_caut; var unde='write_cauta_planta.php?cp='+cp+'&limba='+limba_java+'&parent_id_caut='+parent_id_caut+'&mai_multe_inf=da'+'&limita='+nr_rec_per_page_cauta+'&url='+the_url+'&the_baza='+baza+'&selectat='+selectat+'&id_selectat='+date_selectie; display_page_selector(cp,1,total_mai_multe_java,pag_curent_cauta,'multe_info_selector',nr_rec_per_page_cauta,nr_page_in_page_selector,2); document.getElementById('dcr').innerHTML=text_inreg+total_mai_multe_java; document.getElementById('multe_info_selector').style.display='block'; load_mai_multe_date.requestFile = unde; load_mai_multe_date.onError = function() {alert(load_mai_multe_date.response);}; load_mai_multe_date.onCompletion = function() { afis_mai_multe_info_cauta_();}; // Specify function that will be executed after file has been found load_mai_multe_date.runAJAX(); } function afis_mai_multe_info_cauta_(){ var info_text=load_mai_multe_date.response; //load_tree_db = false; load_mai_multe_date.reset(); var the_tree=document.getElementById('multe_info'); the_tree.innerHTML=info_text; document.getElementById('multe_info_progres').style.display='none'; the_tree.style.display='block'; document.getElementById('multe_info_selector').style.display='block'; if (plus_minus_status){ document.getElementById('main_multe_info').style.display='none'; document.getElementById('cautare_avansata_opt').style.display='block'; return; } }