var bNetscape;

//checks the type of browser
if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) 
{
	bNetscape=true;
} 
else
{
	bNetscape=false;
}

// pre-loads the button images
/*
if (typeof(loadimages)=="function")
  { loadimages( ); }
if (typeof(preloadImages)=="function")
  { preloadImages( ); }
*/

if (bNetscape)
  document.captureEvents(Event.KEYDOWN);
document.onkeydown=keydowncheck;

// this function looks for the enter key
function keydowncheck(e)
{ var Key;
  if (bNetscape)
    { Key=e.which;
    }
  else
    { Key=event.keyCode;
    }
  if (Key==13)
    { var oBtn=new getObj(GetKeyDownButton( ));
      if (oBtn.obj!=null
          && oBtn.obj.disabled!= true
          && oBtn.style.visibility!="hidden"
          && oBtn.style.display!="none")
        { oBtn.obj.focus( );
        }
    }
}

//this function will set focus on the first invalid control
/*
function FocusOnInvalidControl( )
{ 
return;
for (var i=0; i<Page_Validators.length; i++)
    { if (!Page_Validators[i].isvalid)
        { var ctrl=new getObj(Page_Validators[i].controltovalidate);
          if (ctrl.obj!=null)
            { if (ctrl.obj.disabled== false
                  && ctrl.style.display!="none"
                  && ctrl.style.visibility!="hidden")
                { ctrl.obj.focus( );
                }
            }
          return;
        }
    }
}
*/
 /*
if (typeof(Page_ClientValidate)=="function")
  { Page_ClientValidateOld=Page_ClientValidate;
    Page_ClientValidate= function ( )
                         { var isValid;
                           isValid=Page_ClientValidateOld( );
                           if (!isValid)
                             { FocusOnInvalidControl( );
                             }
                           else
                             { DisableFormMethod( );
                             }
                           return isValid;
                         };
  }
*/
//this function will disable all submit buttons on a form and replace them with spans, once a submit button
// has been pressed 
// Update: submit button is now disabled, no span swapping occurs.

function DisableFormMethod( )
{ 
    var theForm = document.forms['form1'];
    if (!theForm) {
        theForm = document.forms['Form1'];
    }
    if (!theForm) {
        theForm = document.form1;
    }
   
  var SubmitOnce= false;
  for (var i=0; i<theForm.length; i++)
    { var oButton=theForm.elements[i];
      if (oButton.type.toLowerCase( )=="submit" && oButton.style.display!="none")
        { SubmitOnce= true;
          var oSpan=new getObj(oButton.id+"_span");
          if (oSpan.obj!=null)
            {
              oButton.style.display="none";
              //oButton.obj.disabled="true";
              oSpan.obj.innerHTML=oButton.value;
              oSpan.style.display="inline";
              oSpan.style.width=oButton.style.width;
            }
        }
    }
  if (SubmitOnce)
    { theForm.submit( );
    }
}


function XMLHttpRequestor( )
{ var xmlhttp;
  if (window.ActiveXObject)
    {
     // use the ActiveX control for IE5.x and IE6
     // Esoteric Javascript to grab the proper version of the ActiveX control
     /*@cc_on @*/
     /*@if (@_jscript_version >= 5)
     try {
                     xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.4.0");
                     return xmlhttp;

             } catch (e) {
                     try {
                             xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                             return xmlhttp;

                     } catch (E) {
                             return null;
                     }
     }
     @else
             return null;
     @end @*/
     }
  else
    { if (window.XMLHttpRequest)
        {
          // If IE7, Mozilla, Safari, etc: Use native object
          xmlhttp=new XMLHttpRequest( );
          xmlhttp.isDOM= true;
          return xmlhttp;
        }
    }
}
var req;

function SynchRequestXML(url,parameters)
{
  // Grab a valid ActiveX XMLHTTPRequest object
  req=XMLHttpRequestor( );
  // IF a valid ActiveX object was not returned then return false
  if (!req)
    return null;
  // Call the web page
  //req.onreadystatechange = LookupZipCallback(); *** for ASYNC only

  
  req.open("POST",url, false);
  if (req.overrideMimeType)
    { req.setRequestHeader("Connection","close");
      req.overrideMimeType("text/xml");
    }
  req.setRequestHeader("Content-type","application/x-www-form-urlencoded");
  req.setRequestHeader("Content-length",parameters.length);
  req.send(parameters);
  // return the XML as text
  if (req.status==200)
    { return req.responseText;
    }
  else
    { return null;
    }
}

function LookupZip( )
{
  //Lookup the city, state, country by the zipcode
  var zip=new getObj("txtPostalCode");
  if (zip.obj!=null
      && zip.obj.value.length>0)
    {
      //validate the zipcode
      var zipcode=zip.obj.value;
      if (zipcode.length>5)
        { zipcode=zipcode.substring(0,5);
        }
      if (!IsNumeric(zipcode))
        { return;
        }
      //add files in this folder to the listbox **note: does not work in //localhost
      var result=SynchRequestXML("/admin/XMLRequest.aspx?zip="+zipcode,"&zip="+zipcode);
      if (result != null)
      {
          result=result.replace("<Result>","");
          result=result.replace("</Result>","");
          var arrResult=result.split("|");
          var city=new getObj("txtCity");
          if (city.obj!=null)
            { city.obj.value=arrResult[0];
            }
          var state=new getObj("dropState");
          var index;
          if (state.obj!=null)
            { for (i=0; i<state.obj.options.length; i++)
                { if (state.obj.options[i].value==arrResult[1])
                    {
                      //set state drop to the returned state
                      state.obj.options[i].selected= true;
                      index=i;
                      break;
                    }
                }
            }
          
          var license=new getObj("dropLicense");
          if (license.obj!=null)
            { for (i=0; i<license.obj.options.length; i++)
                { if (license.obj.options[i].text==state.obj.options[index].text)
                    {
                      //set license drop to the returned state as set by dropstate
                      license.obj.options[i].selected= true;
                    }
                }
            }
            
          var country=new getObj("dropCountry");
          if (country.obj!=null)
            { for (i=0; i<country.obj.options.length; i++)
                { if (country.obj.options[i].value==arrResult[2])
                    {
                      //set state drop to the returned state
                      country.obj.options[i].selected= true;
                    }
                }
            }
        }
    }
}

function IsNumeric(strString)
//  check for valid numeric strings     
{ return !/\D/.test(strString);
}

function openremoteWindow(which)
{ win=window.open(which,"viewdoc","height=500,width=700,scrollbars=yes,toolbar=no,resizable=yes,menubar=no,status=no,left=100,top=100");
  window.setTimeout("win.focus()",250);
}


function popitup(url)
{ newwindow=window.open(url,'images','width=800,height=600,status=no,toolbar=no,menubar=no,resizable=yes,scrollbars=yes,left,top');
  if (window.focus)
    { newwindow.focus( );
    }
}

