
// behaviour rules
var rules = {
    '#go' : function(element){
        element.onclick     = function () {
            var val    = $('value').value;
            if(val){
                window.location = '/items/search/' + encodeURI(val);
                return;
            }
            return false;
        }
    },
    '#value' : function(element){
        element.onkeydown    = function (event) {
            if(event.keyCode == 13){
                window.location = '/items/search/' + encodeURI(this.value);
                return;
            }
        }
    },
    'a'   : function(element){
        element.onfocus = function(event) {
            this.blur();
        }
    },
    '#f'   : function(element){
        element.onsubmit = function(event) {
            if($('p1').value != $('p2').value){
                alert('Passwords Don\'t Match.');
                $('p1').focus();
                return false;
            }
            
            var c = $('userCardNumber');
            
            if(c.value.length == 9 && c.value.substr(0,5) == 'XXXX '){
            	alert('Please enter your Credit Card information.');
            	c.focus();
            	return false;
            }
            
            return true;
        }
    },
    '#p'   : function(element){
        element.onclick = function(event) {
            if($('p1').value != $('p2').value){
                alert('Passwords Don\'t Match.');
                $('p1').focus();
                return false;
            }
            return true;
        }
    },
    '.animal'   : function(element){
        element.onclick = function(event) {
            var k = window.open(
                this.href,
                'animal',
                'width=400,height=300,scrollbars=auto'
                );
            k.focus();
            return false;
        }
    },
    '.close'   : function(element){
        element.onclick = function(event) {
            window.close();
        }
    }
};

Behaviour.register(rules);
