var shtout = new Array();

function getWindowWidth() {
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
}

function getWindowHeight() {
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}

function findObj(theObj,theDoc) {
  var p, i, foundObj;
  if (!theDoc) theDoc = document;
  if ((p = theObj.indexOf("?")) > 0 && parent.frames.length) {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if (!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++)
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  return foundObj;
} // findObj

function getElementLeft(szElementName) {
  var ret_val = 0;
  obj = findObj(szElementName);
  ret_val = obj.offsetLeft;
  objHTMLelement = obj.offsetParent;
  while (objHTMLelement != null) {
    ret_val += objHTMLelement.offsetLeft;
    objHTMLelement = objHTMLelement.offsetParent;
  }
  return ret_val;
} // getElementLeft

function getElementTop(szElementName) {
  var ret_val = 0;
  obj = findObj(szElementName);
  ret_val = obj.offsetTop;
  objHTMLelement = obj.offsetParent;
  while (objHTMLelement != null) {
    ret_val += objHTMLelement.offsetTop;
    objHTMLelement = objHTMLelement.offsetParent;
  }
  return ret_val;
} // getElementTop

function toggle_bottom_menu_link(num, v) {
	el = document.getElementById('bottom_menu_link_' + num);
	if (v == 1) {
		el.style.backgroundColor = '#ffffff';
		el.style.borderColor = '#f19d42';
	}
	else {
		el.style.backgroundColor = 'transparent';
		el.style.borderColor = '#fdedc5';
	}
} // toggle_bottom_menu_link

function show_bottom_submenu(v, mx, my, mid) {
	tsm = document.getElementById("bottom_submenu_" + mid);
	if (v == 0) {
	}
	else {
		tsm.style.position = 'absolute';
		tsm.style.bottom = (getWindowHeight() - my - 2 - document.body.scrollTop) + "px";
		tsm.style.left = mx + "px";
	}
	only_toggle_bottom_submenu(v, mid);
} // show_bottom_submenu

function turn_submenu_off(mid) {
	tsm = document.getElementById("bottom_submenu_" + mid);
	tsm.style.display = 'none';
	toggle_bottom_menu_link(mid, 0);
}

function only_toggle_bottom_submenu(v, mid) {
	tsm = document.getElementById("bottom_submenu_" + mid);
	if (v == 0) {
		shtout[mid] = setTimeout("turn_submenu_off(" + mid + ")", 400);
	}
	else {
		clearTimeout(shtout[mid]);
		tsm.style.display = 'block';
		toggle_bottom_menu_link(mid, 1);
	}
} // only_toggle_bottom_submenu

function hide_all_submenus() {
	only_toggle_bottom_submenu(0, 0);
	//only_toggle_bottom_submenu(0, 1);
	only_toggle_bottom_submenu(0, 2);
	only_toggle_bottom_submenu(0, 3);
	only_toggle_bottom_submenu(0, 4);
	//only_toggle_bottom_submenu(0, 5);
}

function popup_bottom_submenu(mid) {
	l = getElementLeft('bottom_menu_link_' + mid);
	t = getElementTop('bottom_menu_link_' + mid);
	show_bottom_submenu(1, l, t, mid)
}

