﻿var gridSelected = -1; var oldBG; var tbSearch; var lastPressed = '';
var rgRows = new Array(); var rgIDs = new Array(); var stackKeyHandlers = new Array(); var lastKeyHandler = '';
var rgToUpdate = new Array();
var rgUpdateWith = new Array();

function DoUpdateStuff()
{
   var i;
   for (i = 0; i < rgToUpdate.length; i++)
   {
      var o = document.getElementById(rgToUpdate[i]);
      if (o != null)
      {
         var s1 = rgUpdateWith[i];
         if (typeof s1 == 'string')
         {            
            var o2 = document.getElementById(s1);
            if (o2 != null)
            {
               o.innerHTML = o2.value;
            }
            else
            {
               o.innerHTML = s1;
            }
         }
         else if (typeof s1 == 'function')
         {
            o.innerHTML = s1(o);
         }               
      }
   }
   
   window.setTimeout("DoUpdateStuff();", 1000);
}

function GetCurrentFocusElementID()
{
   var hfFoc = document.getElementById('ctl00_fe');
   if (hfFoc == null || hfFoc.value == '') return '';
   var hfVal = hfFoc.value; return hfVal;   
}

function HiL(o1, s1)
{
   if (s1 == 1) { o1.style.backgroundColor='#FFCCCC'; }
   if (s1 == 0) { o1.style.backgroundColor='Transparent'; }
}

function ToggleDisplay(s1, s2)
{
   var o1 = document.getElementById(s1);
   if (o1 != null)
   {
      if (typeof(s2) != "undefined")
      {
         if (s2) { o1.style.display = 'block'; } else { o1.style.display = 'none'; }
      }
      else
      {
         if (o1.style.display == null)
         {
            o1.style.display = 'block';
         }
         else if (o1.style.display == 'block')
         {
            o1.style.display = 'none';
         }
         else
         {
            o1.style.display = 'block';
         }
      }
   }
}

function BGC(o1, s1)
{
   o1.style.backgroundColor=s1;
}

function NAV(s1)
{
   try
   {
      window.navigate(s1);
   } 
   catch (ex)
   {
      window.location.href=s1;
   }
}

function MyTimer(s1, s2, n1)
{
   window[s1](s2);    
   window.setTimeout("MyTimer('" + s1 + "','" + s2 + "'," + n1.toString() + ");", n1);
}

function SCFID(s1)
{
   TryF(s1);
   var hfFoc = document.getElementById('ctl00_fe');
   if (hfFoc == null) return false;
   hfFoc.value = s1;
}

function GetCurrentFocusElement()
{
   var hfVal = GetCurrentFocusElementID();
   if (hfVal != '') return document.getElementById(hfVal);
   return null;   
}

function SetShowAllFieldNames(sSet)
{
   var hfShowAll = document.getElementById('ctl00_sfn');
   if (hfShowAll == null) return false;
   hfShowAll.value = sSet;
   return true;
}

function GetShowingAllFieldNames(sSet)
{
   var hfShowAll = document.getElementById('ctl00_sfn');
   if (hfShowAll == null) return false;
   return (hfShowAll.value == '') ? false : true;
}

function EnsureFocus()
{
   var v = GetCurrentFocusElementID();
   if (v == '') { return false; }
   window.setTimeout("FcSel('" + v + "');", 25);
   window.setTimeout("try {document.getElementById('" + v + "').focus();} catch (ex) {}", 30);
}

function HL(v)
{
   v.style.backgroundColor='#FFCCCC';
}

function NHL(v)
{
   v.style.backgroundColor='Transparent';
}

function PersDelQ()
{
   return confirm('Deleting a person also deletes ALL contact records, group membership, and all other data using this record.  It is not recommended.  Proceed?');
}

function FPB(s1,s2)
{
	var HiddenBox = document.getElementById(s1);
	if (typeof(s2)=="undefined") { s2 = "RANDOMPARAM" + Math.random(); };
	if (HiddenBox.value == s2) { s2 = s2 + "RANDOMPARAM" + Math.random(); };
	HiddenBox.value = s2;
	var MyCommand = String(HiddenBox.onchange).replace('function anonymous()\n{\n','');	
	MyCommand = MyCommand.replace('\n}','');
	MyCommand = MyCommand.replace('function onchange(event) {\njavascript:\n','');
	eval(MyCommand);
}

function DoEscapePressedCommand(v1)
{
   var hfEsc = document.getElementById('ctl00_esc');
   if (hfEsc == null || hfEsc.value == '') return false;
   var hfVal = hfEsc.value; var ty = typeof hfVal;   
   if (ty == 'string') { return window[hfVal](v1);  } else  { return hfVal(v1);  }   
}

function DoEnterPressedCommand(v1)
{
   var hfEsc = document.getElementById('ctl00_ent');
   if (hfEsc == null || hfEsc.value == '') return false;
   var hfVal = hfEsc.value; var ty = typeof hfVal;   
   if (ty == 'string') { return window[hfVal](v1);  } else  { return hfVal(v1);  }   
}

function GetKeyStokeHistory()
{
   return document.getElementById('ctl00_ks');
}

function AppendKeystrokeHistory(chCode)
{
   var k = GetKeyStokeHistory();
   if (k != null) 
   { 
      if (k.value.length > 30) { k.value = ''; }
      k.value = k.value.concat(chCode.toString().concat('|'));
   }
}

function MainKeyHandler(e)
{
   var evt = IE ? event : e;
   AppendKeystrokeHistory(evt.keyCode);
   var hf = document.getElementById('ctl00_cch');
   if (hf == null || hf.value == '') return ListPageKeyDownHandler(e);
   var hfVal = hf.value; var ty = typeof hfVal;   
   if (ty == 'string')
   {
      if (hfVal == '' && stackKeyHandlers.length > 0) 
      {
         hf.value = stackKeyHandlers.pop();
         hfVal = hf.value;
         lastKeyHandler = hfVal;
      }
      else if (lastKeyHandler != hfVal)
      {
         stackKeyHandlers.push(lastKeyHandler);
         lastKeyHandler = hfVal;
      }
      return window[hfVal](e); 
   } else  { return hfVal(e);  }   
}

function SetLFAndGo(sID)
{
   try { SetLF(sID); } catch (ex) { }
   window.setTimeout("FcSel('" + sID + "');", 110);
}

function KeyDigit() { return (event.keyCode >= 48 && event.keyCode <= 57); }
function KeyArrows() { return (event.keyCode >= 37 && event.keyCode <= 40); }
function KeyBS() { return (event.keyCode == 8); } 
function KeyEnter() { return (event.keyCode == 13); }
function KeyDelete() { return (event.keyCode == 46); } 
function FcSel(s1) { 
   var o1 = document.getElementById(s1); 
   if (o1 != null) { try { o1.focus(); o1.select(); SetLF(s1); } catch(e) { } } 
   else 
   {
      window.setTimeout("FcSel('" + s1 + "')", 100);
   }
}
function textboxSelect(oTextbox, iStart, iEnd) 
{ 
   var isOpera = navigator.userAgent.indexOf("Opera") > -1;  var isIE = navigator.userAgent.indexOf("MSIE") > 1 && !isOpera;  var isMoz = navigator.userAgent.indexOf("Mozilla/5.") == 0 && !isOpera;
   switch(arguments.length)  {   case 1:  oTextbox.select();  break;  case 2:  iEnd = oTextbox.value.length;  case 3: if (isIE)  {  var oRange = oTextbox.createTextRange();  oRange.moveStart("character", iStart);  oRange.moveEnd("character", -oTextbox.value.length + iEnd);  oRange.select(); }  else if (isMoz) {  oTextbox.setSelectionRange(iStart, iEnd);  } } 
}
function TryF(vID) { var v = document.getElementById('__LASTFOCUS'); if (v != null) { v.value = vID; } }
function FcSelEnd(s1)  {  var o1 = document.getElementById(s1); if (o1 != null) { try { o1.focus(); var st = o1.value; textboxSelect(o1, st.length); SetLF(s1); } catch (e2) { } } }
function SetLF(s2) { try { document.getElementById('__LASTFOCUS').value = s2; } catch (ex) { alert(ex); } }
function KeyChk(n1, n2, s1, s2) 
{ 
   var k = event.keyCode; 
   if (n1 == 1 && k>=48 && k<=57) { return false; } 
   if (n2 == 1 && k>=37 && k<=40) { return false; } 
   if (s1 != '' && k==38) { FcSel(s1); return false; } 
   if (s2 != '' && k==40) { FcSel(s2); return false; } 
   return true; 
}
function FcS(s1) { var o1 = document.getElementById(s1); if (o1 != null) { try { o1.focus(); SetLF(s1); } catch (e2) { } } }
function getMouseXY(s1, s2)  { try { document.getElementById(s1).value=window.event.clientX; document.getElementById(s2).value=window.event.clientY; } catch (ex) { } return true; }
function NoKeyDownHandler(e) { return true; }
function ManualKeyHandler(e) { 
   var evt = IE ? event : e;    
   return true; 
}

function ListPageKeyDownHandler(e)
{   
   var evt = IE ? event : e; var iNext = 0;
   if (evt.keyCode==27)
   {    
      if (gridSelected >= 0) { DeSelectRow(); }
      else { window.setTimeout("DoEscapePressedCommand('e')", 1);  }   
      evt.returnValue=false;  evt.cancelBubble=true;  return false;          
   }
   else if (evt.keyCode == 38)
   {
      lastPressed = 'u';
      if (gridSelected > 0) { iNext = gridSelected - 1; DeSelectRow(); SelectGridRow(iNext); } else if (gridSelected == 0) { DeSelectRow(); }
      evt.returnValue = false;  evt.cancelBubble = true;  return false;
   } 
   else if (evt.keyCode == 40)
   { 
      lastPressed = 'd';
      if (gridSelected + 1 < rgRows.length) { iNext = gridSelected + 1; DeSelectRow(); SelectGridRow(iNext); }
      evt.returnValue = false; evt.cancelBubble=true; return false; 
   }
   else if (evt.keyCode == 13)
   { 
      if (gridSelected >= 0 && lastPressed != '') 
      {      
         window.setTimeout("DoEnterPressedCommand('' + gridSelected + ',' + rgIDs[gridSelected])", 1); 
         evt.returnValue = false;  evt.cancelBubble=true;  return false; 
      }
      else { DeSelectRow(); }
   }
   else if (tbSearch != null)  { lastPressed = ''; var tb = document.getElementById(tbSearch); tb.focus();  return true; }
   return true;
}

function DeSelectRow()
{
   if (gridSelected < 0) return;  if (gridSelected >= rgRows.length) return;
   var bg = document.getElementById(rgRows[gridSelected]); if (bg != null) { bg.style.backgroundColor = oldBG; }
   gridSelected = -1;
}

function SelectGridRow(oI)
{   
   if (gridSelected == oI) { DeSelectRow(); return; }
   gridSelected = oI; if (gridSelected >= rgRows.length) { gridSelected = rgRows.length - 1; return; }
   var s = rgRows[gridSelected]; var bg = document.getElementById(s); 
   if (bg != null)  {  bg.focus(); oldBG = bg.style.backgroundColor;  bg.style.backgroundColor = '#DDDDDD'; }   
}

function SetTimeoutForAC(oClientCmd, oTextB)
{
   var sStr = '' + oClientCmd + '(document.getElementById(\'' + oTextB + '\').value);';
   var vFN = window[oClientCmd];
   window.clearTimeout(toutID);     
   toutID = window.setTimeout("CallerIt('" + oClientCmd + "','" + oTextB + "')", 500);
}

function CallerIt(oClientCmd, oTextB)
{
   try
   {
      window[oClientCmd](document.getElementById(oTextB).value);
      window.setTimeout("FcSelEnd('" + oTextB + "');", 200);
   }
   catch (ex) { }
}

function SubmitSpecialKey(oClientCmd, sArg)
{
   var sStr = '' + oClientCmd + '(\'' + sArg + '\');';
   var vFN = window[oClientCmd];
   window.clearTimeout(toutID);     
   toutID = window.setTimeout("CallerIt2('" + oClientCmd + "','" + sArg + "')", 5);
}

function CallerIt2(oClientCmd, sArg)
{
   window[oClientCmd](sArg);
}

function FlashIsInstalled()
{
   if (navigator.plugins && navigator.plugins.length) { x = navigator.plugins["Shockwave Flash"]; return (x) ? 1 : 0; }
   else if (navigator.mimeTypes && navigator.mimeTypes.length) { x = navigator.mimeTypes['application/x-shockwave-flash']; return (x && x.enabledPlugin) ? 1 : 0; }
}

function ToggleID(uniqueID, hiddenFieldID)
{
   var selIDs = new Array();  
   var o = document.getElementById(hiddenFieldID);   
   selIDs = o.value.split(' ');      
   var s = '';
   var added = 1;
   for (i = 0; i < selIDs.length; i++)
   {
      if (selIDs[i]==uniqueID) {added = 0;}
      else {s = s + " " + selIDs[i];}
   }
   if (added==1) {s = s + " " + uniqueID;}
   o.value = s;
}

function AddUpdate(s1, s2)
{
   rgToUpdate.push(s1);
   rgUpdateWith.push(s2);
}

DoUpdateStuff();
AddUpdate('track1', 'ctl00_hX');
AddUpdate('track2', 'ctl00_hY'); 
AddUpdate('track3', 'ctl00_hM'); 
AddUpdate('track4', 'ctl00_ks'); 
AddUpdate('track5', 'ctl00_cch'); 
AddUpdate('track6', 'ctl00_ent'); 
AddUpdate('track7', 'ctl00_esc'); 
/*	   
if (x) { if (x.description) { y = x.description; flashversion = y.charAt(y.indexOf('.')-1); } }
else { return 0; }
if (navigator.plugins["Shockwave Flash 2.0"]) { return 1; }
*/

/*
function ClearFunctionArray()
{
   rgRet = new Array();
}
var sss = '';
function GetAllFunctionsWithPrefix(nStartNode, sPrefix)
{
   var sLookingFor = 'function '+sPrefix;
   for (var i = 0; i < window.document.all.length; i++)
   {
     var v = window.document.all[i];
     if (!v.text) continue;
     var sTxt = '' + v.text;
     var idx = sTxt.indexOf(sLookingFor);
     if (idx >= 0 && idx < 20)
     {
       var iEnd = sTxt.indexOf('(');
       var sS = sTxt.substring(idx+9, iEnd);
       rgRet.push(sS);
     }
   }
}

function ExecuteAllFunctions(vParam)
{
   var i;
   for (i = 0; i < rgRet.length; i++)
   {
      window[rgRet[i]]('' + vParam);
   }
}

function ExecuteAllEscapePressed(vPar)
{
   ClearFunctionArray();
   GetAllFunctionsWithPrefix(null, 'EscapePressed');
   ExecuteAllFunctions(vPar);
}

function ExecuteAllEnterPressed(vPar)
{
   ClearFunctionArray();
   GetAllFunctionsWithPrefix(null, 'EnterPressed');
   ExecuteAllFunctions(vPar);
}
*/