/***************
 * Copyright:   Copyright (c) 2002, nexum MarsNet Kft.
 *              6722 Szeged, Gyertyámos u. 14-16 C
 *              Tel.: +36 62 55 88 99;
 *              Fax.: +36 62 55 88 98
 *              http://www.nexum.hu; info@nexum.hu
 * Leírás:      állandó gyűjtemény
 * Keletkezés:  2003.09.24
 * Fejlesztő:   Gyuris Gellért
 ***************
 * Fejlesztés:  [id] - [dátum] - [fejlesztő] - [módosítási megjegyzések]
 *              [id] - [dátum] - [fejlesztő] - [módosítási megjegyzések]
 **************/

/********************************************************
 * BrowserCheck v4.3
 *******************************************************/
function BrowserCheck(){ 
	// segédfunkciók
	this.geckoGetRv = function() {
		var nRv = 0, nStart, nEnd, sRv, aRv, nExp = 1, i, nTemp;
		nStart = this.agent.indexOf( 'rv:' );
		nEnd   = this.agent.indexOf( ')', nStart );
		sRv    = this.agent.substring( nStart + 'rv:'.length , nEnd  );
		aRv    = sRv.split('.');
		for ( i = 0; i < aRv.length; i++ ) {
			nTemp = parseInt( aRv[i] );
			nRv += nTemp / nExp;
			nExp *= 10;
		}
		return nRv;
	}
	this.getVersion = function() {
		var sId;
		switch ( this.app ) {
			case 'gecko' :
				return this.geckoRv; break;
			case 'ie' :
				sId = 'msie ' ; break;
			case 'opera' :
				sId = ( this.agent.indexOf( 'opera/' ) > -1 ) ? 'opera/' : 'opera '; break;
			case 'khtml' :
				sId = ( this.saf ) ? 'applewebkit/' : 'konqueror/';	break;
			case 'ns4' :
				sId = 'mozilla/'; break;
		}
		return parseFloat( '0' + this.agent.substr( this.agent.indexOf( sId ) + sId.length ), 10 );
	}
	// adatok átvétele
	this.ver         = navigator.appVersion.toLowerCase();
	this.agent       = navigator.userAgent.toLowerCase();
	this.platform    = navigator.platform.toLowerCase();
	this.product     = new String( navigator.product ).toLowerCase();
	this.productSub  = new String( navigator.productSub ).toLowerCase();
	this.vendor      = new String( navigator.vendor ).toLowerCase();
	this.vendorSub   = new String( navigator.vendorSub ).toLowerCase();
	this.opera       = typeof ( window.opera ) != 'undefined';
	this.dom         = document.getElementById ? true : false;
	this.compatMode  = new String( document.compatMode ).toLowerCase();
	
	// platform
	this.win         = this.platform.indexOf("win") > -1;
	this.linux       = ( this.platform.indexOf("linux") > -1 || this.platform.indexOf("x11") > -1 );
	this.mac         = this.platform.indexOf("mac") > -1;

	// böngészők
	this.khtml       = ( this.agent.indexOf("khtml") > -1 || this.product.indexOf("khtml") > -1 )
	this.konq        = ( this.agent.indexOf("konqueror") > -1 || this.product.indexOf("konqueror") > -1 );
	this.konq31      = ( this.konq && this.ver.indexOf("konqueror/3.1") > - 1 );
	this.saf         = ( this.agent.indexOf("safari") > -1 || this.ver.indexOf("safari") > -1 );
	
	this.opera       = ( this.opera || this.agent.indexOf("opera") > -1 ); // nem win platformok az opera obj nem jön létre
	this.opera5      = ( this.opera && this.agent.indexOf("opera 5") > -1 );
	this.opera6      = ( this.opera && ( this.agent.indexOf("opera 6") > -1 || this.agent.indexOf("opera/6") > -1 ) );
	this.opera7      = ( this.opera && ( this.agent.indexOf("opera 7") > -1 || this.agent.indexOf("opera/7") > -1 ) );
	
	this.ie          = ( this.ver.indexOf('msie') != -1 && !this.opera ) ? true : false;
	this.ie4         = ( document.all && !this.dom && !this.opera ) ? true : false;
	this.ie5         = ( document.all && this.ver.indexOf("msie 5.0") > -1 && !this.opera ) ? true : false; 
	this.ie5mac      = ( this.ie5 && this.mac ) ? true : false; 
	this.ie55        = ( document.all && this.ver.indexOf("msie 5.5") > -1 && !this.opera ) ? true : false; 
	this.ie6         = ( document.all && this.ver.indexOf("msie 6" )  > -1 && !this.opera ) ? true : false;
	/*@cc_on @*/ /*@if (@_jscript) 
	this.ieJSBuild   = @_jscript_build;
	this.ieJSVersion = @_jscript_version; /*@end @*/
	
	this.ns4         = ( document.layers && !this.dom ) ? true : false;
	this.gecko       = ( this.product == "gecko" && !this.khtml ) ? true : false;
	this.geckoRv     = ( this.gecko ) ? this.geckoGetRv() : 0;
	this.gecko1      = ( this.gecko && Number( this.productSub ) > 20020530 ) ? true : false;
	this.moz1        = ( this.gecko && this.vendor == '' && !( this.geckoRv < 1 ) ) ? true : false;
	this.ns6         = ( this.gecko && this.vendor == 'netscape6' && parseFloat( this.vendorSub ) >= 6 && parseFloat( this.vendorSub ) < 7 ) ? true : false;
	this.ns7         = ( this.gecko && this.vendor == 'netscape' && parseFloat( this.vendorSub ) >= 7 ) ? true : false;
	this.fb          = ( this.gecko && ( this.vendor == 'mozilla firebird' || this.vendor == 'phoenix' ) );
	this.cm          = ( this.gecko && ( this.vendor == 'chimera' || this.vendor == 'camino' ) );
	this.beo         = ( this.gecko && this.vendor == 'beonex' );
	this.kmel        = ( this.agent.indexOf('k-meleon') > -1 ) ? true : false ;

	this.app         = ( ( this.ie ) ?  'ie' : ( this.gecko ) ? 'gecko' : ( this.opera ) ?  'opera' : ( this.khtml ) ? 'khtml' : ( this.ns4 ) ? 'ns4' : 'undefined' );
	this.appVer      = this.getVersion();

	// csoportok
	this.bs4         = ( this.ie || this.ns4 || this.gecko || this.opera || this.khtml );
	this.bs5         = ( ( this.ie && this.appVer >= 5.5 ) || this.gecko || this.opera7 || this.konq31 || this.saf );
	this.bss         = ( this.gecko || this.opera7 || this.konq31 || this.saf )
	this.min         = ( this.bs5 || this.ie5 || this.opera || this.khtml );
	return this
}
var is = new BrowserCheck();

/********************************************************
 * eventBinding v3.2
 *******************************************************/
function eventBinding( node, bFlag, sType, fListener, bCapture ) {
	sType = sType.toLowerCase();
	if ( bFlag ) {
		if ( is.ie && is.win ) 
			node.attachEvent( 'on' + sType, fListener );
		if ( is.ie5mac )
			eventBindingCompletion( [node], bFlag, sType, fListener, bCapture );
		if ( is.bss ) {
			node.addEventListener( sType, fListener, bCapture );
		}
	}
	else {
		if ( is.ie && is.win ) 
			node.detachEvent( 'on' + sType, fListener );
		if ( is.ie5mac )
			eventBindingCompletion( [node], bFlag, sType, fListener, bCapture );
		if ( is.bss ) {
			node.removeEventListener( sType, fListener, bCapture );
			}
	}
}
// ie5Mac nem támogatja a többszörösen csatolt eseményeket!
// Konqueror is hasznája a loadBindingben
function eventBindingCompletion( aNode, bFlag, sType, fListener, bCapture ) {
	function eventObject( sType, fListener) {
		this.type = sType;
		this.listener = fListener;
		return this;
	}
	function findType( aAttachedEvents, sType) {
		var i;
		for ( i = 0; i < aAttachedEvents.length; i++ ) {
			if ( aAttachedEvents[i] == null ) continue;
			if ( aAttachedEvents[i].type == sType )
				return true;
		}
		return false;
	}
	function findFunctionString( firstFunc ) {
		var str, num1, num2;
		num1 = firstFunc.toString().indexOf('{');
		num2 = firstFunc.toString().lastIndexOf(')');
		str = firstFunc.toString().substring( num1 + 1, num2 + 1 )
		return str.trim();
	}
	var i, k, fFirst;
	if ( bFlag ) {
		for ( i = 0 ; i < aNode.length; i++ ) {
			if ( typeof aNode[i].aAttachedEvents == 'undefined' )
				aNode[i].aAttachedEvents = [];
			aNode[i].dispatchEvents = function() {
				var j, type = window.event.type;
				for ( j = 0; j < this.aAttachedEvents.length; j++ ) {
					if ( this.aAttachedEvents[j] == null ) continue;
					if ( type == this.aAttachedEvents[j].type ) {
						if ( typeof this.aAttachedEvents[j].listener == 'string' )
							eval( this.aAttachedEvents[j].listener );
						else if ( typeof this.aAttachedEvents[j].listener == 'function' )
							eval( this.aAttachedEvents[j].listener.getName() + '()' );
					}
				}
			}
			fFirst = eval( 'aNode['+i+'].on' + sType )
			if ( fFirst != null && !findType( aNode[i].aAttachedEvents, sType ) ) // ha már inline volt egy függvény hozzárendelve, azt átemeljük
				aNode[i].aAttachedEvents[aNode[i].aAttachedEvents.length] = new eventObject( sType, findFunctionString( fFirst ) ); // typeof: string
			eval( 'aNode['+i+'].on' + sType + ' = ' + 'aNode['+i+'].dispatchEvents' );
			aNode[i].aAttachedEvents[aNode[i].aAttachedEvents.length] = new eventObject( sType, fListener ); // typeof : function
		}
	}
	else { 
		for ( i = 0; i < aNode.length; i++ ) {
			for ( k = 0; k < aNode[i].aAttachedEvents.length; k++ ) { 
				if ( aNode[i].aAttachedEvents[k] == null ) continue;
				if ( aNode[i].aAttachedEvents[k].type == sType && aNode[i].aAttachedEvents[k].listener == fListener ) // typeof aNode.aAttachedEvents[i].listener = string || function 
					aNode[i].aAttachedEvents[k] = null;
			}
		}
	}
}
// a betöltési eseménykötés érdekességei miatt van külön
// opera7 : a document bocsátja el az eseményt
// Konqueror és Safari: a window bocsátja el az eseményt, de a document kapja meg...
function loadEventBinding( win, fFunction ) {
	if ( is.ie || is.gecko )
		eventBinding( win, true, 'load', fFunction, false );
	if ( is.opera7 )
		eventBinding( win.document, true, 'load', fFunction, false );
	if ( is.konq || is.saf )
		eventBindingCompletion( [ win, win.document], true, 'load', fFunction, false );
}
// a beágyazott IFRAME-k eseményeinek átvételére
function globalEventBinding( node, bFlag, sType, fListener, bCapture, IEcaptureNode ) {
	var windows, i;
	if ( is.ie ) {
		eventBinding( document, bFlag, sType, fListener, bCapture )
		if ( bFlag )
			IEcaptureNode.setCapture();
		else
			IEcaptureNode.releaseCapture();
	}
	if ( is.bss ) {
		eventBinding( document, bFlag, sType, fListener, bCapture )
		var windows = node.getElementsByTagName('IFRAME');
		for ( i = 0; i < windows.length; i++ ) {
			eventBinding( windows[i].contentDocument, bFlag, sType, fListener, bCapture )
			globalEventBinding( windows[i].contentDocument , bFlag, sType, fListener, bCapture )
		}
	}
}