window.onload = function () {
  var ee = document.getElementsByTagName("a"), i, sh;
  for (i = 0; i < ee.length; i++) {
    sh = ee[i].href ? ee[i].href : ""; 
    if (/\/(feedback|courier|callback)\/$/.test(sh)) {
//      ee[i].onclick = popupFormOpen;
      ee[i].onclick = function () {return true;};
    }
  }
//  document.getElementsByTagName("body")[0].onclick = onBodyClick;
}

function onBodyClick (e) {
  e = e ? e : window.event;
  var coord = mousePageXY(e);
  hideform2("feedback", coord);
  hideform2("courier", coord);
  hideform2("callback", coord);
}

function popupFormOpen (e) {
  e = e ? e : window.event;
  var re = /\/(feedback|courier|callback)\/$/,
      am = this.href.match(re),
      coord = mousePageXY(e);
  if (am[1]) {
    showform(am[1], coord);
    return false;
  }
}

function mousePageXY(e)
{
  var x = 0, y = 0;
  if (!e) e = window.event;
  if (e.pageX || e.pageY)
  {
    x = e.pageX;
    y = e.pageY;
  }
  else if (e.clientX || e.clientY)
  {
    x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
    y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
  }
  return {"x":x, "y":y};
}

function showform(formid, coord)
{
	var elem = document.getElementById(formid);
	if (!coord) {
	  coord = getMousePosition();
	}
	elem.style.top=coord.y+"px";
	elem.style.left=coord.x+"px";
	elem.style.display='block';
}

function hideform(formid)
{
  
	var elem = document.getElementById(formid);
	elem.style.display='none';
	
}

function hideform2(formid, mousecoord)
{
  
	var elem = document.getElementById(formid);
	if (elem!=null && elem.style.display == 'block') 
	{
		if (!mousecoord) {
		  mousecoord=getMousePosition();
		}  
		x0=elem.offsetLeft;
		x1=x0+elem.offsetWidth;
		y0=elem.offsetTop;
		y1=y0+elem.offsetHeight;
		inform=false;
		if ((mousecoord.x>x0 && mousecoord.x<x1 && mousecoord.y>y0 && mousecoord.y<y1) || (mousecoord.x==x0 && mousecoord.y==y0)) inform=true;
		if (!inform) elem.style.display='none';
	}

}

function window_open(url, win_width, win_height) {
	var screen_width = window.screen.width;
	var screen_height = window.screen.height;
	var win_left = screen_width / 2 - win_width / 2;
	var win_top = screen_height / 2 - win_height / 2;
	var win = window.open(url, "popup", "width=" + win_width + ", height=" + win_height + ", scrollbars=1, location=0, menubar=0, resizable=0, status=0, titlebar=0, toolbar=0, screenX=100, left=" + win_left + ", screenY=30, top=" + win_top);
	win.focus();
}

function popupWindow(w, h) {
	var sw = window.screen.width;
	var sh = window.screen.height;
	var l = sw / 2 - w / 2;
	var t = sh / 2 - h / 2;
	window.resizeTo(w, h);
	window.moveTo(l, t);
}

function viewBlock(name, obj) {
	var elems = document.getElementsByName(obj.name);
	var viewAll = false;
	for (var i = 0; i < elems.length; i += 1) {
		if (elems[i].checked) {
			viewAll = true;
			break;
		}
	}
	var elems = document.getElementsByName(name);
	if (!viewAll) {
		return;
	}
	switch (name) {
		case 'written':
			break;
		case 'verbal':
			break;
	}
}

