var xmlHttpReq = createXmlHttpObject();
var lexiconPage = "/units/lexicon.php";
var dword_id = null;

function createXmlHttpObject(){
	var xmlHttp_obj;
	if(window.ActiveXObject)
	{
		try
		{
			xmlHttp_obj = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp_obj = false;
		}
	}
	else
	{
		try
		{
			xmlHttp_obj = new XMLHttpRequest();
		}
		catch (e)
		{
			xmlHttp_obj = false;
		}
	}
	if (!xmlHttp_obj)
		alert("Błąd podczas tworzenia obiektu XMLHttpRequest.");
	else
		return xmlHttp_obj;
}

function lexiconHandleSR(){
	if(xmlHttpReq.readyState == 4){
		if(xmlHttpReq.status == 200) {
			var dest;
			dest = document.getElementById('lexicon_subject_matter');
			if(dest != undefined && dest != null){
				dest.innerHTML = xmlHttpReq.responseText;
			}
		} else {
			
		}
	}
}

function getSubjectMatter(dictId){
	
	dictId = parseInt(dictId);
	if(xmlHttpReq.readyState == 4 || xmlHttpReq.readyState == 0)
	{
		xmlHttpReq.open("GET",lexiconPage + "?dictId=" + dictId,true);
		xmlHttpReq.onreadystatechange = lexiconHandleSR;
		xmlHttpReq.send(null); 
	} else {
		setTimeout("getSubjectMatter(" + dictId +")",1000);
	}
	//return false;
}

function getAnswerForQuestion(parentObj, questId, otherIds){	
	
	for(x in otherIds){		
		if(otherIds[x] != questId){
			$('#' + otherIds[x]).parent().find('a').css('color','#828282');
			$('#' + otherIds[x]).parent().find('a').css('fontWeight','normal');
			$('#' + otherIds[x]).hide();						
		}
	}
	if($('#' + questId).css('display') == 'none'){
		$('#' + questId).parent().find('a').css('color','#90B4E4');
		$('#' + questId).parent().find('a').css('fontWeight','bold');		
	} else {
		$('#' + questId).parent().find('a').css('color','#828282');
		$('#' + questId).parent().find('a').css('fontWeight','normal');
	}
	$('#' + questId).toggle();	
		
	
}
function action_clickSM(item, dictWord){
	var head;
	var reg = new RegExp();
	dictWord = dictWord.replace(/(<([^>]+)>)/ig,"");
	head = document.getElementById("lexicon_sm_header_txt_001");
	if(head != undefined && head != null)
	{
		head.innerHTML = dictWord.toLowerCase();
	}
	if(dword_id != null){
		var linkDword;
		linkDword = document.getElementById(dword_id);
		if(linkDword != null && linkDword != undefined){
			linkDword.style.color = "";
			linkDword.style["fontWeight"] = "normal"
		} 
	}
	if(item != null && item != undefined){
		item.style.color = "#70a0e2";
		item.style["fontWeight"] = "bold";
		dword_id = item.id;
	}
}

function validateLexiconSearh(form){
	return DDXLen(form.search,3,1024,"Długość wyrażenia do wyszukania jest niepoprawna.");
}

function goToPrint(questId){
	questId = parseInt(questId);
	window.open("/potrzebujesz_porady/leksykon?questionId=" + questId,'_blank','toolbar=no, status=no,menubar=no,scrollbars=yes,resizable=yes, top=100,left=100,height=500,width=500');
	return false;
}
function printText()
{		
	if (!window.print){
	      alert("Twoja przeglądarka nie obsługuje drukowania!")
	} else
	{
		window.print();
	}
}
