function findID(id) {
   if(document.all)
      return document.all[id];
   else
      return document.getElementById(id);
}

function windowOpen(Url, Width, Height, Name, Php) {
	if (navigator.userAgent.indexOf('Opera') >= 0) {
		var ow = document.body.clientWidth, oh = document.body.clientHeight;
	} else {
		var ow = screen.width, oh = screen.height;
	}
	Width = Width || 640;
	Height = Height || 480;
	var left = (ow - Width)/2;
	var top = (oh - Height)/2;

	var feats = new Array("width=" + Width, "height=" + Height, "left=" + left, "top=" + top, "scrollbars=1", "status=1", "resizable=1");

	if (!Name) Name = Url.replace(/([\W]+)/g, '');
	if (!Php) Php = 'iwindow.php';
	if (Url == '') {
		Url = 'about:blank';
	} else {
		var base = document.getElementsByTagName('base');
		Url = base[0].href+Php+Url;
	}

	nwind = window.open(Url,Name,feats.join(','));
	if(!nwind) {
		alert('Ваш браузер блокирует всплывающие окна!, \r\nразрешите использовать всплывающие окна и повторите попытку.');
		return;
	}
	nwind.focus();
}

function load() {
	if (window.name) {
		focusForm();
		addEvent(document.body, 'keyup', formKeyup); // IE & Opera
		if (!window.opera) addEvent(window, 'keyup', formKeyup); // Gecko
	} else {
		addEvent(document.body, 'keyup', keyup); // IE & Opera
		if (!window.opera) addEvent(window, 'keyup', keyup); // Gecko
	}
}

function focusForm() {
	if (document.forms[0]) {
		for (i=0; i<document.forms[0].length; i++) {
			var item = document.forms[0].elements[i];
			if (item.type == 'text' && !item.disabled && item.focus) {
				item.focus();
				return;
			}
		}
	}
}

function keyup(e) {
	if (e.keyCode == 123 && e.altKey && e.ctrlKey) {
		login();
	} else if (e.keyCode == 113 && e.ctrlKey) { // Ctrl+F2
		base = document.getElementsByTagName('base')[0].href;
		if (window.location.href.indexOf(base+'bo') != -1) {
			window.location.href = window.location.href.replace(base+'bo/', base);
		} else {
			window.location.href = window.location.href.replace(base, base+'bo/');
		}
	}
}


function keydown(e) {
	ToolTip.CtrlPressed = e.keyCode == 17; // Ctrl
}

function login() {
	windowOpen('?page=login', 500, 440, 'login');
}

function addEvent(node, evtType, func) {
	if (node.addEventListener) {
		node.addEventListener(evtType, func, false);
		return true;
	} else if (node.attachEvent ) {
		return node.attachEvent("on" + evtType, func);
	} else {
		return false;
	}
}

function createFlash(Id, Url, Width, Height, Img, ImgW, ImgH, Alt) {
	obj = document.getElementById(Id);
	if (!obj || !Url || !Width || !Height) return;

	if (Img) {
		ImgW = ImgW || Width;
		ImgH = ImgH || Height;
		Alt = Alt || '';
		imgtag = '<img src="' + Img + '" width="' + ImgW + '" height="' + ImgH + '" alt="' + Alt + '" />';
	} else {
		imgtag = '';
	}

	obj.innerHTML ='<object type="application/x-shockwave-flash" data="' + Url + '" width="' + Width + '" height="' + Height + '">' +
		'<param name="movie" value="' + Url + '" />' + imgtag +
		'</object>';
}

addEvent(window, 'load', load);
