﻿var current_fund_id = 0;
var AreaPopup = null;
var TematicsPopup = null;
var TypePopup = null;



function GetAllParents(items)
{
	var p =new Array();
	var s =new Array();
	var i;
	var j;
	var parent;
	var ch;
	
	for (i=0;i<items.length;i++)
	{
		p.push(items[i]);
		s.push(1);				
	};
	ch=true;
	while (ch)
	{
		ch=false;
		i=0;
		while(i<p.lenght)
		{	
			if (s[i]==1)
			{
				parent=ppi_parent[p[i]];
				s[i]=2;
				if (parent!=0)
				{
					q=false;
					ch=true;
					for (j=0;j<p.length&&q;j++)
					{
						q=q || p[i]!=parent
					};
					if (q)
					{
						p.push(parent);
						s.push(1);				
					};
				}
			};
			i++;
			
		}
	};

}


function SetInitialFundId(fid) {
	current_fund_id = fid;
} // end function access_item_select

function FundClick(fid)
{
	var ft = document.getElementById('ftr' + fid);
	var fi = document.getElementById('fimg' + fid);
	var fl = document.getElementById('flink' + fid);
	var cft = document.getElementById('ftr' + current_fund_id);
	var cfi = document.getElementById('fimg' + current_fund_id);
	var cfl = document.getElementById('flink' + current_fund_id);	
	if (ft) ft.style.display = 'none';
	if (fi) fi.src = '/img/access_info_close.gif';
	if (fl) fl.className = 'access_item';
	if (fid == current_fund_id){
		current_fund_id = 0;
	}
	else{
		if (cft) cft.style.display = 'none';
		if (cfi) cfi.src = '/img/access_info_close.gif';
		if (cfl) cfl.className = 'access_item';
		if (ft = document.getElementById('ftr' + fid)) ft.style.display = '';
		if (fi = document.getElementById('fimg' + fid)) fi.src = '/img/menu_open.gif';
		if (fl = document.getElementById('flink' + fid)) fl.className = 'access_item_selected';		
		current_fund_id = fid;
	} // end if
	return false;
}

var area_item_country = new Array();
var area_rows = new Array();
var ppi_parent = new Array();
var ppi_childs = new Array();
ppi_childs[0] = 0;

function LoadPublishingPlaceItemsFromXML(xml, list, pid, checked) {
	var root = XmlRootByText(xml);
	var items = GetXmlNodesByTagName(root, 'item');
	var item, id, havechild, title, li, html, it, checked2, temp;
	list.innerHTML = items.length > 0 ? '' : '<li>' + text_empty + '</li>';
	for (i = 0; i < items.length; i++) {
		item = items[i];
		id = GetXmlAttributeValue(item, 'id');
		havechild = GetXmlAttributeValue(item, 'havechild') == 'true';
		title = GetXmlNodeValue(item);
		it = document.getElementById('ppce' + id);
		checked2 = (checked) ? true : ((it) ? it.checked : false);
		li = document.createElement('LI');
		li.id = 'ppl' + id;
		html = (havechild) ? '<a href="#" onclick="return PublishingPlaceItemClick(' + id + ')"><img id="ppi' + id + '" src="/img/tree_item_closed.gif" width="11" height="11" border="0" alt="' + text_expand + '"></a> ' : '';
		html += '<label id="ppt' + id + '" for="ppc' + id + '"' + ((havechild) ? '' : ' class="nochild"') + '>' + title + '</label> ';
		html += '<table cellpadding="0" cellspacing="0"><tr><td><input type="checkbox" id="ppc' + id + '" onclick="return PublishingPlaceItemCheck(' + id + ')"' + ((checked2) ? ' checked' : '') + '></td></tr></table> ';
		if (havechild) html += '<ul id="ppd' + id + '" style="display: none"></ul>';
		li.innerHTML = html;
		list.appendChild(li);
		ppi_parent[id] = pid;
		ppi_childs[id] = 0;
		if (!checked2) ppi_childs[pid]++;
		if ((it) && (checked)) {
			it.checked = true;
		} // end if
	} // end for
	if ((items.length > 0) && (!checked) && (!ppi_childs[pid])) {
		temp = pid;
		while ((temp) && (!ppi_childs[temp])) {
			item = document.getElementById('ppc' + temp);
			if (item.checked) break;
			item.checked = true;
			temp = ppi_parent[temp];
			ppi_childs[temp]--;
		} // end if
	} // end if
} // end function

function PublishingPlaceItemClick(pid) {
	var me = document.getElementById('ppc' + pid);
	var list = document.getElementById('ppd' + pid);
	var img = document.getElementById('ppi' + pid);
	if ((me) && (list) && (img)) {
		if (list.style.display == 'none') {
			if (list.innerHTML.length == 0) {
				var li = document.createElement('LI');
				li.innerHTML = text_loading;
				list.appendChild(li);
				HttpRequest('/ajax/get_area_tree.aspx?parent.id=' + pid, null, null, LoadPublishingPlaceItemsFromXML, list, pid, me.checked);
			} // end if
			list.style.display = 'block';
			img.src = '/img/tree_item_opened.gif';
			img.alt = text_collapse;
		} else {
			list.style.display = 'none';
			img.src = '/img/tree_item_closed.gif';
			img.alt = text_expand;
		} // end if
	} // end if
	return false;
} // end function

function PublishingPlaceItemCheck(id) {
	var me = document.getElementById('ppc' + id);
	if (me) {
		SyncPublishingPlaceWithList(id);
		var i, temp, item;
		if (me.checked) {
			temp = ppi_parent[id];
			ppi_childs[temp]--;
			while ((temp) && (!ppi_childs[temp])) {
				item = document.getElementById('ppc' + temp);
				if (item.checked) break;
				item.checked = true;
				temp = ppi_parent[temp];
				ppi_childs[temp]--;
			} // end if
		} else {
			ppi_childs[ppi_parent[id]]++;
			temp = id;
			while (ppi_parent[temp]) {
				temp = ppi_parent[temp];
				item = document.getElementById('ppc' + temp);
				if (!item.checked) break;
				item.checked = false;
				SyncPublishingPlaceWithList(temp);
				ppi_childs[ppi_parent[temp]]++;
			} // end while
		} // end if
		var list = document.getElementById('ppd' + id);
		if (list) {
			var childs = list.getElementsByTagName('INPUT');
			if (me.checked) {
				for (i = 0; i < childs.length; i++) {
					if (!childs[i].checked) {
						childs[i].checked = true;
						temp = parseInt(childs[i].id.substr(3));
						SyncPublishingPlaceWithList(temp);
						ppi_childs[ppi_parent[temp]]--;
					} // end if
				} // end for
			} else {
				for (i = 0; i < childs.length; i++) {
					if (childs[i].checked) {
						childs[i].checked = false;
						temp = parseInt(childs[i].id.substr(3));
						SyncPublishingPlaceWithList(temp);
						ppi_childs[ppi_parent[temp]]++;
					} // end if
				} // end for
			} // end if
		} // end if
	} // end if
	return true;
} // end function

function SyncPublishingPlaceWithList(id) {
	var me = document.getElementById('ppc' + id);
	var it = document.getElementById('ppce' + id);
	if ((me) && (it) && (me.checked != it.checked)) it.checked = me.checked;
	return true;
} // end if

function SyncPublishingPlaceWithTree(id) {
	var me = document.getElementById('ppce' + id);
	var it = document.getElementById('ppc' + id);
	if ((me) && (it) && (me.checked != it.checked)) {
		it.checked = me.checked;
		PublishingPlaceItemCheck(id);
	} // end if
	return true;
} // end function

function GetPublishingPlaceTreeItems() {
	var checks = document.getElementById('publishing_place_tree').getElementsByTagName('INPUT');
	var res = new Object();
	res.ids = new Array();
	res.titles = new Array();
	var i, id, pid, parent;
	for (i = 0; i < checks.length; i++) {
		if (checks[i].checked) {
			id = parseInt(checks[i].id.substr(3));
			pid = (ppi_parent[id]) ? ppi_parent[id] : 0;
			parent = document.getElementById('ppc' + pid);
			if ((!parent) || (!parent.checked)) {
				res.ids.push(id);
				res.titles.push(document.getElementById('ppt' + id).innerHTML);
			} // end if
		} // end if
	} // end for
	return res;
} // end function

function GetPublishingPlaceListItems() {
	var res = new Object();
	res.ids = new Array();
	res.titles = new Array();
	var list = document.getElementById('publishing_place_list');
	if (list) {
		var checks = list.getElementsByTagName('INPUT');
		var i, id;
		for (i = 0; i < checks.length; i++) {
			if (checks[i].checked) {
				id = parseInt(checks[i].id.substr(4));
				res.ids.push(id);
				res.titles.push(document.getElementById('ppte' + id).innerHTML);
			} // end if
		} // end for
	} // end if
	return res;
} // end function

function PublishingPlaseShowTree()
{
	var ttd = document.getElementById('area_tree');
	var tdiv = document.getElementById('publishing_place_tree');
	var ldiv = document.getElementById('publishing_place_div');
	var ltd = document.getElementById('area_list');
	var sel_all=document.getElementById('show_choosen');
	var sel_countryes=document.getElementById('show_countryes');
	if (ldiv && ltd && ttd && tdiv && sel_all && sel_countryes){
		ldiv.style.display='none';
		ltd.className="source_popup";
		ttd.className="source_popup_select";
		tdiv.style.display='';
		sel_all.style.display='';
		sel_countryes.style.display='none';
	}
}

function PublishingPlaseShowList() {
	var ltd = document.getElementById('area_list');
	var ttd = document.getElementById('area_tree');
	var tdiv = document.getElementById('publishing_place_tree');
	var ldiv = document.getElementById('publishing_place_div');
	var list = document.getElementById('publishing_place_list');
	var sel_all=document.getElementById('show_choosen');
	var sel_countryes=document.getElementById('show_countryes');
	if (ldiv) ldiv.style.display = 'block';
	if (ltd) ltd.className="source_popup_select";
	if (ttd) ttd.className="source_popup";
	if (tdiv) tdiv.style.display = 'none';
	if (sel_all) sel_all.style.display = 'none';
	if (sel_countryes) sel_countryes.style.display = 'block';
	if ((list) && (list.style.display == 'none')) {
		var event =
			function (result) {
				var root = XmlRootByText(result);
				var items = GetXmlNodesByTagName(root, 'item');
				var item, id, path, title, tr,td3 ,td0 ,td1, td, td2, html0, html, html2,html3;
				item = document.getElementById('loading_row');
				if (item) list.tBodies[0].removeChild(item);
				for (i = 0; i < items.length; i++) {
					item = items[i];
					id = GetXmlAttributeValue(item, 'id');
					path = GetXmlAttributeValue(item, 'path');
					title = GetXmlNodeValue(item);
					area_item_country[id] = path;
					it = document.getElementById('ppc' + id);
					checked = (it) ? it.checked : false;
					td0 = document.createElement('TD');
					td1 = document.createElement('TD');
					html = '<div><label id="ppte' + id + '" for="ppce' + id + '">' + title + '</label><table cellpadding="0" cellspacing="0"><tr>';
					html += '<td><input type="checkbox" id="ppce' + id + '" onclick="return SyncPublishingPlaceWithTree(' + id + ')"' + ((checked) ? ' checked' : '') + '></td></tr></table></div>';
					td1.innerHTML = html;
					td2 = document.createElement('TD');
					html2 = path;
					td2.style.padding = '0 0 0 20px';
					td2.innerHTML = html2;
					td3 = document.createElement('TD');
					tr = document.createElement('TR');
					tr.id = 'ppre' + id;
					if (i % 2) tr.className = 'gray';
					tr.appendChild(td0);
					tr.appendChild(td1);
					tr.appendChild(td2);
					tr.appendChild(td3);
					list.tBodies[0].appendChild(tr);
					area_rows.push(tr);
				} // end for
				var sel = document.getElementById('select_country').disabled = false;
			} // end event
			list.style.display = 'block';
			//if (sort) s = "?sort=" + sort;
		HttpRequest('/ajax/get_area_list.aspx', null, null, event);
	} // end if
	if (navigator.appName == 'Opera') {
		var timer =
			function () {
				list.style.width = '100%';
			} // end event
		setTimeout(timer, 1);
		list.style.width = '99%';
	} // end if
	return false;
} // end function

function LoadPublishingTematicsItemsFromXML(xml, list, pid, checked) {
	var root = XmlRootByText(xml);
	var items = GetXmlNodesByTagName(root, 'item');
	var item, id, havechild, title, li, html, it, checked2, temp;
	list.innerHTML = items.length > 0 ? '' : '<li>' + text_empty + '</li>';
	for (i = 0; i < items.length; i++) {
		item = items[i];
		id = GetXmlAttributeValue(item, 'id');
		havechild = GetXmlAttributeValue(item, 'havechild') == 'true';
		title = GetXmlNodeValue(item);
		li = document.createElement('LI');
		html = (havechild) ? '<a href="#" onclick="return PublishingTematicsItemClick(' + id + ')"><img id="ppi' + id + '" src="/img/tree_item_closed.gif" width="11" height="11" border="0" alt="' + text_expand + '"></a> ' : '';
		html += '<label id="ppt' + id + '" for="ppc' + id + '"' + ((havechild) ? '' : ' class="nochild"') + '>' + title + '</label> ';
		html += '<table cellpadding="0" cellspacing="0"><tr><td><input type="checkbox" id="ppc' + id + '" onclick="return PublishingTematicsItemCheck(' + id + ')"' + ((checked) ? ' checked' : '') + '></td></tr></table> ';

		if (havechild) html += '<ul id="ppd' + id + '" style="display: none"></ul>';
		li.innerHTML = html;
		list.appendChild(li);
		ppi_parent[id] = pid;
		ppi_childs[id] = 0;
		if (!checked2) ppi_childs[pid]++;
		if ((it) && (checked)) {
			it.checked = true;
		} // end if
	} // end for
	if ((items.length > 0) && (!checked) && (!ppi_childs[pid])) {
		temp = pid;
		while ((temp) && (!ppi_childs[temp])) {
			item = document.getElementById('ppc' + temp);
			if (item.checked) break;
			item.checked = true;
			temp = ppi_parent[temp];
			ppi_childs[temp]--;
		} // end if
	} // end if
} // end function

function PublishingTematicsItemClick(pid) {
	var me = document.getElementById('ppc' + pid);
	var list = document.getElementById('ppd' + pid);
	var img = document.getElementById('ppi' + pid);
	if ((me) && (list) && (img)) {
		if (list.style.display == 'none') {
			if (list.innerHTML.length == 0) {
				var li = document.createElement('LI');
				li.innerHTML = text_loading;
				list.appendChild(li);
				HttpRequest('/ajax/getpublishingtematics.aspx?parent.id=' + pid, null, null, LoadPublishingTematicsItemsFromXML, list, pid, me.checked);
			} // end if
			list.style.display = 'block';
			img.src = '/img/tree_item_opened.gif';
			img.alt = text_collapse;
		} else {
			list.style.display = 'none';
			img.src = '/img/tree_item_closed.gif';
			img.alt = text_expand;
		} // end if
	} // end if
	return false;
} // end function

function PublishingTematicsItemCheck(id) {
	var me = document.getElementById('ppc' + id);
	if (me) {
		var i, temp, item;
		if (me.checked) {
			temp = ppi_parent[id];
			ppi_childs[temp]--;
			while ((temp) && (!ppi_childs[temp])) {
				item = document.getElementById('ppc' + temp);
				if (item.checked) break;
				item.checked = true;
				temp = ppi_parent[temp];
				ppi_childs[temp]--;
			} // end if
		} else {
			ppi_childs[ppi_parent[id]]++;
			temp = id;
			while (ppi_parent[temp]) {
				temp = ppi_parent[temp];
				item = document.getElementById('ppc' + temp);
				if (!item.checked) break;
				item.checked = false;
				ppi_childs[ppi_parent[temp]]++;
			} // end while
		} // end if
		var list = document.getElementById('ppd' + id);
		if (list) {
			var childs = list.getElementsByTagName('INPUT');
			if (me.checked) {
				for (i = 0; i < childs.length; i++) {
					if (!childs[i].checked) {
						childs[i].checked = true;
						temp = parseInt(childs[i].id.substr(3));
						ppi_childs[ppi_parent[temp]]--;
					} // end if
				} // end for
			} else {
				for (i = 0; i < childs.length; i++) {
					if (childs[i].checked) {
						childs[i].checked = false;
						temp = parseInt(childs[i].id.substr(3));
						ppi_childs[ppi_parent[temp]]++;
					} // end if
				} // end for
			} // end if
		} // end if
	} // end if
	return true;
} // end function

function GetPublishingTematicsItems() {
	var checks = document.getElementById('publishing_place_tree').getElementsByTagName('INPUT');
	var res = new Object();
	res.ids = new Array();
	res.titles = new Array();
	var i, id, pid, parent;
	for (i = 0; i < checks.length; i++) {
		if (checks[i].checked) {
			id = parseInt(checks[i].id.substr(3));
			pid = (ppi_parent[id]) ? ppi_parent[id] : 0;
			parent = document.getElementById('ppc' + pid);
			if ((!parent) || (!parent.checked)) {
				res.ids.push(id);
				res.titles.push(document.getElementById('ppt' + id).innerHTML);
			} // end if
		} // end if
	} // end for
	return res;
} // end function

function clearPlaceForm(inp, hid, huid)
{
	var name = document.source_search_form.edition_name;
	if (name.disabled == ""){
		var input = document.getElementsByName(inp)[0];
		var hidden = document.getElementsByName(hid)[0];
		var hid_und = document.getElementsByName(huid)[0];
		if (input){
			input.value="";
			input.readOnly = "";
		}
		if (hidden) {hidden.value="";}
		if (hid_und) {hidden.value="";}
	}
	return false;
}

function clearPublishingForm()
{
	var name = document.source_search_form.edition_name;
	if (name.disabled == ""){
		var place = document.source_search_form.edition_place;
		var place_hidden = document.source_search_form.edition_place_hidden;
		var tematics = document.source_search_form.edition_tematics;
		var tematics_hidden = document.source_search_form.edition_tematics;
		var profiles = document.source_search_form.edition_profiles;
		var type = document.source_search_form.edition_type;
		var type_hidden = document.source_search_form.edition_type_hidden;
		var undertype_hidden = document.source_search_form.edition_undertype_hidden;
		var format = document.source_search_form.edition_format;
		var periodicity = document.source_search_form.edition_periodicity;
		var post_index = document.source_search_form.edition_post_index;
		name.value="";
		place.value=""; place.readOnly="";
		place_hidden.value="";
		tematics.value=""; tematics.readOnly="";
		tematics_hidden.value="";
		profiles.selectedIndex=0;
		type.value=""; type.readOnly="";
		type_hidden.value="";
		undertype_hidden.value="";
		format.selectedIndex=0;
		periodicity.selectedIndex=0;
		post_index.value="";
	}
return false;
}

function LoadPublishingTypeItemsFromXML(xml, list, pid, checked) {
	var root = XmlRootByText(xml);
	var items = GetXmlNodesByTagName(root, 'item');
	var item, id, title, li, html;
	for (i = 0; i < items.length; i++) {
		item = items[i];
		id = GetXmlAttributeValue(item, 'id');
		havechild = GetXmlAttributeValue(item, 'havechild') == 'true';
		title = GetXmlNodeValue(item);
		li = document.createElement('LI');
		html = (havechild) ? '<a href="#" onclick="return PublishingTypeItemClick(' + id + ')"><img id="ppi' + id + '" src="/img/tree_item_closed.gif" width="11" height="11" border="0" alt="' + text_expand + '"></a> ' : '';
		html += '<label id="ppt' + id + '" for="ppc' + id + '"' + ((havechild) ? '' : ' class="nochild"') + '>' + title + '</label> ';
		html += '<table cellpadding="0" cellspacing="0"><tr><td><input type="checkbox" id="ppc' + id + '" onclick="return PublishingTypeItemCheck(' + id + ')"' + ((checked) ? ' checked' : '') + '></td></tr></table> ';
		if (havechild) html += '<ul id="ppd' + id + '" style="display: none"></ul>';
		li.innerHTML = html;
		list.appendChild(li);
		ppi_childs[id] = 0;
	} // end for
} // end function

function LoadPublishingUndertypeItemsFromXML(xml, list, pid, checked) {
	var root = XmlRootByText(xml);
	var items = GetXmlNodesByTagName(root, 'item');
	var item, id, title, li, html;
	list.innerHTML = items.length > 0 ? '' : '<li>' + text_empty + '</li>';
	for (i = 0; i < items.length; i++) {
		item = items[i];
		id = GetXmlAttributeValue(item, 'id');
		title = GetXmlNodeValue(item);
		li = document.createElement('LI');
		html = '<label id="put' + id + '" for="puc' + id + '" class="nochild">' + title + '</label> ';
		html += '<table cellpadding="0" cellspacing="0"><tr><td><input type="checkbox" id="puc' + id + '" onclick="return PublishingUndertypeItemCheck(' + id + ')"' + ((checked) ? ' checked' : '') + '></td></tr></table> ';
		li.innerHTML = html;
		list.appendChild(li);
		ppi_parent[id] = pid;
		if (!checked) ppi_childs[pid]++;
	} // end for
} // end function

function PublishingTypeItemClick(pid) {
	var me = document.getElementById('ppc' + pid);
	var list = document.getElementById('ppd' + pid);
	var img = document.getElementById('ppi' + pid);
	if ((me) && (list) && (img)) {
		if (list.style.display == 'none') {
			if (list.innerHTML.length == 0) {
				var li = document.createElement('LI');
				li.innerHTML = text_loading;
				list.appendChild(li);
				HttpRequest('/ajax/get_publishing_undertype.aspx?parent.id=' + pid, null, null, LoadPublishingUndertypeItemsFromXML, list, pid, me.checked);
			} // end if
			list.style.display = 'block';
			img.src = '/img/tree_item_opened.gif';
			img.alt = text_collapse;
		} else {
			list.style.display = 'none';
			img.src = '/img/tree_item_closed.gif';
			img.alt = text_expand;
		} // end if
	} // end if
	return false;
} // end function

function PublishingTypeItemCheck(id) {
	var me = document.getElementById('ppc' + id);
	if (me) {
		var list = document.getElementById('ppd' + id);
		if (list) {
			var childs = list.getElementsByTagName('INPUT');
			if (me.checked) {
				for (var i = 0; i < childs.length; i++) {
					if (!childs[i].checked) {
						childs[i].checked = true;
						ppi_childs[id]--;
					} // end if
				} // end for
			} else {
				for (var i = 0; i < childs.length; i++) {
					if (childs[i].checked) {
						childs[i].checked = false;
						ppi_childs[id]++;
					} // end if
				} // end for
			} // end if
		} // end if
	} // end if
	return true;
} // end function

function PublishingUndertypeItemCheck(id) {
	var me = document.getElementById('puc' + id);
	if (me) {
		var i, pid, item;
		if (me.checked) {
			pid = ppi_parent[id];
			ppi_childs[pid]--;
			if (!ppi_childs[pid]) {
				item = document.getElementById('ppc' + pid);
				if (item) item.checked = true;
			} // end if
		} else {
			pid = ppi_parent[id];
			item = document.getElementById('ppc' + pid);
			if (item) item.checked = false;
			ppi_childs[pid]++;
		} // end if
	} // end if
	return true;
} // end function

function GetPublishingTypeItems() {
	var checks = document.getElementById('publishing_place_tree').getElementsByTagName('INPUT');
	var res = new Object();
	res.ids = new Array();
	res.titles = new Array();
	var i, id, pid;
	for (i = 0; i < checks.length; i++) {
		if ((checks[i].checked) && (checks[i].id.substr(0, 3) == 'ppc')) {
			id = parseInt(checks[i].id.substr(3));
			res.ids.push(id);
			res.titles.push(document.getElementById('ppt' + id).innerHTML);
		} // end if
	} // end for
	return res;
} // end function

function GetPublishingUndertypeItems() {
	var checks = document.getElementById('publishing_place_tree').getElementsByTagName('INPUT');
	var res = new Object();
	res.ids = new Array();
	res.titles = new Array();
	var i, id, pid, parent;
	for (i = 0; i < checks.length; i++) {
		if ((checks[i].checked) && (checks[i].id.substr(0, 3) == 'puc')) {
			id = parseInt(checks[i].id.substr(3));
			if (ppi_parent[id]) {
				pid = ppi_parent[id];
				parent = document.getElementById('ppc' + pid);
				if ((!parent) || (!parent.checked)) {
					res.ids.push(id);
					res.titles.push(document.getElementById('put' + id).innerHTML);
				} // end if
			} // end if
		} // end if
	} // end for
	return res;
} // end function

function AreaPopupOpen() {
	var name = document.source_search_form.edition_name;
	if (name.disabled == ""){
		if ((AreaPopup) && (!AreaPopup.closed)) {
			AreaPopup.focus();
		} else {
			AreaPopup = OpenWindow('/geographicalplace.aspx', null, 700, 575);
		} // end if
		//	if (AreaPopup) {
		//	} // end if
	}
	return false;
} // end function

function TematicsPopupOpen() {
	var name = document.source_search_form.edition_name;
	if (name.disabled == ""){	
		if ((TematicsPopup) && (!TematicsPopup.closed)) {
			TematicsPopup.focus();
		} else {
			TematicsPopup = OpenWindow('/publishingtematics.aspx', null, 700, 575);
		} // end if
		//	if (TematicsPopup) {
		//	} // end if
	}
	return false;
} // end function

function TypePopupOpen() {
	var name = document.source_search_form.edition_name;
	if (name.disabled == ""){
		if ((TypePopup) && (!TypePopup.closed)) {
			TypePopup.focus();
		} else {
			TypePopup = OpenWindow('/sourcetype.aspx', null, 700, 575);
		} // end if
		//	if (TypePopup) {
		//	} // end if
	}
	return false;
} // end function

function OpenWindow(url, name, width, height) {
	var left = (screen.width - width) / 2;
	var top = (screen.height - height) / 2;
	if (!name) name = '_blank';
	var win = window.open(url, name, 'width=' + width + ', height=' + height + ', left=' + left + ', top=' + top + ', location=no, toolbar=no, menubar=no, status=no, scrollbars=no');
	if (win) {
		win.focus();
	} else {
		alert('Пожалуйста, отключите блокировку всплывающих окон.');
	} // end if
	return win;
} // end function


function SubmitToOpener(save)
{
	if(window.opener && save){
	var ldiv = document.getElementById('publishing_place_div');
		if (ldiv){	var res = ldiv.style.display=='none' ? GetPublishingPlaceTreeItems() : GetPublishingPlaceListItems();
		var parent_input = window.opener.document.source_search_form.edition_place;
		var parent_hidden = window.opener.document.source_search_form.edition_place_hidden;
		parent_input.value = res.titles.join('; ');
		parent_input.readOnly = "false";
		//alert(parent_input.value);
		parent_hidden.value = res.ids.join(',');		
		}
	}
	//var vv=GetAllParents(res.ids);
	//alert(vv);
	window.close();
	window.opener.focus();
	return false;
}

function SubmitToTematics(save)
{
	if((window.opener) && (save)) {
		var res = GetPublishingTematicsItems();
		var parent_input = window.opener.document.source_search_form.edition_tematics;
		var parent_hidden = window.opener.document.source_search_form.edition_tematics_hidden;
		parent_input.value = res.titles.join('; ');
		parent_input.readOnly="true";
		//alert(parent_input.value);
		parent_hidden.value = res.ids.join(',');
		
	} // enf if
	window.close();
	window.opener.focus();
	return false;
}

function SubmitToTypes(save) {
	if ((window.opener) && (save)) {
		var res1 = GetPublishingTypeItems();
		var res2 = GetPublishingUndertypeItems();
		var parent_input = window.opener.document.source_search_form.edition_type;
		var parent_hidden = window.opener.document.source_search_form.edition_type_hidden;
		var parent_undertype_hidden = window.opener.document.source_search_form.edition_undertype_hidden;
		parent_input.value = res1.titles.concat(res2.titles).join('; ');
		parent_input.readOnly="true";
		parent_hidden.value = res1.ids.join(',');
		parent_undertype_hidden.value = res2.ids.join(',');
		//alert(res1.ids.join(',') + '  ' + res1.titles.concat(res2.titles).join('; '));
		//res2.ids.join(',');
		//var parent_input = window.opener.document.getElementsByName('edition_type')[0];
		//var parent_hidden = window.opener.document.getElementsByName('edition_type_hidden')[0];
		//parent_input.value = res.titles.join(' ; ');
		//parent_hidden.value = res.ids.join(',');
	} // end if
	window.close();
	window.opener.focus();
	return false;
} // end function

function SourceSearchIndexKeyEvent(event) {
	return ((event.keyCode < 32) || (event.keyCode >= 48) && (event.keyCode <= 57));
} // end function

function UpdateSourceSearchFormState() {
	var name = document.source_search_form.edition_name;
	var place = document.source_search_form.edition_place;
	var place_hidden = document.source_search_form.edition_place_hidden;
	var tematics = document.source_search_form.edition_tematics;
	var tematics_hidden = document.source_search_form.edition_tematics_hidden;
	var profiles = document.source_search_form.edition_profiles;
	var type = document.source_search_form.edition_type;
	var type_hidden = document.source_search_form.edition_type_hidden;
	var undertype_hidden = document.source_search_form.edition_undertype_hidden;
	var format = document.source_search_form.edition_format;
	var periodicity = document.source_search_form.edition_periodicity;	
	var index_input = document.source_search_form.edition_post_index;
	var disabled = index_input.value.length > 0;
	name.disabled = disabled;
	place.disabled = disabled;
	place_hidden.disabled = disabled;
	tematics.disabled = disabled;
	tematics_hidden.disabled = disabled;
	profiles.disabled = disabled;
	type.disabled = disabled;
	type_hidden.disabled = disabled;
	undertype_hidden.disabled = disabled;
	format.disabled = disabled;
	periodicity.disabled = disabled;
} // end function

function AreaListSortChange() {
	var img_asc = document.getElementById('scia');
	var img_desc = document.getElementById('scid');
	if ((img_asc) && (img_desc)) {
		if (img_asc.style.display == 'none') {
			img_asc.style.display = '';
			img_desc.style.display = 'none';
		} else {
			img_asc.style.display = 'none';
			img_desc.style.display = '';
		} // end if
		AreaListFilterChange();
	} // end if
	return false;
} // end function

function AreaListFilterChange() {
	var sel = document.getElementById('select_country');
	if (sel) {
		var cid = sel.value;
		var list_table = document.getElementById('publishing_place_list');
		var list = list_table.tBodies[0];
		var i, id, last;
		for (i = list.childNodes.length - 1; i >= 0; i--) {
			if (list.childNodes[i].nodeType == 1) {
				last = list.removeChild(list.childNodes[i]);
			} // end if
		} // end for
		list.appendChild(last);
		var k = 0;
		var img_asc = document.getElementById('scia');
		var back = (img_asc.style.display == 'none');
		var childs = list.childNodes;
		for (i = (back) ? area_rows.length - 1 : 0; (back) ? i >= 0 : i < area_rows.length; i += (back) ? -1 : 1) {
			id = parseInt(area_rows[i].id.substr(4));
			visible = (cid <= 0) || (area_item_country[id].indexOf('.' + cid + '.') >= 0);
			if (visible) {
				list.appendChild(area_rows[i]);
				area_rows[i].className = (k % 2) ? 'gray' : '';
				k++;
			} // end if
		} // end for
	} // end if
} // end function

function AreaTreeShowOnlyCheck() {
	var check = document.getElementById('show_checked');
	if (check) {
		var i, id, temp;
		if (check.checked) {
			var checks = document.getElementById('publishing_place_tree').getElementsByTagName('INPUT');
			var arr = new Array();
			for (i = 0; i < checks.length; i++) {
				if ((checks[i].checked) && (checks[i].id.substr(0, 3) == 'ppc')) {
					id = parseInt(checks[i].id.substr(3));
					temp = id;
					while ((temp) && (!arr[temp])) {
						arr[temp] = true;
						temp = (ppi_parent[temp]) ? ppi_parent[temp] : 0;
					} // end while
				} // end if
			} // end for
			for (i = 0; i < checks.length; i++) {
				if (checks[i].id.substr(0, 3) == 'ppc') {
					id = parseInt(checks[i].id.substr(3));
					if (!arr[id]) {
						temp = document.getElementById('ppl' + id);
						if (temp) temp.style.display = 'none';
					} // end if
				} // end if
			} // end for
		} else {
			var items = document.getElementById('publishing_place_tree').getElementsByTagName('LI');
			for (i = 0; i < items.length; i++) {
				items[i].style.display = 'block';
			} // end for
		} // end if
	} // end if
	return true;
} // end function

function SourceSearchLister(start) {
	document.source_search_form.start.value = start;
	document.source_search_form.submit();
	return false;
} // end function

