function $(val) {
  return document.getElementById(val);
}

function _(fname, el) {
  if (el != undefined)
    return document.forms[fname].elements[el];
  else
    return document.forms[fname];
}

function Show(obj) {
  $(obj).style.display = '';
}

function Hide(obj) {
  $(obj).style.display = 'none';
}

//Add/Remove event crossbrowser
function addEvent(obj,evt,fn) {
	if (obj.addEventListener) obj.addEventListener(evt,fn,false);
	else if (obj.attachEvent) obj.attachEvent('on'+evt,fn);
}

function removeEvent(obj,evt,fn) {
	if (obj.removeEventListener) obj.removeEventListener(evt,fn,false);
	else if (obj.detachEvent)	obj.detachEvent('on'+evt,fn);
}


//////Window functions////
function CloseWin() {
  Hide('MainWin');
  removeEvent($('MainWin'), 'click', WinClickEv);
  removeEvent(window, 'scroll', WinFixYPos);
}

function WinClickEv(e) {
  var e = e || window.event;
  var t = e.target || e.srcElement;
  if (t.id == 'MainWin') CloseWin();
}

function WinFixYPos() {
  if ($('MainWin').style.display != 'none') {
    var y = (window.scrollY) ? window.scrollY : document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
    document.getElementById('MainWin').style.top = y+'px';
  }
}

function OpenWin() {
  Show('MainWin');
  WinFixYPos();
  addEvent($('MainWin'), 'click', WinClickEv);
  addEvent(window, 'scroll', WinFixYPos);
  return false;
}

function goto(url) {
  window.location.href = url;
}

