var isIE = ( navigator.appName == "Microsoft Internet Explorer" );
var isMozilla = ( navigator.appName == "Mozilla" );
var isIE6 = ( isIE ) ? (navigator.appVersion.match(".*MSIE 6.0.*")!=null?true:false) : false;
//---------------------------------------------------------------------
function removeTextNodes( node ) {
	if( ! node ) return;
	for( var i = 0 ; i < node.childNodes.length ; i++ ) {
		if( node.childNodes[i].nodeType != 1 ) {
			node.removeChild( node.childNodes[i] );
			i--;
		} else {
			removeTextNodes( node.childNodes[i] );
		}
	}
}
//---------------------------------------------------------------------
var allObjects, PAGE_LOADED=false;
//---------------------------------------------------------------------
function addOnLoadAction( functionReference , args ) {
	if( window.__msh_prevOnLoad == null ) {
		window.__msh_prevOnLoad = [];
		if( window.onload ) window.__msh_prevOnLoad.push( [ window.onload , null ] );
		window.onload = null;
		window.onload = function() {
			for( var i = 0 ; i < window.__msh_prevOnLoad.length; i++ ) {
				//we want the window to be the caller and `this` to work properly
				window.__msh_tmpHandler = window.__msh_prevOnLoad[i][0];
				var evalStr = "";
				for( var j = 1 ; j < window.__msh_prevOnLoad[i][1].length ; j++ )
					evalStr = evalStr + ( ( evalStr!="")?",":"" ) + "window.__msh_prevOnLoad[i][1]["+j+"]";
				eval( "window.__msh_tmpHandler("+evalStr+");" );
			}
		}
	}
	window.__msh_prevOnLoad.push( [ functionReference , arguments ] );
}
addOnLoadAction( function(){ PAGE_LOADED = true;updateAllObjects();} );
addOnLoadAction( setup );
//dodać addOnLoadAction( setup() );
//---------------------------------------------------------------------
function setup() {
	o = document.getElementsByTagName( 'span' );
	for( i = 0; i < o.length; i++ ) if( o[i].className == 'clicker' && ! o[i].onclick ) o[i].onclick = function() {
			this.previousSibling.click();
		}
	/**
	 *	following code blocks border-spacing settings from css external file
	 */
	/*
	var tables;
	tables = document.getElementsByTagName( "table" );
	for( var i = 0 ; i < tables.length ; i++ ){ 
		if( ! tables[i].cellSpacing && ! tables[i].style.borderSpacing ) {
			tables[i].cellSpacing = 0;
			tables[i].style.borderSpacing = "0px";
			tables[i].cellPadding = 0;
		}
	}
	*/
}
function getElementsByName( name ) {
	var array = new Array();
	if( navigator.appName.indexOf( "Microsoft" ) == -1 ) return document.getElementsByName( name );
	else {
		if( allObjects == null) return new Array(); 
		return ( allObjects[ name ] ) ? allObjects[ name ] : new Array();
	}
}
function updateAllObjects() {
	allObjects = new Array();
	if( navigator.appName.indexOf( "Microsoft" ) == -1 ) return;
	allObjects = new Array();
	for( i = 0 ; i < document.all.length ; i++ ) {
		o = document.all(i);
		if( allObjects[o.name] == null ) allObjects[o.name] = new Array();
		allObjects[o.name].push(o);
	}
	return allObjects;
}
function getFormElement( formId , elementName ) {
	var form, nodes;
	form = document.getElementById( formId );
	if( !form.elements[ elementName ] ) {
		nodes = getElementsByName( elementName );
		for( i = 0 ; i < nodes.length ; i++ )
			if( getFormId( nodes[i] ) == formId ) break;
		return nodes[i];
	}else return form.elements[ elementName ];
}
function getFormElementValue( formId , elementName ) {
	var node
	node = getFormElement( formId , elementName );
	if( node == null ) return null;
	else return node.value;
}
function setFormElementValue( formId , elementName , value ) {
	var node;
	node = getFormElement( formId , elementName );
	if( node != null ) node.value = value; 
}
function getFormId( o ) {
	if( o.form ) return o.form.id
	while( o.parentNode && o.tagName.toLowerCase() != "form" ) o = o.parentNode;
	if( ! o.id ) return null;
	else return o.id;
}
function getForm( o ) {
	return document.getElementById( getFormId( o ) );
}
function getFormElementsById( formId , elementId ) {
	return getChildrenWithId( document.getElementById( formId ) , elementId );
}
function getChildrenWithId( obj , id ) {
	if( ! obj.childNodes ) return null;
	var sack = [];
	for( var i = 0 ; i < obj.childNodes.length ; i++ ) {
	//	if( obj.childNodes[i].tagName == "DIV") alert(obj.childNodes[i] +" "+obj.childNodes[i].id+" "+id);
		if( obj.childNodes[i].id == id ) sack.push( obj.childNodes[i] );
		sack = sack.concat( getChildrenWithId( obj.childNodes[i] , id ) );
	}
	return sack;
}
function getEvent( e ) {
	return e;
}
function imageWindow( a ) {
	window.open( 'showImage.php?path=' + a , 'imageWindow' , 'status=no,scrollbar=no,toolbar=no,left=10,top=10,margin=0');
}
//---------------------------------------------------------------------
function roll_form_elements_by_flag( obj , flag , value ) {

	o = obj.form.elements;
	for( i = 0 ; i < o.length ; i++ ) if( o[i].attributes[flag] != null ) {
		o[i].parentNode.parentNode.style.display = ( o[i].attributes[flag].value == value ) ? '' : 'none';
	}
}
//---------------------------------------------------------------------
/******************HeightGuardian****************************
*/

function HeightGuardian(){
	document.heightGuardian = this;
	this.intervalId = setInterval( "document.heightGuardian.levelSlots()", 1000 );
}
HeightGuardian.prototype.slot = [];
HeightGuardian.prototype.firstFit = 1;
HeightGuardian.prototype.internal = 1;
HeightGuardian.prototype.external = 0;
HeightGuardian.prototype.addItems = function() {
	for( var i = 0 ; i < arguments.length; i++ )
		if(  ! ( arguments[i] instanceof Array ) ) arguments[i] = [ arguments[i] , HeightGuardian.prototype.external ];
		else if( arguments[i][1] != this.internal && arguments[i][1] != this.external ) arguments[i][1] = this.external; 
	this.slot.push(arguments);
}
HeightGuardian.prototype.levelSlots = function() {
	for( var i = 0 ; i < this.slot.length; i++ ) {
		var maxHeight = 0;
		for( var j = 0 ; j < this.slot[i].length; j++ )
			if( ( this.slot[i][j][1] == this.external || this.firstFit ) && maxHeight < this.slot[i][j][0].offsetHeight )
				maxHeight = this.slot[i][j][0].offsetHeight;

//		for( var j = 0 ; j < this.slot[i].length; j++ ) alert(maxHeight+" " + this.slot[i][j][0].id +" "+this.slot[i][j][0].offsetHeight);
		for( var j = 0 ; j < this.slot[i].length; j++ ) if( this.slot[i][j][0].offsetHeight <= maxHeight )
			this.slot[i][j][0].style.height = maxHeight+"px";

		for( var j = 0 ; j < this.slot[i].length; j++ ) 
			if( this.slot[i][j][0].offsetHeight > maxHeight && this.slot[i][j][1] == this.external )
				this.slot[i][j][0].style.height = parseInt(this.slot[i][j][0].style.height) - this.slot[i][j][0].offsetHeight + maxHeight +"px";

		for( var j = 0 ; j < this.slot[i].length; j++ )
			if( this.slot[i][j][1] == this.internal ) this.slot[i][j][0].style.height = maxHeight+"px";
	}
	this.firstFit = 0;
}
