function reportError(){
    var uri = new String(window.location);
    JsHttpRequest.query( 
        '/ajax/report.php',
        {
            error_text: $('error_text').getValue(),
            error_page: uri.toString()
        },
        function(result, debugMessages) {
            if (result.check){
                $('error_popup').hide();
            } else {
                $('captcha_text').innerHTML = 'Каптча введена верно';
                $('captcha_text').addClassName('gray');
                $('captcha_text').removeClassName('red');
                captcha = true;
                if (code){
                    eval(code);
                }
            }
        },
        function(result, debugMessages) {},
        false
    );
}


/**
* Функция переключения состояния панели header'a
*/
function toggleHeader(){
    var region = $('change_region');
    var header = $('header');
    suppress = 0;
    if (header.style.display == 'none'){
        header.show();
        region.hide();
        suppress = 0;
    } else {
        header.hide();
        region.show();
        suppress = 1;
    }
    setSession('suppress_header',suppress);
}

/**
* Функция установки переменных сессии из javascript
*/
function setSession(param,val){
    JsHttpRequest.query( 
        '/ajax/session.php',
        { 
            parametr: param, 
            value: val
        },
        function(result, debugMessages) {},
        function(result, debugMessages) {},
        false
    );
}

/**
* Функция покупки товара
*/
function buyItem(id,obj){
    JsHttpRequest.query( 
        '/ajax/orders_backend.php',
        { 
            item_id: id
        },
        function(result, debugMessages) {
            if (parseInt(result.number) >0)
            obj.innerHTML = 'Купить (в корзине '+result.number+')';
        },
        function(result, debugMessages) {},
        false
    );
}

/**
* Функция удаления купленного товара
*/
function delItem(id,obj_id){
    $(obj_id).remove();
    JsHttpRequest.query( 
        '/ajax/orders_backend.php',
        { 
            item_id: id,
            del_it: 1
        },
        function(result, debugMessages) {
            if (result.redirect){
                window.location = '/';
            }
        },
        function(result, debugMessages) {},
        false
    );
}


/**
* Функция установки переменных cookies
*/
function setCookie (name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
* Функция переключения видимости карты
*/
function showMap(){
    var map = document.getElementById('map');
    map.style.display = (map.style.display == 'none')?'':'none';
}

/**
* Функция для переключения текста и шрифта в заданном input'e
*/
function switchView(obj,text,act){
    if (act){
        if (obj.value == text){
            obj.value = '';
            obj.style.color = 'rgb(0, 0, 0)';
        }
    } else {
        if (obj.value == ''){
            obj.style.color = 'rgb(153, 153, 153)';
            obj.value = text;
        }
    }
};

/**
* Функция сокрытия плашки помощи
*/
function toggleHelpBlock(state){
    var help_block = $('help_block');
    if (state){
        help_block.style.padding = '13px 19px';
        help_block.style.height = 'auto';
        help_block.style.position = 'relative';
        help_block.style.visibility = 'visible';
        help_block.style.cursor = 'auto';
        $('question_icon').hide();
    } else {
        help_block.style.padding = '0px';
        help_block.style.height = '0px';
        help_block.style.overflow = 'hidden';
        help_block.style.visibility = 'hidden';
        help_block.style.cursor = 'default';
        //help_block.style.width = '10px';
        $('question_icon').show();
    }
    setSession('suppress_help',!state);
}

/**
* Функция для проверки правильности введенной каптчи
*/
var captcha = false;
function checkCaptcha(code){
    JsHttpRequest.query( 
        '/ajax/check_captcha.php',
        { 
            captcha: document.getElementsByName('captcha')[0].value
        },
        function(result, debugMessages) {
            if (!result.check){
                $('captcha_text').innerHTML = 'Вы ввели неверный текст!';
                $('captcha_text').addClassName('red');
                $('captcha_text').removeClassName('gray');
                captcha = false;
            } else {
                $('captcha_text').innerHTML = 'Каптча введена верно';
                $('captcha_text').addClassName('gray');
                $('captcha_text').removeClassName('red');
                captcha = true;
                if (code){
                    eval(code);
                }
            }
        },
        function(result, debugMessages) {},
        false
    );
}

/**
* Функция для ручного расширения любой
* ссылки на объект до объекта типа
* Element:extended(Prototype)
*/
function prototyper(obj){
    if (!obj.id){
        obj.id = 'new';
        obj = $(obj.id);
        obj.id = null;
    } else {
        obj = $(obj.id);
    }
    
    return obj;
}
