function formCountLetter(obj, max) {
    num = max - obj.value.length;
    if (num < 20)  {num = "<span style='color: red;'>" + num + "</span>";}
    document.getElementById(obj.id + "Msg").innerHTML = "Осталось симовлов: " + num; 
}

function formFocus(obj) {
    $('indicator_' + obj.id).style.visibility = "hidden";
}

function formFieldValide(obj, capcha_td) {
    if(typeof(capcha_td)=='undefined') capcha_td = false;
    var id = obj.id;
    var url = document.location.pathname.replace(/\//, "_");
    url =  '/ajax/' + url + '/valid/' + id + '/';
    var req = new Ajax.Request(url, {
            method: 'post',
            parameters: id + "=" + encodeURIComponent(obj.value),
            onSuccess: function(transport){
                if(capcha_td) {
                    var updateAtea = $('indicator_' + id).parentNode;
                } else {
                    var updateAtea = $('indicator_' + id).parentNode;
                }
                if(transport.responseText!='')
                    updateAtea.innerHTML = transport.responseText;
                    
                if (transport.responseText.search(/true\.gif/i) == -1) {
                    //$(id).style.backgroundColor = "#";
                } else {
                    $(id).style.filter = 'alpha(opacity=50)';
                    $(id).style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=50)';
                    $(id).style.opacity = '0.5';
                }
            }
        });
    var str = '<img src="/img/indicator.gif" style="vertical-align: top;" width=20 height=20>';
    $('indicator_' + id).innerHTML = str;
    $('indicator_' + id).style.visibility = "visible";
}

function regouthit(siteId) {
	var url = '/main/regouthit/' + siteId;
	new Ajax.Request(url, {
		method: 		'get',
		asynchronous:	false
	});
	return true;	
}

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}
function trims(str) {
    return trim(str, ' \t\n\r\0\x0B');
}
function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
