function HTTP() {
 var xmlhttp
 if (!xmlhttp) {
  try {
   xmlhttp = new XMLHttpRequest();
  } catch (e) {
        xmlhttp=false;
  }
 }
 return xmlhttp;
}
try {
    if (new HTTP()) {
        document.getElementById('scriptWarning').style.display="none";
    }
} catch (E) {}

function getDragParent(el) {
    var oldEl=el;
    while (el) {
        el=el.parentNode;
        if (el.id=="maptable" || el.nodeName.toUpperCase()=='BODY') {
            return oldEl;
        }
        oldEl=el;
    }
}

var offsetX,offsetY,draggingThing;
function startDrag(e) {
    draggingThing=getDragParent(e.srcElement || e.target); 
    offsetX=e.clientX-draggingThing.offsetLeft;
    offsetY=e.clientY-draggingThing.offsetTop;
    document.body.onmousemove=moveDrag;
    document.body.onmouseup=endDrag;
    document.onselectstart=nullFunc;
}

function nullFunc(e) {
    return false;
}
function moveDrag(e) {
    e=e || event;
    if (draggingThing) {
        draggingThing.style.top=(e.clientY-offsetY)+'px';
        draggingThing.style.left=(e.clientX-offsetX)+'px';
        return true;
    }
}
function endDrag(e) {
    draggingThing=null;
    document.body.onmousemove=null;
    document.body.onmouseend=null;
    document.onselectstart=null;
}

function outputTable(arr,headings,tableID,selectFunc) {
    var arrl=arr.length;
    var table=[];
    var item=arr[0];
    table.push('<table id="'+tableID+'"><tr onmousedown="startDrag(event)">');
    var headingsl=headings.length;
    for (var j=0;j<headingsl;j++) {
        var head=headings[j];
        sortType=(parseFloat(item[head.name])==item[head.name]);
        table.push('<th sortType='+sortType+'><a href="#" onclick="sortTable(this);return false;">'+head.heading+'</a></th>');
    }
    table.push('</tr>');
    for (var i=0;i<arrl;i++) {
        var item=arr[i];
        table.push('<tr onmouseenter="highlight(this)" onmouseleave="highlightOff(this)" onclick="'+selectFunc+'(this.firstChild.firstChild.nodeValue)">');
        for (var j=0;j<headingsl;j++) {
            var head=headings[j];
            sortVal=item[head.name];
            sortType=(parseFloat(sortVal)==sortVal);
            if (sortType) {
                outVal=(sortVal*1).toFixed(1);
            } else {
                outVal=sortVal;
            }
            table.push('<td sortvalue="'+sortVal+'">'+outVal+'</td>');
        }
        table.push('</tr>');
    }
    table.push('</table>');
    return table.join('');
}

function initial() {
    document.getElementById('maptable').style.display="block";
}


window.onload=initial;


