if (top.location.href && location.href != top.location.href && (!/.*(?:facebook|wavxeconnect|winwithtoshiba).*/i.test(top.location.href))) {
	top.location.replace(location.href);
}


window.addEvent('domready', function () {

    // toshiba logo
    $$('#masthead p').addEvent('click', function () {
        window.open('/home', '_self');
    });

    // global search
    if ($('submit')) {
        $('submit').addEvent('click', function (e) {
            e.stop();
            var value = $('q').get('value').trim();
            if (value.length > 0) {
                //window.open('/search/' + value.replace(' ','_').replace('/','_').replace('\\','_') , '_self');
                //window.open('/search/?q=' + value);
                window.location = '/search/?q=' + value;
            }
        });
    }

    // fix navigation hover
    if (Browser.Engine.trident4) { // ie6
        var select = $$('body.support div.wide #filters select');
        $('navigation').getElements('ul.menu>li').addEvents({
            'mouseenter': function () {
                this.addClass('hover');
                if (this.id.contains('green-toshiba'))
                    select.setStyle('visibility', 'hidden');
            },
            'mouseleave': function () {
                this.removeClass('hover');
                if (this.id.contains('green-toshiba'))
                    select.setStyle('visibility', 'visible');
            }
        });
    }

    // apply sub-menu opacity
    if (!(document.querySelectorAll && Browser.Engine.trident)) {
        if ($('navigation'))
            $('navigation').getElements('ul.menu ul').setOpacity(0.85); // todo: only apply to first child
    }

    $$('div.buttons a.print').addEvent('click', function (e) {
        window.print();
    });

    // popup [intel]
    if ($('body')) {
        $('body').getElements('a[rel^=popup][rel*=intel]').addEvent('click', function (e) {
            e.preventDefault(); e.stopPropagation();
            new IntelPopup(this);
        });
    }

});

var IntelPopup = new Class({
    Extends: Popup,
    initialize: function(item) {
        this.parent(item.href, { window: { height: 220, width: 360, resizable: true }});
    }
});

function SubmitOnEnter(field, e) {
    var keycode;

    if (window.event) 
        keycode = window.event.keyCode;
    else if (e)
        keycode = e.which;
    else 
        return true;

    if (keycode == 13) {
        var searchPath = '/search/';
		//if (location.pathname.indexOf(searchPath) != -1) searchPath = location.pathname;
        //window.location = searchPath + field.value.replace('/','_').replace('\\', '_').replace(' ', '_');
        window.location = searchPath + '?q=' + field.value;
        return false;
    }
    else
        return true;
}

