//formcheck// 18 Feb 97 created Eric Krock
//
// (c) 1997 Netscape Communications Corporation

// VARIABLE DECLARATIONS

var digits = "0123456789";
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz"
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

// whitespace characters
var whitespace = " \t\n\r";

// decimal point character differs by language and culture
var decimalPointDelimiter = "."

// CONSTANT STRING DECLARATIONS
// (grouped for ease of translation and localization)

// m is an abbreviation for "missing"

var mPrefix = "Please enter a value into the "
var mSuffix = " field."

// s is an abbreviation for "string"
var sEmail = "Email"

// p is an abbreviation for "prompt"
var pEntryPrompt = "Please enter a "
var pEmail = "valid email address (like foo@bar.com)."

var iEmail = "This field must be a valid email address (like foo@bar.com). Please reenter it now."
var iPhone = "This field must be a valid phone number (like 345-555-9012). Please reenter it now."

var daysInMonth = new Array(13);
daysInMonth[0] = 0;
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;


// 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 );
}


// Global variable defaultEmptyOK defines default return value 
// for many functions when they are passed the empty string. 
// By default, they will return defaultEmptyOK.
var defaultEmptyOK = false

// Check whether string s is empty.

function isEmpty(s)
{  if (s == null) {
		return true
	} else {
		if  (s.length == 0){
			return true
		} else {
			return false
		}
	}
}

// Check whether field is undefined or is empty
function isEmptyOrMissing(theField)
{ if(theField){	
		var myValue = fieldValue(theField)
		if (myValue == null) {
			return true;
		} else {
			if (myValue.length == 0) {
				return true
			} else {
				return false
			}
		}		
	} else {
		return true;
	}
}


// Returns true if string s is empty or 
// whitespace characters only.

function isWhitespace (s)

{   var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

// Removes all characters which appear in string bag from string s.

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 stripCharsNotInBag (s, bag)

{   var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is 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;
}


// Returns true if character c is an English letter 
function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}



// Returns true if character c is a digit 
// (0 .. 9).
function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}


// Returns true if character c is a letter or digit.
function isLetterOrDigit (c)
{   return (isLetter(c) || isDigit(c))
}


// isInteger (STRING s [, BOOLEAN emptyOK])
function isInteger (s)

{   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

// isSignedInteger (STRING s [, BOOLEAN emptyOK])
function isSignedInteger (s)

{   if (isEmpty(s)) 
       if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isSignedInteger.arguments[1] == true);

    else {
        var startPos = 0;
        var secondArg = defaultEmptyOK;

        if (isSignedInteger.arguments.length > 1)
            secondArg = isSignedInteger.arguments[1];

        // skip leading + or -
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
           startPos = 1;    
        return (isInteger(s.substring(startPos, s.length), secondArg))
    }
}

// isNonnegativeInteger (STRING s [, BOOLEAN emptyOK])
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, 10) >= 0) ) );
}

// isFloat (STRING s [, BOOLEAN emptyOK])
// 

function isFloat (s)

{   var i;
    var seenDecimalPoint = false;

    if (isEmpty(s)) 
       if (isFloat.arguments.length == 1) return defaultEmptyOK;
       else return (isFloat.arguments[1] == true);

    if (s == decimalPointDelimiter) return false;

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
        else if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

// isSignedFloat (STRING s [, BOOLEAN emptyOK])
// 
function isSignedFloat (s)

{   if (isEmpty(s)) 
       if (isSignedFloat.arguments.length == 1) return defaultEmptyOK;
       else return (isSignedFloat.arguments[1] == true);

    else {
        var startPos = 0;
        var secondArg = defaultEmptyOK;

        if (isSignedFloat.arguments.length > 1)
            secondArg = isSignedFloat.arguments[1];

        // skip leading + or -
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
           startPos = 1;    
        return (isFloat(s.substring(startPos, s.length), secondArg))
    }
}

// isIntegerInRange (STRING s, INTEGER a, INTEGER b [, BOOLEAN emptyOK])
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).
    var num = parseInt (s, 10);
    return ((num >= a) && (num <= b));
}

// isCheckbox(theField)
function isCheckbox(theField) {
	if (theField != undefined) {
		if (theField.length != undefined) {
			if (theField[0].type == "checkbox") return true;
		} else {
			if (theField.type == "checkbox") return true;
		}
	}
	return false;
}

// isSelect(theField)
function isSelect(theField) {
	if (theField == undefined) {
	} else {
		if (theField.type != undefined){
			if (theField.type.indexOf("select") != -1) return true;
		}
	}
	return false;
}

/* FUNCTIONS TO NOTIFY USER OF INPUT REQUIREMENTS OR MISTAKES. */


// Display prompt string s in status bar.

//function prompt (s)
//{   window.status = s
//}



// Display data entry prompt string s in status bar.

function promptEntry (s)
{   window.status = pEntryPrompt + s
}


function warnEmpty (theField, s)
{
	if(theField){
		if(theField.type != 'hidden')	{theField.focus()}
	}
	alert(mPrefix + s + mSuffix)
	return false
}


function warnInvalid (theField, s)
{   theField.focus()
    if (theField.type.search(/select/ig)== -1) theField.select()
    alert(s)
    return false
}

function confirmDelete(){
	if(confirm("Are you sure you want to delete this item?")){
		mintValidated = true
		return true
	} else {return false}
}

function confirmGridDelete(thisField){
	if(thisField.checked){
		thisField.checked = confirm("Are you sure you want to delete this item?")
	}
}

/* FUNCTIONS TO INTERACTIVELY CHECK VARIOUS FIELDS. */

// checkString (TEXTFIELD theField, STRING s, [, BOOLEAN emptyOK==false])

function fieldValue(theField)
{	var myValue="";
	var sComma = "";
	if (theField) {
		if (isCheckbox(theField)) {
			if (theField.length == undefined) {
				if (theField.checked) {
					myValue = theField.value;
				}
			} else {
				for (var i = 0; i < theField.length; i++) { 
						if (theField[i].checked)  {
							myValue = myValue + sComma + theField[i].value;
							sComma = ", ";
						}
				}
			}
		} else {
			if (isSelect(theField)){
				for (var i = 0; i < theField.options.length; i++) { 
					if (theField.options[i].selected)  {
						myValue = theField.options[i].value;
					}
				}
			    
			} else {
			    myValue = theField.value
			}
		}
	}
	return myValue;
}

function fieldText(theField)
{	var myValue="";
	var sComma = "";
	if (isCheckbox(theField)) {
		for (var i = 0; i < theField.length; i++) { 
				if (theField[i].checked)  {
					myValue = myValue + sComma + theField[i].text;
					sComma = ", ";
				}
		}
	} else {
		if (isSelect(theField)){
			for (var i = 0; i < theField.options.length; i++) { 
				if (theField.options[i].selected)  {
					myValue = theField.options[i].text;
				}
			}
		} else {
		    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
		    myValue = theField.value
		}
	}
	return myValue;
}

function checkString (theField, s, emptyOK, ignoreMissing)
{   // Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
    var myValue="";
	if (checkString.arguments.length == 2) emptyOK = defaultEmptyOK;
    if (ignoreMissing == true){
		if(theField){} else {return true};
    }
 	var sComma = "";
	myValue = fieldValue(theField)
	if ((emptyOK == true) && (isEmpty(myValue))) return true;
	
	if (isWhitespace(myValue)) {
		return warnEmpty (theField, s);
	} else {
		return true;
	}
}

// check for a checkbox

function checkCheckbox(theField, s, emptyOK){
    if (checkCheckbox.arguments.length == 2) emptyOK = defaultEmptyOK;
	if (theField.type == 'checkbox') {
		if(theField.checked == true) {myValue = theField.value}
	} 
	else {
		if (theField.length > 1) {
			if (theField[0].type == 'checkbox') {
				// checkbox
				var myValue="";
				for (var i = 0; i < theField.length; i++) { 
					if (theField[i].checked)  {
						myValue = theField[i].value;
					}
				}
			} else {
				// not a checkbox
				return true;
			}
		} else { return true; }
   }
   
   if (isWhitespace(myValue)) {
		alert('You did not select a ' + s + '. Please choose one now.');
		return false
   } else {
		return true;
   }
}


function fillCheckboxes(theField){

    if (theField.length > 1) {
		// checkbox
		var myValue="";
		for (var i = 0; i < theField.length; i++) { 
			theField[i].checked = true
		}
	} else {
		theField.checked = true
	}
}
function clearCheckboxes(theField){

    if (theField.length > 1) {
		// checkbox
		var myValue="";
		for (var i = 0; i < theField.length; i++) { 
			theField[i].checked = false
		}
	} else {
		theField.checked = false
	}
}

// checkLength

function checkLength(theField, intLength, strMsg){
	if (theField.value.length < intLength){
		warnInvalid(theField, strMsg);
		return (false);
	} else { return (true); }
}

// checkEmpty (TEXTFIELD theField, STRING s)

function checkEmpty (theField, s)
{  if (isEmpty(theField.value)) return true;
	    myValue = theField.value
   if (isWhitespace(myValue)) return true;
   return warnInvalid(theField, "The " + s + " field must be empty."); 
}

// checkInteger (TEXTFIELD theField, STRING s, [, BOOLEAN emptyOK==false])

function checkInteger (theField, s, emptyOK, ignoreMissing)
{ 	// strip any number characters ("$", ",")
	
		if (ignoreMissing){
			if(theField){} else {return true};
		}

	if (checkInteger.arguments.length==2) emptyOK = defaultEmptyOK;
	if ((emptyOK == true) && (isEmpty(theField.value))) return true;
	theField.value  = stripCharsInBag(theField.value, "$, ")
   	if (!isInteger(theField.value, emptyOK)){ 
		return warnInvalid(theField, "Please enter an integer in the " + s + " field");
	}
	else return true;

}

// checkFloat (TEXTFIELD theField, STRING s, [, BOOLEAN emptyOK==false])

function checkFloat (theField, s, emptyOK, ignoreMissing){

    if (ignoreMissing == true){
		if(theField){} else {return true};
    }
	if (checkFloat.arguments.length==2) emptyOK = defaultEmptyOK;
	if ((emptyOK == true) && (isEmpty(theField.value))) return true;
	if (isWhitespace(theField.value)) {
		return warnEmpty (theField, s);}
	var bFoundPercent = false
 	// check for % sign
	if(theField.value.indexOf("%") > 0) bFoundPercent = true
	
	var bFoundParens = false
 	// check for parentheses 
	if(theField.value.indexOf(")") > 0) bFoundParens = true
	
	// strip any number characters ("$", ",", "%", "(", ")")
	theField.value = stripCharsInBag(theField.value, "%$, )(")
   	if (!isSignedFloat(theField.value, true)){
		return warnInvalid(theField, "Please enter a number in the " + s + " field");
	}
	else {
		if (bFoundPercent) theField.value = parseFloat(theField.value)/100;
		if (bFoundParens) theField.value = -parseFloat(theField.value);
		return true;
	}
}

// checkPercent (TEXTFIELD theField, STRING s, [, BOOLEAN emptyOK==false])

function checkPercent (theField, s, emptyOK, ignoreMissing, numPercentLimit){
    if (ignoreMissing == true){
		if(theField){} else {return true};
    }

	if (checkPercent.arguments.length==2) emptyOK = defaultEmptyOK;
	if ((emptyOK == true) && (isEmpty(theField.value))) return true;
	if (isWhitespace(theField.value)) {
		return warnEmpty (theField, s);}
	
	var bFoundPercent = false
 	// check for % sign
	if(theField.value.indexOf("%") > 0) bFoundPercent = true
	
	var bFoundParens = false
 	// check for parentheses 
	if(theField.value.indexOf(")") > 0) bFoundParens = true
	
	// strip any number characters ("$", ",", "%", "(", ")")
	theField.value = stripCharsInBag(theField.value, "%$, )(")
   	if (!isSignedFloat(theField.value, true)){
		return warnInvalid(theField, "Please enter a number in the " + s + " field");
	}
	else {
		if (bFoundParens) theField.value = -parseFloat(theField.value);
		if (bFoundPercent) {
			theField.value = parseFloat(theField.value)/100;
		} else {
			if(theField.value > numPercentLimit) {
				theField.value = parseFloat(theField.value)/100;
			}
		}
		return true;
	}
}

var IMAGE_DELIMITER = "|";
var IMAGE_EXTENSIONS = ".gif|.jpg";	
function isImage(s){
	if (isEmpty(s)){
	if (isImage.arguments.length ==1) return defaultEmptyOK;
	else return (isImage.arguments[1] == true);
	}
	return ((IMAGE_EXTENSIONS.indexOf(s.substring(s.length-4, s.length).toLowerCase()) != -1) &&
		(s.indexOf(IMAGE_DELIMITER) == -1));
}

function checkImage (theField, emptyOK)
{   // Next line is needed on NN3 to avoid "undefined is not a number" error
// in equality comparison below.
	if (checkImage.arguments.length == 1) emptyOK = defaultEmptyOK;
	if ((emptyOK == true) && (isEmpty(theField.value))) return true;
	if (!isImage(theField.value)) 
		return warnInvalid(theField, "The file name must end in either '.gif' or '.jpg'.");
	else return true;
}

// isEmail (STRING s [, BOOLEAN emptyOK])
// 
// Email address must be of form a@b.c -- in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isEmail (s)
{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(s)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

// checkEmail (TEXTFIELD theField, [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid Email.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.



function checkEmail (theField, emptyOK, ignoreMissing)
{   

    if (ignoreMissing == true){
		if(theField){} else {return true};
    }

	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);
    else return true;
}

// checkPhone (TEXTFIELD theField, [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid phone number.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isPhone(s) {
	/* strip whitespace head & tail */
	var phoneTemp = stripCharsNotInBag(s, '0123456789');
	if ((phoneTemp.length > 6) && isInteger(phoneTemp) ){
		return phoneTemp	
	} else {
		return false 
	}
}

function checkPhone (theField, emptyOK, ignoreMissing)
{   
	
    if (ignoreMissing == true){
		if(theField){} else {return true};
    }

	if (checkPhone.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))){
		 return true;
	} else {
		var phoneTemp = isPhone(theField.value, false)
		if (!phoneTemp) {
			return warnInvalid (theField, iPhone);
		} else {
			if (phoneTemp.length == 10) {
				theField.value = '(' + phoneTemp.substring(0,3) + ') ' + phoneTemp.substring(3,6)+ '-' + phoneTemp.substring(6,10)
			} else {
				if ((phoneTemp.length == 11) && (phoneTemp.charAt(0) == '1')) {
				theField.value = '(' + phoneTemp.substring(1,4) + ') ' + phoneTemp.substring(4,7)+ '-' + phoneTemp.substring(7,11)
				}
			}
			return true;
		}
	}
}


// isYear (STRING s [, BOOLEAN emptyOK])
// 
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])
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])
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,10);
    var intMonth = parseInt(month, 10);
    var intDay = parseInt(day, 10);

    // catch invalid days, except for February
    if (intDay > daysInMonth[intMonth]) return false; 

    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;

    return true;
}

// checkDate (yearField, monthField, dayField, STRING labelString [, OKtoOmitDay==false])
//
// Check that yearField.value, monthField.value, and dayField.value 
// form a valid date.

function checkDate (theField, labelString, emptyOK, ignoreMissing)
{   // Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
    var varYear;
    var varMonth;
    var varDay;
    var intSlash1;
    var intSlash2;
    var myValue;
    
    if (ignoreMissing == true){
		if(theField){} else {return true};
    }

    if (checkDate.arguments.length == 2) emptyOK = defaultEmptyOK;

    myValue = fieldValue(theField)
	if ((emptyOK == true) && (isEmpty(myValue))) return true;
	if (isWhitespace(myValue)) {
		return warnEmpty (theField, labelString);
	} else {
		intSlash1 = myValue.indexOf("/");
		if (intSlash1 != -1 && intSlash1 < myValue.length){
			intSlash2 = myValue.indexOf("/",intSlash1+1)
			if (intSlash2 != -1 && intSlash2 < myValue.length){
				if (isDate(myValue.substring(intSlash2+1, myValue.length),myValue.substring(0,intSlash1), myValue.substring(intSlash1+1,intSlash2)))
					return true;
			}
		}
	}
	return warnInvalid(theField, "Please enter a date in the form '01/01/99' in the " + labelString + " field.");
    
}

// compareDates (strDate1, strDate2)
//
	// return negative resulte if strDate1 > strDate2
	// return 0 if equal
	// return positive result if strDate2 > strDate1
	// return null if one of the dates is not a date
function compareDates(strDate1, strDate2){
	var myDate1 = new Date(strDate1)
	var myDate2 = new Date(strDate2)

	if ((myDate1 == 'NaN') || (myDate2 == 'NaN')) return null
	if (myDate1.getFullYear() < 2000) myDate1.setFullYear (100 + myDate1.getFullYear())
	if (myDate2.getFullYear() < 2000) myDate2.setFullYear (100 + myDate2.getFullYear())
	return myDate2.valueOf() - myDate1.valueOf()
}

// getDateArray (strDate)
//
// Check strDate is a date 
// returns null is not a date, 
// returns an array of [0] full date, [1] day, [2] month, [3] year if a date

function getDateArray(strDate){
	// not perfect but not bad
	// assumes slashes
	myRe=/(^[0|1]?\d)\/([0|1|2|3]?\d)\/(\d{2}|19\d{2}|20\d{2})$/g;
	var myMatches =  myRe.exec(strDate);
	if (myMatches == null){
		// try dashes
		myRe=/(^[0|1]?\d)-([0|1|2|3]?\d)-(\d{2}|19\d{2}|20\d{2})$/g;
		myMatches =  myRe.exec(strDate);
	}
	return myMatches
}

// openLocation(strLocation)
// opens a URL in  a new window

function openLocation(strLocation){
		var newwin;
		newwin = window.open(strLocation, 'RWFMain', 'location=yes,menubar=yes,scrollbars=yes,status=yes,width=650,height=500,resizable=yes')	
	}

// deleteRow(strLocation)
// used by list.asp to delete a record in the edit.asp window
	
function deleteRow(numRecordID){
		if (confirm("Delete this record?")) {
			if(parent.edit){
				parent.edit.location = "edit.asp?RecordID=" + numRecordID + "&FormMode=Delete" 
			} else {
				document.location = document.location.pathname + "?RecordID=" + numRecordID + "&FormMode=Delete" 
			}
		}
	}


function deleteQuote(numQuoteID){ 
	var strhref = window.location.href
	var intFormmode = (strhref.toLowerCase().indexOf('formmode='))
	
	if (intFormmode != -1 ){
		strhref = strhref.replace(/(formmode=[^\&]*\&)|(formmode=[^\&]*$)/gi, 'FormMode=Delete')
		strhref = strhref.replace(/(QuoteID=[^\&]*\&)|(QuoteID=[^\&]*$)/gi, '')
		strhref = strhref + '&QuoteID='	+ numQuoteID
	} 	else {
		strhref = strhref + '?FormMode=Delete&QuoteID=' + numQuoteID  
	}
	if(confirmDelete()){ 
        window.location = strhref
    } else {  
        return void(0); 
    } 
}  

function getLocation(strLocation){
	window.location = strLocation
}

// used by rich text editor
function openEditor(strID) {
	var oTextArea = document.getElementById(strID);
	document.getElementById(strID + 'FieldDiv').style.display = '';
	
	var intRows = 10;
	var intCols = 0;
	if(oTextArea.rows){
		if(oTextArea.rows > 0){
			intRows = oTextArea.rows;
			intCols = oTextArea.cols;
		}
	}	
	var intWidth = 0
	if (intCols > 0){
		intWidth = intCols * 8
		oTextArea.style.width = intWidth + "pt";
	} else {
		oTextArea.style.width = "90%";
	}
	var intHeight =  70 + (intRows * 12);
	oTextArea.style.height = intHeight + "px";
	tinyMCE.execCommand('mceAddControl',false,strID);
	document.getElementById(strID + 'HTMLDiv').style.display = 'none';
	if(document.getElementById(strID + 'ActionOpenDiv1')) document.getElementById(strID + 'ActionOpenDiv1').style.display='none';
	if(document.getElementById(strID + 'ActionOpenDiv')) document.getElementById(strID + 'ActionOpenDiv').style.display='none';
	if(document.getElementById(strID + 'ActionCloseDiv')) document.getElementById(strID + 'ActionCloseDiv').style.display='';
	
}

function closeEditor(strID) {
	tinyMCE.execInstanceCommand(strID,'mceFocus',false,strID);
	var strValue = tinyMCE.getContent()
	if(hasHTML(strValue)){
		document.getElementById(strID + 'FieldDiv').style.display = 'none';	
		document.getElementById(strID + 'Span').innerHTML = strValue
		document.getElementById(strID + 'HTMLDiv').style.display = '';
	} 
	tinyMCE.execCommand('mceRemoveControl',false,strID);
		if(document.getElementById(strID + 'ActionOpenDiv1')) document.getElementById(strID + 'ActionOpenDiv1').style.display='';
	if(document.getElementById(strID + 'ActionOpenDiv')) document.getElementById(strID + 'ActionOpenDiv').style.display='';
	if(document.getElementById(strID + 'ActionCloseDiv')) document.getElementById(strID + 'ActionCloseDiv').style.display='none';
	
}

function hasHTML(strValue){
	var fHasHTML = false;
	if(!isEmpty(strValue)){
		if((strValue.indexOf("/>") != -1 ) || (strValue.indexOf("</") != -1 )){
			fHasHTML = true;
		}
	}
	return fHasHTML;
}

function Browser(){
	if (document) {
		this.dom = document.getElementById?1:0;
		this.ie4 = (document.all && !this.dom)?1:0;
		this.ie4or5 = (document.all)?1:0;
		this.ns4 = (document.layers && !this.dom)?1:0;
		this.ns4or5 = (document.layers)?1:0;
		this.ns5 = (document.layers && this.dom)?1:0;
		this.ns6 = (this.dom && !document.all)?1:0;
		this.ie5 = (this.dom && document.all)?1:0;
		this.ok = this.dom || this.ie4 || this.ns4;
		this.platform = navigator.platform;
	}
  }
function noError(){
	return true;
}
window.onerror = noError
var browser = new Browser();  
window.onerror = null;


