var urlForLoad = '';
var timerCheckUrl = null;
var wikiBlameBox 	    = null;
var wikiBlameAddress 	= null;
var wikiBlameFlag 		= null;
var wikiBlameText 		= null;
var paramsForLoad 		= null;



function wiki_draw_button(place_id,event_type,event_parent_id,obj,obj_parent_id,obj_id,page_no) {
	
	var main_panel = document.getElementById(place_id);
	if (main_panel == null) {
		return;	
	}

	var page_no_param = '';	
	if (page_no !== null) {
		page_no_param = '&n='+page_no;	
	}
    
	var nm = 'e_'+event_type+'_'+obj+'_'+obj_parent_id+'_'+obj_id;
	var panel_show = document.getElementById(nm);
	panel_show = isPanel_show = (panel_show != null) ? 1 : 0;
	   
	main_panel.innerHTML +=  '&nbsp;<img border=1 style="cursor:pointer;" src="images/wiki/tool_'+event_type+'.gif"'+
' onclick=\'centerWin("",500,500,"yes","yes","'+main_url+'/wiki_add_event.php?redraw='+panel_show+'&event_type='+event_type+'&e_parent='+event_parent_id+'&obj='+obj+'&obj_parent_id='+obj_parent_id+'&obj_id='+obj_id+page_no_param+'");\' />';
		main_panel.style.visibility = 'visible';

}


function mb_loadUrl()
{
	if(typeof(urlForLoad) == 'string' && urlForLoad.length > 0) { 
		clearInterval(timerCheckUrl);
		timerCheckUrl = null;
		var p_urlForLoad = urlForLoad;
		urlForLoad = '';
	var whb = document.getElementById('wiki_hidden_box');
	if (wikiBlameBox != null && typeof(wikiBlameBox) != 'undefined' && wikiBlameBox.parentNode != whb) { 
		whb.appendChild(wikiBlameBox);	
	} 
		httpXmlShell.LoadUrl( p_urlForLoad, wiki_draw_events);	
	}
}


function wiki_draw_link(place_id,tool_type,event_parent_id,obj,obj_parent_id,obj_id,isPanel_show,page_no,link_text) {
	
	var main_panel = document.getElementById(place_id);

	if (main_panel == null) {
		return;	
	}
	var page_no_param = '';	
	if (page_no !== null) {
		page_no_param = '&n='+page_no;	
	}
	main_panel.innerHTML += '<a href="#" onclick=\'centerWin("",500,500,"yes","yes","'+main_url+'/wiki_add_event.php?redraw='+isPanel_show+'&event_type='+tool_type+'&e_parent='+event_parent_id+'&obj='+obj+'&obj_parent_id='+obj_parent_id+'&obj_id='+obj_id+page_no_param+'"); return false;\' >'+ link_text+'</a>';
		
		main_panel.style.visibility = 'visible';
}

function wiki_draw_events(result) {
	
	if (httpXmlShell.CheckError(result) != 0 || paramsForLoad == null) {
		return;
	} 

	var boxes = httpXmlShell.SelectNodes( 'container/boxId' ) ;
	if (boxes == null) {
		//alert('Otrava wiki_tools.js row: 102  :: ERROR boxId=null');
		return;
	}
	var initSuccess = false;
	for (var i = 0; i < boxes.length; i++)
	{
		var box = boxes[i];
		boxId = box.attributes.getNamedItem('id').value;
		var container = document.getElementById(boxId); 
		if (container != null) {
			 initSuccess = true;
			//var oNodes = httpXmlShell.SelectSingleNode( 'container/items' ) ;
			if (box.childNodes[0] != null) {
				if (bIsIE && typeof(box.childNodes[0].text) == 'string' && box.childNodes[0].text.length > 0) { 
					container.innerHTML = box.childNodes[0].text;
				} else if (typeof(box.childNodes[0].textContent) == 'string' && box.childNodes[0].textContent.length > 0) {	
					container.innerHTML = box.childNodes[0].textContent;
				}
			}
			
			//var oScriptNodes = httpXmlShell.SelectSingleNode( 'container/script_section' ) ;
			if (box.childNodes[1] != null){
				if (bIsIE && box.childNodes[1].text != null && box.childNodes[1].text.length > 0) {
					//container.innerText += box.childNodes[1].text;
						eval(box.childNodes[1].text);
						
				} else if (box.childNodes[1].textContent != null && box.childNodes[1].textContent.length > 0) { 
				
				//container.innerText = box.childNodes[1].textContent;
						eval(box.childNodes[1].textContent);
				}
			}
		}
	
	}
	if (initSuccess == true) {
    	timerCheckUrl = setInterval(mb_loadUrl,250);
	}
}


function initShowEvents()
{
	//alert('Otrava DEBUG: functin initShowEvents call');	
	if (typeof(arUserFlags) == 'object') {
		wikiBlameBox 	    = document.getElementById('wiki_blame_box');
		wikiBlameAddress 	= document.getElementById('wiki_blame_address');
		wikiBlameFlag 		= document.getElementById('wiki_blame_n_flag');
		wikiBlameText 		= document.getElementById('wiki_blame_text');
		if (wikiBlameFlag != null) {
			for (n_id in arUserFlags) {
				addOption(wikiBlameFlag,n_id,arUserFlags[n_id],false);
			}
		}
	} else {
		//alert('Otrava wiki_tools.js row:127 DEBUG: arUserFlags = null');		
	}

	if (httpXmlShell == null || paramsForLoad == null || typeof(paramsForLoad) == 'undefined') {
		return;
	}

	httpXmlShell.LoadUrl( main_url+'/'+'wiki_show_events.php', wiki_draw_events,'POST','param='+paramsForLoad);					  
	
}

function initShowArticles()
{
	//alert('Otrava DEBUG: functin initShowArticles call');	

	//alert('Otrava paramsForLoad: '+paramsForLoad);
	
	if (httpXmlShell == null || paramsForLoad == null || typeof(paramsForLoad) == 'undefined') {
		return;
	}

	httpXmlShell.LoadUrl( main_url+'/'+'wiki_show_articles.php', wiki_draw_events,'POST','param='+paramsForLoad);					  
	
}


function initShowTutorials()
{
	//alert('Otrava DEBUG: functin initShowTutorials call');	

	//alert('Otrava paramsForLoad: '+paramsForLoad);
	
	if (httpXmlShell == null || paramsForLoad == null || typeof(paramsForLoad) == 'undefined') {
		return;
	}

	httpXmlShell.LoadUrl( main_url+'/'+'wiki_show_tutorials.php', wiki_draw_events,'POST','param='+paramsForLoad);					  
	
}


function initShowComments()
{
	//alert('Otrava DEBUG: functin initShowTutorials call');	

	//alert('Otrava paramsForLoad: '+paramsForLoad);
	if (typeof(arUserFlags) == 'object') {
		wikiBlameBox 	    = document.getElementById('wiki_blame_box');
		wikiBlameAddress 	= document.getElementById('wiki_blame_address');
		wikiBlameFlag 		= document.getElementById('wiki_blame_n_flag');
		wikiBlameText 		= document.getElementById('wiki_blame_text');
		if (wikiBlameFlag != null) {
			for (n_id in arUserFlags) {
				addOption(wikiBlameFlag,n_id,arUserFlags[n_id],false);
			}
		}
	} else {
		//alert('Otrava wiki_tools.js row:127 DEBUG: arUserFlags = null');		
	}
	
	if (httpXmlShell == null || paramsForLoad == null || typeof(paramsForLoad) == 'undefined') {
		return;
	}

	httpXmlShell.LoadUrl( main_url+'/'+'wiki_show_comments.php', wiki_draw_events,'POST','param='+paramsForLoad);					  
	
}




function wiki_getUserFlagForm(boxId)
{
	//alert('Otrava function wiki_getUserFlagForm call');
	var box = document.getElementById(boxId);
	if (box == null) { 
		//alert('Otrava : box = null');
		return;
	}
	
	if (wikiBlameBox == null) {
		//alert('Otrava : wikiBlameBox = null');
		return;	
	}
	

		
	//wikiBlameAddress.value = '';
	//wikiBlameFlag.value = -1;												
	//wikiBlameText.value = '';
	
	wikiBlameBox.identify = boxId;		
	
	wikiBlameBox.style.display = 'none';
	box.appendChild(wikiBlameBox);
	$("#"+'wiki_blame_box').show("slow");	

}

function wiki_sendUserFlag()
{ 
	if (wikiBlameBox == null) {
		//alert('Otrava wikiBlameBox = null');
		return;
	}
	
	if (wikiBlameFlag.value == -1) {
		//alert('Otrava wikiBlameFlag.value = -1');
		return;
	}
	
	if (wikiBlameAddress.value.length == 0) {
		alert('e-mail address is empty');
		return;
	}
	
	if (checkmail(wikiBlameAddress.value) == true) {
		alert('e-mail address not correct');
		return;
	} 
	
	if (wikiBlameFlag.value == 9 && wikiBlameText.value.length == 0) {
		alert('Comment is empty');
		return;
	}
	
	var whb = document.getElementById('wiki_hidden_box');
	if (wikiBlameBox.parentNode != whb) { 
		whb.appendChild(wikiBlameBox);	
	}
	$("#"+wikiBlameBox.identify).hide("slow");
	document.getElementById(wikiBlameBox.identify).style.display = 'none';
	httpXmlShell.LoadUrl( main_url+'/'+'wiki_add_user_flag.php', wiki_flag_added,'POST','ident='
						 													+wikiBlameBox.identify
																			+'&address='+wikiBlameAddress.value
																			+'&n_flag='+wikiBlameFlag.value
																			+'&comment='+wikiBlameText.value);
}

function hideBlameWnd()
{
	var whb = document.getElementById('wiki_hidden_box');
	if (wikiBlameBox.parentNode != whb) { 
		whb.appendChild(wikiBlameBox);	
	}
}


function wiki_flag_added(result) {

	if (httpXmlShell.CheckError(result) != 0) {
		return;
	} 

	var boxes = httpXmlShell.SelectNodes( 'container/boxId' ) ;
	if (boxes == null) {
		alert('wiki_tools.js row: 102  :: ERROR boxId=null');
		return;
	}
	var initSuccess = false; 
	for (var i = 0; i < boxes.length; i++)
	{
		var box = boxes[i];
		boxId = box.attributes.getNamedItem('id').value;
		var container = document.getElementById(boxId);
	
		if (container != null) { 			
			 initSuccess = true;
			if (box.childNodes[0] != null) {
				if (bIsIE && typeof(box.childNodes[0].text) == 'string' && box.childNodes[0].text.length > 0) { //alert(box.childNodes[0].text);
					container.innerHTML = box.childNodes[0].text; 
				} else if (typeof(box.childNodes[0].textContent) == 'string' && box.childNodes[0].textContent.length > 0) {	
					container.innerHTML = box.childNodes[0].textContent;
				}
			} 

			$("#"+container.id).show("slow");
		}
	
	} 
	if (initSuccess == true) {
    	timerCheckUrl = setInterval(mb_loadUrl,250);
	}
}




























