function CreateXmlHttp()
{
	var xmlHttp = null;

	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	try{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP")
	}catch (e){
		try{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP")
		}catch (E){
		}
	}
	@else
	@end @*/
	if (xmlHttp == null) {
		try{
			xmlHttp = new XMLHttpRequest();
		}catch (e){
		}
	}
	return xmlHttp;
}

function prepareUrl(url) {
	if (url.indexOf('?') >= 0) {
		url += '&';
	} else {
		url += '?';
	}
	url += 'rnd=' + Math.random();
	return url;
}

function showDocInfo()
{
	if(typeof(WorkWindow) == "undefined" ||
		WorkWindow.Tab == null)
		return null;

    var activeTab = WorkWindow.Tab.getActive();
    if (activeTab.isDocViewer())
		window.open('?searchnum&index5='+WndDoc.getOid()+'&docinfo=1');
	else
		showHelp();
}

function getHelpResult() {
    get_data('get_helpfile', function(answer) {
		return answer;
    });
}

function getnh() {
	var arr = WorkWindow.Tab.getActive().getCurrentUrl().match('nh=(.)&');
	return null == arr ? null : arr[arr.length-1];
}

function isSearchPanel() {
	var fa_len = window.parent.frames.length;
	for (i=0; i < fa_len; i++) {
		try {
			if (window.parent.frames[i].document != null) {
				var doc = window.parent.frames[i].document;
				if (el = doc.getElementById('TSearch_panel'))
					if (el.style.display == 'block')
						return true;
			}
		} catch(err) {
		}
	}
}

function showHelp(topic) {

    if (null == topic || '' == topic) {
        topic = getTopic();
    } else {
		topic = getTopicByName(topic);
	}
    
    var helpresult = getHelpResult();
    if ('' == helpresult || null == helpresult) {
        helpresult = 'help.html';
    }
	
    wnd = window.open(helpresult, '_blank', 'location=yes, toolbar=no, status=no, scrollbars=yes, resizable=yes');    
    wnd.topic = topic + '.html';
}


// Определение темы справки
function getTopic() {

	try {
		if (typeof(WorkWindow) == "undefined" || WorkWindow.Tab == null)
			return '01_logic';
			
		var activeTab = WorkWindow.Tab.getActive();	
		if (null == activeTab) {
			if (document.title.match('Фильтр')) 
   		       return '04_2_lists_filter';		
		} else {				
			if (activeTab.isSearchByAttributes())		    
				return '03_2_asearch';
			if (activeTab.isSearchBySituation())		    
   				return '03_search';		    
			if (activeTab.isIntelligentSearch())		    
				return '03_1_isearch';		    
			if ((activeTab.isUsersData()) && (!activeTab.isHistoryViewer()))		    
				return '06_user_materials';		    
			if (isSearchPanel())		    
				return '05_3_4_document_operations_search';		    
			if (getnh()=='3')		        
				return '05_1_document_contents';		    
			if ((activeTab.isDocViewer()) && (!isMainPage()) && (!activeTab.isList()))		    
				return '05_document';		    
			if (activeTab.isHistoryViewer())		    
				return '06_2_user_materials_history';		    
			if (activeTab.isList())		    
				return '04_lists';		    
			if (isMainPage())		    
				return '01_logic';			 
		}		  
	} catch (err) {	
	}
	return '01_logic';
}


function getTopicByName(topic) {

	switch(topic) {
		case 'user_config': 
			return 'user_material_setup';			
		case 'set_bmarks':
			return '05_3_6_document_operations_bookmarks';
		case 'search_ext':
			return '03_2_asearch';
		case 'find':
			return '03_1_isearch';
		case 'bookmarks':
			return '06_user_materials';
		case 'txt_work':
			return '05_document';
		case 'history':
			return '06_2_user_materials_history';
		case 'lists':
			return '04_lists';
		case 'to_folder':
			return '05_3_7_document_operations_save2folder';
		case 'add_folder':
			return '06_1_user_materials_folders';
		default:
			return topic;		
	}
}
