//--------------------------------------------------------------
var Slide_Interval = -1;
var slide_Timer
var CurSlideVal = 0;
var NewSlideVal = 0;
var Slide_Step;

var Slide_tmp;
var Slide_tmpPos = { x: 0, y: 0 }; ;
//--------------------------------------------------------------


var Scale_old = { i: 0, f: 0 };
var MapCenter_old = { x: 0, y: 0 };
var Scale = { i: 0, f: 0 };


//var Scale_Min = 10000000;
//var Scale_Max = 2000;
var Scale_BarPx = 0;
//var ScaleBarPos = { x: 0, y: 0 };

















var ScaleBar_InticatorActive;
var CirclePan_PanActive=false ;
var CirclePan_ZoomActive=false ;
//var slide_Timer;
//var Slide_Interval;
//var CurSlideVal;

var ScaleCounter_Visible=false;
var MapLoadWait_Timer
var MapLoadWait_Counter
/*
*/

var isNav;
var isIE;

if (parseInt(navigator.appVersion) >= 4) {
	if (navigator.appName == "Netscape") {
		isNav = true;
		isIE = false;
	} else {
	    isNav = false;
		isIE = true;
	}
	
}
//alert (navigator.appName + "  isIE " + isIE)


//function setNavEventCapture() {
//	if (isNav) {
//		document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP)
//	}
//}


// Set the rect position based on the adjusted start and current points:
function GetRec_FromTwoPoint(startPoint,currentPoint) {
    var Rec = {x:0, y:0, w:0, h:0, cx:0, cy:0};

    Rec.x=Math.min(startPoint.x, currentPoint.x);
    Rec.y=Math.min(startPoint.y, currentPoint.y);
    Rec.w=Math.abs(currentPoint.x - startPoint.x);
    Rec.h=Math.abs(currentPoint.y - startPoint.y);
    
    Rec.cx=Rec.x + Rec.w/2 ; 
    Rec.cy=Rec.y + Rec.h/2 ;  
	//MkRect(rect, Math.min(startPoint.x, currentPoint.x), Math.min(startPoint.y, currentPoint.y),
    //Math.abs(currentPoint.x - startPoint.x), Math.abs(currentPoint.y - startPoint.y));
return Rec;	
}

// A function that computes and returns the distance between two points.
function distance(x1, y1, x2, y2)
{
    var dx = (x2 - x1);
    var dy = (y2 - y1);
    return Math.sqrt(dx*dx + dy*dy);
}

function PointOnLineByDistance(StartPosX,StartPosY,EndPosX,EndPosY,dist) {
var Point = {x:0, y:0};

    var L = distance (StartPosX, StartPosY, EndPosX, EndPosY);
    if (L==0){
        Point.x=StartPosX
        Point.y=StartPosY
        return Point;
    }
    var R= dist/L;
    var Dx=(EndPosX - StartPosX);
    var Dy=(EndPosY - StartPosY);
    if (Dx!=0){
        Point.x = StartPosX + Dx * R
    } else {
        Point.x = StartPosX
    }
    if (Dy!=0){
        Point.y = StartPosY + Dy * R
    } else {
        Point.y = StartPosY
    }
 //   alert (Point.x + " , " + Point.y + " L= " + L + " R= " + R)  
    return Point;
}    

function PointFromPointDistanceAzimouth(StartPosX,StartPosY,azim,dist) {
    var Point = {x:0, y:0};
    angle0 = 270 - azim;
    Point.x = StartPosX - dist * Math.cos(angle0 * Math.PI / 180);
    Point.y = StartPosY + dist * Math.sin(angle0 * Math.PI / 180);
return Point;
} 


//http://hartshorne.ca/2006/01/23/javascript_cursor_position/

function getPosition_Cursor(e) {
    e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } 
    else {
        var de = document.documentElement;
        var b = document.body;
        cursor.x = e.clientX +(de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY +(de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }
    return cursor;
}


// adapted from MochiKit.DOM.elementPosition();	
function getPosition_ObjectRelative(ObjectId) {
        var Object=document.getElementById(ObjectId)
		var x = 0;
		var y = 0;
		
        x= Object.offsetLeft || x;
        y= Object.offsetTop || y;
		    
/*	
	    if (isIE){	
            x= Object.offsetLeft || x;
		    y= Object.offsetTop || y;
		} else {
		  //   x = Object.x || x;
		   //  y = Object.y || y;
		    x= Object.offsetLeft|| x;
	        y= Object.offsetTop|| y;
		}
*/
		return {x: x, y: y};
}

// adapted from MochiKit.DOM.elementPosition();	
function getPosition_Object(InValue) {
    var Object;
    if (typeof(InValue)=="string"){
        Object=document.getElementById(InValue);
     }else{  
        Object= InValue;
    } 

    //    var Object=document.getElementById(ObjectId)
    //var x = 0;
    //var y = 0;
    var position = { x: 0, y: 0 };
    if (!Object) { return position; }
    HandleOnWindow_Resize_IsActive = false;
    //-----------------------------------------
    //-----------------------------------------
    if (Object.offsetParent) {
        while (Object.offsetParent) {
            position.x += Object.offsetLeft;
            position.y += Object.offsetTop;
            Object = Object.offsetParent;
        }
    } else {
        position.x = Object.x || position.x;
        position.y = Object.y || position.y;
    }
    //-----------------------------------------
    HandleOnWindow_Resize_IsActive = true;
    return position;
}
function getObject_Size(InValue) {
    var Object
    if (typeof(InValue)=="string"){
        Object=document.getElementById(InValue);
     }else{  
        Object= InValue;
    }
    var Size = { w: 0, h: 0 };
    if (!Object) { return Size; }
    HandleOnWindow_Resize_IsActive = false;
    if (isIE){	
        Size.h = Object.clientHeight;
		Size.w = Object.clientWidth;
	} else {	
	    Size.h = Object.clientHeight;
	    Size.w = Object.clientWidth;
	}
	HandleOnWindow_Resize_IsActive = true;
return Size;	
}

//=========| getBody_Size
function getBody_Size() {
    var Size = {w:0, h:0};
    Size.h = document.body.clientHeight;
    Size.w = document.body.clientWidth;	
return Size;	
}

//=========| getWindow_Size
function getWindow_Size() {
    var Size = {w:0, h:0};
//    if (document.all)
//	{	Size.h = document.body.clientHeight;
//	    Size.w = document.body.clientWidth;
//	} else if (document.layers)
//	{	Size.h = window.innerHeight;
//	    Size.w = window.innerWidth;
//	}
    Size.h = document.documentElement.clientHeight;
    Size.w = document.documentElement.clientWidth;	
return Size;	
}

function getScreen_Size() {
    var sWidth = 0;
    var sHeight = 0;
    var bitDepth = 0;
    if (document.all)
	{	sHeight = screen.height;
		sWidth = screen.width;
		bitDepth = screen.colorDepth; 
	} else if (document.layers)
	{   sHeight = screen.height;
		sWidth = screen.width;
		bitDepth = screen.colorDepth; 
	}
return {w: wWidth, h: wHeight,  d: bitDepth};		
}

function GetScreenDPI() {
var tempDPI=96
    if (isIE){	
        tempDPI=screen.logicalXDPI;
	//} else {	
	
	}
	return  tempDPI ;	
}

function GetEventTrigger (e) {
e = e || window.event;
 //   if (! e)
 //       e = event;
    return e.target || e.srcElement;
}
function GetEventType (e) {
e = e || window.event;
    return e.type || e.type;
}	
function GetEventMousebutton(e) {
   // var MousebuttonID=-1;
    var Mousebutton = "none";
    //var tmp;
    if( window.event ) {
       // tmp=10
        if (event.button == 1) {Mousebutton="left"} 
        if (event.button == 2) {Mousebutton="right"} 
        if (event.button == 4) {Mousebutton= "middle"} 
    }else{
      //  tmp=e.which
        if ( e.button == 0) {Mousebutton=  "left"}
        if ( e.button == 2) {Mousebutton=  "right"} 
        if ( e.button == 1) {Mousebutton=  "middle"}

    }
   // 
 
 
 //if ( !e.button == 0 )  {alert( e.button)}
   //  document.writeln (e.button + "  " +  Mousebutton )
  //  }
//document.getElementById("TabMenu_Tab2").innerHTML = tmp +" Mousebutton=  " + MousebuttonID + " // " + Mousebutton
    
//defaultStatus = e.button + "  " +  Mousebutton  + "  " +  MousebuttonID 
return  Mousebutton ;	
}








function fadeIn(objId,opacity) {
    if (opacity <= 100) {
      setFilter_Opacity(objId, opacity);
      opacity += 5;
      window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 20);
    }
}

function setFilter_Opacity(objId, opacity) {
var obj = document.getElementById(objId);

  opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
  obj.style.filter = "alpha(style=0,opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}


function setFilter_Glow(objId, color,strength) {
var obj = document.getElementById(objId);
  // IE/Win
  obj.style.filter = "glow(color:"+color+",strength:"+strength+")";
   // Safari<1.2, Konqueror
 // obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
 // obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
 // obj.style.opacity = opacity/100;
} 
function RestoreFilter(objId) {
var obj = document.getElementById(objId);
  // IE/Win
  obj.style.filter = "";
   // Safari<1.2, Konqueror
 // obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
 // obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
 // obj.style.opacity = opacity/100;
}
function TransitionsEfect (objId1,objId2,opacity) {
var tmpopacity
    if (opacity <= 200) {
        if (opacity <= 100) {
            tmpopacity=100- opacity;
            setFilter_Opacity(objId1, tmpopacity);
        } 
        if (opacity == 100) {
            tmpopacity=100- opacity;
            setFilter_Opacity(objId1, tmpopacity);
            document.getElementById(objId1).style.display="none";
            document.getElementById(objId2).style.display="block";
            tmpopacity=opacity-100;
            setFilter_Opacity(objId2, tmpopacity);
        } else if (opacity > 50) {
            tmpopacity=opacity-100;
            setFilter_Opacity(objId2, tmpopacity);
        }
        opacity += 25;
        
        window.setTimeout("TransitionsEfect('"+objId1+"','" + objId2 +"'," +opacity+")", 50);
    }
//    defaultStatus =opacity + "  " + tmpopacity
}




//var aaGDI_StaticLabel= new Array();

function GDI_StaticLabel_Rec(IDValue, LabelValue){
  this.ID = IDValue;
  this.Label = LabelValue;
}
//-------------------------------------------------------------------------------------
function GDI_StaticLabel_Add(IDValue,  LabelValue){
    GDI_StaticLabel[GDI_StaticLabel.length] = new GDI_StaticLabel_Rec(IDValue, LabelValue);
}
//-------------------------------------------------------------------------------------
function GDI_StaticLabel_Set() {
    var Myobj ;
    var Myobj_ID ;
    for (var i=0;i<GDI_StaticLabel.length;i++){
        Myobj_ID= GDI_StaticLabel[i].ID;
        Myobj= document.getElementById(Myobj_ID);
        if (Myobj) {
            Myobj.innerHTML =GDI_StaticLabel[i].Label;
        }
    }
}
//-------------------------------------------------------------------------------------
function GDI_Title_Add(IDValue,  LabelValue){
    GDI_Title[GDI_Title.length] = new GDI_StaticLabel_Rec(IDValue, LabelValue);
}
//-------------------------------------------------------------------------------------
function GDI_Title_Set() {
    var Myobj ;
    var Myobj_ID ;
    for (var i=0;i<GDI_Title.length;i++){
        Myobj_ID= GDI_Title[i].ID;
        Myobj= document.getElementById(Myobj_ID);
        if (Myobj) {
            Myobj.title= GDI_Title[i].Label;
        }
    }
}
//-------------------------------------------------------------------------------------
function GetOptionIndex_FromValue(MyobjID,MyValue) {
    var selectOBJ = document.getElementById(MyobjID)  
    for (var i = 0; i < selectOBJ.options.length; i ++) {
        if (selectOBJ.options[i].value == MyValue) {
            return i;
        }
    }
    return -1;
}


//-------------------------------------------------------------------------------------
//Array.prototype.inArray = function (value){
//// Returns true if the passed value is found in the
//// array. Returns false if it is not.
//for (var i=0; i < this.length; i++) 
//{
//	if (this[i] == value) 
//	{
//	return true;
//	}
//}
//return false;
//};
//-------------------------------------------------------------------------------------
inArray = function (MyArray,MyValue) {
    for (var i=0; i < MyArray.length; i++){
        if (MyArray[i] == MyValue) { return true; }
    }
    return false;
};
//-------------------------------------------------------------------------------------
//  Replaces all instances of the given substring.
//  Link:
//	http://www.bennadel.com/index.cfm?dax=blog:142.view
String.prototype.replaceAll = function( 
	strTarget, // The substring you want to replace
	strSubString // The string you want to replace in.
	){
	var strText = this;
	var intIndexOfMatch = strText.indexOf( strTarget );
	// Keep looping while an instance of the target string still exists in the string.
	while (intIndexOfMatch != -1){
		// Relace out the current instance.
		strText = strText.replace( strTarget, strSubString )
		// Get the index of any next matching substring.
		intIndexOfMatch = strText.indexOf( strTarget );
	}
	// Return the updated string with ALL the target strings
	// replaced out with the new substring.
	return( strText );
}
//-------------------------------------------------------------------------------------
    function GetZeroFrontNumber (Number,Zero) {
        var R_string= "0000000000" ;
        R_string= R_string +  String(Number);
        R_string= R_string.substr(R_string.length -Zero, Zero);
        return R_string;
    } 
    
    
function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}