var genericWindow;
var m_sFormMain = "formMain";

function genericWindowIsOpen( nextElem )
{
   if ( genericWindow == null )
   {
      tabOffField( nextElem ); 
   }
}

//
// tabOffField - Allows automatic tabbing to the specified field
// I guess people are really lazy these days...
//
function tabOffField( nextElem )
{
   nextElem.focus();
}

function ConditionalMoneyFormat( strValue )
{
   if ( strValue != "0.00" )
   {
      return formatMoney( strValue );
   }
   
   return "";
}

function newImage(arg)
{
   if (document.images)
   {
      rslt = new Image();
      rslt.src = arg;
      return rslt;
   }
}

function changeImages()
{
   if (document.images && (preloadFlag == true))
   {
      for (var i=0; i<changeImages.arguments.length; i+=2)
      {
         document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
      }
   }
}

var preloadFlag = false;

function preloadImages()
{
   if (document.images)
   {
      footer_legal_over = newImage("images/footer_legal-over.gif");
      footer_privacy_over = newImage("images/footer_privacy-over.gif");
      footer_security_over = newImage("images/footer_security-over.gif");
      preloadFlag = true;
   }
}


// Opens the generic  window.
function openGenericWindow(url, w, h, winName, showMenus ) 
{
   if (navigator.appName.substring(0, 5) == 'WebTV')
     return true;

   var t = 100;
   var l = findCenter() - 50;

   var params = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=" + w + ",height=" + h + ",top=" + t + ",left=" + l + ",screenX=" + l + ",screenY=" + t + "";
   
   if ( showMenus )
   {
      var params = "toolbar=yes,location=no,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no,width=" + w + ",height=" + h + ",top=" + t + ",left=" + l + ",screenX=" + l + ",screenY=" + t + "";
   }
   
   genericWindow = window.open(url, winName, params);

   genericWindow.focus();

   return false;
}

function PositionFooter( isLoggedIn )
{
   var h = screen.height;
   
   //alert( "isLoggedIn = " + isLoggedIn + "\nh = " + h );
   
   if ( isLoggedIn )
   {
   
      if ( h <= 600 )
      {
         MoveLayer( "theFooter", 5, 1150 );
      }
      else if ( h > 600 && h <= 1200 )
      {
      MoveLayer( "theFooter", 5, 1000 );      
      }
      else
      {
      MoveLayer( "theFooter", 5, 1100 );
      }
   }
   else
   {
      if ( h <= 600 )
      {
         MoveLayer( "theFooter", 5, 1050 );
      }
      else if ( h > 600 && h <= 1200 )
      {
      MoveLayer( "theFooter", 5, 750 );      
      }
      else
      {
      MoveLayer( "theFooter", 5, 800 );
      }  
   } // if logged in
      
} // PositionFooter

function MoveLayer( strLayerName, xCoord, yCoord )
{
   if ( document.all ) 
   {
      // We have IE4+
      var theLayer = eval( "document.all." + strLayerName + ".style" );     
      theLayer.pixelLeft = xCoord;
      theLayer.pixelTop = yCoord;

   } 
   else if ( document.layers ) 
   {
      // We have Netscape 4.x
      var theLayer = eval( "document." + strLayerName );
      theLayer.left = xCoord;
      theLayer.top = yCoord;   
   } 
   else if ( !document.all && document.getElementById ) 
   {
      // We have Mozilla or Netscape 6.x
      var theLayer = document.getElementById( strLayerName ).style;    
      theLayer.left = xCoord + "px";
      theLayer.top = yCoord + "px";    
   }     
}

function showHideLayer( strLayerName )
{
   var strAction = "";

   if ( document.all ) 
   {
      // We have IE4+
      var theLayer = eval( "document.all." + strLayerName + ".style" );     
      strAction = ( theLayer.visibility == "hidden" ) ? "visible" : "hidden";    
      theLayer.visibility = strAction;
      
   } 
   else if ( document.layers ) 
   {
      // We have Netscape 4.x
      var theLayer = eval( "document." + strLayerName );
      strAction = ( theLayer.visibility == "hide" ) ? "show" : "hide";
      theLayer.visibility = strAction;
   
   } 
   else if ( !document.all && document.getElementById ) 
   {
      // We have Mozilla or Netscape 6.x
      var theLayer = document.getElementById( strLayerName ).style;    
      strAction = ( theLayer.visibility == "hidden" ) ? "visible" : "hidden";
      theLayer.visibility = strAction;
   }
   
} // showHideLayer

function IsVisible( strLayerName )
{
   var LayerVisible = false;
   
   if ( document.all ) 
   {
      // We have IE4+
      var theLayer = eval( "document.all." + strLayerName + ".style" );     
      LayerVisible = ( theLayer.visibility == "visible" ) ? true : false;     
      
   } 
   else if ( document.layers ) 
   {
      // We have Netscape 4.x
      var theLayer = eval( "document." + strLayerName );
      LayerVisible = ( theLayer.visibility == "show" ) ? true : false;     
   
   } 
   else if ( !document.all && document.getElementById ) 
   {
      // We have Mozilla or Netscape 6.x
      var theLayer = document.getElementById( strLayerName ).style;    
      LayerVisible = ( theLayer.visibility == "visible" ) ? true : false;     
   }  
   
   return LayerVisible;
}

// Opens the generic  window.
function openFormInGenericWindow( theForm, url, w, h, winName, showMenus ) 
{
   if (navigator.appName.substring(0, 5) == 'WebTV')
     return true;

   var t = 100;
   var l = findCenter() - 50;

   var params = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=" + w + ",height=" + h + ",top=" + t + ",left=" + l + ",screenX=" + l + ",screenY=" + t + "";
   
   if ( showMenus )
   {
      var params = "toolbar=yes,location=no,directories=yes,status=no,menubar=yes,scrollbars=yes,resizable=no,copyhistory=no,width=" + w + ",height=" + h + ",top=" + t + ",left=" + l + ",screenX=" + l + ",screenY=" + t + "";
   }
   
   genericWindow = window.open(url, winName, params);

   theForm.target = winName;
   theForm.submit();

   genericWindow.focus();

   return false;
}

function closeGenericWindow()
{
   if ( !genericWindow.closed )
   {
      genericWindow.close();
   }
} // closes the window


//
// ENSURES THAT CVV2 IS AT LEAST 3 CHARACTERS LONG
//
function isValidCVV2( fieldCVV2 )
{
   var isValid = true;
   var strCVV2 = fieldCVV2.value;
   var len = strCVV2.length;
   
   // Only check the field if it is not empty
   if ( len != 0 )
   {
      // B is for by-pass
      if ( strCVV2 != "B" )
      {
      if ( len < 3 || len > 4 || isNaN( strCVV2 ) )
      {
         isValid = false;
         requireField(fieldCVV2.name, m_sFormMain, "CVV2 value must be numeric and 3-4 characters in length.");
      }
      }
   }

   return isValid;
}

// 
// GRAB THE CENTER OF THE SCREEN
//
function findCenter() {
   var mid;

   if (document.all) { 
      origWidth = document.body.offsetWidth;

   } else if(document.layers) {
      origWidth = window.innerWidth;

   } else if(!document.all && document.getElementById) {
      origWidth = window.innerWidth;
      
   } else {
      origWidth = window.innerWidth;
   }
   
   mid = parseInt(origWidth / 2);

   if(!document.all && document.getElementById) {
      var winHeight = window.innerHeight - 100;
      var pageHeight = document.body.offsetHeight;
      
      //alert("ph = " + pageHeight);
      //alert("wh = " + winHeight);
      
      if (pageHeight < winHeight) {
         mid += 8;
      }
   
   }

   if (mid < 378) {
      mid = 378;
   }

   return mid;
}

function setFormMain( strFormName )
{
   m_sFormMain = strFormName;
} // setFormMain

// refreshParentOnClose
// Closes the current (popup) window and refreshes its parent.
//
function refreshParentOnClose( executeFunction )
{
   if ( executeFunction )
   {
      if ( top.opener )
      {
         if ( !top.opener.closed )
         {
            top.opener.location.href = top.opener.location.href;
            top.opener.focus();
         }
      }
   }
   
   self.close();

} // refreshParentOnClose

// refreshParentOnClose
// Closes the current (popup) window and refreshes its parent.
//
function refreshParentOnClose2( executeFunction )
{
   if ( executeFunction )
   {
      if ( top.opener )
      {
         if ( !top.opener.closed )
         {
            top.opener.location.reload();
            top.opener.focus();
         }
      }
   }
   
   self.close();

} // refreshParentOnClose

// refreshMainOnClose
// Closes the current (popup) window and refreshes its parent.
//
function refreshMainOnClose( executeFunction )
{
   if ( executeFunction )
   {
      if ( top.opener )
      {
         if ( !top.opener.closed )
         {
            top.opener.location.href = top.opener.location.href;
            top.opener.focus();
         }
      }
   }
   
   self.close();

} // refreshMainOnClose

function frontPadWithZeros( theValue, requiredLength )
{
   var changedStr = "" + theValue;
   var strLen = theValue.length;
   var numZeros = requiredLength - strLen;
   var i = 0;
   
   for ( i = 0; i < numZeros; i++ )
   {
      changedStr = "0" + changedStr;
   }

   return changedStr; 
}

function getFieldObject( fieldNameSnippet )
{
   var theForm = eval( "document." + m_sFormMain );
   var i = 0;
   var len = theForm.elements.length;
   var ReturnField = null;
   
   //alert("theForm = " + theForm); 
   //alert("len = " + len);   
   
   for ( i = 0; i < len; i++ )
   {
      var theField = theForm.elements[i];
      
      //alert("name = " + theField.name);
      
      if ( theField.name.indexOf( fieldNameSnippet ) >= 0 )
      {
         ReturnField = theField;

      } // look for name in name
   } // 

   return ReturnField;
} // 


function getFieldName( fieldNameSnippet )
{
   var theForm = eval( "document." + m_sFormMain );
   var i = 0;
   var len = theForm.elements.length;
   var theName = "";
   
   //alert("theForm = " + theForm); 
   //alert("len = " + len);   
   
   for ( i = 0; i < len; i++ )
   {
      var theField = theForm.elements[i];
      
      //alert("name = " + theField.name);
      
      if ( theField.name.indexOf( fieldNameSnippet ) >= 0 )
      {
         theName = theField.name;

      } // look for name in name
   } // 

   return theName;
} // getFieldName

function getFieldValue( fieldNameSnippet )
{
   var theForm = eval( "document." + m_sFormMain );
   var i = 0;
   var len = theForm.elements.length;
   var theValue = "";
   
   //alert("theForm = " + theForm); 
   //alert("len = " + len);   
   // alert("fieldNameSnippet = " + fieldNameSnippet );

   
   for ( i = 0; i < len; i++ )
   {
      var theField = theForm.elements[i];
            
      if ( theField.name.indexOf( fieldNameSnippet ) >= 0 )
      {
         // alert("fieldNameSnippet = " + fieldNameSnippet + "\nname = " + theField.name + "\nvalue = " + theField.value );

         theValue = theField.value;

      } // look for name in name
   } // 

   return theValue;
} // getFieldValue

function ShowHistory(serviceId, status, resolutionHours, resolutionMins, resolutionAmPm)
{
   document.PostForm.action = "ShowHistory.aspx";
   document.PostForm.sid.value = serviceId;
   document.PostForm.status.value = status;
   document.PostForm.duration_hours.value = resolutionHours;
   document.PostForm.duration_minutes.value = resolutionMins;
   document.PostForm.duration_ampm.value = resolutionAmPm;
   return sendTransaction( document.PostForm, "history_" + serviceId, 1000, 450 );
} // ShowHistory

function showSubscribe(sid)
{
	var params = "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=500,height=300";
	window.open("Subscribe.aspx?sid=" + sid, "subscribe", params);
	return false;
}

function UpdateNotificationList( ServerID )
{
	var params = "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=720,height=450,top=20,left=20,screenX=20,screenY=20";
	window.open("EditList.aspx?sid=" + ServerID, "editlist_" + ServerID, params);
	return false;
} // UpdateNotificationList

function UpdateMultipleServerStatus()
{
	// Grab the selected services.
	
	var selectedServices = "";
	var inputElements = document.getElementsByTagName("input");
	for (var k = 0; k < inputElements.length; k++)
	{
		if (inputElements[k].type == "checkbox" && inputElements[k].checked)
		{
			selectedServices += inputElements[k].value + ",";
		}
	}
	
	// If no services are selected, return.
	
	if (selectedServices.length == 0)
		return false;

	// Open the update status page.
	
	document.PostForm.action = "UpdateStatus.aspx";
	document.PostForm.sid.value = selectedServices.substr(0, selectedServices.length - 1);
	return sendTransaction(document.PostForm, "UpdateMultiple", 540, 500);
} // UpdateMultipleServerStatus


function UpdateServerStatus(serviceId, status, resolutionHours, resolutionMins, resolutionAmPm)
{
   document.PostForm.action = "UpdateStatus.aspx";
   document.PostForm.sid.value = serviceId;
   document.PostForm.status.value = status;
   document.PostForm.duration_hours.value = resolutionHours;
   document.PostForm.duration_minutes.value = resolutionMins;
   document.PostForm.duration_ampm.value = resolutionAmPm;
   return sendTransaction( document.PostForm, "update_" + serviceId, 540, 500 );
} // UpdateServerStatus

function UpdateHistory( HistoryID )
{
   document.PostForm.action = "UpdateHistory.aspx";
   document.PostForm.hid.value = getFieldValue( "HistoryID_" + HistoryID );
   document.PostForm.sid.value = getFieldValue( "ServiceID_" + HistoryID );
   document.PostForm.sn.value = getFieldValue( "ServiceName_" + HistoryID );
   document.PostForm.issue.value = getFieldValue( "IssueReported_" + HistoryID );
   document.PostForm.pub.value = getFieldValue( "PublicComments_" + HistoryID );
   document.PostForm.priv.value = getFieldValue( "PrivateComments_" + HistoryID );
   
   //alert( "hid = " + document.PostForm.hid.value );
   //alert( "sid = " + document.PostForm.sid.value );
   //alert( "sn = " + document.PostForm.sn.value );
   //alert( "issue = " + document.PostForm.issue.value );
   //alert( "pub = " + document.PostForm.pub.value );
   //alert( "priv = " + document.PostForm.priv.value );
   
   return sendTransaction( document.PostForm, "updateHistory_" + HistoryID, 540, 500 );

} // UpdateServerStatus

function EditContact( EmailID )
{

   if ( EmailID > -1 )
   {
      if ( document.EditFormValues.EmailID.value == EmailID || document.EditFormValues.EmailID.value == "" )
      {
         var EditButton = eval( "document." + m_sFormMain + ".EditButton_" + EmailID );
         var NameField = eval( "document." + m_sFormMain + ".Name_" + EmailID );
         var EmailField = eval( "document." + m_sFormMain + ".Email_" + EmailID );  
         document.EditFormValues.EmailID.value = EmailID;
         
         if ( NameField.readOnly && EmailField.readOnly )
         {

            NameField.style.border = "solid 1px #000000";
            NameField.readOnly = false;
            EmailField.style.border = "solid 1px #000000";
            EmailField.readOnly = false;
            EditButton.style.color = "#FFFFFF";
            EditButton.style.background = "#FF6600";
            EditButton.style.border = "solid 1px #000000";

         }
         else
         {
            // validate and submit changes
            //

            //if ( NameField.value.length == 0 )
            //{
            //   NameField.style.background = "#FF0000";
            //   NameField.style.color = "#FFFFFF";
            //   alert( "Name cannot be blank!" );
            //   NameField.select();
            //   return;
            //}
            //else
            //{
               NameField.style.background = "#FFFFFF";
               NameField.style.color = "#000000";
            //}

            if ( EmailField.value.length == 0 )
            {
               EmailField.style.background = "#FF0000";
               EmailField.style.color = "#FFFFFF";
               alert( "Email cannot be blank!" );
               EmailField.select();
               return;
            }
            else
            {
               EmailField.style.background = "#FFFFFF";
               EmailField.style.color = "#000000";
            }

            var msg = "Edit this contact?\n\nName: " + NameField.value + "\nEmail: " + EmailField.value;

            if ( confirm( msg ) )
            {
               // set values and submit changes
               //
               document.EditFormValues.EditMode.value = "EDIT";
               document.EditFormValues.EditName.value = NameField.value;
               document.EditFormValues.EditEmail.value = EmailField.value;

               document.EditFormValues.submit();
            }
            else
            {
               NameField.style.border = "none";
               NameField.readOnly = true;
               EmailField.style.border = "none";
               EmailField.readOnly = true;
               EditButton.style.color = "#000000";
               EditButton.style.background = "#FFFFFF";
               EditButton.style.border = "solid 1px #000000";
               document.EditFormValues.EditMode.value = "";
               
            } // confirm edit

         } // click once to make fields editable...click again to submit changes
      } 
      else
      {
         alert( "You can only edit one record at a time." );  
      } // check if we are in edit mode
   }
   else
   {
      alert( "Service ID is invalid.  You will not be able to edit contacts.  Contact the administrator if this situation persists." );
   } // have a valid service ID
} // EditContact


function DeleteContact( EmailID )
{

   if ( EmailID > -1 )
   {
      var DeleteButton = eval( "document." + m_sFormMain + ".DeleteButton_" + EmailID );
      var NameField = eval( "document." + m_sFormMain + ".Name_" + EmailID );
      var EmailField = eval( "document." + m_sFormMain + ".Email_" + EmailID );  

      NameField.style.border = "solid 1px #FF0000";
      NameField.style.color = "#FF0000";
      EmailField.style.border = "solid 1px #FF0000";
      EmailField.style.color = "#FF0000";

      DeleteButton.style.color = "#FFFFFF";
      DeleteButton.style.background = "#FF6600";
      DeleteButton.style.border = "solid 1px #000000";
      
      var msg = "Delete this contact?\n\nName: " + NameField.value + "\nEmail: " + EmailField.value;

      if ( confirm( msg ) )
      {
         DeleteButton.style.color = "";
         DeleteButton.style.background = "";
         DeleteButton.style.border = "none";

         // set values and submit changes
         //
         document.EditFormValues.EditMode.value = "DELETE";
         document.EditFormValues.EditName.value = NameField.value;
         document.EditFormValues.EditEmail.value = EmailField.value;
         document.EditFormValues.EmailID.value = EmailID;
         
         document.EditFormValues.submit();         
      }
      else
      {
         NameField.style.border = "none";
         NameField.style.color = "#000000";
         EmailField.style.border = "none";
         EmailField.style.color = "#000000";

         DeleteButton.style.color = "#000000";
         DeleteButton.style.background = "#FFFFFF";
         DeleteButton.style.border = "solid 1px #000000";
      
      } // delete record?

   } // have a valid service ID
   else
   {
      alert( "Service ID is invalid.  You will not be able to delete contacts.  Contact the administrator if this situation persists." );
   } // have a valid service ID   
} // DeleteContact



// sendTransaction
// Sends a form transaction (post) to a new window.
//
function sendTransaction( sForm, winName, w, h )
{
   var params = "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=" + w + ",height=" + h + ",top=20,left=20,screenX=20,screenY=20";
   theWindow = window.open("", winName, params);   
   sForm.target = winName;
   sForm.submit();
   theWindow.focus();
   return false;
   
} // sendTransaction


function ConfirmHistoryClose()
{
   var CloseIssue = eval( "document." + m_sFormMain + "." + getFieldName( "CloseIssue" ) );
   var ServerStatus = eval( "document." + m_sFormMain + "." + getFieldName( "StatusList" ) );
   
   if ( CloseIssue != null )
   {
      if ( CloseIssue.checked )
      {
         return confirm( "Are you sure you wish to close this issue?" );
      }
      else if ( ServerStatus.value == "1" )
      {
         
         if ( confirm( "Do you wish to close this issue?" ) )
         {
            CloseIssue.checked = true;
            return true;
         }
      }
      
   }

   return true;

} // ConfirmHistoryClose


//#####################################################################################
//### Generic Functions for Buttons
//#####################################################################################
//=== changeButton(sFormName,sElementName,sValue,sErrMsg)
//=====================================================================================
//=== Description: Sets a form button's value to a "in process" state
//===              and disallows them from being clicked again
//===       Input: sFormName - the form in which the element exists
//===              sElementName - the button element
//===              sValue - the value that button is being assigned on click
//===              sErrMsg - the message that will be displayed is clicked again
//===     Returns: true/false - depending on the button already being clicked or not
//=== Uses Func's: setTextValue()
//===     Example: onclick="if (changeButton(this.form.name,this.name,'Processing...',
//===                          'Already in the state of Processing your Transaction.
//===                           Please Wait...')) {this.form.submit();}"
//===     Created: 08.08.01 - L2 / Last Modified: 00.00.00 - L2
//=====================================================================================
var bSubmitted = false;
function changeButton(sFormName,sElementName,sValue,sErrMsg)
{
  setTextValue(sFormName,sElementName,sValue);
  if (bSubmitted) { alert(sErrMsg);    return false; }
  else            { bSubmitted = true; return true;  }
}

function changeButtonBack(sFormName,sElementName,sValue)
{
  setTextValue(sFormName,sElementName,sValue);
  bSubmitted = false;
}

function setTextValue(sFormName,sElementName,sValue)
{ eval('document.'+sFormName+'.'+sElementName+'.value="'+sValue+'"') }

//#####################################################################################
//### Generic Functions for Field Validation/Formatting
//#####################################################################################
//--------------------------------------------------------------------------------
//    Function: replaceChars(strOrig,strOut,strAdd)
// Description: Replaces a string with another string
//       Input: strOrig - the string that is being modified
//              strOut  - what to replace
//              strAdd  - what to replace with
//     Returns: the modified string
//--------------------------------------------------------------------------------
function replaceChars(strOrig,strOut,strAdd)
{
  strTemp = "" + strOrig;
  while (strTemp.indexOf(strOut)>-1)
  {
    nCharPos = strTemp.indexOf(strOut);
    strTemp = "" + (strTemp.substring(0, nCharPos) + strAdd + strTemp.substring((nCharPos+ strOut.length), strTemp.length));
  }
  return strTemp;
}
//--------------------------------------------------------------------------------
//    Function: isEmpty(strInput)
// Description: See if an input value has been entered
//       Input: strInput - string being checked
//     Returns: true  - if empty
//              false - otherwise
//--------------------------------------------------------------------------------
function isEmpty(strInput)
{
  if (strInput.length == 0 || strInput == null) { return true;  }
  else                                          { return false; }
}

//#####################################################################################
//### Generic Functions for Text Boxes
//#####################################################################################

function setTextValue(sFormName,sElementName,sValue)
{ eval('document.'+sFormName+'.'+sElementName+'.value="'+sValue+'"') }

//=== setTextBoxColors(sElement,sFormName,sBackColor,sTextColor)
//======================================================================
//=== Description: Changes the background and text color for a text field
//===       Input: sFormName    - form name
//===              sElementName - form element
//===              sBackColor   - background color for text box
//===              sTextColor   - text color for text box
//=== Uses Func's: None
//===     Returns: Nothing
//===     Example: setTextBoxColors(sElement,sFormName,'#CC3300','WHITE');
//===     Created: 01.03.01 - L2 / Last Modified: 01.11.01 - L2
//======================================================================
function setTextBoxColors(sElement,sFormName,sBackColor,sTextColor)
{
  eval('document.' + sFormName + '.' + sElement + '.style.backgroundColor = sBackColor;');
  eval('document.' + sFormName + '.' + sElement + '.style.color           = sTextColor;');
}

//######################################################################
//### Generic Functions for Event Validation
//######################################################################
//=== isKeyOnlyNumbers(e)
//======================================================================
//=== Description: Keeps a user from entering specified characters into a form element
//===       Input: e - the javascript event
//=== Uses Func's: none
//===     Returns: true if restricted character - false if not restricted
//===     Example: onkeypress="if (isKeyOnlyNumbers(event)) {return false;}"
//===     Created: 10.16.00 - L2 / Last Modified: 10.16.00 - L2
//======================================================================
function isKeyOnlyNumbers(e)
{
  if (navigator.appName == "Netscape") { var nCheckChar = e.which;   }
  else                                 { var nCheckChar = e.keyCode; }

  var sCheckChar = String.fromCharCode(nCheckChar);

   if ( nCheckChar == 0 || nCheckChar == 8 )
   {
      // delete, space, backspace...
      return false;
   }


  if (!( nCheckChar > 45 && nCheckChar < 58))
  {
    e.returnValue = false;
    return true;
  }
  else { return false; }
}

//=== isKeyOnlyAlphaNumeric(e)
//======================================================================
//=== Description: Keeps a user from entering specified characters into a form element
//==               Allows letters, numbers spaces and the delete/backspace key.
//===       Input: e - the javascript event
//=== Uses Func's: none
//===     Returns: true if restricted character - false if not restricted
//===     Example: onkeypress="if (isKeyOnlyAlphaNumeric(event)) {return false;}"
//===     Created: 10.16.00 - L2 / Last Modified: 10.16.00 - L2
//======================================================================
function isKeyOnlyAlphaNumeric(e)
{
   if (navigator.appName == "Netscape") { var nCheckChar = e.which;   }
   else                                 { var nCheckChar = e.keyCode; }

   var sCheckChar = String.fromCharCode(nCheckChar);
   
   if (!( nCheckChar > 45 && nCheckChar < 58) )
   {
      if ( ( nCheckChar >= 65 && nCheckChar <= 90) )
      {     
         return false;
      }

      if ( ( nCheckChar >= 97 && nCheckChar <= 122) )
      {     
         return false;
      }
      
      if ( nCheckChar == 0 || nCheckChar == 8 )
      {
         return false;
      }
      
      e.returnValue = false;
      return true;
      
   }

   return false; 

} // isKeyOnlyAlphaNumeric



//#####################################################################################
//### Form Specific Functions
//#####################################################################################

//--------------------------------------------------------------------------------
//--- Check to see if the field is Empty ---
//--------------------------------------------------------------------------------
function checkRequiredField(sFormName,sElementName,sErrorMsg)
{
  if ( eval('isEmpty(document.'+sFormName+'.'+sElementName+'.value)') )
  {
    requireField(sElementName,sFormName,sErrorMsg);
    return false;
  }
  else
  { return true; }
}

//--------------------------------------------------------------------------------
//--- Alert user that field is required & set the cursor to that field
//--- Modified from standard to add field color changing
//--------------------------------------------------------------------------------
function requireField(strElement,strFormName,strAlert)
{
  alert(strAlert);
  setFocusOnField(strElement,strFormName);
  setTextBoxColors(strElement,strFormName,'#CC3300','WHITE');
}
//--------------------------------------------------------------------------------
//--- Set the cursor to that field
//--------------------------------------------------------------------------------
function setFocusOnField(strElement,strFormName)
{
  var theElement = eval('document.' + strFormName + '.' + strElement );
  
  theElement.focus();
  
  if ( theElement.type == "text" || theElement.type == "password" || theElement.type == "textarea" )
  {
   theElement.select();
  }

}

//=== setTextBoxColors(sElement,sFormName,sBackColor,sTextColor)
//======================================================================
//=== Description: Changes the background and text color for a text field
//===       Input: sFormName    - form name
//===              sElementName - form element
//===              sBackColor   - background color for text box
//===              sTextColor   - text color for text box
//=== Uses Func's: None
//===     Returns: Nothing
//===     Example: setTextBoxColors(sElement,sFormName,'#CC3300','WHITE');
//===     Created: 01.03.01 - L2 / Last Modified: 01.11.01 - L2
//======================================================================
function setTextBoxColors(sElement,sFormName,sBackColor,sTextColor)
{
  eval('document.' + sFormName + '.' + sElement + '.style.backgroundColor = sBackColor;');
  eval('document.' + sFormName + '.' + sElement + '.style.color           = sTextColor;');
}

function getElementValue(sFormName,sElementName)
{ return eval('document.' + sFormName + '.' + sElementName + '.value') }

//
// blastFieldValue - Blows away the value in the given form field
//
function blastFieldValue( theField )
{
   theField.value = ""
} // blastFieldValue


function checkIsAlphaNumeric( theField, strName )
{
   if (!isEmpty(theField.value))

   {
      if ( !isAlphaNumeric( theField.value ) )
      {
         requireField(theField.name, m_sFormMain, strName + " can only contain alpha-numeric characters.");
         return false;
      }
   }

   setTextBoxColors( theField.name, m_sFormMain,'#FFFFFF','#000000');

   return true;

} // checkIsAlphaNumeric

//
// Checks all the characters in a string to see if they're alphanumeric
// @param strValue - the value of the field
// @return true if correct length, false otherwise
//
function isAlphaNumeric( strValue )
{
   var isValid = true;
   var isNumber = false;
   var isLetter = false;

   strValue = strValue.replace(" ", "");
   var len = strValue.length;
   var letterArr = new Array(
   
   "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
   "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
   "~", "!", "@", "#", "$", "^", "&", "*", "(", ")", "-", "_", "=", "+", "[", "]", "{", "}", ";", ":", ",", ".", "/", "<", ">",
   "'"
   );
   
   var lenArr = letterArr.length;

   for ( var i = 0; i < len; i++ )
   {
      var ch = strValue.charAt(i);

      if ( !isNaN( ch ) )
      {
         // alert( "'" + ch + "' isNumber" );
         isNumber = true;
      }
      else
      {
         for ( var j = 0; j < lenArr; j++ )
         {
            if ( ch.toUpperCase() == letterArr[j] )
            {
               // alert( "'" + ch + "' isLetter" );
               isLetter = true;
               break;
            }

         } // inner loop
      }

      if ( !isNumber && !isLetter )
      {
         isValid = false;
         break;
      }

      // Reset for the next character
      //
      isNumber = false;
      isLetter = false;

   } // for loop


   return isValid;
}

function NotificationWarning( ServiceName, Action, ServiceID, StatusFieldValue )
{
	var action = ( Action == "OPEN" ) ? "beginning" : "completion";
	var message = "Are you sure you want to send an alert to clients indicating the " + action + " of maintenance";

	if ( StatusFieldValue != "1" )
	{
		if ( ServiceName != "ALL" )
		{                  
			action = ( Action == "OPEN" ) ? "service outage" : "resumption of service";
			message = "Are you sure you want to send a " + action + " alert to clients for " + ServiceName;
		}
	}
	else if ( StatusFieldValue == "1" && Action == "OPEN" )
	{
		alert( "Status of " + ServiceName + " is marked as Fully Functional.\n\nPlease change the status of this service before sending the Down message." );	
		return false;
	} // don't allow messages to fire if fully functional

	message += "?";

   return confirm( message );
} // NotificationWarning