	var MAXDEPTH = 13;
	var topLink = "";
	var linkTree = new Array(); 
	var curDepth = 1; // current depth of deepest map place
	
	// adds depth of the item to the array
	function addToTree(linkId, level)
	{
		var itm = new Array();
		itm[0] = linkId;
		itm[1] = level;
		for (var i=0; i<linkTree.length; i++)
		{
			if (linkTree[i][0] == linkId) return;
		}
		
		linkTree[linkTree.length] = itm;
	}
	
	// returns depth of the item
	function getFromTree(linkId)
	{
		for (var i=0; i<linkTree.length; i++)
		{
			if (linkTree[i][0] == linkId) return linkTree[i][1];
		}
		return -1;
	}
	
	function deleteOldRows()
	{
		var tbl = _getEl("tshootinner");
		if (tbl)
		{
			var rows = tbl.rows;
			if (rows != null)
				for (var i=0; i<rows.length;i++)
					if (rows[i].depth >= curDepth)
						_clearEl(rows[i]);
		}
	}
	
	// this function obtains actual issue list using AJAX
	// product = SQ,XB,CX,CHK
	// link = node ID or POSITION
	// NoBL = do not include link to parent
	// wiki = name of wiki article to display
	var lastEventSrc = null;
	function getInfo(product, currentPath, link,noBL, wiki)
	{
		var imgx = _getEl("img"+link);
		if (imgx)
		{
			if (imgx.src.indexOf('expand_open') != -1)
			{
				imgx.src='img/expand_close.gif'
				curDepth = getFromTree(link);
				deleteOldRows();
				return;
			}
			else
			{
				imgx.src='img/expand_open.gif';
			}
		}
	
		curDepth = getFromTree(link);
		if (curDepth == -1) curDepth = 1;
		deleteOldRows();
	
		lastEventSrc =  ((currentPath != null) && imgx) ? _getParent(imgx,'TR') : null;
		
		var row = _createEl("tr",{});
		row.depth = 999;
		var nbs = "";
		for (var n=0; n<curDepth-1; n++)
			row.appendChild(_createEl("td",{}));
		var td = _createEl("td",{width:'20px'});
		td.appendChild(_createEl("img",{src:"img/load_icon.gif"}));
		row.appendChild(td);

		td = _createEl("td",{});
		td.colspan = (MAXDEPTH-curDepth-1);
		td.appendChild(_createEl("span",{},texts["load"]));
		row.appendChild(td);

		if (lastEventSrc != null) 
			 _insertAfter(row,lastEventSrc); 
		else
		{
			var tbl = _createEl("table", {className:"data",id:'tshootinner',cellspacing:'0', cellpadding:'1'});
			var tBody = _createEl("tbody",{});
			tbl.appendChild(tBody);				
			tBody.appendChild(row);
			var resp = document.getElementById('tshoot');
			_clearEl(resp);
			resp.appendChild(tbl);
		}

		var withAt = (link.indexOf("@") == 0);
		var aLink = link;
		if (link.indexOf("/") != -1)
		{
			var prods = link.split("/"); 

			link = prods[1];
			aLink = link;
			product = prods[0];
			
			if (withAt)
			{
				link = "@"+link;
				product = product.substring(1);
			}
			_setOpt(_getById('i_product'),product);
		}
		
		if (curDepth == 1)
		{
			if (_getEl("a_"+aLink))
				topLink = currentPath;
			if (_getEl("i_subject2"))
				_getEl("i_subject2").innerHTML = "(" +topLink+")";
			if (_getEl("relatedto"))
				_getEl("relatedto").value = topLink;
		}
		_status(link + "@" + product);
		_getById("_ts_load").style.display = 'block';
	
		document.getElementById("dPath").innerHTML = link;
		document.getElementById("path").value = link;
		
		try
		{			
			var request = XHRFactory.getInstance();
			request.open('POST', tsUrl, true);
			request.onreadystatechange = function()
			{
				if (request.readyState == 4)
				{
           			if (/^(200|304)$/.test(request.status.toString())) 
					{
						
						if(wiki)
							showWiki(wiki);
						else
							buildTree(request.responseXML,link);
						
						XHRFactory.release(request);
					}
				
					else if (request.status == 404)
					{
						document.getElementById('tshoot').innerHTML = "<b>Loading failed</b>";	
					}
				}
			};
			
			var href = "link="+link+"&product="+product+(("en" != currentLang) ? "&lang="+currentLang : "");
			request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset:UTF-8");
			request.send(href);
		
		}
		catch (ex)
		{
			alert("GI#" + ex + "/" + ex.message);
		}
	}
	
	function appendNBS(row,last)
	{
		var bitMask = row.btree;
		for (var n=1; n<row.depth; n++) 
		{
			if (n == (row.depth-1))
				row.appendChild(_createEl("td",{valign:(last ? "top" : "middle"), className:(last? "cell last" : "cell join" )}));
			else
			{
				var bit = Math.pow(2,n-1);
				if ((bit & bitMask) == bit)
					row.appendChild(_createEl("td",{className:"cell line"}));
				else
					row.appendChild(_createEl("td",{className:"cell"}));
				
			}
		}
	}
	
	// **************************************************************************************************
	// called by AJAX request (getInfo fn)
	// displays the troubleshooting tree
	// XML = response from TShootServlet, LNK = parent node ID
	var prevXML = null;
	var prevLNK = null;
	function buildTree(_xml, _lnk)
	{
		var depthBits = 0; // bit map for current tree
		var depth = getFromTree(_lnk); // depth of current row
		if (depth == -1) depth = 1;
		
		deleteOldRows();
	
		var showPath = true;
		var obj2 = _getById('i_product');
		var product = (obj2 != null) ? _getOpt(obj2).value : null;
		if (product == null) product = "SQ";

		var lnk = (_lnk == null) ? prevLNK : _lnk;
		if (_lnk != null) prevLNK = _lnk;
	
		var xml = (_xml == null) ? prevXML : _xml;
		if (_xml != null) prevXML = _xml;
		//try
		{
			var canEdit = (usrType == 'VIP') ? true : false;
			var list = xml.getElementsByTagName('message');
			//alert(list);
			var resp = document.getElementById('tshoot');
			var data = "";
			
			var itemCnt = 0;
			var cntLink = 0;
			var prevID = 666;

			var reRTP = /\[RTP\]/i;
			var reRMA = /\[RMA\]/i;
			var reKB = /\[KB:[ ]*(.*)\]/i;
			var reAR = /\[AR:[ ]*([0-9]+)[;]*(.*)\]/i;
			var reDOWNLOAD = /\[A:[ ]*(.*):[ ]*(.*)\]/i;
			var reANCH = /#([^:]+):/i;
			var reGT = /\[GOTO:[ ]*(.+)\]/i;
			
			var isLang = ("en" != currentLang); // is english translation
			var isAllTranslated = isLang; // is all on this page translated to local language?
			
			var edRows = (product == 'SQ2') ? 6 : 3;
			
			var tbl = _createEl("table", {className:"data",id:'tshootinner',cellspacing:'0', cellpadding:'2'});
			var tBody = _createEl("tbody",{});
			
			if (isAllTranslated)
			{
				for (var i =0; i<list.length; i++)
				{
					var text = list[i].getElementsByTagName('text');
					var isOk = false;
					
					for (var t =0; t<text.length; t++)
					{
						if (text[t].getAttribute("lang") == currentLang)
						{
							isOk = true;
							break;
						}
					}
					
					if (isOk) continue;
					
					isAllTranslated = false;
					break;					
				}
				
				if (_getEl("RES_enonly"))
					_getEl("RES_enonly").style.display = (isAllTranslated ? "none" : "block");
			}

			var numQuestions = canEdit ? 1 : 0;
			var numAnswers = 0;
			for (var i =0; i<list.length; i++)
			{
				var isQuestion = (list[i].getAttribute("type") == 0);
				if (isQuestion) continue;
					
				var name = "";
				var text = list[i].getElementsByTagName('text');
				for (var t =0; t<text.length; t++)
				{
					if (text[t].getAttribute("lang") == "en")
					{
						name = text[t].firstChild.nodeValue;
					}
				}
					
				var isCheck = ((name.indexOf('@') >= 0) && (name.indexOf('@') <= 2)) ? true : false;
				var isFixed = ((name.indexOf('^') >= 0) && (name.indexOf('^') <= 2)) ? true : false;
				var isFAQ = ((name.indexOf('?') >= 0) && (name.indexOf('?') <= 2)) ? true : false;
				var isRTP = ((name.indexOf('[RTP]') >= 0) || (name.indexOf('[RMA]') >= 0)) ? true : false;
				
				if (!(isCheck || isFixed || isFAQ || isRTP))
					numAnswers ++;
			}
			
			for (var i =0; i<list.length; i++)
			{
				var isQuestion = (list[i].getAttribute("type") == 0);
				var visible = (tsSearchResult == null) || (tsSearchResult[list[i].getAttribute("id")] != null) || (numAnswers == 0);
				if (visible)
					numQuestions += isQuestion ? 1 : 0;
			}
			
			
			var row = depthBits;
			if (lastEventSrc != null) 
				depthBits = lastEventSrc.btree;
			//if (depthBits == 0)
				//depthBits = 1;

			var lastQuestionBit = depthBits;

			var isLastQ = false;
			var isLastA = false;
			var cntResults = -1;
			for (var i =0; i<list.length; i++)
			{
				var _ID = list[i].getAttribute("id"); 
				var cName = (numAnswers > 0) ? "gray" : "bright";

				// ignore items that doesn't match filter
				cntResults = (tsSearchResult == null) ? -1 : (tsSearchResult[_ID] == null) ? 0 : tsSearchResult[_ID];
				if (cntResults == 0)
					if (numAnswers > 0) continue;

				// ALL Items are divided into category questions and answers
				var isQuestion = (list[i].getAttribute("type") == 0);
				if (isQuestion) isLastA = false;

				if (i == (list.length-1)) { isLastQ = true; isLastA = !canEdit; }
				
				if (cntResults == -1) // if nothing has been searched
				{
					if ((i < list.length -2) && !isQuestion && (list[i+1].getAttribute("type") == 0))
						isLastA = true;
				}
				else
				{
					var nothingVisible = true;
					for (var x=i+1;x<list.length;x++)
					{
						var visible = (tsSearchResult[list[x].getAttribute("id")] != null) || (numAnswers == 0);
						if (visible && (list[x].getAttribute("type") == 0))
							isLastA = true;
						if (visible) { nothingVisible = false; break; }
					}
					if (nothingVisible) isLastA = true;
				}
					
				if (isQuestion && (--numQuestions == 0)) isLastQ = true;
				
				var link = _ID;
				var name = "";
				var name_loc = null;
				var answer = "";
				

				var text = list[i].getElementsByTagName('text');
				for (var t =0; t<text.length; t++)
				{
					if (text[t].getAttribute("lang") == "en")
					{
						name = text[t].firstChild.nodeValue;
					}
					else
						name_loc = text[t].firstChild.nodeValue;
				}
				
				var aLink = link;
				if (link && (link.indexOf("/") != -1))
				{
					var prods = link.split("/");
					aLink = prods[1];
				}
				
				name = name.replace(/'/g,"`").replace(/"/g,"`");
				name = trimAll(name);
				
				var origName_loc = "-"+ currentLang + " TRANSLATION-";
				if (name_loc != null)
				{	
					name_loc = name_loc.replace(/'/g,"`").replace(/"/g,"`");
					name_loc = trimAll(name_loc);
					origName_loc = name_loc;
				}

				var origName = name;
				if (isAllTranslated && (name_loc != null)) name = name_loc;
								
				// can continue with next question
				var isNext = true;

				// transformation of anchors every branch can start with #ANCHOR_NAME: text of the branch
				var anch = reANCH.exec(name);
				//if (anch != null)
				//		alert (anch[1]);

				// this element will be displayed after all elements are checked
				var isAfterChecklist = ((name.indexOf('!') == 1) || (name.indexOf('!') == 2)) ? true : false;
				
				// RTP tag (leads to report the problem)
				var rtp = reRTP.exec(name);
				if (rtp != null)
				{
					if (!isQuestion)
						name = texts["troub_rtp"];
					else
						name = name.replace('[RTP]','<a class="rtp" href="#" onClick="reportTheProblem()">'+texts["troub_rtp"]+'/a>');
				}

				// RMA tag (leads to RMA from)
				var rma = reRMA.exec(name);
				if (rma != null)
				{
					if (!isQuestion)
						name = texts["troub_rma"];
					else
						name = name.replace('[RMA]','<a href="#" onClick="setStep(3)">'+texts["troub_rma"]+'</a>');
				}
				
				name = name.replace(reANCH,'');

				// @ tag denotes checklist
				var isCheck = ((name.indexOf('@') >= 0) && (name.indexOf('@') <= 2)) ? true : false;
				if (isCheck)
					name = name.substring(name.indexOf('@')+1);

				// ^ tag denotes FIXED item, with not hyperlink
				var isFixed = ((name.indexOf('^') >= 0) && (name.indexOf('^') <= 2)) ? true : false;
				if (isFixed)
					name = name.substring(name.indexOf('^')+1);
								
				var gt = reGT.exec(name);

				var txt = "";
				
				var fn = "showWiki";
				var kb = reKB.exec(name);
				var kbText = "";
				if (kb != null)
				{
					name = name.replace(reKB,'');
					kbText = kb[1];
				}
				else
				{
					fn = "showAr";
					kb = reAR.exec(name);
					if (kb != null)
					{
						name = name.replace(kb[0],'');
						if ((kb.length > 2) && ('' != kb[2]))
							kbText = kb[2];
						else
							kbText = "installation guide";
					}
				}
				
				// ? tag denotes Q&A / FAQ item
				var isFAQ = ((name.indexOf('?') >= 0) && (name.indexOf('?') <= 2)) ? true : false;
				if (isFAQ)
				{
					answer = name.substring(name.indexOf('\n') + 1);
					name = name.substring(name.indexOf('?')+1,name.indexOf('\n'));
					var reANS = /^[*](.*)$/gim;
					
					var ans = reANS.exec(answer);
					while (ans != null)
					{
						answer = answer.replace(ans[0],"<li class='ul2'>"+ans[1]+"</li>");
						ans = reANS.exec(answer);
					}
					
					answer = answer.replace(/\n\n/g,"<br>");
				}
				
				//name = curDepth+ ":" + name;
				
				// this is overall text for the section
				// typically the major question
				if (isQuestion)
				{
					
					// if editable, display edit dlg
					if (canEdit && (prevID != 666))
					{
						
						row = _createEl("tr",{});
						row.depth = curDepth;
						row.prevId = _lnk;

						var bTree = depthBits | ((isLastQ ? 0 : 1)*Math.pow(2,row.depth-1));
						
						if (lastEventSrc != null) 
						{ 
							_insertAfter(row,lastEventSrc); lastEventSrc = row; 
						}
						else
							tBody.appendChild(row);

						row.btree = bTree;
						appendNBS(row,isLastQ);
						row.appendChild(_createEl("td",{className:cName,valign:top,colSpan:(MAXDEPTH-depth)},
							"<img src='img/bullet.png' style='margin-bottom: -2px'>"
							+ 		"<textarea rows='"+edRows+"' class='add_a' id='edit_"+_ID+"' onFocus='doFocus(this,true)' onBlur='doFocus(this,false)'>"+_ADD_DEFV+"</textarea>"
							+		"<input type='hidden' id='link_"+_ID+"' value='"+prevID+"'>"
							+		"<a class='btn1' href='#' onClick='_sub(\""+_ID+"\",\""+lnk+"\",1)'>+</a>"
							,true));							
					}
					

					row = _createEl("tr",{});
					row.depth = curDepth;
					row.prevId = _lnk;
					var bTree = depthBits | ((isLastQ ? 0 : 1)*Math.pow(2,row.depth-1));

					if (lastEventSrc != null) 
					{ 
						_insertAfter(row,lastEventSrc); lastEventSrc = row; 
					}
					else
						tBody.appendChild(row);
						

					row.btree = bTree;
					//lastQuestionBit = row.btree;
					appendNBS(row,isLastQ);
					row.appendChild(_createEl("td",{className:cName,width:'20px', valign:top},
						"<img style='margin-bottom: -3px;' src='img/help.png'>",true));
						
					row.appendChild(_createEl("td",{className:cName,valign:top,colSpan:(MAXDEPTH-row.depth-(canEdit ? 2 : 0))},
						"<div id='_ed"+_ID+"' style='display:none'>"
						+			"<textarea rows='"+edRows+"'  class='add_a' id='edit_"+_ID+"'>"+origName+"</textarea>"
						+			(isLang ? "<br><textarea rows='"+edRows+"' class='add_al'  id='edit_"+_ID+"_loc'>"+origName_loc+"</textarea>" : "")
						+			"<input type='hidden' id='link_"+_ID+"' value='"+_ID+"'>"
						+			"<a class='btn1' href='#' onClick='_sub(\""+_ID+"\",\""+lnk+"\")'>+</a>"
						+		"</div>"
						+		"<div id='_bl"+_ID+"'>"
						+		((isFAQ) 
								? "<b><a class='tsm' onClick='showFAQ(\""+_ID+"\")'>" + name + "</a></b>"				
						 		: "<b>" + name + "</b>"
								)
						+ 		((kb != null)
									? ("<br><b>"+texts["troub_chk"]+"</b><a href='#' onClick='"+fn+"(\""+kb[1]+"\")' alt='Show knowledge base article'>" +kbText+ "</a>")
									: "") 
						+ 		"</div>"
						,true));
						
					if (canEdit) 
					{
						row.appendChild(_createEl("td",{className:cName},
							"<a class='btn1' href='#' onClick='_delete(\""+_ID+"\",\""+lnk+"\")'>x</a>",true));
						if (name_loc != null)
							row.appendChild(_createEl("td",{className:cName},
								"<a class='btn1' href='#' onClick='_edit(\""+_ID+"\")'>e</a>",true));
						else
							row.appendChild(_createEl("td",{className:cName},
								"<a class='btn1' href='#' onClick='_edit(\""+_ID+"\")'>e/l</a>",true));
					}							
					prevID = _ID;
										
				}
				// ********************************* this is the answer to the the question above
				else
				{				
					var anchor = reDOWNLOAD.exec(name);
					if (anchor != null)
					{
						name = name.replace(reDOWNLOAD,"<a href='/download/"+anchor[1]+"'>"+anchor[2]+"</a>");
					}
					var onClick = "";
					
					var obc = ""; // onBeforeClick
					if (isAfterChecklist)
					{
						obc = "if (updateChkList()) ";
					}
					
					var xname = (name.indexOf("<br>") != -1) ? name.substring(0,name.indexOf("<br>")) : name;
					var xname = xname.replace(/<[^>]*>/ig,"").replace(/^\s\s*/, '').replace(/\s\s*$/, '');
					var xpath = xname;
					
					isNext = false;
					if (rma != null)
						onClick = "onclick='setStep(3)'";
					else if (rtp != null)
						onClick =  "onclick='"+obc+"reportTheProblem()'";
					else
					{
						isNext = true;
						if(kb != null)
							onClick = "onclick='"+obc+"getInfo(\""+product+"\",\"" + xpath + "\",\"" + link + "\", false, \"" + kb[1] + "\")'";
						else
							onClick = "onclick='"+obc+"getInfo(\""+product+"\",\"" + xpath + "\",\"" + link + "\")' ";
							
						addToTree(link,curDepth+2);
					}

					if (isFAQ) 
						onClick= "onclick='showFAQ("+_ID+")' ";
					
					var kbLink = (kb != null) 
									? "<b>"+texts["troub_chk"]+" </b><a href='#' onClick='"+fn+"(\""+kb[1]+"\")' alt='Show knowledge base article'>" + kbText+ "</a>" 
									: "" ;
						
						
					row = _createEl("tr",{});
					row.depth = curDepth+1;
					row.prevId = _lnk;
					
					var bTree = lastQuestionBit | ((isLastQ ? 0 : 1)*(Math.pow(2,row.depth-3)) | (isLastA ? 0 : 1)*(Math.pow(2,row.depth-2)));
					
					
					if (lastEventSrc != null) 
					{ 
						_insertAfter(row,lastEventSrc); lastEventSrc = row; 
					}
					else
						tBody.appendChild(row);

					row.btree = bTree;
					appendNBS(row,isLastA);
					var tdx = _createEl("td",{className:cName,width:'20px', valign:top},
						((!isCheck)
							? ((isFixed || isFAQ) 
									? "<img src='img/ppfeill.gif' style='margin-bottom: -2px'>" 
									: (isNext 
											? "<img id='img"+_ID+"' src='img/expand_close.gif' style='margin-bottom: -2px; cursor:pointer;' "+onClick+">"
											: "<img src='img/bullet.png' style='margin-bottom: -2px'>"))
							: "<input type='checkbox' value='"+xname+"'/>"
							)
						,true);
					row.appendChild(tdx);

					row.appendChild(_createEl("td",{className:cName,valign:top, colSpan:(MAXDEPTH-row.depth-(canEdit ? 2 : 0))},
						"<div  id='_ed"+_ID+"' style='display:none' >"
						+			"<textarea rows='"+edRows+"' class='add_a' type='text' id='edit_"+_ID+"' >"+origName+"</textarea>"
						+			(isLang ? "<br><textarea rows='"+edRows+"' class='add_al' type='text' id='edit_"+_ID+"_loc' >"+origName_loc+"</textarea>" : "")
						+			"<input type='hidden' id='link_"+_ID+"' value='"+_ID+"'>"
						+			"<a class='btn1' href='#' onClick='_sub(\""+_ID+"\",\""+lnk+"\")'>+</a>"
						+		"</div>"
						+		"<div id='_bl"+_ID+"' "+(!isNext ? " style='background-color:#CCC'" : "")+">"
						+	((!isCheck && !isFixed)
								? "<a id='a_"+aLink+"' class='tsm' href='#a_"+aLink+"' " + onClick + "><div>"
									+ 	name 
									+ 	"</div></a>"
								: "<div>"  + name + "</div>"
								)
						+ 		kbLink
						+		"</div>"
						,true));

						if (canEdit) 
						{
							row.appendChild(_createEl("td",{className:cName},
								"<a class='btn1' href='#' onClick='_delete(\""+_ID+"\",\""+lnk+"\")'>x</a>",true));
							if (name_loc != null)
								row.appendChild(_createEl("td",{className:cName},
									"<a class='btn1' href='#' onClick='_edit(\""+_ID+"\")'>e</a>",true));
							else
								row.appendChild(_createEl("td",{className:cName},
									"<a class='btn1' href='#' onClick='_edit(\""+_ID+"\")'>e/l</a>",true));
						}							
						
					cntLink++;
				}
				
				if (cntResults >= 0)
				{
					row.appendChild(_createEl("td",{className:cName},( (isQuestion) ? "" : cntResults + "results")));
				}
							

				if (isFAQ)
				{
					var row = _createEl("tr",{id:'faq_'+_ID});
					row.depth = curDepth+1;
					row.prevId = _lnk;
					row.style.display='none';
					if (lastEventSrc != null) 
					{ 
						_insertAfter(row,lastEventSrc); lastEventSrc = row; 
					}
					else
						tBody.appendChild(row);
					
					row.btree = bTree;
					appendNBS(row,isLastA);
					var tdx = _createEl("td",{className:cName,valign:top, colSpan:(MAXDEPTH-row.depth)},answer,true);
					tdx.style= 'border: 1px solid #CCC;background-color:#FFF; padding:2px';
					row.appendChild(tdx);
					cntLink ++;
				}

			} // end for all items in map
			
			var cName = "gray";
			
			// display add new item dialogue
			if (canEdit)
			{
				isLastA = true;
				isLastQ = true;
				if (prevID != 666)
				{
					var row = _createEl("tr",{});
					row.depth = curDepth+1;
					row.prevId = _lnk;
					if (lastEventSrc != null) 
					{ 
						_insertAfter(row,lastEventSrc); lastEventSrc = row; 
					}
					else
						tBody.appendChild(row);
					
					row.btree = bTree;
					appendNBS(row,isLastA);
					row.appendChild(_createEl("td",{className:cName,valign:top,colSpan:(MAXDEPTH-row.depth)},
						"<img src='img/bullet.png' style='margin-bottom: -2px'>"
						+			"<textarea class='add_a' type='text' id='edit_0' rows='"+edRows+"' onFocus='doFocus(this,true)' onBlur='doFocus(this,false)'>"+_ADD_DEFV+"</textarea>"
						+			"<input type='hidden' id='link_0' value='"+prevID+"'>"
						+			"<a class='btn1' href='#' onClick='_sub(0,\""+lnk+"\",1)'>+</a>"
						,true));
				}	
				if (lnk != "0")
				{
					var row = _createEl("tr",{});
					row.depth = curDepth;
					if (lastEventSrc != null) 
					{ 
						_insertAfter(row,lastEventSrc); lastEventSrc = row; 
					}
					else
						tBody.appendChild(row);
					
					row.btree = lastQuestionBit + (isLastA ? 0 : 1)*Math.pow(2,row.depth);
					appendNBS(row,isLastA);
					row.appendChild(_createEl("td",{className:cName,width:'20px', valign:top},
						"<img style='margin-bottom: -3px;' src='img/help.png'>",true));
					row.appendChild(_createEl("td",{className:cName,valign:top,colSpan:(MAXDEPTH-row.depth)},
						 "<input type='text' class='add_q' id='edit_1000' value='"+_ADD_DEFV+"' onFocus='doFocus(this,true)' onBlur='doFocus(this,false)'/>"
						 +			"<input type='hidden' id='link_1000' value='"+lnk+"'>"
						 +			"<a class='btn1' href='#' onClick='_sub(1000,\""+lnk+"\",1)'>+</a>"
						 ,true));
				}
			}
			
			if (cntLink == 0)
			{
				if ((cntResults == -1) && (product != 'CHK')) // no search
				{
					var row = _createEl("tr",{});
					row.depth = curDepth;
					if (lastEventSrc != null) 
					{ 
						_insertAfter(row,lastEventSrc); lastEventSrc = row; 
					}
					else
						tBody.appendChild(row);
					
					row.btree = lastQuestionBit;
					appendNBS(row,true);
					row.appendChild(_createEl("td",{className:cName,width:'20px', valign:top},
							"<img style='margin-bottom: -3px;' src='img/help.png'>",true));
					row.appendChild(_createEl("td",{className:cName,valign:top,colSpan:(MAXDEPTH-row.depth)},
						"<b>Troubleshooting</b>" ,true));
						
					row = _createEl("tr",{});
					row.depth = curDepth +1;
					if (lastEventSrc != null) 
					{ 
						_insertAfter(row,lastEventSrc); lastEventSrc = row; 
					}
					else
						tBody.appendChild(row);
					
					row.btree = lastQuestionBit;
					appendNBS(row,true);
					var tdx = _createEl("td",{className:cName,valign:top,colSpan:(MAXDEPTH-row.depth)},
						"<div style='background-color:#CCC;font-size:24px'><a class='tsm' href='#' onClick='reportTheProblem()'><div>"+texts["troub_rtp"]+"</div></a></div>" 
						,true);
					row.appendChild(tdx);
				}
				else if (product != 'CHK')
				{
					var row = _createEl("tr",{});
					row.depth = curDepth;
					if (lastEventSrc != null) 
					{ 
						_insertAfter(row,lastEventSrc); lastEventSrc = row; 
					}
					else
						tBody.appendChild(row);
					
					row.btree = lastQuestionBit;
					appendNBS(row,true);
					row.appendChild(_createEl("td",{className:cName,width:'20px', valign:top},
							"<img style='margin-bottom: -3px;' src='img/help.png'>",true));
					row.appendChild(_createEl("td",{className:cName,valign:top,colSpan:(MAXDEPTH-row.depth)},
						texts["qa_none"]));					
				}
			}
					
			var fullPath = "";

			if (canEdit && (lastEventSrc == null))
			{
				var divx = _createEl("div",{});
				divx.innerHTML = "<a href='#' onClick='showWiki(\"Troubleshooting\")'>rules for editation</a>";
				resp.appendChild(divx);
			}
			
			if (lastEventSrc != null)
			{
				lastEventSrc = null;
			}
			else
			{
				tbl.appendChild(tBody);
				
				_clearEl(resp);
				resp.appendChild(tbl);
			}
			
			_getEl("_ts_load").style.display = 'none';

			resizeHeight();
		}
		//catch (ex)
		//{
			//alert('BT#:' + ex + "/" + ex.message);
		//}
	}
	
	// ****************************************************************************************************

	// updates checklist - if all items are checked and verified, system allows problem reporting
	function updateChkList()
	{
		var notChecked = 0;
		var elements = _getByTag(_getById('tshoot'),'input') ;
		for(var i=0; i < elements.length; i++)
		{
			if (elements[i].type != 'checkbox') continue;
			if(!elements[i].checked)
				notChecked ++;
		}
		
		if (notChecked == 0)
			return true;
		else
		{
			alert(texts["checksteps"].replace("#1",""+notChecked));
			return false;
		}
	}
	
	// ****************************************************************************************************

	
	// opens WIKI window
	function showWiki(kb)
	{
		loadingShow();
		
		try 
		{	
			var vp = _getById('wikiPage');
			if (vp != null) vp.style.display='block'; 
			
			_getById("idWiki").src = wikiURL + trimAll(kb.replace("\[ ]\gi","%20")) + ""; 
			_getById("idWikiName").value = kb.replace("\[ ]\gi","_");	;
			
			setWikiRate();

			_getById("dYSF").style.display='none';
			_getById("dWiki").style.display='none';
		}
		catch (E) { alert("SW#" + E + "/" + E.message); }
	}

	// hides WIKI window
	function hideWiki()
	{
		_getById("dWiki").style.display='none'; 
		_getById("dYSF").style.display=''; 
		
		var vp = _getById('wikiPage');
		if (vp != null) vp.style.display='none'; 
		infoLock = false;
	}
	
	// rates WIKI
	function setWikiRate()
	{
		if (!_getEl("idWikiName")) return; 
		
		var cook = _getById("idWikiName").value;
		var number = getCookie("feedback_" + cook);
		
		if ((number != null) && (number > 0) && (number < 6))
		{
			var rate = "?";
			switch ( parseInt(number) )
			{
				case 1: rate = "Not working"; break; 
				case 2: rate = "Not helpful"; break;
				case 3: rate = "Helpful"; break;
				case 4: rate = "Very Helpful"; break;
				case 5: rate = "Solved my problem"; break;
			}
			_getById('rateArticle').style.display = 'none';
			_getById('rateArticleDone').style.display = 'inline';
			_getById('rateArticleDone').innerHTML = 'already rated: (' + number + ") " + rate + ".";
		}
		else
		{
			if (_getById('rateArticle') == null) return;
			_getById('rateArticle').style.display = 'inline';
			_getById('rateArticleDone').style.display = 'none';
		}
	}
		
	// gets number of ITEMS in troubleshooting maps
	function writeLinkCnt(xml)
	{
			try
			{
				
				var request = XHRFactory.getInstance();
				request.open('POST', tsUrl, true);
				request.onreadystatechange = function()
				{
					if (request.readyState == 4)
					{
	           			if (/^(200|304)$/.test(request.status.toString())) 
						{
								var list = request.responseXML.getElementsByTagName('message');
								var resp = document.getElementById('i_diag');
								if(resp != null){
									for (var i =0; i<list.length; i++)
									{
										var link = list[i].firstChild.nodeValue; 
										resp.innerHTML = "" + link + ";";
									}
								}
							XHRFactory.release(request);
						}					
					}
				};
				request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset:UTF-8");
				request.send('act=CNT&lang='+currentLang);
			
			}
			catch (ex)
			{
				alert('WLC#:' + ex + "/" + ex.message);
			}
				
	}
	
	/* ******************************************************************** */
	// FUNCTIONS FOR TROUBLESHOOTING MAP EDITATION 
	
	var _ADD_DEFV = "Click to add new item";
	function doFocus(obj, foc)
	{
		if (foc)
		{
			if(obj.value == _ADD_DEFV)
			{
				obj.value = "";
				obj.style.color = "#000000";
			}
		}
		else
		{
			if(obj.value == "")
			{
				obj.value = _ADD_DEFV;
				obj.style.color = "#B7B7B7";
			}
		}
	}
	
	function _edit(id)
	{
		var obj1 = _getById("_ed"+id);
		var obj2 = _getById("_bl"+id);
		if ((obj1 == null) || (obj2 == null)) return;

		obj1.style.display = 'block';
		obj2.style.display = 'none';
	}
	
	function _delete(id,link)
	{
		var obj = _getById("edit_"+id);
		if (confirm("Are you absolutely sure you want to delete this record?\n"+obj.value))
		{
			var lnk = _getById("link_"+id);
			var obj2 = _getById('i_product');
			var product = (obj2 != null) ? _getOpt(obj2).value : null;
			if (product == null) product = "SQ";

			_getById("_ts_load").style.display = 'block';
			var href =  "link="+link+"&act=DEL&product="+product+"&id="+lnk.value;
			//alert(href);
			_JSON2(tsPath + '.TShotServlet',href, buildTree, link);	
		}
	}
	
	// submit change or editation
	function _sub(id, par, addAsNew)
	{
		try
		{
			var obj = _getById("edit_"+id);
			var obj_loc = _getById("edit_"+id+"_loc");
			var lnk = _getById("link_"+id);
			if ((obj == null) || (lnk == null))
			{
				alert("Invalid reference!");
				return;
			}
			

			var obj2 = _getById('i_product');
			var product = (obj2 != null) ? _getOpt(obj2).value : null;
			if (product == null) product = "SQ";

			var action = "EDT";
			if (addAsNew == 1) action = "ADD";
			if (addAsNew == 2) action = "APP";

			var valu = encodeURIComponent(obj.value);

			_getById("_ts_load").style.display = 'block';
			var href =  "link="+par	+"&act="+action+"&product="+product+"&id="+lnk.value+"&text="+valu;
			if ((currentLang != "en") && (obj_loc != null))
			{
				var valu_loc = encodeURIComponent(obj_loc.value);
				href += "&text_loc="+valu_loc+"&lang="+currentLang;
			}

			var imgx = _getEl("img"+par);
			if (imgx)
			{
				curDepth = getFromTree(par);
				if (curDepth == -1) curDepth = 1;
				deleteOldRows();			
				lastEventSrc =  _getParent(imgx,'TR');
			}
	
		

			//alert ('Rebuilding: ' + lnk.value + " to: " + valu + " for " + parent + " action=" + action);
			_JSON2(tsPath + '.TShotServlet',href, buildTree, par);	
			getAuthors();
		}
		catch (e)
		{
			alert("SUB#" + e);
		}
	}
	
	// EOB: EDITATION FUNCTIONS
	/* ******************************************************************* */
	
	// goes back one step in the troubleshoot map
	function goBack()
	{
	
		var obj2 = _getById('i_product');
		var product = (obj2 != null) ? _getOpt(obj2).value : null;
		if (product == null) product = "SQ";

		var rep = _getById('selReport');
		if (rep == null) rep = _getById('report');
		
		if (rep.style.display != 'none')
		{
			cancelTicket();
		}
		else
		{
			setStep(0);
		}
	}

	// CHECK IF THE FORM IS SUBMITABLE - eg. was open in expected way
	var submittable = false;
	function _checkSubmit(sub)
	{
		_getEl("checks").value = "";
		var frm = _getEl("frmReport");
		if (!submittable) return false;
		submittable = false;
		if (sub != null)
		{
		
			var checks = "";
			// gather all checklist
			var elements = _getByTag(_getById('tshoot'),'input') ;
			for(var i=0; i < elements.length; i++)
			{
				if (elements[i].type != 'checkbox') continue;
				if(elements[i].checked)
					checks += "* " + elements[i].value + "\n";
			}
			
			_getEl("checks").value = checks; 
		
			applyRules();
			AIM.submit(frm, {'onStart' : troub_startCallback, 'onComplete' : troub_completeCallback});			
			frm.submit();
		}
		return true;
	}
	
	function troub_startCallback()
	{
		_getEl("selReport").style.display = "none";
		var rep = _getEl("selReportSubmit");
		rep.innerHTML = "<p style='padding:20px 0'><img src='img/load_icon.gif'>" + texts["submitting"] + "</span></p>";
		rep.style.display = "block";
		resizeHeight();
	}
	
	function troub_completeCallback()
	{
	}
	
	function setSubmitStatus(status,err)
	{
		if ('1' == status)
		{
			var rep = _getEl("selReportSubmit");
			rep.innerHTML = 
				"<p style='padding:20px 0'>" + texts["ticket_ok"] + "</span></p>"
				+"<p style='padding:20px 0'>" + texts["ticket_ok1"] + "</span></p>";
		}
		else
		{
			var rep = _getEl("selReportSubmit");
			rep.innerHTML = 
				"<p style='padding:20px 0;cursor:pointer'>" + texts["ticket_fail"] + "</span></p>"
				+"<p style='padding:20px 0;cursor:pointer'>" + texts["ticket_fail1"] + err + "</span></p>";
			rep.onclick = function() {
				_getEl("selReport").style.display = "block";
				_getEl("selReportSubmit").style.display = "none";
			};
			//XXX onclickfn
		}
		resizeHeight();
	}

	
	// opens the REPORTING FORM
	function reportTheProblem(quest)
	{
		var sev = _getById("severity");
		var val = 'X';

		if (_getById("rowRemAs") != null)
			_getById("rowRemAs").style.display = (quest == 10) ? "block" : "none";
		
		if (setStep == null)
			val = sev.value;
		else
			val = (sev != null) ? sev.options[sev.selectedIndex].value : 'X';
		
		if ((val == 'X') || (quest != null))
		{
			if (sev != null)
				sev.selectedIndex = 3;
			//_status("disable all:" + quest);
			_getById('row1').style.display = 'none';
			_getById('row2a').style.display = 'none';
			_getById('row2b').style.display = 'none';
			_getById('row2c').style.display = 'none';
			_getById('row2d').style.display = 'none';
			_getById('row3').style.display = 'none';
		}
		else
		{
			//_status("enable all" + quest);
			_getById('row1').style.display = 'table-row';
			_getById('row2a').style.display = 'table-row';
			_getById('row2b').style.display = 'table-row';
			_getById('row2c').style.display = 'table-row';
			_getById('row2d').style.display = 'table-row';
			_getById('row3').style.display = 'table-row';
		}
		
		var obj2 = _getById('i_product');
		var product = (obj2 != null) ? _getOpt(obj2).value : null;
		if (_getEl('row2sqv'))
		{
			if	((product == 'SQ') || (product == 'SQ2') || (product == 'CHK'))
			{
				_getById('row2sqv').style.display = 'table-row';
				_getById('row2sqp').style.display = 'table-row';
				var opt3 = _getEl("sqversion");
				_clearEl(opt3);
				for (var i=0; i<sqVersions.length; i++)
					opt3.options[i] = new Option(sqVersions[i],sqVersions[i]);
			}
			else
			{
				_getById('row2sqv').style.display = 'none';
				_getById('row2sqp').style.display = 'none';
				_getEl("sqpatch").value = "";
				_setOpt("sqversion","-");
			}
		}

		if (setStep != null)
		{
			setStep(4);
		}
		else
		{
			document.getElementById("noProb").style.display="none";
			document.getElementById("report").style.display="block";
		}
		
		resizeHeight();
	}
	
	function setProduct(obj)
	{
		_setOpt('i_product',_getOpt(obj).value);
	}

	// displays RMA page
	function showRMA()
	{
		loadingShow();
		
		try 
		{	
			document.getElementById("idWiki").src = "rma.jsp"; 
			document.getElementById("dWiki").style.display='';
			document.getElementById("dYSF").style.display='none';
		}
		catch (E) { alert("RMA#" + E + "/" + E.message); }
	}
	
	// displays Card Tester Page
	function showFindCard()
	{
		loadingShow();
		
		try 
		{	
			document.getElementById("idWiki").src = "ct.jsp"; 
			document.getElementById("dWiki").style.display='';
			document.getElementById("dYSF").style.display='none';
		}
		catch (E) { alert("FC#" + E + "/" + E.message); }
	}
	
	function unload()
	{
		//if (!confirm("Are you sure you want to quit the Troubleshooting?"))
			return 'Leaving this page will cause you to start again!';
	}

	// ********** DATA STORAGE FUNCTIONS - cookies ***********************
	var clearable = true;
	function doClear(obj)
	{
		if (!clearable) return;
		obj.value = '';
		obj.style.backgroundColor="#FFFFFF";
		clearable = false;
	}

	function setCookie(c_name,value,expiredays)
	{
		var exdate=new Date();
		exdate.setDate(exdate.getDate()+expiredays);
		document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
	} 
	
	function getCookie(c_name)
	{
		if (document.cookie.length>0)
	  {
	  	c_start=document.cookie.indexOf(c_name + "=");
	  	if (c_start!=-1)
	    { 
	    	c_start=c_start + c_name.length+1; 
	    	c_end=document.cookie.indexOf(";",c_start);
	    	if (c_end==-1) c_end=document.cookie.length;
	    	return unescape(document.cookie.substring(c_start,c_end));
	    } 
	  }
		return "";
	}


	function updateData() {}
	function saveData()	{}


	// ********** TICKET CREATION AND MANIPULATION FUNCTIONS ***********************

	function sendTicket(sub)
	{
		saveData();
		
		try
		{
			if (_getById('i_from').value == '') { alert(texts["frm_from"]); return; }
			if (_getById('i_contact_person').value == '') { alert(texts["frm_cp"]); return; }
			if (_getById('i_subject').value == '') { alert(texts["frm_subj"]); return; }
			if (_getOpt('sqversion').value == '?') { alert(texts["frm_sq"]); return; }

			if (_getById("rowRemAs").style.display == 'block')
				_getById('i_problem_info').value = '';
			if (_getById('i_problem_info').value == texts["r_sqinfo"]) 
				{ 
					if (!confirm(texts["frm_info"])) return; 
				}

			
			if (_getById('i_phone').value == '') 
				{ 
					if (!confirm(texts["frm_phone"])) return; 
				}
			else
				_getById('i_contact_person').value = _getById('i_contact_person').value + '(' + _getById('i_phone').value + ')';

			
		
			submittable = true;
			
			var frm = _getEl("frmReport");
			if (!frm) return;

			
			_getById("i_problem_description").text = ((_getById("i_reason") != null) ? _getById("i_reason").text + "\n" : "")
				 + _getById("i_problem_description").text;
				 
			if (sub == null)
				frm.submit();
			else
				_checkSubmit(1);
		}
		catch (ex)
		{
			alert(texts["frm_fail"] + ex);
		}
	}

	function cancelTicket()
	{
		if (curDepth > 1)
		{
			_getById("selTrouble").style.display = 'block';
			_getById("selReport").style.display = 'none';
			resizeHeight();
			return;
		}
		
		if (setStep != null)
		{
			setStep(0);
			return;
		}
		document.getElementById("noProb").style.display="";
		document.getElementById("report").style.display="none";
	}

		
	// ********* FEEDBACK && Wiki Rating Functions ****************
	
	function doFeedback(number)
	{
		var str = "NOT RATED";
		switch (number)
		{
			case 1: str = "Not working"; break;
			case 2: str = "Not helpful"; break;
			case 3: str = "Helpful"; break;
			case 4: str = "Very Helpful"; break;
			case 5: str = "Solved the problem"; break;
		}
		_getById('f3').value = "Feedback for the WIKI article ("+ _getById("idWikiName").value +") is: " + str;
		if (_getById('i_from') != null) _getById('f2').value = _getById('i_from').value;
		if (_getById('i_contact_person') != null) _getById('f1').value = _getById('i_contact_person').value;
		sendFeedback("tech",number);
	}
	
	
	function hlBtn(type, pos)
	{
		var obj = (pos != null) ? _getById('backBtn'+pos) : _getById('backBtn');
		if(type == 0)
		{
			obj.style.backgroundPosition = 'top';
		}
		else
		{
			obj.style.backgroundPosition = 'bottom';	
		}
	}
	
	//prida dalsi radek s prilohou
	function addFile(img)
	{
		//zmenit add btn na remove
		img.src = 'img/i_delete.gif';
		img.onclick = new Function('removeFile(this)');
				
		var row = img.parentNode.parentNode;
		var tbody = row.parentNode;

		//novy radek a bunky
		var newRow = document.createElement('TR');
		tbody.insertBefore(newRow, row.nextSibling);

		//label cell
		var cell = newRow.insertCell(-1);
		cell.className = 'lbl';
		
		//inputs cell
		cell = newRow.insertCell(-1);
		
		//file input
		var fileInp = document.createElement('INPUT');
		fileInp.type = 'file';
		fileInp.name = 'file_name';
		fileInp.size = 45;
		cell.appendChild(fileInp);
		cell.appendChild(document.createTextNode(' '));
	
		//add button
		var addImg = _create('IMG');
		addImg.src = 'img/i_plus.gif';
		addImg.className = 'imgBtn';
		addImg.onclick = new Function('addFile(this)');
		cell.appendChild(addImg);
	}
	
	
	//pridava dalsi soubor
	function removeFile(img)
	{
		var row = img.parentNode.parentNode;
		var table = row.parentNode.parentNode;

		if(row.id == 'add3')
		{
			var helpImg = row.cells[1].firstChild;

			nextRow = table.rows[row.rowIndex + 1];
			nextRow.cells[0].appendChild(row.cells[0].firstChild);
			nextRow.cells[1].appendChild(helpImg);
			nextRow.id = 'add3';
		}
		
		table.deleteRow(row.rowIndex);	
	}
	
	//zobrazuje/skryva pole pro vyplneni alternativni moznosti
	function handleOS(opt)
	{
		document.getElementById('os_other').style.display = (opt.selectedIndex == opt.options.length - 1 ? '' : 'none');
	}

	
	//zmeni velikost panelu
	function resizeHeight()
	{
		var an2 = _getById('anchor2');
		if (an2 == null) 
		{
			for (var i =1; i<20; i++)
			{
				an2 = _getById('anchor2-'+i);
				if (an2 == null) continue;
				if (an2.style.display == "none") continue; 
				else if (parseInt(_getTop(an2)) > 0) break;
			}
			if (an2 == null) return;
		}
		
		if (_getById('anchor1') == null) return;
		var a1 = parseInt(_getTop(_getById('anchor1')));
		var a2 = parseInt(_getTop(an2));
		var a2a=  0;//(_getById('anchor2a') == null) ? 0 : parseInt(_getTop(_getById('anchor2a')));


		var height = ((a2 > a2a)  ? a2 : a2a) - a1 + 50; 


		if(height < 500)
		{
			height = 500;
		}


		try {
			_getById('question').style.height = height + 'px';
			_getById('smallquestion').style.height = height + 'px';
			_getById('disclaimer').style.top = height + 'px';
		} 	catch (ex) { }

		try {
			_status('height=' + height + '/sph=' + _getById('smallpadder').style.height +  '/a2=' + a2 +  "a1=" + a1);

			if (_getById('smallpadder').style.height > (height+175))
				height = _getById('smallpadder').style.height;
			_getById('smallpadder').style.height = (height-175) + 'px';
			_getById('padder').style.height = (height) + 'px';
		} 	catch (ex) { }

	}

	function loadingShow()
	{
		if (!_getEl('loading'))
			_getById('loading').style.display = '';
	}
	
	function loadingHide()
	{
		_getById('loading').style.display = 'none';
		_getById('dWiki').style.display = 'block';
	}
	
	function _status(text)
	{
		try
		{
			_getById('status').innerHTML =  text;
		}
		catch (x) {}
	}

	var prevFAQ = 0;
	function showFAQ(pos)
	{
		var obj = _getEl("faq_"+prevFAQ);
		if (obj)
			obj.style.display = "none";

		prevFAQ = pos;
		var obj = _getEl("faq_"+prevFAQ);
		if (obj)
			obj.style.display = "";
			
		resizeHeight();
	}
	
	// big troubleshooting map search function
	var tsSearchResult = null;
	function initTSSearch()
	{
		_getEl("ts_search").onkeyup = function ()
		{
			if (this.value == "")
			{
				tsSearchResult = null;
				var obj2 = _getById('i_product');
				var product = (obj2 != null) ? _getOpt(obj2).value : null;
				if (this.oldValue != '') getInfo(product,null,"0");
				this.oldValue = this.value;
			}
			else
			if (this.value != this.oldValue)
			{
				tsSearchResult = new Array();
				var val = this.value;
				if (this.timer != null)
					clearTimeout(this.timer);
				this.timer = setTimeout(performSearch,1000); 
				this.oldValue = this.value;
			}
		}
	}
	
	function performSearch()
	{
		_getById("_ts_load").style.display = 'block';
		var srch = _getEl("ts_search").value;
		if (srch != null)
			_XHR(tsPath + '.TShotServlet',"act=SRCH&text="+srch, getSearchResp);	
	}
	
	function getSearchResp(xml)
	{
		var list = xml.getElementsByTagName('res');
		if (list.length == 0) 
		{
			return;
		}		
		
		for (var i=0; i<list.length;i++)
		{
			var key = list[i].getAttribute('id');
			var cnt = list[i].getAttribute('cnt');
			tsSearchResult[key] = cnt;
		}

		var obj2 = _getById('i_product');
		var product = (obj2 != null) ? _getOpt(obj2).value : null;
		getInfo(product,null,"0");
	}

