var isMozilla;
var objDiv = null;
var originalDivHTML = "";
var DivID = "dimming";
var over = false;
var state = '1';
var playsound = '0';
var otimerid = null;
var inite = false;
var emgnum = 0;
var http_status_request = false;
var baseurl = "/location/assetact?";
var left = 0;
var top = 0;
var nodeListPast001;


if(window.XMLHttpRequest)
{
	http_status_request=new XMLHttpRequest();
}
else if(window.ActiveXObject){
	http_status_request=new ActiveXObject("Microsoft.XMLHTTP");
}

function initStatus() {
	if(!inite)
		initEvent();
	doStatus();
}

function onUnloadStatus() {
	if(otimerid != null)
		clearTimeout(otimerid);
}

function doStatus() {
	showStatus();
}

function initHome() {
	var home = document.getElementById("home").style;
	home.width = screen.width - 220;
	home.height = screen.height - 300;
}

function showStatus() {
	if( !http_status_request) 
		return;
      var url = baseurl + "command=eventstatus&userId=" + ebiByName('userId')[0].value;
	http_status_request.open("GET", url, true);
	http_status_request.onreadystatechange = handleevenStatusResponse;
	http_status_request.send(null);
}

function handleevenStatusResponse() {
        if (http_status_request.readyState == 4  && http_status_request.status == 200) {
			  var xmlString = http_status_request.responseXML;
                    var nodeListPast = xmlString.documentElement.getElementsByTagName( "Event" );
                    if(nodeListPast.length > 0) {
        	  if(emgnum < nodeListPast.length)
					  playsound = '0';
				  emgnum = nodeListPast.length;

				originalDivHTML =  ' <table  width="100%" border="1" cellpadding="2" cellspacing="0" bordercolor="#FFFFFF" style="background-color: #FFFFFF;">';

				var role = nodeListPast[0 ].attributes.item( 6 ).nodeValue;
				if(trim(role) == "1") {
//					originalDivHTML += 		'<tr><td colspan="6"  align=center>&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>'+
					originalDivHTML += 	'<tr > '+
								'<TH class="table2" style="width: 10%; word-wrap: break-word;">User</TH>'+
								'<TH class="table2" style="width: 10%; word-wrap: break-word;">Device</TH>'+
								'<TH class="table2" style="width: 25%; word-wrap: break-word;">Event</TH>'+
								'<TH class="table2" style="width: 30%; word-wrap: break-word;">DD/MM/YYYY HH:MM:SS</TH>'+
								'<TH class="table2" style="width: 25%; word-wrap: break-word;" colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="0">'+
								'<tr>'+
								'<td><img src="images/bin_closed.png" alt="bin"></td>'+
								'<td><a href="javascript:deleteAllemg()" class="text_highlight">Delete All</a></td>'+
								'</tr>'+
								'</table></TH>'
							'</tr>';

					  for( var i = 0 ; i < nodeListPast.length ; i++ ) {
						  var status = nodeListPast[ i ].attributes.item( 1 ).nodeValue;
						  if(status != '' )
							originalDivHTML += '<TR><TD align=center class="border_inner" >' + nodeListPast[ i ].attributes.item( 5 ).nodeValue + '</TD>' + 
								  '<TD align=center class="border_inner" >' + nodeListPast[ i ].attributes.item( 0 ).nodeValue + '</TD>' + 
								  '<TD align=center class="border_inner" >' + nodeListPast[ i ].attributes.item( 1 ).nodeValue + '</TD>' + 
								  '<TD align=center class="border_inner" >' + nodeListPast[ i ].attributes.item( 3 ).nodeValue + '</TD>' + 
								  '<TD align=center class="border_inner" > <A Href="/location/map/MapAdministrator.do?activity=emergency&userId=' + ebiByName('userId')[0].value+'&unitId=' + nodeListPast[ i ].attributes.item( 2 ).nodeValue + 
								   '&datetm=' + nodeListPast[ i ].attributes.item( 3 ).nodeValue + 
								   '&deviceId=' + nodeListPast[ i ].attributes.item( 0 ).nodeValue + '">To Map</A></TD>'+
								  '<TD align=center class="border_inner" ><A Href="javascript:handled(' + nodeListPast[ i ].attributes.item( 4 ).nodeValue+')">Handled</A></TD></TR>';
					  			 
					  }
				} else {
//					originalDivHTML += 		'<tr><td colspan="5"  align=center>&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>'+
					originalDivHTML += 	'<tr > '+
								'<TH class="table2" style="width: 20%; word-wrap: break-word;">Device</TH>'+
								'<TH class="table2" style="width: 25%; word-wrap: break-word;">Event</TH>'+
								'<TH class="table2" style="width: 30%; word-wrap: break-word;">DD/MM/YYYY HH:MM:SS</TH>'+
								'<TH class="table2" style="width: 25%; word-wrap: break-word;" colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="0">'+
								'<tr>'+
								'<td><img src="images/bin_closed.png" alt="bin"></td>'+
								'<td><a href="javascript:deleteAllemg()" class="text_highlight">Delete All</a></td>'+
								'</tr>'+
								'</table></TH>'
								//'<TH class="table2" style="width: 25%; word-wrap: break-word;" colspan="2"></TH>'+
							'</tr>';
//<A Href="javascript:handledAll('+')">Remove All</A>
//'<TH style="width: 10%; word-wrap: break-word;">123</TH>'+
					  for( var i = 0 ; i < nodeListPast.length ; i++ ) {
						  var status = nodeListPast[ i ].attributes.item( 1 ).nodeValue;
						  if(status != '' )
							originalDivHTML += '<TR><TD align=center class="border_inner" >' + nodeListPast[ i ].attributes.item( 0 ).nodeValue + '</TD>' + 
								  '<TD align=center class="border_inner" >' + nodeListPast[ i ].attributes.item( 1 ).nodeValue + '</TD>' + 
								  '<TD align=center class="border_inner" >' + nodeListPast[ i ].attributes.item( 3 ).nodeValue + '</TD>' + 
								  '<TD align=center class="border_inner" > <A Href="/location/map/MapAdministrator.do?activity=emergency&userId=' + ebiByName('userId')[0].value+'&unitId=' + nodeListPast[ i ].attributes.item( 2 ).nodeValue + 
								   '&datetm=' + nodeListPast[ i ].attributes.item( 3 ).nodeValue + 
								   '&deviceId=' + nodeListPast[ i ].attributes.item( 0 ).nodeValue + '">To Map</A></TD>'+
								  '<TD align=center class="border_inner" ><A Href="javascript:handled(' + nodeListPast[ i ].attributes.item( 4 ).nodeValue+')">Handled</A></TD></TR>';
								
					  }
				}

				originalDivHTML += '</table>';
                       
					//   displayWindow();
						
					displayAlertWindow(); //Add by Tony Jiang on Dec.01,2009	
                       
			      otimerid = setTimeout("doStatus()",60000);

			  } else {  ebi(DivID).style.visibility = "hidden"; 
							document.getElementById("alertid").style.display="none";
							state='1';
                             otimerid = setTimeout("doStatus()",60000);
                           }


		  } //else otimerid = setTimeout("doStatus()",30000);

}

function handled(unitid)
{
	var answer = confirm ('Remove this Record ?' );
	if(answer) {
		if( !http_status_request && unitid != null ) 
			return;
		var url = baseurl + "command=emghandled&unitId=" + unitid;
		http_status_request.open("GET", url, true);
		http_status_request.onreadystatechange = handledEmgResponse;
		http_status_request.send(null);
	}
}
//By Qing Zhang
//Purpose:Remove all Records from DataBase
//function handledByUnitId(url)
//{
//	
//		if( !http_status_request && unitid != null ) 
//			return;
		//var url = baseurl + "command=emghandledByUnitIdList&unitId=" + unitid;
//		http_status_request.open("GET", url, true);
  //          http_status_request.onreadystatechange = handledEmgResponse;
	//      http_status_request.send("");
//}
//By Qing Zhang
//Purpose:Handle by unitIdList
//function handledAll()
//{
  //    nodeListPast001=nodeListPast;
    //  var answer = confirm ('Remove all Records?' );
     // var i=0; 
      //var total=nodeListPast001.length;
      //var tmp;
	//if(answer) {
	//	if( !http_status_request && nodeListPast!= null ) 
	//		return;
        //     var url = baseurl + "command=emghandledByUnitIdList"; 
          //   while(i<total){
            //     url=url+"&unitId="+nodeListPast001[i].attributes.item( 4 ).nodeValue;
              //   alert(url);
              //   i=i+1;
             //    }
	//	http_status_request.open("GET", url, true);
      //      http_status_request.onreadystatechange = handledEmgResponse;
	//      http_status_request.send(null);
  	 //     }
 //}

function handledEmgResponse() {
	  if (http_status_request.readyState == 4  && http_status_request.status == 200) {
			  var txt = http_status_request.responseText;
			  if(trim(txt) == "1") {
				  if(otimerid != null)
					  clearTimeout(otimerid);
				  showStatus();
			  }
	  }
}
function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}


function turnoffsound()
{
	//ebi('auEmb').innerHTML = '';
	//playsound = false;
	if(playsound == '1') {
		document.getElementById('auEmb').innerHTML = '';
		document.getElementById('auTxt').innerHTML = 'Enable Audible Alarm';
		//alert('turnoffsound 1');
		playsound = '0'

	} else {
		document.getElementById('auEmb').innerHTML = '<embed src="http://www.locationnow.com/location/alarm.wav" autostart="true" loop="false" width="10" height="15" hidden="true" />';
		document.getElementById('auTxt').innerHTML = 'Disable Audible Alarm';
		//alert('turnoffsound 0');
		playsound = '1'
	}

	//alert('playsound = ' + playsound);

	Set_Cookie('_attr',document.getElementById(DivID).style.left.replace('px','') + ',' + document.getElementById(DivID).style.top.replace('px','') + ',' + state + ',' + playsound, 50);

}


function ebi(a){
	return document.getElementById(a);
}

//By Qing Zhang 
/*By Qing Zhang */
	function ebiByName(a){
		return document.getElementsByName(a);
	}




// swap images using the cached images
function swap(x, y, parent) {
  if(document.all || document.getElementById) {
    if (document.images[x]) document.images[x].src=eval(y+'.src');
  } else if (document.layers) {
    if (parent) {
      if (eval('document.'+parent+'.document.images["'+x+'"]')) {
        eval('document.'+parent+'.document.images["'+x+'"].src = '+y+'.src')
      }
    } else if (eval('document.images["'+x+'"]')) {
      eval('document.images["'+x+'"].src = '+y+'.src')
    }
  }
}

//cache images for quick image swapping
function preload() {
  if (document.images) {
    for(var i = 0; i < preload.arguments.length; i += 2) {
      eval(preload.arguments[i]+'on = new Image()')
      eval(preload.arguments[i]+'on.src = "images/'+preload.arguments[i+1]+'_hover.gif"')
      eval(preload.arguments[i]+'off = new Image()')
      eval(preload.arguments[i]+'off.src = "images/'+preload.arguments[i+1]+'.gif"')
    }
  }
}


var doc = (document.layers) ? 'document.':'document.all.';
var sty = (document.layers) ? '' : '.style';
var ns = (document.layers)? true:false
var ie = (document.all)? true:false
var ns6 = (document.getElementById)? true:false

// Show/Hide functions for non-pointer layer/objects
function show(id) {
  if (ns) { if (document.layers[id]) document.layers[id].visibility = "show" }
  else if (ie) { if (document.all[id]) document.all[id].style.visibility = "visible" }
  else if (ns6) { if (document.getElementById(id)) document.getElementById(id).style.visibility="visible"; }
}

function hide(id) {
  if (ns) { if (document.layers[id]) document.layers[id].visibility = "hide" }
  else if (ie) { if (document.all[id]) document.all[id].style.visibility = "hidden" }
  else if (ns6) { if (document.getElementById(id)) document.getElementById(id).style.visibility="hidden"; }
}

function setTop(eleId, y) {
 if (document.all || document.layers || document.getElementById) {
  if (document.getElementById)
   document.getElementById(eleId).style.top = y;
  else
   eval(doc + eleId + sty + '.top = ' + y);
 }
}

function setLeft(eleId, x) {
 if (document.all || document.layers || document.getElementById) {
  if (document.getElementById)
   document.getElementById(eleId).style.left = x;
  else
   eval(doc + eleId + sty + '.left = ' + x);
 }
}

function move(eleId, x, y) {
  setTop(eleId, y);
  setLeft(eleId, x);
}

/********************** nav stuff below **********************/
navTimer = 0	// used by menu setTimeout() functions

function showNav (what) {
  show(what+'Div');
  swap(what, what+'on');
}

function hideNav (what) {
  exeHide = "hide('"+what+"Div'); swap('"+what+"','"+what+"off');";
  navTimer = setTimeout(exeHide ,1000000);
}

function hideAll (what) {
  //this for loop hides other navigation when a new menu is opened
  //it uses an array built when the navigation is created.
  for (i=0;i<navigation.length;i++) {
    hide('navArrowDiv');
    if (navigation[i] != what) {
      hide(navigation[i]+'Div');
      swap(navigation[i],navigation[i]+'off');
    }
  }
}

function navDisplay (what, showHide, x, y) {
  (showHide) ? swap(what, what+'on'):swap(what, what+'off');
  (showHide) ? show('nav_arrow_up'):hide('nav_arrow_up');
  (showHide) ? move('nav_arrow_up',x,y):'';
}

function leftnavDisplay (what, showHide) {
  (showHide) ? swap(what, what+'on'):swap(what, what+'off');
  (showHide) ? show('desc_'+what):hide('desc_'+what);
  hide('sbankingDiv');
  swap('sbanking','sbankingoff');
}

function makeLayer_bak (layer,name,x,y,zindex) {
	content = '';
	if (x>0 && y>0) {
		content += (document.layers) ? '<div name="'+name+'" left="'+x+'" top="'+y+'" z-index="'+zindex+'" position="absolute" visibility="hidden">\n':'<div id="'+name+'" style="position: absolute; left: '+x+'; top: '+y+'; z-index: '+zindex+'; visibility: hidden;">\n';
	} else {
		content += (document.layers) ? '<div name="'+name+'" z-index="'+zindex+'" position="relative" visibility="hidden">\n':'<div id="'+name+'" style="position: relative; z-index: '+zindex+'; visibility: hidden;">\n';
	}
	content += (layer);
//	content += (document.layers) ? '</div>\n':'</div>\n';
	return(content);
}

function popWindow (choice,myWidth,myHeight,myScrollbars,myTop,myLeft,myMenubar) {
  var ziWin = window.open (choice, "","width="+myWidth+",height="+myHeight+",scrollbars="+myScrollbars+",top="+myTop+",left="+myLeft+",menubar="+myMenubar+",bgcolor=#ffffff,resizable=yes");
  if (ziWin) ziWin.focus();	
}

function buildBreadcrumb (breadcrumbArray) {
	newBreadcrumb = '<span class="breadcrumb">';
	for (i=0; i<breadcrumbArray.length; i++) {
		// open link tag
		if (breadcrumbArray[i][0] != '') newBreadcrumb += '<a href="'+breadcrumbArray[i][0]+'" class="breadcrumb">';
		// add breadcrumb name
		newBreadcrumb += breadcrumbArray[i][1];
		// close link tag
		if (breadcrumbArray[i][0] != '') newBreadcrumb += '</a>';
		// add separator
		newBreadcrumb += '<img src="images/bread_crumb.gif" width="28" height="9" border="0">';
	}
	newBreadcrumb += '</span>';
	return newBreadcrumb;
}

function buildHeader (header) {
	newHeader = '<span class="headline">';
	// add breadcrumb name
	newHeader += header;
	newHeader += '</span>';
	return newHeader;
}


/********************************************************************
  this function sets a cookie value that will expire in two years
 ********************************************************************/
function setCookieValue(valueName, value) {
  var exp = new Date();
  var nowPlusOneWeek = exp.getTime() + (104*7*24*60*60*1000);
  exp.setTime(nowPlusOneWeek);
  //alert(valueName+"="+value+"; expires="+(exp.toGMTString())+"; domain="+domain);
  document.cookie = valueName+"="+value+"; expires="+exp.toGMTString();
  //return (document.cookie);
}

function stripSpaces(string) {
  return(string.replace(/^\W+/,'')).replace(/\W+$/,'');
}


/********************************************************************
  this function returns an array of the contents of the cookie
  indexed by the name of each value.  Reference the values in
  this manner: returnedArray["valueName"].
 ********************************************************************/
function makeCookieArray () {
  var cookieTable = new Array;
  var cookieString = document.cookie+"";
  var cookieArray = cookieString.split(";");
  for (i=0; i<cookieArray.length; i++) {
    cookieTable[stripSpaces(cookieArray[i].split("=")[0])] = cookieArray[i].split("=")[1];
    //alert(cookieTable["username"]);
  }
  return(cookieTable);
}

function submit (form) {
  formObj = eval('document.'+form)
  formObj.submit();
}

function makeHelpNavigation (nav_array) {
	var menu = '';

	menu += '	<tr>\n';
	menu += '		<td bgcolor="dff8fb"><table width="90%" border="0" align="right" cellpadding="3" cellspacing="1"> \n';

	for (i=0;i<nav_array.length;i++) {
		menu += '	<tr>\n';
		menu += '		<td class="link2">' + nav_array[i]+ '</td> \n';
		menu += '	</tr>\n';
	}
	menu += '	</table></td>\n';
	menu += '	</tr>\n';

	return menu;
}


function makeLayer (layer,name,x,y,zindex) {
	content = '<div id="'+name+'" style="position: absolute; left: '+x+'; top: '+y+'; z-index: '+zindex+'; visibility: visible;">\n';
	content += layer;
	content += '</div>\n';
	return content;
}

function makeNavigation (nav_array) {
	var menu = '';

	menu += '	<tr>\n';
	menu += '		<td><img src="' + nav_array[0]+ '" width="172" height="26" alt=""></td> \n';
	menu += '	</tr>\n';

	menu += '	<tr>\n';
	menu += '		<td background="images/menu_back.gif"><table width="90%" border="0" align="right" cellpadding="3" cellspacing="1"> \n';

	for (i=1;i<nav_array.length;i++) {
		menu += '	<tr>\n';
		menu += '		<td class="link2">' + nav_array[i]+ '</td> \n';
		menu += '	</tr>\n';
	}
	menu += '	</table></td>\n';
	menu += '	</tr>\n';

	return menu;
}


function makeNavigation_bak (nav_array,div_name) {
	menu = '';
	menu += '<table cellpadding="0" cellspacing="0" border="0">\n';
	menu += '	<!-- column definition -->\n';
	menu += '	<tr>\n';
	menu += '		<td width="142" colspan="3" class="navigation_category_matte"><img src="images/spc.gif" width="142" height="1" border="0"><br></td>\n';
	menu += '	</tr>\n';

	menu += '	<tr>\n';
	menu += '		<td width="2" class="navigation_category_matte" height="19" align="center" valign="center"><html:img bundle="adminimages" pageKey="icon.arrow.expanded"/><br></td>\n';
	menu += '		<td colspan="2" class="navigation_category_matte navigation_link  copy" align="left" valign="center">\n';
	menu += '			'+nav_array[0]+'\n';
	menu += '		</td>\n';
	menu += '	</tr>\n';
	menu += '	<!-- top orange line --><tr><td colspan="3" class="background_matte"><img src="images/spc.gif" width="142" height="2" border="0"</td></tr>\n';

	for (i=1;i<nav_array.length;i++) {
		menu += '	<tr >\n';
//		menu += '		<td colspan="2" class="white_matte"><img src="images/spc.gif" width="1" height="20" border="0"><br></td>\n';
		menu += '		<td colspan="3" align="center" width="142" class="white_matte  copy" height="20" >';
		menu += '			'+nav_array[i]+'\n';
		menu += '		</td>\n';
//		menu += '		<td colspan="2" class="white_matte"><img src="images/spc.gif" width="1" height="20" border="0"><br></td>\n';
		menu += '	</tr>\n';
	}
	menu += '	<!-- top orange line --><tr><td colspan="3" class="background_matte"><img src="images/spc.gif" width="142" height="2" border="0"</td></tr>\n';

	menu += '</table>\n';
	return menu;
}

function makeNav () {
	menu = '';
	menu += '<table cellpadding="0" cellspacing="0" border="0">\n';
	menu += '	<!-- column definition -->\n';
	menu += '	<tr>\n';
	menu += '		<td width="142" colspan="3" class="navigation_category_matte"><img src="images/spc.gif" width="142" height="10" border="0"><br></td>\n';
	menu += '	</tr>\n';



	menu += '	<tr><td colspan="3"  style="font: 10px Arial; font-weight:bold;color:#1B46AE;"  >SPONSORED BY:</td></tr>\n';
	menu += '	<!-- top orange line --><tr><td colspan="3" align="center" class="background_matte"><a href="javascript:void(0);" onClick="window.open(\'http://www.laipac.com/\', \'\', \'fullscreen=yes, scrollbars=auto\');"><img src="images/laipac.gif"  width="100" border="0" ></a></td></tr>\n';

	menu += '	<tr>\n';
	menu += '		<td width="142" colspan="3" class="navigation_category_matte"><img src="images/spc.gif" width="142" height="10" border="0"><br></td>\n';
	menu += '	</tr>\n';
	menu += '	<!-- top orange line --><tr><td colspan="3" align="center" class="background_matte"><a href="javascript:void(0);" onClick="window.open(\'http://www.laipac.com/\', \'\', \'fullscreen=yes, scrollbars=auto\');"><img src="images/laipac911.gif"  width="70" border="0" ></a></td></tr>\n';


	menu += '</table>\n';
	return menu;
}

	function Get_Cookie(name) { 
	   var start = document.cookie.indexOf(name+"="); 
	   var len = start+name.length+1; 
	   if ((!start) && (name != document.cookie.substring(0,name.length))) return null; 
	   if (start == -1) return null; 
	   var end = document.cookie.indexOf(";",len); 
	   if (end == -1) end = document.cookie.length; 
	   return unescape(document.cookie.substring(len,end)); 
	} 
	// This function has been slightly modified
	function Set_Cookie(name,value,expires,path,domain,secure) { 
		expires = expires * 60*60*24*1000;
		var today = new Date();
		var expires_date = new Date( today.getTime() + (expires) );
	    var cookieString = name + "=" +escape(value) + 
	       ( (expires) ? ";expires=" + expires_date.toGMTString() : "") + 
	       ( (path) ? ";path=" + path : "") + 
	       ( (domain) ? ";domain=" + domain : "") + 
	       ( (secure) ? ";secure" : ""); 
	    document.cookie = cookieString; 
	} 


function buildDimmerDiv()
{
    document.write('<div id="dimming" class="dimmer" style="width:'+ window.screen.width + 'px; height:' + window.screen.height +'px"></div>');
}


function displayWindow() 
{
	DivID = "dimming";

	//var left = screen.width/4;
	//var top = screen.height/4;


	document.getElementById(DivID).style.visibility = "visible";


/*	var cookiePos = Get_Cookie('_attr') + '';	
	var cookieValues = new Array();
	if(cookiePos.indexOf(',')>0){
		cookieValues = cookiePos.split(',');
		left = Math.max(0,cookieValues[0]);
		top = Math.max(0,cookieValues[1]);
		state = cookieValues[2];
		playsound = cookieValues[3];
	} */

	document.getElementById(DivID).style.left = left + 'px';
	document.getElementById(DivID).style.top = top + 'px';
	
	
	
	
	var addHeader;

	
	if(state == '1' ) {
         //  alert('Status=1');
		document.getElementById(DivID).style.width = '400px';
		document.getElementById(DivID).style.height = '400px';
          //  document.getElementById(DivID).style.overflow='auto';
 		addHeader = '<table style="width:100%; height:20px;" class="floatingHeader">' +
	            '<tr>' + 
			    '<td ondblclick="void(0);" onmouseover="over=true;" onmouseout="over=false;" style="cursor:move;height:18px" class="texthighlight5">Emergency Messages<DIV ID="auEmb">';

		if(playsound == '1') {
                //        alert('Sound=1');
				addHeader = '<embed src="http://www.locationnow.com/location/alarm.wav" autostart="true" loop="false" width="8" height="15" hidden="true" />' ;
                          }
	    addHeader +=  '</DIV></td><td style="width:10px"><input type="button" onClick="deleteAllemg()" value="Delete All"></td><td style="width:10px" align="right"><a href="javascript:minFloatingDiv(\'' + DivID + '\');void(0);">' + 
	            '<img alt="Minimize" title="Minimize" src="images/minior.gif" border="0"></a></td></tr></table>';

	//	document.getElementById(DivID).innerHTML = addHeader + originalDivHTML;
         
        
		minFloatingDiv(DivID); 
		
		document.getElementById("alertid").style.display="";
		   
		 

	} else {
		document.getElementById(DivID).style.width = '150px';
		document.getElementById(DivID).style.height = '25px';
		addHeader = '<table style="width:100%; height:20px;" class="floatingHeader">' +
	            '<tr>' + 
				'<td ondblclick="void(0);" onmouseover="over=true;" onmouseout="over=false;" style="cursor:move;height:18px">Messages &nbsp; <img src="images/alarm.gif" width="18" height="18" boder="0" /><DIV ID="auEmb" >';
		if(playsound == '1'){ 
                      //  alert('Status=0 Sound=1');
				addHeader += '<embed src="http://www.locationnow.com/location/alarm.wav" autostart="true" loop="false" width="10" height="15" hidden="true" />' ;
                        }


	    addHeader +=  '</DIV></td><td style="width:18px" align="right"><a href="javascript:fullFloatingDiv(\'' + DivID + '\');void(0);">' + 
	            '<img  title="Full Size" src="images/maximum.gif" border="0"></a></td></tr></table>';
		document.getElementById(DivID).innerHTML = addHeader;
           // alert(document.getElementById(DivID).innerHTML);
	}

	document.getElementById(DivID).className = 'dimming';
	document.getElementById(DivID).style.visibility = "visible";
        

	playsound = '0';

	//Set_Cookie('_attr',document.getElementById(DivID).style.left.replace('px','') + ',' + document.getElementById(DivID).style.top.replace('px','') + ',' + state + ',' + playsound, 50);

}

function minFloatingDiv(DivID) 
{
    document.getElementById(DivID).style.width = '150px';
    document.getElementById(DivID).style.height = '25px';
    document.getElementById(DivID).style.overflow='hidden';

	var addHeader = '<table style="width:100%; height:20px;" class="floatingHeader">' +
			'<tr>' + 
		    '<td ondblclick="void(0);" onmouseover="over=true;" onmouseout="over=false;" style="cursor:move;height:18px">MESSAGES &nbsp; <img src="images/alarm.gif" width="18" height="18" boder="0" /><DIV ID="auEmb" >';
	if(playsound == '1') 
			addHeader += '<embed src="http://www.locationnow.com/location/alarm.wav" autostart="true" loop="false" width="10" height="15" hidden="true" />' ;


	addHeader +=  '</DIV></td><td style="width:10px" align="right"><a href="javascript:fullFloatingDiv(\'' + DivID + '\');void(0);">' + 
			'<img  title="Full Size" src="images/maximum.gif" border="0"></a></td></tr></table>';

	document.getElementById(DivID).innerHTML = addHeader;
	state = '0';
//	Set_Cookie('_attr',document.getElementById(DivID).style.left.replace('px','') + ',' + document.getElementById(DivID).style.top.replace('px','') + ',' + state + ',' + playsound, 50);
}

function minFloatingDivNew(DivID) 
{
alert("new");
  //  document.getElementById(DivID).style.width = '40x';
   // document.getElementById(DivID).style.height = '30px';
  
document.getElementById(DivID).style.position="absolute";
document.getElementById(DivID).style.left=300;
document.getElementById(DivID).style.top=300;
    document.getElementById(DivID).style.overflow='hidden';

	var addHeader = '<table >' +
			'<tr>' + 
		    '<td ><a href="#"><img src="images/alert.gif" alt="alert" width="30" height="22">'+
			'</a></td></tr></table>';
	

	document.getElementById(DivID).innerHTML = addHeader;
	state = '0';
//	Set_Cookie('_attr',document.getElementById(DivID).style.left.replace('px','') + ',' + document.getElementById(DivID).style.top.replace('px','') + ',' + state + ',' + playsound, 50);
}



function fullFloatingDiv(DivID) 
{
    document.getElementById(DivID).style.width = '400px';
    document.getElementById(DivID).style.height = '400px';
    document.getElementById(DivID).style.overflow='auto';
	var addHeader = '<table style="width:100%; height:20px;" class="floatingHeader">' +
			'<tr>' + 
			'<td ondblclick="void(0);" onmouseover="over=true;" onmouseout="over=false;" style="cursor:move;height:18px" class="texthighlight5">Emergency Messages<DIV ID="auEmb" >'; 

	if(playsound == '1') 
			addHeader += '<embed src="http://www.locationnow.com/location/alarm.wav" autostart="true" loop="false" width="10" height="15" hidden="true" />' ;


	addHeader +=  '</DIV></td><td style="width:10px"><input type="button" onClick="deleteAllemg()" value="Delete All"></td><td style="width:18px" align="right"><a href="javascript:minFloatingDiv(\'' + DivID + '\');void(0);">' + 
			'<img alt="Minimize" title="Minimize" src="images/minior.gif" border="0"></a></td></tr></table>';




	document.getElementById(DivID).innerHTML = addHeader + originalDivHTML;
	state = '1';
//	Set_Cookie('_attr',document.getElementById(DivID).style.left.replace('px','') + ',' + document.getElementById(DivID).style.top.replace('px','') + ',' + state + ',' + playsound, 50);

}

function MouseDown(e) 
{
    if (over)
    {
        if (isMozilla) {
            objDiv = document.getElementById(DivID);
            X = e.layerX;
            Y = e.layerY;
            return false;
        }
        else {
            objDiv = document.getElementById(DivID);
            objDiv = objDiv.style;
            X = event.offsetX;
            Y = event.offsetY;
        }
    }
}


//
//
//
function MouseMove(e) 
{
    if (objDiv) {
        if (isMozilla) {
            objDiv.style.top = (e.pageY-Y) + 'px';
            objDiv.style.left = (e.pageX-X) + 'px';
            return false;
        }
        else 
        {
            objDiv.pixelLeft = event.clientX-X + document.body.scrollLeft;
            objDiv.pixelTop = event.clientY-Y + document.body.scrollTop;
			left = objDiv.pixelLeft;
			top = objDiv.pixelTop;

            return false;
        }
    }

//	Set_Cookie('_attr',document.getElementById(DivID).style.left.replace('px','') + ',' + document.getElementById(DivID).style.top.replace('px','') + ',' + state + ',' + playsound, 50);

}


function MouseUp() 
{
    objDiv = null;

}

function initEvent()
{
    // check browser
    isMozilla = (document.all) ? 0 : 1;


    if (isMozilla) 
    {
        document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
    }

	//ebi(DivID).style.visibility = "hidden";//By Qing 
	//ebi(DivID).style.zIndex = 1000;//By Qing 

    document.onmousedown = MouseDown;
    document.onmousemove = MouseMove;
    document.onmouseup = MouseUp;

	left = screen.width/4;
	top = 10;

	inite = true;


    // add the div
    // used to dim the page
//	buildDimmerDiv();

}

	function resizemap() {

	  var ww = getWindowWidth() - 225;  //var ww = getWindowWidth() - 180;        *********Modify by Tony
	  if(ww < 50) ww = 50;

	  var hh = getWindowHeight() ; // var hh = getWindowHeight()  - 260;	********** Modify by Tony
	  if(hh < 50) hh = 50;

	  ebi('map').style.width = ww;
	  ebi('map').style.height = hh;

	}

	function getWindowWidth() 
	{
		var windowWidth=0;
		
		if (typeof(window.innerWidth)=='number') //Non-IE
	   {
			windowWidth=window.innerWidth;
		} 
		else if (document.documentElement && document.documentElement.clientWidth) //IE 6+ in 'standards compliant mode'
		{
			windowWidth=document.documentElement.clientWidth;
	   } 
	   else if (document.body && document.body.clientWidth) //IE 4 compatible
	   {
		  windowWidth=document.body.clientWidth;
		}
		
		return windowWidth;
	}

	function getWindowHeight()
	{
		var windowHeight=0;
		
		if (typeof(window.innerHeight)=='number') //Non-IE
	   {
			windowHeight=window.innerHeight;
		} 
		else if (document.documentElement && document.documentElement.clientHeight) //IE 6+ in 'standards compliant mode'
		{
			windowHeight=document.documentElement.clientHeight;
	   } 
	   else if (document.body && document.body.clientHeight) //IE 4 compatible
	   {
		  windowHeight=document.body.clientHeight;
		}
		
		return windowHeight;
	}

//By Qing Zhang 
//Qing Zhang 
function getBrowserType()
{
var isOpera, isIE, isNav, isFox, isSafari,isOther = false;
var valueReturned;
if (navigator.userAgent.indexOf("Opera")!=-1) {
isOpera = true;
}
if (navigator.userAgent.indexOf("Safari")!=-1) {
isSafari = true;
} else if (navigator.userAgent.indexOf("Firefox")!=-1) {
 isFox = true;
} else if (navigator.appName == "Microsoft Internet Explorer") {
 isIE = true;
} else if (navigator.appName == "Netscape") {
 isNav = true;
} else {
 isOther = true;
}
       //alert('Ie:'+isIE);
       //alert('Fox:'+isFox);
       //alert('Nav:'+isNav);
       //alert('Safari:'+isSafari);
       //alert('Opera:'+isOpera);
      //alert('other:'+isOther);

	if (isIE||isFox||isNav)
	{
         valueReturned="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6";
        // alert(valueReturned);
         return valueReturned; 
    }
      if (isSafari||isOpera)
      {
         valueReturned="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6";
          //alert(valueReturned);
          return valueReturned; 
      }
}
//Add by Tony
function deleteAllemg() {
var answer = confirm ('Remove All Record ?' );
if(answer) {

handledall();

}


}
function handledall()   //unitid is emgeventId
{
	
		if( !http_status_request) 
			return;
		var url = baseurl + "command=emgdelall&userId=" + ebiByName('userId')[0].value;		
		http_status_request.open("GET", url, true);
		http_status_request.onreadystatechange = handledEmgallResponse;
		http_status_request.send(null);
	
}
function handledEmgallResponse() {
	  if (http_status_request.readyState == 4  && http_status_request.status == 200) {
			  var txt = http_status_request.responseText;
			 // alert("respose=="+txt);
			  if(trim(txt) == "1") {
				  if(otimerid != null)
					  clearTimeout(otimerid);
					  
				  showStatus();
			  }
	  }
}
//Add  by Tony Jiang on Nov.30,2009
function showEmg() {
//alert("show=="+originalDivHTML);

//document.getElementById(DivID).style.z-index = 10;
document.getElementById(DivID).style.position="absolute";
document.getElementById(DivID).style.left=310;
document.getElementById(DivID).style.top=5;
document.getElementById(DivID).style.width = '500px';
document.getElementById(DivID).style.height = '400px';
var addcontent;
	addcontent='<table width="100%" border="0" cellspacing="0" cellpadding="0" style="background-color: #FFFFFF;">'+								
				'<table width="100%" border="0" cellspacing="0" cellpadding="0" style="background-color:#a60606;">'+
				' <tr>'+				
				'<td width="95%" ondblclick="void(0);" onmouseover="over=true;" onmouseout="over=false;" style="cursor:move;height:18px" width="10%" class="text_bold_big"><img src="images/alert.gif" alt="alert" width="30" height="22" align="absmiddle">'+
				'&nbsp;&nbsp;Emergency Messages&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+
				'<img src="images/drag.gif" width="19" height="19" align="absmiddle">&nbsp;&nbsp;<em class="text_highlight">(Click &amp; Drag)</em>&nbsp;'+
				'</td>'+
				'<td width="5%"><a href="javascript:minEmgwindow()"><img src="images/minimum.png" alt="minimum" width="18" height="18" border="0"></a></td>'+				
				'</tr>'+
				'</table>'+											
				originalDivHTML+				
				'</table>';
	
//alert("show=="+addcontent);		
document.getElementById("alertid").style.display="none";
document.getElementById(DivID).style.visibility = "visible";
document.getElementById(DivID).innerHTML = addcontent;		
	state='0';
				


}

function displayAlertWindow() {
if(state == '1' ) {
// alert("state=="+state);
 document.getElementById("alertid").style.display="";
 document.getElementById(DivID).style.visibility = "hidden"; 
 
 
} else {

showEmg();
//document.getElementById("alertid").style.display="none";
//document.getElementById(DivID).style.visibility = "visible";
}

}

function minEmgwindow() {
 document.getElementById("alertid").style.display="";
 document.getElementById(DivID).style.visibility = "hidden"; 
 state='1';
}

//This is for new map display    --------Add by tony jiang May.06,2010
function mappageload(){ 
drag(document.getElementById('drag')); 
drag(document.getElementById('drag2')); 
drag(document.getElementById('drag3')); 
drag(document.getElementById('drag4')); 
drag(document.getElementById('drag5')); 
drag(document.getElementById('drag6')); 
drag(document.getElementById('drag7')); 
drag(document.getElementById('drag8')); 
drag(document.getElementById('drag9')); 
drag(document.getElementById('drag10')); 
drag(document.getElementById('drag11')); 
drag(document.getElementById('drag12')); 
}; 
function drag(o,r){ 
o.p_p_c_gw=function(index){ 
if(window.ActiveXObject){ 
return o.parentNode.parentNode.cells[o.parentNode.cellIndex+index].offsetWidth; 
}else{ 
return parseInt(o.parentNode.parentNode.cells[o.parentNode.cellIndex+index].offsetWidth)- 
parseInt(o.parentNode.parentNode.parentNode.parentNode.cellPadding)*2-2; 
} 
}

o.p_p_p_sw=function(index,w){ 
for(var i=0;i<o.parentNode.parentNode.parentNode.parentNode.rows.length;i++) { 
o.parentNode.parentNode.parentNode.parentNode.rows[i].cells[index].style.width=w; 
} 
}

//var out=document.getElementById('my');

o.firstChild.onmousedown=function(){return false;}; 
o.onmousedown=function(a){ 
var d=document;if(!a)a=window.event; 
var lastX=a.clientX; 
var watch_dog=o.p_p_c_gw(0)+o.p_p_c_gw(1);
if(o.setCapture) 
o.setCapture(); 
else if(window.captureEvents) 
window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP); 
// 
d.onmousemove=function(a){ 
if(!a)a=window.event; 
if(o.p_p_c_gw(0)+o.p_p_c_gw(1)>watch_dog){ 
o.p_p_p_sw(o.parentNode.cellIndex+1,watch_dog-o.p_p_c_gw(0)); 
return; 
} 
var t=a.clientX-lastX;
//out.innerHTML=t; 
if(t>0) {//right 
if(parseInt(o.parentNode.parentNode.cells[o.parentNode.cellIndex+1].style.width)-t<10) 
return; 
o.p_p_p_sw(o.parentNode.cellIndex,o.p_p_c_gw(0)+t); 
o.p_p_p_sw(o.parentNode.cellIndex+1,o.p_p_c_gw(1)-t); 
} else {//left 
if(parseInt(o.parentNode.parentNode.cells[o.parentNode.cellIndex].style.width)+t<10) 
return; 
o.p_p_p_sw(o.parentNode.cellIndex,o.p_p_c_gw(0)+t); 
o.p_p_p_sw(o.parentNode.cellIndex+1,o.p_p_c_gw(1)-t); 
} 
lastX=a.clientX; 
}; 
d.onmouseup=function(){ 
if(o.releaseCapture) 
o.releaseCapture(); 
else if(window.captureEvents) 
window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP); 
d.onmousemove=null; 
d.onmouseup=null; 
}; 
}; 
} 