
//Set Defaults
pgStart='/monitor/mnstart.asp'
pgBegin='/monitor/mnscript.asp'
pgPause='/monitor/mnpause.asp'
pgFrame='/monitor/mnframe.asp'

//Do Browser Detection------------------------------------------------------------------
iAppType=0; IsIE=false; IsN4=false; IsN6=false; IsMac=false

iAppVs=(navigator.appVersion.indexOf('MSIE')>0)?navigator.appVersion.indexOf('MSIE')+5:0
iAppVs=parseFloat(navigator.appVersion.substr(iAppVs,3))
sAppAgent=navigator.userAgent.toLowerCase()

if (document.all){iAppType=1; IsIE=true}					//ie
else if (document.layers){iAppType=2; IsN4=true}			//nn4
else if (document.getElementById){iAppType=3; IsN6=true}	//nn6,mozilla
IsMac=(sAppAgent.indexOf('mac')!=-1)						//mac
//alert(' iAppType: '+iAppType +'\n iAppVs: '+iAppVs +'\n sAppAgent: '+sAppAgent)
//--------------------------------------------------------------------------------------


function IsEnterKey(e) {//keycode: 13=Enter
	kcode=IsIE?event.keyCode:(IsN4||IsN6)?e.which:0; return (kcode==13)
 }

function rtrim(str) { while(str.substr(str.length-1)==' '){str=str.substring(0,str.length-1)};return str }
function ltrim(str) { while(str.substr(0,1)==' '){str=str.substring(1,str.length)};return str }
function trim(str)  { return ltrim(rtrim(str)) }


function goMonitor(mnId)
	{
	wnm='mon'+mnId
	url='/monitor/mnframe.asp?mnId=' + mnId
	monwin=window.open(url,wnm,"resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,width=470,height=260,top=50,left=150")
	monwin.focus()
	}


function beginMon()
	{
	bMonStarted=1
	bb=document.all.btnBegin; bp=document.all.btnPause
	bb.disabled=true	; bb.style.backgroundColor='#bdbdbd'
	bp.disabled=false	; bp.style.backgroundColor='#f9eaec'
	
	monAction(pgBegin)
	
	iCD=window.setInterval('countDown()',1*1000) //1sec
	}
	
	
function pauseMon()
	{
	bMonStarted=0
	try{window.clearInterval(iCD)} catch(exception){}
	
	if( (d=window.parent.frames('NavMonStart').document) && (bb=d.all.btnBegin) && (bp=d.all.btnPause) && (iN=d.getElementById('iNext')) && (sN=d.getElementById('sNext')) )
		{
			bb.disabled=false	; bb.style.backgroundColor='#daf9eb'
			bp.disabled=true	; bp.style.backgroundColor='#bdbdbd'
			
			iN.value='0'
			sN.value='0 secs'
		}
		
	if(d=window.parent.frames('NavMonScript').document)
		{
		dl=d.location.pathname.toLowerCase()
		if(dl!=pgPause) {monAction(pgPause)}
		}
	}


function reloadMon()
	{
	pauseMon()
	fm=document.forms.fEMon
	fm.target='NavMonStart'
	fm.action=pgStart
	fm.submit()
	}


function exitMon()
	{
	wrn='End monitoring for this event ??'
	if (confirm(wrn)) { window.close() }
	}


function monAction(url)
	{
	iIntv=document.getElementById('iIntv')
	iESnRpt=document.getElementById('iESnRpt')
	iESIntv=document.getElementById('iESIntv')
	
	t=parseInt(iIntv.value)
	r=parseInt(iESnRpt.value)
	v=parseInt(iESIntv.value)
	
	if(t.toString()=='NaN'){t=10} else{if(t<1||t>99){t=10}}
	if(r.toString()=='NaN'){r=10} else{if(r<0||r>99){r=10}}
	if(v.toString()=='NaN'){v=20} else{if(v<1||v>99){v=20}}
	
	iIntv.value=t
	iESnRpt.value=r
	iESIntv.value=v
	
	fm=document.forms.fEMon
	fm.action=url
	fm.submit()
	}
	
	
function monStatsReport(iCnt,iNext,iFnd)
	{
	if ( d=window.parent.frames('NavMonStart').document )
	{
		d.getElementById('iCnt').value=iCnt
		d.getElementById('sCnt').value=iCnt+' times'
		if(iFnd >= 0) {d.getElementById('sFnd').value=iFnd+' times'}
					
		d.getElementById('sLast').value=formatDate('',7)
					
		d.getElementById('iNext').value=iNext
		d.getElementById('sNext').value=iNext+' secs'
	}
	}
	
	
function foundFlasher()
	{
	if ( d=window.parent.frames('NavMonStart').document )
		{
		f=d.getElementById('idFnd')
		f.style.color='blue'
		}
	}
	

function countDown()
	{
	if ( d=window.parent.frames('NavMonStart').document )
	{
		e1=d.getElementById('iNext')
		e2=d.getElementById('sNext')
		v=parseInt(e1.value)
		if(v.toString()=='NaN'){v=1}
		e1.value=v-1
		if(v>0||v<-60){e2.value=v-1+' secs'}
		if(v<(-2*60)){e1.value='10'; pauseMon(); beginMon()} //raise the dead !
	}
	}


function winTickets(url,tgt)
	{
	mywin=window.open(url,tgt)
	mywin.focus()
	}
	
	
	
function delRecord(recId,recInp)
	{
	wrn='permanently delete record ' +recId +' ??'
	
	if ( confirm(wrn) )
		{
		fm=document.getElementById('fSubmit')
		fm.intention.value='Delete'
		fm(recInp).value=recId
		fm.submit()
		}
	}
	
	
	
function resetRecord(recId,recInp)
	{
	fm=document.getElementById('fSubmit')
	fm.intention.value='Reset'
	fm(recInp).value=recId
	fm.submit()
	}
	

function showStalker()
	{
	idChk=document.getElementById('iEvStlkr')
	idOpt=document.getElementById('idESOptns')
	idRpt=document.getElementById('iESnRpt')
	idItv=document.getElementById('iESIntv')
	if(idChk.checked)
		{
		//idOpt.style.display=''
		idRpt.disabled=false
		idItv.disabled=false
		idRpt.style.backgroundColor=''
		idItv.style.backgroundColor=''
		}
	else
		{
		//idOpt.style.display='none'
		idRpt.disabled=true
		idItv.disabled=true
		idRpt.style.backgroundColor='#bdbdbd'
		idItv.style.backgroundColor='#bdbdbd'
		}
	}
	
	
function showTime(idTimeBox)
	{
	if( tmbox=document.getElementById(idTimeBox) )
		{ window.setInterval(putTime,1*1000) }
	}	
function putTime(){tmbox.innerText=' ' +formatDate('',9) +' '}



function visibility(oId,bActn)
	{	//oID: objectID		bActn: 0=hide 1=show
	var c,o,h,s; c=IsN4?'visibility':'style.display'; h=IsN4?'hide':'none'; s=IsN4?'show':'block'
	if(o=document.getElementById(oId)){eval('o.'+c+'=(bActn==0)?h:s')}
	}


function doSort(sortMaxNum) {
	var i,v,fm,fe,fl,sOrd,bWrn,sWrn
	fm=document.forms.fSubmit; fm.action=''
	fe=fm.elements; fl=fe.length
	sOrd=''; bWrn=0; sWrn='Order must be number between 0 and '+sortMaxNum+' !'
	for (i=0;i<fl;i++) { e=fe[i]
		switch (e.name) {
			case 'ListAbsolutePage': if(p=document.forms.fPgMove.jumpToPg){e.value=p.value}; break
			case 'sortOrder': v=parseInt(e.value)
				if(v.toString()=='NaN'||v.toString()!=e.value.toString()){v=0;bWrn=1} else{if(v<0||v>sortMaxNum){v=0;bWrn=1}}
				if(bWrn==1){e.focus();e.style.backgroundColor='red';alert(sWrn);e.style.backgroundColor='';e.value='';return false} else{if(sOrd==''){sOrd=v.toString()} else{sOrd+=','+v} }
			}
		}
	fm.action1x.value='sort'; fm.submit(); return false
	}


function changePgList(itn,e) {
	if(IsEnterKey(e)) return eval(itn)
	if(typeof(iReady)!='undefined'&&iReady==1) window.clearInterval(iCD)
	iReady=1; iCD=window.setInterval(itn+'()',1*500) //1sec=1*1000
	}
			  
function pgRange() {
	if(typeof(iReady)!='undefined'&&iReady==1) window.clearInterval(iCD); iReady=0
	fm=document.forms.fPgMove; j=trim(fm.stdListRange.value); p=stdListRange
	if(dirty||fm.Pagesize.disabled)j=p; if(j==''||j==p){fm.stdListRange.value=p;return false}
	fm.submit(); return false
	}

function getPgJump() {
	if(IsEnterKey()) return pgJump()
	if(typeof(iReady)!='undefined'&&iReady==1) window.clearInterval(iCD)
	iReady=1; iCD=window.setInterval('pgJump()',1*500) //1sec=1*1000
	}
	
function pgJump() {
	if(typeof(iReady)!='undefined'&&iReady==1) window.clearInterval(iCD); iReady=0
	fm=document.forms.fPgMove; j=trim(fm.jumpToPg.value); p=trim(fm.ListAbsolutePage.value)
	if(dirty)j=p; if(j==''||j==p){fm.jumpToPg.value=p;return false}
	fm.ListAbsolutePage.value=fm.jumpToPg.value; fm.sortCat.value=''; fm.sortField.value=''
	fm.submit(); return false
	}
	
function pgMove(mv) {
	if(dirty)return false
	fm=document.forms.fPgMove
	if( (mv=='p'||mv=='pp')&&(ListAbsolutePage==1) || (mv=='n'||mv=='nn')&&(ListAbsolutePage==PageCount) ) return false
	fm.jumpToPg.value=''; fm.sortCat.value=''; fm.sortField.value=''; fm.list_PagingMove.value=mv
	fm.submit(); return false
	}
	
function pgSort(scat,sfld) {
	if(fm=document.forms.fPgMove){} else{return false}
	fm.sortCat.value=scat; fm.sortField.value=sfld
	fm.submit(); return false
	}
	

function formatDate(sDate,iFormat)
	{/*
	Return Formats:
		case 1: Thu: Jan 12, 2001. 9.12pm
		case 2:	
		case 3: 
	*/
		
	sRes=''
	month=new Array('January','February','March','April','May','June','July','August','September','October','November','December')
	day=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')
	dt=new Date()	//Date(sDate)
		
	df=day[dt.getDay()]
	mf=month[dt.getMonth()]
		
	da=df.substring(0,3)
	mo=mf.substring(0,3)
	dy=dt.getDate().toString()
	yr=dt.getYear()
	hr=dt.getHours()
	mn=dt.getMinutes().toString()
	se=dt.getSeconds().toString()
	
	if(hr>11){pa='pm'; if(hr>12){hr-=12}} else{pa='am'; if(hr==0){hr=12}}		
	if(yr<1000){yr+=1900}
	if(dy.length==1){dy='0'+dy}
	if(mn.length==1){mn='0'+mn}
	if(se.length==1){se='0'+se}
		
	switch (iFormat)
		{
		case 1: sRes=da+': '+mo+' '+dy+', '+yr+'. '+hr+':'+mn+''+pa; break
		case 2: sRes=mo+' '+dy+', '+yr; break
		case 3: sRes=da+': '+mo+' '+dy+', '+yr; break
		case 4: sRes=mof+' '+dy+', '+yr; break
		case 5: sRes=hr+':'+mn+''+pa; break
		case 6: sRes=mo+' '+dy+'. '+hr+':'+mn+''+pa; break
		case 7: sRes=da+'. '+hr+':'+mn+''+pa; break
		case 8: sRes=da+'. '+hr+':'+mn+':'+se+' '+pa; break
		case 9: sRes=hr+':'+mn+':'+se+' '+pa; break
		case 10: sRes=df+': '+mf+' '+dy+', '+yr+'. '+hr+':'+mn+''+pa; break
		default: sRes=da+': '+mo+' '+dy+', '+yr+'. '+hr+':'+mn+''+pa; break
		}
	return sRes
	}
	

function errorHandler() {return true}


