/*

*/
var currentLanguage = "pl"
// mainApplicationServlet
var mainApplicationServlet="/4ses/servlet/MainServlet";
var maxWidth=1016;

function checkCookie(){
  // check if cookie are enabled
  cookieBackup = document.cookie;
  document.cookie = "cookie=enabled"
  var cookieOK = false;
  if (document.cookie.indexOf("cookie=enabled") > -1) {
  	//alert ("Cookie sa wlaczone :)");
		document.getElementById("cookiesDivHead").style.visibility = "hidden";
		document.getElementById("cookiesDiv").style.visibility = "hidden";
  }else{
	  //alert("Cookie sa wylaczone! Nie bedzie mozna zalogowac sie do systemu.");
		document.getElementById("cookiesDivHead").style.visibility = "visible";
		document.getElementById("cookiesDiv").style.visibility = "visible";		
  }
	document.cookie = cookieBackup;
}

function openWin(lcUrl,lnWidth,lnHeight,lnResize,lnSroll,lcWinName,lnTopPosition) {
	if(!lnWidth)	lnWidth = 0;
	if(!lnHeight)	lnHeight = 0;
	if(!lnSroll)	lnSroll = 0;
	if(!lnResize)	lnResize = 0;
	if(!lcWinName)	lcWinName = "Win" + getRandomParam();
	if(!lnTopPosition)		lnTopPosition = 0;
	var lcParaExtra = "";
	var lnLeft = 0;
	var lnTop  = 0;
	
	var lnStatus = 0;
	var lnMenubar = 0;
	
	//opcja do wlaczania fullscreen
	//if(lnWidth<1 && lnHeight<1)lcParaExtra += ",fullscreen=Yes";
	
	if(lnWidth<1) {
		lnWidth = screen.availWidth - 10;
	}else{
		lnLeft  = screen.availWidth/2 - lnWidth/2;		
	}

	if(lnHeight>screen.availHeight){
		lnHeight = screen.availHeight - 40;
	}

	if(lnHeight<1){
		lnHeight = screen.availHeight - 30;		
	}else{
		lnTop    = (lnTopPosition>0)?lnTopPosition:screen.availHeight/2 - lnHeight/2;		
	}
	if (lnWidth > maxWidth) {
		lnWidth = maxWidth;
		lnLeft  = screen.availWidth/2 - lnWidth/2;
		lnResize = 0;
	}
	var lcPara = "directories=0,location=0,menubar="+lnMenubar+",resizable=" + lnResize +",scrollbars="+lnSroll+",status="+lnStatus+",toolbar=0";
	    lcPara += lcParaExtra + ",screenX="+lnLeft+",screenY="+lnTop+",top="+lnTop+",left="+lnLeft+",width="+lnWidth+",height="+lnHeight;

	var oWin = window.open(lcUrl,lcWinName,lcPara);
    try
    {
        if (oWin != null)oWin.focus();
    } catch(e) {}
	
	//return oWin;
}
//-------------------------------------------------------------
function getRandomParam(){
	var now = new Date();
	return(""+now.getTime())
}
//-------------------------------------------------------------
function _alert(msg){
	//alert(msg);
}
//-------------------------------------------------------------
function closeWin(){
	top.window.close();	
	return true;
}
//-------------------------------------------------------------
function refresh(){
  top.window.document.location.reload()
  return true;
}
//-------------------------------------------------------------
function openHelpWindow(pageName){
	openWin(pageName,600,400,1,1,"helpWindow")
	return;
}
//-------------------------------------------------------------
// popup message
function goToMsg(){
	openWin(mainApplicationServlet+"?method=lms.GlobalMailerDisplayPopup",520,320,1,1,"popup_message");
}
//-------------------------------------------------------------
// open chat window
function goToChat(id_chat){
	if(!id_chat)id_chat=-1;
	openWin(mainApplicationServlet+"?method=lms.chat.Chat&id_chat="+id_chat,700,600,0,0,null,10)
	return;
}
//-------------------------------------------------------------
// open course window
function arg2str(arg){
	if(!arg || arg.length<1)return "Without args!"
	var lcS = "";
	for(var i=0;i<arg.length;i++){
		lcS+=arg[i] + "\n";
	}
	return lcS;
}
//uruchomienie kursu poprzez liste elementow skladowych
function goToCourseByTrainingList(id_training,id_course,backPage){
	var lcUrl = mainApplicationServlet+"?method=lms.StudentGoToCourse&noLink=0&id_training="+id_training+"&id_course="+id_course+"&id_sco=0&backPage="+backPage;
	document.location=lcUrl;
	return;
}

//uruchomienie kursu
function goToCourseByTraining(id_training,id_course,id_sco){
	var lcUrl = mainApplicationServlet+"?method=lms.StudentGoToCourse&noLink=0&id_training="+id_training+"&id_course="+id_course+"&id_sco="+id_sco+"&id_group=-1";
	document.location=lcUrl;
	return;
}

//uruchomienie kursu
function goToCourse(id_course,id_sco,id_group){
	if (id_group==-1) id_group="-1"; 
	var lcUrl = mainApplicationServlet+"?method=lms.StudentGoToCourse&noLink=0&id_course="+id_course+"&id_sco="+id_sco+"&id_group="+id_group;
	document.location=lcUrl;
	return;
}

//uruchomienie kursu z ikienka powiadomienia o kursach otwartych
function notificationGoToCourse(id_course,id_sco,backPage,id_notification){
	var lcUrl = mainApplicationServlet+"?method=lms.StudentGoToCourse&noLink=0&id_course="+id_course+"&id_sco="+id_sco+"&id_notification="+id_notification+"&backPage="+backPage;
	document.location=lcUrl;
	return;
}

//uruchomienie egzaminu poprzez liste elementow skladowych
function goToExamByTrainingList(id_training,id_exam,backPage){
	var lcUrl = mainApplicationServlet+"?method=lms.StudentGoToExam&id_training="+id_training+"&id_exam="+id_exam+"&backPage="+backPage;
	document.location=lcUrl;
	return;
}

//uruchomienie egzaminu
function goToExamByTraining(id_training,id_exam){
	var lcUrl = mainApplicationServlet+"?method=lms.StudentGoToExam&id_training="+id_training+"&id_exam="+id_exam+"&id_group=-1";
	document.location=lcUrl;
	return;
}
//uruchomienie egzaminu
function goToExam(idexam,id_group){
	if (id_group==-1) id_group="";
	var lcUrl = mainApplicationServlet+"?method=lms.StudentGoToExam&id_exam="+idexam+"&id_group="+id_group;
	document.location=lcUrl;
	return;
}

//uruchomienie encyklopedii
function goToEncyclopedia(id_course,id_sco,searchParam){
	var lcUrl = mainApplicationServlet+"?method=lms.StudentGoToEncyclopedia&id_course="+id_course+"&id_sco="+id_sco+"&search="+searchParam;
	document.location=lcUrl;
	return;
}

//-------------------------------------------------------------
function goToExamLinks(idexam, id_training,id_group){
	var lcUrl = mainApplicationServlet+"?method=lms.StudentExamResult&id_exam="+idexam+"&id_training="+id_training+"&id_group="+id_group;
	document.location=lcUrl;
	return;
}
//-------------------------------------------------------------
function goToTrainingDetails(id_training){
	var lcUrl = mainApplicationServlet +"?method=lms.training.TrainingDetails&id_training="+id_training+"&display=current";
	if (opener!=null){
		opener.document.location.href=lcUrl;
		window.close();
	}else{
		document.location.href=lcUrl;
	}
	
}
//-------------------------------------------------------------
function goToFaq(idcourse){
	document.forms[0].gotofaq.value="yes";
	document.forms[0].gotofaqcourseid.value=idcourse;
	document.forms[0].submit();
}
//-------------------------------------------------------------
function courseAction(action, idcourse){
	document.forms[0].courseaction.value=action;
	document.forms[0].courseactionid.value=idcourse;
	document.forms[0].submit();
}
//-------------------------------------------------------------
function checkAll() {
	//alert("gg");
	//alert(document.forms[0].getElementById(checkbuton).value);
}
//-------------------------------------------------------------
function selectAllCheckbox(formNumber, checked) {
	chckB = document.forms[formNumber].elements;
	for(i=0; i < chckB.length; i++) {
		var obj = chckB[i];
		if(obj.type=='checkbox'){
			obj.checked = checked;
		}
	}
}
//-------------------------------------------------------------
// zaznacza wszystkie przedmioty w danej dziedzinie
function selecAllDomainCheckbox(formNumber, checked, obj_id) {
	chckB = document.forms[formNumber].elements;
	var damain_id = 'domain#'+obj_id;
	for(i=0; i < chckB.length; i++) {
		var obj = chckB[i];
		if(obj.type=='checkbox' && obj.name==damain_id){
			obj.checked = checked;
		}
	}
}
//-------------------------------------------------------------
function getUrlFromHtml(url, url_decode) {
	url_decode.value = encodeURI(url.value);
}
//-------------------------------------------------------------
function aspGoToCredits(){
	if(opener){
		opener.location.href = mainApplicationServlet+"?method=lms.ProductList";
	}	
	return;
}
//-------------------------------------------------------------
function showSCOComments(){
	var lcUrl = mainApplicationServlet+"?method=lms.StudentScoComments";
	openWin(lcUrl,590,400,0,0,'comments',0)
	return;
}
//-------------------------------------------------------------
function openExternalPage(lcUrl,lnResize){
	if(!lnResize)lnResize=0;
	openWin(lcUrl,780,500,lnResize,0,'ExternalPage',0)
	return;
}
//-------------------------------------------------------------
function getCookie(what){
	var result="nocookies";
	if (document.cookie.length>1){
		cookiesStuff=document.cookie;
		var iscookie=cookiesStuff.indexOf(what);
		
		if (iscookie!=-1){
			cookiesStuff = cookiesStuff.substring(iscookie,cookiesStuff.length);
			start=cookiesStuff.indexOf("=")+1;
			end=cookiesStuff.indexOf(";");
			if (end==-1){
				end = cookiesStuff.length;
			}
			result=cookiesStuff.substring(start,end);
		}
	}
	return result;
}

//-------------------------------------------------------------
function setCookie (name, value){
	var expire = new Date();
	expire.setTime(expire.getTime() + ( 7*24*60*60*1000 ) ); // expire in 1 week
	document.cookie = name+"="+value+"; expires=" + expire.toGMTString();
}

function openExtendChat(usid, unique, langVersion){
	var url = mainApplicationServlet+'?method=lms.chatextend.ChatExtendRedirect&language='+langVersion;
	if(usid != null){
		url += "&usid=" + usid;
	}
	openWin(url,730,530,0,0,'Chat'+unique,0);
}
//-------------------------------------------------------------
//global object (You can translate month&day names)
//alert("currentLanguage:" + currentLanguage);
var oCalLng = null;
oCalLng_pl={
	 day:['pn','wt','&#347;r','cz','pt','so','n'],
	 month:['Stycze&#324;','Luty','Marzec','Kwiecie&#324;','Maj','Czerwiec',
	 'Lipiec','Sierpie&#324;','Wrzesie&#324;','Pa&#378;dziernik','Listopad','Grudzie&#324;'],
	 D:new Date(),M:new Date().getMonth(),R:new Date().getFullYear()
}
oCalLng_de={
	 day:['mo','di','mi','do','fr','sa','so'],
	 month:['Januar','Februar','M�rz','April','Mai','Juni',
	 'Juli','August','September','Oktober','November','Dezember'],
	 D:new Date(),M:new Date().getMonth(),R:new Date().getFullYear()
}
oCalLng_en={
	 day:['mo','tu','we','th','fr','sa','su'],
	 month:['January','February','March','April','May','June',
	 'July','August','September','October','November','December'],
	 D:new Date(),M:new Date().getMonth(),R:new Date().getFullYear()
}	

function getXXXXXXXXXXCalLng(lng){
var oCalLng = oCalLng_en;
if (currentLanguage=="pl"){
oCalLng = oCalLng_pl;
}else if (currentLanguage=="de"){
oCalLng = oCalLng_de;
}else {
oCalLng = oCalLng_en;
}
return oCalLng;
}
//Written by Bogdan Blaszczak/BlaTek
//blatek@25.pl
function Calendar(E,T){
 oCalLng = getXXXXXXXXXXCalLng();
 if(!document.getElementById||!document.body.appendChild)return
 var i,j,tBody,Row,od,Do,d,dt
 function cEl(t,p,h,w,c){
  p.appendChild(t=document.createElement(t))
  if(h)t.innerHTML=h;if(w)t.style.width='27px';
  if (c) {t.className=c}
  return t}
 function cB(x){with(oCalLng){
  B=0;x==0?R--:x==1?R++:x==2?(!M?(M=11,R--):M--):(M==11?(M=0,R++):M++)}
 }
 with(oCalLng){
  od=Date.UTC(R,M,1);Do=Date.UTC(R,M+1,1)}
 E=document.getElementById(E)
 while(E.childNodes.length)E.removeChild(E.firstChild)
 tBody=cEl('tbody',cEl('table',E))
 tBody.onmouseup=function(){T.focus()}
 tBody.onmousemove=function(){
  if(window.getSelection)window.getSelection().removeAllRanges()}
 Row=cEl('tr',tBody)
 cEl('td',Row,'&#171;',1).onmousedown=function(){cB(0)}
 cEl('td',Row,oCalLng.R)
 cEl('td',Row,'&#187;',1).onmousedown=function(){cB(1)}
 Row=cEl('tr',tBody)
 cEl('td',Row,'&#171;',1).onmousedown=function(){cB(2)}
 cEl('td',Row,oCalLng.month[oCalLng.M])
 cEl('td',Row,'&#187;',1).onmousedown=function(){cB(3)}

 tBody=cEl('tbody',cEl('table',E))
 Row=cEl('tr',tBody)
 for(i=0;i<7;i++)
  with(cEl('th',Row,oCalLng.day[i]))
   if(i==6){
	 //style.backgroundColor='#990000'
	 //style.color='#ffffff'
	 }

 for(i=od;i<Do;i+=86400000){
  with(new Date(i)){d=getUTCDate();dt=getUTCDay()}
  if(dt==1||i==od)Row=cEl('tr',tBody)
  if(dt!=1&&d==1)for(j=1;j<(dt?dt:7);j++)cEl('td',Row,null,null,"empt")
  dt=cEl('td',Row,d);dt.onmousedown=function(x){
   x=+this.innerHTML
   with(oCalLng)
    T.value=(x<10?'0'+x:x)+'.'+((x=M+1)<10?'0'+x:x)+'.'+R
  }
  with(oCalLng)
  if(d==D.getDate()&&M==D.getMonth()&&R==D.getFullYear()){
	 dt.style.backgroundColor='#990000'
	 dt.style.color='#ffffff'
  }
 }
 T.onblur=function(){if(oCalLng.B)E.style.display='none'}
 oCalLng.B=1;E.style.display='block'
}

/*
jk
*/
var sColors = "000000,993300,333300,003300,003366,000080,333399,333333,800000,FF6600,808000,808080,008080,0000FF,666699,808080,FF0000,FF9900,99CC00,339966,33CCCC,3366FF,800080,999999,FF00FF,FFCC00,FFFF00,00FF00,00FFFF,00CCFF,993366,C0C0C0,FF99CC,FFCC99,FFFF99,CCFFCC,CCFFFF,99CCFF,CC99FF,FFFFFF";
var colorObj = null;
var cdWaitForAction = false;

function colorDialogFire(color)
{
	if (colorObj) {
		colorObj.value = color;
		var obj = document.getElementById(colorObj.name+"_preview");
		if (obj) {
			obj.style.backgroundColor = color;
		}
		hideFloatingDiv();
		//document.body.style.backgroundColor = color;
	}
	
	cdWaitForAction = false;
};

function ColorDialog(color, obj)
{
	makeFloatingDiv();
	
	obj.onblur = function() {
		if (!cdWaitForAction) {
			hideFloatingDiv();
		}
	}
	
	colorObj = obj;
	
	var ch = 0;
	var cols = 8;
	var s = '<table onmouseout="cdWaitForAction=false;" onmouseover="cdWaitForAction=true;"><tr><td><table><tr><td id="__colorTable">';
	var colors = sColors.split(",");
	s += '<table>';
	while (ch < colors.length) {
		s += '<tr>';
		for (var i=0; i<cols; i++) {
			if (ch >= colors.length) break;
			
			s += '<td class="colorDOut" onmouseout="this.className=\'colorDOut\';" onmouseover="this.className=\'colorDOver\';" onclick="colorDialogFire(\'#' + colors[ch] + '\');">';
			s += '<p class="ccp" style="background-color:#' + colors[ch] + ';">&nbsp;</p>';
			s += '</td>';
			
			ch++;
		}
		s += '</tr>';
	}
	
	s += '</table>';
	s += '</td></tr></table></td></tr><tr></tr></table>';
	
	if (obj) {
		var x = findPosX(obj);
		var y = findPosY(obj) + 20;
	} else {
		var x = 0;
		var y = 0;
	}
	showFloatingDiv(x + "px", y + "px", 160 + "px", 125 + "px", s);
}

//end Color Dialog

function printPage(){
	document.getElementById("printPage").style.display="none";
	var a = window.print();
	document.getElementById("printPage").style.display="block";
}
// wykorzystywane do ustawiania sortowania 
// w DataListBaseContent (dla FastView)
function setFormVarsAndSubmit(){	
	var oForm = document.getElementById('fastviewForm');
	if(!oForm)return;
	var oEl;
	for(var i=0;i<arguments.length;i++){
		var p = arguments[i].split("=");
		oEl = oForm.elements[p[0]];
		if(oEl)oEl.value=p[1];
	}
	oForm.submit();
}
function setElementVisibility(id,visible){
	if (visible==true){
		document.getElementById(id).style.visibility="visible";
	}else{
		document.getElementById(id).style.visibility="hidden";
	}
}

var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  xmlhttp = new XMLHttpRequest();
}

function buildPOST() {
theForm = document.forms[0];
var qs = ''
for (e=0;e<theForm.elements.length;e++) {
if (theForm.elements[e].name!='') {
var name = theForm.elements[e].name;
qs+=(qs=='')?'':'&'
qs+= name+'='+escape(theForm.elements[e].value);
}
}
return qs
}

function callMethod(method,params){
	xmlhttp=false;
	if (xmlhttp){
		var xmlMessage = buildPOST()+params;
		url = mainApplicationServlet+"?method="+method;
		xmlhttp.open("POST",url,false);
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
				if (xmlhttp.status==404) {
					alert("An error occured! Cannot submit data.");
				}
			}
		}
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlhttp.send(xmlMessage);
		document.open();
		document.write(xmlhttp.responseText);
		document.close();
		return true;
	}else{
		window.document.forms[0].submit();
	}
	return false;
}

function selectObjects() {
	var idList = "";
	var idList2 = "";
	var count1 = 0;
	var count2 = 0;
	for (var i=0; i<=document.forms[0].length; i++){
		if (document.forms[0].elements[i]!=null && document.forms[0].elements[i].type=='checkbox'){
			if (document.forms[0].elements[i].checked==true){
				
				var checkboxId = document.forms[0].elements[i].id;
				if (checkboxId.indexOf("object_")>-1){
					count1+=1;
					var id = checkboxId.substring(checkboxId.indexOf("object_")+7,checkboxId.length);
					if (count1==1){
						idList=""+id;
					}else{
						idList=idList+","+id;
					}
				}
			}else{
				
				var checkboxId = document.forms[0].elements[i].id;
				if (checkboxId.indexOf("object_")>-1){
					count2+=1;
					var id = checkboxId.substring(checkboxId.indexOf("object_")+7,checkboxId.length);
					if (count2==1){
						idList2=""+id;
					}else{
						idList2=idList2+","+id;
					}
				}
			}
		}
	}
	document.forms[0].objectsChecked.value=idList;
	document.forms[0].objectsNotChecked.value=idList2;
	document.forms[0].objectsCheckingActive.value="true";
}

var focusedElement = null;
function initForm(form) {
	if (form && form.getElementsByTagName) {
		var e, i = 0;
		while (e = form.getElementsByTagName('INPUT')[i++]) {
			if (!e) continue;
			e.oldOnFocus = e.onfocus;
			e.onfocus = function () {
				if (this.oldOnFocus) this.oldOnFocus();
				focusedElement = this;
			}
		}
		var e, i = 0;
		while (e = form.getElementsByTagName('SELECT')[i++]) {
			if (!e) continue;
			e.oldOnFocus = e.onfocus;
			e.onfocus = function () {
				if (this.oldOnFocus) this.oldOnFocus();
				focusedElement = this;
			}
		}
	}
}
function isInArray(arr, value) {
	for (var i=0; i < arr.length; i++){
		if (arr[i] == value) return true;
	}
	return false;
}
function isMultiDeleteIncludeCategory(form) {
	var obj = null;
	var arr = new Array();
	var inputArr = form.getElementsByTagName('INPUT');
	for (var i=0; i < inputArr.length; i++)
	{
		obj = inputArr[i];
		if (obj.type == "checkbox" && obj.checked){
			if (obj.value.indexOf("category") > -1) return true;
		}
	}
	return false;
}
function validateForm(form) {
	if (!form) return false;
	if (!focusedElement) return true;
	var actionName = "";
	var nameSplit = "";
	var actions = "";
	switch (focusedElement.tagName) {
		case "INPUT":
			try {
				nameSplit = focusedElement.name.split("#");
				if (typeof(nameSplit[1]) != 'undefined'){
					actions = nameSplit[1].split(":");
					actionName = actions[1];
				}
			} catch (e) {}
			break;
		case "SELECT":
			try {
				var actions = focusedElement.value.split("#")[0].split(":");
				if (typeof(actions[1]) != 'undefined'){
					actionName = actions[1];
				}
			} catch (e) {}
			break;
	}
	switch (actionName) {
		case "delete":
			var arr = actions[0].split('.');			
			if (isInArray(arr, "category") || (focusedElement.tagName == "SELECT" && isMultiDeleteIncludeCategory(form))) {
				if (confirm(core.lang.delete_folder_msg)) {
					return true;
				} else {
					if (focusedElement.tagName == "SELECT") {
						focusedElement.selectedIndex = 0;
					}
					return false;
				}
			}else{
				if (confirm(core.lang.delete_msg)) {
					return true;
				} else {
					if (focusedElement.tagName == "SELECT") {
						focusedElement.selectedIndex = 0;
					}
					return false;
				}			
			}
	}
	return true;
}

var funcToRunOnLoad = new Array();
function addFuncToRunOnLoad(func) {
	funcToRunOnLoad[funcToRunOnLoad.length] = func;
};

function doLoad() {
	for (var i=0; i<funcToRunOnLoad.length; i++) {
		var func = funcToRunOnLoad[i];
		if (typeof(func) == "undefined" || func == null) {
			continue;
		}
		func();
	}
};

function doBodyLoad() {
	alert("System failure.\nMethod doBodyLoad is deprecated. Remove this method from your index template.\nCorrect: <body>\nIncorrect: <body onload=\"doBodyLoad();\">.\nFor more information ask your legal guardian.");
};

var funcToRunOnUnLoad = new Array();
function addFuncToRunOnUnLoad(func) {
	funcToRunOnUnLoad[funcToRunOnUnLoad.length] = func;
};

function doUnLoad() {
	for (var i=0; i<funcToRunOnUnLoad.length; i++) {
		var func = funcToRunOnUnLoad[i];
		if (typeof(func) == "undefined" || func == null) {
			continue;
		}
		func();
	}
};

function doBodyUnLoad() {
	alert("System failure.\nMethod doBodyUnLoad is deprecated. Remove this method from your index template.\nCorrect: <body>\nIncorrect: <body onload=\"doBodyUnLoad();\">\nFor more information ask your legal guardian.");
};

window.onload = doLoad;
window.onunload = doUnLoad;

var funcToRunOnSubmit = new Array();
function addFuncToRunOnSubmit(func) {
	funcToRunOnSubmit[funcToRunOnSubmit.length] = func;
};

function confirmation(text) {
	var answer = confirm(text)
	if (answer){
		alert("Bye bye!")
		window.location = "http://www.google.com/";
	}
	else{
		alert("Thanks for sticking around!")
	}
}

function doActionButton(obj, params) {
	if (obj) {
		var reNameCancel = new RegExp(/:cancel?/);
		if (obj.name.match(reNameCancel)) {
			var answer = confirm(core.lang.cancel_msg);
			if (!answer) {
				return;
			}
		}
	}

	for (var i=0; i<funcToRunOnSubmit.length; i++) {
		var func = funcToRunOnSubmit[i];
		if (typeof(func) == "undefined" || func == null) {
			continue;
		}
		func();
	}
	
	if (!obj) return;
	var oForm = obj.form;
	if (!oForm) return;
	var page = "";
	if (obj.type == "button" || obj.type == "submit") {
		page = obj.name;
	}
	if (page != "" && oForm.elements[core.pagePrefix]) {
		oForm.elements[core.pagePrefix].value = page;
	}
	if (typeof(params) != "undefined" && oForm.elements[core.paramsPrefix]) {
		oForm.elements[core.paramsPrefix].value = params;
	}
	if (validateForm(oForm)) {
		oForm.submit();
	}
	return true;
}
function doActionList(obj) {
	if (!obj) return;
	var oForm = obj.form;
	if (!oForm) return;
	var page = "";
	var params = "";
	if (obj.type == "select" || obj.type == "select-one") {
		var val = obj.value.split("#");
		page = val[0];
		params = val[1];
	}
	if (page != "" && oForm.elements[core.pagePrefix]) {
		oForm.elements[core.pagePrefix].value = page;
	}
	if (typeof(params) != "undefined" && oForm.elements[core.paramsPrefix]) {
		oForm.elements[core.paramsPrefix].value = params;
	}
	if (validateForm(oForm)) {
		oForm.submit();
	}
}

function doActionCombo(obj) {
    doActionList(obj);
}

function navGoToPage(action, pageNo, formName) {
	var form = document.getElementById(formName);
	if (!form) return;
	for (var i=0; i<form.elements.length; i++) {
		if (form.elements[i].name == "wbts:ai") {
			form.elements[i].value = action;
			break;
		}
	}
	objCurrentPage = form.elements['page.current']
	if (objCurrentPage!=null){
		objCurrentPage.value=pageNo;
	}
	
	if (validateForm(form)) {
		form.submit();
	}
};

function getLinksUnusedID() {
	var i = 1;
	while (document.getElementById('chb_link'+i)) i++;
	
	return i;
}
function addLink(obj) {
	var oForm = obj.form;
	if (!oForm) return;
	var link = oForm.elements['links'].value;
	var reUrl = new RegExp(/(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?/);
	var reProtoOnly = new RegExp(/^(http|ftp|https):\/\//);
	if (!link.match(reProtoOnly)) link = "http://" + link;
	if (link.match(reUrl)){
		oForm.elements['links'].style.backgroundColor = "";
		var ind = getLinksUnusedID();
		var linkContent = document.getElementById('links_content');
		linkContent.innerHTML+="<div id='div_chb_link"+ind+"'><input class='checkbox' type='checkbox' id='chb_link"+ind+"' name='chb_link'/>"+link+"<input type='hidden' id='linkParams' name='linkParams' value='"+link+"'/><br/></div>";
		
		document.getElementById('remove_links_button').style.display="block";
	} else {
		oForm.elements['links'].style.backgroundColor = "#FF8888";
	}
}
function removeLink(obj) {
	var oForm = obj.form;
	if (!oForm) return;
	var link = oForm.elements['links'].value;
	var linkContent = document.getElementById('links_content');
	var allChb = document.getElementsByName('chb_link');
	var allChbLength = allChb.length;
	for (var i=allChbLength-1; i >-1; i--)
	{
		//alert("i: "+i+" checked: "+allChb[i].checked);
		if (allChb[i] && allChb[i].checked){
			obj = document.getElementById('div_'+allChb[i].id);
			linkContent.removeChild(obj);
		}
	}
	for (var i=allChbLength-1; i >-1; i--)
	{
		if (allChb[i] && allChb[i].checked){
			linkContent.removeChild(allChb[i]);
		}
	}
	var allChb = document.getElementsByName('chb_link');
	if (allChb.length==0){
		document.getElementById('remove_links_button').style.display="none";
	}
}
function removeAttachments(obj) {
	var oForm = obj.form;
	if (!oForm) return;

	//usuwanie dodanych juz zalacznikow
	var attContent = document.getElementById('attachments_content');
	var attChb = document.getElementsByName('chb_attachment');
	var attChbLength = attChb.length;
	for (var i=attChbLength-1; i >-1; i--)
	{
		if (attChb[i] && attChb[i].checked){
			obj = document.getElementById('div_'+attChb[i].id);
			attContent.removeChild(obj);
		}
	}
	
	attChb = document.getElementsByName('chb_attachment');
	if (attChb.length==0) {
		document.getElementById('remove_attachments_button').style.display="none";
	}
}

function isArray(obj){
    if(!obj){
        return false;
    }
    
    return(typeof(obj.length) == "undefined") ? false : true;
}

function changeSelectAll(obj,name){
	if (!obj.checked) {
		document.getElementById('selectAll').checked = false;		
	}else{
		var oForm = obj.form;
		if(!oForm)return;
		var oEl = oForm[name];
		if(!oEl){			
			return;
		}		
		var allChecked = true;
		for(var i=0; i<oEl.length; i++){
			allChecked &= oEl[i].checked;
			if (!allChecked) return;
		};	
		var selAll = document.getElementById('selectAll');
		if (selAll) selAll.checked = true;
	};
};
	
function selectList(obj,mode,name){
    var oForm = obj.form;
    if(!oForm)return;
    var oEl = oForm[name];
    if(!oEl){			
        return;
    }
    var flag = obj.checked;
    if (!isArray(oEl)){
        //jesli zaznaczony jeden element
        oEl.checked = flag
        return;
    }
    for(var i=0; i<oEl.length; i++){
        oEl[i].checked  = flag;	
    };		
};

function waitForImage(image, counter) {
	var result = false;
	while (counter > 0) {
		if (image.complete) {
			result = true;
			break;
		}
		counter--;
	}
	return result;
};

function getImage(url) {
	var img = new Image();
	img.src = url;
	waitForImage(img, 5000);
	return img;
};

function openResource(id, name, type) {
	if (typeof(id) == "undefined") {
		return;
	}
	
	if (typeof(type) == "undefined") {
		type = 4;
	}
	
	var lcUrl = core.context + "/servlet/MainServlet?method=wbts.GetResource&mode=cms.resource&downloadMode=inline&id=" + id;
	openWin(lcUrl,300,300,1,1,"xxx");
};

function setEnabled(obj_name, value) {
	var obj = document.getElementById(obj_name);
	if (obj) {
		obj.disabled = !value;
	}
};


/**
base floating
author: jk
*/
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}else if (obj.x){
		curleft += obj.x;
	};
	return curleft;
};

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		};
	} else if (obj.y) {
		curtop += obj.y;
	};
	return curtop;
};

function makeFloatingDiv(border)
{
	if (!floatingWindow) {
		floatingWindow = new FLOATING_WINDOW(null, null, border);
	}
};

// parametry x, y, w, h przekazywane sa jako wartosc liczbowa z dolaczonym formatem, np.
// 50px, 100pt, 
function showFloatingDiv(x, y, w, h, ihtml)
{
	if (floatingWindow) {
		floatingWindow.show(null, ihtml, x, y, w, h);
	}
};

function hideFloatingDiv()
{
	if (floatingWindow) {
		floatingWindow.hide();
	}
};

/**
FLOATING_WINDOW object
author: jk
*/
FLOATING_WINDOW = function(name, content, border)
{
	this.visible = false;
	this.fw = null;
	this.name = name || "__floatingWindow";
	this.content = content || "";
	this.border = border || null;
	
	this.init();
};

FLOATING_WINDOW.prototype.init = function()
{
	this.fw = document.getElementById(this.name);
	if (!this.fw) {
		var fwstr = '<div id="' + this.name + '" style="visibility: hidden; position:absolute; left:0px; top:0px; width: 500px; height: 50px; background-color: #FFFFFF;';
		fwstr += (this.border) ? this.border : 'border: solid 1px #716F64;';
		fwstr += 'overflow: auto;">' + this.content + '</div>';
		if (document.all) {
			document.body.insertAdjacentHTML("beforeEnd", fwstr);
		} else {
			var rng = document.body.ownerDocument.createRange();
			rng.setStartBefore(document.body);
			var obj = rng.createContextualFragment(fwstr);
			document.body.appendChild(obj);
		}
		this.fw = document.getElementById(this.name);
	}
};

FLOATING_WINDOW.prototype.show = function(obj, ihtml, x, y, w, h)
{
	if (this.fw) {
		var ox = 0;
		var oy = 0;
		
		if (obj) {
			ox = findPosX(obj) + obj.offsetWidth - 10;
			oy = findPosY(obj) + obj.offsetHeight - 10;
		}
		
		if (typeof(x) == "undefined" || x == null) { x = ox + "px"; }
		if (typeof(y) == "undefined" || y == null) { y = oy + "px"; }
		if (typeof(w) == "undefined" || w == null) { w = ""; }
		if (typeof(h) == "undefined" || h == null) { h = ""; }
		
		this.fw.style.left = x;
		this.fw.style.top = y;
		this.fw.style.width = w;
		this.fw.style.height = h;
		this.fw.style.visibility = "inherit";
		this.fw.innerHTML = ihtml;
		
		this.visible = true;
	}
};

FLOATING_WINDOW.prototype.hide = function()
{
	if (this.fw) {
		this.fw.innerHTML = "";
		this.fw.style.visibility = "hidden";
	}
	
	this.visible = false;
};

var floatingWindow = null;

function createFloatingWindow() {
	if (floatingWindow == null) {
		floatingWindow = new FLOATING_WINDOW();
	}
};

addFuncToRunOnLoad(createFloatingWindow);

/**
CALENDAR_FLOATING_WINDOW object
author: jk
*/
var CALENDAR_EVENT_NEW = 0;
var CALENDAR_EVENT_EDIT = 1;

CALENDAR_FLOATING_WINDOW = function(data)
{
	this.data = data || new Array();
	this.fw = new FLOATING_WINDOW("__calendarFloatingWindow");
	
	this.init();
};

CALENDAR_FLOATING_WINDOW.prototype.init = function()
{
	
};

CALENDAR_FLOATING_WINDOW.prototype.getItem = function(idx)
{
	if (idx < 0 || idx > this.data.length) {
		return null;
	}
	
	return this.data[idx];
};

CALENDAR_FLOATING_WINDOW.prototype.show = function(obj, idx)
{
	var item = this.getItem(idx);
	if (item == null) {
		return;
	}
	
	var ihtml = "ala ma kota";
	
	this.fw.show(obj, ihtml);
};

/**
AJAX object
author: jk
*/
var AJAX_GET = 0;
var AJAX_POST = 1;

AJAX = function(name)
{
	this.initialized = false;
	this.sendmethod = AJAX_GET;
	this.xmlhttp = null;
	this.params = new Array();
	
	this.onreadystatechange = function(response_text){};
	
	this.init();
};

AJAX.prototype.init = function()
{
	if (!this.initialized) {
		if (navigator.appName == "Microsoft Internet Explorer") {
			try {
				this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {
					this.xmlhttp = new XMLHttpRequest();
				}
			}
		} else {
			this.xmlhttp = new XMLHttpRequest(); // Mozilla, Safari, ...
			/*if (this.xmlhttp.overrideMimeType) {
				// Set type accordingly to anticipated content type.
				this.xmlhttp.overrideMimeType("text/xml");
				// this.xmlhttp.overrideMimeType("text/html");
			}*/
		}
	}
};

AJAX.prototype.reset = function()
{
	this.params = new Array();
};

AJAX.prototype.addListner = function(name, obj)
{
	if (name == "onreadystatechange") {
		this.onreadystatechange = obj;
	}
};

AJAX.prototype.addParam = function(name, value)
{
	var param = {"name" : name, "value" : value};
	this.params[this.params.length] = param;
};

AJAX.prototype.removeParam = function(name)
{
	//
};

AJAX.prototype.request = function(control, sendmethod)
{
	this.sendmethod = (sendmethod) ? sendmethod : AJAX_GET;
	//lms patch
	if (typeof(core) == "undefined") {
		var url = mainApplicationServlet + "?method=wbts.GetContent&control=" + control;
	} else {
		var url = core.context + "/servlet/MainServlet?method=wbts.GetContent&control=" + control;
	}
	
	if (this.sendmethod == AJAX_POST) {
		var params = "";
		for (var i = 0; i < this.params.length; i++) {
			var param = this.params[i];
			if (params != "") params += "&";
			params += "&" + param.name + "=" + param.value;
		}
		
		this.xmlhttp.abort();
		this.xmlhttp.open("POST", url, true);
		this.xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		this.xmlhttp.setRequestHeader("Content-length", params.length);
		if (!window.document.all) {
			this.xmlhttp.setRequestHeader("Connection", "close");
		}
		this.xmlhttp.onreadystatechange = this.onreadystatechange;
		this.xmlhttp.send(params);
	} else {
		for (var i = 0; i < this.params.length; i++) {
			var param = this.params[i];
			url += "&" + param.name + "=" + param.value;
		}
		this.xmlhttp.abort();
		this.xmlhttp.open("GET", url, true);
		this.xmlhttp.onreadystatechange = this.onreadystatechange;
		this.xmlhttp.send(null);
	}
};

/**
POLLBOX_AJAX object
author: jk
*/
POLLBOX_AJAX = function(id)
{
	this.ajax = new AJAX();
	this.ajax.addListner("onreadystatechange", this.ajaxListner);
};

POLLBOX_AJAX.prototype.ajaxListner = function()
{
	// default empty
	alert("POLLBOX_AJAX: listner not defined");
};

POLLBOX_AJAX.prototype.addListner = function(listnerName, objListner)
{
	this.ajax.addListner(listnerName, objListner);
};

POLLBOX_AJAX.prototype.addVote = function(id_poll, vote)
{
	this.ajax.reset();
	this.ajax.addParam("id_poll", id_poll);
	this.ajax.addParam("vote", vote);
	this.ajax.addParam("component", "wbts.modules.cms.container.box.poll.PollBox");
	this.ajax.request("core.html.Component", AJAX_POST);
};

/**
NOTIFICATION_MANAGER object
author: jk
*/

var NM_AR_UNKNOWN = -1;
var NM_AR_UPDATE = 0;

var NM_BUTTON_NONE = -1;
var NM_BUTTON_OK = 0;
var NM_BUTTON_CANCEL = 1;
var NM_BUTTON_CLOSE = 2;
var NM_BUTTON_OKCANCEL = 10;
var NM_BUTTON_OKCLOSE = 11;

var notificationManager_enabled = true;

NOTIFICATION_MANAGER = function()
{
	this.notifications = new Array();
	this.ajax = new AJAX();
	this.ajax.addListner("onreadystatechange", this.ajaxListner);
	this.ajaxInProgress = false;
	
	this.serverDown = false;
	this.inProgress = false;
	this.overlay = this.createOverlay();
	//this.notification = this.createNotificationDIV();
	this.notification = document.getElementById('notification');
	this.activeNID = -1;
	this.activeNISS = false;
	
	this.enabled = notificationManager_enabled;
	
	//lms patch
	if (typeof(core) == "undefined") {
		this.timerInterval = (typeof(notificationTimerInterval) != "undefined") ? notificationTimerInterval : 120000;
	} else {
		this.timerInterval = core.settings.notificationTimerInterval;
	}
	if (isNaN(this.timerInterval)) {
		this.timerInterval = 120000;
	}
	this.timer = null;
	if (this.enabled) {
		this.onTimer();
	}
	
	//lms patch
	if (typeof(core) == "undefined") {
		this.lang_action_ok = notification_lang_action_ok;
		this.lang_action_cancel = notification_lang_action_cancel;
		this.lang_action_close = notification_lang_action_close;
	} else {
		this.lang_action_ok = core.lang.action_ok;
		this.lang_action_cancel = core.lang.action_cancel;
		this.lang_action_close = core.lang.action_close;
	}
};

NOTIFICATION_MANAGER.prototype.createOverlay = function()
{
	var overlay = document.createElement("div");
	overlay.setAttribute("id", "overlay");
	overlay.style.display = "none";
	
	var body = document.getElementsByTagName("body").item(0);
	if (body) body.appendChild(overlay);
	
	return document.getElementById("overlay");
};

NOTIFICATION_MANAGER.prototype.createNotificationDIV = function()
{
	/*var body = document.getElementsByTagName("body").item(0);
	if (!body) return;
	var notification = document.createElement("div");
	notification.setAttribute("id", "notification");
	notification.style.display = "none";*/
	/*notification.innerHTML = '<input type="hidden" id="notification_id" /><input type="hidden" id="notification_static" />'
		+'<div class="box_popup">'
		+'	<div class="box_popup_title_container">'
		+'		<div class="box_popup_arrow"></div>'		
		+'		<div class="box_popup_title"><span id="notification_title"></span></div>'
		+'	</div>'
		+'	<div class="box_popup_content"><span id="notification_content"></span></div>'		
		+'	<div class="box_popup_actions"><span id="notification_actions_bar"></span></div>'
		+'	<div class="box_popup_footer"></div>'
		+'</div>';*/
/*
	notification.innerHTML = '<input type="hidden" id="notification_id" />'
		+ '<input type="hidden" id="notification_static" />'
		+ '<table class="list" cellspacing="0" cellpadding="0" style="width:100%;">'
		+ '<tr class="box_header">'
		+ '<th width="99%"><span id="notification_title"></span></th>'
		+ '<th><div id="cancel_button" onclick="notificationManager.cancel();" /></div></th>'
		+ '</tr>'
		+ '<tr><td id="notification_content" class="box_menu_content" colspan="2"></td></tr>'
		+ '<tr>'
		+ '<td id="notification_actions_bar" class="box_menu_content" style="text-align: center;" colspan="2">'
		+ '</td>'
		+ '</tr>'
		+ '</table>';
	*/
	/*body.appendChild(notification);
	
	return document.getElementById("notification");*/
};

NOTIFICATION_MANAGER.prototype.showOverlay = function()
{
	if (this.overlay) {
		this.overlay.style.display = "";
	}
};

NOTIFICATION_MANAGER.prototype.hideOverlay = function()
{
	if (this.overlay) {
		this.overlay.style.display = "none";
	}
};

NOTIFICATION_MANAGER.prototype.showNotification = function()
{
	this.showOverlay();
	if (this.notification) {
		this.notification.style.display = "block";
	}
};

NOTIFICATION_MANAGER.prototype.hideNotification = function()
{
	this.hideOverlay();
	if (this.notification) {
		this.notification.style.display = "none";
	}
};

NOTIFICATION_MANAGER.prototype.onTimer = function()
{
	this.stopTimer();
	
	if (!this.enabled || this.serverDown) {
		return;
	}
	
	if (!this.ajaxInProgress) {
		this.ajaxInProgress = true;
		
		this.ajax.reset();
		this.ajax.addParam("type", "check");
		this.ajax.request("core.plain.Notification", AJAX_POST);
	}
	
	this.runTimer();
};

//static
NOTIFICATION_MANAGER.prototype.runTimer = function()
{
	this.stopTimer();
	this.timer = window.setTimeout('notificationManager.onTimer();', this.timerInterval);
};

NOTIFICATION_MANAGER.prototype.stopTimer = function()
{
	if (this.timer != null) {
		window.clearTimeout(this.timer);
		this.timer = null;
	}
};

//static
NOTIFICATION_MANAGER.prototype.ajaxListner = function(value)
{
	if (typeof(notificationManager) != "undefined" && notificationManager && notificationManager.ajax.xmlhttp.readyState == 4) {
		notificationManager.ajaxInProgress = false;
		if (notificationManager.ajax.xmlhttp.status == 0) {
			notificationManager.serverDown = true;
			return;
		}
		//alert("1::rstate: 4, http: " + notificationManager.ajax.xmlhttp.status);
		var rt = notificationManager.ajax.xmlhttp.responseText;
		if (parseInt(rt.charAt(0)) == NM_AR_UPDATE) {
			var nm = rt.split("##");
			for (var i = 0; i < nm.length; i++) {
				var obj = nm[i].split("$$");
				if (obj.length > 4) {
					notificationManager.addNotification(obj[1], obj[2], obj[3], obj[4], obj[5], obj[6]);
				}
			}
		}
	}
};

NOTIFICATION_MANAGER.prototype.getNotification = function(id)
{
	for (var i = 0; i < this.notifications.length; i++) {
		var obj = this.notifications[i];
		if (obj.id == id) {
			return obj;
		}
	}
	
	return null;
};

NOTIFICATION_MANAGER.prototype.getParamValue = function(params, action, def)
{
	if (typeof(params) == "undefined" || params == null || params == "") {
		return def;
	}
	
	var arr1 = params.split(",");
	for (var i = 0; i < arr1.length; i++) {
		var arr2 = arr1[i].split("=");
		if (arr2[0] == action) {
			return arr2[1];
		}
	}
	
	return def;
};

NOTIFICATION_MANAGER.prototype.addNotification = function(id, title, content, is_static, buttons, act_params)
{
	if (this.getNotification(id) || this.activeNID == id) {
		return;
	}
	
	var def_actions = {
		"ok" : "notificationManager.close();",
		"cancel" : "notificationManager.cancel();",
		"close" : "notificationManager.close();"
	}
	
	actions = new Object();
	actions.ok = this.getParamValue(act_params, "ok", def_actions.ok);
	actions.cancel = this.getParamValue(act_params, "cancel", def_actions.cancel);
	actions.close = this.getParamValue(act_params, "close", def_actions.close);
	
	var actions_bar = "";
	switch (parseInt(buttons)) {
		case NM_BUTTON_OK:
			actions_bar = '<input class="button" type="button" value="' + this.lang_action_ok + '" onclick="' + actions.ok + '">';
			break;
		case NM_BUTTON_CANCEL:
			actions_bar = '<input class="button" type="button" value="' + this.lang_action_cancel + '" onclick="' + actions.cancel + '">';
			break;
		case NM_BUTTON_CLOSE:
			actions_bar = '<input class="button" type="button" value="' + this.lang_action_close + '" onclick="' + actions.close + '">';
			break;
		case NM_BUTTON_OKCANCEL:
			actions_bar = '<input class="button" type="button" value="' + this.lang_action_ok + '" onclick="' + actions.ok + '">'
				+ '&nbsp;'
				+ '<input class="button" type="button" value="' + this.lang_action_cancel + '" onclick="' + actions.cancel + '">';
			break;
		case NM_BUTTON_OKCLOSE:
			actions_bar = '<input class="button" type="button" value="' + this.lang_action_ok + '" onclick="' + actions.ok + '">'
				+ '&nbsp;'
				+ '<input class="button" type="button" value="' + this.lang_action_close + '" onclick="' + actions.close + '">';
			break;
	}
	
	var obj = {
		"id" : id,
		"title" : title,
		"content" : content,
		"is_static" : is_static,
		"actions_bar" : actions_bar
	};
	
	this.notifications.push(obj);
	
	if (!this.inProgress) {
		this.callAwaitNotification();
	}
};

NOTIFICATION_MANAGER.prototype.callAwaitNotification = function()
{
	var obj = this.notifications.shift();
	if (obj) {
		this.open(obj);
	}
};

NOTIFICATION_MANAGER.prototype.open = function(obj)
{
	if (obj) {
		this.inProgress = true;
		this.activeNID = obj.id;
		this.activeNISS = obj.is_static;
		
		var cnt = document.getElementById("notification_id");
		cnt.value = obj.id;
		cnt = document.getElementById("notification_title");
		cnt.innerHTML = obj.title;
		cnt = document.getElementById("notification_content");
		cnt.innerHTML = obj.content;
		cnt = document.getElementById("notification_actions_bar");
		cnt.innerHTML = obj.actions_bar;
		cnt = document.getElementById("notification_static");
		cnt.value = obj.is_static;
		
		this.showNotification();
	}
};

NOTIFICATION_MANAGER.prototype.close = function(id, is_static)
{
	if (typeof(id) == "undefined") {
		id = this.activeNID;
	}
	if (typeof(is_static) == "undefined") {
		is_static = this.activeNISS;
	}
	
	this.ajaxInProgress = true;
	this.ajax.reset();
	this.ajax.addParam("id", id);
	this.ajax.addParam("is_static", is_static);
	this.ajax.addParam("type", "read");
	this.ajax.request("core.plain.Notification", AJAX_POST);
	
	this.hideNotification();
	this.inProgress = false;
	this.activeNID = -1;
	
	if (this.notifications.length > 0) {
		this.callAwaitNotification();
	}
};

NOTIFICATION_MANAGER.prototype.cancel = function()
{
	this.hideNotification();
	this.inProgress = false;
	this.activeNID = -1;
	
	if (this.notifications.length > 0) {
		this.callAwaitNotification();
	}
};

NOTIFICATION_MANAGER.prototype.enable = function()
{
	this.enabled = true;
};

NOTIFICATION_MANAGER.prototype.disable = function()
{
	this.enabled = false;
};

var notificationManager = null;

function createNotificationManager() {
	if (notificationManager == null) {
		notificationManager = new NOTIFICATION_MANAGER();
	}
};

function destroyNotificationManager() {
	if (notificationManager != null) {
		notificationManager.stopTimer();
	}
};

addFuncToRunOnLoad(createNotificationManager);
addFuncToRunOnUnLoad(destroyNotificationManager);

/**
DL_LIST object
description: js datalist
author: jk
*/
var DLT_FULL = 0;
var DLT_WITHOUT_HEADER = 1;

DL_LIST = function(name, separator, type)
{
	this.line_separator = (document.all) ? "\r\n" : "\n";
	this.name = name;
	this.separator = (separator) ? separator : "|";
	this.type = (type) ? type : DLT_FULL;
	this.columns = new Array();
	this.rows = new Array();
};

DL_LIST.prototype.addColumn = function(name, type, caption)
{
	if (typeof(caption) == "undefined" || caption == null || caption.length == 0) {
		return false;
	}
	name = (name) ? name : "c_" + this.columns.length;
	type = (type) ? type : "string";
	var column = {"name" : name, "type" : type, "caption" : caption};
	this.columns[this.columns.length] = column;
	
	return true;
};

DL_LIST.prototype.addRow = function(rowStr)
{
	if (typeof(rowStr) == "undefined" || rowStr == null || rowStr.length == 0) {
		return false;
	}
	var row = new Array();
	if (arguments.length > 1) {
		for (var i=0; i<this.columns.length; i++) {
			row[row.length] = arguments[i];
		}
	} else {
		var data = rowStr.split(this.separator);
		for (var i=0; i<this.columns.length; i++) {
			row[row.length] = data[i];
		}
	}
	
	this.rows[this.rows.length] = row;
	
	return true;
};

DL_LIST.prototype.flush = function()
{
	var found = true;
	while (found) {
		found = false;
		for (var i=0; i<this.rows.length; i++) {
			if (this.rows[i] == null) {
				this.rows.splice(i, 1);
				found = true;
				break;
			}
		}
	}
	
	var found = true;
	while (found) {
		found = false;
		for (var i=0; i<this.columns.length; i++) {
			if (this.columns[i] == null) {
				for (var j=0; j<this.rows.length; j++) {
					var row_obj = this.rows[j];
					row_obj.splice(i, 1);
				}
				this.columns.splice(i, 1);
				found = true;
				break;
			}
		}
	}
};

DL_LIST.prototype.getType = function(cell, def)
{
	var column = this.columns[cell];
	return column.type;
};

DL_LIST.prototype.getColumnObject = function(cell, def)
{
	var column = this.columns[cell];
	return column;
};

DL_LIST.prototype.setColumnObject = function(cell, mode, value)
{
	var column = this.columns[cell];
	switch (mode) {
		case "name":
			column.name = value;
			break;
		case "type":
			column.type = value;
			break;
		case "caption":
			column.caption = value;
			break;
	}
};

DL_LIST.prototype.getObject = function(row, cell, def)
{
	var row_obj = this.rows[row];
	if (row_obj[cell] == null || row_obj[cell] == "null") {
		return def;
	}
	return row_obj[cell];
};

DL_LIST.prototype.setObject = function(row, cell, value)
{
	var row_obj = this.rows[row];
	row_obj[cell] = value;
};

DL_LIST.prototype.loadFromString = function(source)
{
	if (typeof(source) == "undefined" || source == null || source.length == 0) {
		return;
	}
	
	var lines = source.split(this.line_separator);
	var ln1 = lines[0].split(this.separator);
	var ln2 = lines[1].split(this.separator);
	var ln3 = lines[2].split(this.separator);
	for (var i=0; i<ln1.length; i++) {
		this.addColumn(ln1[i], ln2[i], ln3[i]);
	}
	
	for (var i=3; i<lines.length; i++) {
		this.addRow(lines[i]);
	}
};

DL_LIST.prototype.toString = function()
{
	var ln1 = "";
	var ln2 = "";
	var ln3 = "";
	var result = "";
	if (this.columns.length == 0) {
		return result;
	}
	
	if (this.type != DLT_WITHOUT_HEADER) {
		for (var i=0; i<this.columns.length; i++) {
			var column = this.columns[i];
			if (ln1.length > 0) ln1 += this.separator;
			ln1 += column.name;
			if (ln2.length > 0) ln2 += this.separator;
			ln2 += column.type;
			if (ln3.length > 0) ln3 += this.separator;
			ln3 += column.caption;
		}
		result += ln1 + this.line_separator + ln2 + this.line_separator + ln3 + this.line_separator;
	}
	
	for (var i=0; i<this.rows.length; i++) {
		var row = this.rows[i];
		var row_str = "";
		for (var j=0; j<this.columns.length; j++) {
			if (j > 0) row_str += this.separator;
			row_str += (row[j]) ? row[j] : "";
		}
		result += row_str + this.line_separator;
	}
	return result;
};

DL_LIST.prototype.toHTML = function()
{
	var result = "<table>";
	result += '<tr>';
	for (var i=0; i<this.columns.length; i++) {
		var column = this.columns[i];
		result += '<th id="' + column.name + '">' + column.caption + '</th>';
	}
	result += '</tr>';
	var row_t = false;
	for (var i=0; i<this.rows.length; i++) {
		result += '<tr' + ((row_t) ? ' class="row_t"' : ' class="row_f"') + '>';
		var row = this.rows[i];
		for (var j=0; j<this.columns.length; j++) {
			result += '<td>' + ((row[j]) ? row[j] : "null") + '</td>';
		}
		if (this.editable) {
			result += '<td>&nbsp;</td>';
		}
		result += '</tr>';
		row_t = !row_t;
	}
	result += "</table>";
	
	return result;
};

/**
COOKIES object

description: cookies managment
author: jk
*/
COOKIES = function()
{
};

COOKIES.prototype.set = function(name, value, expires, path, domain, secure)
{
	var today = new Date();
	today.setTime(today.getTime());
	if (expires) {
		expires = expires * 1000 * 60 * 60 * 24;
		var expires_date = new Date(today.getTime() + (expires));
	}
	document.cookie = name + "=" + escape(value)
		+ ((expires) ? ";expires=" + expires_date.toGMTString() : "")
		+ ((path) ? ";path=" + path : "")
		+ ((domain) ? ";domain=" + domain : "")
		+ ((secure) ? ";secure" : "");
};

COOKIES.prototype.get = function(name)
{
	var start = document.cookie.indexOf(name + "=");
	var len = start + name.length + 1;
	if ((!start) && (name != document.cookie.substring(0, name.length))) return null;
	if (start == -1) return null;
	var end = document.cookie.indexOf(";", len);
	if (end == -1) end = document.cookie.length;
	return unescape(document.cookie.substring(len, end));
};

COOKIES.prototype.remove = function(name, path, domain)
{
	if (this.get(name)) {
		document.cookie = name + "="
			+ ((path) ? ";path=" + path : "")
			+ ((domain) ? ";domain=" + domain : "")
			+ ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	}
};

/**
FLOAT_FIELD object
description: float field
author: jk
*/
var _float_field = null;
var FF_RESULT_UNKNOWN = -1;
var FF_PREFIX		= "__ff_";
var FFT_UNDEFINED	= "undefined";
var FFT_IDENTIFIER	= "identifier";
var FFT_TEXT		= "text";
var FFT_MEMO		= "memo";
var FFT_NUMERIC		= "numeric";
var FFT_BOOLEAN		= "boolean";
var FFT_SELECT		= "select";
var FFT_DATE		= "date";
var FFT_DATETIME	= "datetime";
var FFT_DL_FORMAT	= "datalistformat";
var FFT_POSTCODE	= "postcode";

FLOAT_FIELD = function(obj, type, name, value, params)
{
	_float_field = this;
	this.obj = obj;
	this.type = (type) ? type : FFT_UNDEFINED;
	this.name = name;
	this.value = (value) ? value : "";
	this.params = (params) ? params : new Object();
	this.x = 0;
	this.y = 0;
	
	this.ff = new FLOATING_WINDOW("__floatField", "", "border:0px;");
	
	if (obj) {
		this.y = findPosY(obj);
		if (this.params.offsetTop) this.y += this.params.offsetTop;
		this.x = findPosX(obj);
		if (this.params.offsetLeft) this.x += this.params.offsetLeft;
	}
	
	switch (type) {
		case FFT_DL_FORMAT:
		case FFT_BOOLEAN:
			this.params.style = (this.params.style) ? this.params.style : "width:" + (obj.offsetWidth) + "px";
			break;
		case FFT_DATE:
		case FFT_DATETIME:
			this.params.style = (this.params.style) ? this.params.style : "width:" + (obj.offsetWidth - 30) + "px";
			break;
		case FFT_MEMO:
			this.params.style = (this.params.style) ? this.params.style : "width:" + (obj.offsetWidth - 2) + "px";
			break;
		case FFT_NUMERIC:
		case FFT_TEXT:
		case FFT_IDENTIFIER:
		default:
			this.params.style = (this.params.style) ? this.params.style : "width:" + (obj.offsetWidth - 2) + "px";
	}
	
	this.html = this.initHTML(this.name, this.type, this.value, this.params);
};

FLOAT_FIELD.prototype.checkKey = function(e, key)
{
	var characterCode;
	if (e && e.which) {
		e = e;
		characterCode = e.which;
	} else {
		e = event;
		characterCode = e.keyCode;
	}
	
	if (characterCode == key) {
		return true;
	}
	
	return false;
};

FLOAT_FIELD.prototype.checkEnter = function(e)
{
	return this.checkKey(e, 13);
};

FLOAT_FIELD.prototype.checkEscape = function(e)
{
	return this.checkKey(e, 27);
};

FLOAT_FIELD.prototype.fnOnKeyDown = function(e)
{
	if (this.checkEscape(e)) {
		this.hide();
		return;
	}
	if (!this.checkEnter(e)) {
		return;
	}
	if (!this.params.submit) {
		alert("FLOAT_FIELD Internal error. Wrong component initialization: Function \"submit\" is not defined in \"params\" Object.");
		return;
	}
	
	if (!this.check()) {
		switch (this.type) {
			case FFT_DATE:
			case FFT_DATETIME:
				alert(core.lang.float_field_check_wrong_date_format);
				break;
			case FFT_NUMERIC:
				alert(core.lang.float_field_check_wrong_numeric_format);
				break;
			default:
				alert(core.lang.float_field_check_wrong_data_format);
		}
		return;
	}
	this.params.submit(this.obj, this.value, this.type);
	this.hide();
};

FLOAT_FIELD.prototype.fnOnBlur = function(e)
{
	if (!this.params.submit) {
		alert("FLOAT_FIELD Internal error. Wrong component initialization: Function \"submit\" is not defined in \"params\" Object.");
		return;
	}
	
	if (!this.check()) {
		switch (this.type) {
			case FFT_DATE:
			case FFT_DATETIME:
				alert(core.lang.float_field_check_wrong_date_format);
				break;
			case FFT_NUMERIC:
				alert(core.lang.float_field_check_wrong_numeric_format);
				break;
			default:
				alert(core.lang.float_field_check_wrong_data_format);
		}
		return;
	}
	this.params.submit(this.obj, this.value, this.type);
	this.hide();
};

FLOAT_FIELD.prototype.initHTML = function(name, type, value, params)
{
	var result = "";
	switch (type) {
		case FFT_DL_FORMAT:
			result = '<select style="' + params.style + '" id="' + FF_PREFIX + name + '" onkeydown="_float_field.fnOnKeyDown(event);">';
			result += '<option value="...">' + core.lang.dltype_undefined  + '</option>';
			result += '<option value="string"' + ((value == "string") ? " selected" : "") + '>' + core.lang.dltype_string  + '</option>';
			result += '<option value="memo"' + ((value == "memo") ? " selected" : "") + '>' + core.lang.dltype_memo  + '</option>';
			result += '<option value="boolean"' + ((value == "boolean") ? " selected" : "") + '>' + core.lang.dltype_boolean  + '</option>';
			result += '<option value="date"' + ((value == "date") ? " selected" : "") + '>' + core.lang.dltype_date  + '</option>';
			result += '<option value="select"' + ((value == "select") ? " selected" : "") + '>' + core.lang.dltype_select  + '</option>';
			result += '<option value="numeric"' + ((value == "numeric") ? " selected" : "") + '>' + core.lang.dltype_numeric  + '</option>';
			result += '<option value="nip"' + ((value == "nip") ? " selected" : "") + '>' + core.lang.dltype_nip  + '</option>';
			result += '<option value="pesel"' + ((value == "pesel") ? " selected" : "") + '>' + core.lang.dltype_pesel  + '</option>';
			result += '<option value="email"' + ((value == "email") ? " selected" : "") + '>' + core.lang.dltype_email  + '</option>';
			result += '<option value="postcode"' + ((value == "postcode") ? " selected" : "") + '>' + core.lang.dltype_kod  + '</option>';
			result += '</select>';
			break;
		case FFT_BOOLEAN:
			result = '<select style="' + params.style + '" id="' + FF_PREFIX + name + '" onkeydown="_float_field.fnOnKeyDown(event);" onblur="_float_field.fnOnBlur(event);" >';
			result += '<option value="0"' + ((value == 0) ? " selected" : "") + '>' + core.lang.dltype_boolean_0  + '</option>';
			result += '<option value="1"' + ((value == 1) ? " selected" : "") + '>' + core.lang.dltype_boolean_1  + '</option>';
			result += '</select>';
			break;
		case FFT_DATE:
			result = '<input type="text" style="' + params.style + '" id="' + FF_PREFIX + name + '" value="' + value + '" onkeydown="_float_field.fnOnKeyDown(event);"/>';
			result += '<input class="button" type="button" onclick="showCalendar(\'' + FF_PREFIX + name + '\', \'%Y-%m-%d\', \'24\', true);" value="..." onblur="_float_field.fnOnBlur(event);" />';
			break;
		case FFT_DATETIME:
			result = '<input type="text" style="' + params.style + '" id="' + FF_PREFIX + name + '" value="' + value + '" onkeydown="_float_field.fnOnKeyDown(event);"/>';
			result += '<input class="button" type="button" onclick="showCalendar(\'' + FF_PREFIX + name + '\', \'%Y-%m-%d %H:%M\', \'24\', true);" value="..." onblur="_float_field.fnOnBlur(event);" />';
			break;
		case FFT_MEMO:
			result = '<textarea style="' + params.style + '" id="' + FF_PREFIX + name + '" value="' + value + '" onkeydown="_float_field.fnOnKeyDown(event);"></textarea>';
			break;
		case FFT_NUMERIC:
		case FFT_TEXT:
		case FFT_IDENTIFIER:
		default:
			result = '<input type="text" style="' + params.style + '" id="' + FF_PREFIX + name + '" value="' + value + '" onkeydown="_float_field.fnOnKeyDown(event);" onblur="_float_field.fnOnBlur(event);" />';
	}
	
	return result;
};

FLOAT_FIELD.prototype.show = function()
{
	this.ff.show(null, this.html, this.x + "px", this.y + "px", "", "");
	document.getElementById(FF_PREFIX + this.name).focus();
	document.getElementById(FF_PREFIX + this.name).value = document.getElementById(FF_PREFIX + this.name).value;
};

FLOAT_FIELD.prototype.hide = function()
{
	this.ff.hide();
};

FLOAT_FIELD.prototype.check = function()
{
	this.value = document.getElementById(FF_PREFIX + this.name).value;
	switch (this.type) {
		case FFT_DL_FORMAT:
			return this.value != "...";
			break;
		case FFT_BOOLEAN:
			return (this.value == 1 || this.value == 0);
			break;
		case FFT_DATE:
		case FFT_DATETIME:
			return isDate(this.value);
			break;
		case FFT_NUMERIC:
			return !isNaN(this.value);
		case FFT_IDENTIFIER:
			var result = FF_RESULT_UNKNOWN;
			if (this.u_check) {
				result = this.u_check(this.type, this.value);
				if (result != FF_RESULT_UNKNOWN) {
					return result;
				}
			}
			if (!isNaN(this.value.charAt(0)) || this.value.replace(/\w+/g, "") != "") {
				return false;
			}
			return true;
			break;
		case FFT_TEXT:
		case FFT_MEMO:
		default:
			return (this.value.replace(/\|/g, "") == this.value);
	}
	return false;
};

/**
FLOAT_FIELD date, datetime check section
*/
var dtCh = "-"; //%Y-%m-%d %H:%M
var minYear = 1900;
var maxYear = 2100;

function isInteger(s) {
	return !isNaN(s);
};

function stripCharsInBag(s, bag) {
	var result = "";
	// Search through string's characters one by one.
	// If character is not in bag, append to returnString.
	for (var i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1) result += c;
	}
	return result;
};

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
	// EXCEPT for centurial years which are not also divisible by 400.
	return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28);
};

function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31;
		if (i == 4 || i == 6 || i == 9 || i == 11) {
			this[i] = 30;
		}
		if (i == 2) {
			this[i] = 29;
		}
	}
	return this;
};

function isDate(dtStr) {
	// %Y-%m-%d %H:%M
	// mm/dd/yyyy
	var daysInMonth = DaysArray(12);
	var pos1 = dtStr.indexOf(dtCh);
	var pos2 = dtStr.indexOf(dtCh, pos1 + 1);
	var strYear = dtStr.substring(0, pos1);
	var strMonth = dtStr.substring(pos1 + 1, pos2);
	var strDay = dtStr.substring(pos2 + 1);
	strYr = strYear;
	if (strDay.charAt(0) == "0" && strDay.length > 1) strDay = strDay.substring(1);
	if (strMonth.charAt(0) == "0" && strMonth.length > 1) strMonth = strMonth.substring(1);
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0) == "0" && strYr.length > 1) strYr = strYr.substring(1);
	}
	month = parseInt(strMonth);
	day = parseInt(strDay);
	year = parseInt(strYr);
	if (pos1 == -1 || pos2 == -1) {
		return false;
	}
	if (strMonth.length < 1 || month < 1 || month > 12) {
		return false;
	}
	if (strDay.length < 1 || day < 1 || day > 31 || (month == 2 && day > daysInFebruary(year)) || day > daysInMonth[month]) {
		return false;
	}
	if (strYear.length != 4 || year < minYear || year > maxYear) {
		return false;
	}
	if (dtStr.indexOf(dtCh, pos2 + 1) !=- 1 || !isInteger(stripCharsInBag(dtStr, dtCh))) {
		return false;
	}
	return true;
};

function doSearch(location){
	var searchParam = document.getElementById("search").value;
	var params = "&name="+searchParam+"&location=&subject=&keywords=&type=%2D1&participation_type=%2D1";
	document.location.href=location+params;
}

function showOverlay() {
	var overlay = document.getElementById("overlay");
	if (overlay) {
		overlay.style.display = "";
	}
};

function hideOverlay() {
	var overlay = document.getElementById("overlay");
	if (overlay) {
		overlay.style.display = "none";
	}
};

function showHideDiv(imgObj, divObj, icoCollapse, icoExpand, imgPathArr) {
	if (divObj.style.display == "none"){
		divObj.style.display = "block";
		imgPathArr[imgPathArr.length-1] = icoCollapse;		
	}else{
		divObj.style.display = "none";
		imgPathArr[imgPathArr.length-1] = icoExpand;
	}
	if (imgObj) imgObj.src = imgPathArr.join('/');
}
function showHideDivById(divId) {
	var divObj = document.getElementById(divId);
	if (divObj.style.display == "none"){
		divObj.style.display = "block";
	}else{
		divObj.style.display = "none";
	}
}

function showSubMenu(e, subMenuId, icoId, ce_key) {
	
	var subMenu = document.getElementById(subMenuId);
	var img = document.getElementById(icoId);
	if (img) imgPathArr = img.src.split('/');
	
	if (subMenu) {
		showHideDiv(img, subMenu, 'menuCollapse.png', 'menuExpand.png', imgPathArr);
		var ceAjax = new AJAX();
		ceAjax.addListner("onreadystatechange", empty_listen);
		if (subMenu.style.display == "none"){
			sendInformationWithAjax(subMenuId, false, ce_key, ceAjax);
		}
		else {
			sendInformationWithAjax(subMenuId, true, ce_key, ceAjax);
		}		
	};
	e.cancelBubble = true;
};

function collapseExpandBox(e, subMenuId, icoId, ce_key) {
	var subMenu = document.getElementById("content"+subMenuId);
	var img = document.getElementById("ico"+icoId);
	var imgPathArr = new Array();
	if (img) imgPathArr = img.src.split('/');
	if (subMenu) {
		showHideDiv(img, subMenu, 'icon_collapse.gif', 'icon_expand.gif', imgPathArr);
		if (document.getElementById(subMenuId)) {
			if (subMenu.style.display == "none"){
				document.getElementById(subMenuId).className="box_menu_title";
			}else{
				document.getElementById(subMenuId).className="box_menu_title_active";
			}
		}

		var ceAjax = new AJAX();
		ceAjax.addListner("onreadystatechange", empty_listen);
		if (subMenu.style.display == "none"){
			sendInformationWithAjax("content"+subMenuId, false,ce_key,ceAjax);
		}
		else {
			sendInformationWithAjax("content"+subMenuId, true,ce_key, ceAjax);
		}
	};
	e.cancelBubble = true;
}

function empty_listen(){
}

function sendInformationWithAjax(id_obj, is_show, key, ceajax){

 	objlist = document.getElementById(id_obj);
	ceajax.reset();	
	ceajax.addParam("key", key);
	ceajax.addParam("id_obj", id_obj);
	ceajax.addParam("showList", is_show);
	ceajax.request("collapse_expand_list", AJAX_POST);
}	

var filterSuggest = null;
var thisfilterObj = null;

function autoSearch(liObjName, objName, formName, liObjId){	
	var input = document.getElementById(objName);
	var hide = document.getElementById("id_value");
	if (input) {
		if (liObjId != 0){
			input.value = liObjName.innerHTML;		
		} else {
			input.value = "";
		}
		
	}
	if (hide){
		hide.value = liObjId;
	}
	/*	
	if (liObjId != null)
			{
				elem = document.createElement('Input')
				elem.setAttribute('type', 'hidden');
				elem.setAttribute('value', liObjId);
				elem.setAttribute('name', thisfilterObj.ObjectName);
				elem.setAttribute('id', thisfilterObj.ObjectName);
				// uwaga poprawic wyciagane odpowiedniego formularza (teraz brane po indeksie narazie dziala)				
				document.forms[0].appendChild(elem);				
				//alert('utworzono');					
				} 
	*/
	
	var form = document.getElementById(formName);
	if (form) form.submit();
};	


function getSuggest(e, obj, filterObj) {
	//kr
	//work stopped
	//return;	
	var hide = document.getElementById("id_value");
	
	if (hide){
		hide.value = obj.value;
	}	
	
	e = (e) ? e : event;
	
	if (e.keyCode == 16) return;
		
	
	if (filterSuggest == null) {
		filterSuggest = new FILTER_SUGGEST_MANAGER(obj);
	}
				
	filterSuggest.stopTimer();
	thisfilterObj = filterObj;
	filterSuggest.timer = window.setTimeout('filterSuggest.onTimer();', 500);
	
		
};

FILTER_SUGGEST_MANAGER = function(obj)
{
	this.ceAjax = new AJAX();
	this.ceAjax.addListner("onreadystatechange", this.writeSuggest);	
	this.input = obj;
	this.keyword = "";
	this.floatingDiv = null;
	this.timer = null;
}

FILTER_SUGGEST_MANAGER.prototype.stopTimer = function()
{
	if (this.timer != null) {
	 if (this.ceAjax.xmlhttp != null)
				this.ceAjax.xmlhttp.abort();
				
		window.clearTimeout(this.timer);
		this.timer = null;
	}
}

FILTER_SUGGEST_MANAGER.prototype.onTimer = function()
{
	if (this.input.value != "") {
		filterSuggest.sendRequest(this.input.value);
	}else{
		if (filterSuggest.floatingDiv) {
			filterSuggest.floatingDiv.hide();
		}
	}
}
FILTER_SUGGEST_MANAGER.prototype.sendRequest = function(keyWord)
{	
	this.ceAjax.reset();	

	if (thisfilterObj.additionalFilter){
		var addFilterArr = thisfilterObj.additionalFilter.split('#');
		var arr = "";
		for (var i=0; i < addFilterArr.length; i++){
			arr = addFilterArr[i].split(":");
			if (this.input.id == arr[0]) continue;
			var obj = document.getElementById(arr[0]);
			if (obj){
				this.ceAjax.addParam("filterNumber", obj.value);
				this.addParam("key", arr[1]);
				break;
			}
		}
	}else{
		this.ceAjax.addParam("key", thisfilterObj.filterType);
	}
	if (thisfilterObj.filterAssigned){
		this.ceAjax.addParam("filterAssigned", thisfilterObj.filterAssigned);
	}
	this.ceAjax.addParam("paramSearchUser", keyWord);	
	this.ceAjax.addParam("idTraining", thisfilterObj.idTraining);						  	
	this.ceAjax.request("getSuggestFilter", AJAX_POST);
}

FILTER_SUGGEST_MANAGER.prototype.writeSuggest = function()
{	
	if (typeof(filterSuggest) != 'undefined' && filterSuggest.ceAjax.xmlhttp.readyState == 4) {		
		var responseText = filterSuggest.ceAjax.xmlhttp.responseText;		
		responseText = responseText.split('#');
		var optionsStr = "";
			
		var content =  responseText[0];
			
		// alert(responseText[0]);
		if (typeof(responseText[1]) != 'undefined') {
			
			content += '<ul>';
			optionsStr += responseText[1].replace(/\|/ig, '<li style="cursor:pointer;" onclick="autoSearch(this, \'' + filterSuggest.input.id + '\', \'' + thisfilterObj.formName);
			//+ '\');">'
			content += optionsStr.replace(/\^/ig, '</li>');
			content += '</ul>';			
		}
		
		
		if (!filterSuggest.floatingDiv) {
			filterSuggest.floatingDiv = new FLOATING_WINDOW("filterSuggest", null, "border: 1px solid #d2d2d2;");
		};
		var x = findPosX(filterSuggest.input) + 'px';
		var y = findPosY(filterSuggest.input) + filterSuggest.input.offsetHeight + 'px';
		var w = '300px';
		if (content.length > 0){
			filterSuggest.floatingDiv.show(filterSuggest.input, content, x, y, w, null);		
		}
		
	}
		
}

function getTimeStringFromMillis(durationTime){
	var timeStr = "";
	var hour = 0;
	var min = 0;
	var sec = 0;
	
	hour = Math.floor(durationTime / (1000 * 60 * 60));
	if (hour < 10) {
		timeStr = "0" + hour + ":";
	} else {
		timeStr = hour + ":";
	}
	durationTime = durationTime - (hour * 1000 * 60 * 60);
	
	min = Math.floor(durationTime / (1000 * 60));
	if (min < 10) {
		timeStr += "0" + min + ":";
	} else {
		timeStr += min + ":";
	}
	durationTime = durationTime - (min * 1000 * 60);
}

function formatTime(hour, minute, second){
  if (hour<10){
    hour = "0"+hour;
  }
  if (minute<10){
    minute = "0"+minute;
  }
  if (second<10){
    second = "0"+second;
  }
  return hour+":"+minute+":"+second;
}

function formatTimeShort(hour, minute){
  if (hour<10){
    hour = "0"+hour;
  }
  if (minute<10){
    minute = "0"+minute;
  }
  return hour+":"+minute;
}

function getTimeFormSeconds(seconds){
    seconds = Math.round(seconds);
    hour = Math.floor(seconds / 3600);
    min = Math.floor((seconds - (hour * 3600)) / 60);
    sec = seconds - (hour * 3600) - (min * 60);
    return formatTimeShort(hour,min,sec);
}

