



/**
*	Base, version 1.0.2
*	Copyright 2006, Dean Edwards
*	License: http://creativecommons.org/licenses/LGPL/2.1/
*/
var Base = function() {
	if (arguments.length) {
		if (this == window) { // cast an object to this class
			Base.prototype.extend.call(arguments[0], arguments.callee.prototype);
		} else {
			this.extend(arguments[0]);
		}
	}
};

Base.version = "1.0.2";

Base.prototype = {
	extend: function(source, value) {
		var extend = Base.prototype.extend;
		if (arguments.length == 2) {
			var ancestor = this[source];
			// overriding?
			if ((ancestor instanceof Function) && (value instanceof Function) &&
				ancestor.valueOf() != value.valueOf() && /\bbase\b/.test(value)) {
				var method = value;
			//	var _prototype = this.constructor.prototype;
			//	var fromPrototype = !Base._prototyping && _prototype[source] == ancestor;
				value = function() {
					var previous = this.base;
				//	this.base = fromPrototype ? _prototype[source] : ancestor;
					this.base = ancestor;
					var returnValue = method.apply(this, arguments);
					this.base = previous;
					return returnValue;
				};
				// point to the underlying method
				value.valueOf = function() {
					return method;
				};
				value.toString = function() {
					return String(method);
				};
			}
			return this[source] = value;
		} else if (source) {
			var _prototype = {toSource: null};
			// do the "toString" and other methods manually
			var _protected = ["toString", "valueOf"];
			// if we are prototyping then include the constructor
			if (Base._prototyping) _protected[2] = "constructor";
			for (var i = 0; (name = _protected[i]); i++) {
				if (source[name] != _prototype[name]) {
					extend.call(this, name, source[name]);
				}
			}
			// copy each of the source object's properties to this object
			for (var name in source) {
				if (!_prototype[name]) {
					extend.call(this, name, source[name]);
				}
			}
		}
		return this;
	},

	base: function() {
		// call this method from any other method to invoke that method's ancestor
	}
};

Base.extend = function(_instance, _static) {
	var extend = Base.prototype.extend;
	if (!_instance) _instance = {};
	// build the prototype
	Base._prototyping = true;
	var _prototype = new this;
	extend.call(_prototype, _instance);
	var constructor = _prototype.constructor;
	_prototype.constructor = this;
	delete Base._prototyping;
	// create the wrapper for the constructor function
	var klass = function() {
		if (!Base._prototyping) constructor.apply(this, arguments);
		this.constructor = klass;
	};
	klass.prototype = _prototype;
	// build the class interface
	klass.extend = this.extend;
	klass.implement = this.implement;
	klass.toString = function() {
		return String(constructor);
	};
	extend.call(klass, _static);
	// single instance
	var object = constructor ? klass : _prototype;
	// class initialisation
	if (object.init instanceof Function) object.init();
	return object;
};

Base.implement = function(_interface) {
	if (_interface instanceof Function) _interface = _interface.prototype;
	this.prototype.extend(_interface);
};

function htLog(mixed) {
    var out = mixed;
    try {
        console.log(out);
    } catch(error) { }
}


function htDump(object,panel) {
    var l      = panel ? "<br>" : "\n";
    var out    = typeof(object) + ' ' + object + l;
    for(propertyName in object) { 
        type = typeof(object[propertyName]);
        out += '' 
            + type + ' ' 
            + propertyName 
            + ( type!='function' ? '' + ' = ' + object[propertyName] : '' )
            //+ ' = '+object[propertyName] 
            + l
        ;
    }    
    if(panel) {
        alert(document.getElementById('_debugPanel'));
	    if(document.getElementById('_debugPanel')) {
		    document.getElementById('_debugPanel').innerHTML = ''
                + document.getElementById('_debugPanel').innerHTML 
                //+"test";
                + out + "<hr>";
            ;
            document.getElementById('_debugPanel').style.display = 'block';
        }
    } else {
        alert(out);
    }    
}

function htDump2(object,panel) {
    var l      = panel ? "<br>" : "\n";
    var out    = typeof(object) + ' ' + object + l;
    i=0;
    for(propertyName in object) { 
        type = typeof(object[propertyName]);
        out += ''
            +'['+i+' : '                 
            + type + ' ' 
            + propertyName 
            + ( type!='function' ? '' + ' = ' + object[propertyName] : '' )
            + ']   '
        ;
    }    
    alert(out);
}

function htDump3(object) {
    var l      = "\r\n";
    var out    = typeof(object) + ' ' + object + l;
    i=0;
    for(propertyName in object) { 
        type = typeof(object[propertyName]);
        out += ''
            +'['+i+' : '                 
            + type + ' ' 
            + propertyName 
            + ( type!='function' ? '' + ' = ' + object[propertyName] : '' )
            + ']   '
            + l
        ;
        i++;
    }    
    return out;
}

function getAbsoluteOffsetTop(obj) {
    var top = obj.offsetTop;
    var parent = obj.offsetParent;
    while (parent != document.body) {
        top += parent.offsetTop;
        parent = parent.offsetParent;
    }
    return top;
}

function getAbsoluteOffsetLeft(obj) {
    var left = obj.offsetLeft;
    var parent = obj.offsetParent;
    while (parent != document.body) {
        left += parent.offsetLeft;
        parent = parent.offsetParent;
    }
    return left;
}

function implode(seperator, input){
	var output = '';

	for (var i=0; i<input.length; i++) {
		if (i == 0) {
			output += input[i];
		} else {
			output += seperator + input[i];
		}
	}
	
	return output;
}

function explode(separator, input){
    
    //output = input.split(separator);
    output=new Array(1);
    var Count=0;
    var tempString=new String(input);

    while (tempString.indexOf(separator)>0) {
    output[Count]=tempString.substr(0,tempString.indexOf(separator));
    tempString=tempString.substr(tempString.indexOf(separator)+1,tempString.length-tempString.indexOf(separator)+1); 
    Count=Count+1
    }
    output[Count]=tempString;
    
    return output;
}

function readCookie(sName) {
	var re = new RegExp( "(\;|^)[^;]*(" + (sName) + ")\=([^;]*)(;|$)" );
	var res = re.exec( document.cookie );
	return res != null ? res[3] : null;
}

function spliceByValue(item,arr){
	for (var i=0; i<arr.length; i++) {
		if (arr[i] == item) {
            arr.splice(i,1);			
		}
	}
    return arr;
}

function in_array(item, arr){
	for (var i=0; i<arr.length; i++) {
		if (arr[i] == item) {
			return true;
		}
	}

	return false;
}

function htInputFile_Timer() {
    
    var inputs = document.getElementsByTagName("input");
    var files = Array();
    //var s = "";
    //top.c++;
    var usedCount = 0;
    for(i in inputs) if(inputs[i]) if(inputs[i].type == "file") {  // collect all fileInputs
        files.push(inputs[i]); 
        if(inputs[i].value!='') usedCount++;                       // count used one's
    }
    if(usedCount==files.length) {                                  // if all used, create a new one
        clone = files[files.length-1].cloneNode(true);
        clone.value = '';
        clone.name += 'a1';
        files[0].parentNode.appendChild(clone); 
    }        
    window.status = "loads="+top.count+" used="+usedCount;         // display stats in statusbar
    var count = 0;
    for(i in files) if(!files[i].htInputFile_Registered) {         // for all new one's
        if(!files[i].basename) files[i].basename = files[i].name;
        files[i].style.textAlign = "right";
        //files[i].style.color = "red";
        files[i].style.position = "relative";
        files[i].style.float = "right";
        files[i].style.width = "95%";
        files[i].style.verticalAlign = "middle";
        w2  = document.createElement("span");
        w2.style.border="blue solid 0px"; 
        w2.style.margin="0px"; 
        w2.style.padding="0px"; 
        w2.style.position = "relative";
        w2.style.top = "0";
        w2.style.height = "0px";
        w2.style.verticalAlign = "middle";
        w3  = document.createElement("span");
        w3.style.border="green solid 1px"; 
        wrapper = document.createElement("div");
        wrapper.name = "wrapper";
        wrapper.style.border="red solid 0px";
        wrapper.style.textAlign = 'right';
        wrapper.style.margin="0px"; 
        wrapper.style.padding="0px"; 
        files[i].parentNode.appendChild(wrapper);
        button = document.createElement("img");
        button.height = button.width = 22;
        button.src = "/odb2/client/img/22x22/cancel.png";
        button.style.float = "left";
        button.style.verticalAlign = "top";
        button.onclick = function() {                              // remove-handler
            if(top.count > 1) {
                top.count--;
                this.parentNode.parentNode.removeChild(this.parentNode.parentNode.firstChild); 
                this.parentNode.parentNode.removeChild(this.parentNode.parentNode.firstChild);
            }     
        };
        wrapper.appendChild(files[i]);
        wrapper.appendChild(button);
        w2.appendChild(button);
        wrapper.appendChild(w2);
        //s = files[i].name + "::"+files[i]+ "\n";
        top.count++;
        files[i].htInputFile_Registered = true;
    }
} 



/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * class htControl
 * @desc base-class for all htControls
 * @package htControl
 */
var htControl = Base.extend({
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    constructor: function(params) {
        this.initParams(params);
    },

    initParams: function(params) {
        this.type = "htControl";
        //this.name = "htStandard";
        for(param in params) {
            //alert([param] + ' = ' + params[param]);
            this[param] = params[param];
        }
        //alert('init:'+this.name);
    },

    initDefaults: function() {
    },

    onChange: function() {
    },

    dump: function() {
        htDump(this);
    },

    setCookie: function ( sName, sValue, nDays ) {
	    var expires = "";
	    if ( nDays ) {
		    var d = new Date();
		    d.setTime( d.getTime() + nDays * 24 * 60 * 60 * 1000 );
		    expires = "; expires=" + d.toGMTString();
	    }
	    document.cookie = this.name+"_"+sName + "=" + sValue + expires + "; path=/";
    },

    getCookie: function (sName) {
	    var re = new RegExp( "(\;|^)[^;]*(" + (this.name+"_"+sName) + ")\=([^;]*)(;|$)" );
	    var res = re.exec( document.cookie );
	    return res != null ? res[3] : null;
    },

    removeCookie: function ( name ) {
	    setCookie( name, "", -1 );
    }
    
    //finalize: function() {}

});    


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * class htTemplate
 * @desc ...
 * @package htControl
 */
var htTemplate = htControl.extend({ 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    constructor: function(params) {
        this.base(params);
    }
    
});    






/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * class htScandTreeView
 * @desc ...
 * @package htControl
 */

var htScandTreeView = htControl.extend({ 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    constructor: function(params) {
        this.base(params);
    }
    
});    



/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * class htAjaxControl
 * @desc base-class for all htAjaxControls
 * @package htControl
 */
var htAjaxControl = htControl.extend({ 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    constructor: function(params) {
        this.ajax = true;
        this.base(params);
    },
    
    reload : function(params) {
        //alert(params);
        
	    if(document.getElementById(this.name + '_ajaxContainer')) {
		    document.getElementById(this.name + '_ajaxContainer').innerHTML = ''
                + document.getElementById(this.name + '_ajaxContainer').innerHTML 
                + this.compileLoadingScreen()
            ;
        }
        
        
        ajaxObj.method = 'POST'; 
        ajaxObj.format = 'TEXT'; 
        var command = 'control='+this.name;
        for(param in params) {
            //alert(param);
            command += ('&'+param+'='+params[param]);
        }
        //alert(command);
        ajaxObj.call(''
            +command
            //+'control='+this.name+''
            //."action=" //.$out2
            
            ,this.name + '_ajaxContainer' 
        ); 
    },

    compileLoadingScreen : function(params) {
        opacity = 0.7;
        var out = ''
            +'<div style="'
                +'border-bottom:gray solid 1px; '
                +'display: block; position: fixed; left: '+'0'+'; top: '+'0'+'; '
                +'filter:Alpha(opacity='+(opacity*100)+'); '
                +'-moz-opacity:'+(opacity)+'; '
 
            +' ">'
            +'<table width=100% border=0 bgcolor=#ffffff >'
                +'<tr>'
                    +'<td width=50% align=center valign=middle >'+'&nbsp;'+'</td>'
                    +'<td width=1px align=center valign=middle >'+'<img src="/php/img/htControls/htControls_progress_intermediate.gif">'+'</td>'
                    +'<td width=1px align=center valign=middle >'+'Loading...'+'</td>'
                    +'<td width=50% align=center valign=middle >'+'&nbsp;'+'</td>'
                +'</tr>'
            +'</table>'
            +'</div>'
        ;
        return(out);
    }

    
});    
    

    
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * class htDbTable
 * @desc dynamic database tables
 * @package htControl
 */
var htDbTable = htAjaxControl.extend({ 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    constructor: function(params) {
        this.base(params);
        //this.dump();
        this.reload();
    }
    
});    



/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * class htPage
 * @desc the entire html-page and helper-structures
 * @package htControl
 */
var htPage = htControl.extend({ 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    constructor: function(params) {
        this.base(params);
    }
});    



/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * class htFoldingPanel
 * @desc panel to fold/unfold
 * @package htControl
 */
var htFoldingPanel = htControl.extend({ 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    constructor: function(params) {
        this.base(params);
        if(!this.getCookie('open')) {
            this.open = true;
        } else {         
            this.open = this.getCookie('open') == "true" ? true : false ;
        }    
        this.button = document.getElementsByName(this.name+'_button')[0];     
        this.button.owner = this;
        this.button.onclick = this.onOpenClick;
        this.panel = document.getElementById(this.name+'_panel');     
        this.panel.owner = this;
        this.label = document.getElementById(this.name+'_label');     
        this.label.owner = this;
        this.label.onclick = this.onOpenClick;
        this.updateStatus();
    },

    onOpenClick: function() { // CAUTION! IS NOT EXECUTED IN CLASS CONTEXT. 
        // this points not to htFoldingPanel but to button's html-dom-object
        this.owner.open = !this.owner.open;
        this.owner.setCookie("open",this.owner.open,3);
        this.owner.updateStatus();
    },

    updateStatus: function() {
        if(this.open ) {
            this.button.src = this.imageOpen;
            if ( typeof window.attachEvent != "undefined" ) { 
                this.panel.style.display = "block";
            } else {
                this.panel.style.display = "table-row";
            }    
        } else {
            this.button.src = this.imageClose;
            this.panel.style.display = "none";
        }        
    },

    onChange:  function( ) {

    }
    
});    




/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * class htTab
 * @desc Tab-Control
 * @package htControl
 */
var htTab = htControl.extend({ 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    constructor: function(params) {
        this.base(params);
	    this.pages = Array();
	    this.init = false;
	    this.tabHeight = -1;
        this.initParams(params);
        
    },

    initCompleted: function() {
        if(!this.getCookie('selection')) {
            this.setSelection(this.pages[0]);
        } else {
            this.setSelection( this.getCookie('selection') );
        }    
    },

    labelOver: function(id) {
        if(this.selection != id ) {
            this.showOver(id);
        } else {
            this.showSelected(id);
        }
    },

    labelOut: function(id) {
        if(this.selection != id ) {
            this.showNormal(id);
        } else {
            this.showSelected(id);
        }
    },

    labelClick: function( id ) {
        if(this.selection != id ) {
            this.setSelection(id)
        } else {
        }
    },

    addPage: function(id) {
        this.pages[this.pages.length] = id;
    },

    setSelection: function( id ) {
        this.selection = id;
        this.setCookie("selection",this.getSelection(),3);
        for(i in this.pages) {
            if(this.selection != this.pages[i] ) { 
                this.showNormal(this.pages[i]) 
                var back = document.getElementById( this.pages[i] + '_center'  );
                var page = document.getElementById( this.pages[i] + '_page'  );
                page.style.display = "none";
            }    
        }
        this.showSelected(id);
    },

    showNormal: function( id ) {
        var left    = document.getElementById( id + '_left' );
        var center  = document.getElementById( id + '_center'  );
        var icon    = document.getElementById( id + '_icon'  );
        var right   = document.getElementById( id + '_right'  );
        var back    = document.getElementById( id + '_back'  );
        var top     = document.getElementById( id + '_top'  );
        var page    = document.getElementById( id + '_page'  );
        center.style.color = "black";
        center.style.fontWeight = "normal";
        center.style.textDecoration = "none";
        left.style.backgroundImage = "url('/php/lib/htTab/luna/inactive.left.gif')";
        center.style.backgroundImage = "url('/php/lib/htTab/luna/inactive.center.gif')";
        if(icon) icon.style.backgroundImage = "url('/php/lib/htTab/luna/inactive.center.gif')";
        right.style.backgroundImage = "url('/php/lib/htTab/luna/inactive.right.gif')";
        back.style.padding = "0 0 0 0";
        back.style.margin = "0 0 0 0";
        center.style.padding = (icon?1:3)+" 10 "+(icon?1:3)+" "+(icon?0:10);
        if ( typeof window.attachEvent != "undefined" ) { 
            top.style.display = "block";
        } else {
            top.style.display = "table-row";
        }    

    },

    showSelected: function( id ) {
        var left    = document.getElementById( id + '_left' );
        var center  = document.getElementById( id + '_center'  );
        var icon    = document.getElementById( id + '_icon'  );
        var right   = document.getElementById( id + '_right'  );
        var back    = document.getElementById( id + '_back'  );
        var top     = document.getElementById( id + '_top'  );
        var page    = document.getElementById( id + '_page'  );
        if(icon) icon.style.backgroundImage = "url('/php/lib/htTab/luna/active.center.gif')";
        if(center) {
            center.style.color = "black";
            center.style.fontWeight = "bold";
            center.style.textDecoration = "none";
            center.style.backgroundImage = "url('/php/lib/htTab/luna/active.center.gif')";
            center.style.padding = (icon?5:5)+" 10 "+(icon?3:3)+" "+(icon?0:10);
        }
        if(left) left.style.backgroundImage = "url('/php/lib/htTab/luna/active.left.gif')";
        if(right) right.style.backgroundImage = "url('/php/lib/htTab/luna/active.right.gif')";
        if(top) top.style.display = "none";
        if(page) page.style.display = "block";
    },

    showOver: function( id ) {
        var left    = document.getElementById( id + '_left' );
        var center  = document.getElementById( id + '_center'  );
        var icon    = document.getElementById( id + '_icon'  );
        var right   = document.getElementById( id + '_right'  );
        center.style.color = "blue";
        center.style.textDecoration = "underline";
        left.style.backgroundImage = "url('/php/lib/htTab/luna/active.left.gif')";
        center.style.backgroundImage = "url('/php/lib/htTab/luna/active.center.gif')";
        if(icon) icon.style.backgroundImage = "url('/php/lib/htTab/luna/active.center.gif')";
        right.style.backgroundImage = "url('/php/lib/htTab/luna/active.right.gif')";
    },

    getSelection: function( ) {
        return(this.selection);
    }
    
});    
























