function SelectBox(theForm) {

  theForm.focus();
  theForm.select();
  
}

// Preload images
var empty = new Image(); empty.src = "fieldempty.gif";
var email = new Image(); email.src = "emailerror.gif";
var zipcd = new Image(); zipcd.src = "ziperror.gif";
var phone = new Image(); phone.src = "phoneerror.gif";

var haveerrors = 0;

function showImage(imagename, imageurl, errors) {

  document[imagename].src = imageurl;
  if (!haveerrors && errors) haveerrors = errors;

}

function Validate(objForm) {

  haveerrors = 0;

  (objForm.txtFName.value == "")
    ? showImage("firstnameerror", "fieldempty.gif", true)   // no semi-colon after this line!
    : showImage("firstnameerror", "blankimage.gif", false); // true = errors, false = no errors

  (objForm.txtLName.value == "") 
    ? showImage("lastnameerror", "fieldempty.gif", true)   // no semi-colon after this line!
    : showImage("lastnameerror", "blankimage.gif", false); // true = errors, false = no errors
  
  (objForm.txtCompany.value == "") 
    ? showImage("companyerror", "fieldempty.gif", true)   // no semi-colon after this line!
    : showImage("companyerror", "blankimage.gif", false); // true = errors, false = no errors
  
  (objForm.txtPhone.value == "") 
    ? showImage("phoneerror", "phoneerror.gif", true)   // no semi-colon after this line!
    : showImage("phoneerror", "blankimage.gif", false); // true = errors, false = no errors
	
  (checkInternationalPhone(objForm.txtPhone.value)==false) 
    ? showImage("phoneerror", "phoneerror.gif", true)   // no semi-colon after this line!
    : showImage("phoneerror", "blankimage.gif", false); // true = errors, false = no errors
  
  (objForm.txtBusAddress1.value == "") 
    ? showImage("addresserror", "fieldempty.gif", true)   // no semi-colon after this line!
    : showImage("addresserror", "blankimage.gif", false); // true = errors, false = no errors

  (objForm.txtBusCity.value == "")
    ? showImage("cityerror", "fieldempty.gif", true)   // no semi-colon after this line!
    : showImage("cityerror", "blankimage.gif", false); // true = errors, false = no errors

  (objForm.txtBusState.options[objForm.txtBusState.selectedIndex].value == "")
    ? showImage("stateerror", "fieldempty.gif", true)   // no semi-colon after this line!
    : showImage("stateerror", "blankimage.gif", false); // true = errors, false = no errors
  
  (!validateZIP(objForm.txtBusZip.value)) 
    ? showImage("ziperror", "ziperror.gif", true)   // no semi-colon after this line!
    : showImage("ziperror", "blankimage.gif", false); // true = errors, false = no errors
  
  (objForm.rdoHasRestrictions[0].checked && objForm.txtRestrictionList.value == "")
    ? showImage("listerror", "fieldempty.gif", true)   // no semi-colon after this line!
    : showImage("listerror", "blankimage.gif", false); // true = errors, false = no errors

  (objForm.rdoWantsBooth[0].checked && objForm.txtVendorContact.value == "")
    ? showImage("vendorcontacterror", "fieldempty.gif", true)   // no semi-colon after this line!
    : showImage("vendorcontacterror", "blankimage.gif", false); // true = errors, false = no errors

  (objForm.rdoIsCitizen[1].checked && objForm.txtCitizenCountry.value == "")
    ? showImage("countryerror", "fieldempty.gif", true)   // no semi-colon after this line!
    : showImage("countryerror", "blankimage.gif", false); // true = errors, false = no errors

  (!validateEmail(objForm.txtEmail.value)) 
    ? showImage("emailerror", "emailerror.gif", true)   // no semi-colon after this line!
    : showImage("emailerror", "blankimage.gif", false); // true = errors, false = no errors

  return (!haveerrors);

}

function ValidatePayment(objForm) {

  haveerrors = 0;

  (!DateIsValid(objForm.txtDatePaid.value))   
    ? showImage("dateerror", "dateerror.gif", true)   // no semi-colon after this line!
    : showImage("dateerror", "blankimage.gif", false); // true = errors, false = no errors

  (objForm.txtCheckNum.value == "") 
    ? showImage("checkerror", "fieldempty.gif", true)   // no semi-colon after this line!
    : showImage("checkerror", "blankimage.gif", false); // true = errors, false = no errors
  
  (objForm.txtAmountPaid.value == "") 
    ? showImage("amounterror", "fieldempty.gif", true)   // no semi-colon after this line!
    : showImage("amounterror", "blankimage.gif", false); // true = errors, false = no errors
  
  return (!haveerrors);

}

function ValidateUpload(objForm) {

  haveerrors = 0;

  (objForm.txtAttach.value == "") 
    ? showImage("fileerror", "fieldempty.gif", true)   // no semi-colon after this line!
    : showImage("fileerror", "blankimage.gif", false); // true = errors, false = no errors
  
  (objForm.txtTitle.value == "") 
    ? showImage("titleerror", "fieldempty.gif", true)   // no semi-colon after this line!
    : showImage("titleerror", "blankimage.gif", false); // true = errors, false = no errors
  
  return (!haveerrors);

}

function validateZIP(field) {
var valid = "0123456789-";
var hyphencount = 0;

if (field.length!=5 && field.length!=10) {
//alert("Please enter your 5 digit or 5 digit+4 zip code.");
return false;
}
for (var i=0; i < field.length; i++) {
temp = "" + field.substring(i, i+1);
if (temp == "-") hyphencount++;
if (valid.indexOf(temp) == "-1") {
//alert("Invalid characters in your zip code.  Please try again.");
return false;
}
if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) {
//alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.");
return false;
   }
}
return true;
}


function validateEmail(EmailAddress) {
  invalidCharacters = " /:,;";
  if (EmailAddress == "") {
    return false;
  }
  for (i = 0; i < invalidCharacters.length; i++) {
    badCharacter = invalidCharacters.charAt(i);
    if (EmailAddress.indexOf(badCharacter,0) > -1) {
      return false;
    }
  }
  atSignPosition = EmailAddress.indexOf("@",1);
  if (atSignPosition == -1) {
    return false;
  }
  if (EmailAddress.indexOf("@",atSignPosition+1) > -1) {
    return false;
  }
  periodPosition = EmailAddress.indexOf(".",atSignPosition);
  if (periodPosition == -1) {
    return false;
  }
  if (periodPosition+3 > EmailAddress.length) {
   return false;
  }
  return true;
}

/**
 * DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()-. ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;


function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function DateIsValid( sDate ) { 

  var aMatch = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/.exec(sDate); 
  if (aMatch == null)
    return false;
  else { 
    if (!isDate(aMatch[3], aMatch[1], aMatch[2]))
      return false;
    else
      return true;
  }
}

var reWhitespace = /^\s+$/
var reLetter = /^[a-zA-Z]$/
var reAlphabetic = /^[a-zA-Z]+$/
var reAlphanumeric = /^[a-zA-Z0-9]+$/
var reDigit = /^\d/
var reLetterOrDigit = /^([a-zA-Z]|\d)$/
var reInteger = /^\d+$/
var reSignedInteger = /^(\+|-)?\d+$/
var reFloat = /^((\d+(\.\d*)?)|((\d*\.)?\d+))$/
var reSignedFloat = /^(((\+|-)?\d+(\.\d*)?)|((\+|-)?(\d*\.)?\d+))$/
var reEmail = /^.+\@.+\..+$/
var digits = "0123456789";
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz"
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
var whitespace = " \t\n\r";
var defaultEmptyOK = false;
var daysInMonth = new Array(12);

daysInMonth[1] = 31;
daysInMonth[2] = 29; 
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;


function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

function isWhitespace (s)

{   // Is s empty?
    return (isEmpty(s) || reWhitespace.test(s));
}

function isMyInteger (s)

{   var i;

    if (isEmpty(s)) 
       if (isMyInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isMyInteger.arguments[1] == true);

    return reInteger.test(s)
}

function isSignedInteger (s)

{   if (isEmpty(s)) 
       if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isSignedInteger.arguments[1] == true);

    
    else {
       return reSignedInteger.test(s)
    }
}


function isPositiveInteger (s)
{   var secondArg = defaultEmptyOK;

    if (isPositiveInteger.arguments.length > 1)
        secondArg = isPositiveInteger.arguments[1];

    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) > 0) ) );
}

function isNonnegativeInteger (s)
{   var secondArg = defaultEmptyOK;

    if (isNonnegativeInteger.arguments.length > 1)
        secondArg = isNonnegativeInteger.arguments[1];

    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) >= 0) ) );
}

function isNegativeInteger (s)
{   var secondArg = defaultEmptyOK;

    if (isNegativeInteger.arguments.length > 1)
        secondArg = isNegativeInteger.arguments[1];

    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) < 0) ) );
}

function isNonpositiveInteger (s)
{   var secondArg = defaultEmptyOK;

    if (isNonpositiveInteger.arguments.length > 1)
        secondArg = isNonpositiveInteger.arguments[1];

    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) <= 0) ) );
}

function isYear (s)
{   if (isEmpty(s)) 
       if (isYear.arguments.length == 1) return defaultEmptyOK;
       else return (isYear.arguments[1] == true);
    if (!isNonnegativeInteger(s)) return false;
    return ((s.length == 2) || (s.length == 4));
}

function isMyIntegerInRange (s, a, b)
{   if (isEmpty(s)) 
       if (isMyIntegerInRange.arguments.length == 1) return defaultEmptyOK;
       else return (isMyIntegerInRange.arguments[1] == true);

    if (!isMyInteger(s, false)) return false;

    var num = parseInt (s);
    return ((num >= a) && (num <= b));
}

function isMonth (s)
{   if (isEmpty(s)) 
       if (isMonth.arguments.length == 1) return defaultEmptyOK;
       else return (isMonth.arguments[1] == true);
    return isMyIntegerInRange (s, 1, 12);
}

function isDay (s)
{   if (isEmpty(s)) 
       if (isDay.arguments.length == 1) return defaultEmptyOK;
       else return (isDay.arguments[1] == true);   
    return isMyIntegerInRange (s, 1, 31);
}

function daysInFebruary (year)
{   

    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}


function isDate (year, month, day)
{   // catch invalid years (not 2- or 4-digit) and invalid months and days.
    if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false))) return false;

    // Explicitly change type to integer to make code work in both
    // JavaScript 1.1 and JavaScript 1.2.
    var intYear = parseInt(year);
    var intMonth = parseInt(month);
    var intDay = parseInt(day);

    // catch invalid days, except for February
    if (intDay > daysInMonth[intMonth]) return false; 

    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;

    return true;
}

function checkYear (theField, emptyOK)
{   if (checkYear.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (!isYear(theField.value, false)) 
       return warnInvalid (theField, iYear);
    else return true;
}


function checkMonth (theField, emptyOK)
{   if (checkMonth.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (!isMonth(theField.value, false)) 
       return warnInvalid (theField, iMonth);
    else return true;
}


function checkDay (theField, emptyOK)
{   if (checkDay.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (!isDay(theField.value, false)) 
       return warnInvalid (theField, iDay);
    else return true;
}


function checkDate (yearField, monthField, dayField, labelString, OKtoOmitDay)
{   // Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
    if (checkDate.arguments.length == 4) OKtoOmitDay = false;
    if (!isYear(yearField.value)) return warnInvalid (yearField, iYear);
    if (!isMonth(monthField.value)) return warnInvalid (monthField, iMonth);
    if ( (OKtoOmitDay == true) && isEmpty(dayField.value) ) return true;
    else if (!isDay(dayField.value)) 
       return warnInvalid (dayField, iDay);
    if (isDate (yearField.value, monthField.value, dayField.value))
       return true;
    alert (iDatePrefix + labelString + iDateSuffix)
    return false
}

function OpenWindow(strURL, intWidth, intHeight) {
  intLeftPos = 0
  intTopPos  = 0
  if (screen) {
    intLeftPos = (screen.width - parseInt(intWidth)) / 2
    intTopPos  = (screen.height - parseInt(intHeight)) / 2
  }
  objWindow = window.open(strURL, 'BIOS', 'width='+parseInt(intWidth)+',height='+parseInt(intHeight)+',toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,left='+intLeftPos+',top='+intTopPos+'')
  objWindow.focus()
}

  if(document.images) {
    //create image objects
	  pics1on = new Image();
	  pics2on = new Image();
	  pics3on = new Image();
	  pics4on = new Image();
	  pics1off = new Image();
	  pics2off = new Image();
	  pics3off = new Image();
	  pics4off = new Image();


    //load image files
          pics1on.src = "images/ncs_splash_mockup_07on.jpg";
          pics2on.src = "images/ncs_splash_mockup_08on.jpg";
          pics3on.src = "images/ncs_splash_mockup_09on.jpg";
          pics4on.src = "images/ncs_splash_mockup_10on.jpg";
	  pics1off.src = "images/ncs_splash_mockup_07.jpg";
	  pics2off.src = "images/ncs_splash_mockup_08.jpg";
	  pics3off.src = "images/ncs_splash_mockup_09.jpg";
	  pics4off.src = "images/ncs_splash_mockup_10.jpg";
  }

  function LightOn(Name) {
    if(document.images)
		document.images[Name].src = eval(Name + "on.src");
  }

  function LightOff(Name) {
	if(document.images)
		document.images[Name].src = eval(Name + "off.src");
  }


