﻿// ===========================================

var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
  document.onmousemove=getMouseXY;
var mX = 0;
var mY = 0;

function getMouseXY(e) {
  try {
    if (IE) { // grab the x-y pos.s if browser is IE
      mX = event.clientX + document.body.scrollLeft;
      mY = event.clientY + document.body.scrollTop;
    }  else {  // grab the x-y pos.s if browser is NS
      mX = e.pageX;
      mY = e.pageY;
    }  

  } catch(err) {
  }
  var xy = new Array();
  mX = (1 * mX);
  mY = 1 * mY;
}

// ===========================================
function getObj(id) {
  try {	
	  if (document.getElementById)
		  return document.getElementById(id);
	  else if (document.all)
		  return document.all[id];
	  else if (document.layers)
		  return document.layers[id];
  } catch(err) {
	  return null;
  }
}
// ===========================================
function hide(id) {
  var b = getObj(id);
  if (b != null) 
    b.style.display = "none";
}

function show(id) {
  var b = getObj(id);
  if (b != null) 
    b.style.display = "block";
}


// ===========================================
function pop(id, x, y, html) {
  var b = getObj(id);
  if (b != null) {
    b.style.left = x + "px";
    b.style.top = y + "px";
    b.style.height="auto";
    b.style.overflow = "hidden";
    b.style.display = "block";
    if (html != null)
      b.innerHTML = html;
  }
  return b;
}

function move(id, x, y) {
  var v = getObj(id);
  if (v != null) {
    v.style.left = x + "px";
    v.style.top = y + "px";
  }  
}

// ===========================================
function openWin(url) {
  window.open(url, '_blank','toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=1000, height=700');
}
// ===========================================
function insertAtCursor(areaID, txt, newLine) {
  var myField = getObj(areaID);
  if (newLine != null)
    txt = "\n" + txt;
    
  //IE support
  if (document.selection) {
    myField.focus();
    sel = document.selection.createRange();
    sel.text = txt;
  }
  //MOZILLA/NETSCAPE support
  else if (myField.selectionStart || myField.selectionStart == '0') {
    var startPos = myField.selectionStart;
    var endPos = myField.selectionEnd;
    myField.value = myField.value.substring(0, startPos) + txt + myField.value.substring(endPos, myField.value.length);
  } 
}
// ===========================================
function swap(id1, id2) {
  var o1 = getObj(id1);
  var o2 = getObj(id2);
  if (o1 != null && o2 != null) {
    var v = o1.value;
    o1.value = o2.value;
    o2.value = v;
  }
}

function setValue(id, val) {
  var x = getObj(id);
  if (id != null)
    x.value = val;
}
