function import_script(url) {
	var tag = document.createElement('script');
	tag.type = 'text/javascript';
	tag.src = url;
	alert(url);
	document.body.appendChild(tag);
}

/*
window.onload = function() {
	if (lang.length > 0) {
		lang += '/';
	}
	import_script(base + lang + 'filetransmit/js/interface');
};
*/

window.onload = mark_rows;

var marked_row = new Array;
var xml_http_obj = false;


function report_abuse()
{
	var report_abuse = prompt(interface.report_abuse_about_the_content_page + ':\n' + document.location.href, '');
	if (report_abuse != null) {
		var parameters = 'report_abuse=' + encodeURI(report_abuse) + '&url=' + document.location.href;
		xml_http_obj = get_xml_http_object();
		xml_http_obj.open('POST', base + 'main/report_abuse', true);
		xml_http_obj.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
		xml_http_obj.setRequestHeader('Content-length', parameters.length);
		xml_http_obj.setRequestHeader('Connection', 'close');
		xml_http_obj.send(parameters);
		alert(interface.your_report_abuse_has_been_sent);
		if (item = document.getElementById('reportabuse')) {
			item.parentNode.removeChild(item);
		}
	}
}

function remove_photo(a_id)
{
	if (!confirm(interface.delete_confirm)) {
		return;
	}
	if (item = document.getElementById('photo_' + a_id)) {
		item.parentNode.removeChild(item);
	}
	xml_http_obj = get_xml_http_object();
	xml_http_obj.open('GET', base + 'photos/remove/' + a_id + '.html', true);
	xml_http_obj.send(null);
}

function disable_input(a_id)
{
	if (l_element = document.getElementById(a_id)) {
		l_element.disabled = 'disabled';
	}
}

function enable_input(a_id)
{
	if (l_element = document.getElementById(a_id)) {
		l_element.disabled = '';
	}
}

/* Select text id field */
function select_text(a_element)
{
	var content = eval(a_element);
	content.focus();
	content.select();
}

/* Reload security images */
function security_images_reload(a_id)
{
	var date = new Date();
	var uniq = date.getTime();
	var l_element = document.getElementById(a_id);
	l_element.src = base + lang + 'user/' + uniq + '/securityimages/';
}

/* Collapse table rows */
function collapse_table_section(a_table, a_class)
{
	var l_table = document.getElementById(a_table);
	var l_rows = l_table.getElementsByTagName('TR');
	var l_int = document.getElementById('id_tr_' + a_class);
	for(i = 0; i < l_rows.length; i++) {
		if (l_rows[i].className == a_class) {
			
			if ((l_rows[i].style.display == 'table-row') || (l_rows[i].style.display == '')) {
				l_rows[i].style.display = 'none';
				l_int.firstChild.nodeValue = '[+]';
			} else {
				l_rows[i].style.display = '';
				l_int.firstChild.nodeValue = '[-]';
			}
		}
	}
}

/* Collapse table rows as tabs */
function collapse_table_tab(a_class, a_table_id)
{
	if (l_table = document.getElementById('form_data_' + a_table_id)) {
		var l_rows = l_table.getElementsByTagName('TR');
		var l_tabs = document.getElementById('tabs_' + a_table_id);
		var l_a_tabs = l_tabs.getElementsByTagName('A');
		for (i = 0; i < l_a_tabs.length; i++) {
			if (l_a_tabs[i].id == ('tab_' + a_class)) {
				l_a_tabs[i].className = 'active';
			} else {
				l_a_tabs[i].className = null;
			}
		}
		for(i = 0; i < l_rows.length; i++) {
			if (l_rows[i].className == 'row_' + a_class) {
				l_rows[i].style.display = '';
			} else if (l_rows[i].className.substr(0, 4) == 'row_') {
				l_rows[i].style.display = 'none';
			}
		}
	}
}

/* Show element */
function element_show(a_id, a_display)
{
	if (l_element = document.getElementById(a_id)) {
		l_element.style.display = a_display;
	}
}

/* Display or hide alternative input for field*/
function control_alternative_input(a_element, a_id)
{
	if (a_id != '') {
		a_id = '_' + a_id;
	}
	if ((base_element = document.getElementById(a_element + a_id)) && (alternative_element = document.getElementById(a_element + '_alternative' + a_id))) {
		if (base_element.value == '') {
			alternative_element.style.display = '';
			alternative_element.disabled = '';
		} else {
			alternative_element.style.display = 'none';
			alternative_element.disabled = 'disabled';
			alternative_element.value = '';
		}
	}
}

/* Set listener 'setphoto' onclick atelement - temporary function */
function set_listener(a_element)
{
	a_element.onclick = function(){setphoto(a_element);};
}

/* Create elements */
function create_elements(a_parent, a_nodes, id)
{
	for (var key in a_nodes) {
		var new_element = document.createElement(a_nodes[key].element);
		if ((a_nodes[key].attributes != undefined) && (typeof(a_nodes[key].attributes) == 'object')) {
			for (var attribute in a_nodes[key].attributes) {
				if ((id) && (((attribute == 'id') || (attribute == 'name') || (attribute == 'for')))) {
					if (a_nodes[key].element == 'tr') {
						new_element.setAttribute(attribute, a_nodes[key].attributes[attribute] + '[' + id + '][' + key + ']');
					} else {
						new_element.setAttribute(attribute, a_nodes[key].attributes[attribute] + '[' + id + ']');
					}
				} else {
					if ((attribute == 'class') && (navigator.appName == 'Microsoft Internet Explorer')) {
						new_element.setAttribute('className', a_nodes[key].attributes[attribute]);
					} else {
						new_element.setAttribute(attribute, a_nodes[key].attributes[attribute]);
					}
				}
			}
		}

		if (a_nodes[key].listeners != undefined) {
			for (var event in a_nodes[key].listeners) {
				var func = a_nodes[key].listeners[event];
				if (new_element.addEventListener) {
					new_element.addEventListener(event, a_nodes[key].listeners[event], false);
				} else if (new_element.attachEvent) {
					new_element.attachEvent('on' + event, a_nodes[key].listeners[event]);
				}
			}
		}

		if (a_nodes[key].textnode != undefined) {
			if (typeof(a_nodes[key].textnode) == 'object') {
				create_elements(new_element, a_nodes[key].textnode, id);
			} else if (a_nodes[key].textnode != '') {
				if (a_nodes[key].textnode == 'id') {
					var text_node = document.createTextNode(id);
				} else {
					var text_node = document.createTextNode(a_nodes[key].textnode);
				}
				new_element.appendChild(text_node);
			}
		}
		a_parent.appendChild(new_element);
	}
}

/* Cart form calculator */
function cart_form_calc(a_id)
{
	if ((frm = document.getElementById('cart_poducts')) || (frm = document.getElementById('cart_poducts_' + a_id))) {
		if ((el_price = frm.elements['products_price[' + a_id + ']']) &&
			(el_count = frm.elements['products_count[' + a_id + ']']) &&
			(el_total = frm.elements['total[' + a_id + ']'])) {
			if ((el_price.value.length > 0) && (el_count.value.length > 0)){
				if (isNaN(parseInt(el_count.value))){
					el_count.value = 1;
				} else {
					el_count.value = parseInt(el_count.value);
				}
				var l_total = el_price.value * el_count.value;
				el_total.value = l_total.toFixed(2);
				if ((cart_products_count = document.getElementById('cart_products_count_' + a_id)) && (document.getElementById('total_sum'))) {
					cart_products_count.innerHTML = el_count.value;
				}
				if (document.getElementById('total_sum')) {
					xml_http_obj = get_xml_http_object();
					xml_http_obj.open('GET', base + lang + 'cart/' + a_id + '/products_count_update/' + el_count.value + '.html', true);
					xml_http_obj.send(null);
				}
			}
		}
		cart_form_calc_total();
	}
}

/* Calculete total from Cart form s*/
function cart_form_calc_total()
{
	if ((frm = document.getElementById('cart_poducts')) || (frm = document.getElementById('cart_poduct_' + a_id))) {
		if (base_element = document.getElementById('total_sum')) {
			total = 0;
			empty = true;
			for (i = 0; i < frm.length; i++){
				if (frm.elements[i].name.substr(0, 6) == 'total[') {
					empty = false;
					total += frm.elements[i].value * 1;
				}
			}
			frm.elements['total_sum'].value = total.toFixed(2);
			if (cart_sum = document.getElementById('cart_sum')) {
				cart_sum.innerHTML = total.toFixed(2);
			}
			if (empty) {
				if (total_sum_box = document.getElementById('total_sum_box')) {
					frm.removeChild(total_sum_box);
					var new_element = document.createElement('h2');
					new_element.appendChild(document.createTextNode(interface.empty));
					frm.appendChild(new_element);
				}
				if ((cart = document.getElementById('cart')) && (cart_block = document.getElementById('cart_block'))) {
					cart.parentNode.removeChild(cart);
					var new_element = document.createTextNode(interface.empty);
					cart_block.appendChild(new_element);
				}
			}
		}
	}
}

/* Set form action nad submit. Panel function */
function form_action(a_form_name, a_url, a_element, a_confirm, a_confirm_msg)
{
	l_flag = true;
	if (l_form = document.forms[a_form_name]) {
		if (a_element) {
			for (var i = 0; i < l_form.elements.length; i++) {
				if (l_form.elements[i].checked) {
					if (a_confirm) {
						l_result = confirm(a_confirm_msg);
					} else {
						l_result = true;
					}
					if (l_result) {
						l_form.action = a_url;
						l_form.submit();
						return true;
					}
					l_flag = false;
				}
			}
			if (l_flag){
				alert(interface.you_do_not_choose);
			}
		} else {
			if (a_url) {
				l_form.action = a_url;
			}
			l_form.submit();
		}
	}
}

/* Set data to form and submit. Panel function */
function set_data_and_submit(a_form, a_el, a_data) {
	if ((l_form = document.getElementById(a_form)) && (l_el = document.getElementById(a_el))) {
		l_el.value = a_data;
		l_form.submit();
	}
}

/* Set focus to element */
function set_focus(a_id)
{
	if (l_element = document.getElementById(a_id)) {
		l_element.select();
		l_element.focus();
	}
}

/* Mark table rows if class is row_dark or row_light for check checkbox input */
function mark_rows()
{
	var rows = document.getElementsByTagName('tr');
	for (var i = 0; i < rows.length; i++) {
		if ('row_dark' != rows[i].className.substr(0,8) && 'row_light' != rows[i].className.substr(0,9)) {
			continue;
		}
		if ( navigator.appName == 'Microsoft Internet Explorer' ) {
			// but only for IE, other browsers are handled by :hover in css
			rows[i].onmouseover = function() {
				this.className += ' hover';
			}
			rows[i].onmouseout = function() {
				this.className = this.className.replace( ' hover', '' );
			}
		}
		if (rows[i].className.search(/noclick/) != -1) {
			continue;
		}
		rows[i].onmousedown = function() {
			var unique_id;
			var checkbox;
			checkbox = this.getElementsByTagName( 'input' )[0];
			if (checkbox && checkbox.type == 'checkbox') {
				unique_id = checkbox.name + checkbox.value;
			} else if (this.id.length > 0) {
				unique_id = this.id;
			} else {
				return;
			}
			if (typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id]) {
				marked_row[unique_id] = true;
			} else {
				marked_row[unique_id] = false;
			}
			if (marked_row[unique_id]) {
				this.className += ' marked';
			} else {
				this.className = this.className.replace(' marked', '');
			}
			if (checkbox && checkbox.disabled == false) {
				checkbox.checked = marked_row[unique_id];
			}
		}
		var labeltag = rows[i].getElementsByTagName('label')[0];
		if (labeltag) {
			labeltag.onclick = function() {
				return false;
			}
		}
		var checkbox = rows[i].getElementsByTagName('input')[0];
		if (checkbox) {
			checkbox.onclick = function() {
				this.checked = ! this.checked;
			}
		}
	}
}

/* Mark all checkbox input */
function mark_all_rows(a_id)
{
	var rows = document.getElementById(a_id).getElementsByTagName('tr');
	var unique_id;
	var checkbox;
	for (var i = 0; i < rows.length; i++ ) {
		checkbox = rows[i].getElementsByTagName('input')[0];
		if (checkbox && checkbox.type == 'checkbox') {
			unique_id = checkbox.name + checkbox.value;
			if (checkbox.disabled == false) {
				checkbox.checked = true;
				if (typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id]) {
					rows[i].className += ' marked';
					marked_row[unique_id] = true;
				}
			}
		}
	}
}

/* Unmark all checkbox input */
function unmark_all_rows(a_id)
{
	var rows = document.getElementById(a_id).getElementsByTagName('tr');
	var unique_id;
	var checkbox;

	for (var i = 0; i < rows.length; i++ ) {
		checkbox = rows[i].getElementsByTagName('input')[0];
		if (checkbox && checkbox.type == 'checkbox') {
			unique_id = checkbox.name + checkbox.value;
			checkbox.checked = false;
			rows[i].className = rows[i].className.replace(' marked', '');
			marked_row[unique_id] = false;
		}
	}
}

/* Validate user forms */
function submit_user_form(a_id)
{
	var error = false;
	var filds = new Array();
	filds['photo_num'] = 'photo_num';
	filds['secure_code'] = 'secure_code';
	filds['user_email'] = 'user_email';
	filds['user_login'] = 'user_login';
	filds['user_password'] = 'user_password';
	filds['user_repeat_password'] = 'user_repeat_password';
	filds['user_last_name'] = 'user_last_name';
	filds['user_name'] = 'user_name';
	filds['user_patronymic'] = 'user_patronymic';
	filds['user_appointment'] = 'user_appointment';
	filds['user_street'] = 'user_street';
	filds['user_house_number'] = 'user_house_number';
	filds['user_room_number'] = 'user_room_number';
	filds['user_phone'] = 'user_phone';
	filds['user_mobile'] = 'user_mobile';

	var filds_alternative = new Array();
	filds_alternative['user_counteragent'] = 'user_counteragent';
	filds_alternative['user_departments'] = 'user_departments';

	var user_city = 'user_city';
	var user_city_alternative = 'user_city_alternative';

	if (typeof a_id !== 'undefined') {
		for (var key in filds) {
			filds[key] += '[' + a_id + ']';
		}
		user_city += '[' + a_id + ']';
		user_city_alternative += '[' + a_id + ']';
	}

	if (frm = document.getElementById('user_form')) {
		if ((delivery_method_type = document.getElementById('delivery_method')) && (delivery_method_type.value == 'point')) {
			frm.submit();
			return;
		}

		for (var key in filds) {
			if ((element = frm.elements[filds[key]]) && (element.value.length == 0)) {
				if (l_label = document.getElementById('label_' + filds[key])) {
					l_label.innerHTML = interface.must_be_not_empty;
				} else {
					alert(filds[key] + ': ' + interface.must_be_not_empty);
				}
				error = true;
			} else {
				if (l_label = document.getElementById('label_' + filds[key])) {
					l_label.innerHTML = '';
				}
			}
		}

		for (var key in filds_alternative) {
			if (
					((element = frm.elements[filds_alternative[key]]) && (element.value.length == 0))
				&&
					((element_alternative = frm.elements[filds_alternative[key] + '_alternative']) && (element_alternative.value.length == 0))
				) {
				if (l_label = document.getElementById('label_' + filds_alternative[key])) {
					l_label.innerHTML = interface.must_be_not_empty;
				} else {
					alert(filds_alternative[key] + ': ' + interface.must_be_not_empty);
				}
				error = true;
			} else {
				if (l_label = document.getElementById('label_' + filds_alternative[key])) {
					l_label.innerHTML = '';
				}
			}
		}

		if ((typeof frm.elements[filds['user_password']] !== 'undefined') && (typeof frm.elements[filds['user_repeat_password']] !== 'undefined')) {
			if (frm.elements[filds['user_password']].value != frm.elements[filds['user_repeat_password']].value) {
				if (l_label = document.getElementById('label_' + filds['user_repeat_password'])) {
					l_label.innerHTML = interface.password_fields_dont_match;
				} else {
					alert('user_repeat_password: ' + interface.password_fields_dont_match);
				}
				error = true;
			} else {
				if (l_label = document.getElementById('label_' + filds['user_repeat_password'])) {
					l_label.innerHTML = '';
				}
			}
		}

		if (typeof frm.elements[filds['user_email']] !== 'undefined') {
			var reg_email = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
			if (reg_email.test(frm.elements[filds['user_email']].value)) {
				if (l_label = document.getElementById('label_' + filds['user_email'])) {
					l_label.innerHTML = '';
				}
			} else {
				if (l_label = document.getElementById('label_' + filds['user_email'])) {
					l_label.innerHTML = interface.incorrect_email;
				} else {
					alert('user_email: ' + interface.incorrect_email);
				}
				error = true;
			}
		}

		if (typeof frm.elements[filds['user_login']] !== 'undefined') {
			var reg_login = /^([A-Za-z0-9_\-\.])+$/;
			if (reg_login.test(frm.elements[filds['user_login']].value)) {
				if (l_label = document.getElementById('label_' + filds['user_login'])) {
					l_label.innerHTML = '';
				}
			} else {
				if (l_label = document.getElementById('label_' + filds['user_login'])) {
					l_label.innerHTML = interface.use_only + ' \'A-Z\', \'a-z\', \'0-9\', \'_\', \'-\', \'.\'';
				} else {
					alert('user_login: ' + interface.use_only + ' \'A-Z\', \'a-z\', \'0-9\', \'_\', \'-\', \'.\'');
				}
				error = true;
			}
		}

		if (((element = frm.elements[user_city_alternative]) && (element.value.length == 0)) && ((element2 = frm.elements[user_city]) && (element2.value.length == 0))) {
			if (l_label = document.getElementById('label_' + user_city)) {
				l_label.innerHTML = interface.must_be_not_empty;
			} else {
				alert('user_city: ' + interface.must_be_not_empty);
			}
			error = true;
		} else {
			if (l_label = document.getElementById('label_' + user_city)) {
				l_label.innerHTML = '';
			}
		}

		if (!error) {
			frm.submit();
		}
	}
}

/* Get XML HTTP Request Object */
function get_xml_http_object()
{
	try {
		xml_http_obj = new XMLHttpRequest();
	} catch (e) {
		try {
			xml_http_obj = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xml_http_obj = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xml_http_obj;
}

function get_http_user_search()
{
	var parameters = 'user_email=' + document.getElementById('search_user_email').value + '&user_last_name=' + document.getElementById('search_user_last_name').value+ '&user_name=' + document.getElementById('search_user_name').value;
	document.getElementById('search_result').innerHTML = '<tr><td colspan="4" align="center">' + interface.search_in_progress + '</td></tr>';
	xml_http_obj = get_xml_http_object();
	xml_http_obj.open('POST', base + lang + 'ajax/search_user/', true);
	xml_http_obj.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	xml_http_obj.setRequestHeader('Content-length', parameters .length);
	xml_http_obj.setRequestHeader('Connection', 'close');
	xml_http_obj.onreadystatechange = function()
	{
		if (xml_http_obj.readyState == 4) {
			var search_result = document.getElementById('search_result');
			search_result.innerHTML = '';
			var xmlDoc = xml_http_obj.responseXML.documentElement;
			var l_root = xmlDoc.getElementsByTagName('users');
			if (xmlDoc.getElementsByTagName('status')[0].childNodes[0].nodeValue == 'true') {
				for (i=0; i<l_root.length; i++) {
					user_id = xmlDoc.getElementsByTagName('user_id')[i].childNodes[0].nodeValue;
					user_email = xmlDoc.getElementsByTagName('user_email')[i].childNodes[0].nodeValue;
					user_last_name = xmlDoc.getElementsByTagName('user_last_name')[i].childNodes[0].nodeValue;
					user_name = xmlDoc.getElementsByTagName('user_name')[i].childNodes[0].nodeValue;
					search_result.innerHTML += '<tr><td align="center"><a href="javascript:set_data_and_submit(\'form_filter\', \'filter_fields[orders_user_id]\', \'' + user_id + '\');">' + user_id + '</a></td><td>' + user_email + '</td><td>' + user_last_name + '</td><td>' + user_name + '</td></tr>';
				}
			} else {
				search_result.innerHTML += '<tr><td colspan="4" align="center">' + interface.nothing_found + '</td></tr>';
			}
		}
	}
	xml_http_obj.send(parameters);
}

function state_changed_delivery_method()
{
	if (xml_http_obj.readyState == 4) {
		var delivery_method = document.getElementById('delivery_method');
		if (xml_http_obj.responseXML.documentElement != null) {
		var xmlDoc = xml_http_obj.responseXML.documentElement;
		var l_root = xmlDoc.getElementsByTagName('order_delivery_item');
		if (xmlDoc.getElementsByTagName('order_delivery_status')[0].childNodes[0].nodeValue == 'true') {
			for (i=0; i<l_root.length; i++) {
				var new_element = document.createElement('option');
				l_id = xmlDoc.getElementsByTagName('order_delivery_id')[i].childNodes[0].nodeValue;
				l_title = xmlDoc.getElementsByTagName('order_delivery_title')[i].childNodes[0].nodeValue;
				new_element.setAttribute('value', l_id);
				new_element.appendChild(document.createTextNode(l_title));
				delivery_method.appendChild(new_element);
			}
		}
		}
		delivery_method_set();
	}
}


function get_delivery_method()
{
	var delivery_method = document.getElementById('delivery_method');
	var user_location = document.getElementById('user_city');
	delivery_method.innerHTML = '';
	xml_http_obj = get_xml_http_object();
	xml_http_obj.onreadystatechange = state_changed_delivery_method;
	xml_http_obj.open('GET', base + lang + 'order/delivery/' + user_location.value + '.html', true);
	xml_http_obj.send(null);
}

function delivery_method_set()
{
	var l_table = document.getElementById('delivery');
	var l_rows = l_table.getElementsByTagName('TR');
	var delivery_method_type =  document.getElementById('delivery_method');
	for (i = 0; i < l_rows.length; i++) {
		if ((delivery_method_type.value == 'courier') && (l_rows[i].className == 'point')) {
			l_rows[i].style.display = 'none';
		} else if ((delivery_method_type.value == 'point') && (l_rows[i].className == 'courier')) {
			l_rows[i].style.display = 'none';
		} else {
			l_rows[i].style.display = '';
		}
	}
	var user_delivery_points = document.getElementById('orders_delivery_id');
	var user_location = document.getElementById('user_city');
	user_delivery_points.innerHTML = '';
	xml_http_obj = get_xml_http_object();
	xml_http_obj.onreadystatechange = state_changed_delivery;
	xml_http_obj.open('GET', base + lang + 'order/' + delivery_method_type.value + '/delivery/' + user_location.value + '.html', true);
	xml_http_obj.send(null);
}


function state_changed_delivery()
{
	if (xml_http_obj.readyState == 4) {
		var user_delivery_points = document.getElementById('orders_delivery_id');
		var xmlDoc = xml_http_obj.responseXML.documentElement;
		var l_root = xmlDoc.getElementsByTagName('order_delivery_item');
		if (xmlDoc.getElementsByTagName('order_delivery_status')[0].childNodes[0].nodeValue == 'true') {
			for (i=0; i<l_root.length; i++) {
				var new_element = document.createElement('option');
				l_id = xmlDoc.getElementsByTagName('order_delivery_id')[i].childNodes[0].nodeValue;
				l_title = xmlDoc.getElementsByTagName('order_delivery_title')[i].childNodes[0].nodeValue;
				new_element.setAttribute('value', l_id);
				new_element.appendChild(document.createTextNode(l_title));
				user_delivery_points.appendChild(new_element);
			}
		}
	}
}

/* AJAX get http products remove */
function get_http_products_remove(a_id)
{
	if ((frm = document.getElementById('cart_poducts')) && (el = document.getElementById('products_' + a_id))) {
		frm.removeChild(el);
		if ((frm = document.getElementById('cart')) && (el = document.getElementById('cart_products_' + a_id))) {
			frm.removeChild(el);
		}
		cart_form_calc_total();
		xml_http_obj = get_xml_http_object();
		xml_http_obj.open('GET', base + lang + 'cart/products_remove/' + a_id + '.html', true);
		xml_http_obj.send(null);
	}
}

/* AJAX get http departments */
function get_http_departments(a_id)
{
	var user_counteragents = document.getElementById('user_counteragent_' + a_id);
	var user_departments = document.getElementById('user_departments_' + a_id);
	user_departments.innerHTML = '';
	if (user_counteragents.value == '') {
		var new_element = document.createElement('option');
		new_element.setAttribute('value', '');
		new_element.appendChild(document.createTextNode(interface.other));
		user_departments.appendChild(new_element);
		control_alternative_input('user_departments', a_id);
		return;
	}
	xml_http_obj = get_xml_http_object();
	xml_http_obj.onreadystatechange = state_changed_departments;
	xml_http_obj.open('GET', base + lang + 'departments/get_list/' + user_counteragents.value + '.html', true);
	xml_http_obj.send(null);
}

/* State changed of the get http departments */
function state_changed_departments()
{
	if (xml_http_obj.readyState == 4) {
		var xmlDoc = xml_http_obj.responseXML.documentElement;
		var l_root = xmlDoc.getElementsByTagName('departments_item');
		var user_id = xmlDoc.getElementsByTagName('user_id')[0].childNodes[0].nodeValue;
		var user_departments = document.getElementById('user_departments_' + user_id);
		var user_departments_hidden = document.getElementById('user_departments_hidden_' + user_id);
		if (xmlDoc.getElementsByTagName('departments_status')[0].childNodes[0].nodeValue == 'true') {
			var new_element = document.createElement('option');
			new_element.setAttribute('value', '');
			new_element.appendChild(document.createTextNode(interface.other));
			user_departments.appendChild(new_element);
			for (i=0; i < l_root.length; i++) {
				l_id = xmlDoc.getElementsByTagName('departments_id')[i].childNodes[0].nodeValue;
				l_title = xmlDoc.getElementsByTagName('departments_name')[i].childNodes[0].nodeValue;
				var new_element = document.createElement('option');
				new_element.setAttribute('value', l_id);
				new_element.appendChild(document.createTextNode(l_title));
				if (user_departments_hidden.value == l_id) {
					new_element.setAttribute('selected', 'selected');
				}
				user_departments.appendChild(new_element);
			}
			if (user_alternativ = document.getElementById('user_departments_alternative_' + user_id)) {
				user_alternativ.value = '';
				control_alternative_input('user_departments', user_id);
			}
		}
	}
}

var swfobject=function(){var b="undefined",Q="object",n="Shockwave Flash",p="ShockwaveFlash.ShockwaveFlash",P="application/x-shockwave-flash",m="SWFObjectExprInst",j=window,K=document,T=navigator,o=[],N=[],i=[],d=[],J,Z=null,M=null,l=null,e=false,A=false;var h=function(){var v=typeof K.getElementById!=b&&typeof K.getElementsByTagName!=b&&typeof K.createElement!=b,AC=[0,0,0],x=null;if(typeof T.plugins!=b&&typeof T.plugins[n]==Q){x=T.plugins[n].description;if(x&&!(typeof T.mimeTypes!=b&&T.mimeTypes[P]&&!T.mimeTypes[P].enabledPlugin)){x=x.replace(/^.*\s+(\S+\s+\S+$)/,"$1");AC[0]=parseInt(x.replace(/^(.*)\..*$/,"$1"),10);AC[1]=parseInt(x.replace(/^.*\.(.*)\s.*$/,"$1"),10);AC[2]=/r/.test(x)?parseInt(x.replace(/^.*r(.*)$/,"$1"),10):0}}else{if(typeof j.ActiveXObject!=b){var y=null,AB=false;try{y=new ActiveXObject(p+".7")}catch(t){try{y=new ActiveXObject(p+".6");AC=[6,0,21];y.AllowScriptAccess="always"}catch(t){if(AC[0]==6){AB=true}}if(!AB){try{y=new ActiveXObject(p)}catch(t){}}}if(!AB&&y){try{x=y.GetVariable("$version");if(x){x=x.split(" ")[1].split(",");AC=[parseInt(x[0],10),parseInt(x[1],10),parseInt(x[2],10)]}}catch(t){}}}}var AD=T.userAgent.toLowerCase(),r=T.platform.toLowerCase(),AA=/webkit/.test(AD)?parseFloat(AD.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):false,q=false,z=r?/win/.test(r):/win/.test(AD),w=r?/mac/.test(r):/mac/.test(AD);/*@cc_on q=true;@if(@_win32)z=true;@elif(@_mac)w=true;@end@*/return{w3cdom:v,pv:AC,webkit:AA,ie:q,win:z,mac:w}}();var L=function(){if(!h.w3cdom){return }f(H);if(h.ie&&h.win){try{K.write("<script id=__ie_ondomload defer=true src=//:><\/script>");J=C("__ie_ondomload");if(J){I(J,"onreadystatechange",S)}}catch(q){}}if(h.webkit&&typeof K.readyState!=b){Z=setInterval(function(){if(/loaded|complete/.test(K.readyState)){E()}},10)}if(typeof K.addEventListener!=b){K.addEventListener("DOMContentLoaded",E,null)}R(E)}();function S(){if(J.readyState=="complete"){J.parentNode.removeChild(J);E()}}function E(){if(e){return }if(h.ie&&h.win){var v=a("span");try{var u=K.getElementsByTagName("body")[0].appendChild(v);u.parentNode.removeChild(u)}catch(w){return }}e=true;if(Z){clearInterval(Z);Z=null}var q=o.length;for(var r=0;r<q;r++){o[r]()}}function f(q){if(e){q()}else{o[o.length]=q}}function R(r){if(typeof j.addEventListener!=b){j.addEventListener("load",r,false)}else{if(typeof K.addEventListener!=b){K.addEventListener("load",r,false)}else{if(typeof j.attachEvent!=b){I(j,"onload",r)}else{if(typeof j.onload=="function"){var q=j.onload;j.onload=function(){q();r()}}else{j.onload=r}}}}}function H(){var t=N.length;for(var q=0;q<t;q++){var u=N[q].id;if(h.pv[0]>0){var r=C(u);if(r){N[q].width=r.getAttribute("width")?r.getAttribute("width"):"0";N[q].height=r.getAttribute("height")?r.getAttribute("height"):"0";if(c(N[q].swfVersion)){if(h.webkit&&h.webkit<312){Y(r)}W(u,true)}else{if(N[q].expressInstall&&!A&&c("6.0.65")&&(h.win||h.mac)){k(N[q])}else{O(r)}}}}else{W(u,true)}}}function Y(t){var q=t.getElementsByTagName(Q)[0];if(q){var w=a("embed"),y=q.attributes;if(y){var v=y.length;for(var u=0;u<v;u++){if(y[u].nodeName=="DATA"){w.setAttribute("src",y[u].nodeValue)}else{w.setAttribute(y[u].nodeName,y[u].nodeValue)}}}var x=q.childNodes;if(x){var z=x.length;for(var r=0;r<z;r++){if(x[r].nodeType==1&&x[r].nodeName=="PARAM"){w.setAttribute(x[r].getAttribute("name"),x[r].getAttribute("value"))}}}t.parentNode.replaceChild(w,t)}}function k(w){A=true;var u=C(w.id);if(u){if(w.altContentId){var y=C(w.altContentId);if(y){M=y;l=w.altContentId}}else{M=G(u)}if(!(/%$/.test(w.width))&&parseInt(w.width,10)<310){w.width="310"}if(!(/%$/.test(w.height))&&parseInt(w.height,10)<137){w.height="137"}K.title=K.title.slice(0,47)+" - Flash Player Installation";var z=h.ie&&h.win?"ActiveX":"PlugIn",q=K.title,r="MMredirectURL="+j.location+"&MMplayerType="+z+"&MMdoctitle="+q,x=w.id;if(h.ie&&h.win&&u.readyState!=4){var t=a("div");x+="SWFObjectNew";t.setAttribute("id",x);u.parentNode.insertBefore(t,u);u.style.display="none";var v=function(){u.parentNode.removeChild(u)};I(j,"onload",v)}U({data:w.expressInstall,id:m,width:w.width,height:w.height},{flashvars:r},x)}}function O(t){if(h.ie&&h.win&&t.readyState!=4){var r=a("div");t.parentNode.insertBefore(r,t);r.parentNode.replaceChild(G(t),r);t.style.display="none";var q=function(){t.parentNode.removeChild(t)};I(j,"onload",q)}else{t.parentNode.replaceChild(G(t),t)}}function G(v){var u=a("div");if(h.win&&h.ie){u.innerHTML=v.innerHTML}else{var r=v.getElementsByTagName(Q)[0];if(r){var w=r.childNodes;if(w){var q=w.length;for(var t=0;t<q;t++){if(!(w[t].nodeType==1&&w[t].nodeName=="PARAM")&&!(w[t].nodeType==8)){u.appendChild(w[t].cloneNode(true))}}}}}return u}function U(AG,AE,t){var q,v=C(t);if(v){if(typeof AG.id==b){AG.id=t}if(h.ie&&h.win){var AF="";for(var AB in AG){if(AG[AB]!=Object.prototype[AB]){if(AB.toLowerCase()=="data"){AE.movie=AG[AB]}else{if(AB.toLowerCase()=="styleclass"){AF+=' class="'+AG[AB]+'"'}else{if(AB.toLowerCase()!="classid"){AF+=" "+AB+'="'+AG[AB]+'"'}}}}}var AD="";for(var AA in AE){if(AE[AA]!=Object.prototype[AA]){AD+='<param name="'+AA+'" value="'+AE[AA]+'" />'}}v.outerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+AF+">"+AD+"</object>";i[i.length]=AG.id;q=C(AG.id)}else{if(h.webkit&&h.webkit<312){var AC=a("embed");AC.setAttribute("type",P);for(var z in AG){if(AG[z]!=Object.prototype[z]){if(z.toLowerCase()=="data"){AC.setAttribute("src",AG[z])}else{if(z.toLowerCase()=="styleclass"){AC.setAttribute("class",AG[z])}else{if(z.toLowerCase()!="classid"){AC.setAttribute(z,AG[z])}}}}}for(var y in AE){if(AE[y]!=Object.prototype[y]){if(y.toLowerCase()!="movie"){AC.setAttribute(y,AE[y])}}}v.parentNode.replaceChild(AC,v);q=AC}else{var u=a(Q);u.setAttribute("type",P);for(var x in AG){if(AG[x]!=Object.prototype[x]){if(x.toLowerCase()=="styleclass"){u.setAttribute("class",AG[x])}else{if(x.toLowerCase()!="classid"){u.setAttribute(x,AG[x])}}}}for(var w in AE){if(AE[w]!=Object.prototype[w]&&w.toLowerCase()!="movie"){F(u,w,AE[w])}}v.parentNode.replaceChild(u,v);q=u}}}return q}function F(t,q,r){var u=a("param");u.setAttribute("name",q);u.setAttribute("value",r);t.appendChild(u)}function X(r){var q=C(r);if(q&&(q.nodeName=="OBJECT"||q.nodeName=="EMBED")){if(h.ie&&h.win){if(q.readyState==4){B(r)}else{j.attachEvent("onload",function(){B(r)})}}else{q.parentNode.removeChild(q)}}}function B(t){var r=C(t);if(r){for(var q in r){if(typeof r[q]=="function"){r[q]=null}}r.parentNode.removeChild(r)}}function C(t){var q=null;try{q=K.getElementById(t)}catch(r){}return q}function a(q){return K.createElement(q)}function I(t,q,r){t.attachEvent(q,r);d[d.length]=[t,q,r]}function c(t){var r=h.pv,q=t.split(".");q[0]=parseInt(q[0],10);q[1]=parseInt(q[1],10)||0;q[2]=parseInt(q[2],10)||0;return(r[0]>q[0]||(r[0]==q[0]&&r[1]>q[1])||(r[0]==q[0]&&r[1]==q[1]&&r[2]>=q[2]))?true:false}function V(v,r){if(h.ie&&h.mac){return }var u=K.getElementsByTagName("head")[0],t=a("style");t.setAttribute("type","text/css");t.setAttribute("media","screen");if(!(h.ie&&h.win)&&typeof K.createTextNode!=b){t.appendChild(K.createTextNode(v+" {"+r+"}"))}u.appendChild(t);if(h.ie&&h.win&&typeof K.styleSheets!=b&&K.styleSheets.length>0){var q=K.styleSheets[K.styleSheets.length-1];if(typeof q.addRule==Q){q.addRule(v,r)}}}function W(t,q){var r=q?"visible":"hidden";if(e&&C(t)){C(t).style.visibility=r}else{V("#"+t,"visibility:"+r)}}function g(s){var r=/[\\\"<>\.;]/;var q=r.exec(s)!=null;return q?encodeURIComponent(s):s}var D=function(){if(h.ie&&h.win){window.attachEvent("onunload",function(){var w=d.length;for(var v=0;v<w;v++){d[v][0].detachEvent(d[v][1],d[v][2])}var t=i.length;for(var u=0;u<t;u++){X(i[u])}for(var r in h){h[r]=null}h=null;for(var q in swfobject){swfobject[q]=null}swfobject=null})}}();return{registerObject:function(u,q,t){if(!h.w3cdom||!u||!q){return }var r={};r.id=u;r.swfVersion=q;r.expressInstall=t?t:false;N[N.length]=r;W(u,false)},getObjectById:function(v){var q=null;if(h.w3cdom){var t=C(v);if(t){var u=t.getElementsByTagName(Q)[0];if(!u||(u&&typeof t.SetVariable!=b)){q=t}else{if(typeof u.SetVariable!=b){q=u}}}}return q},embedSWF:function(x,AE,AB,AD,q,w,r,z,AC){if(!h.w3cdom||!x||!AE||!AB||!AD||!q){return }AB+="";AD+="";if(c(q)){W(AE,false);var AA={};if(AC&&typeof AC===Q){for(var v in AC){if(AC[v]!=Object.prototype[v]){AA[v]=AC[v]}}}AA.data=x;AA.width=AB;AA.height=AD;var y={};if(z&&typeof z===Q){for(var u in z){if(z[u]!=Object.prototype[u]){y[u]=z[u]}}}if(r&&typeof r===Q){for(var t in r){if(r[t]!=Object.prototype[t]){if(typeof y.flashvars!=b){y.flashvars+="&"+t+"="+r[t]}else{y.flashvars=t+"="+r[t]}}}}f(function(){U(AA,y,AE);if(AA.id==AE){W(AE,true)}})}else{if(w&&!A&&c("6.0.65")&&(h.win||h.mac)){A=true;W(AE,false);f(function(){var AF={};AF.id=AF.altContentId=AE;AF.width=AB;AF.height=AD;AF.expressInstall=w;k(AF)})}}},getFlashPlayerVersion:function(){return{major:h.pv[0],minor:h.pv[1],release:h.pv[2]}},hasFlashPlayerVersion:c,createSWF:function(t,r,q){if(h.w3cdom){return U(t,r,q)}else{return undefined}},removeSWF:function(q){if(h.w3cdom){X(q)}},createCSS:function(r,q){if(h.w3cdom){V(r,q)}},addDomLoadEvent:f,addLoadEvent:R,getQueryParamValue:function(v){var u=K.location.search||K.location.hash;if(v==null){return g(u)}if(u){var t=u.substring(1).split("&");for(var r=0;r<t.length;r++){if(t[r].substring(0,t[r].indexOf("="))==v){return g(t[r].substring((t[r].indexOf("=")+1)))}}}return""},expressInstallCallback:function(){if(A&&M){var q=C(m);if(q){q.parentNode.replaceChild(M,q);if(l){W(l,true);if(h.ie&&h.win){M.style.display="block"}}M=null;l=null;A=false}}}}}();