// -------------------------------------------------------------------
function inner_setCookie(sName, sValue, lifeTime, path, domain, isSecure) {

    if (!sName) {
	return false;
    }
    if (lifeTime == "delete") {
	//this is in the past. Expires immediately.
	lifeTime = -10;
    }
    //document.cookie = sName + "=" + escape(sValue) + ";";

    var cookie_str = escape (sName) + "=" + escape (sValue) +
	(lifeTime ? ";expires="+(new Date((new Date()).getTime()+(1000*lifeTime))).toGMTString() : "") +
	(path ? ";path="+path : "") + 
	(domain ? ";domain="+domain : "") + 
	(isSecure ? ";secure" : "")
    document.cookie = cookie_str;

    //check if the cookie has been set/deleted as required
    var is_cookie = (typeof(GetCookie(sName)) == "string");
    if (lifeTime < 0) {
	return !is_cookie;
    }
    return is_cookie;
}

// -------------------------------------------------------------------
function SetCookie (sName, sValue, lifeTime, path, domain, isSecure) {

    if (typeof lifeTime == 'undefined') {
	if (typeof cookie_time == 'string')
	    cookie_time = parseInt(cookie_time);
	if (cookie_time < 1)
	    cookie_time = 86400 * 7;
	lifeTime = cookie_time;
    } else {
	if (lifeTime == "delete") {
	    lifeTime = -10;
	}
    }

    if (typeof path == 'undefined') {
	path = cookie_root;
    }
    if (typeof domain == 'undefined') {
//	domain = cookie_domain;
    }
    if (lifeTime > 0) {
	inner_setCookie (sName, sValue, -10, path, domain, isSecure);
    }
    return inner_setCookie (sName, sValue, lifeTime, path, domain, isSecure);
}
// -------------------------------------------------------------------
function GetCookie (sName) {

    /* retrieved in the format
	cookieName4=value; cookieName3=value; cookieName2=value; cookieName1=value
	only cookies for this domain and path will be retrieved */
    var aCookie = document.cookie.split("; ");
    for (var i=0; i < aCookie.length; i++) {
	// a name/value pair (a crumb) is separated by an equal sign
	var aCrumb = aCookie[i].split("=");
	if (escape(sName) == aCrumb[0])
	    return unescape(aCrumb[1]);
    }

    // a cookie with the requested name does not exist
    return null;
}

var last_req, last_req_abort;
// -------------------------------------------------------------------
function ac_Send_Req_JH (ac_handler, req_values, post_func, container) {

    start_loading();
    try {
	var req = new JsHttpRequest();
	last_req = req; last_req_abort = false;
        req.caching = ac_cache;
	req.open ('POST', ac_handler);
	req.onreadystatechange = function() {
	    if (req.readyState != 4) return '';
	    if (last_req_abort) {
		last_req = null;
		last_req_abort = false;
		return false;
	    }
	    end_loading();
	    try {
		if (typeof req.responseJS.cookies != 'undefined') {
		    $H(req.responseJS.cookies).each(function(pair) {
			SetCookie (pair.key, pair.value);
		    });
		}
	    } catch (e2) {}
	    if (container !== null) {
		try {
		    //$(container).innerHTML = req.responseText;
		    $(container).innerHTML = req.responseJS.content;
		} catch (e2) {}
	    }
	    if (post_func !== null) {
		if (post_func.constructor != Array) {
		    //var x = post_func;
		    //post_func = new Array();
		    post_func = [post_func];
		}
		for (var i = 0; i < post_func.length; i++) {
		    //alert ('PFUNC='+post_func[i]+' ('+typeof(post_func[i])+')');
		    if (typeof post_func[i]  == 'function') {
			var x = post_func[i];
			try {
			    x (req.responseJS);
			} catch (e_post_f) {
			    if (e_post_f.description && !e_post_f.message) e_post_f.message = e_post_f.description; // for IE5
			    var msg = (e_post_f.message != null? e_post_f.message : e_post_f.toString()).replace(/^Error:\s+/g, '');
			    alert (msg);
			};
		    }
		}
	    }
	    if (container !== null) {
		try {
		    req.responseJS.content.evalScripts();
		} catch (e2) {}
	    }
	    last_req = null;
	    return true;
	}
	req.send(req_values);
    } catch (e) {
	if (e.description && !e.message) e.message = e.description; // for IE5
	var msg = (e.message != null? e.message : e.toString()).replace(/^Error:\s+/g, '');
	// Work-around for similar messages ("for ... in" iterates elements with 
	// different order in different browsers).
	msg = msg.replace(/(Element).*(belongs)/g, '$1 *** $2');
	msg = msg + (!msg.match(/^JsHttpRequest:/) && e.fileName ? '\nat ' + e.fileName + ':' + e.lineNumber : '');
	alert (msg);
	last_req = null;
	end_loading();
	return false;
    }
    //setTimeout(end_loading, 60 * 1000);
}

var g_showIndicatorTimeout;
function showIndicator() {
	g_showIndicatorTimeout = window.setTimeout(function(){
		start_loading();
	},250);
}
function hideIndicator() {
	if (g_showIndicatorTimeout)
		window.clearTimeout(g_showIndicatorTimeout);
	end_loading();
}

// -------------------------------------------------------------------
function ac_Send_Req (ac_handler, req_values, post_func, container) {

	showIndicator();
	try {
		var req = new Ajax.Request(ac_handler, {
			method: 'post',
			parameters: req_values,
			encoding: 'UTF-8',
			evalJSON: true,
			onFailure: function () {
				hideIndicator();
				if (container !== null) {
					try {
						$(container).innerHTML = 'Error load response from server';
					} catch (e2) {}
				}
				last_req = null;
				last_req_abort = false;
			},
			onSuccess: function(transport) {
				var responseJS = Object.extend({
					content: transport.responseText
				}, transport.headerJSON || {});
	
				if (last_req_abort) {
					last_req = null;
					last_req_abort = false;
					return false;
				}
				
				hideIndicator();

				if (typeof responseJS.cookies != 'undefined') {
					try {
						$H(responseJS.cookies).each(function(pair) {
							SetCookie (pair.key, pair.value);
						});
					} catch (e2) {}
				}

				if (container !== null) {
					try {
						$(container).innerHTML = responseJS.content;
					} catch (e2) {}
				}

				if (post_func !== null) {
					if (post_func.constructor != Array) {
						post_func = [post_func];
					}
					for (var i = 0; i < post_func.length; i++) {
						if (typeof post_func[i]  == 'function') {
							var x = post_func[i];
							try {
								x (responseJS);
							} catch (e_post_f) {
								if (e_post_f.description && !e_post_f.message) e_post_f.message = e_post_f.description; // for IE5
								var msg = (e_post_f.message != null? e_post_f.message : e_post_f.toString()).replace(/^Error:\s+/g, '');
								alert (msg);
							};
						}
					}
				}

				if (container !== null) {
					try {
						//var js_scripts = responseJS.content.extractScripts();
						//js_scripts.map (function(script) { return globalEval(script); });
						responseJS.content.evalScripts();
					} catch (e2) {}
				}
				last_req = null;
				return true;
			}
		}); 

		last_req = req; last_req_abort = false;

	} catch (e) {
		if (e.description && !e.message) e.message = e.description; // for IE5
		var msg = (e.message != null? e.message : e.toString()).replace(/^Error:\s+/g, '');
		alert (msg);
		last_req = null;
		hideIndicator();
		return false;
	}
	//setTimeout(end_loading, 60 * 1000);
}

// -------------------------------------------------------------------
function serializeForm (form_name) {

    var v;
    try {
	v = Form.Methods.serialize(form_name, true);

	// Insert unchecked checkboxes as empty values
	Form.Methods.getElements(form_name).each (function (element) {
	    if (!element.disabled && element.name && 
		element.type.toLowerCase() == 'checkbox' &&
		v[element.name] === undefined) {
		v[element.name] = '';
	    }
	});
    } catch (e) {
	v = new Array();
    }
    return v;
}
// -------------------------------------------------------------------
function ac_Submit_Form (ac_handler, form_name, pre_func, post_func, container) {

    var v = serializeForm(form_name);
    if (typeof pre_func == 'function') {
	try {
	    pre_func (v);
	} catch (e_post_f) {};
    }

    return ac_Send_Req (ac_handler, v, post_func, container);
}


// -------------------------------------------------------------------
function globalEval (code) {

    if (window.execScript) {
	window.execScript(code);
	return null;
    } else return (window.eval ? window.eval(code) : eval(code));
}
// -------------------------------------------------------------------
// -------------------------------------------------------------------
function show_hide (what) {
    var obj, obj1, lbox_head;
    if (what.tagName == "A") {
	lbox_head = what.parentNode;
	obj1 = lbox_head.parentNode;
    } else {
	obj1 = what.parentNode;
	lbox_head = what;
    }
    var boxid;
    boxid = obj1.id;
    for (var i=0; i < obj1.childNodes.length; i++) {
	if (obj1.childNodes[i].nodeType==1 && obj1.childNodes[i].className == "box_body") {
	    obj = obj1.childNodes[i];
	    break;
	}
    }
    // obj= //this must be div

    if (obj) {
	if (obj.style.display != 'none') {
	    SetCookie ("state_"+boxid, "0");
	    lbox_head.className = 'lbox_head_off';
	} else {
	    SetCookie ("state_"+boxid, "1");
	    lbox_head.className = 'lbox_head_on';
	}
	Effect.Phase (obj, {duration:0.4});
    }
}

// -------------------------------------------------------------------
function langs_scroll (dir) {

    var cont = $('langs_cont');
    var cur_scroll = cont.scrollLeft;
    var lp = $('lang_panel').lastChild;
    var new_scroll = 0, scroll_w = cont.getDimensions().width;
    if (dir == 0) {
	new_scroll = (cur_scroll > scroll_w ? cur_scroll - scroll_w : 0);
    } else {
	var w = 0;
	while (lp !== null) {
	    if (lp.offsetLeft !== undefined && lp.offsetLeft !== null && lp.offsetLeft > 0) {
		w = lp.offsetLeft + lp.offsetWidth;
		break;
	    }
	    lp = lp.previousSibling;
	}
	new_scroll = (cur_scroll + 2*scroll_w >= w ? (w > scroll_w ? w-scroll_w : cur_scroll) : cur_scroll + scroll_w);
    }
    if (new_scroll != cur_scroll)
	new Effect.Scroll (cont, {x: new_scroll, y: 0, duration: 0.3})
    return false;
}
			        																			                    	    
// -------------------------------------------------------------------
function langs_scroll_to (lang) {

    var vis_lang = $('a_flag_'+lang);
    if (vis_lang === null)
	return false;

    var cont = $('langs_cont');
    var cur_scroll = cont.scrollLeft;
    var new_scroll = 0, scroll_w = cont.getDimensions().width;
    var w = 0;
    var lp = $('lang_panel').lastChild;
    while (lp !== null) {
	if (lp.offsetLeft !== undefined && lp.offsetLeft !== null && lp.offsetLeft > 0) {
	    w = lp.offsetLeft + lp.offsetWidth;
	    break;
	}
	lp = lp.previousSibling;
    }
    
    var n_p = vis_lang.offsetLeft + Math.round(vis_lang.offsetWidth/2 - scroll_w/2);
    if (n_p < 0) {
	n_p = 0;
    } else if ((n_p + scroll_w) > w)
	n_p = (w - scroll_w);

    cont.scrollLeft = n_p;
//    new Effect.Scroll (cont, {x: n_p, y: 0, duration: 0.2})
    return false;
}
			        																			                    	    
// -------------------------------------------------------------------
function RestoreBoxes () {

try {
    var cont = document.getElementById ('leftcol');
    var d, z, obj1, boxid, j=0;
    if (cont) {
	for (var i=0; i < cont.childNodes.length; i++) {
	    if (cont.childNodes[i].nodeType==1 && cont.childNodes[i].className=="lbox") {
		obj1 = cont.childNodes[i];
		d = GetCookie ("state_" + obj1.id);
		for (z=0; z < obj1.childNodes.length; z++) {
		    if (obj1.childNodes[z].nodeType==1 && (obj1.childNodes[z].className=="lbox_head_on" || obj1.childNodes[z].className=="lbox_head_off")) {
	    		obj1.childNodes[z].className = 'lbox_head_' + (d=="0" ? "off" : "on");
		    }
		    if (obj1.childNodes[z].nodeType==1 && obj1.childNodes[z].className=="box_body") {
			obj1.childNodes[z].style.display = (d == "0" ? 'none' : '');
		    }
		}
	    }
	}
    }
    var lcv = GetCookie("leftcol_visible");
    if (lcv=="false") {
	Element.hide ('leftcol');
	Element.hide ('page_header');
	set_lc_hidden();
    } else {
	Element.show ('leftcol');
	Element.show ('page_header');
	set_lc_visible();
    }
} catch (e) {}
}

// -------------------------------------------------------------------
function set_lc_hidden () {
	$('separator').className = 'cl_closed';
	$('img_separator').src = img_root+'menu/cl_right.gif';
}

// -------------------------------------------------------------------
function set_lc_visible () {
	$('separator').className = 'cl_open';
	$('img_separator').src = img_root+'menu/cl_left.gif';
}

// -------------------------------------------------------------------
function hide_left_bar() {

	try { $('x_copyright').hide();} catch(e){}
	new Effect.BlindUp ('page_header', {
		transition: Effect.Transitions.sinoidal,
		duration: 0.4
	});
	new Effect.BlindOutLeft ('leftcol', {
		transition: Effect.Transitions.sinoidal,
		duration: 0.4,
		afterFinish: function () {
			set_lc_hidden ();
			SetCookie ("leftcol_visible", false);
		}
	});
}

// -------------------------------------------------------------------
function show_left_bar () {

	new Effect.BlindInLeft ('leftcol', {
		transition: Effect.Transitions.sinoidal,
		duration: 0.4,
		afterFinish: function () {
			set_lc_visible();
			SetCookie ("leftcol_visible", true);
			try { $('x_copyright').show();} catch(e){}
		}
	});
	new Effect.BlindDown ('page_header', {
		transition: Effect.Transitions.sinoidal,
		duration: 0.4
	});
}

// -------------------------------------------------------------------
function showhide_left_bar () {

    if(Element.visible ('leftcol')) {
	hide_left_bar ('leftcol');
    } else {
	show_left_bar ('leftcol');
    }
}

// -------------------------------------------------------------------
//RestoreBoxes('leftcol');
// -------------------------------------------------------------------
function ChangeLocation (url) {
    if (typeof url == 'undefined' || url == '') {
	url = location.href;
    }
    location.href = url;
}

// -------------------------------------------------------------------
function encode_pass (values) {
	values.logon_password = hex_md5(hex_md5(values.logon_password) + values.logon_challenge);
}

function encode_reg_pass (values) {

    if (values['reg_data[password]'].length != 0) {
	values['reg_data[password]'] = hex_md5(values['reg_data[password]']);
    }
    if (values['reg_data[password2]'].length != 0) {
	values['reg_data[password2]'] = hex_md5(values['reg_data[password2]']);
    }
}
// -------------------------------------------------------------------
function select_all (sel_name, checked, action_panel) {

    inps = document.getElementsByTagName ('input');
    var cnt = 0;
    for (i = 0; i < inps.length; i++) {
	if (inps[i].getAttribute('name') == sel_name && inps[i].type == 'checkbox') {
	    inps[i].checked = checked;
	    cnt++;
	}
    }
    check_selected (sel_name, action_panel);
}
    
// -------------------------------------------------------------------
function check_selected (sel_name, action_panel) {

    inps = document.getElementsByTagName ('input');
    var cnt = 0;
    for (i = 0; i < inps.length; i++) {
	if (inps[i].getAttribute('name') == sel_name && inps[i].type == 'checkbox' && inps[i].checked) {
	    cnt++;
	}
    }
    try {
	var x = $(action_panel);
	if (cnt > 0 && x !== null)
	    x.show();
	    else x.hide();
    } catch (e) {};
    return (cnt > 0);
}
// -------------------------------------------------------------------
function get_selected (sel_name) {

    var res = [];
    inps = document.getElementsByTagName ('input');
    var cnt = 0;
    for (i = 0; i < inps.length; i++) {
	if (inps[i].getAttribute('name') == sel_name && inps[i].type == 'checkbox' && inps[i].checked) {
	    res.push(inps[i].value);
	    cnt++;
	}
    }
    return (cnt > 0 ? res : false);
}
// -------------------------------------------------------------------

function getElementsByRegExp (name, tag) {

    if (tag === undefined || tag === null || tag.length == 0)
	tag = '*';
    var t = new RegExp(name);
    var list = document.getElementsByTagName(tag);
    var res = [];
    for (var i = 0; i < list.length; i++) {
	if (list[i].id.length > 0 && t.test(list[i].id))
	    res.push (Element.extend(list[i]));
    }
    return res;
}


// -------------------------------------------------------------------


// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.com
// Edit for Firefox by pHaez
//
function get_page_size() {
	
    var xScroll, yScroll;
	
    if (window.innerHeight && window.scrollMaxY) {	
	xScroll = window.innerWidth + window.scrollMaxX;
	yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
	xScroll = document.body.scrollWidth;
	yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
	xScroll = document.body.offsetWidth;
	yScroll = document.body.offsetHeight;
    }
	
    var windowWidth, windowHeight;
	
    if (self.innerHeight) {	// all except Explorer
	if (document.documentElement.clientWidth) {
	    windowWidth = document.documentElement.clientWidth; 
	} else {
	    windowWidth = self.innerWidth;
	}
	windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
	windowWidth = document.documentElement.clientWidth;
	windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
	windowWidth = document.body.clientWidth;
	windowHeight = document.body.clientHeight;
    }	
	
    // for small pages with total height less then height of the viewport
    pageHeight = (yScroll < windowHeight ? windowHeight : yScroll);
    //console.log("xScroll " + xScroll)

    // for small pages with total width less then width of the viewport
    pageWidth = (xScroll < windowWidth ? xScroll : windowWidth);

    return new Array(pageWidth,pageHeight,windowWidth,windowHeight);
}


// -------------------------------------------------------------------
function start_loading () {

    try {
	var arrayPageSize = get_page_size();
	var objOverlay = $('am_overlay');
	if (objOverlay == null) {
	    var objBody = document.getElementsByTagName("body").item(0);
	
	    objOverlay = $(document.createElement("div"));
	    objOverlay.setAttribute('id','am_overlay');
	    objOverlay.setStyle ({
		position: 'fixed',
		left: '0px',
		top: '0px',
		zIndex: 999,
		backgroundColor: '#fff',
		width: '100%',
		height: '100%'
	    });
	    objOverlay.onclick = function() { end_loading(); }
	    objBody.appendChild(objOverlay);
	}

	var objContent = $('am_overlay_content');
	if (objContent == null) {
	    var div1_w = 325;
	    objContent = $(document.createElement("div"));
	    objContent.setAttribute('id','am_overlay_content');
	    objContent.setStyle ({
		position: 'fixed',
		backgroundColor: '#fff',
		padding: '3px',
		zIndex: 1000,
		width: div1_w +'px'
	    });
	    //objOverlay.onclick = function() { end_loading(); }
	    objBody.appendChild(objContent);
	}
	objContent.setStyle ({
		left: Math.round((arrayPageSize[0] - div1_w) / 2)+'px',
		top: Math.round(arrayPageSize[1] / 2 - 60)+'px'
	});

	objContent.innerHTML = 
	    "<div style=\"border:1px solid #C0C0C0;padding:3px;\">"+
		"<div style=\"background: url("+img_root+"dialog_bg.jpg) top left repeat-y;padding-left:83px;height:100%;color:#000;\">" +
		    "<div style=\"color:#7F7F7F;font-size:14px;font-weight:900;\"><img width=\"30\" height=\"30\" alt=\"\" src=\""+img_root+"load/load.gif\" style=\"margin-right:10px;vertical-align:middle;\"/>"+js_texts['Wait']+"...</div>"+
		    "<br />"+
		    js_texts['Load data...']+
		    "<br />"+
		    "<div align=\"right\" class=\"buttonBar\">" +
			"<input type=\"button\" class=\"button\" onclick=\"cancel_loading();\" value=\""+js_texts['Cancel']+"\"/>" +
		    "</div>" +
		"</div>" +
	    "</div>";

	objOverlay.setOpacity(0.0);
	new Effect.Appear('am_overlay', { duration: 0.2, from: 0.0, to: 0.5 });
	objContent.show();
    } catch(e) {};
}

// -------------------------------------------------------------------
function indicator_resize () {

    var objOverlay = $(string_edit_overlay_name);
    if (objOverlay !== null) {
	var arrayPageSize = get_page_size();
	objOverlay.setStyle ({
	    width: arrayPageSize[0]+'px',
	    height: arrayPageSize[1]+'px'
	});
    }
}
// -------------------------------------------------------------------
function end_loading() {

    try {
	new Effect.Fade('am_overlay_content', { duration: 0.1});
	new Effect.Fade('am_overlay', { duration: 0.1});
    } catch(e) {};
}
// -------------------------------------------------------------------
function cancel_loading() {

    end_loading();
    try {
	if (typeof last_req !== 'undefined' && last_req !== null) {
	    last_req_abort = true;
	    last_req.abort();
	}
	last_req = null;
    } catch(e) {};
}
// -------------------------------------------------------------------
function isEmpty (object) {
	var t = typeof(object);
	return (t == 'undefined' || object === null || (t == 'string' && object == ''));
}
function isEmptyS (object) {
	var t = typeof(object);
	return (t == 'undefined' || object === null || (t == 'string' && object == ''));
}
function isEmptyA (object) {
	var t = typeof(object);
	return (t == 'undefined' || object === null || (object instanceof Array && object.length == 0));
}

function ltrim (value, charlist) {
	charlist = (typeof(charlist) == 'undefined' ||charlist === null || charlist.length == 0 ? '\\s' : RegExp.escape(charlist));
	var re = new RegExp('[' + charlist + ']+$');
	return value.replace(re, '');
}

function rtrim (value, charlist) {
	charlist = (typeof(charlist) == 'undefined' ||charlist === null || charlist.length == 0 ? '\\s' : RegExp.escape(charlist));
	var re = new RegExp('^[' + charlist + ']+');
	return value.replace(re, '');
}

// Removes leading and ending whitespaces
function trim (value) {
	return ltrim(rtrim(value));
}

function append_gets (link, v) {

	return link + 
		((/.*\?/).test(link) ? '&' : '?') + 
		(typeof(v) == 'object' ? $H(v).toQueryString() : v);
}

function localize_url (url) {

    if (/^https?:\/\//.test(url)) {
	url = url.replace (/^https?:\/\/[^\/]*/, '');
    }
    url = url.replace (new RegExp('^' + ac_root.replace(/\//g, '\\/')), '');
    return url;
}

function getInt (v) {
    var x = parseInt (v);
    if (isNaN(x))
	x = 0;
    return x;
}

function getFloat (v) {
    var x = parseFloat (v);
    if (isNaN(x))
	x = 0;
    return x;
}

// Round float to prec sign after point
function fRound (fl, prec) {
    return Math.round(fl * Math.pow(10,prec)) / Math.pow(10,prec);
}

function toQPair (key, value) {
    if (Object.isUndefined(value)) return key;
    return key + '=' + encodeURIComponent(String.interpret(value));
}

// -------------------------------------------------------------------
function edit_image (img_id) {

	var cur_val = $(img_id);
	if (cur_val !== null) {
		cur_val = cur_val.value;
	} else cur_val = '';

	fm = new OpenModal({
		opacity: 0.6,
		width: 785,
		height: 460,
		title: 'File manager',
		url: append_gets(fm_url, {
			hef_file: cur_val,
			hef_ret_id: img_id,
			is_editor: 0
		}),
		iframe: true,
		open: true
	});
}
function edit_image_clear (img_id) {

	var img = $(img_id);
	if (img !== null) {
		img.value = '';
	}
	img = $(img_id+'_image');
	if (img !== null) {
		img.src = '';
		if (img.visible())
			img.hide();
	}
}

function imgedit_chg_lang(elem) {

    var o_l = parseInt($(elem+'_clang').value);
    var n_l = parseInt($(elem+'_lang').value);
    $(elem+'_clang').value = n_l;
    $(elem+'_icnt'+o_l).hide();
    $(elem+'_icnt'+n_l).show();
}

function select_file (file_id) {

	var cur_val = $(file_id);
	if (cur_val !== null) {
		cur_val = cur_val.value;
	} else cur_val = '';

	fm = new OpenModal({
		opacity: 0.6,
		width: 785,
		height: 460,
		title: 'File manager',
		url: append_gets(fm_url, {
			hef_file: cur_val,
			ftype: 'file',
			hef_ret_id: file_id,
			is_editor: 0
		}),
		iframe: true,
		open: true
	});
}

function select_file_clear (file_id) {

	var file = $(file_id);
	if (file !== null) {
		file.value = '';
	}
}

// -------------------------------------------------------------------

Event.observe (window, 'load', RestoreBoxes);

