/**
 * Created by JetBrains PhpStorm.
 * User: Mitrich
 * Date: 29.11.11
 * Time: 19:35
 * To change this template use File | Settings | File Templates.
 */
window.addEvent('domready', function()
{

    var domain_on_top = $('domain_on_top');
    if (domain_on_top)
    {
        domain_on_top.addEvent('keydown',function(e)
        {
            if((e.code == 0) || (e.code == 219) || (e.code == 221) || (e.code == 222) || (e.code == 59) || (e.code == 188) || (e.code == 190))
            {
                return true;
            }
            var clean_domain_regex = /^[a-zA-Zа-яёА-ЯЁ0-9-]$/;

            if (!clean_domain_regex.test(e.key) && e.code != 8 && e.code != 189)
            {
                if ((e.key != 'left') && (e.key != 'right'))
                {
                    e.preventDefault();
                    return false;
                }
            }
            if (e.shift && e.code == 109)
            {
                e.preventDefault();
                return false;
            }
        });
        domain_on_top.addEvent('keyup',function(e)
        {
            if (e.code == 27)
            {
                domain_on_top.set('value','');
                return false;
            }
        });

        var sub_but = $('sub_but');
        sub_but.addEvent('click',function(e)
        {
            if (domain_on_top.get('value').length >= 3)
            {
                $('top_domain_form').submit();
            } else {
                e.preventDefault();
            }
        });
    }

    var orderlink = $$('a.order_link');
    if (orderlink.length > 0)
    {
        orderlink.addEvent('click',function(e){
            if (e.target.get('href').contains('#')){
                var splitlinks = e.target.get('href').split('#');
                location.href = 'index.php?option=com_billi&view=onepage&Itemid=52&quota='+splitlinks[1];
                e.preventDefault();
            }
        });
    }
});
