function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(insertFlash);
addLoadEvent(tooltip);

function getObj(id) {
	return document.getElementById(id)
}

function inputFocus(a, b) 
{
	if (a.value == b) 
	{
		a.value = '';
	}
}

function inputBlur(a, b) 
{
	if (a.value == '') 
	{
		if (a.type == 'password') 
		{
			if (a.DisplayLabel)
			{ }
			else 
			{
				var l = document.createElement('input');
				l.type = 'text';
				l.value = b;
				l.className = a.className;
				l.PasswordInput = a;
				a.DisplayLabel = l;
				l.onfocus = function() 
				{
					this.style.display = 'none';
					this.PasswordInput.style.display = '';
					this.PasswordInput.focus();
				};
				a.parentNode.insertBefore(l, a);
			}
			a.style.display = 'none';
			a.DisplayLabel.style.display = 'inline-block';
		}
		else 
		{
			a.value = b;
		}
	}
}

function ReplaceInputType(el, newType) 
{
	var nel = document.createElement('input');
	nel.type = newType;
	nel.id = el.id;
	nel.name = el.name;
	nel.className = el.className;
	nel.onblur = el.onblur;
	el.parentNode.replaceChild(nel, el);
	nel.focus();
	nel.onfocus = el.onfocus;
	return nel;
}

function insertFlash(){
	var params = {menu:'false', wmode:'transparent', allowScriptAccess:'sameDomain'};

	if(getObj('headerFlash')) {
		swfobject.embedSWF('img/head.swf', 'headerFlash', '612', '494', '8', '', false, params, false);
	}
}

//общая функция определения координат
function getCurrentPos(eThis) {
	var current = eThis;
	var currentTop = 0;
	var currentLeft = 0;
	var currentHeight = current.offsetHeight;
	var currentWidth = current.offsetWidth;

	while (current) {
		currentLeft += current.offsetLeft;
		currentTop += current.offsetTop;
		current = current.offsetParent;
	}
	return {left:currentLeft, top:currentTop, width:currentWidth, height:currentHeight};
}

function showObj(eThis, objId) {
	var current = getCurrentPos(eThis); //координаты "родителя" объекта
	var obj = getObj(objId) ? getObj(objId) : objId; //получаем объект по ID или простой ссылке
	obj.style.left = current.left + 'px'; //координаты объекта (подменю, подсказки и т.д.) относительно "родителя" объекта
	obj.style.top = current.top + current.height + 'px';
	obj.style.display = 'block';
}

function hideObj(objId) {
	var obj = getObj(objId) ? getObj(objId) : objId;
	obj.style.display = 'none';
}

function showHiddenObj(eThis) {
	eThis.style.display='block';
}

function hideShownObj(eThis) {
	getObj(eThis) ? getObj(eThis).style.display='none' : eThis.style.display='none';
}

function tooltip() {
	var all_ = document.getElementsByTagName('*');
	for (var i=0, a=all_.length; i<a; i++){
		if (all_[i].className == 'tt') {
			if (all_[i].title) (all_[i].title = ''); //убираем title, если есть
			(function(i) {
				all_[i].onclick = function(){showObj(this, this.lastChild)}
				all_[i].onmouseout = function(){hideObj(this.lastChild)}
			})(i);
		}
	}
}


