﻿
// 
//-----------------------------------------------------------------
//  FileName            : util.js
//-----------------------------------------------------------------
//  Project             : AIGM
//  Language            : Javascript
//  Author              :
//  Date of creation    :
//-----------------------------------------------------------------
//  Contains utility functions.
//
//-----------------------------------------------------------------


var writer=null;

//var vehicleAXObject=new ActiveXObject("Scripting.FileSystemObject"); 
//writer= vehicleAXObject.OpenTextFile("C:\\aa2.txt",2,false);   

function getPageEventCoords(evt) {
    var coords = {left:0, top:0};
    if (evt.pageX) {
        coords.left = evt.pageX;
        coords.top = evt.pageY;
    } 
    else if (evt.clientX) {
        coords.left =
        evt.clientX + document.body.scrollLeft - document.body.clientLeft;
        coords.top = evt.clientY + document.body.scrollTop - document.body.clientTop;
        if (document.body.parentElement && document.body.parentElement.clientLeft) {
            var bodParent = document.body.parentElement;
            coords.left += bodParent.scrollLeft - bodParent.clientLeft;
            coords.top += bodParent.scrollTop - bodParent.clientTop;
        }
    }
    return coords;
}



function dumpProps(obj, parent) {

   // Go through all the properties of the passed-in object
   for (var i in obj) {
      // if a parent (2nd parameter) was passed in, then use that to
      // build the message. Message includes i (the object's property name)
      // then the object's property value on a new line
      if (parent) { var msg = parent + "." + i + "\n" + obj[i]; } else { var msg = i + "\n" + obj[i]; }
      // Display the message. If the user clicks "OK", then continue. If they
      // click "CANCEL" then quit this level of recursion
    //  writer.writeLine(msg);
    alert(msg);
      // If this property (i) is an object, then recursively process the object
      if (typeof obj[i] == "object") {
         if (parent) { dumpProps(obj[i], parent + "." + i); } else { dumpProps(obj[i], i); }
      }
   }
}

function getYOfElement( oElement )
{
    var iReturnValue = 0;
    while( oElement != null ) {
    iReturnValue += oElement.offsetTop;
    oElement = oElement.offsetParent;
    }
    return iReturnValue;
}

function getXOfElement( oElement )
{
    var iReturnValue = 0;
    while( oElement != null ) {
    iReturnValue += oElement.offsetLeft;
    oElement = oElement.offsetParent;
    }
    return iReturnValue;
}

  
  
function createDelegates(mapObj){
    mapObj.setKeyAction(Sys.UI.Key.right,Function.createDelegate(mapObj,function() {return;}),Function.createDelegate(this,function() {return;}),null,true);
    mapObj.setKeyAction(Sys.UI.Key.left,Function.createDelegate(mapObj,function() {return;}),Function.createDelegate(this,function() {return;}),null,true);
    mapObj.setKeyAction(Sys.UI.Key.up,Function.createDelegate(this,function() {return;}),Function.createDelegate(this,function() {return;}),null,true);
    mapObj.setKeyAction(Sys.UI.Key.down,Function.createDelegate(this,function() {return;}),Function.createDelegate(this,function() {return;}),null,true);
    mapObj.setKeyAction(33,Function.createDelegate(this,function() {return;}),Function.createDelegate(this,function() {return;}),null,true); //Numlock 9
    mapObj.setKeyAction(34,Function.createDelegate(this,function() {return;}),Function.createDelegate(this,function() {return;}),null,true); //Numlock 3
    mapObj.setKeyAction(35,Function.createDelegate(this,function() {return;}),Function.createDelegate(this,function() {return;}),null,true); //Numlock 1
    mapObj.setKeyAction(36,Function.createDelegate(this,function() {return;}),Function.createDelegate(this,function() {return;}),null,true); //Numlock 7
    mapObj.setKeyAction(107,Function.createDelegate(this,function() {return;}),Function.createDelegate(this,function() {return;}),null,true); //Numlock 7
    mapObj.setKeyAction(109,Function.createDelegate(this,function() {return;}),Function.createDelegate(this,function() {return;}),null,true); //Numlock 7
    mapObj.setKeyAction(16,Function.createDelegate(this,function() {return;}),Function.createDelegate(this,function() {return;}),null,true); //Numlock 7
    mapObj.setKeyAction(17,Function.createDelegate(this,function() {return;}),Function.createDelegate(this,function() {return;}),null,true); //Numlock 7
			
}
