Guest User

lib/tiki-js.js

a guest
Jul 9th, 2010
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 50.28 KB | None | 0 0
  1. //$Id: tiki-js.js 27824 2010-07-02 13:30:55Z jonnybradley $
  2. var feature_no_cookie = 'n';
  3.  
  4. function browser() {
  5.     var b = navigator.appName;
  6.     if (b == "Netscape") { this.b = "ns"; }
  7.     else { this.b = b; }
  8.     this.version = navigator.appVersion;
  9.     this.v = parseInt(this.version, 10);
  10.     this.ns = (this.b=="ns" && this.v>=5);
  11.     this.op = (navigator.userAgent.indexOf('Opera')>-1);
  12.     this.safari = (navigator.userAgent.indexOf('Safari')>-1);
  13.     this.op7 = (navigator.userAgent.indexOf('Opera')>-1 && this.v>=7);
  14.     this.ie56 = (this.version.indexOf('MSIE 5')>-1||this.version.indexOf('MSIE 6')>-1);
  15.     /* ie567 added by Enmore */
  16.     this.ie567 = (this.version.indexOf('MSIE 5')>-1||this.version.indexOf('MSIE 6')>-1||this.version.indexOf('MSIE 7')>-1);
  17.     this.iewin = (this.ie56 && navigator.userAgent.indexOf('Windows')>-1);
  18.     /* iewin7 added by Enmore */   
  19.     this.iewin7 = (this.ie567 && navigator.userAgent.indexOf('Windows')>-1);
  20.     this.iemac = (this.ie56 && navigator.userAgent.indexOf('Mac')>-1);
  21.     this.moz = (navigator.userAgent.indexOf('Mozilla')>-1);
  22.     this.moz13 = (navigator.userAgent.indexOf('Mozilla')>-1 && navigator.userAgent.indexOf('1.3')>-1);
  23.     this.oldmoz = (navigator.userAgent.indexOf('Mozilla')>-1 && navigator.userAgent.indexOf('1.4')>-1 || navigator.userAgent.indexOf('Mozilla')>-1 && navigator.userAgent.indexOf('1.5')>-1 || navigator.userAgent.indexOf('Mozilla')>-1 && navigator.userAgent.indexOf('1.6')>-1);
  24.     this.ns6 = (navigator.userAgent.indexOf('Netscape6')>-1);
  25.     this.docom = (this.ie56||this.ns||this.iewin||this.op||this.iemac||this.safari||this.moz||this.oldmoz||this.ns6);
  26. }
  27.  
  28. function getElementById(id) {   // actually gets element by name too...
  29.     if (typeof document.getElementById == "function") {
  30.         var el = document.getElementById(id);
  31.         if (el) {
  32.             return el;
  33.         }
  34.     }
  35.     if (typeof document.getElementsByName == "function") {
  36.         var arr = document.getElementsByName(id);
  37.         if (arr.length > 0) {
  38.             return arr[0];
  39.         }
  40.     }
  41.     for (i=0;i<document.forms.length;i++) {
  42.         if (document.forms[i].elements[id]) {return document.forms[i].elements[id]; }
  43.     }
  44. }
  45.  
  46. /* toggle CSS (tableless) layout columns */
  47. function toggleCols(id,zeromargin,maincol) {
  48.     var showit = 'show_' + escape(id);
  49.     if (!zeromargin) { zeromargin = ''; }
  50.     if (!id) { id = ''; }
  51.     if (!maincol) { maincol = 'col1'; }
  52.     if (document.getElementById(id).style.display == "none") {
  53.         document.getElementById(id).style.display = "block";
  54.         if (zeromargin == 'left') {
  55.             document.getElementById(maincol).style.marginLeft = '';
  56.             if (!document.getElementById(maincol).style.marginLeft) {
  57.                 document.getElementById(maincol).style.marginLeft = $jq("#"+id).width() + "px";
  58.             }
  59.             setSessionVar(showit,'y');
  60.         } else {
  61.             document.getElementById(maincol).style.marginRight = '';
  62.             if (!document.getElementById(maincol).style.marginRight) {
  63.                 document.getElementById(maincol).style.marginRight = $jq("#"+id).width() + "px";
  64.             }
  65.             setSessionVar(showit,'y');
  66.         }
  67.     } else {
  68.         document.getElementById(id).style.display = "none";
  69.         if (zeromargin == 'left') {
  70.             document.getElementById(maincol).style.marginLeft = '0';
  71.             setSessionVar(showit,'n');
  72.         } else {
  73.             document.getElementById(maincol).style.marginRight = '0';
  74.             setSessionVar(showit,'n');
  75.         }
  76.     }
  77. }
  78.  
  79. function toggle_dynamic_var(name) {
  80.     name1 = 'dyn_'+name+'_display';
  81.     name2 = 'dyn_'+name+'_edit';
  82.     if(document.getElementById(name1).style.display == "none") {
  83.         document.getElementById(name2).style.display = "none";
  84.         document.getElementById(name1).style.display = "inline";
  85.     } else {
  86.         document.getElementById(name1).style.display = "none";
  87.         document.getElementById(name2).style.display = "inline";
  88.  
  89.     }
  90.  
  91. }
  92.  
  93. function chgArtType() {
  94.     var articleType = document.getElementById('articletype').value;
  95.     var typeProperties = articleTypes[articleType];
  96.  
  97.     var propertyList = ['show_topline','y',
  98.                         'show_subtitle','y',
  99.                         'show_linkto','y',
  100.                         'show_lang','y',
  101.                         'show_author','y',
  102.                         'use_ratings','y',
  103.                         'heading_only','n',
  104.                         'show_image_caption','y',
  105.                         'show_pre_publ','y',
  106.                         'show_post_expire','y',
  107.                         'show_image','y',
  108.                         'show_expdate','y'
  109.                         ];
  110.     if (typeof articleCustomAttributes != 'undefined') {
  111.         propertyList = propertyList.concat(articleCustomAttributes);
  112.     }
  113.     var l = propertyList.length, property, value;
  114.     for (var i=0; i<l; i++) {
  115.         property = propertyList[i++];
  116.         value = propertyList[i];
  117.  
  118.         if (typeProperties[property] == value || (!typeProperties[property] && value == "n")) {
  119.             display = "";
  120.         } else {
  121.             display = "none";
  122.         }
  123.  
  124.         if (document.getElementById(property)) {
  125.             document.getElementById(property).style.display = display;
  126.         } else {
  127.             j = 1;
  128.             while (document.getElementById(property+'_'+j)) {
  129.                 document.getElementById(property+'_'+j).style.display = display;
  130.                 j++;
  131.             }
  132.         }
  133.     }
  134. }
  135.  
  136. function chgMailinType() {
  137.     if (document.getElementById('mailin_type').value != 'article-put') {
  138.         document.getElementById('article_topic').style.display = "none";
  139.         document.getElementById('article_type').style.display = "none";
  140.     } else {
  141.         document.getElementById('article_topic').style.display = "";
  142.         document.getElementById('article_type').style.display = "";
  143.     }
  144. }
  145.  
  146. function toggleSpan(id) {
  147.     if (document.getElementById(id).style.display == "inline") {
  148.         document.getElementById(id).style.display = "none";
  149.     } else {
  150.         document.getElementById(id).style.display = "inline";
  151.     }
  152. }
  153.  
  154. function toggleBlock(id) {
  155.     if (document.getElementById(id).style.display == "none") {
  156.         document.getElementById(id).style.display = "block";
  157.     } else {
  158.         document.getElementById(id).style.display = "none";
  159.     }
  160. }
  161.  
  162. function toggleTrTd(id) {
  163.     if (document.getElementById(id).style.display == "none") {
  164.         document.getElementById(id).style.display = "";
  165.     } else {
  166.         document.getElementById(id).style.display = "none";
  167.     }
  168. }
  169.  
  170. function showTocToggle() {
  171.     if (document.createTextNode) {
  172.         // Uses DOM calls to avoid document.write + XHTML issues
  173.  
  174.         var linkHolder = document.getElementById('toctitle');
  175.         if (!linkHolder) { return; }
  176.  
  177.         var outerSpan = document.createElement('span');
  178.         outerSpan.className = 'toctoggle';
  179.  
  180.         var toggleLink = document.createElement('a');
  181.         toggleLink.id = 'togglelink';
  182.         toggleLink.className = 'internal';
  183.         toggleLink.href = 'javascript:toggleToc()';
  184.         toggleLink.appendChild(document.createTextNode(tocHideText));
  185.  
  186.         outerSpan.appendChild(document.createTextNode('['));
  187.         outerSpan.appendChild(toggleLink);
  188.         outerSpan.appendChild(document.createTextNode(']'));
  189.  
  190.         linkHolder.appendChild(document.createTextNode(' '));
  191.         linkHolder.appendChild(outerSpan);
  192.         if (getCookie("hidetoc") == "1" ) { toggleToc(); }
  193.     }
  194. }
  195.  
  196. function changeText(el, newText) {
  197.     // Safari work around
  198.     if (el.innerText) {
  199.         el.innerText = newText;
  200.     } else if (el.firstChild && el.firstChild.nodeValue) {
  201.         el.firstChild.nodeValue = newText;
  202.     }
  203. }
  204.  
  205. function toggleToc() {
  206.     var toc = document.getElementById('toc').getElementsByTagName('ul')[0];
  207.     var toggleLink = document.getElementById('togglelink');
  208.  
  209.     if (toc && toggleLink && toc.style.display == 'none') {
  210.         changeText(toggleLink, tocHideText);
  211.         toc.style.display = 'block';
  212.         setCookie("hidetoc","0");
  213.     } else {
  214.         changeText(toggleLink, tocShowText);
  215.         toc.style.display = 'none';
  216.         setCookie("hidetoc","1");
  217.     }
  218. }
  219.  
  220. function chgTrkFld(f,o) {
  221.     var opt = 0;
  222.     document.getElementById('z').style.display = "none";
  223.     document.getElementById('zDescription').style.display = "";
  224.     document.getElementById('zStaticText').style.display = "none";
  225.     document.getElementById('zStaticTextToolbars').style.display = "none";
  226.  
  227.     for (var i = 0; i < f.length; i++) {
  228.         var c = f.charAt(i);
  229.         if (document.getElementById(c)) {
  230.             var ichoiceParent = document.getElementById('itemChoicesRow');
  231.             var ichoice = document.getElementById(c + 'itemChoices');
  232.             if (c == o) {
  233.                 document.getElementById(c).style.display = "";
  234.                 document.getElementById('z').style.display = "block";
  235.                 if (c == 'S') {
  236.                     document.getElementById('zDescription').style.display = "none";
  237.                     document.getElementById('zStaticText').style.display = "";
  238.                     document.getElementById('zStaticTextToolbars').style.display = "";
  239.                 }
  240.                 if (ichoice) {
  241.                     ichoice.style.display = "";
  242.                     ichoiceParent.style.display = "";
  243.                 } else {
  244.                     ichoiceParent.style.display = "none";
  245.                 }
  246.             } else {
  247.                 document.getElementById(c).style.display = "none";
  248.                 if (ichoice) {
  249.                     ichoice.style.display = "none";
  250.                 }
  251.             }
  252.         }
  253.     }
  254. }
  255.  
  256. function chgTrkLingual(item) {
  257.     document.getElementById("multilabelRow").style.display = ( item == 't' || item == 'a' ) ? '' : 'none';
  258. }
  259.  
  260. function multitoggle(f,o) {
  261.     for (var i = 0; i < f.length; i++) {
  262.         if (document.getElementById('fid'+f[i])) {
  263.             if (f[i] == o) {
  264.                 document.getElementById('fid'+f[i]).style.display = "block";
  265.             } else {
  266.                 document.getElementById('fid'+f[i]).style.display = "none";
  267.             }
  268.         }
  269.     }
  270. }
  271.  
  272. function setMenuCon(foo) {
  273.     var it = foo.split(",");
  274.     document.getElementById('menu_url').value = it[0];
  275.     document.getElementById('menu_name').value = it[1];
  276.     if (it[2]) {
  277.         document.getElementById('menu_section').value = it[2];
  278.     } else {
  279.         document.getElementById('menu_section').value = '';
  280.     }
  281.     if (it[3]) {
  282.         document.getElementById('menu_perm').value = it[3];
  283.     } else {
  284.         document.getElementById('menu_perm').value = '';
  285.     }
  286. }
  287.  
  288. function genPass(w1) {
  289.     vo = "aeiouAEU";
  290.  
  291.     co = "bcdfgjklmnprstvwxzBCDFGHJKMNPQRSTVWXYZ0123456789_$%#";
  292.     s = Math.round(Math.random());
  293.     l = 8;
  294.     p = '';
  295.  
  296.     for (i = 0; i < l; i++) {
  297.         if (s) {
  298.             letter = vo.charAt(Math.round(Math.random() * (vo.length - 1)));
  299.  
  300.             s = 0;
  301.         } else {
  302.             letter = co.charAt(Math.round(Math.random() * (co.length - 1)));
  303.  
  304.             s = 1;
  305.         }
  306.  
  307.         p = p + letter;
  308.     }
  309.  
  310.     document.getElementById(w1).value = p;
  311. }
  312.  
  313. function setUserModule(foo1) {
  314.     document.getElementById('usermoduledata').value = foo1;
  315. }
  316.  
  317. function replaceLimon(vec) {
  318.     document.getElementById(vec[0]).value = document.getElementById(vec[0]).value.replace(vec[1], vec[2]);
  319. }
  320.  
  321. function setSelectionRange(textarea, selectionStart, selectionEnd) {
  322.     if (typeof textarea.setSelectionRange != 'undefined') {
  323.         textarea.focus();
  324.         textarea.setSelectionRange(selectionStart, selectionEnd);
  325.     } else if (document.selection.createRange) {    // IE
  326.         var val = textarea.value, c = 0;
  327.         var isWin = val.indexOf("\r") > -1;
  328.         textarea.focus();
  329.         var range =  document.selection.createRange();
  330.         range.collapse();
  331.         if (selectionEnd > 1) {
  332.             if (isWin) {
  333.                 for (var i = 0; i < selectionEnd; i++) {
  334.                     if (val[i] == "\n") {
  335.                         c++;
  336.                     }
  337.                 }
  338.             }
  339.             range.moveEnd('character', selectionEnd - c);
  340.         }
  341.         range.collapse(false);
  342.         if (selectionStart < selectionEnd) {
  343.             c = 0;
  344.             if (isWin) {
  345.                 for (i = selectionEnd; i > selectionStart; i--) {
  346.                     if (val[i] == "\n") {
  347.                         c++;
  348.                     }
  349.                 }
  350.             }
  351.             range.moveStart('character', selectionStart - selectionEnd - c);
  352.         }
  353.         try {
  354.             range.select();
  355.         } catch (e) {}
  356.     }
  357. }
  358.  
  359. function getTASelection( textarea ) {
  360.     if (typeof $jq(textarea).attr("selectionStartSaved") === 'string' && $jq(textarea).attr("selectionStartSaved")) {   // forgetful firefox
  361.         return textarea.value.substring($jq(textarea).attr("selectionStartSaved"), $jq(textarea).attr("selectionEndSaved"));
  362.     } else if (typeof textarea.selectionStart != 'undefined') {
  363.         return textarea.value.substring(textarea.selectionStart, textarea.selectionEnd);
  364.     } else {    // IE
  365.         var r = document.selection.createRange();
  366.         return r.text;
  367.     }
  368. }
  369.  
  370. /*
  371.  * Save selection - mainly for Firefox that keeps forgetting it
  372.  * @param elem = DOM element or string matching id or name
  373.  */
  374.  
  375. function saveTASelection( elem ) {
  376.     if (typeof elem === 'string') {
  377.         elem = getElementById(elem);
  378.     }
  379.     if (elem && typeof elem.selectionStart != 'undefined') {
  380.         $jq(elem).attr("selectionStartSaved", elem.selectionStart);
  381.         $jq(elem).attr("selectionEndSaved", elem.selectionEnd);
  382.     }
  383. }
  384.  
  385. /*
  386.  * Restore for function above
  387.  * @param elem = DOM element or string matching id or name
  388.  */
  389.  
  390. function restoreTASelection( elem ) {
  391.     if (typeof elem === 'string') {
  392.         elem = getElementById(elem);
  393.     }
  394.     if (elem && $jq(elem).attr("selectionStartSaved")) {
  395.         if (elem.selectionStart != $jq(elem).attr("selectionStartSaved")) {
  396.             elem.selectionStart = $jq(elem).attr("selectionStartSaved");
  397.             elem.selectionEnd = $jq(elem).attr("selectionEndSaved");
  398.         }
  399.         $jq(elem).removeAttr("selectionStartSaved");
  400.         $jq(elem).removeAttr("selectionEndSaved");
  401.     }
  402. }
  403.  
  404. function setCaretToPos (textarea, pos) {
  405.     setSelectionRange(textarea, pos, pos);
  406. }
  407.  
  408. function getCaretPos (textarea) {
  409.     if (typeof textarea.selectionEnd != 'undefined') {
  410.         return textarea.selectionEnd;
  411.     } else if ( document.selection ) {
  412.  
  413.         textarea.focus();
  414.         var range = document.selection.createRange();
  415.         if (range === null) {
  416.             return 0;
  417.         }
  418.         var re = textarea.createTextRange();
  419.         var rc = re.duplicate();
  420.         re.moveToBookmark(range.getBookmark());
  421.         rc.setEndPoint('EndToStart', re);
  422.         return rc.text.length ? rc.text.length : 0;
  423.  
  424.     } else {
  425.         return 0;
  426.     }
  427. }
  428.  
  429. function insertAt(elementId, replaceString, blockLevel, perLine, replaceSelection) {
  430.     // inserts given text at selection or cursor position
  431.     textarea = getElementById(elementId);
  432.     var toBeReplaced = /text|page|area_name/g; //substrings in replaceString to be replaced by the selection if a selection was done
  433.     var hiddenParents = $jq(textarea).parents('fieldset:hidden:last');
  434.     if (hiddenParents.length) { hiddenParents.show(); }
  435.  
  436.     textarea.focus();
  437.     var selection = $jq(textarea).selection();
  438.  
  439.     var selectionStart = selection.start;
  440.     var selectionEnd = selection.end;
  441.     var scrollTop=textarea.scrollTop;
  442.  
  443.     if (selectionStart < 0 || (selectionStart == textarea.value.length && selectionStart == selectionEnd)) {    // couldn't get textarea selection via jq
  444.         if (typeof $jq(textarea).attr("selectionStartSaved") === 'string' && $jq(textarea).attr("selectionStartSaved")) {   // forgetful firefox
  445.             selectionStart = $jq(textarea).attr("selectionStartSaved");
  446.             selectionEnd = $jq(textarea).attr("selectionEndSaved");
  447.         } else {
  448.             selectionStart = getCaretPos(textarea);
  449.             selectionEnd = selectionStart;
  450.         }
  451.     }
  452.  
  453.     if( blockLevel ) {
  454.         // Block level operations apply to entire lines
  455.  
  456.         // +1 and -1 to handle end of line caret position correctly
  457.         selectionStart = textarea.value.lastIndexOf( "\n", selectionStart - 1 ) + 1;
  458.         selectionEnd = textarea.value.indexOf( "\n", selectionEnd );
  459.         if (selectionEnd < 0) {
  460.             selectionEnd = textarea.value.length;
  461.         }
  462.     }
  463.  
  464.     if (selectionStart != selectionEnd) { // has there been a selection
  465.         var newString = '';
  466.         if( perLine ) {
  467.             var lines = textarea.value.substring(selectionStart, selectionEnd).split("\n");
  468.             for( k = 0; lines.length > k; ++k ) {
  469.                 if( lines[k].length !== 0 ) {
  470.                     newString += replaceString.replace(toBeReplaced, lines[k]);
  471.                 }
  472.                 if( k != lines.length - 1 ) {
  473.                     newString += "\n";
  474.                 }
  475.             }
  476.         } else {
  477.             if (replaceSelection) {
  478.                 newString = replaceString;
  479.             } else if (replaceString.match(toBeReplaced)) {
  480.                 newString = replaceString.replace(toBeReplaced, textarea.value.substring(selectionStart, selectionEnd));
  481.             } else {
  482.                 newString = replaceString + '\n' + textarea.value.substring(selectionStart, selectionEnd);
  483.             }
  484.         }
  485.         textarea.value = textarea.value.substring(0, selectionStart)
  486.         + newString
  487.         + textarea.value.substring(selectionEnd);
  488.         setSelectionRange(textarea, selectionStart, selectionStart + newString.length);
  489.     } else { // insert at caret
  490.         textarea.value = textarea.value.substring(0, selectionStart)
  491.         + replaceString
  492.         + textarea.value.substring(selectionEnd);
  493.         setCaretToPos(textarea, selectionStart + replaceString.length);
  494.     }
  495.     textarea.scrollTop=scrollTop;
  496.  
  497.     if (hiddenParents.length) { hiddenParents.hide(); }
  498.     if (typeof auto_save_id != "undefined" && auto_save_id.length > 0 && typeof auto_save == 'function') {  auto_save(); }
  499.  
  500. }
  501.  
  502. function setUserModuleFromCombo(id, textarea) {
  503.     document.getElementById(textarea).value = document.getElementById(textarea).value
  504.                 + document.getElementById(id).options[document.getElementById(id).selectedIndex].value;
  505. }
  506.  
  507.  
  508. function toggle(foo) {
  509.     if (document.getElementById(foo).style.display == "none") {
  510.         show(foo, true, "menu");
  511.     } else {
  512.         if (document.getElementById(foo).style.display == "block") {
  513.             hide(foo, true, "menu");
  514.         } else {
  515.             show(foo, true, "menu");
  516.         }
  517.     }
  518. }
  519.  
  520. function flip_thumbnail_status(id) {
  521.     var elem = document.getElementById(id);
  522.     if ( elem.className == 'thumbnailcontener' ) {
  523.         elem.className += ' thumbnailcontenerchecked';
  524.     } else {
  525.         elem.className = 'thumbnailcontener';
  526.     }
  527. }
  528.  
  529. function flip_class(itemid, class1, class2) {
  530.     var elem = document.getElementById(itemid);
  531.     if (elem && typeof elem != 'undefined') {
  532.         elem.className = elem.className == class1 ? class2 : class1;
  533.         setCookie('flip_class_' + itemid, elem.className);
  534.     }
  535. }
  536.  
  537. function tikitabs(focus,max,ini) {
  538.     var didit = false, didone = false;
  539.     if (!ini) {
  540.         ini = 1;
  541.     }
  542.     for (var i = ini; i <= max; i++) {
  543.         var tabname = 'tab' + i;
  544.         var content = 'content' + i;
  545.         if (document.getElementById(tabname) && typeof document.getElementById(tabname) != 'undefined') {
  546.             if (i == focus) {
  547.                 // show(tabname);
  548.                 show(content);
  549.                 setCookie('tab',focus);
  550.                 document.getElementById(tabname).className = 'tabmark';
  551.                 document.getElementById(tabname).className += ' tabactive';
  552.                 didit = true;
  553.             } else {
  554.                 // hide(tabname);
  555.                 hide(content);
  556.                 document.getElementById(tabname).className = 'tabmark';
  557.                 document.getElementById(tabname).className += ' tabinactive';
  558.             }
  559.             if (!didone) { didone = true; }
  560.         }
  561.     }
  562.     if (didone && !didit) {
  563.         show('content'+ini);
  564.         setCookie('tab',ini);
  565.         document.getElementById('tab'+ini).className = 'tabmark';
  566.         document.getElementById('tab'+ini).className += ' tabactive';
  567.     }
  568. }
  569.  
  570. /* foo: name of the menu
  571.  * def: menu type (e:extended, c:collapsed, f:fixed)
  572.  * the menu is collapsed function of its cookie: if no cookie is set, the def is used
  573.  */
  574. function setfolderstate(foo, def, img, status) {
  575.     if (!status) {
  576.         status = getCookie(foo, "menu", "o");
  577.     }
  578.     if (!img) {
  579.         if (document.getElementsByName('icn' + foo)[0].src.search(/[\\\/]/)) {
  580.             img = document.getElementsByName('icn' + foo)[0].src.replace(/.*[\\\/]([^\\\/]*)$/, "$1");
  581.         } else {
  582.             img = 'folder.png';
  583.         }
  584.     }
  585.     var src = img; // default
  586.     if (status == 'c') {
  587.         hide(foo, false, "menu");
  588.     } else {
  589.         show(foo, false, "menu");
  590.     }
  591.     if (status == 'c' && def != 'd') { /* need to change the open icon to a close one*/
  592.         src = src.replace(/^o/, '');
  593.     } else if (status != 'c' && def == 'd' && src.indexOf('o') !== 0) { /* need to change the close icon to an open one */
  594.         src = 'o' + img;
  595.     }
  596.     document.getElementsByName('icn' + foo)[0].src = document.getElementsByName('icn' + foo)[0].src.replace(/[^\\\/]*$/, src);
  597. }
  598.  
  599. function setheadingstate(foo) {
  600.     var status = getCookie(foo, "showhide_headings");
  601.     if (status == "o") {
  602.         show(foo);
  603.         collapseSign("flipper" + foo);
  604.     } else /* if (status == "c") */ {
  605.         if (!document.getElementById(foo).style.display == "none") {
  606.             hide(foo);
  607.             expandSign("flipper" + foo);
  608.         }
  609.     }
  610. }
  611.  
  612. function setsectionstate(foo, def, img, status) {
  613.     if (!status) {
  614.         status = getCookie(foo, "menu", "o");
  615.     }
  616.     if (status == "o") {
  617.         show(foo);
  618.         if (img) { src = "o" + img; }
  619.     } else if (status != "c" && def != 'd') {
  620.         show(foo);
  621.         if (img) { src = "o" + img; }
  622.     } else /* if (status == "c") */ {
  623.         hide(foo);
  624.         if (img) { src = img; }
  625.     }
  626.     if (img && document.getElementsByName('icn' + foo).length) {
  627.         document.getElementsByName('icn' + foo)[0].src = document.getElementsByName('icn' + foo)[0].src.replace(/[^\\\/]*$/, src);
  628.     }
  629. }
  630.  
  631. function icntoggle(foo, img) {
  632.     if (!img) {
  633.         if (document.getElementsByName('icn' + foo)[0].src.search(/[\\\/]/)) {
  634.             img = document.getElementsByName('icn' + foo)[0].src.replace(/.*[\\\/]([^\\\/]*)$/, "$1");
  635.         } else {
  636.             img = 'folder.png';
  637.         }
  638.     }
  639.     if (document.getElementById(foo).style.display == "none") {
  640.         show(foo, true, "menu");
  641.         document.getElementsByName('icn' + foo)[0].src = document.getElementsByName('icn' + foo)[0].src.replace(/[^\\\/]*$/, 'o' + img);
  642.  
  643.     } else {
  644.         hide(foo, true, "menu");
  645.         img = img.replace(/(^|\/|\\)o(.*)$/, '$1$2');
  646.         document.getElementsByName('icn' + foo)[0].src = document.getElementsByName('icn' + foo)[0].src.replace(/[^\\\/]*$/, img);
  647.     }
  648. }
  649.  
  650. //Initialize a cross-browser XMLHttpRequest object.
  651. //The object return has to be sent using send(). More parameters can be
  652. //given.
  653. //callback - The function that will be called when the response arrives
  654. //First parameter will be the status
  655. //(HTTP Response Code [200,403, 404, ...])
  656. //method - GET or POST
  657. //url - The URL to open
  658. function getHttpRequest( method, url, async )
  659. {
  660.     if( async === undefined ) {
  661.         async = false;
  662.     }
  663.     var request;
  664.  
  665.     if( window.XMLHttpRequest ) {
  666.         request = new XMLHttpRequest();
  667.     } else if( window.ActiveXObject )
  668.     {
  669.         try
  670.         {
  671.             request = new ActiveXObject( "Microsoft.XMLHTTP" );
  672.         }
  673.         catch( ex )
  674.         {
  675.             request = new ActiveXObject("MSXML2.XMLHTTP");
  676.         }
  677.     }
  678.     else {
  679.         return false;
  680.     }
  681.     if( !request ) {
  682.         return false;
  683.     }
  684.     request.open( method, url, async );
  685.  
  686.     return request;
  687. }
  688.  
  689. //name - name of the cookie
  690. //value - value of the cookie
  691. // [expires] - expiration date of the cookie (defaults to end of current session)
  692. // [path] - path for which the cookie is valid (defaults to path of calling document)
  693. // [domain] - domain for which the cookie is valid (defaults to domain of calling document)
  694. // [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
  695. //* an argument defaults when it is assigned null as a placeholder
  696. //* a null placeholder is not required for trailing omitted arguments
  697. function setSessionVar(name,value) {
  698.     var request = getHttpRequest( "GET", "tiki-cookie-jar.php?" + name + "=" + escape(value));
  699.     request.send('');
  700.     tiki_cookie_jar[name] = value;
  701. }
  702.  
  703. function setCookie(name, value, section, expires, path, domain, secure) {
  704.     if (getCookie(name, section) == value) {
  705.         return true;
  706.     }
  707.     if (!expires) {
  708.         expires = new Date();
  709.         expires.setFullYear(expires.getFullYear() + 1);
  710.     }
  711.     if (feature_no_cookie == 'y') {
  712.         var request = getHttpRequest( "GET", "tiki-cookie-jar.php?" + name + "=" + escape( value ) );
  713.         try {
  714.             request.send('');
  715.             // alert("XMLHTTP/set"+request.readyState+request.responseText);
  716.             tiki_cookie_jar[name] = value;
  717.             return true;
  718.         }
  719.         catch( ex ) {
  720.             setCookieBrowser(name, value, section, expires, path, domain, secure);
  721.             return false;
  722.         }
  723.     }
  724.     else {
  725.         setCookieBrowser(name, value, section, expires, path, domain, secure);
  726.         return true;
  727.     }
  728. }
  729. function setCookieBrowser(name, value, section, expires, path, domain, secure) {
  730.     if (section) {
  731.         valSection = getCookie(section);
  732.         name2 = "@" + name + ":";
  733.         if (valSection) {
  734.             if (new RegExp(name2).test(valSection)) {
  735.                 valSection  = valSection.replace(new RegExp(name2 + "[^@;]*"), name2 + value);
  736.             } else {
  737.                 valSection = valSection + name2 + value;
  738.             }
  739.             setCookieBrowser(section, valSection, null, expires, path, domain, secure);
  740.         }
  741.         else {
  742.             valSection = name2+value;
  743.             setCookieBrowser(section, valSection, null, expires, path, domain, secure);
  744.         }
  745.  
  746.     }
  747.     else {
  748.         var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "")
  749.         + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
  750.         document.cookie = curCookie;
  751.     }
  752. }
  753.  
  754. //name - name of the desired cookie
  755. //section - name of group of cookies or null
  756. // * return string containing value of specified cookie or null if cookie does not exist
  757. function getCookie(name, section, defval) {
  758.     if( feature_no_cookie == 'y' && (window.XMLHttpRequest || window.ActiveXObject) && typeof tiki_cookie_jar != "undefined" && tiki_cookie_jar.length > 0) {
  759.         if (typeof tiki_cookie_jar[name] == "undefined") {
  760.             return defval;
  761.         }
  762.         return tiki_cookie_jar[name];
  763.     }
  764.     else {
  765.         return getCookieBrowser(name, section, defval);
  766.     }
  767. }
  768. function getCookieBrowser(name, section, defval) {
  769.     if (section) {
  770.         var valSection = getCookieBrowser(section);
  771.         if (valSection) {
  772.             var name2 = "@"+name+":";
  773.             var val = valSection.match(new RegExp(name2 + "([^@;]*)"));
  774.             if (val) {
  775.                 return unescape(val[1]);
  776.             } else {
  777.                 return null;
  778.             }
  779.         } else {
  780.             return defval;
  781.         }
  782.     } else {
  783.         var dc = document.cookie;
  784.  
  785.         var prefix = name + "=";
  786.         var begin = dc.indexOf("; " + prefix);
  787.  
  788.         if (begin == -1) {
  789.             begin = dc.indexOf(prefix);
  790.  
  791.             if (begin !== 0) {
  792.                 return null;
  793.             }
  794.         } else { begin += 2; }
  795.  
  796.         var end = document.cookie.indexOf(";", begin);
  797.  
  798.         if (end == -1) {
  799.             end = dc.length;
  800.         }
  801.         return unescape(dc.substring(begin + prefix.length, end));
  802.     }
  803. }
  804.  
  805. //name - name of the cookie
  806. //[path] - path of the cookie (must be same as path used to create cookie)
  807. // [domain] - domain of the cookie (must be same as domain used to create cookie)
  808. // * path and domain default if assigned null or omitted if no explicit argument proceeds
  809. function deleteCookie(name, section, expires, path, domain, secure) {
  810.     if (section) {
  811.         valSection = getCookieBrowser(section);
  812.         name2 = "@" + name + ":";
  813.         if (valSection) {
  814.             if (new RegExp(name2).test(valSection)) {
  815.                 valSection  = valSection.replace(new RegExp(name2 + "[^@;]*"), "");
  816.                 setCookieBrowser(section, valSection, null, expires, path, domain, secure);
  817.             }
  818.         }
  819.     }
  820.     else {
  821.  
  822. //      if( !setCookie( name, '', 0, path, domain ) ) {
  823. //      if (getCookie(name)) {
  824.         document.cookie = name + "="
  825.         + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  826. //      }
  827.     }
  828. }
  829.  
  830. //date - any instance of the Date object
  831. //* hand all instances of the Date object to this function for "repairs"
  832. function fixDate(date) {
  833.     var base = new Date(0);
  834.  
  835.     var skew = base.getTime();
  836.  
  837.     if (skew > 0) {
  838.         date.setTime(date.getTime() - skew);
  839.     }
  840. }
  841.  
  842.  
  843. //Expand/collapse lists
  844.  
  845. function flipWithSign(foo) {
  846.     if (document.getElementById(foo).style.display == "none") {
  847.         show(foo, true, "showhide_headings");
  848.         collapseSign("flipper" + foo);
  849.     } else {
  850.         hide(foo, true, "showhide_headings");
  851.         expandSign("flipper" + foo);
  852.     }
  853. }
  854.  
  855. //set the state of a flipped entry after page reload
  856. function setFlipWithSign(foo) {
  857.     if (getCookie(foo, "showhide_headings", "o") == "o") {
  858.         collapseSign("flipper" + foo);
  859.  
  860.         show(foo);
  861.     } else {
  862.         expandSign("flipper" + foo);
  863.  
  864.         hide(foo);
  865.     }
  866. }
  867.  
  868. function expandSign(foo) {
  869.     if (document.getElementById(foo)) {
  870.         document.getElementById(foo).firstChild.nodeValue = "[+]";
  871.     }
  872. }
  873.  
  874. function collapseSign(foo) {
  875.     if (document.getElementById(foo)) {
  876.         document.getElementById(foo).firstChild.nodeValue = "[-]";
  877.     }
  878. } // flipWithSign()
  879.  
  880. //Set client timezone
  881. //Added 7/25/03 by Jeremy Jongsma ([email protected])
  882. //Updated 11/04/07 by Nyloth to get timezone name instead of timezone offset
  883. //Updated feb 2010 by jonnyb (had stopped working)
  884.  
  885. function inArray(item, array) {
  886.     for (var i in array) {
  887.         if (array[i] === item) {
  888.             return i;
  889.         }
  890.     }
  891.     return false;
  892. }
  893.  
  894. var allTimeZoneCodes = ["A","ACDT","ACST","ADT","AEDT","AEST","AKDT","AKST","AST","AWDT","AWST","B","BST","C","CDT","CDT","CEDT","CEST","CET","CST","CST","CST","CXT","D","E","EDT","EDT","EEDT","EEST","EET","EST","EST","EST","F","G","GMT","H","HAA","HAC","HADT","HAE","HAP","HAR","HAST","HAT","HAY","HNA","HNC","HNE","HNP","HNR","HNT","HNY","HST","I","IST","K","L","M","MDT","MESZ","MEZ","MSD","MSK","MST","N","NDT","NFT","NST","O","P","PDT","PST","Q","R","S","T","U","UTC","V","W","WDT","WEDT","WEST","WET","WST","WST","X","Y","Z"];
  895. var expires = new Date();
  896. var local_tz = "";
  897. var local_dates = expires.toLocaleString().match(/[A-Za-z]{1,4}/g); // split into alpha strings
  898. if (local_dates !== null) {
  899.     for (var i = local_dates.length - 1; i > -1; i--) {                 // iterate through backwards
  900.         var cx = inArray(local_dates[i], allTimeZoneCodes);
  901.         if (cx) {
  902.             local_tz = allTimeZoneCodes[cx];                            // until you find a matching timezone
  903.             break;
  904.         }
  905.     }
  906. }
  907. if (!local_tz) {                                                    // some browsers only do the tz in toString()
  908.     local_dates = expires.toString().match(/[A-Za-z]{1,4}/g);
  909.     for (i = local_dates.length - 1; i > -1; i--) {
  910.         cx = inArray(local_dates[i], allTimeZoneCodes);
  911.         if (cx) {
  912.             local_tz = allTimeZoneCodes[cx];
  913.             break;
  914.         }
  915.     }
  916. }
  917. expires.setFullYear(expires.getFullYear() + 1);
  918. setCookie("local_tz", local_tz, null, expires, "/");
  919.  
  920. //function added for use in navigation dropdown
  921. //example :
  922. //<select name="anything" onchange="go(this);">
  923. //<option value="http://tikiwiki.org">tikiwiki.org</option>
  924. //</select>
  925. function go(o) {
  926.     if (o.options[o.selectedIndex].value !== "") {
  927.         location = o.options[o.selectedIndex].value;
  928.  
  929.         o.options[o.selectedIndex] = 1;
  930.     }
  931.  
  932.     return false;
  933. }
  934.  
  935.  
  936. //function: targetBlank
  937. //desc: opens a new window, XHTML-compliant replacement of the "TARGET" tag
  938. //added by: Ralf Lueders ([email protected])
  939. //date: Sep 7, 2003
  940. //params: url: the url for the new window
  941. //mode='nw': new, full-featured browser window
  942. //mode='popup': new windows, no features & buttons
  943.  
  944. function targetBlank(url,mode) {
  945.     var features = 'menubar=yes,toolbar=yes,location=yes,directories=yes,fullscreen=no,titlebar=yes,hotkeys=yes,status=yes,scrollbars=yes,resizable=yes';
  946.     switch (mode) {
  947.     // new full-equipped browser window
  948.     case 'nw':
  949.         break;
  950.         // new popup-window
  951.     case 'popup':
  952.         features = 'menubar=no,toolbar=no,location=no,directories=no,fullscreen=no,titlebar=no,hotkeys=no,status=no,scrollbars=yes,resizable=yes';
  953.         break;
  954.     default:
  955.         break;
  956.     }
  957.     blankWin = window.open(url,'_blank',features);
  958. }
  959.  
  960. //function: confirmTheLink
  961. //desc: pop up a dialog box to confirm the action
  962. //added by: Franck Martin
  963. //date: Oct 12, 2003
  964. //params: theLink: The link where it is called from
  965. //params: theMsg: The message to display
  966. function confirmTheLink(theLink, theMsg)
  967. {
  968.     // Confirmation is not required if browser is Opera (crappy js implementation)
  969.     if (typeof(window.opera) != 'undefined') {
  970.         return true;
  971.     }
  972.  
  973.     var is_confirmed = confirm(theMsg);
  974.     // if (is_confirmed) {
  975.     // theLink.href += '&amp;is_js_confirmed=1';
  976.     // }
  977.  
  978.     return is_confirmed;
  979. }
  980.  
  981. /** \brief: modif a textarea dimension
  982.  * \elementId = textarea idea
  983.  * \height = nb pixels to add to the height (the number can be negative)
  984.  * \width = nb pixels to add to the width
  985.  * \formid = form id (needs to have 2 input rows and cols
  986.  **/
  987. function textareasize(elementId, height, width, formId) {
  988.     textarea = $jq(getElementById(elementId))[0];
  989.     form1 = textarea.form;
  990.     if (textarea && height !== 0 && textarea.rows + height > 5) {
  991.         textarea.rows += height;
  992.         if (form1.rows) {
  993.             form1.rows.value = textarea.rows;
  994.         }
  995.     }
  996.     if (textarea && width !== 0 && textarea.cols + width > 10) {
  997.         textarea.cols += width;
  998.         if (form1.cols) {
  999.             form1.cols.value = textarea.cols;
  1000.         }
  1001.     }
  1002. }
  1003.  
  1004.  
  1005. /** \brief: insert img tag in textarea
  1006.  *
  1007.  */
  1008. function insertImgFile(elementId, fileId, oldfileId,type,page,attach_comment) {
  1009.     textarea = getElementById(elementId);
  1010.     fileup   = getElementById(fileId);
  1011.     oldfile  = getElementById(oldfileId);
  1012.     prefixEl = getElementById("prefix");
  1013.     prefix   = "img/wiki_up/";
  1014.  
  1015.     if (!textarea || ! fileup) {
  1016.         return;
  1017.     }
  1018.     if ( prefixEl) { prefix= prefixEl.value; }
  1019.  
  1020.     filename = fileup.value;
  1021.     oldfilename = oldfile.value;
  1022.  
  1023.     if (filename == oldfilename || filename === "" ) { // insert only if name really changed
  1024.         return;
  1025.     }
  1026.     oldfile.value = filename;
  1027.  
  1028.     if (filename.indexOf("/")>=0) { // unix
  1029.         dirs = filename.split("/");
  1030.         filename = dirs[dirs.length-1];
  1031.     }
  1032.     if (filename.indexOf("\\")>=0) { // dos
  1033.         dirs = filename.split("\\");
  1034.         filename = dirs[dirs.length-1];
  1035.     }
  1036.     if (filename.indexOf(":")>=0) { // mac
  1037.         dirs = filename.split(":");
  1038.         filename = dirs[dirs.length-1];
  1039.     }
  1040.     // @todo - here's a hack: we know its ending up in img/wiki_up.
  1041.     // replace with dyn. variable once in a while to respect the tikidomain
  1042.     if (type == "file") {
  1043.         str = "{file name=\""+filename + "\"";
  1044.         var desc = getElementById(attach_comment).value;
  1045.         if (desc) {
  1046.             str = str + " desc=\"" + desc + "\"";
  1047.         }
  1048.         str = str + "}";
  1049.     } else {
  1050.         str = "{img src=\"img/wiki_up/" + filename + "\" }\n";
  1051.     }
  1052.     insertAt(elementId, str);
  1053. }
  1054.  
  1055. /* add new upload image form in page edition */
  1056. var img_form_count = 2;
  1057. function addImgForm() {
  1058.     var new_text = document.createElement('span');
  1059.     new_text.setAttribute('id','picfile' + img_form_count);
  1060.     new_text.innerHTML = '<input name=\'picfile' + img_form_count + '\' type=\'file\' onchange=\'javascript:insertImgFile("editwiki","picfile' + img_form_count + '","hasAlreadyInserted","img")\'/><br />';
  1061.     document.getElementById('new_img_form').appendChild(new_text);
  1062.     needToConfirm = true;
  1063.     img_form_count ++;
  1064. }
  1065.  
  1066. /*
  1067.  * opens wiki 3d browser
  1068.  */
  1069. function wiki3d_open (page, width, height) {
  1070.     window.open('tiki-wiki3d.php?page='+page,'wiki3d','width='+width+',height='+height+',scrolling=no');
  1071. }
  1072.  
  1073. /* some little email protection */
  1074. function protectEmail(nom, domain, sep) {
  1075.     return '<a class="wiki" href="mailto:'+nom+'@'+domain+'">'+nom+sep+domain+'</a>';
  1076. }
  1077.  
  1078. browser();
  1079.  
  1080. //This was added to allow wiki3d to change url on tiki's window
  1081. window.name = 'tiki';
  1082.  
  1083. /* Function to add image from filegals in non wysiwyg editor */
  1084. /* must be here when ajax is activated */
  1085. function SetMyUrl(area,url) {
  1086.     var str, myurl = url.replace(/.*\/([^\/]*)$/, '$1'); /* make relative path from the absolute url */
  1087.     if (area == 'fgal_picker' ) {
  1088.         str = myurl;
  1089.         getElementById(area).value = str;
  1090.         window.focus();
  1091.         return true;
  1092.     } else {
  1093.         var fileId = myurl.match(/display(\d*)$/);  // sefurl
  1094.         if (!fileId || fileId.length < 2 || !fileId[1]) {
  1095.             fileId = myurl.match(/fileId=(\d*)/); // normurl
  1096.         }
  1097.         if ( area == 'fgal_picker_id' ) {
  1098.             str = fileId[1];   
  1099.             getElementById(area).value = str;
  1100.             window.focus();
  1101.             return true;
  1102.         } else {
  1103.         if (fileId && fileId.length >= 1) {
  1104.             fileId = fileId[1];
  1105.             str = "{img fileId=\""+fileId+"\" thumb=\"y\" alt=\"\" rel=\"box[g]\"} ";
  1106.         } else {
  1107.             str = "{img src=\""+myurl+"\" alt=\"\" link=\""+myurl+"\" rel=\"box[g]\"} ";
  1108.         }
  1109.         }
  1110.     }
  1111.     insertAt(area, str);
  1112.     window.focus();
  1113. }
  1114.  
  1115. if (typeof fgals_window == "undefined") {
  1116.     fgals_window = null;
  1117. }
  1118. function openFgalsWindow(filegal_manager_url, area_name) {
  1119.     if(fgals_window && typeof fgals_window.document != "undefined" && typeof fgals_window.document != "unknown" && !fgals_window.closed) {
  1120.         fgals_window.focus();
  1121.     } else {
  1122.         fgals_window=window.open(filegal_manager_url,'_blank','menubar=1,scrollbars=1,resizable=1,height=500,width=800,left=50,top=50');
  1123.     }
  1124. }
  1125.  
  1126. /* Count the number of words (spearated with space) */
  1127. function wordCount(maxSize, source, cpt, message) {
  1128.     var formcontent = source.value;
  1129.     str = formcontent.replace(/^\s+|\s+$/g, '') ;
  1130.     formcontent = str.split(/[^\S]+/);
  1131.     if (maxSize > 0 && formcontent.length > maxSize) {
  1132.         alert(message);
  1133.         source.value = source.value.substr(0, source.value.length-1);
  1134.     } else {
  1135.         document.getElementById(cpt).value = formcontent.length;
  1136.     }
  1137. }
  1138. function charCount(maxSize, source, cpt, message) {
  1139.     var formcontent = source.value;
  1140.     if (maxSize > 0 && formcontent.length > maxSize) {
  1141.         alert(message);
  1142.         source.value = source.value.substr(0, maxSize);
  1143.     } else {
  1144.         document.getElementById(cpt).value = formcontent.length;
  1145.     }
  1146. }
  1147.  
  1148. function show_plugin_form( type, index, pageName, pluginArgs, bodyContent )
  1149. {
  1150.     var target = document.getElementById( type + index );
  1151.     var content = target.innerHTML;
  1152.  
  1153.     var form = build_plugin_form( type, index, pageName, pluginArgs, bodyContent );
  1154.  
  1155.     target.innerHTML = '';
  1156.     target.appendChild( form );
  1157. }
  1158.  
  1159. /* wikiplugin editor */
  1160. function popup_plugin_form( area_name, type, index, pageName, pluginArgs, bodyContent, edit_icon )
  1161. {
  1162.     if ($jq.ui) {
  1163.         return popupPluginForm( area_name, type, index, pageName, pluginArgs, bodyContent, edit_icon );
  1164.     }
  1165.     var container = document.createElement( 'div' );
  1166.     container.className = 'plugin-form-float';
  1167.     var textarea = getElementById(area_name);
  1168.  
  1169.     var minimize = document.createElement( 'a' );
  1170.     var icon = document.createElement( 'img' );
  1171.     minimize.appendChild( icon );
  1172.     minimize.href = 'javascript:void(0)';
  1173.     container.appendChild( minimize );
  1174.     icon.src = 'pics/icons/cross.png';
  1175.     icon.style.position = 'absolute';
  1176.     icon.style.top = '5px';
  1177.     icon.style.right = '5px';
  1178.     icon.style.border = 'none';
  1179.  
  1180.     if (!index) { index = 0; }
  1181.     if (!pageName) { pageName = ''; }
  1182.     if (!pluginArgs) { pluginArgs = {}; }
  1183.     if (!bodyContent) {
  1184.         if (document.getTASelection) {
  1185.             bodyContent = document.getTASelection(textarea);
  1186.         } else if (window.getTASelection) {
  1187.             bodyContent = window.getTASelection(textarea);
  1188.         } else if (document.selection) {
  1189.             bodyContent = document.selection.createRange().text;
  1190.         } else {
  1191.             bodyContent = '';
  1192.         }
  1193.     }
  1194.  
  1195.     var form = build_plugin_form(
  1196.             type,
  1197.             index,
  1198.             pageName,
  1199.             pluginArgs,
  1200.             bodyContent
  1201.     );
  1202.  
  1203.     form.onsubmit = function()
  1204.     {
  1205.         var meta = tiki_plugins[type];
  1206.         var params = [];
  1207.         var edit = edit_icon;
  1208.  
  1209.         for(i=0; i<form.elements.length; i++){
  1210.             element = form.elements[i].name;
  1211.  
  1212.             var matches = element.match(/params\[(.*)\]/);
  1213.  
  1214.             if (matches === null) {
  1215.                 // it's not a parameter, skip
  1216.                 continue;
  1217.             }
  1218.             var param = matches[1];
  1219.  
  1220.             var val = form.elements[i].value;
  1221.  
  1222.             if( val !== '' ) {
  1223.                 params.push( param + '="' + val + '"' );
  1224.             }
  1225.         }
  1226.  
  1227.         var blob = '{' + type.toUpperCase() + '(' + params.join(',') + ')}' + (typeof form.content != 'undefined' ? form.content.value : '') + '{' + type.toUpperCase() + '}';
  1228.  
  1229.         if (edit) {
  1230.             return true;
  1231.         } else {
  1232.             insertAt( area_name, blob );
  1233.             document.body.removeChild( container );
  1234.         }
  1235.         return false;
  1236.     };
  1237.  
  1238.     minimize.onclick = function() {
  1239.         var edit = edit_icon;
  1240.         if (edit) {
  1241.             edit.style.display = 'inline';
  1242.         }
  1243.         document.body.removeChild( container );
  1244.     };
  1245.  
  1246.     document.body.appendChild( container );
  1247.     if (edit_icon) {
  1248.         edit_icon.style.display = 'none';
  1249.     }
  1250.     container.appendChild( form );
  1251. }
  1252.  
  1253. function build_plugin_form( type, index, pageName, pluginArgs, bodyContent )
  1254. {
  1255.     var form = document.createElement( 'form' );
  1256.     form.method = 'post';
  1257.     form.action = 'tiki-wikiplugin_edit.php';
  1258.     form.className  = 'wikiplugin_edit';
  1259.  
  1260.     var hiddenPage = document.createElement( 'input' );
  1261.     hiddenPage.type = 'hidden';
  1262.     hiddenPage.name = 'page';
  1263.     hiddenPage.value = pageName;
  1264.     form.appendChild( hiddenPage );
  1265.  
  1266.     var hiddenType = document.createElement( 'input' );
  1267.     hiddenType.type = 'hidden';
  1268.     hiddenType.name = 'type';
  1269.     hiddenType.value = type;
  1270.     form.appendChild( hiddenType );
  1271.  
  1272.     var hiddenIndex = document.createElement( 'input' );
  1273.     hiddenIndex.type = 'hidden';
  1274.     hiddenIndex.name = 'index';
  1275.     hiddenIndex.value = index;
  1276.     form.appendChild( hiddenIndex );
  1277.  
  1278.     var meta = tiki_plugins[type];
  1279.  
  1280.     var header = document.createElement( 'h3' );
  1281.     header.innerHTML = meta.name;
  1282.     form.appendChild( header );
  1283.  
  1284.     var desc = document.createElement( 'div' );
  1285.     desc.innerHTML = meta.description;
  1286.     form.appendChild( desc );
  1287.  
  1288.     var table = document.createElement( 'table' );
  1289.     table.className = 'normal';
  1290.     form.appendChild( table );
  1291.  
  1292.     var potentiallyExtraPluginArgs = pluginArgs;
  1293.  
  1294.     var rowNumber = 0;
  1295.     for( param in meta.params )
  1296.     {
  1297.         if( typeof(meta.params[param]) != 'object' || meta.params[param].name == 'array' ) {
  1298.             continue;
  1299.         }
  1300.         var row = table.insertRow( rowNumber++ );
  1301.         build_plugin_form_row(row, param, meta.params[param].name, meta.params[param].required, pluginArgs[param], meta.params[param].description, meta.params[param]);
  1302.  
  1303.         delete potentiallyExtraPluginArgs[param];
  1304.     }
  1305.  
  1306.     for( extraArg in potentiallyExtraPluginArgs) {
  1307.         if (extraArg === '') {
  1308.             // TODO HACK: See bug 2499 http://dev.tikiwiki.org/tiki-view_tracker_item.php?itemId=2499
  1309.             continue;
  1310.         }
  1311.  
  1312.         row = table.insertRow( rowNumber++ );
  1313.         build_plugin_form_row(row, extraArg, extraArg, 'extra', pluginArgs[extraArg], extraArg);
  1314.     }
  1315.  
  1316.     var bodyRow = table.insertRow(rowNumber++);
  1317.     var bodyCell = bodyRow.insertCell(0);
  1318.     var bodyField = document.createElement( 'textarea' );
  1319.     bodyField.cols = '70';
  1320.     bodyField.rows = '12';
  1321.     var bodyDesc = document.createElement( 'div' );
  1322.  
  1323.     if( meta.body ) {
  1324.         bodyDesc.innerHTML = meta.body;
  1325.     } else {
  1326.         bodyRow.style.display = 'none';
  1327.     }
  1328.     bodyField.name = 'content';
  1329.     bodyField.value = bodyContent;
  1330.  
  1331.     bodyRow.className = 'formcolor';
  1332.  
  1333.     bodyCell.appendChild( bodyDesc );
  1334.     bodyCell.appendChild( bodyField );
  1335.     bodyCell.colSpan = '2';
  1336.  
  1337.     var submitRow = table.insertRow(rowNumber++);
  1338.     var submitCell = submitRow.insertCell(0);
  1339.     var submit = document.createElement( 'input' );
  1340.  
  1341.     submit.type = 'submit';
  1342.     submitCell.colSpan = 2;
  1343.     submitCell.appendChild( submit );
  1344.     submitCell.className = 'submit';
  1345.  
  1346.     return form;
  1347. }
  1348.  
  1349.  
  1350. function build_plugin_form_row(row, name, label_name, requiredOrSpecial, value, description, paramDef)
  1351. {
  1352.  
  1353.     var label = row.insertCell( 0 );
  1354.     var field = row.insertCell( 1 );
  1355.     row.className = 'formcolor';
  1356.  
  1357.     label.innerHTML = label_name;
  1358.     switch ( requiredOrSpecial ) {
  1359.     case (true):  // required flag
  1360.         label.style.fontWeight = 'bold';
  1361.     break;
  1362.     case ('extra') :
  1363.         label.style.fontStyle = 'italic';
  1364.     }
  1365.  
  1366.     var input;
  1367.     if (paramDef && paramDef.options) {
  1368.         input = document.createElement('select');
  1369.         input.name = 'params[' + name + ']';
  1370.         for (var o = 0; o < paramDef.options.length; o++) {
  1371.             var opt = document.createElement('option');
  1372.             opt.value = paramDef.options[o].value;
  1373.             var opt_text = document.createTextNode(paramDef.options[o].text);
  1374.             opt.appendChild(opt_text);
  1375.             if (value && opt.value == value) {
  1376.                 opt.selected = true;
  1377.             }
  1378.             input.appendChild(opt);
  1379.         }
  1380.     } else {
  1381.         input = document.createElement('input');
  1382.         input.type = 'text';
  1383.         input.name = 'params[' + name + ']';
  1384.         if (value) {
  1385.             input.value = value;
  1386.         }
  1387.     }
  1388.     var desc = document.createElement( 'div' );
  1389.     desc.style.fontSize = 'x-small';
  1390.     desc.innerHTML = description;
  1391.  
  1392.     field.appendChild( input );
  1393.     if (paramDef && paramDef.type == 'image') {
  1394.         icon = document.createElement( 'img' );
  1395.         icon.src = 'pics/icons/image.png';
  1396.         input.id = paramDef.area ? paramDef.area : 'fgal_picker';
  1397.         icon.onclick = function() {openFgalsWindowArea(paramDef.area ? paramDef.area :'fgal_picker');};
  1398.         field.appendChild( icon );
  1399.     }
  1400.     field.appendChild( desc );
  1401.  
  1402.     if (paramDef && paramDef.filter) {
  1403.         if (paramDef.filter == "pagename") {
  1404.             $jq(input).tiki("autocomplete", "pagename");
  1405.         } else if (paramDef.filter == "groupname") {
  1406.             $jq(input).tiki("autocomplete", "groupname", {multiple: true, multipleSeparator: "|"});
  1407.         } else if (paramDef.filter == "username") {
  1408.             $jq(input).tiki("autocomplete", "username", {multiple: true, multipleSeparator: "|"});
  1409.         } else if (paramDef.filter == "date") {
  1410.             $jq(input).tiki("datepicker");
  1411.         }
  1412.     }
  1413.  
  1414. }
  1415.  
  1416. function openFgalsWindowArea(area) {
  1417.     if (typeof fgals_window == "undefined") {
  1418.         var fgals_window = null;
  1419.     }
  1420.     if(fgals_window && fgals_window.document) {
  1421.         fgals_window.focus();
  1422.     } else {
  1423.         fgals_window=window.open('tiki-list_file_gallery.php?filegals_manager='+area,'_blank','menubar=1,scrollbars=1,resizable=1,height=500,width=800,left=50,top=50');
  1424.     }
  1425. }
  1426.  
  1427.  
  1428. //Password strength
  1429. //Based from code by:
  1430. //Matthew R. Miller - 2007
  1431. //www.codeandcoffee.com
  1432. //originally released as "free software license"
  1433.  
  1434. /*
  1435.  * Password Strength Algorithm:
  1436.  *
  1437.  * Password Length: 5 Points: Less than 4 characters 10 Points: 5 to 7
  1438.  * characters 25 Points: 8 or more
  1439.  *
  1440.  * Letters: 0 Points: No letters 10 Points: Letters are all lower case 20
  1441.  * Points: Letters are upper case and lower case
  1442.  *
  1443.  * Numbers: 0 Points: No numbers 10 Points: 1 number 20 Points: 3 or more
  1444.  * numbers
  1445.  *
  1446.  * Characters: 0 Points: No characters 10 Points: 1 character 25 Points: More
  1447.  * than 1 character
  1448.  *
  1449.  * Bonus: 2 Points: Letters and numbers 3 Points: Letters, numbers, and
  1450.  * characters 5 Points: Mixed case letters, numbers, and characters
  1451.  *
  1452.  * Password Text Range: >= 90: Very Secure >= 80: Secure >= 70: Very Strong >=
  1453.  * 60: Strong >= 50: Average >= 25: Weak >= 0: Very Weak
  1454.  *
  1455.  */
  1456.  
  1457.  
  1458. //Settings
  1459. // -- Toggle to true or false, if you want to change what is checked in the password
  1460. var m_strUpperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  1461. var m_strLowerCase = "abcdefghijklmnopqrstuvwxyz";
  1462. var m_strNumber = "0123456789";
  1463. var m_strCharacters = "!@#$%^&*?_~";
  1464.  
  1465. //Check password
  1466. function checkPassword(strPassword)
  1467. {
  1468.     // Reset combination count
  1469.     var nScore = 0;
  1470.  
  1471.     // Password length
  1472.     // -- Less than 4 characters
  1473.     if (strPassword.length < 5)
  1474.     {
  1475.         nScore += 5;
  1476.     }
  1477.     // -- 5 to 7 characters
  1478.     else if (strPassword.length > 4 && strPassword.length < 8)
  1479.     {
  1480.         nScore += 10;
  1481.     }
  1482.     // -- 8 or more
  1483.     else if (strPassword.length > 7)
  1484.     {
  1485.         nScore += 25;
  1486.     }
  1487.  
  1488.     // Letters
  1489.     var nUpperCount = countContain(strPassword, m_strUpperCase);
  1490.     var nLowerCount = countContain(strPassword, m_strLowerCase);
  1491.     var nLowerUpperCount = nUpperCount + nLowerCount;
  1492.     // -- Letters are all lower case
  1493.     if (nUpperCount === 0 && nLowerCount !== 0)
  1494.     {
  1495.         nScore += 10;
  1496.     }
  1497.     // -- Letters are upper case and lower case
  1498.     else if (nUpperCount !== 0 && nLowerCount !== 0)
  1499.     {
  1500.         nScore += 20;
  1501.     }
  1502.  
  1503.     // Numbers
  1504.     var nNumberCount = countContain(strPassword, m_strNumber);
  1505.     // -- 1 number
  1506.     if (nNumberCount == 1)
  1507.     {
  1508.         nScore += 10;
  1509.     }
  1510.     // -- 3 or more numbers
  1511.     if (nNumberCount >= 3)
  1512.     {
  1513.         nScore += 20;
  1514.     }
  1515.  
  1516.     // Characters
  1517.     var nCharacterCount = countContain(strPassword, m_strCharacters);
  1518.     // -- 1 character
  1519.     if (nCharacterCount == 1)
  1520.     {
  1521.         nScore += 10;
  1522.     }
  1523.     // -- More than 1 character
  1524.     if (nCharacterCount > 1)
  1525.     {
  1526.         nScore += 25;
  1527.     }
  1528.  
  1529.     // Bonus
  1530.     // -- Letters and numbers
  1531.     if (nNumberCount !== 0 && nLowerUpperCount !== 0)
  1532.     {
  1533.         nScore += 2;
  1534.     }
  1535.     // -- Letters, numbers, and characters
  1536.     if (nNumberCount !== 0 && nLowerUpperCount !== 0 && nCharacterCount !== 0)
  1537.     {
  1538.         nScore += 3;
  1539.     }
  1540.     // -- Mixed case letters, numbers, and characters
  1541.     if (nNumberCount !== 0 && nUpperCount !== 0 && nLowerCount !== 0 && nCharacterCount !== 0)
  1542.     {
  1543.         nScore += 5;
  1544.     }
  1545.  
  1546.  
  1547.     return nScore;
  1548. }
  1549.  
  1550. //Runs password through check and then updates GUI
  1551. function runPassword(strPassword, strFieldID)
  1552. {
  1553.     // Check password
  1554.     var nScore = checkPassword(strPassword);
  1555.  
  1556.     // Get controls
  1557.     var ctlBar = document.getElementById(strFieldID + "_bar");
  1558.     var ctlText = document.getElementById(strFieldID + "_text");
  1559.     if (!ctlBar || !ctlText) {
  1560.         return;
  1561.     }
  1562.     // Set new width
  1563.     ctlBar.style.width = nScore + "%";
  1564.  
  1565.     // Color and text
  1566.     // -- Very Secure
  1567.     if (nScore >= 90)
  1568.     {
  1569.         var strIcon = "<img src='pics/icons/accept.png' style='vertical-align:middle' alt='Very Secure' />";
  1570.         var strText = "Very Secure";
  1571.         var strColor = "#0ca908";
  1572.     }
  1573.     // -- Secure
  1574.     else if (nScore >= 80)
  1575.     {
  1576.         strIcon = "<img src='pics/icons/accept.png' style='vertical-align:middle' alt='Secure' />";
  1577.         strText = "Secure";
  1578.         vstrColor = "#0ca908";
  1579.     }
  1580.     // -- Very Strong
  1581.     else if (nScore >= 70)
  1582.     {
  1583.         strIcon = "<img src='pics/icons/accept.png' style='vertical-align:middle' alt='Very Strong' />";
  1584.         strText = "Very Strong";
  1585.         strColor = "#0ca908";
  1586.     }
  1587.     // -- Strong
  1588.     else if (nScore >= 60)
  1589.     {
  1590.         strIcon = "<img src='pics/icons/accept.png' style='vertical-align:middle' alt='Strong' />";
  1591.         strText = "Strong";
  1592.         strColor = "#0ca908";
  1593.     }
  1594.     // -- Average
  1595.     else if (nScore >= 40)
  1596.     {
  1597.         strIcon = " ";
  1598.         strText = "Average";
  1599.         strColor = "#e3cb00";
  1600.     }
  1601.     // -- Weak
  1602.     else if (nScore >= 25)
  1603.     {
  1604.         strIcon = "<img src='pics/icons/exclamation.png' style='vertical-align:middle' alt='Weak' />";
  1605.         strText = "Weak";
  1606.         strColor = "#ff0000";
  1607.     }
  1608.     // -- Very Weak
  1609.     else
  1610.     {
  1611.         strIcon = "<img src='pics/icons/exclamation.png' style='vertical-align:middle' alt='Very weak' />";
  1612.         strText = "Very Weak";
  1613.         strColor = "#ff0000";
  1614.     }
  1615.     ctlBar.style.backgroundColor = strColor;
  1616.     ctlText.innerHTML = "<span>"  + strIcon + " Strength: " + strText + "</span>";
  1617. }
  1618.  
  1619. //Checks a string for a list of characters
  1620. function countContain(strPassword, strCheck)
  1621. {
  1622.     // Declare variables
  1623.     var nCount = 0;
  1624.  
  1625.     for (i = 0; i < strPassword.length; i++)
  1626.     {
  1627.         if (strCheck.indexOf(strPassword.charAt(i)) > -1)
  1628.         {
  1629.             nCount++;
  1630.         }
  1631.     }
  1632.  
  1633.     return nCount;
  1634. }
  1635.  
  1636. function checkPasswordsMatch(in1, in2, el) {
  1637.     if ($jq(in1).val().length && $jq(in1).val() == $jq(in2).val()) {
  1638.         $jq(el).html("<img src='pics/icons/accept.png' style='vertical-align:middle' alt='Secure' /><em>Passwords match</em>");
  1639.         return true;
  1640.     } else {
  1641.         $jq(el).html("");
  1642.         return false;
  1643.     }
  1644. }
  1645.  
  1646. /**
  1647.  * Adds an Option to the quickpoll section.
  1648.  */
  1649. function pollsAddOption()
  1650. {
  1651.     var newOption = $jq( '<input />').attr('type', 'text').attr('name', 'options[]');
  1652.     $jq('#tikiPollsOptions').append($jq('<div></div>').append(newOption));
  1653. }
  1654.  
  1655. /**
  1656.  * toggles the quickpoll section
  1657.  */
  1658. function pollsToggleQuickOptions()
  1659. {
  1660.     $jq( '#tikiPollsQuickOptions' ).toggle();
  1661. }
  1662.  
  1663. /**
  1664.  * toggles div for droplist with Disabled option
  1665.  */
  1666.  
  1667. function hidedisabled(divid,value) {
  1668.     if(value=='disabled') {
  1669.         document.getElementById(divid).style.display = 'none';
  1670.     } else {
  1671.         document.getElementById(divid).style.display = 'block';
  1672.     }
  1673. }
  1674.  
  1675. /* for filegals */
  1676.  
  1677. function adjustThumbnails() {
  1678.     var i,j,h = 0;
  1679.     var t = document.getElementById("thumbnails").childNodes;
  1680.     for ( i = 0; i < t.length; i++ ) {
  1681.         if ( t[i].className == "thumbnailcontener" ) {
  1682.             var t2 = t[i].childNodes;
  1683.             for ( j = 0; j < t2.length; j++ ) {
  1684.                 if ( t2[j].className == "thumbnail" ) {
  1685.                     t2[j].style.height = "100%";
  1686.                     t2[j].style.overflow = "visible";
  1687.                 }
  1688.             }
  1689.             if ( t[i].offsetHeight >= h ) {
  1690.                 h = t[i].offsetHeight;
  1691.                 t[i].style.height = h+"px";
  1692.             } else if ( t[i].offsetHeight < h ) {
  1693.                 t[i].style.height = h+"px";
  1694.             }
  1695.         }
  1696.     }
  1697.     for ( i = 0; i < t.length; i++ ) {
  1698.         if ( t[i].className == "thumbnailcontener" ) {
  1699.             if ( t[i].offsetHeight <= h ) {
  1700.                 t[i].style.height = h+"px";
  1701.             } else {
  1702.                 break;
  1703.             }
  1704.         }
  1705.     }
  1706. }
  1707.  
  1708. function open_webdav(url) {
  1709.     // Works only in IE
  1710.     if (typeof ActiveXObject != 'undefined') {
  1711.         EditDocumentButton = new ActiveXObject("SharePoint.OpenDocuments.1");
  1712.         EditDocumentButton.EditDocument(url);
  1713.     } else {
  1714.         alert('Sorry Works only in IE :(');
  1715.     }
  1716. }
Advertisement
Add Comment
Please, Sign In to add comment