/**
 * ScriptLoader v1.4
 * Letöltődés után új script betöltése. Meg kell adni, hogy mely dokumentum 
 * töltse le, mit csináljon a letöltés után, és hogy miket töltsön le. Ezeket 
 * egymás után kezdi el letölteni, hogy az objecktum-függések ne okozzanak 
 * problémát, tehát a szkriptek sorrendje fontos. IE és Geckó aszinkron 
 * betöltődésre megy tovább, Opera8 pedig nem aszikron módon tölti be
 * attribútumok: src kötelező, de más is megadható
 */

 /* String.prototype.toSequence - számok kinyerése egy szringből a tizedeshelyek elvetésével.
* @return String  A leparsolt szöveg. Pl.: '01.2a34bc' -> '01234'
 */
 
String.prototype.toSequence = function() {
	return this.toString().replace(/[^0-9]/g,'');
};

/*--------------------------------------------------------------------------*/

function getElem() {
	var elements = new Array();

	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);

		if (arguments.length == 1) 
			return element;

		elements.push(element);
	}

	return elements;
} 

function ScriptLoader( oDoc, fCommand ) {
	var scripts;
	function Script( oAttributes ) {
		this.attributes = oAttributes;
		this.src = oAttributes.src;
		this.el = null;
		this.id = oAttributes.id;
	};
	this.scripts = [];
	this.add = function( oAttributes,ID ) {
		this.scripts[this.scripts.length] = new Script( oAttributes );
		return true;
	};
	this.scriptIndex = null;
	this.remove = function( sSrc ) {
		var i;
		for ( i = 0; i < this.scripts.length; i++ ) {
			if ( sSrc == this.scripts[i].src ) {
				return this.scripts.splice( i, 1 );
			};
		};
		return false;
	};
	this.load = function() {
		var i;
		this.scriptIndex = 0;
		if ( this.scripts.length > 0 ) {
			this.createScript( this.scripts[0], this.scriptIndex );
		};
		if ( is.opera && is.appVer >= 7.5 ) {
			this.interval = window.setInterval( function( obj ) {
				var i, bLoad;
				bLoad = obj.scripts[obj.scriptIndex].el.text != '' ? true : false;
				if ( bLoad ) {
					obj.scriptLoaded();
				};
			}, 10, this );
		};
	};
	this.createScript = function( oScript, nIndex ) {
		var i, elScript, element;
		elScript = document.createElement('SCRIPT');
		elScript.setAttribute( 'type', 'text/javascript'); // alapbeállítások, felül lehet őket definiálni
		elScript.setAttribute( 'charset', 'utf-8' );
		elScript.setAttribute( 'defer', 'defer' ); // defer || true - még nem tesztelt!
		elScript.loader = this;
		elScript.loader.scripts[nIndex].el = elScript;
		for ( i in oScript.attributes ) {
			if(i != 'id')
				elScript.setAttribute( i, oScript.attributes[i] )
		};
		elScript.onload = function() { // mozilla aszinkron
			this.loader.scriptLoaded(oScript.id);
		};
		elScript.onreadystatechange = function() { // ie aszinkron
			if ( this.readyState == 'complete' || this.readyState == 'loaded') { // ? 'loaded'
				this.loader.scriptLoaded(oScript.id);
			};
		};
		if(oScript.id) {
			element = getElem(oScript.id);
			if(element)
				element.appendChild(elScript);
		} else {	
			oDoc.getElementsByTagName('head')[0].appendChild( elScript );
		}
	};
	this.scriptLoaded = function(id) {
		this.scriptIndex++;
		if ( this.scripts.length > this.scriptIndex ) {
			this.createScript( this.scripts[this.scriptIndex], this.scriptIndex );
		}
		else {
			window.clearInterval( this.interval );
			this.command(id);
		};
	};
	this.command = fCommand;
	return this;
};
var loadScript = new ScriptLoader( document,function( oScript ){


	/*element = getElem(oScript);
	if(element)
		element.innerHTML = phpadsbanner;*/
});
loadScript.add({ 
	src : 'http://sp.cbs.hu/adx.js'
});

function addBanner(id,zone) {
	if (!document.phpAds_used) document.phpAds_used = ',';
	phpAds_random = new String (Math.random()); phpAds_random = phpAds_random.substring(2,11);
	if (document.referrer)
		var referer = "&referer=" + escape(document.referrer);
	else
		var referer = '';
	loadScript.add({ 
		src : 'http://sp.cbs.hu/adjs2.php?n='+phpAds_random+'&what=zone:'+zone+"&id="+id+"&exclude="+document.phpAds_used+referer,
		id: id
	});
}

/**
 * addEvent - egy esemény csatolása. Alapfüggvény.
 * @param obj DOMElement     Az elem, amihez csatolunk.
 * @param type String        Az esmeméyn típusa: pl.: 'click', 'mouseover' ('on' nélkül).
 * @param fn Function  A függvény, melyet csatolunk.
 */
function addEvent( obj, type, fn ) {
	if ( obj.addEventListener ) {
		obj.addEventListener( type, fn, false );
	}
	else if	( obj.attachEvent ) {
		obj['e'+type+fn] = fn;
		obj[type+fn] = function(){ obj['e'+type+fn]( window.event ); };
		obj.attachEvent( 'on'+type, obj[type+fn] );
	};
};

addEvent(window, 'load', LoadBanners);

function LoadBanners() {
	loadScript.load();
}

/**
 * $ browserCheck.js,v 1.12 2005/06/07 13:06:32 gyuris Exp $
 * @package  lib.browserCheck
 * @author   Gyuris Gellért
 */
var is = {
	/**
	 * @constructor
	 */
	getUserAgents : function() { 
		// segédfunkciók
		this.geckoGetRv = function() {
			var aTemp = /rv:(\d+\.)(\d+(\.\d+)?)/g.exec(this.agent);
			return aTemp[1] + aTemp[2].toSequence();
		};
		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(); // 'css1compat', 'backcompat', 'quirksmode'
		
		// platformok
		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
		// khtml
		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.saf         = ( this.agent.indexOf("safari") > -1 || this.ver.indexOf("safari") > -1 );
		// opera
		this.opera       = ( this.opera || this.agent.indexOf("opera") > -1 ); // nem win platformon 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.opera8      = ( this.opera && ( this.agent.indexOf("opera 8") > -1 || this.agent.indexOf("opera/8") > -1 ) );
		// IE
		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;
		this.ie7         = ( document.all && this.ver.indexOf("msie 7" )  > -1 && !this.opera ) ? true : false;
		this.ieJSBuild   = ( this.ie ) ? ScriptEngineBuildVersion() : '';
		this.ieJSVersion = ( this.ie ) ? ScriptEngineMajorVersion() + '.' + ScriptEngineMinorVersion() : '';
		// mozilla
		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.ff          = ( this.gecko && ( this.vendor == 'mozilla firebird' || this.vendor == 'phoenix' || this.vendor == 'firefox' ) );
		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;
		// alkalmazás-verziószám
		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.opera && this.appVer >= 7  ) || this.saf );
		this.bss         = ( this.gecko || ( this.opera && this.appVer >= 7  ) || this.khtml );
		this.min         = ( this.bs5 || this.ie5 || this.opera || this.khtml );
		return this;
	}
};
is.getUserAgents();


