//-------------------------------------------------- 
// XML representation of client browser capabilities
//-------------------------------------------------- 

	var		_version = "1.0";

	function getVersion()
	{
		return _version;
	}

	function putXMLLine_debug (src, txt, level)
	{
		var tabstr = "";
		if (typeof(level) != "undefined")
		{
			for (var i=0; i<level; i++)
			{
				tabstr += "\t";
			}
		}
		src += tabstr + txt + "\n";
		return src;
	}

	function putXMLLine (src, txt, level, encodeline)
	{
		var line = txt;
		
		if (encodeline == "full")
		{		
			line = encodeURI(line);
			line = line.replace (new RegExp("&","g"), "%26");
			line = line.replace (new RegExp("\\+","g"), "%2b");
			line = line.replace (new RegExp("-","g"), "%2d");
			line = line.replace (new RegExp("_","g"), "%5f");
			line = line.replace (new RegExp("%20","g"), " ");
		}
		else if (encodeline == "smart")
		{			
			line = line.replace (new RegExp("&","g"), "%26");
			line = line.replace (new RegExp("\\+","g"), "%2b");
		}

		src += line;
		
		return src;
	}
	
	function scriptReturnedValues(xmlsrc, maxlen, encoderes)
	{
		var _maxlen = maxlen - 100;
		
		var askObjectName = new Array(8);
		var askObjectTagname = new Array(8);
		var askObjectComment = new Array(8);
		var askObjectProps = new Array(8);
		
		var i = 0;
		
		askObjectTagname[i] = "flash";
		askObjectName[i] = "";
		askObjectComment[i] = "Result of Flash detection";
		askObjectProps[i] = new Array ("is_flash5", "is_flash6", "is_flash7", "is_flash8", "plugin_version");
		i++;
		
		askObjectTagname[i] = "screen";
		askObjectName[i] = "screen";
		askObjectComment[i] = "Screen properties";
		askObjectProps[i] = new Array ("width", "height", "colorDepth");
		i++;
		
		askObjectTagname[i] = "window";
		askObjectName[i] = "self";
		askObjectComment[i] = "Window properties";
		askObjectProps[i] = new Array ("innerWidth", "innerHeight", "outerWidth", "outerHeight",
									   "screenX", "screenY", "screenLeft", "screenTop", "clientWidth",
									   "clientHeight");
		i++;
	
		askObjectTagname[i] = "window_more";
		askObjectName[i] = "document.body";
		askObjectComment[i] = "";
		askObjectProps[i] = new Array ("clientWidth", "clientHeight", "clientTop", "clientLeft");
		i++;
	
		askObjectTagname[i] = "browser_detected";
		askObjectName[i] = "";
		askObjectComment[i] = "Browser type reported by detection scripts";
		askObjectProps[i] = new Array ("agt", "is_ie", "is_ns", "is_opera", "is_firefox", "browserVersion");
		i++;

		askObjectTagname[i] = "functions";
		askObjectName[i] = "self";
		askObjectComment[i] = "Capabilities of window movement";
		askObjectProps[i] = new Array ("moveTo", "resizeTo");
		i++;

		askObjectTagname[i] = "platform_detected";
		askObjectName[i] = "";
		askObjectComment[i] = "OS detected by scripts";
		askObjectProps[i] = new Array ("is_win", "is_win32", "is_win2k", "is_win16", "is_win98", "is_winnt", "is_unix", "is_linux",
									    "is_mac", "osVersion");
		i++;

		askObjectTagname[i] = "browser";
		askObjectName[i] = "navigator";
		askObjectComment[i] = "Reported by navigator object";
		askObjectProps[i] = new Array ("appVersion", "appMinorVersion", "appCodeName", "appName", "cookieEnabled",
		                               "cpuClass", "platform", "userAgent");
		i++;
	
	
		for (var objind=0; objind<askObjectName.length; objind++)
		{
			var backupxmlsrc = xmlsrc;
			var xmlsection = "";
			
			var tagname = askObjectTagname[objind]
			var objname = askObjectName[objind];
			var objcomm = askObjectComment[objind];
	
			if (objname == "")
			{
				var xmlobjname = "vars";
			}
			else
			{
				var xmlobjname = objname;
			}
			xmlsection = putXMLLine (xmlsection, "<" + tagname + " obj=\""+xmlobjname+"\">", 0, encoderes);
			
			for (var propind=0; propind<askObjectProps[objind].length; propind++)
			{
				var propname = askObjectProps[objind][propind];
				
				if (objname == "")
				{
					var propstr = propname;
				}
				else
				{
					var propstr = objname + "." + propname;
				}
				var propval = eval(propstr);
				var proptype = typeof(propval);
				
				if (proptype == "number")
				{
					proptype = "num";
				}
				else if (proptype == "string")
				{
					proptype = "str";
				}
				else if (proptype == "boolean")
				{
					proptype = "bool";
					if (propval)
					{
						propval = "1";
					}
					else
					{
						propval = "0";
					}
				}
				else if (proptype == "object" || proptype == "function")
				{
					proptype = "";
					propval = "exist"
				}
				
				if (proptype == "")
				{
					xmlsection = putXMLLine (xmlsection, "<" + propname + " v=\""+propval+"\" />", 1, encoderes);
				}
				else if (proptype == "undefined")
				{
					xmlsection = putXMLLine (xmlsection, "<" + propname + " v=\"NaN\" />", 1, encoderes);
				}
				else
				{
					xmlsection = putXMLLine (xmlsection, "<" + propname + " v=\""+propval+"\" t=\""+proptype+"\" />", 1, encoderes);
				}
			}
			
			xmlsection = putXMLLine (xmlsection, "</" + tagname + ">", 0, encoderes);
			
			xmlsrc += xmlsection;
			
			// explorer meretkorlat miatt
			if (xmlsrc.length > _maxlen)
			{
				xmlsrc = backupxmlsrc;
				xmlsrc = putXMLLine (xmlsrc, "<" + tagname + " obj=\""+xmlobjname+"\" skipped=\"1\" />", 0, encoderes);
			}
		}
		
		return xmlsrc;	
	}


	function timedOut()
	{
		if (!popupok)
		{
			xmlsrc = putXMLLine(xmlsrc, "<popuptest v=\"failed\" />", 0, encoderes);
		}
		if (!flashcallbackok)
		{
			xmlsrc = putXMLLine(xmlsrc, "<flash_callback v=\"failed\" />", 0, encoderes);
		}
		getBrowserCapabilities_finish();
	}
	
	// ezt majd a popupbol hivjuk, ha megnyilt
	function popupCallback()
	{
		popupok = true;
		
		xmlsrc = putXMLLine(xmlsrc, "<popuptest v=\"ok\" />", 0, encoderes);
		
		if (flashcallbackok)
		{
			window.clearTimeout(timeoutid);
			getBrowserCapabilities_finish();
		}
	}

	function flashCallback()
	{
		flashcallbackok = true;
		
		xmlsrc = putXMLLine(xmlsrc, "<flash_callback v=\"ok\" />", 0, encoderes);
		
		if (popupok)
		{
			window.clearTimeout(timeoutid);
			getBrowserCapabilities_finish();
		}
	}	
	

	
	function getBrowserCapabilities(_callback_func, maxlen, _encoderes)
	{
		xmlsrc = "";
		callback_func = _callback_func;
		encoderes = _encoderes;

		// eloszor a scriptek adta cucc
		xmlsrc = scriptReturnedValues(xmlsrc, maxlen, _encoderes);
		
		popupok = false;
		flashcallbackok = false;
		
		// meg egy ropke popup teszt...
		var left = screen.width - 5;
		var right = screen.height - 5;
		var props = "width=10,height=10,screenX="+left+",screenY="+top+",left="+left+",top="+top+",status=no,menubar=no,scrollbars=yes,resizable=yes,personalbar=no,location=no,toolbar=no,fullscreen=no";
		var wh = window.open ("/detection/popup_test.html", "_blank", props);
		
		// meg egy flash callback...
		if (is_flash6)
		{
			var flashsrc = "";
			var flashwidth = 10;
			var flashheight = 10;
			flashsrc += "	<OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"";
			flashsrc += "	codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\"";
			flashsrc += "	WIDTH="+flashwidth+" HEIGHT="+flashheight+" id=movie ALIGN=\"\">";
			flashsrc += "	   <PARAM NAME=movie VALUE=\"/detection/flash_callback.swf\">";
			flashsrc += "	   <PARAM NAME=quality VALUE=high>";
			flashsrc += "	   <PARAM NAME=wmode VALUE=transparent>";
			flashsrc += "	   <PARAM NAME=menu VALUE=false>";
			flashsrc += "	   <EMBED src=\"/detection/flash_callback.swf\" quality=high menu=false wmode=transparent allowscale=true WIDTH=\""+flashwidth+"\" HEIGHT=\""+flashheight+"\" NAME=\"movie\" ALIGN=\"\" TYPE=\"application/x-shockwave-flash\" PLUGINSPAGE=\"http://www.macromedia.com/go/getflashplayer\"></EMBED>";
			flashsrc += "	</OBJECT>";
			
			document.write (flashsrc);
		}
		
		
		timeoutid = window.setTimeout ("timedOut()", 3000);
	}
	
	function getBrowserCapabilities_finish()
	{
		callback_func(xmlsrc);
	}
	
