
var sOfferCode = "Offer code"
var sUSLastName = "Last Name"
var sUSFirstName = "First Name"
var sWorldLastName = "Family Name"
var sWorldFirstName = "Given Name"
var sTitle = "Title"
var sCompanyName = "Company Name"
var sWebSite = "The year company was founded"
var sUSAddress = "Street Address"
var sWorldAddress = "Address"
var sCity = "City"
var sStateCode = "State Code"
var sWorldState = "State, Province, or Prefecture"
var sCountry = "Country"
var sZIPCode = "ZIP Code"
var sWorldPostalCode = "Postal Code"
var sPhone = "Phone Number"
var sFax = "Fax Number"
var sEmail = "Email"
var sOtherInfo = "Other Information"


// i is an abbreviation for "invalid"

var iStateCode = "The state must be a valid two character U.S. state abbreviation (like NY for New York)."
var iZIPCode = "The ZIP code must be a 5 or 9 digit U.S. ZIP Code (like 10701 or 10701-2030)."
var iUSPhone = "The phone number must be a 10 digit U.S. phone number (like 914 555 1212)."
var iWorldPhone = "This field must be a valid international phone number."
var iUSFax = "The fax number must be a 10 digit U.S. phone number (like 914 555 1212)."
var iSSN = "This field must be a 9 digit U.S. social security number (like 123 45 6789)."
var iEmail = "The e-mail address must be a valid email address (like bobs@barra.com)."
var iCreditCardPrefix = "This is not a valid "
var iCreditCardSuffix = " credit card number. (Click the link on this form to see a list of sample numbers.)"
var iDay = "Please enter a day number between 1 and 31."
var iMonth = "Please enter a month number between 1 and 12."
var iYear = "Please enter 4 digit year number."
var iDatePrefix = "The Month, Day, and Year for "
var iDateSuffix = " do not form a valid date."



// p is an abbreviation for "prompt"
var pEntryPrompt = "Please enter a "
var pStateCode = "2 character state code (like NY)."
var pZIPCode = "5 or 9 digit U.S. ZIP Code (like 10701 or 10701-2030)."
var pUSPhone = "10 digit U.S. phone number (like 914 555 1212 or (914) 555-1212)."
var pWorldPhone = "international phone number."
var pEmail = "valid email address (like bobs@barra.com)."
var pCreditCard = "valid credit card number."
var pDay = "day number between 1 and 31."
var pMonth = "month number between 1 and 12."
var pYear = "2 or 4 digit year number."
var pProvince = "province."
var pPostalCode = "postal code."

var defaultEmptyOK = false

//--------------------------------------------------
var reEmail = /^.+\@.+\..+$/
function isEmail (s)
{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
    
    else {
       return reEmail.test(s)
    }
}
function checkEmail (theField, emptyOK)
{   if (checkEmail.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else if (!isEmail(theField.value, false)) 
       //return warnInvalid (theField, iEmail);
	 return false;
    else return true;
}
//--------------------------------------------------
var USStateCodeDelimiter = "|";
var USStateCodes = "AL|AK|AS|AZ|AR|CA|CO|CT|DE|DC|FM|FL|GA|GU|HI|ID|IL|IN|IA|KS|KY|LA|ME|MH|MD|MA|MI|MN|MS|MO|MT|NE|NV|NH|NJ|NM|NY|NC|ND|MP|OH|OK|OR|PW|PA|PR|RI|SC|SD|TN|TX|UT|VT|VI|VA|WA|WV|WI|WY|AE|AA|AE|AE|AP"
function isStateCode(s)
{   if (isEmpty(s)) 
       if (isStateCode.arguments.length == 1) return defaultEmptyOK;
       else return (isStateCode.arguments[1] == true);
    return ( (USStateCodes.indexOf(s) != -1) &&
             (s.indexOf(USStateCodeDelimiter) == -1) )
}
function checkStateCode (theField, emptyOK)
{   if (checkStateCode.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    {  theField.value = theField.value.toUpperCase();
       if (!isStateCode(theField.value, false)) 
          //return warnInvalid (theField, iStateCode);
			return false;
       else return true;
    }
}

//--------------------------------------------------
var digits = "0123456789";
var digitsInUSPhoneNumber = 10;
var phoneNumberDelimiters = "()- ";
var validUSPhoneChars = digits + phoneNumberDelimiters;

function reformatUSPhone (USPhone)
{   return (reformat (USPhone, "(", 3, ") ", 3, "-", 4))
}
function isUSPhoneNumber (s)
{   if (isEmpty(s)) 
       if (isUSPhoneNumber.arguments.length == 1) return defaultEmptyOK;
       else return (isUSPhoneNumber.arguments[1] == true);
    return (isInteger(s) && s.length == digitsInUSPhoneNumber)
}
function checkUSPhone (theField, emptyOK)
{   if (checkUSPhone.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    {  var normalizedPhone = stripCharsInBag(theField.value, phoneNumberDelimiters)
       if (!isUSPhoneNumber(normalizedPhone, false)) 
          //return warnInvalid (theField, iUSPhone);
	    return false;	
       else 
       {  // if you don't want to reformat as (123) 456-789, comment next line out
          theField.value = reformatUSPhone(normalizedPhone)
          return true;
       }
    }
}
//--------------------------------------------------
var ZIPCodeDelimiters = "-";
var ZIPCodeDelimeter = "-"
var digitsInZIPCode1 = 5
var digitsInZIPCode2 = 9

function reformat (s)
{   var arg;
    var sPos = 0;
    var resultString = "";
    for (var i = 1; i < reformat.arguments.length; i++) {
       arg = reformat.arguments[i];
       if (i % 2 == 1) resultString += arg;
       else {
           resultString += s.substring(sPos, sPos + arg);
           sPos += arg;
       }
    }
    return resultString;
}
function reformatZIPCode (ZIPString)
{   if (ZIPString.length == 5) return ZIPString;
    else return (reformat (ZIPString, "", 5, "-", 4));
}
function checkZIPCode (theField, emptyOK)
{
	if (checkZIPCode.arguments.length == 1) emptyOK = defaultEmptyOK;
	if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    { var normalizedZIP = stripCharsInBag(theField.value, ZIPCodeDelimiters)
	   if (!isZIPCode(normalizedZIP, false)) 
         //return warnInvalid (theField, iZIPCode);
		  return false;	
      else 
      {  // if you don't want to insert a hyphen, comment next line out
         theField.value = reformatZIPCode(normalizedZIP)
         return true;
      }
    }
}
function isZIPCode (s)
{  if (isEmpty(s)) 
       if (isZIPCode.arguments.length == 1) return defaultEmptyOK;
       else return (isZIPCode.arguments[1] == true);
   return (isInteger(s) && 
            ((s.length == digitsInZIPCode1) ||
             (s.length == digitsInZIPCode2)))
}
//--------------------------------------------------
var reWhitespace = /^\s+$/
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}
function isWhitespace (s)
{   // Is s empty?
    return (isEmpty(s) || reWhitespace.test(s));
}
function stripCharsInRE (s, bag)

{       return s.replace(bag, "")
}
function stripCharsInBag (s, bag)
{   var i;
    var 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 stripCharsNotInBag (s, bag)
{   var i;
    var returnString = "";
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) != -1) returnString += c;
    }
    return returnString;
}
function stripWhitespace (s)
{   return stripCharsInBag (s, " ")
}
//---------------------------------------------------
var reInteger = /^\d+$/
//var reSignedInteger = /^+|-?(\d+)$/
var reFloat = /^((\d+(\.\d*)?)|((\d*\.)?\d+))$/
//var reSignedFloat = /^(((+|-)?\d+(\.\d*)?)|((+|-)?(\d*\.)?\d+))$/
//var reSignedFloat = /^(((+|-)?\d+(\.\d*)?)|(((+|-)?\d*\.)?\d+))$/

function isInteger (s)
{   var i;
    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);
    return reInteger.test(s)
}
function isSignedFloat (s)
/*
{   if (isEmpty(s)) 
       if (isSignedFloat.arguments.length == 1) return defaultEmptyOK;
       else return (isSignedFloat.arguments[1] == true);

    else {
       return reSignedFloat.test(s)
    }
}
*/

{	
	if	((s.substring(0,1) == "-")||(s.substring(0,1) == "+"))
		{
			s=s.substring(1,s.length)
		}
	return isFloat(s)
}
function isFloat (s)

{   if (isEmpty(s)) 
       if (isFloat.arguments.length == 1) return defaultEmptyOK;
       else return (isFloat.arguments[1] == true);

    return reFloat.test(s)
}


//---------------------------------------------------
function promptEntry (s)
{   window.status = pEntryPrompt + s
}
//---------------------------------------------------
function warnInvalid (theField, s)
{   theField.focus()
    theField.select()
    alert(s)
    return false
}
//---------------------------------------------------
function makeArray(n) {
//*** BUG: If I put this line in, I get two error messages:
//(1) Window.length can't be set by assignment
//(2) daysInMonth has no property indexed by 4
//If I leave it out, the code works fine.
//   this.length = n;
   for (var i = 1; i <= n; i++) {
      this[i] = 0
   } 
   return this
}

var daysInMonth = makeArray(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;   // must programmatically check this
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 getCurrentYear()
{
	var today = new Date();
	var theYear = today.getyear();
	if (theYear.length == 2) { theYear = "19" + theYear };
	return theYear;
}
function isYear (s)
{   if (isEmpty(s)) 
       if (isYear.arguments.length == 1) return defaultEmptyOK;
       else return (isYear.arguments[1] == true);
    //if (!isNonnegativeInteger(s)) return false;
    if (parseInt(s) < 0) return false;
    return  ((s.length == 4)&& (parseInt(s) > 0));
}
function isMonth (s)
{   if (isEmpty(s)) 
       if (isMonth.arguments.length == 1) return defaultEmptyOK;
       else return (isMonth.arguments[1] == true);
    return isIntegerInRange (s, 1, 12);
}
function isDay (s)
{   if (isEmpty(s)) 
       if (isDay.arguments.length == 1) return defaultEmptyOK;
       else return (isDay.arguments[1] == true);   
    return isIntegerInRange (s, 1, 31);
}
function daysInFebruary (year)
{   // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    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 isIntegerInRange (s, a, b)
{   if (isEmpty(s)) 
       if (isIntegerInRange.arguments.length == 1) return defaultEmptyOK;
       else return (isIntegerInRange.arguments[1] == true);

    // Catch non-integer strings to avoid creating a NaN below,
    // which isn't available on JavaScript 1.0 for Windows.
    if (!isInteger(s, false)) return false;

    // Now, explicitly change the type to integer via parseInt
    // so that the comparison code below will work both on 
    // JavaScript 1.2 (which typechecks in equality comparisons)
    // and JavaScript 1.1 and before (which doesn't).
    if (s.length > 1)
       {
			if (s.substring(0,1) == "0")
				{
					s = s.substring(1,s.length)
				}
	   }
    var num = parseInt (s);
    return ((num >= a) && (num <= b));
}
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);
       return false;
    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);
       return false;
    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);
       return false;
    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 false; //return warnInvalid (yearField, iYear);
    if (!isMonth(monthField.value)) return false; //return warnInvalid (monthField, iMonth);
    if ( (OKtoOmitDay == true) && isEmpty(dayField.value) ) return true;
    else if (!isDay(dayField.value)) 
       //return warnInvalid (dayField, iDay);
       return false;
    if (isDate (yearField.value, monthField.value, dayField.value))
       return true;
    //alert (iDatePrefix + labelString + iDateSuffix)
    return false
}

//---------------------------------------------------
function toAlpha(checkString)
{
    newString = "";    // REVISED/CORRECTED STRING
    count = 0;         // COUNTER FOR LOOPING THROUGH STRING

    // LOOP THROUGH STRING CHARACTER BY CHARACTER
    for (i = 0; i < checkString.length; i++) {
        ch = checkString.substring(i, i+1);

        // ENSURE CHARACTER IS AN ALPHA CHARACTER
        if ((ch >= "a" && ch <= "z") || (ch >= "A" && ch <= "Z" )) {
            newString += ch;
        }
    }
    return newString;
}
//---------------------------------------------------
function getMessageTitle()
{
	var msg = "\nInvestWorks is unable to process this information due to incorrect or incomplete information!!!\nPlease make the following corrections to the information you have entered:\n\n";
	return msg;
}
    