
/*
#####################################################
FORM VALIDATION
#####################################################
*/

var reTrim=/^\s*(.*)\s*$/;

/*
----------------------------------------------------------------------------
Function:       LTrim
Description:    Trims leading blanks
Input:          String
Returns:        Trimmed string

----------------------------------------------------------------------------
*/
function LTrim(str)
{
    var whitespace = new String(" \t\n\r");

    var s = new String(str);

    if (whitespace.indexOf(s.charAt(0)) != -1) {
        // We have a string with leading blank(s)...

        var j=0, i = s.length;

        // Iterate from the far left of string until we
        // don't have any more whitespace...
        while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
            j++;

        // Get the substring from the first non-whitespace
        // character to the end of the string...
        s = s.substring(j, i);
    }
    return s;
}

/*
----------------------------------------------------------------------------
Function:       RTrim
Description:    Trims trailing blanks
Input:          String
Returns:        Trimmed string

----------------------------------------------------------------------------
*/
function RTrim(str)
{
    // We don't want to trip JUST spaces, but also tabs,
    // line feeds, etc.  Add anything else you want to
    // "trim" here in Whitespace
    var whitespace = new String(" \t\n\r");
    
    var s = new String(str);
    
    if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
        // We have a string with trailing blank(s)...
    
        var i = s.length - 1;       // Get length of string
    
        // Iterate from the far right of string until we
        // don't have any more whitespace...
        while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
            i--;
    
    
        // Get the substring from the front of the string to
        // where the last non-whitespace character is...
        s = s.substring(0, i+1);
    }
    
   return s;
}

/*
----------------------------------------------------------------------------
Function:       Trim
Description:    Trims leading and trailing blanks
Input:          String
Returns:        Trimmed string

----------------------------------------------------------------------------
*/
function Trim(str)
{
    
   return RTrim(LTrim(str));
}

/*
----------------------------------------------------------------------------
Function:       isString
Description:    Validates a string
Input:          String or form object (including input tag with type attribute "text")
Returns:        true, if string satisfies validity contraints; false, otherwise

Contraints:
1) String must not be empty.

Examples:
A) isString("Hello") --> true
B) isString("") --> false
----------------------------------------------------------------------------
*/
function isString(obj) {
    var strData;

    if(typeof(obj) == "object") {
        strData = obj.value;    
    } else {
        strData = obj;  
    }

    // 1) Data existance
    if (strData != "" && strData.length > 0)
        return true
    else
        return false;
}

/*
----------------------------------------------------------------------------
Function:       isNumeric
Description:    Validates a string composed of digits which evaluates to a number
Input:          String or form object (including input tag with type attribute "text")
Returns:        true, if string satisfies validity contraints; false, otherwise
Requires:       validCharsFound()

Contraints:
1) String must not be empty.
2) Only valid characters can be used (0-9).

Examples:
A) isNumeric("123") --> true
B) isNumeric("Hello123") --> false
----------------------------------------------------------------------------
*/
function isNumeric(obj) {
    var strData;
    
    if(typeof(obj) == "object") {
        strData = obj.value;    
    } else {
        strData = obj;  
    }
    
    var strValidChars = "0123456789";

    // 1) Data existance
    if (strData != "" && strData.length > 0) {
        // 2) Characters used
        if (validCharsFound(strData, strValidChars))
            return true
        else
            return false;
    } else {
        return false;
    }
}

/*
----------------------------------------------------------------------------
Function:       isInteger
Description:    Validates a string that evaluates to an integer
Input:          String or form object (including input tag with type attribute "text")
Returns:        true, if string satisfies validity contraints; false, otherwise

Contraints:
1) String must not be empty.
2) String evaluates to an integer (positive or negative whole number, or zero; no "0" padding);
   Full string evaluates to a full integer equivalent.

Examples:
A) isInteger("123") --> true
B) isInteger("-123") --> true
C) isInteger("123.045") --> false
D) isInteger("0123") --> false
----------------------------------------------------------------------------
*/
function isInteger(obj) {
    var strData;

    // Extract data (via string or form object)
    if(typeof(obj) == "object") {
        strData = obj.value;    
    } else {
        strData = obj;  
    }

    // 1) Data existance
    if (strData != "" && strData.length > 0) {
        // 2) Full string evaluates to a full integer
        if (isNaN(parseInt(strData))) {
            return false
        } else {
            if (parseInt(strData).toString().length < strData.length)
                return false
            else
                return true;
        }
    } else {
        return false;
    }
}

/*
----------------------------------------------------------------------------
Function:       isNumber
Description:    Validates a string that evaluates to a number
Input:          String or form object (including input tag with type attribute "text")
Returns:        true, if string satisfies validity contraints; false, otherwise
Requires:       validCharsFound()

Contraints:
1) String must not be empty.
2) Integer portion of string evaluates to a number (positive or negative integer; no "0" padding).
3) Only valid characters can be used (0-9) - decimal portion of number, if present.

Examples:
A) isNumber("123") --> true
B) isNumber("-123") --> true
C) isNumber("123.045") --> true
D) isNumber("0123") --> false
----------------------------------------------------------------------------
*/
function isNumber(obj) {
    var strData;
    var strValidChars = "0123456789";
    var strIntPortion;
    var strDecPortion;

    // Extract data (via string or form object)
    if(typeof(obj) == "object") {
        strData = obj.value;    
    } else {
        strData = obj;  
    }
    // 1) Data existance
    if (strData != "" && strData.length > 0) {
        // 2) Full integer portion evaluates to a full number
        strIntPortion = strData.substring(0, strData.indexOf("."));
        if (isNaN(parseInt(strIntPortion))) {
            return false
        } else {
            if (parseInt(strIntPortion).toString().length < strIntPortion.length) {
                return false;
            } else {
                // 3) Characters used (decimal portion)
                strDecPortion = strData.substring(strData.indexOf(".") + 1, strData.length);
                if (validCharsFound(strDecPortion, strValidChars))
                    return true
                else
                    return false;
            }
        }
    } else {
        return false;
    }
}


/*
----------------------------------------------------------------------------
Function:       isDate
Description:    Validates a string that evaluates to a date
Input:          String or form object (including input tag with type attribute "text")
Returns:        true, if string satisfies validity contraints; false, otherwise
Requires:       validCharsFound()

Contraints:
1) String must not be empty.
2) Month and day components must be separated by "-" or "/"
3) Day and year components must be separated by "-" or "/"
4) Month and day components must be either 1 or 2 digits in length
   Year component must be either 2 or 4 digits in length
5) Month and day components are within valid ranges (month 1-12, day 1-31)

Examples:
A) isDate("2-8-00") --> true
C) isDate("12/18/2000") --> true
D) isDate("12 18 2000") --> false
----------------------------------------------------------------------------
*/
function isDate(obj) {
    var strData;
    var strValidChars = "0123456789"; // separators "-/"
    var strSepChar;
    var strMonth;
    var strDay;
    var strYear;
    var intMonth;
    var intDay;
    var intYear;
    

    // Extract data (via string or form object)
    if(typeof(obj) == "object") {
        strData = obj.value;    
    } else {
        strData = obj;  
    }

    // 1) Data existance
    if (strData != "" && strData.length > 0) {
        // Determine separator char
        if (strData.indexOf("-") > 0)
            strSepChar = "-"
        else
            strSepChar = "/";

        // 2) Month-Day separator
        if (strData.charAt(1) == strSepChar || strData.charAt(2) == strSepChar) {
            // 3) Day-Year separator
            if (strData.charAt(3) == strSepChar || strData.charAt(4) == strSepChar || strData.charAt(5) == strSepChar) {
                // 4) Month, day, and year lengths; digits only
                strMonth = strData.substring(0, strData.indexOf(strSepChar));
                if ((strMonth.length != 1 && strMonth.length != 2) || !validCharsFound(strMonth, strValidChars)) {
                    return false;
                } else {
                    if (strMonth.substring(0, 1) == 0) {
                        strMonth = strMonth.substring(1,2);
                    }
                }
                strDay = strData.substring(strData.indexOf(strSepChar) + 1, strData.lastIndexOf(strSepChar));
                if ((strDay.length != 1 && strDay.length != 2) || !validCharsFound(strDay, strValidChars)) {
                    return false;
                } else {
                    if (strDay.substring(0, 1) == 0) {
                        strDay = strDay.substring(1,2);
                    }
                }
                strYear = strData.substring(strData.lastIndexOf(strSepChar) + 1, strData.length);
                if ((strYear.length != 2 && strYear.length != 4) || !validCharsFound(strYear, strValidChars)) {
                    return false;
                }
               
                // 5) Month and day ranges
                intMonth = parseInt(strMonth);
                intDay = parseInt(strDay);
                intYear = parseInt(strYear);
               
                if (intMonth == 2) {    
                    if ( (Math.round(intYear / 4) / (intYear / 4)) == 1 ){
                        if (intDay > 29)
                            return false;                       
                    }else{
                        if (intDay > 28)
                            return false;                       
                    }
                }else{
                    if ((intMonth == 4) ||(intMonth == 6)||(intMonth == 9)||(intMonth == 11)) {
                        if (intDay > 30){
                            return false;
                        }
                    } else {
                        if (intDay > 31){
                            return false;
                        }
                    }
                }
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    } else {
        return false;
    }
}

/*
----------------------------------------------------------------------------
Function:       isDateByComponents
Description:    Validates a date type string from its individual components.
Inputs:         Month (string or form object);
                Day (string or form object);
                Year (string or form object)
Returns:        true, if all components have a selected option; false, otherwise
Requires:       isSelectedDropdown()

Examples:
A) isDateByComponents("05", "24", "2001") --> true
B) isDateByComponents("-1", "24", "2001", "") --> false
C) isDateByComponents("", "24", "2001", "") --> false
----------------------------------------------------------------------------
*/
function isDateByComponents(objMonth, objDay, objYear) {
    var strMonth;
    var strDay;
    var strYear;

    // Extract data (via string or form object)
    if (objMonth.length >= 0)
        strMonth = objMonth
    else
        strMonth = objMonth.value;
    if (objDay.length >= 0)
        strDay = objDay
    else
        strDay = objDay.value;
    if (objYear.length >= 0)
        strYear = objYear
    else
        strYear = objYear.value;

    // Data existance (month, day, and year)
    if (!isSelectedDropdown(strMonth)) {
        return false;
    } else {
        if (!isSelectedDropdown(strDay)) {
            return false;
        } else {
            if (!isSelectedDropdown(strYear)) {
                return false;
            } else {
                return true;
            }
        }
    }
}

/*
----------------------------------------------------------------------------
Function:       isDateByComponentsUnselected
Description:    Checks to see if a series of drop-down selection list boxes
                that represent the individual components of a date type string
                are all unselected.
Inputs:         Month (string or form object);
                Day (string or form object);
                Year (string or form object)
Returns:        true, if the component strings are unselected; false, otherwise
Requires:       isSelectedDropdown()

Examples:
A) isDateByComponentsUnselected("", "", "") --> true
B) isDateByComponentsUnselected("05", "24", "2001") --> false
----------------------------------------------------------------------------
*/
function isDateByComponentsUnselected(objMonth, objDay, objYear) {
    var strMonth;
    var strDay;
    var strYear;

    // Extract data (via string or form object)
    if (objMonth.length >= 0)
        strMonth = objMonth
    else
        strMonth = objMonth.value;
    if (objDay.length >= 0)
        strDay = objDay
    else
        strDay = objDay.value;
    if (objYear.length >= 0)
        strYear = objYear
    else
        strYear = objYear.value;

    // Data existance (month, day, and year)
    if (!isSelectedDropdown(strMonth) && !isSelectedDropdown(strDay) && !isSelectedDropdown(strYear))
        return true
    else
        return false;
}

/*
----------------------------------------------------------------------------
Function:       isURL
Description:    Validates a URL address (does not actively validate, i.e. via pinging)
Input:          String or form object (including input tag with type attribute "text")
Returns:        true, if string satisfies validity contraints; false, otherwise
Requires:       validCharsFound()

Contraints:
1) String must not be empty.
2) Only valid characters can be used (a-z, A-Z, 0-9, or _-.:/#?*$=&).
3) A valid prefix must be present ("http://", "https://", or "ftp://").
4) At least one "." character must exist within the domain (<http prefix><domain and path>);
   Domain must not start or end with a "." character.

Examples:
A) isURL("http://www.abc.com") --> true
B) isURL("www.abc.com") --> false
----------------------------------------------------------------------------
*/
function isURL(obj) {
    var strData;
    var strValidChars = "abcdefghijklmnopqrstuvwxyz0123456789_-.:/#?*$=&%";
    var strDomainNameAndPath;

    // Extract data (via string or form object)
    if (obj.length >= 0)
        strData = obj.toLowerCase()
    else
        strData = obj.value.toLowerCase();

    // 1) Data existance
    if (strData != "" && strData.length > 0) {
        // 2) Characters used
        if (validCharsFound(strData, strValidChars)) {
            // 3) Prefix
            if (strData.substring(0,7) != "http://" && strData.substring(0,8) != "https://" && strData.substring(0,6) != "ftp://") {
                return false;
            }
            // 4) Domain and path
            strDomainNameAndPath = strData.substring(strData.indexOf("//") + 2, strData.length);
            if (strDomainNameAndPath.indexOf(".") == -1 || strDomainNameAndPath.charAt(0) == "." || strDomainNameAndPath.charAt(strDomainNameAndPath.length - 1) == ".") {
                return false;
            }
            return true;
        } else {
            return false;
        }
    } else {
        return false;
    }
}

/*
-------------------------------------------------------------------
Function:       compareDates(date1,date1format,date2,date2format)
Description:    Compare two date strings to see which is greater.
Input:          date1,date1format,date2,date2format - All String Objects
Returns:
                1 if date1 is greater than date2
                0 if date2 is greater than date1 of if they are the same
                -1 if either of the dates is in an invalid format
Examples:
A)  compareDates("1/5/2004","M/d/yyyy","1/6/2004","M/d/yyyy"
 -------------------------------------------------------------------
*/
function compareDates(date1,dateformat1,date2,dateformat2) {
        var d1=getDateFromFormat(date1,dateformat1);
        var d2=getDateFromFormat(date2,dateformat2);
        if (d1==0 || d2==0) {
                return -1;
                }
        else if (d1 > d2) {
                return 1;
                }
        return 0;
        }

/* 
---------------------------------------------------------------------
Function: LZ(date_part)
Description: Returns a date part padded with leading zeros.
---------------------------------------------------------------------
*/
function LZ(x) {return(x<0||x>9?"":"0")+x}

/*
---------------------------------------------------------------------
Function: formatDate (date_object, format)
Returns:  Returns a date in the output format specified.
Note:     The format string uses the same abbreviations as in getDateFromFormat()
---------------------------------------------------------------------
*/
function formatDate(date,format) {
        var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
        var DAY_NAMES=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat');

        format=format+"";
        var result="";
        var i_format=0;
        var c="";
        var token="";
        var y=date.getYear()+"";
        var M=date.getMonth()+1;
        var d=date.getDate();
        var E=date.getDay();
        var H=date.getHours();
        var m=date.getMinutes();
        var s=date.getSeconds();
        var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
        // Convert real date parts into formatted versions
        var value=new Object();
        if (y.length < 4) {y=""+(y-0+1900);}
        value["y"]=""+y;
        value["yyyy"]=y;
        value["yy"]=y.substring(2,4);
        value["M"]=M;
        value["MM"]=LZ(M);
        value["MMM"]=MONTH_NAMES[M-1];
        value["NNN"]=MONTH_NAMES[M+11];
        value["d"]=d;
        value["dd"]=LZ(d);
        value["E"]=DAY_NAMES[E+7];
        value["EE"]=DAY_NAMES[E];
        value["H"]=H;
        value["HH"]=LZ(H);
        if (H==0){value["h"]=12;}
        else if (H>12){value["h"]=H-12;}
        else {value["h"]=H;}
        value["hh"]=LZ(value["h"]);
        if (H>11){value["K"]=H-12;} else {value["K"]=H;}
        value["k"]=H+1;
        value["KK"]=LZ(value["K"]);
        value["kk"]=LZ(value["k"]);
        if (H > 11) { value["a"]="PM"; }
        else { value["a"]="AM"; }
        value["m"]=m;
        value["mm"]=LZ(m);
        value["s"]=s;
        value["ss"]=LZ(s);
        while (i_format < format.length) {
                c=format.charAt(i_format);
                token="";
                while ((format.charAt(i_format)==c) && (i_format < format.length)) {
                        token += format.charAt(i_format++);
                        }
                if (value[token] != null) { result=result + value[token]; }
                else { result=result + token; }
                }
        return result;
        }
        
/*
---------------------------------------------------------------------
Function: dayDiff (p_date1, p_date2)
Returns:  Returns the number of days between p_date1 and p_date2
---------------------------------------------------------------------
*/        

function dayDiff(p_Date1, p_Date2){
        var dt1 = new Date(p_Date1);
        var dt2 = new Date(p_Date2);

        // Get milliseconds between dates (UTC) and make into "difference" date
        var iDiffMS = dt2.valueOf() - dt1.valueOf();
        var dtDiff = new Date(iDiffMS);

        // Calculate differences
        var nMilliseconds = iDiffMS;
        var nSeconds = parseInt(iDiffMS/1000);
        var nMinutes = parseInt(nSeconds/60);
        var nHours = parseInt(nMinutes/60);
        var nDays  = parseInt(nHours/24);
        
        return nDays;
}        

/*
----------------------------------------------------------------------------
Function:       isEmail
Description:    Validates an email address (does not actively validate, i.e. user by domain)
Input:          String or form object (including input tag with type attribute "text")
Returns:        true, if string satisfies validity contraints; false, otherwise
Requires:       validCharsFound()

Contraints:
1) String must not be empty.
2) Only valid characters can be used (a-z, A-Z, 0-9, or _-.@).
3) One "@" character and at least one "." character must exist;
   A "." character must exist within the domain (<user>@<domain>);
   The "@" character must preceed the domain "." character.
4) User and domain must not be empty, and the domain must be at least 3 characters in length;
   User and domain must not start or end with a "." character.

Examples:
A) isEmail("test@abc.com") --> true
B) isEmail("test") --> false
----------------------------------------------------------------------------
*/
/*
function isEmail(obj) {
    var strData;
    var strValidChars = "abcdefghijklmnopqrstuvwxyz0123456789_-.@'";
    var strUserName;
    var strDomainName;

    // Extract data (via string or form object)
    if (obj.value.length >= 0)
        strData = obj.value.toLowerCase();

    // 1) Data existance
    if (strData != "" && strData.length > 0) {
        // 2) Characters used
        if (validCharsFound(strData, strValidChars)) {
            // 3) Inclusion and placement of "@" and "." characters
            if (strData.indexOf("@") == -1 || strData.indexOf("@") >= strData.lastIndexOf(".")) {
                return false;
            }
            // 4) User and domain
            strUserName = strData.substring(0, strData.indexOf("@"));
            strDomainName = strData.substring(strData.indexOf("@") + 1, strData.length);
            if (strUserName == "" || strUserName.length == 0 || strDomainName == "" || strDomainName.length < 3) {
                return false;
            }
            if (strUserName.charAt(0) == "." || strUserName.charAt(strUserName.length - 1) == "."  || strDomainName.charAt(0) == "." || strDomainName.charAt(strDomainName.length - 1) == ".") {
                return false;
            }
            return true;
        } else {
            return false;
        }
    } else {
        return false;
    }
}
*/
function isEmail(obj) {
	var str = obj.value;
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);

	if (str.indexOf(at)==-1){
	   return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false;
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		return false;
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false;
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		return false;
	 }
	
	 if (str.indexOf(" ")!=-1){
		return false;
	 }

	 return true;			
}

/*
----------------------------------------------------------------------------
Function:       isEmailMultiple
Description:    Validates an email address or more than one email address
                (does not actively validate, i.e. user by domain)
Input:          String or form object (including input tag with type attribute "text")
Returns:        true, if string satisfies validity contraints; false, otherwise
Requires:       validCharsFound()

Contraints:
1) String must not be empty.
2) Only valid characters can be used (a-z, A-Z, 0-9, or _-.@).
3) One "@" character and at least one "." character must exist per address;
   A "." character must exist within the domain (<user>@<domain>) of each address;
   The "@" character must preceed the domain "." character in each address.
4) User and domain must not be empty, and the domain must be at least 3 characters in length;
   User and domain must not start or end with a "." character.

Examples:
A) isEmailMultiple("test@abc.com") --> true
B) isEmailMultiple("test") --> false
----------------------------------------------------------------------------
*/
function isEmailMultiple(obj) {
    var strData;
    var strValidChars = "abcdefghijklmnopqrstuvwxyz0123456789_-.@;'";
    var strUserName;
    var strDomainName;

    // Extract data (via string or form object)
    if (obj.value.length >= 0)
        strData = obj.value.toLowerCase();
    
    var tempStrData = "";
    for (j=0; j<strData.length; j++) {
        if(strData.charAt(j) != " ") {
            tempStrData = tempStrData + strData.charAt(j);
        }   
    }
    strData = tempStrData;

    // 1) Data existance
    if (strData != "" && strData.length > 0) {
        //if there is no ";" in the string, put one at the end
        if(strData.charAt(strData.length - 1) != ";") {
            var fullString = strData + ";";
        } else {
            var fullString = strData;
        }
        
        varStart = 0;
        for (i=0; i<fullString.length; i++) {
            if (fullString.substring(i, i+1) == ";") {
                strTemp = fullString.substring(varStart, i);
                varStart = i + 1;
            
                // 2) Characters used
                if (validCharsFound(strTemp, strValidChars)) {
                    // 3) Inclusion and placement of "@" and "." characters
                    if (strTemp.indexOf("@") == -1 || strTemp.indexOf("@") >= strTemp.lastIndexOf(".")) {
                        return false;
                    }
                    // 4) User and domain
                    strUserName = strTemp.substring(0, strTemp.indexOf("@"));
                    strDomainName = strTemp.substring(strTemp.indexOf("@") + 1, strTemp.length);
                    if (strUserName == "" || strUserName.length == 0 || strDomainName == "" || strDomainName.length < 3) {
                        return false;
                    }
                    if (strUserName.charAt(0) == "." || strUserName.charAt(strUserName.length - 1) == "."  || strDomainName.charAt(0) == "." || strDomainName.charAt(strDomainName.length - 1) == ".") {
                        return false;
                    }
                    if (fullString.length == i + 1) {
                        return true;
                    } 
                } else {
                    return false;
                }
            }
        }
    } else {
        return false;
    }
}



/*
----------------------------------------------------------------------------
Function:       isZipCode
Description:    Validates a US zip code
Input:          String or form object (including input tag with type attribute "text")
Returns:        true, if string satisfies validity contraints; false, otherwise
Requires:       validCharsFound()

Contraints:
1) String must not be empty.
2) String must be 5 digits or 10 characters (5 digits, a dash "-", and 4 digits).
3) Only valid characters can be used (0-9 or -).

Examples:
A) isZipCode("12345") --> true
B) isZipCode("12345-6789") --> true
C) isZipCode("123456789") --> false
----------------------------------------------------------------------------
*/
function isZipCode(obj) {
    var strData;
    var strValidChars = "0123456789"; // optional "-"

    // Extract data (via string or form object)
    if (obj.length >= 0)
        strData = obj
    else
        strData = obj.value;

    // 1) Data existance
    if (strData != "" && strData.length > 0) {
        // 2) String length (5 or 10)
        if (strData.length == 5) {
            // 3) Characters used
            if (validCharsFound(strData, strValidChars))
                return true
            else
                return false;
        } else if (strData.length == 10) {
            if (strData.charAt(5) != "-") {
                return false;
            } else {
                // 3) Characters used
                if (validCharsFound(strData, strValidChars & "-"))
                    return true
                else
                    return false;
            }
        }
        return false;       
    } else {
        return false;
    }
}

/*


----------------------------------------------------------------------------
Function:       isPhoneByComponents
Description:    Validates a phone type string (telephone, fax, cellular,
                pager, etc.) from its individual components.
Inputs:         Area Code (string or form object);
                Prefix (string or form object);
                Suffix (string or form object);
                Extension (string or form object)
Returns:        true, if the component strings satisfy the validity contraints; false, otherwise
Requires:       validCharsFound()

Contraints:
1) Area code, prefix, and suffix strings must not be empty.
2) Area code must be 3 digits, prefix 3 digits, and suffix 4 digits
3) Only valid characters can be used (0-9).
4) If an extension is provided, it must also contain valid characters.

Examples:
A) isPhoneByComponents("123", "456", "7890", "1234") --> true
B) isPhoneByComponents("123", "456", "7890", "") --> true
C) isPhoneByComponents("", "456", "7890", "") --> false
D) isPhoneByComponents("123", "", "7890", "") --> false
----------------------------------------------------------------------------
*/
function isPhoneByComponents(objAC, objPrefix, objSuffix, objExt) {
    var strAC;
    var strPrefix;
    var strSuffix;
    var strExt;
    var strValidChars = "0123456789";

    // Extract data (via string or form object)
    if (objAC.value.length >= 0)
        strAC = objAC.value;
        
    if (objPrefix.value.length >= 0)
        strPrefix = objPrefix.value;
        
    if (objSuffix.value.length >= 0)
        strSuffix = objSuffix.value;
        
    if (objExt.value.length >= 0)
        strExt = objExt.value;

    // 1) Data existance (area code, prefix, and suffix)
    if ((strAC != "" && strAC.length > 0) && (strPrefix != "" && strPrefix.length > 0) && (strSuffix != "" && strSuffix.length > 0)) {
        // 2) String lengths
        if (strAC.length == 3 && strPrefix.length == 3 && strSuffix.length == 4) {      
            // 3) Characters used
            // Area code
            if (validCharsFound(strAC, strValidChars)) {
                // Prefix
                if (validCharsFound(strPrefix, strValidChars)) {
                    // Suffix
                    if (validCharsFound(strSuffix, strValidChars)) {
                        // 4) Extension
                        if (strExt != "" && strExt.length > 0) {
                            if (validCharsFound(strExt, strValidChars)) {
                                return true
                            } else {
                                return false;
                            }
                        }
                        return true;
                    } else {
                        return false;
                    }
                } else {
                    return false;
                }
            } else {
                return false;
            }
        } else {
            return false;
        }
    } else {
        return false;
    }
}

/*
----------------------------------------------------------------------------
Function:       isPhoneByComponentsEmpty
Description:    Checks to see if a series of input boxes that represent
                individual components of a phone type string (telephone, fax,
                cellular, pager, etc.) are all empty.
Inputs:         Area Code (string or form object);
                Prefix (string or form object);
                Suffix (string or form object);
                Extension (string or form object)
Returns:        true, if the component strings are empty; false, otherwise

Examples:
A) isPhoneByComponentsEmpty("", "", "", "") --> true
B) isPhoneByComponentsEmpty("123", "456", "7890", "") --> false
----------------------------------------------------------------------------
*/
function isPhoneByComponentsEmpty(objAC, objPrefix, objSuffix, objExt) {
    var strAC;
    var strPrefix;
    var strSuffix;
    var strExt;

    // Extract data (via string or form object)
    if (objAC.length >= 0)
        strAC = objAC
    else
        strAC = objAC.value;
    if (objPrefix.length >= 0)
        strPrefix = objPrefix
    else
        strPrefix = objPrefix.value;
    if (objSuffix.length >= 0)
        strSuffix = objSuffix
    else
        strSuffix = objSuffix.value;
    if (objExt.length >= 0)
        strExt = objExt
    else
        strExt = objExt.value;

    // Data existance (area code, prefix, suffix, and extension)
    if ((strAC == "" && strAC.length == 0) && (strPrefix == "" && strPrefix.length == 0) && (strSuffix == "" && strSuffix.length == 0) && (strExt == "" && strExt.length == 0))
        return true
    else
        return false;
}

/*
----------------------------------------------------------------------------
Function:       isSelectedDropdown
Description:    Validates a drop-down selection list box
Input:          String or form object (includes select tag)
Returns:        true, if string (selected item) satisfies validity contraints; false, otherwise
Requires:       isInteger()
Contraints:
1) String must not be empty.
2) String must not evaluate to a reserved default value (<= 0), i.e. -1 ("-- Select One --")

Examples:
A) isSelectedDropdown("123") --> true
B) isSelectedDropdown("-1") --> false
----------------------------------------------------------------------------
*/
function isSelectedDropdown(obj) {
    var strData;

    // Extract data (via string or form object)
    if (!obj.options) {
        strData = obj;
    } else {
        if (obj.selectedIndex <= 0) {
            // no options exist
            return false;
        } else {
            strData = obj.options[obj.selectedIndex].value;
        }
    }

    // 1) Data existance
    if (strData == "" || strData.length == 0)
        return false;
    // 2) Selected item is not a default item
    if (isInteger(strData))
        if (strData == -1)
            return false;

    return true;
}

/*
Function:       isSelectedDropdownNoSelectOneOption
Description:        Validates a drop-down selection list box that DOES NOT have
            a "Select One" option
Input:          String or form object (includes select tag)
Returns:        true, if string (selected item) satisfies validity contraints; false, otherwise
Requires:       isInteger()
Contraints:
1) String must not be empty.

Examples:
A) isSelectedDropdown("123") --> true
B) isSelectedDropdown("-1") --> false
----------------------------------------------------------------------------
*/
function isSelectedDropdownNoSelectOneOption(obj) {
    var strData;

    // Extract data (via string or form object)
    if (!obj.options) {
        strData = obj;
    } else {
        if (obj.selectedIndex < 0) {
            // no options exist
            return false;
        } else {
            strData = obj.options[obj.selectedIndex].value;
        }
    }

    // 1) Data existance
    if (strData == "" || strData.length == 0)
        return false;
    // 2) Selected item is not a default item
    if (isInteger(strData))
        if (strData == -1)
            return false;

    return true;
}

/*
----------------------------------------------------------------------------
Function:       isSelectedDropdownNoSelectOneOption
Description:        Validates a drop-down selection list box that DOES NOT have
            a "Select One" option
Input:          String or form object (includes select tag)
Returns:        true, if string (selected item) satisfies validity contraints; false, otherwise
Requires:       isInteger()
Contraints:
1) String must not be empty.

Examples:
A) isSelectedDropdown("123") --> true
B) isSelectedDropdown("-1") --> false
----------------------------------------------------------------------------
*/
function isSelectedDropdownNoSelectOneOption(obj) {
    var strData;

    // Extract data (via string or form object)
    if (!obj.options) {
        strData = obj;
    } else {
        if (obj.selectedIndex < 0) {
            // no options exist
            return false;
        } else {
            strData = obj.options[obj.selectedIndex].value;
        }
    }

    // 1) Data existance
    if (strData == "" || strData.length == 0)
        return false;
    // 2) Selected item is not a default item
    if (isInteger(strData))
        if (strData == -1)
            return false;

    return true;
}



/*
----------------------------------------------------------------------------
Function:       isIssue
Description:    Validates a custom Issue identifier
Input:          String or form object (including input tag with type attribute "text")
Returns:        true, if string satisfies validity contraints; false, otherwise
Requires:       validCharsFound()

Contraints:
1) String must not be empty.
2) Only valid characters can be used (0-9, or -).
3) SeriesNumber-IssueNumber separator (dash) must exist.
4) SeriesNumber, IssueNumber, and WorkOrderNumber components must be valid
   (digits (0-9) and length <= 10).

Valid Issue Formats:
1) Service Requests:    SeriesNumber-IssueNumber (xxxx-xxxx)
2) Work Orders:         SeriesNumber-IssueNumber-WorkOrderNumber (xxxx-xxxx-xxxx)

Examples:
A) isIssue("123-45") --> true
B) isIssue("123-0") --> false
C) isIssue("123-45667-6789676") --> true
D) isIssue("123 45 6789") --> false
E) isIssue("123456789") --> false
----------------------------------------------------------------------------
*/
function isIssue(obj) {
    var objForm = document.forms[0];
    var strData;
    var strValidChars = "0123456789-";
    var i;
    var intPosDash1;
    var intPosDash2;
    var intSeriesNumber = -1;
    var intIssueNumber = -1;
    var intWorkOrderNumber = -1;

    // Extract data (via string or form object)
    if (obj.length >= 0)
        strData = obj
    else
        strData = obj.value;

    // 1) Data existance
    if (strData != "" && strData.length > 0) {
        // 2) Characters used
        if (validCharsFound(strData, strValidChars)) {
            // 3) SeriesNumber-IssueNumber separator
            intPosDash1 = strData.indexOf("-");
            if (intPosDash1 == -1)
                return false;

            // IssueNumber-WorkOrderNumber separator
            intPosDash2 = strData.substring(intPosDash1 + 1, strData.length).indexOf("-");
            if (intPosDash2 != -1)
                intPosDash2 = intPosDash2 + intPosDash1 + 1;

            // Determine SeriesNumber, IssueNumber, and WorkOrderNumber
            if (intPosDash1 == -1) {
                intSeriesNumber = strData;
            } else {
                intSeriesNumber = strData.substring(0, intPosDash1);
                if (intPosDash2 == -1) {
                    intIssueNumber  = strData.substring(intPosDash1 + 1, strData.length);
                    intWorkOrderNumber = -1
                } else {
                    intIssueNumber = strData.substring(intPosDash1 + 1, intPosDash2);
                    intWorkOrderNumber = strData.substring(intPosDash2 + 1, strData.length);
                }
            }

            // 4) Validate SeriesNumber, IssueNumber, and WorkOrderNumber
            if (intSeriesNumber != -1)
                if (!isNumeric(intSeriesNumber) || parseInt(intSeriesNumber) == 0 || intSeriesNumber.length > 10)
                    return false;
            if (intIssueNumber != -1)
                if (!isNumeric(intIssueNumber) || parseInt(intIssueNumber) == 0 || intIssueNumber.length > 10)
                    return false;
            if (intWorkOrderNumber != -1)
                if (!isNumeric(intWorkOrderNumber) || parseInt(intWorkOrderNumber) == 0 || intWorkOrderNumber.length > 10)
                    return false;

            return true;
        } else {
            return false;
        }
    } else {
        return false;
    }
}

/*
----------------------------------------------------------------------------
Function:       isAccountName
Description:    Validates an account name making sure it doesn't contain spaces.
                Note that most other special chars are allowed.
Input:          String or form object (including input tag with type attribute "text")
Returns:        true, if string satisfies validity contraints; false, otherwise
Requires:       validCharsFound()

Contraints:
1) String must not be empty.
2) Only valid characters can be used (a-z, A-Z, 0-9, ~!@#$%^&*()_+-={}|[]\:;<>?,./)

Examples:
A) isAccountName("jeff2001") --> true
B) isAccountName("jeff 2001") --> false
----------------------------------------------------------------------------
*/
function isAccountName(obj) {
    var strData;
    var strValidChars = "abcdefghijklmnopqrstuvwxyz0123456789~!'@#$%^&*()_+-={}|[]\:;<>?,./";

    // Extract data (via string or form object)
    if (obj.length >= 0)
        strData = obj.toLowerCase()
    else
        strData = obj.value.toLowerCase();

    // 1) Data existence
    if (strData != "" && strData.length > 0) {
        // 2) Characters used
        if (validCharsFound(strData, strValidChars))
            return true
        else
            return false;
    } else {
        return false;
    }
}

/*
----------------------------------------------------------------------------
Function:       validCharsFound
Description:    Validates a given string based on a given string of valid
                characters; Leveraged by all validation functions.
Inputs:         Data (string);
                Valid characters (string)
Returns:        true, if the data string contains valid characters; false, otherwise

Examples:
A) validCharsFound("Hello123", "abcdefghijklmnopqrstuvwxyz0123456789") --> true
B) validCharsFound("Hello123", "0123456789") --> false
----------------------------------------------------------------------------
*/
function validCharsFound(strData, strValidChars) {
    var i;

    // Data existence
    if ((strData != "" && strData.length > 0) && (strValidChars != "" && strValidChars.length > 0)) {
        // Character validity
        for (i=0; i < strData.length; i++) {
            if (strValidChars.indexOf(strData.charAt(i)) == -1)
                return false;
        }
        return true;
    } else {
        return false;
    }
}

/*
----------------------------------------------------------------------------
Function:       addErrorMsgToErrorList
Description:    Accumulates form validation error messages within a global string
Input:          String
Returns:        Nothing
----------------------------------------------------------------------------
*/
function addErrorMsgToErrorList(strErrorMsg) {
    // Set "Please provide:" if this is the first error message
    if (cv_strErrorList == "") {
        cv_strErrorList = "\nPlease provide:\n";
    }
    // Append error message
    cv_strErrorList = cv_strErrorList + "* " + strErrorMsg + "\n";
}

// 
/*
----------------------------------------------------------------------------
Function:       checkKeyForDigits
Description:    Validates field input in real-time for digits
Inputs:         None
Returns:        Nothing

Example:
A) checkKeyForDigits(this.value)
----------------------------------------------------------------------------
*/
function checkKeyForDigits(strValue) {
    var intKeyCode = strValue.charCodeAt(strValue.length-1);
    if(intKeyCode < 48 | intKeyCode > 57) {
        alert("Please enter only digits in this box.");
    }
}


/*
#####################################################
FORM PROCESSING
#####################################################
*/

/*
----------------------------------------------------------------------------
Function:       selectAllItems
Description:    Selects all items within a list box
Input:          Object (select)
Returns:        Nothing

Example:
A) selectAllItems(document.forms[0].selApprovedUsers)
----------------------------------------------------------------------------
*/
function selectAllItems(obj) {
    var i;

    for (i=0; i < obj.length; i++) {
        obj.options[i].selected = true;
    }
}

/*
----------------------------------------------------------------------------
Function:       moveSelectedItems
Description:    Moves selected items from one list box to another
Inputs:         From object (select);
                To object (select)
Returns:        Nothing

Example:
A) moveSelectedItems(document.forms[0].selAvailableUsers, document.forms[0].selSelectedUsers)
----------------------------------------------------------------------------
*/
function moveSelectedItems(objFrom, objTo) {
    for(var i=0; i<objFrom.options.length; i++) {
        if(objFrom.options[i].selected) {
            objTo.options[objTo.options.length] = new Option(objFrom.options[i].text, objFrom.options[i].value);
            objFrom.options[i] = null;
            i--;
        }
    }
}

/*
----------------------------------------------------------------------------
Function:       moveAllItems
Description:    Moves all items from one list box to another
Inputs:         From object (select);
                To object (select);
Returns:        Nothing

Example:
A) moveAllItems(document.forms[0].selAvailableUsers, document.forms[0].selSelectedUsers)
----------------------------------------------------------------------------
*/
function moveAllItems(objFrom, objTo) {
    for(var i=0; i<objFrom.options.length; i++) {
        objTo.options[objTo.options.length] = new Option(objFrom.options[i].text, objFrom.options[i].value);
    }
    objFrom.options.length = 0;
}

/*
----------------------------------------------------------------------------
Function:       inputField
Description:    Returns a reference to a form element (IE and Netscape), so its
                value can be changed, its focus can be set, or anything else.
Inputs:         Form name (string);
                Element name (string)
Returns:        Object (form element)
----------------------------------------------------------------------------
*/
function inputField(strFormName, strElementName) {
    var objFormElement;
    var i;

    // find the form and set a reference to it
    if (document.all) {
        objFormElement = document.forms[strFormName];
    } else if (document.layers) {
        if (document.layers.length > 0) {
            for (i=0; i < document.layers.length; i++) {
                if (document.layers[i].document.forms[strFormName]) {
                    objFormElement = document.layers[i].document.forms[strFormName];
                    break;
                }
            }
        } else {
            objFormElement = document.forms[strFormName];
        }
    }

    // return reference to form element object
    return objFormElement.elements[strElementName];
}

/*
----------------------------------------------------------------------------
Function:       popModalDialog
Description:    opens a Modal Dialog box
Input:          file name (string), window width (integer), window height (integer)
Returns:        Nothing
Note:           For some odd reason, popModalDialog strips off the URL encoding for ampersands, 
                so I added another one in the calling script and then replaced them both 
                specifically with the correct coding (%26).  JAH 1/20/05
----------------------------------------------------------------------------
*/
function popModalDialog(strFileName, intWidth, intHeight) {
    strFileName = strFileName.replace(/&&/g, "%26");
    if(document.all) {
        var intScreenX = window.screenLeft + (document.body.offsetWidth/2) - (intWidth/2);
        var intScreenY = window.screenTop + (document.body.offsetHeight/2) - (intHeight/2);
        modalDialog = window.open(strFileName,"modalDialog","width=" + intWidth + ",height=" + intHeight + ",left=" + intScreenX + ",top=" + intScreenY);
        isPopup = true;
        //window.onfocus = focusPopup;
        modalDialog.focus();
    } else {
        var intScreenX = window.screenX + (document.width/2) - (intWidth/2);
        var intScreenY = window.screenY + (document.height/2) - (intHeight/2);
        modalDialog = window.open(strFileName,"modalDialog","width=" + intWidth + ",height=" + intHeight + ",screenX=" + intScreenX + ",screenY=" + intScreenY);
        modalDialog.onblur = modalDialog.focus;
    }
}

//function focusPopup() {
//    if(isPopup) {
//        modalDialog.focus();
//    }
//}

/*
----------------------------------------------------------------------------
Function:       popModalDialogAlternateXYCoordinates
Description:    opens a Modal Dialog box with a different variation of X and Y axis coordinates
                (works better for larger popup windows)
Input:          file name (string), window width (integer), window height (integer), X axis adjustment (int), Y axis adjustment (int)
Returns:        Nothing
----------------------------------------------------------------------------
*/
function popModalDialogAlternateXYCoordinates(strFileName, intWidth, intHeight, intX, intY) {
    if(document.all) {
        var intScreenX = window.screenLeft + intX;
        var intScreenY = window.screenTop + intY;
        modalDialog = window.open(strFileName,"modalDialog","width=" + intWidth + ",height=" + intHeight + ",left=" + intScreenX + ",top=" + intScreenY);
        isPopup = true;
        //window.onfocus = focusPopup;
        modalDialog.focus();
    } else {
        var intScreenX = window.screenX + intX;
        var intScreenY = window.screenY + intY;
        modalDialog = window.open(strFileName,"modalDialog","width=" + intWidth + ",height=" + intHeight + ",screenX=" + intScreenX + ",screenY=" + intScreenY);
        modalDialog.onblur = modalDialog.focus;
    }
}




/*
----------------------------------------------------------------------------
Function:       popScrollableModalDialog
Description:    opens a Modal Dialog box that is scrollable
Input:          file name (string), window width (integer), window height (integer)
Returns:        Nothing
----------------------------------------------------------------------------
*/
function popScrollableModalDialog(strFileName, intWidth, intHeight) {
    if(document.all) {
        var intScreenX = window.screenLeft + (document.body.offsetWidth/2) - (intWidth/2);
        var intScreenY = window.screenTop + (document.body.offsetHeight/2) - (intHeight/2);
        modalDialog = window.open(strFileName,"modalDialog","width=" + intWidth + ",height=" + intHeight + ",left=100"  + ",top=100" + ", scrollbars");
        isPopup = true;
        //window.onfocus = focusPopup;
        modalDialog.focus();
    } else {
        var intScreenX = window.screenX + (document.width/2) - (intWidth/2);
        var intScreenY = window.screenY + (document.height/2) - (intHeight/2);
        modalDialog = window.open(strFileName,"modalDialog","width=" + intWidth + ",height=" + intHeight + ",screenX=100" +  ",screenY=100" + ", scrollbars");
        modalDialog.onblur = modalDialog.focus;
    }
}


/*
----------------------------------------------------------------------------
Function:       popScrollableModalDialogAlternateXYCoordinates
Description:    opens a Modal Dialog box that is scrollable with a different variation of X and Y axis coordinates
                (works better for larger popup windows)
Input:          file name (string), window width (integer), window height (integer), X axis adjustment (int), Y axis adjustment (int)
Returns:        Nothing
----------------------------------------------------------------------------
*/
function popScrollableModalDialogAlternateXYCoordinates(strFileName, intWidth, intHeight, intX, intY) {
    if(document.all) {
        var intScreenX = window.screenLeft + intX;
        var intScreenY = window.screenTop + intY;
        modalDialog = window.open(strFileName,"modalDialog","width=" + intWidth + ",height=" + intHeight + ",left=" + intScreenX + ",top=" + intScreenY + ", scrollbars");
        isPopup = true;
        //window.onfocus = focusPopup;
        modalDialog.focus();
    } else {
        var intScreenX = window.screenX + intX;
        var intScreenY = window.screenY + intY;
        modalDialog = window.open(strFileName,"modalDialog","width=" + intWidth + ",height=" + intHeight + ",screenX=" + intScreenX + ",screenY=" + intScreenY + ", scrollbars");
        modalDialog.onblur = modalDialog.focus;
    }
}


/*
----------------------------------------------------------------------------
Function:       popResizableModalDialog
Description:    opens a dialog box that is resizable
Input:          file name (string), window width (integer), window height (integer)
Returns:        Nothing
----------------------------------------------------------------------------
*/
function popResizableModalDialog(strFileName, intWidth, intHeight) {
    if(document.all) {
        var intScreenX = window.screenLeft + (document.body.offsetWidth/2) - (intWidth/2);
        var intScreenY = window.screenTop + (document.body.offsetHeight/2) - (intHeight/2);
        modalDialog = window.open(strFileName,"modalDialog","width=" + intWidth + ",height=" + intHeight + ",left=" + intScreenX + ",top=" + intScreenY + ", scrollbars, resizable");
        isPopup = true;
        //window.onfocus = focusPopup;
        modalDialog.focus();
    } else {
        var intScreenX = window.screenX + (document.width/2) - (intWidth/2);
        var intScreenY = window.screenY + (document.height/2) - (intHeight/2);
        modalDialog = window.open(strFileName,"modalDialog","width=" + intWidth + ",height=" + intHeight + ",screenX=" + intScreenX + ",screenY=" + intScreenY + ", scrollbars, resizable");
        modalDialog.onblur = modalDialog.focus;
    }
}

function focusPopup() {
    if(isPopup) {
        modalDialog.focus();
    }
}




/*
----------------------------------------------------------------------------
Function:       popModalPrint
Description:    opens a Modal Dialog box
Input:          file name (string), window width (integer), window height (integer)
Returns:        Nothing
----------------------------------------------------------------------------
*/
function popModalPrint(strFileName, intWidth, intHeight) {
    if(document.all) {
        var intScreenX = window.screenLeft + (document.body.offsetWidth/2) - (intWidth/2);
        var intScreenY = window.screenTop + (document.body.offsetHeight/2) - (intHeight/2);
        window.open(strFileName,"modalDialog","width=" + intWidth + ",height=" + intHeight + ",left=" + intScreenX + ",top=" + intScreenY + ", menubar, toolbar, scrollbars");
    } else {
        var intScreenX = window.screenX + (document.width/2) - (intWidth/2);
        var intScreenY = window.screenY + (document.height/2) - (intHeight/2);
        window.open(strFileName,"modalDialog","width=" + intWidth + ",height=" + intHeight + ",screenX=" + intScreenX + ",screenY=" + intScreenY + ", menubar, toolbar, scrollbars");
    }
}



/*
----------------------------------------------------------------------------
Function:       popNonModalDialog
Description:    opens a non modal dialog box
Input:          url, width, height, scrollbars?, resizable?
Returns:        Nothing
----------------------------------------------------------------------------
*/
function popNonModalDialog(strFileName, intWidth, intHeight, strScrollbars, strResizable) {
    if(document.all) {
        var intScreenX = window.screenLeft + (document.body.offsetWidth/2) - (intWidth/2);
        var intScreenY = window.screenTop + (document.body.offsetHeight/2) - (intHeight/2);
        if (strScrollbars == 'yes') {
            strScrollbars = 'scrollbars=yes,';
        }
        else {
            strScrollbars = 'scrollbars=no,';
        }
        if (strResizable == 'yes') {
            strResizable = 'resizable=yes,';
        }
        else {
            strResizable = 'resizable=no,';
        }
        window.open(strFileName,'modalDialog',strScrollbars + strResizable + 'width=' + intWidth + ',height=' + intHeight + ',left=' + intScreenX + ',top=' + intScreenY);
    } else {
        var intScreenX = window.screenX + (document.width/2) - (intWidth/2);
        var intScreenY = window.screenY + (document.height/2) - (intHeight/2);
        if (strScrollbars == 'yes') {
            strScrollbars = 'scrollbars=yes,';
        }
        else {
            strScrollbars = 'scrollbars=no,';
        }
        if (strResizable == 'yes') {
            strResizable = 'resizable=yes,';
        }
        else {
            strResizable = 'resizable=no,';
        }
        modalDialog = window.open(strFileName,'modalDialog',strScrollbars + strResizable + 'width=' + intWidth + ',height=' + intHeight + ',screenX=' + intScreenX + ',screenY=' + intScreenY);
        modalDialog.onblur = modalDialog.focus;
    }
}




/*
----------------------------------------------------------------------------
Function:       launchHelp
Description:    opens a new window
Input:          url
Returns:        Nothing
----------------------------------------------------------------------------
*/

function launchHelp(url) {
    help = window.open(url,"ol_train","toolbars=yes,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=400,height=500,left=0,top=0");
}


/*
----------------------------------------------------------------------------
Function:       textCounter
Description:        keeps running tally of length based on onkeyup and onkeydown 
            and presents an alert box once maximum is reached
Input:          field and maxLimit
Returns:        character count
Example of call:    onKeyDown="textCounter(this,12);" onKeyUp="textCounter(this,12);"
----------------------------------------------------------------------------
*/

function textCounter(field, maxlimit) {
    if (field.value.length > maxlimit) {
        field.value = field.value.substring(0, maxlimit);
        alert("You've reached the character limit of " + maxlimit);
    }
}



/*
----------------------------------------------------------------------------
Function:       hideHourglassDIV
Description:    Hide DIV containing clock animated gif
Input:          None
Returns:        Nothing
Example of call:    onLoad="javascript:hideHourglassDIV();"
----------------------------------------------------------------------------
*/

function hideHourglassDIV() {
    if (document.all) { // IE4,5,6
        document.all.hourglass.style.display = 'none';
    } else if (document.getElementById) { // NS6
        document.getElementById('hourglass').style.display = 'none'
    } else if (document.layers) { // NS4
        document.hourglass.visibility = "hide"
    }
}  


/*
----------------------------------------------------------------------------
Function:           createMaintenanceTaskRecurrenceDescription
Description:        Concatenate string to display on add/edit Maintenance Task form
Input:              patternType;
                    isInfiniteRecurrence;
                    occurrencesTotal;
                    endDateTime;
                    recurrencePeriod;
                    ordinalDay;
                    dayOfMonth;
                    recurrenceWeeks;
                    recurrenceMonths;
                    daysOfWeek;
                    monthsOfYear;
Returns:            string
Example of call:    onLoad="javascript:createMaintenanceTaskRecurrenceDescription();"
----------------------------------------------------------------------------
*/

function createMaintenanceTaskRecurrenceDescription(patternType, startDate, isInfiniteRecurrence, occurrencesTotal, endDate, recurrencePeriod, ordinalDay, dayOfMonth, recurrenceWeeks, recurrenceMonths, daysOfWeek, monthsOfYear) {
    var strBuild = "";
    switch (patternType) {
        case '9': //non recurring
            strBuild = strBuild + "Occurs on " + startDate;
            break;
        case '10': //daily 1
            strBuild = strBuild + "Occurs every " + recurrencePeriod + " day(s) ";
            break;
        case '11': //daily 2
            strBuild = strBuild + "Occurs every weekday";
            break;
        case '12': //weekly 1
            strBuild = strBuild + "Occurs every " + recurrenceWeeks + " week(s) on " + daysOfWeek;
            break;
        case '13': //monthly 1
            strBuild = strBuild + "Occurs day " + dayOfMonth + " of every " + recurrenceMonths + " months(s)";
            break;
        case '14': //monthly 2
            strBuild = strBuild + "Occurs the " + ordinalDay + " " + daysOfWeek + " of every " + recurrenceMonths + " month(s)";
            break;
        
        case '17': //monthly 3
            strBuild = strBuild + "Occurs day " + dayOfMonth + " of every " + monthsOfYear;
            break;
        case '18': //monthly 4
            strBuild = strBuild + "Occurs the " + ordinalDay + " " + daysOfWeek + " of every " + monthsOfYear;
            break;
        
        case '15': //yearly 1
            strBuild = strBuild + "Occurs every " + monthsOfYear + " " + dayOfMonth;
            break;
        case '16': //yearly 2
            strBuild = strBuild + "Occurs the " + ordinalDay + " " + daysOfWeek + " of " + monthsOfYear;
            break;
        default:
            return "ERROR in javascript function";
            break;          
    }
    
    // add on start date value for all pattern types except non-recurring
    if (patternType != 9) {
        strBuild = strBuild + " for task effective " + startDate;
        // handle endDate or fixed occurrence number
        if (endDate != "") {
            strBuild = strBuild + " until " + endDate;
        } else {
            if (occurrencesTotal != "-1") {
                strBuild = strBuild + " for " + occurrencesTotal + " occurrences";
            }
        }
    }
    return strBuild;
}  





/*
----------------------------------------------------------------------------
Function:           parseDaysOfWeekValue
Description:        Extract a list of names of days of weeks from 7 character string
Input:              daysOfWeek;
Returns:            string
Example of call:    parseDaysOfWeekValue(<%=chrDaysOfWeek%>);
----------------------------------------------------------------------------
*/

function parseDaysOfWeekValue(daysOfWeekValue) {
    var objForm = document.forms[0];
    var strDaysOfWeek = "";
    switch (daysOfWeekValue) {
        case '2222222':
            strDaysOfWeek = 'day';
            break;
        case '3333333':
            strDaysOfWeek = "weekday";
            break;
        case '4444444':
            strDaysOfWeek = "weekend day";
            break;
        default:
            //loop through 0s and 1s of daysOfWeekValue passed in
            var t = 0;
            for (var m = 0; m < daysOfWeekValue.length; m++) {
                if (daysOfWeekValue.slice(m,m+1) == 1) {
                    t = t + 1;
                }
            }
                
            var m = 0;
            for (var k = 0; k < daysOfWeekValue.length; k++) {
                if (daysOfWeekValue.slice(k,k+1) == 1) {
                    switch (k) {
                        case 0:
                            strDaysOfWeek = strDaysOfWeek + "Sunday";
                            m = m + 1;
                            break;
                        case 1:
                            strDaysOfWeek = strDaysOfWeek + "Monday";
                            m = m + 1;
                            break;
                        case 2:
                            strDaysOfWeek = strDaysOfWeek + "Tuesday";
                            m = m + 1;
                            break;
                        case 3:
                            strDaysOfWeek = strDaysOfWeek + "Wednesday";
                            m = m + 1;
                            break;
                        case 4:
                            strDaysOfWeek = strDaysOfWeek + "Thursday";
                            m = m + 1;
                            break;
                        case 5:
                            strDaysOfWeek = strDaysOfWeek + "Friday";
                            m = m + 1;
                            break;
                        case 6:
                            strDaysOfWeek = strDaysOfWeek + "Saturday";
                            m = m + 1;
                            break;
                        default:
                            alert('error12');
                            break;
                    }
                    if (eval(t) - eval(m) == 1) {
                        strDaysOfWeek = strDaysOfWeek + " and ";
                    } else {
                        if (eval(t) - eval(m) != 0) {
                            strDaysOfWeek = strDaysOfWeek + ", ";
                        }
                    }
                }
                    
            }
            break;
    }
    return strDaysOfWeek;
}


/*
----------------------------------------------------------------------------
Function:           parseMonthsOfYearValue
Description:        Extract a list of names of days of weeks from 12 character string
Input:              monthsOfYear;
Returns:            string
Example of call:    parseMonthsOfYearValue(<%=chrMonthsOfYear%>);
----------------------------------------------------------------------------
*/

function parseMonthsOfYearValue(monthsOfYearValue) {
    var objForm = document.forms[0];
    var strMonthsOfYear = "";
    //loop through 0s and 1s of monthsOfYearValue passed in
    var t = 0;
    for (var m = 0; m < monthsOfYearValue.length; m++) {
        if (monthsOfYearValue.slice(m,m+1) == 1) {
            t = t + 1;
        }
    }
                
    var m = 0;
    for (var k = 0; k < monthsOfYearValue.length; k++) {
        if (monthsOfYearValue.slice(k,k+1) == 1) {
            switch (k) {
                case 0:
                    strMonthsOfYear = strMonthsOfYear + "January";
                    m = m + 1;
                    break;
                case 1:
                    strMonthsOfYear = strMonthsOfYear + "February";
                    m = m + 1;
                    break;
                case 2:
                    strMonthsOfYear = strMonthsOfYear + "March";
                    m = m + 1;
                    break;
                case 3:
                    strMonthsOfYear = strMonthsOfYear + "April";
                    m = m + 1;
                    break;
                case 4:
                    strMonthsOfYear = strMonthsOfYear + "May";
                    m = m + 1;
                    break;
                case 5:
                    strMonthsOfYear = strMonthsOfYear + "June";
                    m = m + 1;
                    break;
                case 6:
                    strMonthsOfYear = strMonthsOfYear + "July";
                    m = m + 1;
                    break;
                case 7:
                    strMonthsOfYear = strMonthsOfYear + "August";
                    m = m + 1;
                    break;
                case 8:
                    strMonthsOfYear = strMonthsOfYear + "September";
                    m = m + 1;
                    break;
                case 9:
                    strMonthsOfYear = strMonthsOfYear + "October";
                    m = m + 1;
                    break;
                case 10:
                    strMonthsOfYear = strMonthsOfYear + "November";
                    m = m + 1;
                    break;
                case 11:
                    strMonthsOfYear = strMonthsOfYear + "December";
                    m = m + 1;
                    break;
                default:
                    alert('error12');
                    break;
            }
            if (eval(t) - eval(m) == 1) {
                strMonthsOfYear = strMonthsOfYear + " and ";
            } else {
                if (eval(t) - eval(m) != 0) {
                    strMonthsOfYear = strMonthsOfYear + ", ";
                }
            }
        }
    }
    return strMonthsOfYear;
}

/*
----------------------------------------------------------------------------
Function:           suggestSpecialRequestTime
Description:        Used by Service Request & WorkOrder to get the closest 
		    15 minute increment of time
Input:              None
Returns:            String
Example of call:    suggestSpecialRequestTime();
----------------------------------------------------------------------------
*/
function suggestSpecialRequestTime() {
	var returnDate;
	var increment;
	var minutes;
	var i;
	var newDate = new Date();
	
	for (i=1;i<=4;i++) {
		increment = 15 * i;
		if (newDate.getMinutes() + 10 <= increment) {
			if (increment == 60) {
				returnDate = (newDate.getMonth() + 1) + '/' + newDate.getDate() + '/' + newDate.getFullYear() + ' ' + (newDate.getHours() + 1) + ':00'; 
				break;
			}
			else {
				returnDate = (newDate.getMonth() + 1) + '/' + newDate.getDate() + '/' + newDate.getFullYear() + ' ' + newDate.getHours() + ':' + increment; 
				break;
			}			
		}
		if (newDate.getMinutes() + 10 > 60) {
			returnDate = (newDate.getMonth() + 1) + '/' + newDate.getDate() + '/' + newDate.getFullYear() + ' ' + (newDate.getHours() + 1) + ':15'; 			
			break;			
		}
	}	
	returnDate = new Date(returnDate);
	if (returnDate.getMinutes() < 10)
		minutes = '0' + returnDate.getMinutes();
	else
		minutes = returnDate.getMinutes();
		
	if (returnDate.getHours() > 12) {
		returnDate.setHours(returnDate.getHours() - 12);
		returnDate = returnDate.getHours() + ':' + minutes + ' PM';
	}
	else if (returnDate.getHours() == 12)
		returnDate = returnDate.getHours() + ':' + minutes + ' PM';
	else
		returnDate = returnDate.getHours() + ':' + minutes + ' AM';

	return(returnDate); 
}

