	var listSLAs = null; /// global XML list of SLAs
	var ticketList = null;		// XML list of the ticekts
	var qaaTimer = null;		// search timer for FAQ
	var afterOnlLoad = null;
	var qaaLastText = null;		// last search text for FAX
	var listOfElements = new Array("selType", "selSeverity", "selPasswd", "selTrouble", "selRMA", "selCMGR", "selReport", "selQuestion", "selTickets", "selSlas", "selCapr");
	
	// this function takes care of all required steps in wizard untill real troubleshooting
	function setStep(step)
	{	
		try
		{
			var pt = (typeof(pageTracker) != 'undefined') ? pageTracker : null;
			hideElements();

			if ((step == 1) || (step == 12) || (step == 2) || (step == 7))
			{
				document.getElementById('tshoot').innerHTML = "<img class='load' src='img/loading.gif' /><h3 id='RES_load'></h3><span id='RES_wait'></span>";
			}
			
			var obj  = _getById('severity');	
			var obj2 = _getById('i_product');
			var product = (obj2 != null) ? _getOpt(obj2).value : null;
			if (product == null) product = "SQ";
			switch (step)
			{
				case 98:
						if (listSLAs == null)
						{
							var tb = _getEl("tbSlas");
							_clearEl(tb);
							var tbo = _createEl("tbody",{});
							var row = _createEl("tr",{});
							var td1 = _createEl("td",{});		
								td1.innerHTML = "<img class='load' src='img/loading.gif' /><h3>"+texts['load']+"</h3>";
							
							tb.appendChild(tbo);
							tbo.appendChild(row);
							row.appendChild(td1);
							
							_XHR(contextPath+"/servlet/eu.ysoft.portal.SLAServlet","",buildSLAFn);
						}
						else
							buildSLAOverviewList();
						_getById("selSlas").style.display = 'block';
						if(pt != null)	pageTracker._trackPageview("/tech/sla/list");
						break;
				case 99:_getById("selTickets").style.display = 'block';
						if(pt != null)	pageTracker._trackPageview("/tech/tickets/list");
						break;
				case 0:_getById("selType").style.display = 'block';
						break;
				case 12: // question list
//						_getById("selQuestion").style.display = 'block';
// pageTracker._trackPageview("/techsupport/instconf");
//						break;
				case 1: // question
						_setOpt('severity','X');
						_setOpt('i_product','SQ2');
						_getById('i_subject').value = 'I have a question';
						_getById("i_problem_description").value = '';
						getInfo("SQ2",null,"0");
						_getById("selTrouble").style.display = 'block';
						//reportTheProblem(1);
						if(pt != null)	pageTracker._trackPageview("/techsupport/question");
						break;
				case 11:  // card manager
						_getById("selCMGR").style.display = 'block';
						if(pt != null)	pageTracker._trackPageview("/techsupport/card_manager");
						break;
				case 2: // problem or failure  select severity
						_setOpt('i_product','SQ');
						_setOpt('severity','C');
						_getById("selSeverity").style.display = 'block';
						if(pt != null)	pageTracker._trackPageview("/techsupport/selSeverity");
						break;
				case 21:  // troubleshooting
						if ((obj != null) && (obj.options[obj.selectedIndex].value == 'A') && (_getById('i_reason').value == ''))
						{
							_getById("selSeverity").style.display = 'block';
							alert (texts["setsev"]);
						}
						else
						{
							_getById('i_subject').value = '';
							_getById("i_problem_description").value = '';
							getInfo(product,null,"0");
							_getById("selTrouble").style.display = 'block';
							if (listSLAs == null)
								_XHR(contextPath+"/servlet/eu.ysoft.portal.SLAServlet","",buildSLAList);
							else
								buildSLAList(listSLAs);
						}
						if(pt != null)	pageTracker._trackPageview("/techsupport/chSW");
						break;
				case 3: _getById("selRMA").style.display = 'block';
						if(pt != null)	pageTracker._trackPageview("/techsupport/chHW");
						break;
				case 4: _getById("selReport").style.display = 'block';
						if (listSLAs == null)
							_XHR(contextPath+"/servlet/eu.ysoft.portal.SLAServlet","",buildSLAList);
						else
							buildSLAList(listSLAs);
						if(pt != null)	pageTracker._trackPageview("/techsupport/report");
						break;
				case 5: _getById("selPasswd").style.display = 'block';
						if(pt != null)	pageTracker._trackPageview("/techsupport/passwd");
						break;
				case 7: 
					if (usrNotLogged) 
						_getById("selSeverity").style.display = 'block';
					else
					{
						_setOpt('severity','X');
						_setOpt('i_product','CHK');
						_getById('i_subject').value = 'I`m unable to complete installation';
						_getById("i_problem_description").value = '';
						getInfo("CHK",null,"0");
						_getById("selTrouble").style.display = 'block';
						break;
					}
					if(pt != null)	pageTracker._trackPageview("/techsupport/instconf");
			}
			resizeHeight();
		}
		catch (ex)
		{
			alert("SETSTEP: " + ex + "/" + ex.message + "/" + ex.source);
		}
	}
	
	function init2()
	{
		try
		{		
			// call tree generation
			if (_getById('frmReport') != null)
				getInfo("SQ",null,"0");
						
			// calculate nr of items
			if (_getById('selTrouble') != null)
				writeLinkCnt();		
									
			if (_getById('i_problem_info') != null)
			{
				_getById('i_problem_info').value = texts["r_sqinfo"];
				_getById('i_problem_info').style.backgroundColor = '#EFEFEF';
			}
			
			if (_getById('cHCL') != null)
				initHCL();
			
			if (getBrowserName() == 'msie')
			{
				try
				{
					var mysheet=document.styleSheets[0];
					if (mysheet != null)
						mysheet.addRule("#articleList a", "height: 48px; ");
				}
				catch(e) {}
			}
			
			if (_getById('selTrouble') != null)
			{
				getAuthors();
				getHclSum();
			}

			if (_getById('loginid') != null)
				setLoginBehaviour();

			initSrch();
				
			if (typeof(afterOnlLoad) == 'function')
				afterOnlLoad();
				
			if (typeof(initTSSearch) == 'function')
				initTSSearch();
				
			resizeHeight();
		}
		catch (ex)
		{
			alert("INIT2 Error " + ex + "/" + ex.message + " @ " + ex.lineNumber);
		}

	}

	function getAuthors()
	{
		if (_getById('authList') == null) return;
		_XHR(tsPath + '.TShotServlet',"act=AUT", getAuthorsResp);	
	}

	function getAuthorsResp(xml)
	{
		var obj = _getById('authList');
		var list = xml.getElementsByTagName('author');
		var str = "";
		
		for (i =0; i<list.length; i++)
		{
			var name = list[i].getAttribute("name"); 
			var cnt = list[i].getAttribute("count"); 
			str += "<li><b>"+name+"</b>: " + cnt + "</li>";
		}
		
		obj.innerHTML = "<ul>"+str+"</ul>";
	}
	
	function handlePriority(obj)
	{
		var pos = obj.selectedIndex;
		if (obj.options[pos].value == 'A')
			_getById("reason").style.display = "block";
		else
			_getById("reason").style.display = "none";
		resizeHeight();
	}
	
	function doReg(opt)
	{
		_getById("uSLA").disabled = (opt.value == 'PAR');
		_getById("uSLA").style.backgroundColor = (opt.value == 'PAR') ? '#CCC' : '#FFF';
		_getById("uSLA").style.bgColor = (opt.value == 'PAR') ? '#CCC' : '#FFF';
	}
	
	function doRegistration()
	{
		var frm = _getById('frmRegister');
		
		if (_getById('uEmail').value == '') { alert('Please enter your email address first!'); return; }
		
		if (_getById('uPassword1') != null)
		{
			if (_getById('uPassword1').value == '') { alert('Please enter your password first!'); return; }
			if (_getById('uPassword2').value == '') { alert('Please confirm your password!'); return; }
			if (_getById('uPassword1').value != _getById('uPassword2').value) { alert('Passwords don`t match!'); return; }
		}
		
		if (_getById('uName').value == '') { alert('Please enter your name address first!'); return; }
		if (_getById('uSurname').value == '') { alert('Please enter your surname address first!'); return; }
		
		if (_getById('uCompany').value == '') { alert('Please enter your company name first!'); return; }

		frm.submit();		
	}
	
	// ask for remote assistance
	function askRA()
	{
		if (usrNotLogged) 
		{
			alert (texts["regonly"]);
			return;
		}
		else
		{
			alert(_getById('RES_r_charg').innerHTML);
		}
		_getById('i_subject').value = 'REQUEST FOR REMOTE ASSISTANCE';
		_getById("i_problem_description").value = 'I would like to ask for the remote assistance for [reason]\nThe best time for the assistance would be [when]\nMy contact phone number is [number]';
		reportTheProblem(10);
	}

	// ask for documentation
	function askDOC()
	{
		if (usrNotLogged) 
		{
			alert (texts["regonly"]);
			return false;
		}
		return true;
	}
	
	function askDOC2()
	{
		if (usrNotLogged) 
		{
			alert (texts["regonly"]);
			return false;
		}
		_getById('i_subject').value = 'REQUEST FOR DOCUMENTATION';
		_getById("i_problem_description").value = 'I need documentation for ... ';
		reportTheProblem(1);
	}

	// ask for training
	function askTR()
	{
		if (usrNotLogged) 
		{
			alert (texts["regonly"]);
			return;
		}
		_getById('i_subject').value = 'REQUEST FOR TRAINING';
		_getById("i_problem_description").value = 'I need training for ... ';
		reportTheProblem(1);
	}
	
	// ask for card manager
	function askCM()
	{
		if (usrNotLogged) 
		{
			alert (texts["regonly"]);
			return;
		}
		setStep(11);
	}
	
	// defines type of the problem
	function checkIType()
	{
		if (!_getEl("chSW")) return;
		if (_getById("chSW").checked)
		{
			_getById("swType").style.display='block';
		}
		
		if (_getById("chHW").checked)
		{
			_getById("swType").style.display='none';
		}
	}
	
	//sets next step based on the iType
	function setStepIType()
	{
		_setOpt('i_product',_getOpt('i_productsel').value);


		if (!_getEl("chSW")) setStep(21);
		else
		if (_getById("chSW").checked)
			setStep(21);
		else
		if (_getById("chHW").checked)
			setStep(3);
		else
			alert("Please select type of the reported incident.");
	}
	
	function getCapr()
	{
		var months = ["Jan", "Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
		var today = new Date();
		var dt = new Date (today);
		dt.setDate(i);
		var fy = ""+ dt.getFullYear();
		var fm = dt.getDate() + "-" + months[dt.getMonth()] + "-"+ fy.substring(2);
		
		new_window(contextPath+"/servlet/eu.ysoft.capr.CaprServlet?task=REP&date="+fm,"capr",10,10);
	}

	function URLDecode (encodedString) {
  var output = encodedString;
  var binVal, thisString;
  var myregexp = /(%[^%]{2})/;
  while ((match = myregexp.exec(output)) != null
             && match.length > 1
             && match[1] != '') {
    binVal = parseInt(match[1].substr(1),16);
    thisString = String.fromCharCode(binVal);
    output = output.replace(match[1], thisString);
  }
  return output;
}
	function buildSLAList(xml)
	{
		var obj = _getById('authList');
		var list = xml.getElementsByTagName('sla');
		if ((list == null) || (list.length == 0)) return;
		var str = "";

		var selObj = _createEl("select", { name:"customer_info", id:"i_customer_info", className:"fVal2"});
		var pos = 0;
		if (list.length > 1) selObj.options[pos++] = new Option( texts["r_nosla"] ,'no-sla');
		for (i =0; i<list.length; i++)
		{
			var text = ((list[i] == null)) ? "?" : list[i].childNodes[(list[i].childNodes.length == 3) ? 1 : 0].nodeValue;
			text = URLDecode(text);
			var sla_end = list[i].getAttribute("sla_end");
			var sla_end_js = list[i].getAttribute("sla_end_js");
			var ph_end = list[i].getAttribute("prio_end");
			var ph_end_js = list[i].getAttribute("prio_end_js");
			// var type = ((!sla_end && ph_end) || ( new Date(ph_end) > new
			// Date(sla_end))) ? "PRIO" : ((sla_end) ?
			// list[i].getAttribute("sla_type") : "");
			// var type = ((!sla_end && ph_end) || ( new Date(str2date(ph_end))
			// > new Date(str2date(sla_end)))) ? "PRIO" : ((sla_end) ?
			// list[i].getAttribute("sla_type") : "");
			var prio_type = list[i].getAttribute("prio_type");
			var type = (sla_end) ? list[i].getAttribute("sla_type") : "";
			if(prio_type == "ANO"){
				type = "PRIO";
			}
			var date = (type != "PRIO") ? sla_end : ph_end;
			var date_js = (type != "PRIO") ? sla_end_js : ph_end_js;

			var end = new Date ();
			var dt = str2date_js(date_js);
			if ((dt < end) || (type == "NE")) continue;
			
			var code = text + "(" + list[i].getAttribute("id") + ",SLA=" + type + ":" + date + ")";
			selObj.options[pos++] = new Option( code , code);
		}
		if (list.length <= 1) selObj.options[pos++] = new Option( texts["r_nosla"] ,'no-sla');
				
		_replaceContent("slaInfo",selObj);
	}

	
	var slaTimer = null;
	var slaFilter = null;

	// create list overview of all active and inactive SALs
	function buildSLAFn(xml)
	{
		listSLAs = xml;
		var srch = _getById("slaSearch");
		srch.onkeydown = function()
		{
			hclOffset = 0;
			if (hclTimer != null)
				clearTimeout(slaTimer);
			hclTimer = setTimeout(buildSLAOverviewList,1000);
		};
		buildSLAOverviewList();
		slaFilter = null;;
	}
	
	function str2date(date)
	{
		if (date == null) return "n/a";
		var dt = date.split("-");
		return new Date(dt[1] + " " + dt[0] + "," + dt[2]);
	}
	
	function str2date_js(date)
	{
		if (date == null) return "n/a";
		var dt = date.split("-");
		return new Date(dt[0], dt[1] , dt[2],23,59,59);
	}
	
	function sla_provideSupport()
	{
		var tb = _getEl("tbSlas");
		_clearEl(tb);
		var tbo = _createEl("tbody",{});
		var row = _createEl("tr",{});
		var td1 = _createEl("td",{});		
			td1.innerHTML = "<img class='load' src='img/loading.gif' /><h3>"+texts['load']+"</h3>";
		
		tb.appendChild(tbo);
		tbo.appendChild(row);
		row.appendChild(td1);

		var str = _getEl("slaSearch").value;
		_XHR(contextPath+"/servlet/eu.ysoft.portal.SLAServlet","action="+str,buildSLAFn);
	}
	
	function buildSLAOverviewList(filter)
	{	
		var supportValidation = _getEl("supportValidation");
	
		if (filter == null) filter = slaFilter;
		slaFilter = filter;
		
		var str = _getEl("slaSearch").value;
		var tableSLAClass= "tbSlas";
		var tableSLARowClass = "";
		
		if (listSLAs == null) return null;
	
		var list = listSLAs.getElementsByTagName('sla');
		if (list.length == 0) return;
	
		var tBody = _createEl("tbody",{});
		var tHead = _createEl("thead",{});

		var row = _createEl("tr",{});
		if (!supportValidation)
		{
			// this is standard SLA list
			row.appendChild(_createEl("th",{className:"gray"},"type"));
			row.appendChild(_createEl("th",{className:"gray",  width:"50px"},"#"));
			row.appendChild(_createEl("th",{className:"gray"},texts["sla_cust"]));
			row.appendChild(_createEl("th",{className:"gray", width:"80px"},"age"));
			row.appendChild(_createEl("th",{className:"gray", width:"80px"},"account manager"));
		}
		else
		{
			// this list is to validate support eligibility
			row.appendChild(_createEl("th",{className:"gray"},"type"));
			row.appendChild(_createEl("th",{className:"gray",  width:"50px"},"supportID"));
			row.appendChild(_createEl("th",{className:"gray"},texts["sla_cust"]));
			row.appendChild(_createEl("th",{className:"gray", width:"200px"},"Support Eligibility"));
			row.appendChild(_createEl("th",{className:"gray", width:"200px"},"Non-eligible support provided?"));
		}
		tHead.appendChild(row);
		
		var isExpired = false;
		var cntRecord = 0;	
		for (i =0; i<list.length; i++)
		{
			var evenRow = cntRecord % 2;
			tableSLARowClass = evenRow == 0 ? tableSLAClass+"Odd" : tableSLAClass+"Even";
			var subj = ((list[i] == null)) ? "?" : list[i].childNodes[(list[i].childNodes.length == 3) ? 1 : 0].nodeValue;
			subj = URLDecode(subj);
			var sla_end = list[i].getAttribute("sla_end");
			var sla_end_js = list[i].getAttribute("sla_end_js");
			var ph_end = list[i].getAttribute("prio_end");
			var ph_end_js = list[i].getAttribute("prio_end_js");
			var id = list[i].getAttribute("id");
			var prio_type = list[i].getAttribute("prio_type");
			var type = (sla_end) ? list[i].getAttribute("sla_type") : "";
			if(prio_type == "ANO"){
				type = "PRIO";
			} 
			var classN = "ok";

			if (!supportValidation)
			{
				var accountManagerElement = list[i].getElementsByTagName("accountManager")[0];
				
				var amId = "";
				if(accountManagerElement && accountManagerElement.getElementsByTagName("strId")[0] != null){
					amId = accountManagerElement.getElementsByTagName("strId")[0].childNodes[0].nodeValue;
				}
				
				var amName = "";
				var amFirstName = "";
				if(accountManagerElement && accountManagerElement.getElementsByTagName("firstName")[0] != null){
					amFirstName = accountManagerElement.getElementsByTagName("firstName")[0].childNodes[0].nodeValue;
					amName += amFirstName;
				}
				
				var amSureName = "";
				if(accountManagerElement && accountManagerElement.getElementsByTagName("sureName")[0] != null){
					amSureName = accountManagerElement.getElementsByTagName("sureName")[0].childNodes[0].nodeValue;
					if(amName.length > 0){
						amName += " ";
					}
					amName += amSureName;
				}
				
				if(amName.length <= 0 && amId.length > 0){
					amName = amId;
				}
				
				var amPhone = "";
				if(accountManagerElement && accountManagerElement.getElementsByTagName("phone")[0] != null){
					amPhone = accountManagerElement.getElementsByTagName("phone")[0].childNodes[0].nodeValue;
				}
				
				var amEmail = "";
				if(accountManagerElement && accountManagerElement.getElementsByTagName("email")[0] != null){
					amEmail = accountManagerElement.getElementsByTagName("email")[0].childNodes[0].nodeValue;
				}
			}
				
			var now = new Date ();
			var end = new Date ();
			end.setDate (end.getDate() + 90);			
							
							
			var date = new Date(str2date_js((type != "PRIO") ? sla_end_js : ph_end_js));
			if (date < end) classN = "exp";
			if ((date < now) || (type == "NE")) classN = "old";

			if (filter != null)
			{
				if ((filter == 10) && (classN != "ok")) continue;
				if ((filter == 12) && (classN != "exp")) continue;
				if ((filter == 11) && (classN != "old")) continue;
				if ((filter == 20) && (type != "NBD")) continue;
				if ((filter == 21) && (type != "4H")) continue;
				if ((filter == 22) && (type != "PRIO")) continue;
				if ((filter == 23) && (type != "NE")) continue;

				if ((filter == 30) && (type != "01 No")) continue;
				if ((filter == 31) && ((type != "02 Silver RA") && (type != "03 Silver On-Site"))) continue;
				if ((filter == 32) && (type != "04 Gold RA")) continue;
				if ((filter == 33) && (type != "06 Platinum RA")) continue;
			}
			
			if ((str != null) && (str != ""))
			{
				if ((subj.toLowerCase().indexOf(str.toLowerCase()) == -1) && (id.toLowerCase().indexOf(str.toLowerCase()) == -1)) continue;
			}
			
			cntRecord  ++;
			
			var row = _createEl("tr",{className: tableSLARowClass});
			row.appendChild(_createEl("td",{align:"center"},_createEl("img",{src:"img/sla_"+type+".png"}),true));
			row.appendChild(_createEl("td",{className: classN},id));
			row.appendChild(_createEl("td",{className: classN},subj));

			if (!supportValidation)
			{
				row.appendChild(_createEl("td",{className: classN},(type != "PRIO") ? sla_end : ph_end));
			}
			else
			{
				var support = "";
				var sdate = ((type != "PRIO") ? sla_end : ph_end);
				
				if (type == "NE") { isExpired = true; support = "<b>NO</b>";}
				else if (date < now) { isExpired = true; support = "<b>EXPIRED</b>, " + sdate; }
				else { isExpired = false; support = "<b>YES</b>, expires: " + sdate; }

				row.appendChild(_createEl("td",{className: classN},support,true));
				
				var supports = parseInt(list[i].getAttribute("supports"));
				var last_sup = list[i].getAttribute("last_sup");
				
				var stext = "";
				if (supports == 0) stext = "n/a";
				else stext = "("+supports+"), last: " + last_sup;
				row.appendChild(_createEl("td",{className: "ok"},stext,true));
				
			}
			
			if (!supportValidation)
			{
				var amToolTip = _createEl("span", {className:"tooltip"}, "");
				amToolTip.appendChild(_createEl("span", {className:"top"},""));
				var amToolTipMiddle = _createEl("span", {className:"middle"},"");
				amToolTipMiddle.appendChild(_createEl("div", {}, amName));
				if(amPhone != null){
					amToolTipMiddle.appendChild(_createEl("div",{}, amPhone));
				}
				
				// amEmail
				if(amEmail != null){
					var emailElement = _createEl("a", {href:"mailto:"+amEmail}, amEmail);
					amToolTipMiddle.appendChild(emailElement);
				}
				
				amToolTip.appendChild(amToolTipMiddle);
				amToolTip.appendChild(_createEl("span", {className:"bottom"},""));
				var amLink = _createEl("a", {href:"#", className:"tt"}, _createEl("img", {src:contextPath+"/img/user_n2.gif"}, true));
				amLink.appendChild(amToolTip);
				
				row.appendChild(_createEl("td",{align:"center"}, amLink));
			}
			
			tBody.appendChild(row);
			
			
		}
		
		if (cntRecord == 0)
		{
			var row = _createEl("tr",{});
			row.appendChild(_createEl("td",{colSpan:"4"},texts["no_record"]));
			tBody.appendChild(row);
		}
		
		if (_getEl("provideSupport"))
		{
			if (isExpired && (cntRecord == 1))
				_getEl("provideSupport").style.display = "block";
			else
				_getEl("provideSupport").style.display = "none";
		}
		
		var tb = _getEl("tbSlas");
		_clearEl(tb);
		tb.appendChild(tHead);
		tb.appendChild(tBody);		
		resizeHeight();
	}
	
	
	function searchQAA()
	{		
		if (qaaTimer != null)
			clearTimeout(qaaTimer);
		qaaTimer = setTimeout(searchQAAScheduled,1000);
	}
	
	// search questions and answers
	function searchQAAScheduled()
	{
		var el = _getEl("srchQAA");
		if (!el) return;
		
		if ((el.value != '') && (el.value != qaaLastText) && (el.value.length > 3))
		{
			var el = _getEl("qaaBox");
			if (!el) return;
			
			_clearEl(el);
			el.appendChild(_createEl("img",{src:"img/load_icon.gif"}));
			el.appendChild(_createEl("span",{},"searching questions and answers ..."));

			qaaLastText = el.value;
			_XHR(contextPath+"/qaa.xml","search="+el.value,searchQAAScheduledFn);	
		}
	}
	
	// build Q&A list
	function searchQAAScheduledFn(xml)
	{
		var el = _getEl("qaaBox");
		if (!el) return;
		_clearEl(el);

		
		// ******************* temporary *******************
		var srch = _getEl("srchQAA");
		if (!srch) return;

		var cnt = 0;
		var objs = xml.getElementsByTagName("qaa");
		for(var i=0, ln=objs.length; i<ln; i++)
		{
			var xQuest = _getByTag(objs[i],"question")[0];
			var xAnswer = _getByTag(objs[i],"answer")[0];

			var found = false;

			var strQ = ((xQuest == null)) ? "" : xQuest.childNodes[(xQuest.childNodes.length == 3) ? 1 : 0].nodeValue;
			if (strQ.toUpperCase().indexOf(srch.value.toUpperCase()) != -1)
				found = true;
			var strA = ((xAnswer == null)) ? "" : xAnswer.childNodes[(xAnswer.childNodes.length == 3) ? 1 : 0].nodeValue;
			if (strA.toUpperCase().indexOf(srch.value.toUpperCase()) != -1)
				found = true;
			
			if (found)
			{
				var que = _createEl("div",{id:"qaa_q"+i, onclick: function() {reverseVisibility(this.id.replace("_q","_a"));} },(cnt+1) + ". " + strQ,true);
				que.style.cursor = "pointer";
				el.appendChild(que);
				var ans = _createEl("div",{className:"bignote",id:"qaa_a"+i},nl2br(strA),true);
				ans.style.display = "none";
				el.appendChild(ans);
				cnt ++;
			}
		}
		// ******************* temporary *******************

		if (cnt == 0)
		{
			el.appendChild(_createEl("span",{},"No data has been found."));
			el.appendChild(_createEl("br",{}));
			el.appendChild(_createEl("span",{},"Please, change search string or "));
			el.appendChild(_createEl("a",{href:"#", onclick: function () {setStep(1);} },"ask directly our support team"));
		}
		
		resizeHeight();
	}
	
	function info(what)
	{
		if (what == "SLA")
		{
			alert("Service Level Agreement number or Site Number is required to provide timely responses. Please ask your SafeQ supplier or YSoft for your agreement number. This doesn't apply to partner registration.");
		}
	}
	
	
	// get the list of the tickets
	function getTickets()
	{
		if ((ticketList == null) && _getEl('tickets'))
			_XHR(contextPath+'/servlet/eu.ysoft.portal.TicketsServlet',"email=support.bcz@konicaminolta.cz", getTicketsFn);			
	}
	
	function getTicketsFn(xml)
	{
		ticketList = xml;
		
		var tTotal = 0;
		var tYsoft = 0;
		var tRnd = 0;
		var tCust = 0;
		
		var obj = _getById('tickets');
		if(obj != null){
			
		if (xml != null)
		{
			var list = xml.getElementsByTagName('ticket');
			var str = "";
			
			for (i =0; i<list.length; i++)
			{
				var waiting = list[i].getAttribute("waiting"); 
				var incident = list[i].getAttribute("incident"); 
				var defect = list[i].getAttribute("defect"); 
				tTotal ++;
				if (waiting == "1") 
					tCust ++;
				else if (defect != "null")
					tRnd ++;
				else
					tYsoft ++;
			}
		}
		
		_clearEl(obj);
		var h3 = _createEl("h3",{});
		h3.appendChild(_createEl("span",{},texts["tick_total"] + ": " + tTotal));
		h3.appendChild(_createEl("a",{href:"#", onclick:showTickets},"<img src='img/help.png'>",true));

		obj.appendChild(h3);
		var ul = _createEl("ul");
		ul.appendChild(_createEl("li",{},texts["tick_ts"] + ": " + tYsoft));
		ul.appendChild(_createEl("li",{},texts["tick_rd"] + ": " + tRnd));
		ul.appendChild(_createEl("li",{},texts["tick_cust"] + ": " + tCust));
		obj.appendChild(ul);
		}
	}
	
	// displays table with all tickets
	function showTickets(filter)
	{	
		if (ticketList == null) return;
		var list = ticketList.getElementsByTagName('ticket');
		var tableTicketsClass= "tbTickets";
		var tableTicketsRowClass = "";
		var cntRecord = 0;
		

		if (list.length == 0) return;
	
		var tBody = _createEl("tbody",{celSpacing:2});
		var tHead = _createEl("thead",{});

		var row = _createEl("tr",{});
		row.appendChild(_createEl("th",{className:"gray", width:"120px"},"#"));
		row.appendChild(_createEl("th",{className:"gray"},"status"));
		row.appendChild(_createEl("th",{className:"gray", width:"30px"},"age"));
		tHead.appendChild(row);
		
			
		for (i =0; i<list.length; i++)
		{
			var evenRow = cntRecord % 2;
			tableTicketsRowClass = evenRow == 0 ? tableTicketsClass+"Odd" : tableTicketsClass+"Even";
			var subj = ((list[i] == null)) ? "?" : list[i].childNodes[(list[i].childNodes.length == 3) ? 1 : 0].nodeValue;
			subj = subj + "<br><i>("+list[i].getAttribute("author")+")</i>";
			var status = "new";
			var classN = "ts";

			var waiting = list[i].getAttribute("waiting"); 
			var incident = list[i].getAttribute("incident"); 
			var defect = list[i].getAttribute("defect"); 

			if (waiting == "1") // waiting for customer
			{
				if ((incident == "Resolved to be confirmed") || (defect == "Resolved to be confirmed"))
				{
					status = texts["ts_CR"];
					classN = "cr";				
				}
				else
				{
					status = texts["ts_AR"];
					classN = "ar";
				}
			}
			else
			{
				if (defect != "null")
				{
					var bug = list[i].getAttribute("polarion_id");
					if (bug == "null") bug = list[i].getAttribute("request_id");
					if (bug == "null") bug = "Without internal ID";
					status = texts["ts_RD"] + " (" + bug + ")";
					classN = "rd";
				}
				else
				{
					status = texts["ts_TS"];
					classN = "ts";
				}
			}

			if (filter != null)
			{
				if ((filter == 10) && (classN != "ar")) continue;
				if ((filter == 11) && (classN != "cr")) continue;
				if ((filter == 20) && (classN != "ts")) continue;
				if ((filter == 21) && (classN != "rd")) continue;
			}
		
			var ticketUrl = cerberusLink.replace("[[[ticketId]]]",list[i].getAttribute("id"));
			ticketUrl = "<a href=\"" + ticketUrl + "\" target=\"_blank\">" + list[i].getAttribute("id") + "</a>";
			var row = _createEl("tr",{className: tableTicketsRowClass});
			row.appendChild(_createEl("td",{},ticketUrl, true));
			row.appendChild(_createEl("td",{className: classN},status));
			row.appendChild(_createEl("td",{},list[i].getAttribute("age") +"d"));
			tBody.appendChild(row);

			var row = _createEl("tr",{className: tableTicketsRowClass});
			row.appendChild(_createEl("td",{className:"blank"},"&nbsp", true));
			var tdx = _createEl("td",{colSpan:2},subj,true);
			row.appendChild(tdx);
			tdx.setAttribute("style","border-bottom: 1px solid #FF");
			//tdx.style.borderBottom = "1px solid #FF";
			
			tBody.appendChild(row);
			cntRecord +=1;
		}
		
		var tb = _getEl("tbTickets");
		_clearEl(tb);
		tb.appendChild(tHead);
		tb.appendChild(tBody);
				
		setStep(99);
		
	}
	
	
	function doEditSLA()
	{
		_getEl("sla_editDiv").style.display="block";
	}

	function findSLA()
	{
		window.location = contextPath+"/servlet/eu.ysoft.portal.SLAChServlet?sla=" + _getEl("sla_input").value;
	}
	
	
	
	// get the message
	function getCerbMessage(messageId)
	{
		_XHR(contextPath+'/rest/incidentManagement/message/',"messageId="+messageId, getCerbMessageFn, callbackCerbMessageError);
	}
	
	function getCerbMessageFn(xml)
	{
		
		if(xml != null){
			var messageXml = xml;
			
			var messageObj = xml.getElementsByTagName("message")[0];
			if(messageObj != null){
				var messageId = xml.getElementsByTagName("id").item(0).childNodes[0].nodeValue;
				
				var messageContent = xml.getElementsByTagName("content")[0];
				if(messageId != null){
					var objML = _getById("messageLoading"+messageId);
					if(objML != null){
						objML.style.display = 'none';
						
					} else {
						
					}
					var objCT = _getById("contentText"+messageId);
					if(objCT != null && messageContent != null){
						var objMT = _getById("messageText"+messageId);
						if(objMT != null){
							//objMT.appendChild(document.createTextNode(unescape(messageContent.childNodes[0].nodeValue)));
							_replaceContent("messageText"+messageId,unescape(messageContent.childNodes[0].nodeValue),true);
							//alert(messageContent.childNodes[0].nodeValue);
						}
						if(objCT != null){
							objCT.style.display = 'block';
						}
					}
					
					var objMessageAddressFrom = _getById("messageAddressFrom"+messageId);
					if(objMessageAddressFrom!= null){
						var address = messageObj.getElementsByTagName("messageAddress")[0];
						if(address != null){
							var email = address.getElementsByTagName("email")[0];
							if(email != null){
								objMessageAddressFrom.appendChild(document.createTextNode(email.childNodes[0].nodeValue));
							}
						}
					}
				}
			}
		}
	}
	
	function callbackCerbMessageError(){
		alert("message retrieval failed!");
	}
	
	
	function hideElements(){
		// var listOfElements = new Array("selType", "selSeverity", "selPasswd",
		// "selTrouble", "selRMA", "selCMGR", "selReport", "selQuestion",
		// "selTickets", "selSlas");
		// var elem =
		for (i=0; i < listOfElements.length; i++){
			var elem = _getById(listOfElements[i]);
			if(elem != null){
				elem.style.display = 'none';
			}
		}
	}
	
	function setCaprIntegrated(){
		hideElements();
		var elem = _getById("selCapr");
		if(elem != null){
			elem.style.display = "block";
			initCapr();
		}
		resizeHeight();
	}

	function replyOnTicket(mask){
		var ticketUrl = cerberusLink.replace("[[[ticketId]]]",mask);
		ticketUrl += "?action=replyCreate";
		window.location=ticketUrl;
	}

	function loadTicketMessages(){
		if((messagesToLoad) && (messagesToLoad != null) && (messagesToLoad.length > 0)){
			for(i=0; i < messagesToLoad.length; i++){
				getCerbMessage(messagesToLoad[i]);
				// alert("retrieving data for message id "+ messagesToLoad[i]+"!");
			}
		}
	}
	
	function createWatchDog(id,type,script)
	{
		var divx = _createEl("div",{});
		var img = _createEl("img",{src:"img/wd.gif",className:"left0"});
		var a = _createEl("a",{href:"/servlet/eu.ysoft.pweb.EditWatchdogServlet?action="+type+"&unitId="+id+"&wdType=8&url="+script},texts[(type == 1) ? "ar_wdon" : "ar_wdoff"]);
		divx.appendChild(img);
		divx.appendChild(a);
		_getEl("smallpadder").appendChild(divx);
	}

	function initSrch()
	{
		if (!_getEl("srchBox")) return;
		_getEl("srchBox").value = texts["quicksearch"];
		_getEl("srchBox").onfocus = function ()
		{
			if (this.value != texts["quicksearch"]) return;
			this.oldValue = "";
			_getEl("divSearcher").className = "srchDiv2";
			_getEl("srchImg").style.display = "inline";
			_getEl("divSearcher").style.height = "35px";
			_getEl("divSearcherBox").className = "srchBoxDiv2";
			this.className = "srchBox2";
			this.value = "";
		}
		_getEl("srchBox").onblur = function ()
		{
			if (this.value != "") return;
			destroyQuickSrch();
		}
		_getEl("srchBox").onkeyup = function ()
		{
			if (this.value == "")
			{
				var cont = _getEl("divSearcherRes");
				_clearEl(cont);
				_getEl("divSearcher").style.height = "35px";
				this.oldValue = this.value;
			}
			else
			if (this.value != this.oldValue)
			{
				var val = this.value;
				if (this.timer != null)
					clearTimeout(this.timer);
				this.timer = setTimeout(function () {buildQuickSrch(null,1); _XHR(contextPath+"/servlet/eu.ysoft.pweb.SearchArticleServlet","searchedText="+val,buildQuickSrch);} ,1000); 
				this.oldValue = this.value;
			}
		}
	}
	
	function buildQuickSrch(xml,clear)
	{
		if (_getEl("srchBox").value == texts["quicksearch"]) return;
		var cont = _getEl("divSearcherRes");
		_clearEl(cont);
		var list = (xml != null) ? xml.getElementsByTagName('ar') : null;
		var height = 0;
		
		if (!clear)
		{
			if ((list == null) || (list.length == 0))
			{
				cont.appendChild(createQSItem("#",texts["qa_none"],"img/btn_srch.png"));
				height += 42;
			}
			else
			for (i =0; i<list.length; i++)
			{
				var name = list[i].getAttribute("title"); 
				var lang = list[i].getAttribute("lang"); 
				var id = list[i].getAttribute("id");
				var cat = list[i].getAttribute("category"); 
				name = name;
				
				var href = "#";
				var img = "img/btn_srch.png";
				switch (parseInt(cat))
				{
					case 69: img = "img/main_general.png"; href="/general?page=doc&arId="+id; break;
					case 1:  img = "img/main_marketing.png"; href="/marketing?page=doc&arId="+id;break;
					case 75: img = "img/main_bs.png"; href="/business?page=doc&arId="+id;break;
					case 2:  img = "img/main_ts.png"; href="/tech?page=doc&arId="+id;break;
				}

				cont.appendChild(createQSItem(href,name,img,lang));
				height += 42;
				if (i == 10)
				{
					cont.appendChild(createQSItem("#",texts["qa_many"],"img/btn_srch.png"));
					height += 42;
					break;
				}
			}
		} 
		else
		{
			cont.appendChild(createQSItem("#",texts["qa_"+((xml == null) ? "load" : "none")],"img/loading.gif"));
			height += 42;
		}
		_getEl("divSearcher").style.height = (height+50)+"px";
	}
	
	function createQSItem(ahref,text, icon,lang)
	{
		var imgLoad = _createEl("img",{className:"left",src:icon});
		var div1 = _createEl("div",{width:"34px"},imgLoad,true);
		var div2 = _createEl("div",{width:"340px"},text);
		if ((lang != null) && (lang != currentLang))
		{
			div2.appendChild(_createEl("span",{className:"new"}," " +lang+"!"));
		}
		var li = _createEl("li",{}); var a = _createEl("a",{href:ahref});
		div1.style.width = "34px"; div2.style.width = "336px";
		a.appendChild(div1); a.appendChild(div2);li.appendChild(a); 
		
		return li;
	}
	
	function destroyQuickSrch()
	{
		_clearEl(_getEl("divSearcherRes"));
		_getEl("divSearcher").className = "srchDiv";
		_getEl("divSearcher").style.height = "25px";
		_getEl("divSearcherBox").className = "srchBoxDiv";
		_getEl("srchBox").className = "srchBox";
		_getEl("srchBox").value = texts["quicksearch"];
		_getEl("srchImg").style.display = "none";
	}

	
	function sendFeedback(page,number)
	{
		if (number) // feedback to wiki article
		{		
			if(_getById('f1').value == '' || _getById('f2').value == '' || _getById('f3').value == '')
			{
				return alert('Only registered users can provide feedback!');
			}		
			
			setCookie("feedback_" + _getById("idWikiName").value , number, 999);
			setWikiRate();
			_JSON(tsPath + '.TShotFeedbackServlet', _getFormQuery(_getById('feedbackBody')), showResultFB);
		}
		else // general feedback
		{
			if (page)
			{
				var text = "Feedback for page " + page + "\nFrom: " + _getEl("db_user").value + "\n\n" + _getEl("fb_text").value;
				var hr = "email="+_getEl("db_email").value+"&text="+text+"&name="+ _getEl("db_user").value;
				_JSON(tsPath + '.TShotFeedbackServlet', hr, showResultFB);
				_getEl("fbDiv").style.display = "none";
			}
			else
				_getEl("fbDiv").style.display = "block";

		}
	}

	function showResultFB(result)
	{
		if (_getById('feedback') != null)
			_getById('feedback').style.display = 'none';

		alert(result);
		
		if (_getEl('f1'))
		{
			_getById('f1').value = '';
			_getById('f2').value = '';
			_getById('f3').value = '';
		}
	}		
	
	function testField(input,text,testRL)
	{
		var regLetters = new RegExp('^[a-zA-Z0-9 .,-_/]*$');
		if (input.value == '')
		{
			input.style.backgroundColor = '#FF9966';
			input.focus();
			alert(texts["lic_compl"] + " " + text);
			return false;
		}
		if (testRL && !regLetters.test(input.value))
		{
			input.style.backgroundColor = '#FF9966';
			input.focus();
			alert(texts["lic_compl2"] + " " );
			return false;
		}
		input.style.backgroundColor = 'white';
		
		return true;
	}
	
	
	
