/**
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept == "undefined") var deconcept = new Object();
if(typeof deconcept.util == "undefined") deconcept.util = new Object();
if(typeof deconcept.SWFObjectUtil == "undefined") deconcept.SWFObjectUtil = new Object();
deconcept.SWFObject = function(swf, id, w, h, ver, c, quality, xiRedirectUrl, redirectUrl, detectKey) {
	if (!document.getElementById) { return; }
	this.DETECT_KEY = detectKey ? detectKey : 'detectflash';
	this.skipDetect = deconcept.util.getRequestParameter(this.DETECT_KEY);
	this.params = new Object();
	this.variables = new Object();
	this.attributes = new Array();
	if(swf) { this.setAttribute('swf', swf); }
	if(id) { this.setAttribute('id', id); }
	if(w) { this.setAttribute('width', w); }
	if(h) { this.setAttribute('height', h); }
	if(ver) { this.setAttribute('version', new deconcept.PlayerVersion(ver.toString().split("."))); }
	this.installedVer = deconcept.SWFObjectUtil.getPlayerVersion();
	if (!window.opera && document.all && this.installedVer.major > 7) {
		// only add the onunload cleanup if the Flash Player version supports External Interface and we are in IE
		deconcept.SWFObject.doPrepUnload = true;
	}
	if(c) { this.addParam('bgcolor', c); }
	var q = quality ? quality : 'high';
	this.addParam('quality', q);
	this.setAttribute('useExpressInstall', false);
	this.setAttribute('doExpressInstall', false);
	var xir = (xiRedirectUrl) ? xiRedirectUrl : window.location;
	this.setAttribute('xiRedirectUrl', xir);
	this.setAttribute('redirectUrl', '');
	if(redirectUrl) { this.setAttribute('redirectUrl', redirectUrl); }
}
deconcept.SWFObject.prototype = {
	useExpressInstall: function(path) {
		this.xiSWFPath = !path ? "expressinstall.swf" : path;
		this.setAttribute('useExpressInstall', true);
	},
	setAttribute: function(name, value){
		this.attributes[name] = value;
	},
	getAttribute: function(name){
		return this.attributes[name];
	},
	addParam: function(name, value){
		this.params[name] = value;
	},
	getParams: function(){
		return this.params;
	},
	addVariable: function(name, value){
		this.variables[name] = value;
	},
	getVariable: function(name){
		return this.variables[name];
	},
	getVariables: function(){
		return this.variables;
	},
	getVariablePairs: function(){
		var variablePairs = new Array();
		var key;
		var variables = this.getVariables();
		for(key in variables){
			variablePairs[variablePairs.length] = key +"="+ variables[key];
		}
		return variablePairs;
	},
	getSWFHTML: function() {
		var swfNode = "";
		if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // netscape plugin architecture
			if (this.getAttribute("doExpressInstall")) {
				this.addVariable("MMplayerType", "PlugIn");
				this.setAttribute('swf', this.xiSWFPath);
			}
			swfNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" style="'+ this.getAttribute('style') +'"';
			swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
			var params = this.getParams();
			 for(var key in params){ swfNode += [key] +'="'+ params[key] +'" '; }
			var pairs = this.getVariablePairs().join("&");
			 if (pairs.length > 0){ swfNode += 'flashvars="'+ pairs +'"'; }
			swfNode += '/>';
		} else { // PC IE
			if (this.getAttribute("doExpressInstall")) {
				this.addVariable("MMplayerType", "ActiveX");
				this.setAttribute('swf', this.xiSWFPath);
			}
			swfNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" style="'+ this.getAttribute('style') +'">';
			swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
			var params = this.getParams();
			for(var key in params) {
			 swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
			}
			var pairs = this.getVariablePairs().join("&");
			if(pairs.length > 0) {swfNode += '<param name="flashvars" value="'+ pairs +'" />';}
			swfNode += "</object>";
		}
		return swfNode;
	},
	write: function(elementId){
		if(this.getAttribute('useExpressInstall')) {
			// check to see if we need to do an express install
			var expressInstallReqVer = new deconcept.PlayerVersion([6,0,65]);
			if (this.installedVer.versionIsValid(expressInstallReqVer) && !this.installedVer.versionIsValid(this.getAttribute('version'))) {
				this.setAttribute('doExpressInstall', true);
				this.addVariable("MMredirectURL", escape(this.getAttribute('xiRedirectUrl')));
				document.title = document.title.slice(0, 47) + " - Flash Player Installation";
				this.addVariable("MMdoctitle", document.title);
			}
		}
		if(this.skipDetect || this.getAttribute('doExpressInstall') || this.installedVer.versionIsValid(this.getAttribute('version'))){
			var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
			n.innerHTML = this.getSWFHTML();
			return true;
		}else{
			if(this.getAttribute('redirectUrl') != "") {
				document.location.replace(this.getAttribute('redirectUrl'));
			}
		}
		return false;
	}
}

/* ---- detection functions ---- */
deconcept.SWFObjectUtil.getPlayerVersion = function(){
	var PlayerVersion = new deconcept.PlayerVersion([0,0,0]);
	if(navigator.plugins && navigator.mimeTypes.length){
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			PlayerVersion = new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
		}
	}else if (navigator.userAgent && navigator.userAgent.indexOf("Windows CE") >= 0){ // if Windows CE
		var axo = 1;
		var counter = 3;
		while(axo) {
			try {
				counter++;
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+ counter);
//				document.write("player v: "+ counter);
				PlayerVersion = new deconcept.PlayerVersion([counter,0,0]);
			} catch (e) {
				axo = null;
			}
		}
	} else { // Win IE (non mobile)
		// do minor version lookup in IE, but avoid fp6 crashing issues
		// see http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
		try{
			var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		}catch(e){
			try {
				var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
				PlayerVersion = new deconcept.PlayerVersion([6,0,21]);
				axo.AllowScriptAccess = "always"; // error if player version < 6.0.47 (thanks to Michael Williams @ Adobe for this code)
			} catch(e) {
				if (PlayerVersion.major == 6) {
					return PlayerVersion;
				}
			}
			try {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			} catch(e) {}
		}
		if (axo != null) {
			PlayerVersion = new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
		}
	}
	return PlayerVersion;
}
deconcept.PlayerVersion = function(arrVersion){
	this.major = arrVersion[0] != null ? parseInt(arrVersion[0]) : 0;
	this.minor = arrVersion[1] != null ? parseInt(arrVersion[1]) : 0;
	this.rev = arrVersion[2] != null ? parseInt(arrVersion[2]) : 0;
}
deconcept.PlayerVersion.prototype.versionIsValid = function(fv){
	if(this.major < fv.major) return false;
	if(this.major > fv.major) return true;
	if(this.minor < fv.minor) return false;
	if(this.minor > fv.minor) return true;
	if(this.rev < fv.rev) return false;
	return true;
}
/* ---- get value of query string param ---- */
deconcept.util = {
	getRequestParameter: function(param) {
		var q = document.location.search || document.location.hash;
		if (param == null) { return q; }
		if(q) {
			var pairs = q.substring(1).split("&");
			for (var i=0; i < pairs.length; i++) {
				if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
					return pairs[i].substring((pairs[i].indexOf("=")+1));
				}
			}
		}
		return "";
	}
}
/* fix for video streaming bug */
deconcept.SWFObjectUtil.cleanupSWFs = function() {
	var objects = document.getElementsByTagName("OBJECT");
	for (var i = objects.length - 1; i >= 0; i--) {
		objects[i].style.display = 'none';
		for (var x in objects[i]) {
			if (typeof objects[i][x] == 'function') {
				objects[i][x] = function(){};
			}
		}
	}
}
// fixes bug in some fp9 versions see http://blog.deconcept.com/2006/07/28/swfobject-143-released/
if (deconcept.SWFObject.doPrepUnload) {
	if (!deconcept.unloadSet) {
		deconcept.SWFObjectUtil.prepUnload = function() {
			__flash_unloadHandler = function(){};
			__flash_savedUnloadHandler = function(){};
			window.attachEvent("onunload", deconcept.SWFObjectUtil.cleanupSWFs);
		}
		window.attachEvent("onbeforeunload", deconcept.SWFObjectUtil.prepUnload);
		deconcept.unloadSet = true;
	}
}
/* add document.getElementById if needed (mobile IE < 5) */
if (!document.getElementById && document.all) { document.getElementById = function(id) { return document.all[id]; }}

/* add some aliases for ease of use/backwards compatibility */
var getQueryParamValue = deconcept.util.getRequestParameter;
var FlashObject = deconcept.SWFObject; // for legacy support
var SWFObject = deconcept.SWFObject;


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function showHideObject(index,objectName) {
	var counter = 1;
	var ile=0;
	var zaznaczony=1;
	while(document.getElementById('sluchane'+counter)!=null) 
	{
		if (document.getElementById('sluchane'+counter).checked)
		{
			ile++;
			zaznaczony=counter;
		}
		counter++;
    }
if(ile==1)
{
document.getElementById('sluchana'+zaznaczony).checked=true;
}	
if(ile>1)
{
counter = 1;
	while(document.getElementById('sluchana'+counter)!=null) 
	{
		document.getElementById('sluchana'+counter).checked=false;
		counter++;
    }
document.getElementById('chowany').style.display='block';
}
else
{
document.getElementById('chowany').style.display='none';
}
	
if(document.getElementById('sluchane'+index).checked)
{
document.getElementById(objectName).style.display='block';
//document.getElementById('sluchana'+index).checked=true;
}
else
{
document.getElementById(objectName).style.display='none';
document.getElementById('sluchana'+index).checked=false;
}
} 

function pokazhint(nazwa,text)
{	

 document.getElementById(nazwa).innerHTML = text;
 document.getElementById(nazwa).style.top="600px";
 document.getElementById(nazwa).style.left="600px"; 
 document.getElementById(nazwa).style.visibility="visible";
};
//////////////////////////////////////////////////////////////////////////////////
function showajhint(nazwa)
{	
 document.getElementById(nazwa).style.visibility="hidden";
};	
////////////////////////////////////wysyla posta i wypelnia element//////////////////////////////////////////////
function wyslijform(form,element)
{	
advAJAX.setDefaultParameters({
//    onGroupLeave : function() { alert("wszystko zaladowane..."); },
    onInitialization : function(obj) { document.getElementById(obj.tag).innerHTML += ""; },
    onLoading : function(obj) { document.getElementById(obj.tag).innerHTML += " Loading"; },
    onSuccess : function(obj) { document.getElementById(obj.tag).innerHTML = obj.responseText; },
    onError : function(obj) { document.getElementById(obj.tag).innerHTML = "Error"; }
});
advAJAX.submit( document.getElementById(form),{tag: element });
};	

////////////////////////////////////wysyla geta i wypelnia element//////////////////////////////////////////////
function zmiendane(url,element)
{	
advAJAX.setDefaultParameters({
//    onGroupLeave : function() { alert("wszystko zaladowane..."); },
    onInitialization : function(obj) { document.getElementById(obj.tag).innerHTML += ""; },
    onLoading : function(obj) { document.getElementById(obj.tag).innerHTML += " Loading"; },
    onSuccess : function(obj) { document.getElementById(obj.tag).innerHTML = obj.responseText; },
    onError : function(obj) { document.getElementById(obj.tag).innerHTML = "Error"; }
});
advAJAX.get({ url: url, tag: element });
};	
////////////////////////////////////pytanko czy napewno wysyla geta i wypelnia element//////////////////////////////////////////////
function zmiendanepytanko(url,element,pytanie)
{	
			if(confirm(pytanie)) {
advAJAX.setDefaultParameters({
//    onGroupLeave : function() { alert("wszystko zaladowane..."); },
    onInitialization : function(obj) { document.getElementById(obj.tag).innerHTML += ""; },
    onLoading : function(obj) { document.getElementById(obj.tag).innerHTML += " Loading"; },
    onSuccess : function(obj) { document.getElementById(obj.tag).innerHTML = obj.responseText; },
    onError : function(obj) { document.getElementById(obj.tag).innerHTML = "Error"; }
});
advAJAX.get({ url: url, tag: element });
};
};	

////////////////////////////////////////pytanko czy napewno wysyla posta i wypelnia element//////////////////////////////////////////
function wyslijformpytanko(form,element,pytanie)
{	
if(confirm(pytanie)) {
advAJAX.setDefaultParameters({
//    onGroupLeave : function() { alert("wszystko zaladowane..."); },
    onInitialization : function(obj) { document.getElementById(obj.tag).innerHTML += ""; },
    onLoading : function(obj) { document.getElementById(obj.tag).innerHTML += " Loading"; },
    onSuccess : function(obj) { document.getElementById(obj.tag).innerHTML = obj.responseText; },
    onError : function(obj) { document.getElementById(obj.tag).innerHTML = "Error"; }
});
advAJAX.submit( document.getElementById(form),{tag: element });
};	
};

////////////////////////////////////////zmienia value elementy z geta//////////////////////////////////////////
function zmiendaneval(url,element)
{	
advAJAX.setDefaultParameters({
//    onGroupLeave : function() { alert("wszystko zaladowane..."); },
    onInitialization : function(obj) { document.getElementById(obj.tag).value += ""; },
    onLoading : function(obj) { document.getElementById(obj.tag).value += " Loading"; },
    onSuccess : function(obj) { document.getElementById(obj.tag).value = obj.responseText; },
    onError : function(obj) { document.getElementById(obj.tag).value = "Error"; }
});
advAJAX.get({ url: url, tag: element,parameters : { "data" : document.getElementById(element).value} });
};	
//////////////////////////////////zmieniaczka zawartosci elementu//////////////////////////////////////
		function zmienelement(pytanie,element,tresc){
			if(confirm(pytanie)) {
			document.getElementById(element).innerHTML=tresc;
//				alert( 'To wysylam.' );
			} else {
//              alert( 'Nie to nie.');
		}
		};

//////////////////////////////////zmieniaczka zawartosci elementu//////////////////////////////////////
		function zmienelement(element,tresc){
			document.getElementById(element).innerHTML=tresc;
		};
///////////////////////////////////pytaczka////////////////////////////////////
		function czynapewno(pytanie,link){
			if(confirm(pytanie)) {
			document.location = link; // do tej strony zostanie przeniesiony użytkownik 
//				alert( 'To wysylam.' );
			} else {
            return false;
		}
		};

///////////////////////////////////pytaczka////////////////////////////////////
		function czynapewnopost(pytanie){
			if(confirm(pytanie)) {
				return true;
			} else {
            return false;
		}
		};

///////////////////////////////////////play/////////////////////////////////////////////////////////////////////////////////////////////
/*
var aySound = new Array();
aySound[0] = "klik.mp3";
document.write('<BGSOUND ID="auIEContainer">')
IE = (navigator.appVersion.indexOf("MSIE")!=-1 && document.all)? 1:0;
NS = (navigator.appName=="Netscape" && navigator.plugins["LiveAudio"])? 1:0;
ver4 = IE||NS? 1:0;
onload=auPreload;

function auPreload() {
if (!ver4) return;
if (NS) auEmb = new Layer(0,window);
else {
Str = "<DIV ID='auEmb' STYLE='position:absolute;'></DIV>";
document.body.insertAdjacentHTML("BeforeEnd",Str);
}
var Str = '';
for (i=0;i<aySound.length;i++)
Str += "<EMBED SRC='"+aySound[i]+"' AUTOSTART='FALSE' HIDDEN='TRUE'>"
if (IE) auEmb.innerHTML = Str;
else {
auEmb.document.open();
auEmb.document.write(Str);
auEmb.document.close();
}
auCon = IE? document.all.auIEContainer:auEmb;
auCon.control = auCtrl;
}
function auCtrl(whSound,play) {
if (IE) this.src = play? aySound[whSound]:'';
else eval("this.document.embeds[whSound]." + (play? "play()":"stop()"))
}
function playSound(whSound) { if (window.auCon) auCon.control(whSound,true); }
function stopSound(whSound) { if (window.auCon) auCon.control(whSound,false); }

*/

/////////////////////////////////advajax//////////////////////////////////////////////////////////////////////////////////////////////////

/*
 *  AdvancedAJAX 2.0 RC2
 *  (c) 2006 Łukasz Lach
 *  mail: anakin@php5.pl
 *  www:  http://advajax.anakin.us/
 *        http://anakin.us/
 * Licensed under Creative Commons GNU Lesser General Public License
 * http://creativecommons.org/licenses/LGPL/2.1/
 */
function advAJAX() {

    this.url = window.location.href;
    this.method = 'GET';
    this.parameters = new Object();
    this.headers = new Object();
    this.mimeType = null;
    this.username = null;
    this.password = null;

    this.useJSON = false;
    this.useCache = false;

    this.requestDone = false;
    this.requestAborted = false;
    this.requestTimedOut = false;

    this.queryString = '';
    this.responseText = null;
    this.responseXML = null;
    this.responseJSON = null;
    this.status = null;
    this.statusText = null;

    this.timeout = 0;
    this.retryCount = 0;
    this.retryDelay = 1000;
    this.retryNo = 0;

    this.repeat = false;
    this.repeatCount = 0;
    this.repeatNo = 0;
    this.repeatDelay = 1000;

    this.tag = null;
    this.group = null;
    this.form = null;
    this.disableForm = true;

    this.onInitialization = null;
    this.onFinalization = null;
    this.onAbort = null;
    this.onReadyStateChange = null;
    this.onLoading = null;
    this.onLoaded = null;
    this.onInteractive = null;
    this.onComplete = null;
    this.onSuccess = null;
    this.onFatalError = null;
    this.onInternalError = null;
    this.onError = null;
    this.onTimeout = null;
    this.onRetryDelay = null;
    this.onRetry = null;
    this.onRepeat = null;
    this.onRepeatDelay = null;
    this.onGroupEnter = null;
    this.onGroupLeave = null;

    this._xhr = null;
    this._eventHandled = [ false ];

    this._timerTimeout = null;
    this._timerRepeat = null;

    this.init = function() {

        (this._xhr !== null) && this.destroy();
        if ((this._xhr = this._createXHR()) === null)
            return false;
        if (typeof advAJAX._defaultParameters != 'undefined')
            this.handleArguments(advAJAX._defaultParameters);
        if (typeof this._xhr.overrideMimeType == 'function' && this.mimeType !== null)
            this._xhr.overrideMimeType(this.mimeType);
        this._eventHandled = [ this._eventHandled[0], false, false, false, false ];

        var _this = this;
        this._xhr.onreadystatechange = function() {

            if (_this.requestAborted)
                return;
            _this._raise('ReadyStateChange', _this._xhr.readyState);
            (!_this._eventHandled[_this._xhr.readyState]) && _this._handleReadyState(_this._xhr.readyState);
        };
        return true;
    };

    this.destroy = function(abort) {

        abort = abort || false;
        try {
            abort && this._xhr.abort();
            delete this._xhr['onreadystatechange'];
        } catch(e) {
        }
        ;
        this._xhr = null;
    };

    this._createXHR = function() {

        if (typeof XMLHttpRequest != 'undefined')
            return new XMLHttpRequest();
        var xhr = [ 'MSXML2.XMLHttp.6.0', 'MSXML2.XMLHttp.5.0', 'MSXML2.XMLHttp.4.0', 'MSXML2.XMLHttp.3.0',
                'MSXML2.XMLHttp', 'Microsoft.XMLHttp' ];
        for (var i = 0; i < xhr.length; i++) {
            try {
                var xhrObj = new ActiveXObject(xhr[i]);
                return xhrObj;
            } catch (e) {
            }
            ;
        }
        this._raise('FatalError');
        return null;
    };

    this._handleReadyState = function(readyState) {

        if (this._eventHandled[readyState])
            return;
        this._eventHandled[readyState] = true;
        switch (readyState) {
            /* loading */
            case 1:
                if (this.retryNo == 0 && this.group !== null) {
                    if (typeof advAJAX._groupData[this.group] == 'undefined') {
                        advAJAX._groupData[this.group] = 0;
                        this._raise('GroupEnter', this.group);
                    }
                    advAJAX._groupData[this.group]++;
                }
                this._raise('Loading', this);
                break;
            /* loaded */
            case 2:
                this._raise('Loaded', this);
                break;
            /* interactive */
            case 3:
                this._raise('Interactive', this);
                break;
            /* complete */
            case 4:
                window.clearTimeout(this._timerTimeout);
                if (this.requestAborted)
                    return;
                this.requestDone = true;
                this.responseText = this._xhr.responseText;
                this.responseXML = this._xhr.responseXML;
                try {
                    this.status = this._xhr.status || null;
                    this.statusText = this._xhr.statusText || null;
                } catch (e) {
                    this.status = null;
                    this.statusText = null;
                }
                this._raise('Complete', this);
                if (this.status == 200) {
                    try {
                        var _contentType = this._xhr.getResponseHeader('Content-type');
                        if (_contentType.match(/^text\/javascript/i))
                            eval(this.responseText); else
                        if (_contentType.match(/^text\/x\-json/i))
                            this.responseJSON = eval('(' + this.responseText + ')');
                    } catch(e) {
                        this._raise('InternalError', advAJAX.ERROR_INVALID_EVAL_STRING);
                    };
                    this._raise('Success', this);  
                } else
                    this._raise('Error', this);
                if (this.repeat) {
                    if (++this.repeatNo != this.repeatCount - 1) {
                        this._raise('RepeatDelay', this);
                        var _this = this;
                        this._timerRepeat = window.setTimeout(function() {
                            _this._raise('Repeat', this);
                            _this.init();
                            _this.run();
                        }, this.repeatDelay);
                        return;
                    }
                }
                this.destroy();
                (this.disableForm) && this._switchForm(true);
                this._handleGroup();
                this._raise('Finalization', this);
        }
    };

    this._handleGroup = function() {

        if (this.group === null) return;
        (--advAJAX._groupData[this.group] == 0) && this._raise('GroupLeave', this);
    }

    this._onTimeout = function() {

        if (this._xhr == null || this._eventHandled[4])
            return;
        this.requestAborted = this.requestTimedOut = true;
        this._xhr.abort();
        this._raise('Timeout');
        if (this.retryNo++ < this.retryCount) {
            this.init();
            this._raise('RetryDelay', this);
            var _this = this;
            this._timerTimeout = window.setTimeout(function() {
                _this._raise('Retry', _this);
                _this.run();
            }, this.retryDelay);
        } else {
            this.destroy();
            (this.disableForm) && this._switchForm(true);
            this._handleGroup();
            this._raise('Finalization', this);
        }
    };

    this.run = function() {

        if (this.init() == false)
            return false;
        this.requestAborted = this.requestTimedOut = false;
        (!this._eventHandled[0]) && (this._raise('Initialization', this)) && (this._eventHandled[0] = true);
        if (this.retryNo == 0 && this.repeatNo == 0) {
            if (this.useJSON) {
                if (typeof [].toJSONString != 'function') {
                    this._raise('InternalError', advAJAX.ERROR_NO_JSON);
                    return;
                }
                for (var p in this.parameters) {
                    var useJson = typeof [].toJSONString == 'function';
                    (this.queryString.length > 0) && (this.queryString += '&');
                    this.queryString += encodeURIComponent(p) + '=' +
                                        encodeURIComponent(this.parameters[p].toJSONString());
                }
            } else {
                for (var p in this.parameters) {
                    (this.queryString.length > 0) && (this.queryString += '&');
                    if (typeof this.parameters[p] != "object")
                        this.queryString += encodeURIComponent(p) + '=' + encodeURIComponent(this.parameters[p]); else {
                        if (!(this.parameters[p] instanceof Array)) continue;
                        for (var i = 0, cnt = this.parameters[p].length; i < cnt; i++)
                            this.queryString += encodeURIComponent(p) + '=' + encodeURIComponent(this.parameters[p][i]) + '&';
                        this.queryString = this.queryString.slice(0, -1);
                    }
                }
            }
            (this.method == 'GET') && (this.queryString.length > 0) && (this.url += (this.url.indexOf('?') != -1 ? '&' : '?') + this.queryString);
        }
        (this.disableForm) && this._switchForm(false);
        try {
            this._xhr.open(this.method, this.url, true, this.username || '', this.password || '');
        } catch(e) {
            this._raise('FatalError', this);
            return false;
        }
        var _this = this;
        (this.timeout > 0) && (this._timerTimeout = window.setTimeout(function() {
            _this._onTimeout();
        }, this.timeout));
        if (typeof this._xhr.setRequestHeader == 'function') {
            if (this.method == 'GET' && !this.useCache)
                this._xhr.setRequestHeader('If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT');
            for (var p in this.headers)
                this._xhr.setRequestHeader(encodeURIComponent(p), encodeURIComponent(this.headers[p]));
        }
        if (this.method == 'POST') {
            try {
                this._xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
            } catch(e) {
            };
            this._xhr.send(this.queryString);
        } else if (this.method == 'GET') {
            this._xhr.send('');
        }
    };

    this.getResponseHeader = function(name) {

        return this._xhr.getResponseHeader(name) || null;
    };

    this.getAllResponseHeaders = function() {

        return this._xhr.getAllResponseHeaders() || null;
    };

    this.abort = function() {

        this.requestAborted = true;
        window.clearTimeout(this._timerTimeout);
        window.clearTimeout(this._timerRepeat);
        this._handleGroup();
        this._raise('Abort', this);
        this.destroy();
        this._raise('Finalization', this);
    },

    this._extendObject = function(target, source) {

        for (var p in source)
            target[p] = source[p];
    };

    this.handleArguments = function(args) {

        (typeof args['form'] == 'string') && (args['form'] = document.getElementById(args['form']));
        for (var p in args) {
            if (typeof this[p] == 'undefined') {
                this.parameters[p] = args[p];
            } else {
                if (p != 'parameters' && p != 'headers') {
                    this[p] = args[p];
                } else
                    this._extendObject(this[p], args[p]);
            }
        }
        this.method = this.method.toUpperCase();
        (typeof this.form == 'object') && (this.form !== null) && this._appendForm();
        (args.repeat) && (this.repeatCount++);
    };

    this._switchForm = function(enable) {

        if (typeof this.form != 'object' || this.form === null)
            return;
        var _f = this.form;
        for (var i = 0; i < _f.elements.length; i++)
            if (!enable) {
                if (_f.elements[i]['disabled'])
                    _f.elements[i]['_disabled'] = true; else
                    _f.elements[i]['disabled'] = 'disabled';
            } else {
                if (typeof _f.elements[i]['_disabled'] == 'undefined' || _f.elements[i]['_disabled'] === null)
                    _f.elements[i]['disabled'] = '';
                try {
                    delete _f.elements[i]['_disabled'];
                } catch(e) {
                    _f.elements[i]['_disabled'] = null;
                };
            }
    };

    this._appendForm = function() {

        var _f = this.form;
        this.method = _f.getAttribute('method').toUpperCase();
        this.url = _f.getAttribute('action');
        for (var i = 0; i < _f.elements.length; i++) {
            var _e = _f.elements[i];
            if (_e.disabled)
                continue;
            switch (_e.type) {
                case 'text':
                case 'password':
                case 'hidden':
                case 'textarea':
                    this._addParameter(_e.name, _e.value);
                    break;
                case 'select-one':
                    if (_e.selectedIndex >= 0)
                        this._addParameter(_e.name, _e.options[_e.selectedIndex].value);
                    break;
                case 'select-multiple':
                    var _r = [];
                    for (var j = 0; j < _e.options.length; j++)
                        if (_e.options[j].selected)
                            _r[_r.length] = _e.options[j].value;
                    (_r.length > 0) && (this._addParameter(_e.name, _r));
                    break;
                case 'checkbox':
                case 'radio':
                    (_e.checked) && (this._addParameter(_e.name, _e.value));
                    break;
            }
        }
    };

    this._addParameter = function(name, value) {

        if (typeof this.parameters[name] == 'undefined') {
            this.parameters[name] = value;
        } else {
            if (typeof this.parameters[name] != 'object')
                this.parameters[name] = [ this.parameters[name], value ]; else
                this.parameters[name][this.parameters[name].length] = value;
        }
    };

    this._delParameter = function(name) {

        delete this.parameters[name];
    };

    this._raise = function(name) {

        for (var i = 1, args = []; i < arguments.length; args[args.length] = arguments[i++]);
        (typeof this['on' + name] == 'function') && (this['on' + name].apply(null, args));
        (name == 'FatalError') && this._raise('Finalization', this);
    }

}

advAJAX._groupData = new Object();
advAJAX._defaultParameters = new Object();

advAJAX.get = function(args) {

    return advAJAX._handleRequest('GET', args);
}
advAJAX.post = function(args) {

    return advAJAX._handleRequest('POST', args);
}
advAJAX.head = function(args) {

    return advAJAX._handleRequest('HEAD', args);
}
advAJAX._handleRequest = function(requestType, args) {

    args = args || { };
    var _a = new advAJAX();
    _a.method = requestType;
    _a.handleArguments(args);
    setTimeout(function() {
        _a.run()
    }, 0);
    return _a;
};
advAJAX.submit = function(form, args) {

    args = args || {};
    if (typeof form == 'undefined' || form === null)
        return false;
    var _a = new advAJAX();
    args['form'] = form;
    _a.handleArguments(args);
    setTimeout(function() {
        _a.run()
    }, 0);
    return _a;
};
advAJAX.assign = function(form, args) {

    args = args || {};
    (typeof form == 'string') && (form = document.getElementById(form));
    if (typeof form == 'undefined' || form === null)
        return false;
    form['_advajax_args'] = args;
    var _onsubmit = function(event) {
        event = event || window.event;
        if (event.preventDefault) {
            event.preventDefault();
            event.stopPropagation();
        } else {
            event.returnValue = false;
            event.cancelBubble = true;
        }
        var _e = event.target || event.srcElement;
        return !advAJAX.submit(_e, _e['_advajax_args']);
    }
    if (form.addEventListener) {
        form.addEventListener('submit', _onsubmit, false);
    } else if (form.attachEvent) {
        form.attachEvent('onsubmit', _onsubmit);
    }
    return true;
};
advAJAX.download = function(target, url) {

    (typeof target == 'string') && (target = document.getElementById(target));
    if (typeof target == 'undefined' || target === null)
        return false;
    advAJAX.get({
        'url': url,
        'onSuccess' : function(o) {
            target.innerHTML = o.responseText;
        }
    });
};
advAJAX.setDefaultParameters = function(args) {

    advAJAX._defaultParameters = new Object();
    for (var a in args)
        advAJAX._defaultParameters[a] = args[a];
};

advAJAX.ERROR_INVALID_EVAL_STRING = -1;
advAJAX.ERROR_NO_JSON = -2;