var gmapType = "mappoint"; //initial

var simulcount = 0;
var map;

function simulation(){

	simulcount++;
	count++;
	var thisSrc = src + "?count=" + count;
	
	if(simulcount==1) {
		thisSrc = "templates/" + theme_folder + "/flash/connect.swf";
		thisSrc2= "templates/" + theme_folder + "/flash/connect_2.swf";
		}
	if(simulcount==2) {
		thisSrc = "templates/" + theme_folder + "/flash/request.swf";
		thisSrc2= "templates/" + theme_folder + "/flash/request_2.swf";
		}
	if(simulcount==3) {
		thisSrc = "templates/" + theme_folder + "/flash/located.swf";
		thisSrc2=thisSrc;
		}
	
	//document.status.LoadMovie(0, thisSrc);
	getAllFlashObjects();
	//document("status").LoadMovie(0, thisSrc);
	
	try
	{
		if(mov2) mov2.LoadMovie(0, thisSrc2);
	}
	catch(e)
	{}
/*	if(simulcount>3) 
	{*/
	window.clearInterval(oInterval);
	var f = document.customer_form;
	f.action = "default.aspx?center_logged=map_logged&count=" + date.getTime() ;
	f.submit();		
}


function newLogin()
{
	
	var chk = document.customer_form.chkSecure.checked;
	var url = location.href;
	url = url.toLowerCase();
	
	var i = url.lastIndexOf('/default.aspx');
	if(i==-1) url = url + "/default.aspx";
	
	if(chk)
	{
		// This code will automatically insert www to url only if url starts with http://something.com
		// 1/18/2008
		if (location.host != "localhost")
		{
			var arrayStr = new Array();
			arrayStr = location.host.split('.');
			
			if (arrayStr.length == 2)
			{
				url = url.replace("http://", "http://www."); 
				url = url.replace("https://", "https://www.");
			}
		}
		var rxp = /https:/;
		url = url.replace("http:","https:");
		if (location.host != "localhost") document.customer_form.action = url;
	}
	var j = url.lastIndexOf('?');
	var i = url.lastIndexOf('type=Login');
	
	if (j == -1)  // if URL contains a '?'
	{
		document.customer_form.action = document.customer_form.action + "?type=Login";
	}
	else if (i==-1)		// otherwise, if 'type=login' does not exist in Uri
	{
		document.customer_form.action = document.customer_form.action + "&type=Login";
	}
	
	
	var chkRememberMe = document.customer_form.chkRememberMe;
	//alert('chkRememberMe: ' + chkRememberMe);
	
	if (chkRememberMe != null)
	{
		var chkRM = chkRememberMe.checked;
		var url = document.customer_form.action;
		
		if (chkRM)
		{
			if (url.indexOf('rememberme=') == -1)
			{
				url = url + "&rememberme=1";
			}
			else
			{
				url = url.replace('rememberme=0', 'rememberme=1');
			}
			document.customer_form.action = url;
		}
		else
		{
			document.customer_form.action = document.customer_form.action + "&rememberme=0";
			if (url.indexOf('rememberme=') == -1)
			{
				url = url + "&rememberme=0";
			}
			else
			{
				url = url.replace('rememberme=1', 'rememberme=0');
			}
			document.customer_form.action = url;
		}
	}
	else
	{
		document.customer_form.action = document.customer_form.action + "&rememberme=0";
		//alert('no chked available');
	}
	
	document.customer_form.submit();
}


// Window URL is nothing for now so that we can build it later. No window name so that we can have different popups
//
function PopUpWindow(URL, Title) {

	w = window.open('', '', 'titlebar=no,fullscreen=no,toolbar=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,directories=yes,location=no',false);

	// Only way to set title of new window is to build html
	
	w.document.write('<html><head><title>'+Title+'</title></head><frameset rows="100%,*"><frame src="'+URL+'"></frameset></html>')
	w.document.close()				
}

function ToggleVisibility(control,toggle)
{
	if (toggle) {
		document.getElementById(control).style.visibility = "visible";
	}
	else {
		document.getElementById(control).style.visibility = "hidden";
	}
}









//for zooming 3
function zoomOut3() {
	if(last_zoom > 0) last_zoom--;
	zoomMap3(last_zoom);
}

function zoomIn3() {
	if(last_zoom < 6) last_zoom++;
	zoomMap3(last_zoom);
}


//for zooming
function zoomOut() 
{
	if(last_zoom > 0) last_zoom--;
	zoomMap(last_zoom);
}

function zoomIn() {
	if(last_zoom < 6) last_zoom++;
	zoomMap(last_zoom);
}

//for zooming 2
function zoomOut2() {
	if(last_zoom > 0) last_zoom--;
	zoomMap2(last_zoom);
}

function zoomIn2() {
	if(last_zoom < 6) last_zoom++;
	zoomMap2(last_zoom);
}


// Zoom Map on MapConsole   (Based on old zoom_map)
// 
function zoomMap(zfactor) 
{
	var mapURL = MapConsole.AjaxRenderedMapURL(zfactor);
	
	var img = document.images["MapConsole1_imgMap"];
	var zimg = document.images["zoom" + zfactor];
	
	//GlobeXplorer & MapPoint Zoom
	//  Keep this if-statement for any additional features for MapPoint or GlobExplorer

	if (mapURL.value == "") 
		img.src = "images/NoImage.jpg"
	else
		img.src = mapURL.value;

	last_zoom = zfactor;		
	setImageScale();
	zimg.src = "templates/" + theme_folder + "/images/zoom_on.gif";
	
	for(i=0;i<=6;i++) {
		if(i!=zfactor) {
			zimg = document.images["zoom" + i];
			zimg.src = "templates/" + theme_folder + "/images/zoom_off.gif";
		}
	}
} 


// Zoom Map on MapConsoleRS   (Based on old zoom_map)
// 
function zoomMap2(zfactor) 
{
	var mapURL = MapConsoleRS.AjaxRenderedMapURL(zfactor);
	
	var img = document.images["MapConsoleRS1_imgMap"];
	
	var zimg = document.images["zoom" + zfactor];
	
	//GlobeXplorer & MapPoint Zoom
	//  Keep this if-statement for any additional features for MapPoint or GlobExplorer

	if (mapURL.value == "") 
		img.src = "images/NoImage.jpg"
	else
		img.src = mapURL.value;

	last_zoom = zfactor;		
	setImageScale2();
	zimg.src = "templates/" + theme_folder + "/images/zoom_on.gif";
	
	for(i=0;i<=6;i++) {
		if(i!=zfactor) {
			zimg = document.images["zoom" + i];
			zimg.src = "templates/" + theme_folder + "/images/zoom_off.gif";
		}
	}
} 



// Zoom Map on MapConsolePETTRAK   (Based on old zoom_map)
// 
function zoomMap3(zfactor) 
{
	var mapURL = MapConsolePETTRAK.AjaxRenderedMapURL(zfactor);
	
	var img = document.images["MapConsolePETTRAK1_imgMap"];
	
	var zimg = document.images["zoom" + zfactor];
	
	//GlobeXplorer & MapPoint Zoom
	//  Keep this if-statement for any additional features for MapPoint or GlobExplorer

	if (mapURL.value == "") 
	{
		//alert ("Map Url Value: " + mapURL.value)
		
		img.src = "images/NoImage_bgGreen.jpg"
	}
	else
		img.src = mapURL.value;

	last_zoom = zfactor;		
	setImageScale3();
	zimg.src = "templates/" + theme_folder + "/images/zoom_on.gif";
	
	for(i=0;i<=6;i++) {
		if(i!=zfactor) {
			zimg = document.images["zoom" + i];
			zimg.src = "templates/" + theme_folder + "/images/zoom_off.gif";
		}
	}
} 

// Check that Map images are loaded (Based on old image_loaded)
//
function imageLoaded() 
{
	var img = document.images["MapConsole1_imgMap"];
	if(img.complete){
		window.clearInterval(image_loaded_timer);
		if(imgmovstats) imgmovstats.LoadMovie(0,ff_loading_done);									
	}
}


/// Set Image Scale and check for session timeout   (based on old setscaleimg)
//
var start_time = null;
var cur_time = null;
function setImageScale(){

	if(start_time==null) start_time = new Date();
	cur_time = new Date();
	var tdif = new Date();
	tdif.setTime(Math.abs(cur_time.getTime() - start_time.getTime()));
	
	if(tdif.getMinutes()>15) {
		location.href = "Default.aspx?menu=logout";
	}
	start_time = new Date();

	var scaleImg = document.images["MapConsole1_imgMapScale"];
	var simageSrc = "images/scale_0" + (last_zoom+1)
	
	// GlobeXplorer: zoom 0,1,2,3,4 & 5 is same; 6 = 1inch=53yrd scale
	//
	if(gmapType=="globexplorer"){

		simageSrc += "_white.gif";
		if(last_zoom==6) simageSrc = "images/scale_08_white.gif";
	}
	else {
		simageSrc += ".gif";	
	}
	
	alert('theme" ' + theme_folder);
	if (theme_folder == 'ANDALE')
	{
		simageSrc = "images/telogis-scale-0" + (last_zoom) + ".png";
	}
	
	scaleImg.src = simageSrc;
}


function setImageScale2(){

	if(start_time==null) start_time = new Date();
	cur_time = new Date();
	var tdif = new Date();
	tdif.setTime(Math.abs(cur_time.getTime() - start_time.getTime()));
	
	if(tdif.getMinutes()>15) {
		location.href = "Default.aspx?menu=logout";
	}
	start_time = new Date();

	var scaleImg = document.images["MapConsoleRS1_imgMapScale"];
	var simageSrc = "images/scale_0" + (last_zoom+1)
	
	// GlobeXplorer: zoom 0,1,2,3,4 & 5 is same; 6 = 1inch=53yrd scale
	//
	if(gmapType=="globexplorer"){

		simageSrc += "_white.gif";
		if(last_zoom==6) simageSrc = "images/scale_08_white.gif";
	}
	else {
		simageSrc += ".gif";	
	}
	
	if (theme_folder == 'ANDALE')
	{
		simageSrc = "images/telogis-scale-0" + (last_zoom) + ".png";
	}
	
	scaleImg.src = simageSrc;
}


function setImageScale3(){

	if(start_time==null) start_time = new Date();
	cur_time = new Date();
	var tdif = new Date();
	tdif.setTime(Math.abs(cur_time.getTime() - start_time.getTime()));
	
	if(tdif.getMinutes()>15) {
		location.href = "Default.aspx?menu=logout";
	}
	start_time = new Date();

	var scaleImg = document.images["MapConsolePETTRAK1_imgMapScale"];
	var simageSrc = "images/scale_0" + (last_zoom+1)
	
	// GlobeXplorer: zoom 0,1,2,3,4 & 5 is same; 6 = 1inch=53yrd scale
	//
	if(gmapType=="globexplorer"){

		simageSrc += "_white.gif";
		if(last_zoom==6) simageSrc = "images/scale_08_white.gif";
	}
	else {
		simageSrc += ".gif";	
	}
	
	if (theme_folder == 'ANDALE')
	{
		simageSrc = "images/telogis-scale-0" + (last_zoom) + ".png";
	}
	
	scaleImg.src = simageSrc;
}


function setImageScaleVE(sTheme){

	if(start_time==null) start_time = new Date();
	cur_time = new Date();
	var tdif = new Date();
	tdif.setTime(Math.abs(cur_time.getTime() - start_time.getTime()));
	
	if(tdif.getMinutes()>15) {
		location.href = "Default.aspx?menu=logout";
	}
	start_time = new Date();

	var scaleImg = eval("document.images['MapConsole" + sTheme + "1_imgMapScale']");
	var simageSrc = "images/scale_0" + (last_zoom+1)

	// GlobeXplorer: zoom 0,1,2,3,4 & 5 is same; 6 = 1inch=53yrd scale
	//
	if(gmapType=="globexplorer"){

		simageSrc += "_white.gif";
		if(last_zoom==6) simageSrc = "images/scale_08_white.gif";
	}
	else {
		simageSrc += ".gif";	
	}
	
	if (theme_folder == 'ANDALE')
	{
		simageSrc = "images/telogis-scale-0" + (last_zoom) + ".png";
	}
	
	scaleImg.src = simageSrc;
}

// Change Map Type MapPoint or GlobeXplorer (Based on old changeMapStyle)
//
function changeMapType(selMapType){

	gmapType = selMapType;
	
	var img = document.images["MapConsole1_imgMap"];
	var mapURL;
	
	// MapPoint
	//
	MapConsole.AjaxChangeMapType(selMapType)
		
	mapURL = MapConsole.AjaxRenderedMapURL(last_zoom);		
	
	if (mapURL.value == "") 
		img.src = "images/NoImage.jpg"
	else
		img.src = mapURL.value;

	setImageScale();

	return;
}


// Change Map Type MapPoint or GlobeXplorer (Based on old changeMapStyle)
//
function changeMapType2(selMapType){

	gmapType = selMapType;
	
	var img = document.images["MapConsoleRS1_imgMap"];
	var mapURL;
	
	// MapPoint
	//
	MapConsoleRS.AjaxChangeMapType(selMapType)
		
	mapURL = MapConsoleRS.AjaxRenderedMapURL(last_zoom);		
	
	if (mapURL.value == "") 
		img.src = "images/NoImage.jpg"
	else
		img.src = mapURL.value;

	setImageScale2();

	return;
}


// Change Map Type MapPoint or GlobeXplorer (Based on old changeMapStyle)
//
function changeMapType3(selMapType){

	gmapType = selMapType;
	
	var img = document.images["MapConsolePETTRAK1_imgMap"];
	var mapURL;
	
	// MapPoint
	//
	MapConsolePETTRAK.AjaxChangeMapType(selMapType)
		
	mapURL = MapConsolePETTRAK.AjaxRenderedMapURL(last_zoom);		
	
	if (mapURL.value == "") 
		img.src = "images/NoImage_bgGREEN.jpg"
	else
		img.src = mapURL.value;

	setImageScale3();

	return;
}


// Change Map Type MapPoint or GlobeXplorer (Based on old changeMapStyle)
//
function ChangeMapTypeVE(selMapType, sTheme)
{
	gmapType = selMapType;
	
	var img = eval('document.images["MapConsole' + sTheme + '1_imgMap"]');
	var mapURL;
	// MapPoint
	//								   
	//mapURL = 'MapConsole' + sTheme + '.AjaxChangeMapType(' + selMapType + ')';
	eval("MapConsole" + sTheme + ".AjaxChangeMapType('" + selMapType + "')");
	
	mapURL = eval('MapConsole' + sTheme + '.AjaxRenderedMapURL(' + last_zoom + ')' );		
	if (mapURL.value == "") 
		img.src = "images/NoImage.jpg"
	else
		img.src = mapURL.value;
//alert('imgSrc: ' + img.src + '  sTheme:' + sTheme);
	setImageScaleVE(sTheme);

	return;
}

// Change imgMap source to MapLoading.gif
//
function SetLoadingImage(mapType)
{
//alert('SetLoadingImage - mapType: ' + mapType + '  sTheme:' + sTheme);
	// if same mapstyle, do not show MapLoading.gif
	if ( mapType == gmapType )
		return;
	else
	{
		var img = document.images["MapConsole1_imgMap"];
		img.src = "images/MapLoading.jpg"
	}
}

// Change imgMap source to MapLoading.gif 
//
function SetLoadingImage2(mapType)
{
//alert('SetLoadingImage2 - mapType: ' + mapType + '  sTheme:' + sTheme);
	// if same mapstyle, do not show MapLoading.gif
	if ( mapType == gmapType )
		return;
	else
	{
		var img = document.images["MapConsoleRS1_imgMap"];
		img.src = "images/MapLoading.jpg"
	}
}


// Change imgMap source to MapLoading.gif 
//
function SetLoadingImage3(mapType)
{
	//alert('SetLoadingImage3 - mapType: ' + mapType + '  sTheme:' + sTheme);
	// if same mapstyle, do not show MapLoading.gif
	if ( mapType == gmapType )
		return;
	else
	{
		var img = document.images["MapConsolePETTRAK1_imgMap"];
		img.src = "images/MapLoading_bgGreen.jpg"
	}
}

// Change imgMap source to MapLoading.gif 
//
function SetLoadingImageVE(sTheme, mapType)
{
	// if same mapstyle, do not show MapLoading.gif
	//alert('SetLoadingImageVE - mapType: ' + mapType + '  sTheme:' + sTheme);
	if ( mapType == gmapType )
	{  
		return;
	}
	else
	{
		var img = eval("document.images['MapConsole" + sTheme + "1_imgMap']");
		img.src = "images/MapLoading.jpg"
		
	}
}


// MenuConsole :: cmdCommands:
//
function cmdCommands(){
	var f = document.customer_form;
	var selbox = f.elements["MenuConsole1:lstAssets"];
	var si = selbox.selectedIndex;
	if(si==-1){ alert("Please select an asset from the list"); return; }
	var assetid = selbox.options[si].value;
		
	var formurl = "default.aspx?center_logged=Commands&assetid=" + assetid;
	location.href = formurl; 
}

// MenuConsole :: cmdEdit:
//
function cmdEdit(){
	var f = document.customer_form;
	var selbox = f.elements["MenuConsole1:lstAssets"];
	var si = selbox.selectedIndex;
	if(si==-1){ alert("Please select an asset from the list"); return; }
	var assetid = selbox.options[si].value;
	
	var formurl = "default.aspx?center_logged=parser&process=control&name=CAssetDetail&assetid="  + assetid;
	location.href = formurl; 
}


// MenuConsole :: cmdSettings:
//
function cmdSettings(){

	var f = document.customer_form;
	var selbox = f.elements["MenuConsole1:lstAssets"];
	var si = selbox.selectedIndex;
	if(si==-1){ alert("Please select an asset from the list"); return; }
	var assetid = selbox.options[si].value;
	
	var formurl =   "default.aspx?center_logged=parser&process=control&name=Settings&assetid=" + assetid;
	location.href = formurl; 
}

// MenuConsole ::  cmdHistory:
//
function cmdHistory(){
	var f = document.customer_form;
	var selbox = f.elements["MenuConsole1:lstAssets"];
	var si = selbox.selectedIndex;
	if(si==-1){ alert("Please select an asset from the list"); return; }
	var assetid = selbox.options[si].value;

	var formurl = "default.aspx?center_logged=parser&process=control&name=History&assetid=" + assetid;
	location.href = formurl; 
}

// COMMANDS :: cmdLocate:
//	
function cmdLocate(sTheme){
	var f = document.customer_form;
	f.status_ok.value = "";
	var selbox = f.elements["MenuConsole1:lstAssets"];
	var si = selbox.selectedIndex;
	if(si==-1){ alert("Please select an asset from the list"); return; }
	var assetid = selbox.options[si].value;
	var assetdesc = selbox.options[si].text; 

	var ret = confirm("Do you wish to Locate " + assetdesc + "?");		
	if(!ret) return;
	date = new Date();

	if(simul!="true"){
		//f.action = "default.aspx?center_logged=Sentinel&command=LOCATE&assetid=" + assetid + "&count=" + date.getTime()
		//f.action = "default.aspx?dtmf=true&center_logged=Sentinel&command=LOCATE&assetid=" + assetid + "&count=" + date.getTime()
		if ( sTheme == "ANDALE")
			f.action = "default.aspx?dtmf=true&center_logged=parser&process=control&name=SentinelStatusANDALE&command=LOCATE&assetid=" + assetid + "&count=" + date.getTime()
		else
		f.action = "default.aspx?dtmf=true&center_logged=parser&process=control&name=SentinelStatus&command=LOCATE&assetid=" + assetid + "&count=" + date.getTime()
	//	alert("In production mode");
	}
	else {
		f.action = "default.aspx?center_logged=map_logged&command=LOCATE&assetid=" + assetid  + "&count=" + date.getTime()
		//alert("In simulation mode");
	}

	f.submit();		
}

// COMMANDS :: cmdGeofence:
//	
function cmdGeofence(){
	var f = document.customer_form;
	f.status_ok.value = "";
	var selbox = f.elements["MenuConsole1:lstAssets"];
	var si = selbox.selectedIndex;
	if(si==-1){ alert("Please select an asset from the list"); return; }
	var assetid = selbox.options[si].value;
	var assetdesc = selbox.options[si].text; 
	
	var ret = confirm("Do you wish to enable/disable the Geofence for " + assetdesc + "?");		
	if(!ret) return;
	date = new Date();
	f.action = "default.aspx?center_logged=Sentinel&count=" + date.getTime() + "&command=GEOFENCE_LOCAL_TOGGLE&assetid=" + assetid 
	f.submit();		
}

function cmdGeofenceLocalOn(){
	var f = document.customer_form;
	f.status_ok.value = "";
	var selbox = f.elements["MenuConsole1:lstAssets"];
	var si = selbox.selectedIndex;
	if(si==-1){ alert("Please select an asset from the list"); return; }
	var assetid = selbox.options[si].value;
	var assetdesc = selbox.options[si].text; 
	
	var ret = confirm("Do you wish to activate the Geofence for " + assetdesc + "?");		
	if(!ret) return;
	date = new Date();
	f.action = "default.aspx?center_logged=Sentinel&count=" + date.getTime() + "&command=GEOFENCE_LOCAL_ON&assetid=" + assetid 
	f.submit();		
}

function cmdGeofenceLocalOff(){
	var f = document.customer_form;
	f.status_ok.value = "";
	var selbox = f.elements["MenuConsole1:lstAssets"];
	var si = selbox.selectedIndex;
	if(si==-1){ alert("Please select an asset from the list"); return; }
	var assetid = selbox.options[si].value;
	var assetdesc = selbox.options[si].text; 
	
	var ret = confirm("Do you wish to activate the Geofence for " + assetdesc + "?");		
	if(!ret) return;
	date = new Date();
	f.action = "default.aspx?center_logged=Sentinel&count=" + date.getTime() + "&command=GEOFENCE_LOCAL_OFF&assetid=" + assetid 
	f.submit();		
}

function cmdGeofenceSet(){
	var f = document.customer_form;
	f.status_ok.value = "";
	var selbox = f.elements["MenuConsole1:lstAssets"];
	var si = selbox.selectedIndex;
	if(si==-1){ alert("Please select an asset from the list"); return; }
	var assetid = selbox.options[si].value;
	var assetdesc = selbox.options[si].text; 
	
	var ret = confirm("Do you wish to set the Geofence for " + assetdesc + "?");		
	if(!ret) return;
	date = new Date();
	f.action = "default.aspx?center_logged=Sentinel&count=" + date.getTime() + "&command=GEOFENCE_SET&assetid=" + assetid 
	f.submit();		
}

function cmdGeofenceOn(){
	var f = document.customer_form;
	f.status_ok.value = "";
	var selbox = f.elements["MenuConsole1:lstAssets"];
	var si = selbox.selectedIndex;
	if(si==-1){ alert("Please select an asset from the list"); return; }
	var assetid = selbox.options[si].value;
	var assetdesc = selbox.options[si].text; 
	
	var ret = confirm("Do you wish to activate the Geofence for " + assetdesc + "?");		
	if(!ret) return;
	date = new Date();
	f.action = "default.aspx?center_logged=Sentinel&count=" + date.getTime() + "&command=GEOFENCE_ON&assetid=" + assetid 
	f.submit();		
}

function cmdGeofenceOff(){
	var f = document.customer_form;
	f.status_ok.value = "";
	var selbox = f.elements["MenuConsole1:lstAssets"];
	var si = selbox.selectedIndex;
	if(si==-1){ alert("Please select an asset from the list"); return; }
	var assetid = selbox.options[si].value;
	var assetdesc = selbox.options[si].text; 
	
	var ret = confirm("Do you wish to deactivate the Geofence for " + assetdesc + "?");		
	if(!ret) return;
	date = new Date();
	f.action = "default.aspx?center_logged=Sentinel&count=" + date.getTime() + "&command=GEOFENCE_OFF&assetid=" + assetid 
	f.submit();		
}

// COMMANDS :: cmdStarter:
//	
function cmdStarter(){
	var f = document.customer_form;
	f.status_ok.value = "";
	var selbox = f.elements["MenuConsole1:lstAssets"];
	var si = selbox.selectedIndex;
	if(si==-1){ alert("Please select an asset from the list"); return; }
	var assetid = selbox.options[si].value; 
	var assetdesc = selbox.options[si].text; 

	var ret = confirm("Do you wish to enable/disable the Starter for " + assetdesc + "?");		
	if(!ret) return;
	date = new Date();
	f.action = "default.aspx?center_logged=Sentinel&command=STARTER_TOGGLE&assetid=" + assetid	 + "&count=" + date.getTime()
	f.submit();		
}

function cmdStarterOn(){
	var f = document.customer_form;
	f.status_ok.value = "";
	var selbox = f.elements["MenuConsole1:lstAssets"];
	var si = selbox.selectedIndex;
	if(si==-1){ alert("Please select an asset from the list"); return; }
	var assetid = selbox.options[si].value; 
	var assetdesc = selbox.options[si].text; 

	var ret = confirm("Do you wish to enable the Starter for " + assetdesc + "?");		
	if(!ret) return;
	date = new Date();
	f.action = "default.aspx?center_logged=Sentinel&command=STARTER_ON&assetid=" + assetid + "&count=" + date.getTime()
	f.submit();		
}

function cmdStarterOff(){
	var f = document.customer_form;
	f.status_ok.value = "";
	var selbox = f.elements["MenuConsole1:lstAssets"];
	var si = selbox.selectedIndex;
	if(si==-1){ alert("Please select an asset from the list"); return; }
	var assetid = selbox.options[si].value; 
	var assetdesc = selbox.options[si].text; 

	var ret = confirm("Do you wish to disable the Starter for " + assetdesc + "?");		
	if(!ret) return;
	date = new Date();
	f.action = "default.aspx?center_logged=Sentinel&command=STARTER_OFF&assetid=" + assetid	+ "&count=" + date.getTime()
	f.submit();		
}

// COMMANDS :: cmdMaxSpeed:
//	
function cmdMaxSpeed(){
	var f = document.customer_form;
	f.status_ok.value = "";
	var selbox = f.elements["MenuConsole1:lstAssets"];
	var si = selbox.selectedIndex;
	if(si==-1){ alert("Please select an asset from the list"); return; }
	var assetid = selbox.options[si].value; 
	var assetdesc = selbox.options[si].text; 

	var ret = confirm("Do you wish to retrieve today's Maximum Speed for " + assetdesc + "?") ;		
	if(!ret) return;
	date = new Date();
	f.action = "default.aspx?center_logged=Sentinel&command=MAXSPEED_REPORT&assetid=" + assetid + "&count=" + date.getTime()
	f.submit();		
}

// COMMANDS :: cmdUnlock:
//	
function cmdUnlock(){
	var f = document.customer_form;
	f.status_ok.value = "";
	var selbox = f.elements["MenuConsole1:lstAssets"];
	var si = selbox.selectedIndex;
	if(si==-1){ alert("Please select an asset from the list"); return; }
	var assetid = selbox.options[si].value; 
	var assetdesc = selbox.options[si].text;

	var ret = confirm("Do you wish to Unlock " + assetdesc + "?") ;		
	if(!ret) return;
	date = new Date();
	f.action = "default.aspx?center_logged=Sentinel&command=UNLOCK_DOORS&assetid=" + assetid + "&count=" + date.getTime()
	f.submit();		
}

// COMMANDS :: cmdRemote:
//	
function cmdRemote(){
	var f = document.customer_form;
	f.status_ok.value = "";
	var selbox = f.elements["MenuConsole1:lstAssets"];
	var si = selbox.selectedIndex;
	if(si==-1){ alert("Please select an asset from the list"); return; }
	var assetid = selbox.options[si].value; 
	var assetdesc = selbox.options[si].text;

	var ret = confirm("Do you wish to enable/disable the Remote starter for " + assetdesc + "?") ;		
	if(!ret) return;
	date = new Date();
	f.action = "default.aspx?center_logged=Sentinel&command=REMOTE_START&assetid=" + assetid + "&count=" + date.getTime()
	f.submit();		
}

// Functions for Map Balloon
//
function findPosX(obj)
{
	
	var curleft = 0;
	//alert('offsetparent: ' + curleft);
	var counter = 0;
	//alert('OffsetWidth: ' + document.getElementById("divImage").offsetWidth );
	
	if (obj.offsetParent)
	{
		do
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
			counter++;
			//alert('divImage: ' + document.getElementById("divImage").offsetLeft);
			//alert('OffsetWidth: ' + document.getElementById("divImage").offsetWidth);
		
		}while (obj.offsetParent && counter < 2)
	}
	else if (obj.x)
	{
		
		curleft += obj.x;
	}
	//alert('curleft: ' + curleft + 'px');
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	var counter = 0;
	if (obj.offsetParent)
	{
	
		do
		{
				curtop += obj.offsetTop
				obj	= obj.offsetParent
				counter++
		}while (obj.offsetParent && counter < 2);
	}
	else if (obj.y)
		curtop += obj.y;
	//alert("Current Top: " + curtop);
	
	return curtop;
}

function VEfindPosX(obj)
{
	
	var curleft = 0;
	var counter = 0;
	
	if (obj.offsetParent)
	{
		do
		{
			curleft += obj.offsetLeft
			//alert('obj.name: ' + obj.id);
			//alert('obj.offsetLeft: ' + obj.offsetLeft);
			obj = obj.offsetParent;
			counter++;
			
		}while (obj.offsetParent && counter < 2)
	}
	else if (obj.x)
	{
		curleft += obj.x;
	}
	return curleft;
}


function VEfindPosY(obj)
{
	var curtop = 0;
	var counter = 0;
	if (obj.offsetParent)
	{
		do
		{
				curtop += obj.offsetTop
				obj	= obj.offsetParent
				counter++
		}while (obj.offsetParent && counter < 2);
	}
	else if (obj.y)
		curtop += obj.y;
	//alert("Current Top: " + curtop);
	
	return curtop;
}


function setBalloonLocation(obj, name)
{		
	var myName = new getObj(name);
	var myObj = document.getElementById(obj);
	
	
	var posX = VEfindPosX(myObj);
	var posY = VEfindPosY(myObj);
	
	//alert('x: ' + posX + ' y: ' + posY);
	myName.style.left = posX - 63  + 'px';
	myName.style.top = posY - 157  + 'px';
	
}
		

function SetBalloonVE(obj, name, sTheme)
{		
	var info = new Array();
	info = eval('MapConsole' + sTheme +'.AjaxGetLocationInfo()');
	//alert ("In SetBalloonVE javascript functions");
	var locationName = info.value[0];
	var latitude  =	info.value[1];
	var longitude =	info.value[2];
	var address1  =	info.value[3];
	var address2  =	info.value[4];
	var gpsUTCTime = info.value[5];
	var gpsLocalTime = info.value[6];
	
	document.getElementById("LocationName").innerHTML=  locationName;
	document.getElementById("Latitude").innerHTML= latitude;
	document.getElementById("Longitude").innerHTML= longitude;
	document.getElementById("address1").innerHTML =  address1;
	document.getElementById("address2").innerHTML = address2;
	document.getElementById("GPSUTCTime").innerHTML = gpsUTCTime;
	document.getElementById("GPSLocalTime").innerHTML = gpsLocalTime;
	
	var myBalloon = new getObj(name);
	var centerObj = document.getElementById(obj);

	var posX = VEfindPosX(centerObj);
	var posY = VEfindPosY(centerObj);
	
	myBalloon.style.left = posX  - 63 + 'px';
	myBalloon.style.top = posY -  157  + 'px';
	
	showHide(name);
}		


function showHide(name)
{
	
	var myName = new getObj(name);
	st = myName.style.visibility;
	//alert ("In showHide method: " + st);
	//alert (name);
	if ( st == "visible")
		myName.style.visibility = "hidden";
	else
		myName.style.visibility = "visible";
}

function getObj(name)
{
	if (document.getElementById)
	{
		this.obj = document.getElementById(name);
		try
		{				 
			this.style = document.getElementById(name).style;// document.getElementById(name).style;
		}
		catch(e)
		{
			//alert('no getelementbyID style');
		}
	}
	else if (document.all)
	{
		this.obj = document.all[name];
		try
		{
			this.style = document.all[name].style;
		}
		catch(e)
		{
		}
	}
	else if (document.layers)
	{
		if (document.layers[name])
		{
	   		this.obj = document.layers[name];
	   		this.style = document.layers[name];
		}
		else
		{
			this.obj = document.layers.testP.layers[name];
			this.style = document.layers.testP.layers[name];
		}
	}
	
}


// Mouseover effect for close icon image in Balloon
//
function changeCloseImage(obj, flag)
{	
	if (flag)
		obj.src = "images/closeicon_on.jpg";
	else
		obj.src = "images/closeicon.jpg";
}

function redirectPage(obj)
{
	location.href = obj;
}

// Virtual Earth JS
//
var iZoomLevel = 3;


function GMapChangeMapStyle(psStyle, psTheme)
{
		var oDivImage2 = document.getElementById('divImage2');
		var oImgMap = document.getElementById('divRoadImg');
		var oProgress = document.getElementById('progress');
		if (psStyle=='ROAD')
		{
			ChangeMapTypeVE('MAPPOINT', psTheme);
			oDivImage2.style.visibility = "hidden";
			oDivImage2.style.zindex = 0;
			
			oImgMap.style.visibility = "visible";
			oImgMap.style.zindex = 103;
		}
		else if (psStyle=='AERIAL')
		{
			var fLat = document.getElementById("Latitude").innerHTML;
			var fLong = document.getElementById("Longitude").innerHTML;
			
			var myBalloon = document.getElementById("Balloon"); 
			var balloon = myBalloon.style.visibility;
			
			if ( balloon == "visible" )
				myBalloon.style.visibility = "hidden"
					
			oDivImage2.style.visibility = "visible";
			oDivImage2.style.zindex = 500;
			
			oImgMap.style.visibility = "hidden";
			oImgMap.style.zindex = 5;
		
		}
		GMapZoomMap(last_zoom, psTheme);
}


function VEChangeMapStyle(psStyle, psTheme)
{
		var oDivImage2 = document.getElementById('divImage2');
		var oImgMap = document.getElementById('divRoadImg');
		var oProgress = document.getElementById('progress');
		if (psStyle=='ROAD')
		{
			ChangeMapTypeVE('MAPPOINT', psTheme);
			oDivImage2.style.visibility = "hidden";
			oDivImage2.style.zindex = 0;
			
			oImgMap.style.visibility = "visible";
			oImgMap.style.zindex = 103;
		}
		else if (psStyle=='AERIAL')
		{
			var fLat = document.getElementById("Latitude").innerHTML;
			var fLong = document.getElementById("Longitude").innerHTML;
			
			var myBalloon = document.getElementById("Balloon"); 
			var balloon = myBalloon.style.visibility;
			
			if ( balloon == "visible" )
				myBalloon.style.visibility = "hidden"
					
			oDivImage2.style.visibility = "visible";
			oDivImage2.style.zindex = 500;
			
			oImgMap.style.visibility = "hidden";
			oImgMap.style.zindex = 5;
		
		}
		VEZoomMap(last_zoom, psTheme);
}
	    
function VEZoomIn(psTheme)
{
	var oRadioBtn = document.forms[0].elements['rdRoad'];	
	
	if (oRadioBtn.checked )
	{
		SetLoadingImageVE(psTheme, 'mappoint');
		if(last_zoom < 6) last_zoom++;
			zoomMapVE(last_zoom, psTheme);
		
		//zoomInVE(psTheme);
	}
	else
	{
		var fLat = document.getElementById("Latitude").innerHTML;
		var fLong = document.getElementById("Longitude").innerHTML;
		
		if (iZoomLevel < 6 )
		{
			iZoomLevel = iZoomLevel + 1;
			VEZoomMap(iZoomLevel, psTheme);
		}
	}
}
	
function VEZoomOut(psTheme)
{
	var oRadioBtn =document.forms[0].elements['rdRoad'];	
	
	if (oRadioBtn.checked )
	{
		SetLoadingImageVE(psTheme, 'mappoint');
		if(last_zoom > 0) last_zoom--;
			zoomMapVE(last_zoom, psTheme);
		//zoomOutVE(psTheme);
	}
	else
	{
		var fLat = document.getElementById("Latitude").innerHTML;
		var fLong = document.getElementById("Longitude").innerHTML;
		
		if (iZoomLevel > 0)
		{
			iZoomLevel = iZoomLevel - 1;
			VEZoomMap(iZoomLevel, psTheme);
		}
	}
}

function GMapZoomIn(psTheme)
{
	var oRadioBtn = document.forms[0].elements['rdRoad'];	
	
	if (oRadioBtn.checked )
	{
		SetLoadingImageVE(psTheme, 'mappoint');
		if(last_zoom < 6) last_zoom++;
			zoomMapVE(last_zoom, psTheme);
		
		//zoomInVE(psTheme);
	}
	else
	{
		var fLat = document.getElementById("Latitude").innerHTML;
		var fLong = document.getElementById("Longitude").innerHTML;
		
		if (iZoomLevel < 6 )
		{
			iZoomLevel = iZoomLevel + 1;
			GMapZoomMap(iZoomLevel, psTheme);
		}
	}
}
	

function GMapZoomOut(psTheme)
{
	var oRadioBtn =document.forms[0].elements['rdRoad'];	
	
	if (oRadioBtn.checked )
	{
		SetLoadingImageVE(psTheme, 'mappoint');
		if(last_zoom > 0) last_zoom--;
			zoomMapVE(last_zoom, psTheme);
		//zoomOutVE(psTheme);
	}
	else
	{
		var fLat = document.getElementById("Latitude").innerHTML;
		var fLong = document.getElementById("Longitude").innerHTML;
		
		if (iZoomLevel > 0)
		{
			iZoomLevel = iZoomLevel - 1;
			GMapZoomMap(iZoomLevel, psTheme);
		}
	}
}



function GMapZoomMap(piZoomLevel, psTheme)
{
	var oRadioBtn =document.forms[0].elements['rdRoad'];
	
	if (oRadioBtn.checked)
	{
		SetLoadingImageVE(psTheme, 'mappoint');
		zoomMapVE(piZoomLevel, psTheme);
	}
	else
	{
		var fLat = document.getElementById("Latitude").innerHTML;
		var fLong = document.getElementById("Longitude").innerHTML;
		
		iZoomLevel = piZoomLevel 
		//if ( psTheme == "ANDALE" && iZoomLevel > 2)
		//	iZoomLevel = 2;
			
		//alert ("Check map is null or not: " + map );
		//alert ("Zoom Level: " + iZoomLevel);
		if (iZoomLevel == 6 )
			map.setZoom(iZoomLevel + 13);  // Set deeper zoom (lvl 18) at level 6
		else
		{
			//map.AttachEvent("onerror", function(){alert("Some error");});
			map.setZoom(iZoomLevel + 11);
		}
		
		var zimg = document.images["zoom" + piZoomLevel];
		zimg.src = "templates/" + theme_folder + "/images/zoom_on.gif";
		
		for(i=0;i<=6;i++) 
		{
			if(i!=piZoomLevel) 
			{
				zimg = document.images["zoom" + i];
				zimg.src = "templates/" + theme_folder + "/images/zoom_off.gif";
			}
		}
		last_zoom = piZoomLevel;
	}
}

	
function VEZoomMap(piZoomLevel, psTheme)
{
	var oRadioBtn =document.forms[0].elements['rdRoad'];
	
	if (oRadioBtn.checked)
	{
		SetLoadingImageVE(psTheme, 'mappoint');
		zoomMapVE(piZoomLevel, psTheme);
	}
	else
	{
		var fLat = document.getElementById("Latitude").innerHTML;
		var fLong = document.getElementById("Longitude").innerHTML;
		
		iZoomLevel = piZoomLevel 
		if ( psTheme == "ANDALE" && iZoomLevel > 2)
			iZoomLevel = 2;
			
		//alert ("Check map is null or not: " + map );
		//alert ("Zoom Level: " + iZoomLevel);
		if (iZoomLevel == 6 )
			map.SetZoomLevel(iZoomLevel + 12);  // Set deeper zoom (lvl 18) at level 6
		else
		{
			//map.AttachEvent("onerror", function(){alert("Some error");});
			map.SetZoomLevel(iZoomLevel + 11);
		}
		
		var zimg = document.images["zoom" + piZoomLevel];
		zimg.src = "templates/" + theme_folder + "/images/zoom_on.gif";
		
		for(i=0;i<=6;i++) 
		{
			if(i!=piZoomLevel) 
			{
				zimg = document.images["zoom" + i];
				zimg.src = "templates/" + theme_folder + "/images/zoom_off.gif";
			}
		}
		last_zoom = piZoomLevel;
	}
}



function SetCenterGMap(divID, poLat, poLong, psImageSrc, poTitle, poInfo, psMapType)
{

	//document.getElementById(divID).style.visibility = "visible";

	if (psMapType == null)
		psMapType = '';
	
	map = new GMap2(document.getElementById(divID));

	map.addControl(new GMapTypeControl()); 
	map.addControl(new GLargeMapControl());
	map.addControl(new GScaleControl());
	map.setCenter(new GLatLng(poLat, poLong), 13);

	if (psMapType == '' || psMapType == 'r')
	{
		map.setMapType(G_NORMAL_MAP);
	}
	else if (psMapType == 'a')
	{
	   map.setMapType(G_SATELLITE_MAP);
	}
	else
	{
	   map.setMapType(G_HYBRID_MAP);
	}

	GMapAddIcon(0, poLat, poLong, psImageSrc, poTitle, poInfo);
	map.openInfoWindow(map.getCenter(), "<DIV class='textBold'>" + poTitle +"</DIV><BR>" + poInfo );
}



// http://maps.forum.nu/gm_clickable_circle.html
/// Geofence algorithm
var cicleLine;
function GMapAddSquare(latin, lonin, radius, color) 
{ 

	// Caculate diagonal distance from radius
	//
	var diag = radius * Math.sqrt(2);

	var locs = new Array(); 
	var lat1 = latin * Math.PI/180.0; 
	var lon1 = lonin * Math.PI/180.0; 
	var d = diag/3956; 
	var x; 
	
	for (x = 45; x <= 360; x+=90) 
	{ 
		var tc = (x / 90)* Math.PI / 2; 
		var lat = Math.asin(Math.sin(lat1)*Math.cos(d)+Math.cos(lat1)*Math.sin(d)*Math.cos(tc)); 
		lat = 180.0 * lat / Math.PI; 
		var lon; 
		if (Math.cos(lat1)==0) 
		{ 
			lon=lonin; // endpoint a pole 
		} 
		else 
		{ 
			lon = ((lon1 - Math.asin(Math.sin(tc) * Math.sin(d)/Math.cos(lat1)) + Math.PI) % (2 * Math.PI)) - Math.PI; 
		} 
		lon = 180.0 * lon / Math.PI; 
		//var loc = new VELatLong(lat,lon); 
		var loc = new GLatLng(lat, lon);
		
		//locs.push(loc); 
		locs.push(loc);
	} 
	circleLine = new GPolygon(locs, color, 1, 1, color, 0.5);
	map.addOverlay(circleLine);
}


// http://maps.forum.nu/gm_clickable_circle.html
/// Geofence algorithm
var cicleLine;
function GMapAddCircle(latin, lonin, radius, color) 
{ 
	var locs = new Array(); 
	var lat1 = latin * Math.PI/180.0; 
	var lon1 = lonin * Math.PI/180.0; 
	var d = radius/3956; 
	var x; 
	
	for (x = 0; x <= 360; x+=6) 
	{ 
		var tc = (x / 90)* Math.PI / 2; 
		var lat = Math.asin(Math.sin(lat1)*Math.cos(d)+Math.cos(lat1)*Math.sin(d)*Math.cos(tc)); 
		lat = 180.0 * lat / Math.PI; 
		var lon; 
		if (Math.cos(lat1)==0) 
		{ 
			lon=lonin; // endpoint a pole 
		} 
		else 
		{ 
			lon = ((lon1 - Math.asin(Math.sin(tc) * Math.sin(d)/Math.cos(lat1)) + Math.PI) % (2 * Math.PI)) - Math.PI; 
		} 
		lon = 180.0 * lon / Math.PI; 
		//var loc = new VELatLong(lat,lon); 
		var loc = new GLatLng(lat, lon);
		
		//locs.push(loc); 
		locs.push(loc);
	} 
	circleLine = new GPolygon(locs, color, 1, 1, color, 0.5);
	map.addOverlay(circleLine);
}

function GMapAddIcon(pinID, poLat, poLong, psImageSrc, poTitle, poInfo)
{
	if (document.images)
	{
		oImage1 = new Image();
		oImage1.src = psImageSrc;
	}
	var newPoint = new GLatLng(poLat, poLong);
	var newIcon = new GIcon();

	//alert('location host: ' + newIcon.image);
	var width = 15;
	var height = 15;
	
	
	// dirty fix, jic image is not dl properly
	if (oImage1.width > 0 )
	{
		width = oImage1.width;
	}
	else
	{
		if (psImageSrc.match('-') )
			width = 20;
	}
	if (oImage1.height > 0 )
	{
		height = oImage1.height;
		if (psImageSrc.match('-') )
			height = 20;
	}
	newIcon.iconSize = new GSize(width, height);
	//alert('width: ' + oImage1.width +  ' height: ' + oImage1.height);
	newIcon.iconAnchor = new GPoint(10,20);
	newIcon.infoWindowAnchor = new GPoint(9,2);
	newIcon.infoShadowAnchor = new GPoint(18,25);
	newIcon.image = psImageSrc;
	
	markerOptions = { icon:newIcon };
 	var marker = new GMarker(newPoint, markerOptions);
	GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml("<DIV class='textBold'>" + poTitle +"</DIV><BR>" + poInfo )});
	//alert('src: ' + psImageSrc);
 	map.addOverlay(marker);
}
	
function SetCenterVE30(divID, poLat, poLong, psImageSrc, poTitle, poInfo, psMapType)
{
	try
	{
	// If the browser is Firefox get the version number
	var ffv = 0;
	var ffn = "Firefox/"
	var ffp = navigator.userAgent.indexOf(ffn);
	if (ffp != -1) ffv = parseFloat(navigator.userAgent.substring(ffp + ffn.length));
	// If we're using Firefox 1.5 or above override the Virtual Earth drawing functions to use SVG
	if (ffv >= 1.5) {
	Msn.Drawing.Graphic.CreateGraphic=function(f,b) { return new Msn.Drawing.SVGGraphic(f,b) }
	}
	document.getElementById(divID).style.visibility = "visible";

	map = new VEMap(divID);
	map.LoadMap();
	map.SetCenter(new VELatLong(poLat, poLong));
	map.SetZoomLevel(12);
	
	if (psMapType == null)
		psMapType = '';
		
	if (psMapType == '')
	{
		map.SetMapStyle('r');
	}
	else
	{
	   map.SetMapStyle(psMapType);
	 }
	 
	//map.HideDashboard();
	map.SetDashboardSize(VEDashboardSize.Normal);
	VE30_AddPushPin(0, poLat, poLong, psImageSrc, poTitle, poInfo);
	}
	catch(e)
	{
	//alert ("an exception occured in setcenterve30 function " + e.message);
	}
}


function SetCenterVE60(divID, poLat, poLong, psImageSrc, poTitle, poInfo, psMapType)
{
	try
	{
		// If the browser is Firefox get the version number
		var ffv = 0;
		var ffn = "Firefox/"
		var ffp = navigator.userAgent.indexOf(ffn);
		if (ffp != -1) ffv = parseFloat(navigator.userAgent.substring(ffp + ffn.length));
		// If we're using Firefox 1.5 or above override the Virtual Earth drawing functions to use SVG
		if (ffv >= 1.5) {
		Msn.Drawing.Graphic.CreateGraphic=function(f,b) { return new Msn.Drawing.SVGGraphic(f,b) }
		}
		//document.getElementById(divID).style.visibility = "visible";

		if ( map == null)
		{
			map = new VEMap(divID);
			map.LoadMap();
			map.SetCenter(new VELatLong(poLat, poLong));
			map.SetZoomLevel(12);
		}
		
		if (psMapType == null)
			psMapType = '';
			
		if (psMapType == '')
		{
			map.SetMapStyle('r');
		}
		else
		{
			map.SetMapStyle(psMapType);
		}
		 
		if (location.host.toLowerCase() == "mobileconnect.fleetfind.ca")
		{
			map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);
		}
		else
		{
			map.SetScaleBarDistanceUnit(VEDistanceUnit.Miles);
		}
		
		map.SetDashboardSize(VEDashboardSize.Normal);		
		VE60_AddPushPin(0, poLat, poLong, psImageSrc, poTitle, poInfo);
	}
	catch(e)
	{
	//alert ("an exception occured in setcenterve30 function " + e.message);
	}
}



function VEPanToCenter(poLat, poLong)
{
	try
	{
		//map.PanToLatLong(new VELatLong(poLat, poLong));
		map.SetCenter(new VELatLong(poLat, poLong));
	}
	catch (e)
	{
		//alert (e.message);
	}
}


//  Src: http://howtopedia.spaces.live.com/blog/cns!A1A77DBB3876417A!147.entry
//  Geofence algorithm
function VEAddCircle_OLD(latin, lonin, radius, color) 
{ 

	alert('circle1');
	var locs = new Array(); 
	var lat1 = latin * Math.PI/180.0; 
	var lon1 = lonin * Math.PI/180.0; 
	var d = radius/3956; 
	var x; 
	for (x = 0; x <= 360; x+=6) 
	{ 
		var tc = (x / 90)* Math.PI / 2; 
		var lat = Math.asin(Math.sin(lat1)*Math.cos(d)+Math.cos(lat1)*Math.sin(d)*Math.cos(tc)); 
		lat = 180.0 * lat / Math.PI; 
		var lon; 
		if (Math.cos(lat1)==0) 
		{ 
			lon=lonin; // endpoint a pole 
		} 
		else 
		{ 
			lon = ((lon1 - Math.asin(Math.sin(tc) * Math.sin(d)/Math.cos(lat1)) + Math.PI) % (2 * Math.PI)) - Math.PI; 
		} 
		lon = 180.0 * lon / Math.PI; 
		var loc = new VELatLong(lat,lon); 
		locs.push(loc); 
	} 
		
	poly = new VEPolygon('geofence1', locs);
	poly.SetOutlineWidth(1);
	
	if (color=='BLUE' || color == 'Blue' || color == 'blue')
	{
		poly.SetOutlineColor(new VEColor(0, 0, 250, 0.8));
		poly.SetFillColor(new VEColor(0, 0, 250, 0.3));
	}
	else if (color=='RED' || color == 'Red' || color == 'red')
	{
		poly.SetOutlineColor(new VEColor(250, 0, 0, 0.8));
		poly.SetFillColor(new VEColor(250, 0, 0, 0.3));
	}
	else
	{
		poly.SetOutlineColor(new VEColor(250, 0, 0, 0.8));
		poly.SetFillColor(new VEColor(250, 0, 0, 0.3));
	}
	map.SetMapView(locs); 
	map.AddPolygon(poly); 

}


function VEAddPolygon(latin, lonin, latin2, lonin2, color) 
{

	try
	{
		var poly = new VEShape(VEShapeType.Polygon, [new VELatLong(latin, lonin),
																					new VELatLong(latin, lonin2),
																					new VELatLong(latin2, lonin2),
																					new VELatLong(latin2, lonin)]);
		poly.SetLineWidth(2);
		poly.HideIcon();
		if (color=='BLUE' || color == 'Blue' || color == 'blue')
		{
			poly.SetLineColor(new VEColor(0, 0, 250, 0.8));
			poly.SetFillColor(new VEColor(0, 0, 250, 0.3));
		}
		else if (color=='RED' || color == 'Red' || color == 'red')
		{
			poly.SetLineColor(new VEColor(250, 0, 0, 0.8));
			poly.SetFillColor(new VEColor(250, 0, 0, 0.3));
		}
		else
		{
			poly.SetLineColor(new VEColor(250, 0, 0, 0.8));
			poly.SetFillColor(new VEColor(250, 0, 0, 0.3));
		}
		map.AddShape(poly);
	}
	catch(e)
	{
	}
	
}



//  Src: http://howtopedia.spaces.live.com/blog/cns!A1A77DBB3876417A!147.entry
//  Geofence algorithm
function VEAddCircle(latin, lonin, radius, color) 
{ 
	var locs = new Array(); 
	var lat1 = latin * Math.PI/180.0; 
	var lon1 = lonin * Math.PI/180.0; 
	var d = radius/3956; 
	var x; 
	
	try
	{
		for (x = 0; x <= 360; x+=3) 
		{ 
			var tc = (x / 90)* Math.PI / 2; 
			var lat = Math.asin(Math.sin(lat1)*Math.cos(d)+Math.cos(lat1)*Math.sin(d)*Math.cos(tc)); 
			lat = 180.0 * lat / Math.PI; 
			var lon; 
			if (Math.cos(lat1)==0) 
			{ 
				lon=lonin; // endpoint a pole 
			} 
			else 
			{ 
				lon = ((lon1 - Math.asin(Math.sin(tc) * Math.sin(d)/Math.cos(lat1)) + Math.PI) % (2 * Math.PI)) - Math.PI; 
			} 
			lon = 180.0 * lon / Math.PI; 
			var loc = new VELatLong(lat,lon); 
			locs.push(loc); 
		} 
		//var poly = new VEPolyline(999, locs, new VEColor(0,255,0,.5) , 4);

		poly = new VEShape(VEShapeType.Polygon,  locs);
		poly.SetLineWidth(1);
		poly.HideIcon();
		
		if (color=='BLUE' || color == 'Blue' || color == 'blue')
		{
			poly.SetLineColor(new VEColor(0, 0, 250, 0.8));
			poly.SetFillColor(new VEColor(0, 0, 250, 0.3));
		}
		else if (color=='RED' || color == 'Red' || color == 'red')
		{
			poly.SetLineColor(new VEColor(250, 0, 0, 0.8));
			poly.SetFillColor(new VEColor(250, 0, 0, 0.3));
		}
		else
		{
			poly.SetLineColor(new VEColor(250, 0, 0, 0.8));
			poly.SetFillColor(new VEColor(250, 0, 0, 0.3));
		}
		//map.SetMapView(locs); 
		map.AddShape(poly); 
	}
	catch(e)
	{
		alert(e);
	}
}




//  Src: http://howtopedia.spaces.live.com/blog/cns!A1A77DBB3876417A!147.entry
//  Geofence algorithm
function VEAddSquare(latin, lonin, radius, color) 
{ 
	//alert('rad: ' + radius);
	// Caculate diagonal distance from radius
	//
	var diag = radius * Math.sqrt(2);

	var locs = new Array(); 
	var lat1 = latin * Math.PI/180.0; 
	var lon1 = lonin * Math.PI/180.0; 
	var d = diag/3956; 
	var x; 
	
	try
	{
		for (x = 45; x <= 360; x+=90) 
		{ 
			var tc = (x / 90)* Math.PI / 2; 
			var lat = Math.asin(Math.sin(lat1)*Math.cos(d)+Math.cos(lat1)*Math.sin(d)*Math.cos(tc)); 
			lat = 180.0 * lat / Math.PI; 
			var lon; 
			if (Math.cos(lat1)==0) 
			{ 
				lon=lonin; // endpoint a pole 
			} 
			else 
			{ 
				lon = ((lon1 - Math.asin(Math.sin(tc) * Math.sin(d)/Math.cos(lat1)) + Math.PI) % (2 * Math.PI)) - Math.PI; 
			} 
			lon = 180.0 * lon / Math.PI; 
			var loc = new VELatLong(lat,lon); 
			locs.push(loc); 
		} 
		//var poly = new VEPolyline(999, locs, new VEColor(0,255,0,.5) , 4);

		poly = new VEShape(VEShapeType.Polygon,  locs);
		poly.SetLineWidth(2);
		poly.HideIcon();
		
		if (color=='BLUE' || color == 'Blue' || color == 'blue')
		{
			poly.SetLineColor(new VEColor(0, 0, 250, 0.8));
			poly.SetFillColor(new VEColor(0, 0, 250, 0.3));
		}
		else if (color=='RED' || color == 'Red' || color == 'red')
		{
			poly.SetLineColor(new VEColor(250, 0, 0, 0.8));
			poly.SetFillColor(new VEColor(250, 0, 0, 0.3));
		}
		else
		{
			poly.SetLineColor(new VEColor(250, 0, 0, 0.8));
			poly.SetFillColor(new VEColor(250, 0, 0, 0.3));
		}
		//map.SetMapView(locs); 
		map.AddShape(poly); 
	}
	catch(e)
	{
		alert(e);
	}
}



function VE30_AddPushPin(pinID, poLat, poLong, psImageSrc, poTitle, poInfo)
{
	try
	{
		var pin = new VEPushpin(pinID, 
						new VELatLong(poLat, poLong),
						psImageSrc, 
						'<STRONG>' + poTitle + '</STRONG>', 
						poInfo, 
						'iconStyle');
		map.AddPushpin(pin);
	}
	catch(e)
	{
	
	}
}


function VE60_AddPushPin(pinID, poLat, poLong, psImageSrc, poTitle, poInfo)
{
	try
	{
		var shape = new VEShape(VEShapeType.Pushpin, new VELatLong(poLat, poLong));
		shape.SetCustomIcon(psImageSrc);
		shape.SetTitle(poTitle);
		shape.SetDescription(poInfo);
		map.AddShape(shape);
	}
	catch(e)
	{
	
	}
}

function VE60_AddCustomPushPin(pinID, poLat, poLong, psImageSrc, poTitle, poInfo)
{
	try
	{
		//alert('hello');
		var shape = new VEShape(VEShapeType.Pushpin, new VELatLong(poLat, poLong));
		
		shape.SetCustomIcon("<div class='pinStyle2'><div class='text'>" + pinID + "</div></div>");		
		shape.SetTitle(poTitle);

		shape.SetDescription(poInfo);
		//alert('hello2');
		map.AddShape(shape);
	}
	catch(e)
	{
		alert(eval(e));
	}
}



// Zoom Map on MapConsole   (Based on old zoom_map)
// 
function zoomMapVE(zfactor, sTheme) 
{
	var mapURL = eval("MapConsole"+ sTheme + ".AjaxRenderedMapURL(" + zfactor + ")");
	var img = null;
	var zimg = document.images["zoom" + zfactor];
	img = eval("document.images['MapConsole" + sTheme + "1_imgMap']");
	if (mapURL.value == "") 
		img.src = "~/images/NoImage.jpg"
	else
		img.src = mapURL.value;
	last_zoom = zfactor;		
	setImageScaleVE(sTheme);
	zimg.src = "templates/" + theme_folder + "/images/zoom_on.gif";
	
	for( i=0; i<=6; i++) 
	{
		if(i!=zfactor) 
		{
			zimg = document.images["zoom" + i];
			zimg.src = "templates/" + theme_folder + "/images/zoom_off.gif";
		}
	}
} 
