﻿var isDHTML = 0;
var isLayers = 0;
var isAll = 0;
var isID = 0;

if (document.getElementById){
	isID = 1; 
	isDHTML = 1;
}else {
	if (document.all) {
		isAll = 1; 
		isDHTML = 1;
	}else {
			browserVersion = parseInt(navigator.appVersion);
			if ((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4)) {
				isLayers = 1; isDHTML = 1;
			}
	}
}

//confirm("isDHTML = " + isDHTML + "\nisLayers = " + isLayers + "\nisAll = " + isAll + "\nisID = " + isID);

function findDOM(objectID,withStyle) {
	if (withStyle == 1) {
		if (isID) { return (document.getElementById(objectID).style) ; }
		else { 
			if (isAll) { return (document.all[objectID].style); }
		else {  
			if (isLayers) { return (document.layers[objectID]); }
		};}
	}
	else {
		if (isID) { return (document.getElementById(objectID)) ; }
		else { 
			if (isAll) { return (document.all[objectID]); }
		else {
			if (isLayers) { return (document.layers[objectID]); }
		};}
	}
}

function findDOMObject(objectID) {
	if (isID) { 
		return (document.getElementById(objectID));
	}else { 
		if (isAll) { 
			return (document.all[objectID]);
		}else {
			if (isLayers) { 
				return (document.layers[objectID]); 
			}
		}
	}

}

// timer for cursor stop
			
var cX, cY;
var cTimer;
function findLivePageWidth() {
	if(document.getElementById("theMap")!= null){
		return parseInt(document.getElementById("theMap").style.left) + parseInt(document.getElementById("theMap").style.width);
	}
	else if (window.innerWidth != null){
		return window.innerWidth;
	} 
	else if (document.body.clientWidth != null) return document.body.clientWidth;
	return (null);
}
function findLivePageHeight() {
	if(document.getElementById("theMap")!= null){
		return parseInt(document.getElementById("theMap").style.top) + parseInt(document.getElementById("theMap").style.height);
	}
	else if (window.innerHeight != null) return window.innerHeight;
	else if (document.body.clientHeight != null) return document.body.clientHeight;
	return (null);
}

function popUp(x, y, objectID) {//alert(Maps['Map1'].actionType);
	if (isDHTML) {
	    showMaptip(x, y, objectID);
	}
}

function popOff(objectID) {
    hideMaptipQuick(objectID);
}

function showMaptip(x, y, objectID) {//alert(document.getElementById(objectID).Name);
	clearTimeout(cTimer);	
	var maptipLayer = getLayer("MapTipTag");

	var livePageWidth = findLivePageWidth();
	var livePageHeight = findLivePageHeight();
	//var domStyle = findDOM(objectID,1);
	var dom = findDOM("MapTipTag",0);
	var state = maptipLayer.visibility;
	var elemWidth;
	var elemHeight;
	if (dom.offsetWidth) {
		elemWidth = dom.offsetWidth;
		elemHeight = dom.offsetHeight;
	} else {
		if (isNav) {
			if (dom.clip.width) 
				elemWidth = dom.clip.width;
		}
	}

    var topVal = y+16;
	var leftVal = x+16;
    if (topVal < 45) {
		topVal = 45;
	} else if(parseInt(y + elemHeight + 20) > document.documentElement.clientHeight ){
	    topVal = topVal - elemHeight;
	}
	//alert(document.getElementById(objectID).id);
	var tipid = document.getElementById(objectID).id;
	var pos = tipid.indexOf("-");
	var tipTitle = tipid.substr(0,pos);
	//alert(tipTitle);
	setCursor("theMap", "point");
    var content;
	//content = '<div id="MapTipTagTitle"><table class="maptiptable" ><tr><td width="100%" >' + document.getElementById(objectID).Name + '</td><td width="15" valign="top"><img onclick="hideMaptip();" style="float: right; CURSOR: pointer" onmouseover="this.src =\'images/close_o.gif\'" onmouseout="this.src = \'images/close.gif\'" height="13" alt="Close" src="images/close.gif" /></td><tr></table></div>';
	content = '<div id="MapTipTagTitle"><table class="maptiptable" ><tr><td width="100%" >' + tipTitle + '</td><td width="15" valign="top"><img onclick="hideMaptip();" style="float: right; CURSOR: pointer" onmouseover="this.src =\'images/close_o.gif\'" onmouseout="this.src = \'images/close.gif\'" height="13" alt="Close" src="images/close.gif" /></td><tr></table></div>';
    content = content + '<div id="MapTipTagBody" onmousedown="dragThis2(getElementById(\'MapTipTagBody\'));">';
    content = content + document.getElementById(objectID).innerHTML;
    content = content + '</div>';
    document.getElementById('MapTipTag').innerHTML = content;
    document.getElementById('MapTipTag').className = document.getElementById(objectID).className;
    document.getElementById('MapTipTagTitle').className = "mapTipTitle"
	//alert(maptipLayer.top);	
    maptipLayer.top = topVal + "px"; // positions element from the top
    maptipLayer.left = leftVal + "px" // positions element from the left	
    var maptipTitleLayer = getLayer("MapTipTagTitle");
	if (isNav4){
		maptipTitleLayer.visibility = "show";
		maptipLayer.visibility = "show";
	}else{
		maptipTitleLayer.visibility = "visible";	
		maptipLayer.visibility = "visible";	
	}	

}

function showMaptipTag(){
	clearTimeout(cTimer);
	var maptipLayer = getLayer("MapTipTag");
 	var maptipTitleLayer = getLayer("MapTipTagTitle");
   if (isNav4){
        maptipTitleLayer.visibility = "show";
		maptipLayer.visibility = "show";
   }else{
        maptipTitleLayer.visibility = "visible";	
		maptipLayer.visibility = "visible";	
  }

}
// set the cursor of the specified layer
function setCursor(divLayer, cursor) {
	var dObj = getLayer(divLayer);
	if (dObj!=null) {
		dObj.cursor = cursor;
		theCursor = dObj.cursor;
	}
}

function hideMaptipQuick() {
	clearTimeout(cTimer);
//	var curTool = document.frmMain.tool.value;
//	switch(curTool)
//	{
//		case "T_PAN":
//			setCursor("MapControlDiv_Map1", "move");
//			break    
//		case "T_SELECT":
//			setCursor("MapControlDiv_Map1", "Help");
//			break
//		default:
//			setCursor("MapControlDiv_Map1", "crosshair");
//	} 		
	var pF = "hideMaptip('" + "MapTipTag" + "');hideMaptip('" + "MapTipTagTitle" + "')";
	cTimer = setTimeout("hideMaptip()",100);
}

function hideMaptipSlow() {
		clearTimeout(cTimer);
		var pF = "hideMaptip('" + "MapTipTag" + "');hideMaptip('" + "MapTipTagTitle" + "')";
		cTimer = setTimeout("hideMaptip()",3000);
}

function hideMaptip() {
	clearTimeout(cTimer);
	var maptipLayer = getLayer("MapTipTag");
 	var maptipTitleLayer = getLayer("MapTipTagTitle");
 	
    maptipLayer.visibility = "hidden";
    maptipTitleLayer.visibility = "hidden";
}

function trackCursor(evt, objectID) {
	if (isDHTML) {
		document.all.theMap.style.cursor = "point";
		var newX, newY
		if (evt.pageX) {
			newX = evt.pageX;
			newY = evt.pageY;
		} else {
			newX = evt.x;
			newY = evt.y;
		}
		var pF = "showMaptip(" + newX + "," + newY + ",'" + objectID + "')";
		if (!((newX==cX) && (newY==cY))) {
			clearTimeout(cTimer);
			cTimer = setTimeout(pF,500);
			cX = newX;
			cY = newY;
		}
	}
}


// Drag a panel - start

var dragObj=null;
var dragStartX=-1;
var dragStartY=-1;
var dragObjLeft=-1;
var dragObjTop=-1;
var dragEventObj=null;
var dragMode=false;

function dragThis(draggableObj){
	try{
	    if(navigator.appName=='Netscape' && navigator.userAgent.indexOf('Netscape/7.1')>0)	
	    {
	    		drag_Netscape(draggableObj);
	    		return;
		}
		var curObj;
		dragObj=draggableObj;
		dragObj.zorder=-1;
		window.status='Dragging:' + dragObj.id ;
		curObj=window.event.srcElement;
		dragObjLeft=getSize(dragObj.style.left);
		dragObjTop=getSize(dragObj.style.top);

		dragStartX=getSize(window.event.clientX );
		dragStartY=getSize(window.event.clientY );
		dragEventObj=curObj;
		document.onmousemove=dragMouseMove;
		document.onmouseup=dragMouseUp;
		dragEventObj.onmouseup=dragMouseUp;
		window.event.cancelBubble = true;	
		//document.all.item(dragObj.id+'body').style.filter='progid:DXImageTransform.Microsoft.Alpha(opacity=20)';
	}catch(ex){}
}

function dragMouseMove(e)
{	if(dragObj!=null)
	{
		window.status = getSize(dragObj.style.left) +','+ getSize(dragObj.style.top) ;
		tempX=dragObjLeft-(dragStartX-window.event.clientX );
		tempY=dragObjTop-(dragStartY-window.event.clientY );
		dragObj.style.left=tempX+"px";
		dragObj.style.top=tempY+"px";
		document.all.item(dragObj.id).style.filter='progid:DXImageTransform.Microsoft.Alpha(opacity=70)';

	}
	window.event.cancelBubble = true;
}

function dragMouseUp()
{
	try{
		document.all.item(dragObj.id).style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity=100)";
		}catch(ex){}
	dragObj=null;
	dragEventObj=null;
	window.event.cancelBubble = true;	
}

function getSize(sizeWithPx)
{
	var sizeStr =new String(sizeWithPx);
	if(sizeStr.substring(sizeStr.length-2,sizeStr.length)=="px")
		res=sizeStr.substring(0,sizeStr.length-2);
	else
		res=sizeStr;
	//alert(res);
	return res;
}

function dragThis2(draggableObj){
	try{
	    if(navigator.appName=='Netscape' && navigator.userAgent.indexOf('Netscape/7.1')>0)	
	    {
	    		drag_Netscape(draggableObj);
	    		return;
			}
		var curObj;
		dragObj=draggableObj;
		dragObj.zorder=-1;
		window.status='Dragging:' + dragObj.id ;
		curObj=window.event.srcElement;
		dragObjLeft=getSize(dragObj.style.left);
		dragObjTop=getSize(dragObj.style.top);

		dragStartX=getSize(window.event.clientX );
		dragStartY=getSize(window.event.clientY );
		dragEventObj=curObj;
		document.onmousemove=dragMouseMove2;
		document.onmouseup=dragMouseUp;
		dragEventObj.onmouseup=dragMouseUp;
		window.event.cancelBubble = true;	
		//document.all.item(dragObj.id+'body').style.filter='progid:DXImageTransform.Microsoft.Alpha(opacity=20)';
	}catch(ex){}
}

function dragMouseMove2(e)
{	
	return false;
	window.event.cancelBubble = true;
}

function MouseOverMapTipBody()
{	
	var theStyle = findDOM("MapTipTag",1);
	theStyle.background="#F4FFF4";
	window.event.cancelBubble = true;
}

function MouseOutMapTipBody()
{	
	var theStyle = findDOM("MapTipTag",1);
	theStyle.background="#f9fafb";
	window.event.cancelBubble = true;
}





