
/* Generic javascript class */

var generic = {
    browser : '',
    version : '',
    _init : function () {
        var t = this, d = document, w = window, na = navigator, ua = na.userAgent, i, nl, n, base, p, v;
/*
        alert(t);
    	if (t.checkIt('konqueror')) {
    		t.browser = "Konqueror";
    	}
    	else if (t.checkIt('safari')) t.browser= "Safari";
    	else if (t.checkIt('omniweb')) t.browser= "OmniWeb";
    	else if (t.checkIt('opera')) t.browser= "Opera";
    	else if (t.checkIt('webtv')) t.browser= "WebTV";
    	else if (t.checkIt('icab')) t.browser= "iCab";
    	else if (t.checkIt('msie')) t.browser= "Internet Explorer";
    	else if (!t.checkIt('compatible')) {
    		t.browser = "Netscape Navigator";
//    		t.version = d.detect.charAt(8);
    	}
    	else t.browser = "An unknown browser";

//    	if (t.version=='') t.version = detect.charAt(place + thestring.length);
        alert(t.browser);
        alert(t.version);
*/
    },
    /**
     * Function for clearing a form
     */
    clearForm : function(fo) {
        o=fo.getElementsByTagName('input');
        for (i=0;i<o.length;i++){
            if (o[i].type!='submit') o[i].value='';
        }
        o=fo.getElementsByTagName('select');
        for(i=0;i<o.length;i++){
            o[i].selectedIndex=0;
        }
        return true;
    },
    /**
     * Add Actions to row entries on indexes
     */
    addActions : function (table_id,ignoreClass,color) {
        var e,a,myClasses;
        if (color==undefined) color='#EDEFF1';
        e=$(table_id).getElementsByTagName('tr');
        for(i=0;i<e.length;i++) {
            a = e[i].getElementsByTagName('a');
            e[i].anchor = a[0];
            e[i].onmouseover=function onmouseover() {
                this.curColor=this.style.backgroundColor;
                generic.setColor(this,color);
                this.style.cursor='pointer';
                this.style.cursor='hand';
                window.status=this.anchor;
            };
            e[i].onmouseout=function onmouseout() {
                generic.setColor(this,this.curColor);
                window.status='';
            };
        }
        e=$(table_id).getElementsByTagName('td');
        for (i=0;i<e.length;i++){
            myClasses=e[i].className.split(/ /);
            if (myClasses.indexOf(ignoreClass)==-1) {
                e[i].onclick=function onclick() {
                    document.location = this.parentNode.anchor;
                    return false;
                };
            }
        }
    },
    /**
     * setColor
     */
    setColor : function (element, color) {
        element.style.backgroundColor=color;
    },
    /**
     * removeElementConditional
     */
    removeElementConditional : function(targetId,parentId,resultsId) {
        if (resultsId==null) resultsId='ajax-results';
        var r=$(resultsId).innerHTML;
        if (r==1 || r=='') {
            this.removeElement(targetId,parentId);
        }
        else {
            alert(r);
        }
    },
    /**
     * removeElement
     */
    removeElement : function (targetId, parentId){
        var d;
        if (parentId == null) d = $(targetId).parentNode;
        else d = document.getElementById(parentId);
        var olddiv = document.getElementById(targetId);
        d.removeChild(olddiv);
    },
    /**
     * removeElementRecursive
     */
    removeElementRecursive : function (delChildId, parentId){
        var d = document.getElementById(parentId);
        var olddiv = document.getElementById(delChildId);
        
        pid = olddiv.parentNode.id;
        if (pid == '') pid = olddiv.parentNode.id='removeElementTempId' + Math.floor(Math.random()*9999999);
        if (pid != parentId) {
            this.removeElementRecursive(pid, parentId);
            return;
        }
//        alert(olddiv.id);
        
        d.removeChild(olddiv);
        return;
    },
    /**
     * loadStatus
     * @todo This could be improved
     */
    loadStatus : function (text) {
        d=$('status');
        e=$('status-text');
        floatCenter('status');
        Element.show('status');
        if (!generic.isModernBrowser()) {
            generic.floatCenter('status-iframe');
            Element.show('status-iframe');
        }
        e.innerHTML = text;
        generic.setTimeout('document.images["pi"].src=document.location.appPath + "/img/processing.gif"', 200);
    },
    /**
     * hideLoadStatus
     * @todo Improve this
     */
    hideLoadStatus : function() {
        
        Element.hide('status');
        if (!generic.isModernBrowser()) {
            Element.hide('status-iframe');
        }
    },
    /**
     * isModernBrowser
     */
    isModernBrowser : function() {
    	if (this.browser == "Internet Explorer") {
    		if (this.version < 7) {
    			return false;
    		}
    	}
    	return true;
    },
    checkIt : function (string) {
    	place = d.detect.indexOf(string) + 1;
    	thestring = string;
    	return place;
    }
};
// Required for GZip AJAX loading
window.generic = generic;

// Initialize the API
generic._init();