var depth = 0;
 var dd;
var err="";  
/*****************************************************************************/
function clasify(a)
    {var b="";
      var attr="";
      var attrGroup="";
      var thisLine='';
      var d=a.split("{");
      var dd;
      try{
  
       thisLine='';
      b =  parseInt(d.length);
      for(var c=0;c<(d.length);c++)
         { depth += 1;
           b+="\n<folder expanded='true' title=\'" + thisLine +"\' img='folder.gif'>";
           aLine =d[c].split("\r");  // search on new line
           
           for (var cc=0;cc<aLine.length;cc++)	
          {    attrGroup =aLine[cc] ;
	//alert(attr);
               // b+="\n<folder title=\'" + attr +"\' img='red_ball.gif'\/>";
               
	t =attrGroup.split(";");  // search on ;
	for(var ccc=0;ccc<t.length;ccc++)	
                 {    attr = t[ccc] ;
                       //alert(attr);
	       attr = attr.replace(/\n/g, '');
	       attr = attr.replace(/\r/g, '');
	       attr = attr.replace(/\t/g, '');
	    
                      // attr = attr.replace(/ /g, '');
	     
	         if(attr.indexOf("}")== -1)
	        {  
		
	            if(thisLine.length > 1)
	           { 	  RDFencode(thisLine);
                                 if(thisLine.split("'").length ==1)
	                   {b+="\n<folder title=\'" + thisLine +"\' img='leaf.gif'\/>";}
	                   else {b+='\n<folder title=\"' + thisLine +'\" img="red_ball.gif"\/>';}
	            } // attr.length
	           
	         } else { b+= "}</folder>";
                                     depth -= 1;
                         }
	         thisLine=attr;
	} // end of for t.length
                 
	attrGroup = t[t.length-1] ;
             } // end of aLine.length
             if(attrGroup.indexOf("}")== -1)
               {
                   if(thisLine.split("'").length ==1)
	                   {b+="\n<folder expanded='true' title=\'" + thisLine +"\' img='folder.gif'";}
	                   else {b+='\n<folder expanded="true" title=\"' + thisLine +'\" img="folder.gif"';}
                
	//  b+="\n<folder img='folder.gif' expanded='true' title =\'" + attrGroup.substring(1) + "\'";
                  //RDFencode(thisLine);
	  b+=  ">" +  " ";
	}  else b+= "}</folder>";
             // alert(b);          
        } // end of for d.length
		
      return b;
     } catch(exception) { return exception.description }
    
}
/*****************************************************************************/
function RDFencode(thisLine)
    {var b="";
      var attr="";
      var p,p1,dd;
      var tmp;
      try{
                 var rdf = findObj("rdf",dd);
      	p =thisLine.split("main");
	if(p.length > 1)   rdf.value = rdf.value +  p[1] + "main\' ";
                p =thisLine.split("class");
	if(p.length > 1) 
                      {        
                                 p1 =p[1].split(":");
                                tmp = p1[0].substring(2);
		rdf.value = rdf.value + "\n<rdf:Description rdf:about =\'#" + p1[0] + "\' /> ";
                                 var d=p1[1].split(",");
                                 for(var c=0;c<(d.length);c++)
                                 {     tmp = d[c].substring(1).replace(' ', '-');
		        rdf.value = rdf.value + "\n  <rdfs:subClassOf rdf:resource =\'#" + tmp + "\' /> ";
                                 }
                                 rdf.value = rdf.value + "\n</rdf:Description>";
                       }
	//p =t.split("if");
	//if(p.length == 2)  b+= "if=\'" + p[1] + "\' ";
	//p =t.split("else");
	//if(p.length == 2)  b+= "else=\'" + p[1] + "\' ";
	//p =t.split("struct");
	//if(p.length == 2)  b+= "struct=\'" + p[1] + "\' ";
	//p =t.split("enum");
	//if(p.length == 2)  b+= "enum=\'" + p[1] + "\' ";
    return b;
     } catch(exception) { window.status = "encode ERROR" + exception.description }
    }

/*****************************************************************************
Name : toggle2
Parameters :  node DOM element (<a> tag), folderCode String
Description :    if you use the "code" attribute in a folder element, toggle2 is called
instead of toggle. The consequence is that you MUST implement a selectFolder function in your page.

*****************************************************************************/
function toggle2(node, folderCode)
{

try{
 switch (toggle(node)) 
{
     case (0):
    var s = HttpUrl(node.parentNode,folderCode);
    break
}
   // toggle(node);
   // selectFolder(folderCode);
}catch(exception) { window.status="expand error:"+exception.description + node.nodeName + node.nodeType;
                                 return true;}
}
/*****************************************************************************/
function fileBox(node, folderCode) {
try{
window.status = folderCode +":" +window.status ;
 switch (toggle(node)) 
{
     case (0):
    var s = HttpUrl(node.parentNode,folderCode);
    break
}
   // toggle(node);
   // selectFolder(folderCode);
}catch(exception) { window.status="expand error:"+exception.description + node.nodeName + node.nodeType;
                                 return true;}
}
/*****************************************************************************
Name : HttpUrl
Parameters :  node DOM element , Url to get
Description :  
*****************************************************************************/
function HttpUrl(node,url)
     {

	var str;
                var ta1,ta2;
	var xml;
	var xmlDoc1;
	var result ;
               depth = 0;
	if (url.length == 0) {
                    ta1 = document.createElement("textarea");
	  ta1.value = "Null Url string" ;
	  ta1.cols=15;
	  ta1.rows=1;
	  node.appendChild(ta1);
                    return;
   	}
            BalanceRetry = 0;
               do {
try{
             
                xml= "<?xml version='1.0' encoding='UTF-8'?>" +
                "<treeview title='" + url +"' code='14'> " ;
                
                 err = "";
                 xml  += ShowFile(url) ;

                 for(var i =0; i< BalanceRetry; i++)  xml += "</folder>" ;
                  xml += " </treeview>" ;
                 BalanceRetry++;
                 alert(BalanceRetry);
          
	//x = new ActiveXObject('MSXML2.XMLHTTP');
	//x.open('POST', url, false);
	//x.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	//x.send(str);
	// result = str.substring(p-6);
  }catch(exception) { ta1 = document.createElement("textarea");
		ta1.value = "send failed"+ exception.description+": " + str;
		ta1.cols=70;
		ta1.rows=2;
		node.appendChild(ta1); 
//var p = str.indexOf('<head>');

		

	ta2 = document.createElement("span");
	ta2.innerHTML =  result;
	node.appendChild(ta2); }
window.status = "sent"+ window.status;
	//if(null == x.responseXML || x.responseXML.xml.length <= 0)
	//xml = result;
//	if (xml.length > 0)
//	    {
		//var w = window.open('', '_search');
		//xml =x.responseText;
		//if(xml.indexOf('\/channel')!=-1){ 
                                //            xml = TWikiRssFix(xml);
		//} else {
		ta2 = document.createElement("div");

		// var align = document.createAttribute("style");
		// ta2.setAttribute("style", "overflow-y:auto;overflow-x:auto;height:15%;width:98%;");
  		//ta2.setAttributeNode(align);

                                //        var p = xml.indexOf('>');  // LINE 100
                               //  	xml = xml.replace(/<div/g, "<div style='overflow-y:auto;overflow-x:auto;height:15%;width:98%;' ");
//xml = xml.replace(/<table/g, "<table height='150' ");
	               //   ta2.innerHTML =  xml.substring(p);
	              //    node.appendChild(ta2);
                             //       return;
                               //     }
// load xsl ,should preload as global
		xsl = new ActiveXObject("MSXML2.DOMDocument.4.0");
   		xsl.async = false;
	 	xsl.load("CodeView.xsl");// =  buildXMLSource("CodeView.xsl") ;
		if(xsl.parseError.errorCode!=0)
		    {
			//var ta1 = document.createElement("textarea");
			//ta1.value =  "xsl Doc error"+ xmlDoc1.parseError.line +"-"+
			//xmlDoc1.parseError.linepos+"-"+xmlDoc1.parseError.reason +"-"+ 
			//xmlDoc1.parseError.srctext;
			//ta1.cols=70;
			//ta1.rows=2;
			//node.appendChild(ta1);
		 
		    }
// load xml
	 xmlDoc1= new ActiveXObject("MSXML2.DOMDocument.4.0");
    	xmlDoc1.async = false;
		
	xmlDoc1.loadXML(xml);//  buildXMLSource(xml) ;
                } while((BalanceRetry < 10) &&( xmlDoc1.parseError.errorCode!=0))
       	if(xmlDoc1.parseError.errorCode!=0)
		{
		ta = document.createElement("br");
		node.appendChild(ta);
		
		ta = document.createElement("textarea");
		err = xmlDoc1.parseError.reason;
		ta.name = "almost"
		ta.value = err + xmlDoc1.parseError.line +"-"+
			xmlDoc1.parseError.linepos+xml.substring(0,xmlDoc1.parseError.linepos);
		ta.cols=35;
		ta.rows=12;

		ta1 = document.createElement("button");
                            //   ta1.nodetype =''button";  // LINE 142
		ta1.value = "retry";
                              ta1.onclick = "javascript:fileBox(this,document.almost.value);";
		node.appendChild(ta1);

		ta1 = document.createElement("textarea");
		ta1.value = ""+ xml;
		ta1.cols=75;
		ta1.rows=20;
		 ta1.ondblclick = "document.almost =fileBox(this,document.almost.value);";
		//ta1.toprow(xmlDoc1.parseError.line);
		node.appendChild(ta1);
		node.appendChild(ta);
		ta2 = document.createElement("span");
                                //    var p = str.indexOf('>');
 //alert(p);
	                //  ta2.innerHTML =  xml.substring(p);
	                //  node.appendChild(ta2);			
		}
//	 }else
//	{
		//result = x.responseXML.xml;
//		ta1 = document.createElement("textarea");
//		ta1.value = result;
//		ta1.cols=70;
//		ta1.rows=18;
//		node.appendChild(ta1);
//	}
	
                 
// Apply transform
	var result =  xmlDoc1.transformNode(xsl);  
	ta2 = document.createElement("span");
	ta2.innerHTML =  result;
	node.appendChild(ta2);
	
	
           //      var AdoStreamOut = new ActiveXObject("ADODB.Stream");
            //     AdoStreamOut.Type = 1
	//AdoStreamOut.Open
	//AdoStreamOut .write(result);
	//AdoStreamOut.SaveToFile("ZZZZZ.xml", 1);
        return xml;
    }
function retryTree(a) { window.status = "retry"; }
/*****************************************************************************
Name : readfile
Parameters :  
Description :    
*****************************************************************************/
function ShowFile(file)
     {
      try{
	   var oFS = new ActiveXObject("Scripting.FileSystemObject");
	   var txtResult;	
           if(file.length > 300) return file;     
           txtResult = "<SPAN "+
               "STYLE='background-color:lightyellow;" +
               "cursor:hand;font-size:8pt;' " +
               "TITLE='"
	replaceText = readfile(oFS, file) ;

	//replaceText = replaceText.replace(/function/g, '<function/>');
	replaceText = replaceText.replace(/\n/g, '');
	replaceText = replaceText.replace(/&/g, ' ');
  	replaceText = replaceText.replace(/\t/g, '');
              //  replaceText = replaceText.replace(/ /g, '');
                replaceText = replaceText.replace(/</g, "less ")
                replaceText = replaceText.replace(/>/g, "greater ")
	 
	
	replaceText = clasify(replaceText);
           //     replaceText = replaceText.replace(/}/g, '}</folder>');
                var cls = replaceText.split('}');
       
         //  replaceText += parseInt(cls.length);
            replaceText += parseInt(depth);
           replaceText += "</folder></folder>";
         //  txtResult += replaceText;
           txtResult += "'>(show xml)</SPAN>";
	   //txtResult = format(replaceText,nodelist);
           //w = window.open("","SubjectF","resizable,status");
	//	   d = w.document;
	//	d.write(txtResult);
	//	d.close();
	   //f = createDocumentFragment();
		//xmlDoc1.loadXML(replaceText);
	  
          
           return  replaceText;
      }catch(exception) { return exception.description }
}

/*****************************************************************************
Name : readfile
Parameters :  
Description :    
*****************************************************************************/
function readfile(oFS, sFileName) {
	var sText = "";
                var oF;
	//ForReading = 1;	
	//ForWriting = 2;
	//ForAppending = 8;
	try { // always allow for fs errors...
		oF = oFS.OpenTextFile(sFileName, 1, true);
		if (!oF.AtEndOfStream) sText = oF.ReadAll();
	} catch (e) {
		sText = e.description;	
	}
	try {
		oF.Close();
	} catch (exception) {
	   //  sText = exception.description;
	}
	return sText;
}

// ---------------------------------------------------------------------------
// --- Name:    Easy DHTML Treeview                                         --
// --- Original idea by : D.D. de Kerf                  --
// ---------------------------------------------------------------------------

/*****************************************************************************
Name : toggle
Parameters :  node , DOM element (<a> tag)
Description :     Description, collapse or unfold a branch
Author : Jean-Michel Garnier /  D.D. de Kerf
*****************************************************************************/

function toggle(node) {
    // Get the next tag (read the HTML source)
	var nextDIV = node.nextSibling;

	// find the next DIV
	while(nextDIV.nodeName != "DIV") {
		nextDIV = nextDIV.nextSibling;
	}

	// Unfold the branch if it isn't visible
	if (nextDIV.style.display == 'none') {

		// Change the image (if there is an image)
		if (node.childNodes.length > 0) {

			if (node.childNodes.item(0).nodeName == "IMG") {
				node.childNodes.item(0).src = getImgDirectory(node.childNodes.item(0).src) + "minus.gif";
			}
		}

		nextDIV.style.display = 'block';
	}
	// Collapse the branch if it IS visible
	else {

		// Change the image (if there is an image)
		if (node.childNodes.length > 0) {
			if (node.childNodes.item(0).nodeName == "IMG") {
  				node.childNodes.item(0).src = getImgDirectory(node.childNodes.item(0).src) + "plus.gif";
			}
		}
		nextDIV.style.display = 'none';
	}
	return 0;
}
/*****************************************************************************
Name :hit
Parameters :  node DOM element (<a> tag), folderCode String
Description :   
Author : John Coe
*****************************************************************************/
function hit(node) {
    // Get the next tag (read the HTML source)
try{
	//var nextDIV = node.parent;

	// find the next DIV
	//while(nextDIV.nodeName != "DIV") {
	//	nextDIV = nextDIV.nextSibling;
	//}
	window.status =  "hit:"+  node.nodeName + node.getAttribute('coords');
}catch(exception) { window.status = window.status +"|" ;}
try{
	node.getAttribute('href'); 
}catch(exception) { window.status = window.status +"!" ;}
               window.status = window.status +  window.event.screenX+","+window.event.screenY;
	return true;
	
}
/*****************************************************************************
Name :KeyDown
Parameters :  
Description :   
Author : John Coe
*****************************************************************************/
	function KeyDown(node)
			{	var objParams = new Array();
 				var e = window.event.srcElement;
				var pop = window.createPopup();
				var pbody = pop.document.body;
				return;
				pbody.style.backgroundColor = "#33cc33";
			 	pbody.style.border = "solid black 1px";
				//try {
				//     initializefolderselect();
				//}catch(exception) { window.status="error:"+exception.description + node.nodeName + node.nodeType;  }
			 	pbody.innerHTML = ShowFile("file")+e.innerHTML;
                	 	pop.show(window.event.clientX,window.event.screenY ,399,350,document.body);
				if( e.className == "c" ) {e = e.parentElement;}
								//oMPC.style.visibility="visible";
				 event.keyCode ;
		
				if( 13 == event.keyCode )
				{   objParams[0] = this;
				    v = showModelessDialog("xmlEdit.html",objParams, "status:true;dialogWidth:310px;dialogHeight:300px;status: yes;");
				}
								window.status= window.status + event.keyCode ;
				if( 27 == event.keyCode )
				{
				    self.close();
				}

			}

/*****************************************************************************/
	function  TWikiRssFix(str){
		var p = str.indexOf('channel');

		if(p==-1) p = str.indexOf('CHANNEL');
		var xml = '<?xml version="1.0" encoding="iso-8859-1" ?><rdf:RDF ' +
   		'xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" ' +
      		'xmlns:dc="http://purl.org/dc/elements/1.1/" ' +
      		'xmlns="http://purl.org/rss/1.0/"  ' +
      		'xmlns:wiki="http://purl.org/rss/1.0/modules/wiki/" ><' +
		str.substring(p);
		xml = xml.replace(/46x50.gif"\/>/g, '46x50.gif">');
                                  xml = xml.replace(/&nbsp;/g, '');
       		xml = xml.replace(/%gt;/g, '>');
                                  q = xml.indexOf('<\/item><p');
                                  return xml.substring(0,q) + "</item></rdf:RDF>";
}
/*****************************************************************************
Name : getImgDirectory
Parameters : Image source path
Return : Image source Directory
Author : Jean-Michel Garnier
*****************************************************************************/

function getImgDirectory(source) {
    return source.substring(0, source.lastIndexOf('/') + 1);
}

/************************************
************* IMPORTANT *************
*************************************

The functions above are NOT used by the DHTML treeview. Netherless, have a look bc some be useful if you
need to make XSLT on the client (since IE 5.5 and soon Mozilla !)

*/


/*****************************************************************************
Name : stringExtract
Parameters :
- st String input string, contains n separators
- position int, from 0 to n, position of the token wanted
- separator char, separator between token

Return : the token at the position wanted if it exists

Description : Equivalent to class java.util.StringTokenizer
Example -> stringExtract("A; B; C", 0, ";") = "A"

Author : Jean-Michel Garnier
*****************************************************************************/

function stringExtract( st, position, separator ) {
	var array;
	var result = new String('');
	var s = new String(st);
	if (s != '' ) {
		array = s.split( separator);
		// @TODO, add a control on position value ...
		result = array[position];
	}
	return result;
}

/*****************************************************************************
Name : jsTrim
Parameters : value, String
Return : the same String, with space characters removed
Description : equivalent to trim function
Author : Jean-Michel Garnier
*****************************************************************************/

function jsTrim(value) {
    var result = "";
    for (i=0; i < value.length; i++) {
        if (value.charAt(i) != ' ') {
            result += value.charAt(i);
        }
    }
    return result;
}

/*****************************************************************************
Name : findObj
Parameters :
- n String object's name
- d Document document
Return : a reference on the object if it exists
Description : Search an object in a document from its name.
Author : Macromedia
*****************************************************************************/

function findObj(n, d) {
  var p, i, x;
  if (!d)
    d = document;
  if ( (p=n.indexOf("?") )>0 && parent.frames.length ) {
		d = parent.frames[n.substring(p+1)].document;
		n = n.substring(0,p);
  }
  if (!(x=d[n])&& d.all )
	x = d.all[n];
  for (i=0; !x && i < d.forms.length; i++)
	x = d.forms[i][n];
  for (i=0; !x && d.layers && i<d.layers.length; i++)
	x = findObj(n, d.layers[i].document);

  return x;
}

/*****************************************************************************
Name : isInSelectInput
Parameters :
- v String Option value
- select_input input SELECT
Return : true if the SELECT already value
Author : Jean-Michel Garnier
*****************************************************************************/

function isInSelectInput(v, select_input) {
	for(var i=0; i<select_input.options.length; i++) {
		if (select_input.options[i].value == v) {
			return true;
		}
	}
	return false;
}

/*****************************************************************************
Name : selectOption
Parameters :
- v_value String Option value
- select_input SELECT
Description : Select all options whose value
Author : Jean-Michel Garnier
*****************************************************************************/

function selectOption(v_value, select_input) {
	var i, nb_item;
	nb_item = select_input.options.length;
	for (i = 0; i < nb_item ; i++) {
		if ( select_input.options[i].value == v_value )
			select_input.options[i].selected = true;
	}
}

/*****************************************************************************
Name : selectRemoveSelectedOption
Parameters : select_input SELECT
Description : removes all the selected options
Author : Jean-Michel Garnier
*****************************************************************************/

function selectRemoveSelectedOption(select_input) {
    for(var i=0; i<select_input.options.length; i++) {
        if ( select_input.options[i].selected ) {
  			select_input.options[i] = null;
   		}
	}
	select_input.selectedIndex = -1;
}

/*****************************************************************************
Name : selectRemoveAll
Parameters : select_input
Description : This Function removes all options
Author : Jean-Michel Garnier
*****************************************************************************/

function selectRemoveAll(select_input) {

    var linesNumber = select_input.options.length;
    for(i=0; i < linesNumber; i++) {
		select_input.options[0] = null;
    }
	select_input.selectedIndex = -1;
}

/*****************************************************************************
Name : buildXMLSource
Parameters : xmlSource_name, String, can be a file name (.xml or .xslt) or
a String containing the xml 
!!!BE SURE xml and xlt are lowercase
Return : a reference on a ActiveX Msxml2.FreeThreadedDOMDocument with the xml loaded
Author : Jean-Michel Garnier
*****************************************************************************/

function buildXMLSource(xmlSource_name) {

    var obj, file_extension;
    obj = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
    obj.async = false;
    obj.resolveExternals = false;

    file_extension = stringExtract(xmlSource_name, 1, ".");
    // if there is a file extension, then load the file
    if (file_extension == "xml" || file_extension == "xslt" ) {
        obj.load(xmlSource_name);
    }
    else {
        // else load the XML String
        obj.loadXML(xmlSource_name);
    }

    return obj;
}

/*****************************************************************************
Name : transform
Parameters :
- xmlSource Msxml2.FreeThreadedDOMDocument ActiveX XML
- xsltSource Msxml2.FreeThreadedDOMDocument ActiveX XSLT
Return : String with the result of the transformation (not an ActiveX object !)
Description :

Author : Jean-Michel Garnier
*****************************************************************************/

function transform(xmlSource, xsltSource) {

    var xslt;
    var xslProc, paramName, paramValue;

    // Create XLST
    xslt = new ActiveXObject("Msxml2.XSLTemplate");
    xslt.stylesheet = xsltSource;

    // Add parameters
    xslProc = xslt.createProcessor();

    xslProc.input = xmlSource;

    // add parameters if present
    if (arguments.length >2 && arguments.length % 2 == 0){
        for (var i=0; i < Math.floor((arguments.length)/2)-1; i++){
            paramName = arguments[2*i+2];
            paramValue = arguments[2*i+3];
            xslProc.addParameter(paramName, paramValue);
        }
    }

    xslProc.transform();
    return xslProc.output;
}

function BrowserDetectLite() {
	var ua = navigator.userAgent.toLowerCase();

	// browser name
	this.isGecko     = (ua.indexOf('gecko') != -1);
	this.isMozilla   = (this.isGecko && ua.indexOf("gecko/") + 14 == ua.length);
	this.isNS        = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
	this.isIE        = ( (ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1) );
	this.isOpera     = (ua.indexOf("opera") != -1);
	this.isKonqueror = (ua.indexOf("konqueror") != -1);
	this.isIcab      = (ua.indexOf("icab") != -1);
	this.isAol       = (ua.indexOf("aol") != -1);
	this.isWebtv     = (ua.indexOf("webtv") != -1);

	// spoofing and compatible browsers
	this.isIECompatible = ( (ua.indexOf("msie") != -1) && !this.isIE);
	this.isNSCompatible = ( (ua.indexOf("mozilla") != -1) && !this.isNS && !this.isMozilla);

	// browser version
	this.versionMinor = parseFloat(navigator.appVersion);

	// correct version number
	if (this.isNS && this.isGecko) {
		this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('/') + 1 ) );
	}
	else if (this.isIE && this.versionMinor >= 4) {
		this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
	}
	else if (this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
   }
   else if (this.isOpera) {
		if (ua.indexOf('opera/') != -1) {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera/') + 6 ) );
		}
		else {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera ') + 6 ) );
		}
	}
	else if (this.isKonqueror) {
		this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
	}
	else if (this.isIcab) {
		if (ua.indexOf('icab/') != -1) {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab/') + 6 ) );
		}
		else {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab ') + 6 ) );
		}
	}
	else if (this.isWebtv) {
		this.versionMinor = parseFloat( ua.substring( ua.indexOf('webtv/') + 6 ) );
	}

	this.versionMajor = parseInt(this.versionMinor);
	this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );

	// dom support
   this.isDOM1 = (document.getElementById);
	this.isDOM2Event = (document.addEventListener && document.removeEventListener);

   // css compatibility mode
   this.mode = document.compatMode ? document.compatMode : 'BackCompat';

	// platform
	this.isWin   = (ua.indexOf('win') != -1);
	this.isWin32 = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
	this.isMac   = (ua.indexOf('mac') != -1);
	this.isUnix  = (ua.indexOf('unix') != -1 || ua.indexOf('linux') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)

	// specific browser shortcuts
	this.isNS4x = (this.isNS && this.versionMajor == 4);
	this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
	this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
	this.isNS4up = (this.isNS && this.versionMinor >= 4);
	this.isNS6x = (this.isNS && this.versionMajor == 6);
	this.isNS6up = (this.isNS && this.versionMajor >= 6);
	this.isNS7x = (this.isNS && this.versionMajor == 7);
	this.isNS7up = (this.isNS && this.versionMajor >= 7);

	this.isIE4x = (this.isIE && this.versionMajor == 4);
	this.isIE4up = (this.isIE && this.versionMajor >= 4);
	this.isIE5x = (this.isIE && this.versionMajor == 5);
	this.isIE55 = (this.isIE && this.versionMinor == 5.5);
	this.isIE5up = (this.isIE && this.versionMajor >= 5);
	this.isIE6x = (this.isIE && this.versionMajor == 6);
	this.isIE6up = (this.isIE && this.versionMajor >= 6);

	this.isIE4xMac = (this.isIE4x && this.isMac);
}

