/* Reminder: always indent with 4 spaces (no tabs). */
// +---------------------------------------------------------------------------+
// | Geeklog 1.3                                                               |
// +---------------------------------------------------------------------------+
// | Commmon javascript functions                                              |
// |                                                                           |
// +---------------------------------------------------------------------------+
// | Copyright (C) 2005,2006 by the following authors:                         |
// |                                                                           |
// |            Blaine Lang - blaine@portalparts.com                           |
// +---------------------------------------------------------------------------+
// |                                                                           |
// | This program is free software; you can redistribute it and/or             |
// | modify it under the terms of the GNU General Public License               |
// | as published by the Free Software Foundation; either version 2            |
// | of the License, or (at your option) any later version.                    |
// |                                                                           |
// | This program is distributed in the hope that it will be useful,           |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of            |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             |
// | GNU General Public License for more details.                              |
// |                                                                           |
// | You should have received a copy of the GNU General Public License         |
// | along with this program; if not, write to the Free Software Foundation,   |
// | Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           |
// |                                                                           |
// +---------------------------------------------------------------------------+

// -------------------------------------------------------------------
// caItems(form object)
// Check All Items - generic function that can be used to check and un-check all items in a list
// Used in the Admin Lists - like on the moderation page
// -------------------------------------------------------------------
   function caItems(f) {  
       var n=f.elements.length;
       for (i=0;i<n; i++) {
           var field=f.elements[i];
           if (field.type == 'checkbox' && field.name.match("delitem")) {
                if (f.chk_selectall.checked) {
                    field.checked=true;
                } else {
                    field.checked=false;
                }
           }

       }
   }




// Basic function to show/hide (toggle) an element - pass in the elment id
    function elementToggle(id) {
        var obj = document.getElementById(id);
        if (obj.style.display == 'none') {
            obj.style.display = '';
        } else {
            obj.style.display = 'none';
        }
    }

// Basic function to show/hide an element - pass in the elment id and option.
// Where option can be: show or hide or toggle
    function elementShowHide(id,option) {
        var obj = document.getElementById(id);
        if (option == 'hide') {
            obj.style.display = 'none';
        } else if (option == 'show') {
            obj.style.display = '';
        } else if (option == 'toggle') {
            elementToggle(id);
        }
    }
	
	// Basic function to show/hide an element - pass in the elment id and option.
// Where option can be: show or hide or toggle
    function elementShowHide(id,option) {
        var obj = document.getElementById(id);
        if (option == 'hide') {
            obj.style.display = 'none';
        } else if (option == 'show') {
            obj.style.display = '';
        } else if (option == 'toggle') {
            elementToggle(id);
        }
    }
	


function getElementsByClass(searchClass,node,tag) {
        var classElements = new Array();
        if ( node == null )
                node = document;
        if ( tag == null )
                tag = '*';
        var els = node.getElementsByTagName(tag);
        var elsLen = els.length;
        var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
        for (i = 0, j = 0; i < elsLen; i++) {
                if ( pattern.test(els[i].className) ) {
                        classElements[j] = els[i];
                        j++;
                }
        }
        return classElements;
}

	
	function replacePostCommentsText(){
		var els = new Array();
		els = getElementsByClass('add-comment-replace');
		var elsLen = els.length;
		if (elsLen > 0) {
			for (var i = 0; i < elsLen; i++) {
				if (els[i].hasChildNodes()) {
					els[i].childNodes[0].innerHTML = '';
					els[i].childNodes[0].className = 'add-comment';
					els[i].childNodes[0].title = 'Add Comments';
				}
			}
		}
	}
	function replaceCommentsText(){
		var els = new Array();
		els = getElementsByClass('read-comment-replace');
		var elsLen = els.length;
		if (elsLen > 0) {
			for (var i = 0; i < elsLen; i++) {
				if (els[i].innerHTML === 'Comments (0)') {
					els[i].innerHTML = '';
				}else if (els[i].hasChildNodes()) {
					els[i].childNodes[0].innerHTML = '';
					els[i].childNodes[0].className = 'read-comment';
					els[i].childNodes[0].title = 'Read Comments';
				}
				
			}
		}
	}
	function replaceReadMoreText(){
		var theText = '';
		var els = new Array();
		els = getElementsByClass('read-more-replace');
		var elsLen = els.length;
		
		//theText += els[2].childNodes[0];
		//theText += els[2].innerHTML + ' : ';
		//alert(theText);
		
		for (var i = 0; i < elsLen; i++) {
			if (els[i].hasChildNodes()) {
				var tmp = els[i].childNodes[0];
				els[i].innerHTML = '<a class="read-more" title="Read More" href="' + tmp + '"></a>';
				//els[i].childNodes[0].innerHTML = '';
				//els[i].childNodes[0].className = 'read-more';
				//els[i].childNodes[0].title = 'Read More';
			}
		}
	}
	function initIcons(){
		replaceCommentsText();
		replacePostCommentsText();
		replaceReadMoreText();
	}
	window.onload = initIcons; 
