function urlCheck(strURL) {
	return (strURL.indexOf('http://') == 0 && strURL.indexOf('.') != -1);
}

function emailCheck (strEmail) {
	return ((strEmail.indexOf('@') != -1) && (strEmail.indexOf('.') != -1));
}

//Declare a pivot year constant.
var _PIVOT_YEAR_CONST = 50;

/**********************************************************
	PURPOSE:
		Verifies that a string is a valid date.
	INPUT:
		String possibly containing a date.
	OUTPUT:
		True (1) or False(0)
	ASSUMPTIONS:
	EFFECTS:
*/
function verifyDate(a, bVerifyCurrentorFuture){
	// checkDate (yearField, monthField, dayField, STRING labelString [, OKtoOmitDay==false])
	//
	// Check that yearField.value, monthField.value, and dayField.value 
	// form a valid date.
	//
	// If they don't, labelString (the name of the date, like "Birth Date")
	// is displayed to tell the user which date field is invalid.
	//
	// If it is OK for the day field to be empty, set optional argument
	// OKtoOmitDay to true.  It defaults to false.
	
	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)) return false;
	    if (!isMonth(monthField)) return false;
	    if ( (OKtoOmitDay == true) && isEmpty(dayField) ) return true;
	    else if (!isDay(dayField)) 
	        return false;
	    if (isDate (yearField, monthField, dayField))
	       return true;
	}

	// isYear (STRING s [, BOOLEAN emptyOK])
	// 
	// isYear returns true if string s is a valid 
	// Year number.  Must be 2 or 4 digits only.
	// 
	// For Year 2000 compliance, you are advised
	// to use 4-digit year numbers everywhere.

	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));
	}

	// isMonth (STRING s [, BOOLEAN emptyOK])
	// 
	// isMonth returns true if string s is a valid 
	// month number between 1 and 12.
	//
	// For explanation of optional argument emptyOK,
	// see comments of function isInteger.

	function isMonth (s)
	{   if (isEmpty(s)) 
	       if (isMonth.arguments.length == 1) return defaultEmptyOK;
	       else return (isMonth.arguments[1] == true);
	    return isIntegerInRange (s, 1, 12);
	}

	// isDay (STRING s [, BOOLEAN emptyOK])
	// 
	// isDay returns true if string s is a valid 
	// day number between 1 and 31.
	// 
	// For explanation of optional argument emptyOK,
	// see comments of function isInteger.

	function isDay (s)
	{   if (isEmpty(s)) 
	       if (isDay.arguments.length == 1) return defaultEmptyOK;
	       else return (isDay.arguments[1] == true);   
	    return isIntegerInRange (s, 1, 31);
	}
	
	// isDate (STRING year, STRING month, STRING day)
	//
	// isDate returns true if string arguments year, month, and day 
	// form a valid date.
	// 

	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;
	}

	// daysInFebruary (INTEGER year)
	// 
	// Given integer argument year,
	// returns number of days in February of that year.

	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 );
	}
	
	// Check whether string s is empty.

	function isEmpty(s)
	{   return ((s == null) || (s.length == 0))
	}
	
	// isInteger (STRING s [, BOOLEAN emptyOK])
	// 
	// Returns true if all characters in string s are numbers.
	//
	// Accepts non-signed integers only. Does not accept floating 
	// point, exponential notation, etc.
	//
	// We don't use parseInt because that would accept a string
	// with trailing non-numeric characters.
	//
	// By default, returns defaultEmptyOK if s is empty.
	// There is an optional second argument called emptyOK.
	// emptyOK is used to override for a single function call
	//      the default behavior which is specified globally by
	//      defaultEmptyOK.
	// If emptyOK is false (or any value other than true), 
	//      the function will return false if s is empty.
	// If emptyOK is true, the function will return true if s is empty.
	//
	// EXAMPLE FUNCTION CALL:     RESULT:
	// isInteger ("5")            true 
	// isInteger ("")             defaultEmptyOK
	// isInteger ("-5")           false
	// isInteger ("", true)       true
	// isInteger ("", false)      false
	// isInteger ("5", false)     true

	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)
	}

	// isNonnegativeInteger (STRING s [, BOOLEAN emptyOK])
	// 
	// Returns true if string s is an integer >= 0.
	//
	// For explanation of optional argument emptyOK,
	// see comments of function isInteger.

	function isNonnegativeInteger (s)
	{   var secondArg = defaultEmptyOK;

	    if (isNonnegativeInteger.arguments.length > 1)
	        secondArg = isNonnegativeInteger.arguments[1];

	    // The next line is a bit byzantine.  What it means is:
	    // a) s must be a signed integer, AND
	    // b) one of the following must be true:
	    //    i)  s is empty and we are supposed to return true for
	    //        empty strings
	    //    ii) this is a number >= 0

	    return (isSignedInteger(s, secondArg) && ( (isEmpty(s) && secondArg)  || (parseInt (s) >= 0) ) );
	}

	// isSignedInteger (STRING s [, BOOLEAN emptyOK])
	// 
	// Returns true if all characters are numbers; 
	// first character is allowed to be + or - as well.
	//
	// Does not accept floating point, exponential notation, etc.
	//
	// We don't use parseInt because that would accept a string
	// with trailing non-numeric characters.
	//
	// For explanation of optional argument emptyOK,
	// see comments of function isInteger.
	//
	// EXAMPLE FUNCTION CALL:          RESULT:
	// isSignedInteger ("5")           true 
	// isSignedInteger ("")            defaultEmptyOK
	// isSignedInteger ("-5")          true
	// isSignedInteger ("+5")          true
	// isSignedInteger ("", false)     false
	// isSignedInteger ("", true)      true

	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 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)) return false; // , 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).
	    var num = parseInt(s, 10);

	    return ((num >= a) && (num <= b));
	}

	// Notify user that contents of field theField are invalid.
	// String s describes expected contents of theField.value.
	// Put select theField, pu focus in it, and return false.

	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
	}
	
	// If the user did not specify the bVerifyCurrentorFuture argument,
	// default to false.
	if (verifyDate.arguments.length == 1) bVerifyCurrentorFuture = false;

	// BOI, followed by one or more digits, followed by EOI.
	var reInteger = /^\d+$/

	// BOI, followed by an optional + or -, followed by one or more digits, 
	// followed by EOI.
	var reSignedInteger = /^(\+|\-)?\d+$/;

	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;
	
	var defaultEmptyOK = false;
	var iDay = "This field must be a day number between 1 and 31.  Please reenter it now.";
	var iMonth = "This field must be a month number between 1 and 12.  Please reenter it now.";
	var iYear = "This field must be a 2 or 4 digit year number.  Please reenter it now.";
	var iDatePrefix = "The Day, Month, and Year for ";
	var iDateSuffix = " do not form a valid date.  Please reenter them now.";
	
	aryDateFields = a.split("/");
	if (aryDateFields.length == 1) {
		aryDateFields = a.split("-");
	}
	var strMonth = aryDateFields[0];
	var strDay = aryDateFields[1];
	var strYear = aryDateFields[2];
	var dtToday = new Date();
	var dtTest = new Date(a);

	var bRetVal = false;

	bRetVal = checkDate(strYear, strMonth, strDay, 'the start date or end date');

	// Check of current or future date. Jason Rein, OSGI, 12/14/99
	if (bRetVal && bVerifyCurrentorFuture){
		var bIsCurrent

		// Adjust for Y2K.
		if (dtTest.getYear()<_PIVOT_YEAR_CONST) dtTest.setYear(dtTest.getYear() + 2000);
		
		// Is the date prior to today? (subtract 24*60*60*1000 thousandths of a second)
		bIsCurrent = !(dtTest.getTime() < dtToday.getTime() - 86400000);

		// Notify the user of a date prior to today.
		if (!bIsCurrent) alert('Dates prior to the current date are not allowed.');
		
		// Make sure to return the data.
		bRetVal = (bRetVal && bIsCurrent)
	}
	
	return bRetVal;
}

/**********************************************************
	PURPOSE:
		Validate the length of the text in a specified textarea.
	INPUT:
		The textarea object and the maximum length (default=255) to check for.
	OUTPUT:
		True (1) or False(0)
	ASSUMPTIONS:
	EFFECTS:
*/
function checkTextAreaMaxLength(taTest, lngMaxLength, strExtraText){
	//Combine the textarea value and data in the strExtraText
	var strTestString = new String(taTest.value + strExtraText);


	// check for a second parameter.  If missing, default to 255
	if (checkTextAreaMaxLength.arguments.length == 1){ lngMaxLength = 255 };
	
	// check the length of the text in the textarea.
	// prompt the user if it is too long.
	if (strTestString.length>=lngMaxLength){
		alert('You have reached the maximum length (' + lngMaxLength + ') allowed for this text area.');
		taTest.focus();
		return false;
	}
	else{
		return true;
	}
}

//****************************************************************
//The function is used to remove those offending characters that
//are greater than 126 or less than 32. It will also locate those
//characters that need to be translated into standard ASCII from
//UNICODE, specifically the double and single quotes in Word.
//The primary reason for this code is because MSIE 5.0 has a
//severe bug that causes duplicate postings if certain character
//codes are found in the form.
//01/13/2000 - Paul S. Currie			Inception
//****************************************************************
function removeSpecialChars(myString){
    // Make a copy of the string to work with
    var newString = myString;
    
    // Cycle through each character
    for (var i = 1; i <= myString.length; i++){
        // Look at this character
        if ((newString.charCodeAt(myString.length - i) > 126) || (newString.charCodeAt(myString.length - i) < 32)){
			switch (newString.charCodeAt(myString.length - i)){
				case 10:			//line feed, leave alone
					break;
				case 13:			//carriage return, leave alone
					break;
				case 8216:{			//change to single quote
					newString = (newString.substring(0, myString.length - i) + "'" + newString.substring(myString.length - i + 1, newString.length));
					break;
				}
				case 8217:{			//change to single quote
					newString = (newString.substring(0, myString.length - i) + "'" + newString.substring(myString.length - i + 1, newString.length));
					break;
				}
				case 8221:{			//change to double quote
					newString = (newString.substring(0, myString.length - i) + "\"" + newString.substring(myString.length - i + 1, newString.length));
					break;
				}
				case 8220:{			//change to double quote
					newString = (newString.substring(0, myString.length - i) + "\"" + newString.substring(myString.length - i + 1, newString.length));
					break;
				}
				case 8482:{			//change trademark symbol to "(TM)"
					newString = (newString.substring(0, myString.length - i) + "(TM)" + newString.substring(myString.length - i + 1, newString.length));
					break;
				}
				case 153:{			//change trademark symbol to "(TM)"
					newString = (newString.substring(0, myString.length - i) + "(TM)" + newString.substring(myString.length - i + 1, newString.length));
					break;
				}
				case 169:{			//change copyright symbol to (c)
					newString = (newString.substring(0, myString.length - i) + "(c)" + newString.substring(myString.length - i + 1, newString.length));
					break;
				}
				case 169:{			//change copyright symbol to (c)
					newString = (newString.substring(0, myString.length - i) + "(c)" + newString.substring(myString.length - i + 1, newString.length));
					break;
				}
				case 8211:{			//change to a dash
					newString = (newString.substring(0, myString.length - i) + "-" + newString.substring(myString.length - i + 1, newString.length));
					break;
				}
				case 8212:{			//change to a dash
					newString = (newString.substring(0, myString.length - i) + "-" + newString.substring(myString.length - i + 1, newString.length));
					break;
				}
				case 150:{			//change to a dash
					newString = (newString.substring(0, myString.length - i) + "-" + newString.substring(myString.length - i + 1, newString.length));
					break;
				}
				case 151:{			//change to a dash
					newString = (newString.substring(0, myString.length - i) + "-" + newString.substring(myString.length - i + 1, newString.length));
					break;
				}
				default:{			//all we know is we don't want it right now
					newString = (newString.substring(0, myString.length - i) + newString.substring(myString.length - i + 1, newString.length));
					break;
				}
			}
		}
    }

    // Return the stripped string
    return newString; 
}
//	Validate any Single String Style Control	//
function validateStringControl(cntrl)
{
	var pattern = /\S/;
	var text = cntrl.value;
	var result = text.match(pattern);
	if (result != null)
	{
		return true;
	}
	else
	{	
		return false;
	}

}

//	Validate any Listbox to make sure one item is selected		//
//	The IgnoreFirstLine Parameter gives a developer the ability	//
//		to Ignore the First Item in the Listbox when deciding	//
//		whether or not the Items have been selected				//
function validateListControl(cntrl, IgnoreFirstLine)
{
	var varCounter;
	var ValidationMessage = '';

//	Ignores the First Item if the IgnoreFirstLine Parm is True	//
	if (IgnoreFirstLine == true)
	{
		varCounter = 1;
	}
	else
	{
		varCounter = 0;
	}

//	Check to see if a legal Item has been selected				//	
	for (varCounter; varCounter < cntrl.length; varCounter++)
	{
		if (cntrl.options[varCounter].selected == true)
		{		
			return true;
		}
	}
	return false;
}

//	Validate to make sure that the Province is not set to a US	//
//	State, if the Country is not United States; also, validates	//
//	to see if Province is International and Country is US.		//
//	Return Values are:											//
//		0 = Everything is OK									//
//		1 = Province is International, Country is US			//
//		2 = Province is NotApplicable, Country is US.			//
//		3 = Province is State, Country is not US				//

function validateProvinceCountry(cntrlProvince, cntrlCountry)
{
	var guidUnitedStates = '{DF257189-54B1-11D3-AD9A-00508B0CC8BC}';
	var guidInternational = '{EF73DB10-3BAE-11D4-AD24-00508B6CBB35}';
	var guidNotApplicable = '{EF2571CC-54B1-11D3-AD9A-00508B0CC8BC}';
	var lngReturn = 0;
	
	if(cntrlCountry.options[cntrlCountry.selectedIndex].value == guidUnitedStates)
	{
		if(cntrlProvince.options[cntrlProvince.selectedIndex].value == guidInternational)
		{
			lngReturn = 1;	
		}
		
		if(cntrlProvince.options[cntrlProvince.selectedIndex].value == guidNotApplicable)
		{
			lngReturn = 2;	
		}
	}
	else
	{
		if(cntrlProvince.options[cntrlProvince.selectedIndex].value != guidInternational && cntrlProvince.options[cntrlProvince.selectedIndex].value != guidNotApplicable)
		{
			lngReturn = 3;
		}
	}	
	return lngReturn;		
}

