/*
 * $Id: common.js,v 1.1 2006-05-18 15:48:37 sven Exp $
 */
if ( typeof window.eId != 'function' ) {function eId() {
	var elements = new Array();

	for (var i = 0; i < arguments.length; i++) {
	var element = arguments[i];
	if (typeof element == 'string') { element = document.getElementById(element); }

	if (arguments.length == 1) { return element; }
		elements.push(element);
	}

	return elements;
	};
}

function getTarget(e) {
	return target = e.target ? e.target : e.srcElement;
}

function newWindow(mypage,myname,w,h,features) {
	if(screen.width){
		var winl = (screen.width-w)/2;
		var wint = (screen.height-h)/2;
	}
	else{winl = 0;wint =0;}
	if (winl < 0) winl = 0;
	if (wint < 0) wint = 0;

	var settings = 'height=' + h + ',';
	settings += 'width=' + w + ',';
	settings += 'top=' + wint + ',';
	settings += 'left=' + winl + ',';
	settings += features;
	win = window.open(mypage,myname,settings);
	win.window.focus();
}

function showHideInputClear(e) {

	var target = eId('searchInput');
	var hasInput = (target.value.length > 0);
	var from 	= hasInput ? 'hide' : 'show';
	var to		= hasInput ? 'show' : 'hide';

	if (pDomApi.hasClassName(eId('searchBarClear'), from)) {
		pDomApi.showHide(eId('searchBarClear'), to, from );
	}

}

var actionAttacher = new PrezentDomApi.ActionAttacher();

pDomApi.addEvent(window,'domload', function() {

	if (eId('searchInput')) {
		pDomApi.addEvent( 'searchInput', 'keyup', showHideInputClear);
		pDomApi.addEvent( 'searchInput', 'paste', showHideInputClear);
		pDomApi.addEvent( 'searchInput', 'cut', showHideInputClear);
		pDomApi.addEvent( 'searchBarClear', 'click',
					function() {
						window.location = '/portal/info-items/filter.cmd/type=keywords/value=/';
					}
		);
	}
	actionAttacher.attach();
});
