/* BEGIN: PluginIsInstalled Script *********************************************/
var msie_windows = 0;
if((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1))
{
  msie_windows = 1;
  document.writeln('<SCRIPT LANGUAGE="VBscript">');
  document.writeln('  \'This will scan for plugins for all versions of Internet Explorer that have a VBscript engine version 2 or greater.');
  document.writeln('  \'This includes all versions of IE4 and beyond and some versions of IE 3.');
  document.writeln('  Dim detectViaVBScript');
  document.writeln('  detectViaVBScript = 0');
  document.writeln('  If ScriptEngineMajorVersion >= 2 Then detectViaVBScript = 1');

  document.writeln('  Function ActiveXDetect(activeXname)');
  document.writeln('    On Error Resume Next');
  document.writeln('    If ScriptEngineMajorVersion >= 2 Then');
  document.writeln('      ActiveXDetect = False');
  document.writeln('      ActiveXDetect = IsObject(CreateObject(activeXname))');
  document.writeln('      If (err) Then ActiveXDetect = False');
  document.writeln('    Else');
  document.writeln('      ActiveXDetect = False');
  document.writeln('    End If');
  document.writeln('  End Function');
  document.writeln('</' + 'Script>');
}

function PluginDetect(plugindescription, pluginxtension, pluginmime, activeXname)
{
  var plugin_undetectable = (msie_windows && detectViaVBScript)?(0):(1);
  var detected = 0;
  var daPlugin = new Object();
  var i;

  if(navigator.plugins)
  {
    numPlugins = navigator.plugins.length;
    if(numPlugins > 1)
    {
      if(navigator.mimeTypes && navigator.mimeTypes[pluginmime] && navigator.mimeTypes[pluginmime].enabledPlugin && (navigator.mimeTypes[pluginmime].suffixes.indexOf(pluginxtension) != -1))
      {
        if((navigator.appName == 'Netscape') && (navigator.appVersion.indexOf('4.0') != -1))
        {
          for(i in navigator.plugins)
          {
            if((navigator.plugins[i].description.indexOf(plugindescription) != -1) || (i.indexOf(plugindescription) != -1))
            {
              detected=1;
              break;
            }
          }
        }
        else
        {
          for(i=0; i<numPlugins; i++)
          {
            daPlugin = navigator.plugins[i];
            if((daPlugin.description.indexOf(plugindescription) != -1) || (daPlugin.name.indexOf(plugindescription) != -1))
            {
               detected=1;
               break;
            }
          }
        }

        // Mac weirdness
        if(navigator.mimeTypes[pluginmime] == null)
          detected = 0;
      }
      return detected;
    }
    else return ((msie_windows == 1) && !plugin_undetectable)?(ActiveXDetect(activeXname)):(0);
  }
  else return 0;
}

function PluginIsInstalled(whichPlugin)
{
  var isInstalled = 0;
  if((whichPlugin == 'flash') || (whichPlugin == 'Flash'))
    isInstalled = PluginDetect('Flash', 'swf', 'application/x-shockwave-flash', 'ShockwaveFlash.ShockwaveFlash');
  else if((whichPlugin == 'director') || (whichPlugin == 'Director'))
    isInstalled = PluginDetect('Shockwave', 'dcr', 'application/x-director', 'SWCtl.SWCtl.1');
  else if((whichPlugin == 'quicktime') || (whichPlugin == 'Quicktime') || (whichPlugin == 'QuickTime'))
    isInstalled = PluginDetect('QuickTime', 'mov', 'video/quicktime', '');
  else if((whichPlugin == 'realaudio') || (whichPlugin == 'Realaudio') || (whichPlugin == 'RealAudio'))
    isInstalled = (PluginDetect('RealPlayer', 'rpm', 'audio/x-pn-realaudio-plugin', 'RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)')) || (PluginDetect('RealPlayer', 'rpm', 'audio/x-pn-realaudio-plugin','rmocx.RealPlayer G2 Control')) || (PluginDetect('RealPlayer', 'rpm', 'audio/x-pn-realaudio-plugin','RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)')) || (PluginDetect('RealPlayer', 'rpm', 'audio/x-pn-realaudio-plugin','RealVideo.RealVideo(tm) ActiveX Control (32-bit)'))
  else
    alert('Error in JS_Library.js. whichPlugin=' +whichPlugin+ '\n\n          PluginIsInstalled(\'flash\')\n\n' + '          PluginIsInstalled(\'director\')\n\n' + '          PluginIsInstalled(\'quicktime\')\n\n' + '          PluginIsInstalled(\'realaudio\')');

  return isInstalled;
}
/* END: PluginIsInstalled Script *********************************************/

// Resets all form field values back to their original state...
function clearForm(objForm)
{
  myCollection = objForm.elements;
  for(i=0; i<myCollection.length; i++)
  {
    with(myCollection.item(i))
    {
      if(type == "text" || tagName == "TEXTAREA")
      {
        value = "";
      }
      else if (type == "checkbox" || type == "radio")
      {
        checked = false;
      }
      else if(tagName == "SELECT")
      {
        options.selectedIndex = 0;
      }
    }
  }
}

// Displays a message and focuses the cursor to the given form field...
function doAlertAndFocus(obj, message)
{
  alert(message);
  obj.focus();
  return (false);
}

// Determine whther or not any options in a dropdown form field are selected...
function isOptionSelected(obj)
{
  if(obj.selectedIndex < 0){
    return (false);
  }
    
  for(var i=0; i<obj.length; i++)
  {
    if(obj.options[i].selected && obj.options[i].value != "")
      return (true);
  }
  return (false);
}

// Determine whether first option is  selected-added 01/06/05-sk
function isOptionOneSelected(obj)
{
  if(obj.selectedIndex == 0) { return (true) ;}
  return (false);
}

// Retrieves the index of the checked option of a checkbox or radio button form field...
function getCheckedOption(obj)
{
  var i=0;
  for(; i<obj.length; i++)
  {
    if(obj[i].checked)
      break;
  }
  return (i);
}

// Retrieves the value of the checked option of a checkbox or radio button form field...
function getCheckedValue(obj)
{
  for(var i=0; i<obj.length; i++)
  {
    if(obj[i].checked)
      return (obj[i].value);
  }
  return ("");
}

// Dynamically format a text form field value to currency...
function toCurrency(obj)
{
  var s = obj.value;
  var returnString = "";

  for(i = 0; i < s.length; i++)
  {
    var c = s.charAt(i);
    returnString += ("0123456789".indexOf(c) != -1)?(c):("");
  }

  if(parseInt(returnString) >= 1000)
  {
    var daString = "";
    for(i=returnString.length-1; i>-1;)
    {
      tempStr = "";
      for(n=0;n<3;n++) tempStr = returnString.charAt(i-n)+tempStr;
      daString = (i>2)?("," +tempStr+daString):(tempStr+daString);
      i= i-3;
    }
    returnString = daString;
  }
  returnString = (parseInt(returnString) == 0)?(""):(returnString);
  obj.value = (returnString.length > 0)?("$" +returnString):("")
}

// Dynamically format a text form field value to a phone number...
function toPhone(obj)
{
 var e = obj? obj : window.event; 
 if(!e) return; 
 var key = 0; 
 if (e.keyCode) { key = e.keyCode; } // for moz/fb, if keyCode==0 use 'which' 
 else if (typeof(e.which)!= 'undefined') { key = e.which; } 


  if(key != 8)
  {
    var s = obj.value;

    var tempString1 = "";
    for(i=0; i<s.length; i++)
    {
      if("0123456789".indexOf(s.charAt(i)) != -1)
        tempString1 += s.charAt(i);
    }

    var tempString2 = "";
    for(i=0; i<tempString1.length; i++)
    {
      tempString2 += tempString1.charAt(i);
      tempString2 += (i==2 || i==5)?("-"):("");
    }
    obj.value = (tempString2.length > 12)?(tempString2.substring(0,12)):(tempString2);
  }
}

// Determines whether or not a value is in the format of a phone number...
function isPhoneNumber(strValue)
{
  if(strValue.length != 12)
    return (false);
  else if(strValue.charAt(3) != '-' || strValue.charAt(7) != '-')
    return (false);
  else if(!isNumeric(strValue.substring(0,3)) || !isNumeric(strValue.substring(4,7)) || !isNumeric(strValue.substring(8,strValue.length)))
    return (false);
  else
    return (true);
}

// Determines whether or not text form field is empty...
function isWhiteSpace(strValue)
{
  var whitespace = " \t\n\r";
  iLength = strValue.length;

  if(strValue == null || iLength == 0)
    return (true);

  for(var i=0; i<iLength; i++)
  {
    if(whitespace.indexOf(strValue.charAt(i)) == -1)
       return (false);
  }
  return (true);
}

// Determines whether or not text form field value is numeric...
function isNumeric(strValue)
{
  iLength = strValue.length;

  for(x = 0; x < iLength; x++)
    if(isNaN(parseInt(strValue.charAt(x))))
      return (false);

  return (true);
}

// Determines whether or not text form field value is a valid email address...
function isEmail(strValue)
{
  if(isWhiteSpace(strValue)) return (false);

  // Check for invalid characters
  invalidChars = " ~\'^\`\"*+=\\|][(){}$&!#%/:,;";
  for(i=0; i<invalidChars.length; i++)
    if(strValue.indexOf(invalidChars.charAt(i),0) > -1)
      return (false);

  lengthOfstrValue = strValue.length;
  if((strValue.charAt(lengthOfstrValue - 1) == ".") || (strValue.charAt(lengthOfstrValue - 2) == "."))
    return (false);

  Pos = strValue.indexOf("@");
  if(strValue.charAt(Pos + 1) == ".") return (false);

  while((Pos < lengthOfstrValue) && ( Pos != -1))
  {
    Pos = strValue.indexOf(".",Pos);
    if(strValue.charAt(Pos + 1) == ".") return (false);
    if(Pos != -1) Pos++;
  }

  // There must be one and only one @ symbol
  atPos = strValue.indexOf("@");
  if(atPos == -1) return (false);
  if(strValue.indexOf("@",atPos+1) != -1) return (false);

  // Also check for at least one period after the @ symbol
  periodPos = strValue.indexOf(".",atPos);
  if(periodPos == -1) return (false);
  if(periodPos+3 > strValue.length) return (false);

  return (true);
}

// Determines whether or not text form field value is a URL...
function isURL(strValue)
{
  if(isWhiteSpace(strValue)) return (false);

  // Check for invalid characters
  invalidChars = " ~\'^\`\"*+=\\|][(){}$&!@#%,;";
  for(i=0; i<invalidChars.length; i++)
    if(strValue.indexOf(invalidChars.charAt(i),0) > -1)
      return (false);

  // Make sure http:// is present (only once)
  atPos = strValue.indexOf("http://");
  if(atPos == -1) return (false);
  if(strValue.indexOf("http://",atPos+1) != -1) return (false);

  // Also check for at least one period after http://
  periodPos = strValue.indexOf(".",atPos);
  if(periodPos == -1) return (false);
  if(periodPos+3 > strValue.length) return (false);

  return (true);
}

// Determines whether or not text form field value is a zipcode...
function isZip(strValue)
{
  iLength = strValue.length;

  if(isWhiteSpace(strValue))
    return (false);

  if(iLength != 5 && iLength != 9 && iLength != 10)
    return (false);

  if((iLength == 5 || iLength == 9) && !isNumeric(strValue))
    return (false);

  else if(iLength == 10)
  {
    if(strValue.charAt(5) != "-" && strValue.charAt(5) != " ")
      return (false);

    for(x=0; x < iLength; x++)
    {
      if(x != 5 && !isNumeric(strValue.charAt(x)))
        return (false);
    }
  }
  return (true);
}

// Determines whether or not text form field value is a date...
function isDate(strValue)
{
  if(isWhiteSpace(strValue)) return (false);

  strDate = strValue;

  var dateregex = /^[ ]*[0]?(\d{2})\/(\d{2})\/(\d{4,})[ ]*$/; // mm/dd/yyyy
  var match = strDate.match(dateregex);
  if(match)
  {
    var tmpdate = new Date(match[3],parseInt(match[1],10)-1,match[2]);
    if(tmpdate.getDate() == parseInt(match[2],10) && tmpdate.getFullYear() == parseInt(match[3],10) && (tmpdate.getMonth()+1) == parseInt(match[1],10))
      return (true);
  }
  return (false);
}
function Test()
{
  alert("Hello World!");
}