///////////////////////////////////////////////////////////////////////////////
//
// IntToChar
//
//   Return "char" value for the given int.  (Note: A - z only)
//
///////////////////////////////////////////////////////////////////////////////

var CharArray = new Array(
    "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T",
    "U","V","W","X","Y","Z","","","","","","",
    "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t",
    "u","v","w","x","y","z");

function IntToChar(intValue)
{
    if (intValue < 65 || intValue > 122)
        return "";

    var adjIntValue = intValue - 65;
    return CharArray[adjIntValue];
}

///////////////////////////////////////////////////////////////////////////////
//
// SetValidationIcon  (Set the icon used to display validation errors)
//
///////////////////////////////////////////////////////////////////////////////
var validateIconImg = '';
var validateIconImgOn = '';
var validateIconHTML = '<span style="color:Red">*</span>';

function SetValidationIcon(iconImg, iconImgOn)
{
    validateIconImg = iconImg;
    validateIconImgOn = iconImgOn;
    validateIconHTML = '<img name="validateIcon" src="' + iconImg + '" alt="Click for more information" border="0" onmouseover="this.src=\'' + iconImgOn + '\'" onmouseout="this.src=\'' + iconImg + '\'" align="absmiddle"/>';
}

function ResetValidationIcon()
{
    var imgs = document.getElementsByTagName('img');
    for (var i = 0; i < imgs.length; i++)
    {
        if (imgs[i].name == "validateIcon")
            imgs[i].src = validateIconImg;
    }
}

///////////////////////////////////////////////////////////////////////////////
//
// IsZipcode: check if valid US zip code (##### or #####-####)
//
///////////////////////////////////////////////////////////////////////////////

function IsZipcode(strZip)
{
    var strLeft="", strRight="", strVal = new String(strZip);

    if (IsEmpty(strVal))
        return true;
    if (IsWhitespace(strVal))
        return false;

    if (strVal.length != 5 && strVal.length != 10)
        return false;

    if ((strVal.length == 5) && IsDigit(strVal))
        return true;

    if ((strVal.length == 10) && IsDigit(strVal.substring(0, 5)) && IsDigit(strVal.substring(6)))
        return true;

    return false;
}

///////////////////////////////////////////////////////////////////////////////
//
// IsDatePart: check if nVal is valid day: 1-31, month:1-12, year:YYYY
//
///////////////////////////////////////////////////////////////////////////////

function IsDatePart(nVal, strType)
{
    var strBuffer = new String(nVal);

    if (IsEmpty(strBuffer) || IsWhitespace(strBuffer))
        return false;

    nVal = parseInt(strBuffer);
    if (!IsDigit(nVal))
        return false;

    if ((strType == "Year") && (nVal < 0 || (nVal > 99 && nVal < 1000) || nVal > 9999))
        return false;
    else if ((strType == "Month") && (nVal < 1 || nVal > 12))
        return false;
    else if ((strType == "Day") && (nVal < 1 || nVal > 31))
        return false;

    return true;
}

///////////////////////////////////////////////////////////////////////////////
//
// ValidDate
//
// Check if object is a valid date
//
// Valid formats:  MM (or) M / DD (or) D / Y (or) YY (or) YYYY
//                 YY > 40 should be 19YY
//                 YY <= 40 should be 20YY
// 
// Input:          obj     - form object
//                 minDate - Minimum date (MM/DD/YYYY)
//
// Return:         true / false
//                 change obj.value to (MM/DD/YYYY) if it is valid, otherwise
//                 clear obj.value
//
///////////////////////////////////////////////////////////////////////////////

function ValidDate(obj,minDate)
{
    obj.value = RemoveSpaces(obj.value);
    var strBuffer= new String(obj.value);
    var cDelimiter='';
    var strMonth=0, strDay=0, strYear=0;
    var nPos=-1;

    if (IsEmpty(strBuffer))
        return true;
    if (IsWhitespace(strBuffer))
        return false;

    // Get the delimiter used
    if (Occurs('/', strBuffer) == 2)
        cDelimiter = '/';
    else if (Occurs('-', strBuffer) == 2)
        cDelimiter = '-';

    // If no '/' or '-' found return false
    if (cDelimiter == '')
        return false;

    // validate month, date, and year (Y, YY, YYYY are valid year formats)
    nPos = strBuffer.indexOf(cDelimiter);
    strMonth = strBuffer.substring(0, nPos);
    if (strMonth.length > 2 || !IsDigit(strMonth))
        return false;

    strBuffer = strBuffer.substring(nPos+1);
    nPos = strBuffer.indexOf(cDelimiter);
    strDay = strBuffer.substring(0, nPos);
    if (strDay.length > 2 || !IsDigit(strDay))
        return false;

    strBuffer = strBuffer.substring(nPos+1);
    strYear = strBuffer;
    if ((strYear.length > 4) || (strYear.length == 3) || !IsDigit(strYear))
        return false;

    // if YY < 40 then YYYY=20YY, else if YY >= 40 then YYYY=19YY
    var iYear = parseInt(strYear,10);
    if (iYear < 40)
        strYear = "20" + (iYear < 10 ? '0' + iYear:iYear);
    else if (iYear >= 40 && iYear < 100)
        strYear = "19" + strYear;

    // Pad month if less than 10
    var iMon = parseInt(strMonth,10);
    strMonth = (iMon < 10 ? '0' + iMon:iMon);

    // Pad days if less than 10
    var iDay = parseInt(strDay,10);
    strDay = (iDay < 10 ? '0' + iDay:iDay);

    strBuffer = strMonth + '/' + strDay + '/' + strYear;

    // validate date
    var dBuffer = new Date(strBuffer);
    if (dBuffer.getDate() != parseInt(strDay,10) ||
        dBuffer.getMonth()+1 != parseInt(strMonth,10) ||
        dBuffer.getFullYear() != parseInt(strYear,10))
        return false;

    // Check to see if the date is before the minimum date if one is specified
    if (minDate != null && minDate != '')
    {
        var minStrBuffer= new String(minDate);

        // validate month, date, and year (Y, YY, YYYY are valid year formats)
        nPos = minStrBuffer.indexOf('/');
        minStrMonth = minStrBuffer.substring(0, nPos);

        minStrBuffer = minStrBuffer.substring(nPos+1);
        nPos = minStrBuffer.indexOf('/');
        minStrDay = minStrBuffer.substring(0,nPos);

        minStrBuffer = minStrBuffer.substring(nPos+1);
        minStrYear = minStrBuffer;

        if ( strYear < minStrYear )
            return false;
        else if (strYear == minStrYear)
        {
            if (strMonth < minStrMonth)
                return false;
            else if (strMonth == minStrMonth)
            {
                if (strDay < minStrDay)
                  return false;
            }
        }
    }

    obj.value = strBuffer;
    return true;
}

///////////////////////////////////////////////////////////////////////////////
//
// ValidDay
//
// Check if given day is valid based on the year and month provided
//
// Valid formats:  DD (or) D
//                 MM (or) M 
//                 Y (or) YY (or) YYYY
//                 YY > 40 should be 19YY
//                 YY <= 40 should be 20YY
// 
// Input:          day, month, year
//
// Return:         true / false
//                 change dayObj.value to (DD) if it is valid, otherwise
//                 clear value
//
///////////////////////////////////////////////////////////////////////////////

function ValidDay(dayObj, month, year)
{
    dayObj.value = RemoveSpaces(dayObj.value);
    var strDay= new String(dayObj.value);

    if (IsEmpty(strDay))
        return true;
    if (IsWhitespace(strDay))
        return false;

    var strMonth = new String(month);
    if (strMonth.length > 2 || !IsDigit(strMonth))
        return false;

    var strYear = new String(year);
    if ((strYear.length > 4) || (strYear.length == 3) || !IsDigit(strYear))
        return false;

    // if YY < 40 then YYYY=20YY, else if YY >= 40 then YYYY=19YY
    var iYear = parseInt(strYear,10);
    if (iYear < 40)
        strYear = "20" + (iYear < 10 ? '0' + iYear:iYear);
    else if (iYear >= 40 && iYear < 100)
        strYear = "19" + strYear;

    // Pad month if less than 10
    var iMon = parseInt(strMonth,10);
    strMonth = (iMon < 10 ? '0' + iMon:iMon);

    // Pad days if less than 10
    var iDay = parseInt(strDay,10);
    strDay = (iDay < 10 ? '0' + iDay:iDay);

    var strBuffer = strMonth + '/' + strDay + '/' + strYear;

    // validate date
    var dBuffer = new Date(strBuffer);
    if (dBuffer.getDate() != parseInt(strDay,10) ||
        dBuffer.getMonth()+1 != parseInt(strMonth,10) ||
        dBuffer.getFullYear() != parseInt(strYear,10))
        return false;

    dayObj.value = strDay;
    return true;
}

///////////////////////////////////////////////////////////////////////////////
//
// ValidateDate
//
// Check if object is a valid date. If it is not, then display icon
//
// Parameters:  objField    - Input field object
//              errorMsgId  - Object that contains the error message to display
//
///////////////////////////////////////////////////////////////////////////////

function ValidateDate(objField,errorMsgId)
{
    if (IsEmpty(objField.value))
        return true;
        
    if (!ValidDate(objField,''))
        return TurnOnValidateIcon(objField.id, errorMsgId);
    else
        return TurnOffValidateIcon(objField.id);
}

///////////////////////////////////////////////////////////////////////////////
//
// ValidateDay
//
// Check if object is a valid day based on the given month and year
//
// Parameters:  objField    - Input field object
//              errorMsgId  - Object that contains the error message to display
//
///////////////////////////////////////////////////////////////////////////////

function ValidateDay(objField,month,year,errorMsgId)
{
    if (IsEmpty(objField.value))
        return true;
        
    if (!ValidDay(objField,month,year))
        return TurnOnValidateIcon(objField.id, errorMsgId);
    else
        return TurnOffValidateIcon(objField.id);
}

///////////////////////////////////////////////////////////////////////////////
//
// ValidateField
//
// NOTE: 
//  -- always RemoveSpaces field value before calling any of these functions
//  -- if field is empty, the function call will return true
//
// Parameters:  objField   - Input field reference
//              errorMsgId - Object that contains the error message to display
//              strType    - "Digit" | "Integer" | "Float" | "Zip" | "DatePartYear"
//
///////////////////////////////////////////////////////////////////////////////

function ValidateField(objField, errorMsgId, strType)
{
    objField.value = RemoveSpaces(objField.value);
    if (IsEmpty(objField.value))
        return true;

    // Remove commas from Integer and Float fields
    if ((strType == "Integer") || (strType == "Float"))
        objField.value = ReplaceAll(objField.value, ",", "");

    if (strType == "Digit")
    {
        if (!IsDigit(objField.value))
            return TurnOnValidateIcon(objField.id, errorMsgId);
        else
            return TurnOffValidateIcon(objField.id);
    }

    if (strType == "Integer")
    {
        if (!IsInteger(parseInt(objField.value)))
            return TurnOnValidateIcon(objField.id, errorMsgId);
        else
        {
            objField.value = parseInt(objField.value);
            return TurnOffValidateIcon(objField.id);
        }
    }

    if (strType == "Float")
    {
        if (!IsFloat(parseFloat(objField.value)))
            return TurnOnValidateIcon(objField.id, errorMsgId);
        else
        {
            objField.value = parseFloat(objField.value);
            return TurnOffValidateIcon(objField.id);
        }
    }

    if (strType == "Zip")
    {
        if (!IsZipcode(objField.value))
            return TurnOnValidateIcon(objField.id, errorMsgId);
        else
            return TurnOffValidateIcon(objField.id);
    }

    if (strType == "DatePartYear")
    {
        if (!IsDigit(objField.value) || !IsDatePart(objField.value, "Year"))
            return TurnOnValidateIcon(objField.id, errorMsgId);
        else if (objField.value < 100)
        {
            objField.value = (objField.value < 50 ? 2000:1900) + parseInt(objField.value);
            return TurnOffValidateIcon(objField.id);
        }
    }
}

///////////////////////////////////////////////////////////////////////////////
//
// ValidateRange
//
// Check the range of the field value.
//
// Parameters:  objField   - Input field reference
//              errorMsgId - Object that contains the error message to display
//              fLower     - Inclusive lower boundary
//              fUpper     - Inclusive upper boundary
//              numType    - "Integer" | "Float"
//
///////////////////////////////////////////////////////////////////////////////

function ValidateRange(objField, errorMsgId, fLower, fUpper, numType)
{
    var fVal = 0;
    if (IsEmpty(objField.value))
        return true;

    var isValid = false;
    fVal = (numType == "Integer")? parseInt(objField.value) : parseFloat(objField.value);

    if ((fVal >= fLower) && (fVal <= fUpper))
        isValid = true;

    if (fLower == fUpper)
        isValid = false;
    else if (fUpper < fLower)
        isValid = false;
        
    if (!isValid)
        return TurnOnValidateIcon(objField.id, errorMsgId);
    else
    {
        objField.value = (numType == "Integer")? parseInt(objField.value) : parseFloat(objField.value);
        return TurnOffValidateIcon(objField.id);
    }
}

///////////////////////////////////////////////////////////////////////////////
//
// ValidateMinValue
//
//   Check to see if the field value is greater than the minimum value
//
// Parameters:  objField   - Input field reference
//              errorMsgId - Object that contains the error message to display
//              minVal     - Minimum value
//              numType    - "Integer" | "Float"
//
///////////////////////////////////////////////////////////////////////////////

function ValidateMinValue(objField, errorMsgId, minVal, numType)
{
    var fVal = 0;
    if (IsEmpty(objField.value))
        return true;
        
    var isValid = false;
    fVal = (numType == "Integer")? parseInt(objField.value) : parseFloat(objField.value);
    
    if (fVal >= minVal)
        isValid = true;

    if (!isValid)
        return TurnOnValidateIcon(objField.id, errorMsgId);
    else
    {
        objField.value = (numType == "Integer")? parseInt(objField.value) : parseFloat(objField.value);
        return TurnOffValidateIcon(objField.id);
    }
}

///////////////////////////////////////////////////////////////////////////////
//
// ValidateLength
//
// Check the length of the field value.
//
// Parameters:  objField - Input field reference
//              errorMsgId - Object that contains the error message to display
//              minLength - Min length
//              maxLength - Max length
//
///////////////////////////////////////////////////////////////////////////////

function ValidateLength(objField, errorMsgId, minLength, maxLength)
{
    if (IsEmpty(objField.value))
        return true;
        
    var strVal = new String(objField.value);

    if (strVal.length < minLength || strVal.length > maxLength)
        return TurnOnValidateIcon(objField.id, errorMsgId);
    else
        return TurnOffValidateIcon(objField.id);
}

///////////////////////////////////////////////////////////////////////////////
//
// ValidateEmail
//
// Email address must be of form a@b.c i.e., 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.
// 
// Parameters:  objField    - Input field reference
//              errorMsgId  - Object that contains the error message to display
//
///////////////////////////////////////////////////////////////////////////////

function ValidateEmail(objField, errorMsgId)
{
    var strInvalid = "*?#&^~`'\\[]<>;/:\" ";
    var bAliasedEmail = false;
    var strAliasedEmail="";
    var i = 0, isValid = true;

    objField.value = RemoveSpaces(objField.value);
    if (IsEmpty(objField.value))
        return true;

    var strEmail = new String(objField.value);

    // Assumption: if strEmail contains < and >, Email is between < and >
    if (strEmail.indexOf('<') < strEmail.indexOf('>') && strEmail.indexOf('<') >= 0)
    {
        bAliasedEmail = true;
        strAliasedEmail = strEmail;
        strEmail = strEmail.substring(strEmail.indexOf('<')+1, 
        strEmail.indexOf('>'));
    }

    if (strEmail.length < 5)  // check the length
        isValid = false;
    else if (strEmail.lastIndexOf("@") <= 0 ||            // check positions of @ and .
             (strEmail.lastIndexOf(".") - strEmail.lastIndexOf("@") <= 1))
        isValid = false;
    else if (Occurs('@', strEmail) > 1) // check if @ occurs more than once
        isValid = false
    else
    {   // check if any invalid characters present
        for (i = 0; i < strEmail.length; i++)
        {
          if (strInvalid.indexOf(strEmail.charAt(i)) >= 0)
          {
            isValid = false;
            break;
          }
        }
    }
  
    if (!isValid)
        return TurnOnValidateIcon(objField.id, errorMsgId);
    else
    {
        TurnOffValidateIcon(objField.id);
        if (bAliasedEmail)
            objField.value = strAliasedEmail;
        else
            objField.value = strEmail;
        return true;
    }
}

///////////////////////////////////////////////////////////////////////////////
//
// ValidateFormat
//
// Validate the format to make sure it matches the given format string and length
//
//   Valid values  a | A => Alphabetical character
//                 #     => Number
//                 *     => Either a alphabetical character or a number
//
// Parameters:  objField    - Input field reference
//              errorMsgId  - Object that contains the error message to display
//              formatStr   - Format string (a|#) Example "aa##"
//
///////////////////////////////////////////////////////////////////////////////

function ValidateFormat(objField, errorMsgId, format)
{
    var alphaValid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    var numValid = "0123456789";
    var str = new String(RemoveSpaces(objField.value));
    var strLength = str.length;
    var formatStr = new String(format);
    var formatLength = formatStr.length;
    var i = 0, isValid = true;
    var alphaOk, numOk;

    if (IsEmpty(str))
        return true;

    if (strLength != formatLength)
        isValid = false;

    for (i = 0; i < strLength; i++)
    {
        if (formatStr.charAt(i) == 'a' || formatStr.charAt(i) == 'A')
        {
            if (alphaValid.indexOf(str.charAt(i)) < 0)
            {
                isValid = false;
                break;
            }
        }
        else if (formatStr.charAt(i) == '#')
        {
            if (numValid.indexOf(str.charAt(i)) < 0)
            {
                isValid = false;
                break;
            }
        }
        else
        {
            alphaOk = false;
            numOk = false;
            if (alphaValid.indexOf(str.charAt(i)) >= 0)
                alphaOk = true;
            if (numValid.indexOf(str.charAt(i)) >= 0)
                numOk = true;
            if (!alphaOk && !numOk)
            {
                isValid = false;
                break;
            }
        }
    }

    if (!isValid)
        return TurnOnValidateIcon(objField.id, errorMsgId);
    else
        return TurnOffValidateIcon(objField.id);
}

///////////////////////////////////////////////////////////////////////////////
//
// ValidateCharacters
//
// Validate the string to make sure it matches the given character formats
//
// Valid values  a | A => All alphabetical characters
//               #     => All Numbers
//
// Parameters:  objField    - Input field reference
//              errorMsgId  - Object that contains the error message to display
//              validChars  - Valid characters: Example "a#"
//
///////////////////////////////////////////////////////////////////////////////

function ValidateCharacters(objField,errorMsgId,validChars)
{
    var alphaValid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    var numValid = "0123456789";
    var str = new String(RemoveSpaces(objField.value));
    var strLength = str.length;
    var validStr = new String(validChars);
    var validLength = validStr.length;
    var i = 0, valid = true;
    var alphaOk = false, numOk = false;

    if (IsEmpty(str))
        return true;

    if (validStr.indexOf("a") >= 0 || validStr.indexOf("A") >= 0)
        alphaOk = true;

    if (validStr.indexOf("#") >= 0)
        numOk = true;

    for (i = 0; i < strLength; i++)
    {
        if (!((alphaOk && alphaValid.indexOf(str.charAt(i)) >= 0) ||
             (numOk && numValid.indexOf(str.charAt(i)) >= 0) ||
             (validStr.indexOf(str.charAt(i)) >= 0)))
        {
            valid = false;
            break;
        }
    }

    if (!valid)
        return TurnOnValidateIcon(objField.id, errorMsgId);
    else
    {
        objField.value = str;
        return TurnOffValidateIcon(objField.id);
    }
}

///////////////////////////////////////////////////////////////////////////////
//
// ValidateRequired
//
// Validate input types to see if a value is supplied
//
// Parameters:  objField   - Input field reference
//              errorMsgId - Object that contains the error message to display
//              inputType  - "Text" | "Select" | "Radio"
//
// Return:      true or false
//
///////////////////////////////////////////////////////////////////////////////

function ValidateRequired(objField,errorMsgId,inputType)
{
    var strVal;
    strVal = "";

    if (inputType == "Text")
        strVal = objField.value;
    else if (inputType == "Radio")
    {
        var iLen = objField.length;
        for (var iEle = 0; iEle < iLen; iEle++)
        {
            if (objField[iEle].checked)
            {
                strVal = objField[iEle].value;						
                break;					
            }
        }
    }
    else if (inputType == "Select")
    {
        var iIdx = objField.selectedIndex;
        if (iIdx > -1)
            strVal = objField[iIdx].value;
        else
            strVal = "";
    }

    strVal = RemoveSpaces(strVal);

    if (strVal == "")
        return TurnOnValidateIcon(objField.id, errorMsgId);
    else
        return TurnOffValidateIcon(objField.id);
}

///////////////////////////////////////////////////////////////////////////////
//
// ValidateOnBlur
//
// Validation functions to call onblur of object
//
// Parameters:  objField - Input field reference
//              options  - This is a JSON object with the following (optional) properties
//                         func1: Validate function to call
//                         (Note the first paramater with the object is always passed)
//                         func1_2: Validate function param 2
//                         func1_3 ... func1_10: Validate function param 3 - 10
//                         (Up to 10 functions can be passed into this function)
//
// Example:     ValidateOnBlur(object, {'func1':'ValidateRequired', 'func1_2':'validate_req_name', 'func1_3':'Text'});
//
///////////////////////////////////////////////////////////////////////////////

function ValidateOnBlur(objField, options)
{
    if (IsEmpty(objField.value))
        return false;
        
    for (var func = 1; func <= 10; func++)
    {
        if (!IsEmpty(eval("options.func" + func)))
        {
            var funcCall = eval("options.func" + func) + "(objField";
            for (var param = 2; param <= 10; param++)
            {
                if (!IsEmpty(eval("options.func" + func + "_" + param)))
                    funcCall +=  "," + eval("options.func" + func + "_" + param);
                else
                {
                    funcCall +=  ")";
                    break;
                }
            }
            eval(funcCall);
        }
    }
    return false;
}

///////////////////////////////////////////////////////////////////////////////
//
// TurnOnValidateIcon
//
// Display validation icon if it is not turned on already
//
///////////////////////////////////////////////////////////////////////////////

function TurnOnValidateIcon(objFieldId, errorMsgId)
{
    var iconObj = document.getElementById("validate_icon_" + objFieldId);
    if (iconObj && iconObj.style.display == 'none')
    {
        iconObj.style.display = "inline";
        iconObj.innerHTML = '<a href="javascript:void(ShowValidateWindow(\'' + objFieldId + '\',\'' + errorMsgId + '\'));" id="' + errorMsgId + '_link" tabindex="-1">' + validateIconHTML + '</a>';
    }
    return false;
}

///////////////////////////////////////////////////////////////////////////////
//
// TurnOffValidateIcon
//
// Turn off the validation icon if it is turned on already
//
///////////////////////////////////////////////////////////////////////////////

function TurnOffValidateIcon(objFieldId)
{
    var iconObj = document.getElementById("validate_icon_" + objFieldId);
    if (iconObj && iconObj.style.display == 'inline')
        iconObj.style.display = "none";
    return true;
}

var validateSummaryObj = null;
var validateSummaryMsgObj = null;

function InitValidateSummaryWindow()
{
    if (!validateSummaryObj)
    {
        validateSummaryObj = document.createElement('div');
        validateSummaryObj.className = 'validate_summary_window';
        validateSummaryObj.style.display = 'none';
        document.body.appendChild(validateSummaryObj);
    }
    else
        validateSummaryObj.className = 'validate_summary_window';
}

///////////////////////////////////////////////////////////////////////////////
//
// ShowValidateSummaryWindow
//
// Show full description of the required field
//
// Parameters:  errors   - Array of error strings
//
// Return:      true or false based on whether the error array has values
//
///////////////////////////////////////////////////////////////////////////////

function ShowValidateSummaryWindow()
{
    var summaryObj = document.getElementById("validate_summary");
    
    if (summaryObj)
    {
        GrayOutScreen(true);
        InitValidateSummaryWindow();

        var width = (summaryObj.style.width)? parseInt(summaryObj.style.width) : 350;
        var height = (summaryObj.style.height)? parseInt(summaryObj.style.height) : 350;
        
        validateSummaryObj.style.width = width + 'px';
        validateSummaryObj.style.height = height + 'px';
        var visibleWidth = CalculateVisibleWidth();
        var visibleHeight = CalculateVisibleHeight();
        var scrollX = CalculateScrollLeft();
        var scrollY = CalculateScrollTop();
        
        validateSummaryObj.style.left =scrollX + parseInt((visibleWidth - width) / 2) + 'px';
        validateSummaryObj.style.top = scrollY + parseInt((visibleHeight - height) / 2) + 'px';
        SetOpacity(validateSummaryObj, 0);

        validateSummaryMsgObj = summaryObj;
        MoveChildren(validateSummaryMsgObj, validateSummaryObj);
        validateSummaryObj.style.display = 'block';
        ValidateSummaryFadeIn(0);

        HideShowCovered(validateSummaryObj);
    }
}

function ValidateSummaryFadeIn(opacity)
{
	if (validateSummaryObj)
	{
		if (opacity <= 100)
		{
			opacity += 20;
			SetOpacity(validateSummaryObj, opacity);
			setTimeout("ValidateSummaryFadeIn("+opacity+")", 20);
		}
	}
}

function ValidateSummaryFadeOut(opacity)
{
	if (validateSummaryObj)
	{
		if (opacity > 0)
		{
		    opacity -= 30;
			SetOpacity(validateSummaryObj, opacity);
		    setTimeout("ValidateSummaryFadeOut("+opacity+")", 30);
		}
		else
		    HideValidateSummaryWindow();
	}
}
function HideValidateSummaryWindow()
{
    if (!validateSummaryObj)
        return false;
    validateSummaryObj.style.display = 'none';

    MoveChildren(validateSummaryObj, validateSummaryMsgObj);
    HideShowCovered(validateSummaryObj);
    
    GrayOutScreen(false);
    return false;
}

var validateObj = null;
var validateShowing = false;
var validateLinkObj = null;
var validateMsgObj = null;
var validateMsgHTML = null;
var validateShortMsgObj = null;
var validateShortMsgHTML = null;

function InitValidateWindow()
{
    if (!validateObj)
    {
        validateObj = document.createElement('div');
        validateObj.className = 'validate_window';
        validateObj.style.display = 'none';
        document.body.appendChild(validateObj);
    }
    else
        validateObj.className = 'validate_window';
}

///////////////////////////////////////////////////////////////////////////////
//
// ShowValidateWindow
//
// Show full description of the error message
//
// Parameters:  errorMsgId - Object that contains the error message to display
//
///////////////////////////////////////////////////////////////////////////////

function ShowValidateWindow(objectId, errorMsgId)
{
    var iconName = "validate_icon_" + objectId;
    var iconObj = document.getElementById(iconName);
    var errorMsgObj = document.getElementById(errorMsgId);
    var linkObj = document.getElementById(errorMsgId + "_link");
    
    if (errorMsgObj)
    {
        InitValidateWindow();
        if (validateShowing)
            return;
            
        var x = FindPositionX(linkObj);
        var y = FindPositionY(linkObj);
        var width = (errorMsgObj.style.width)? parseInt(errorMsgObj.style.width) : 250;
        
        // If text-align = left then align the popup window on the left side instead of the default right side
        if (errorMsgObj.style.textAlign && errorMsgObj.style.textAlign == "left")
        {
            var xOffset = (23 + width) * -1;
            var yOffset = -10;

            validateObj.style.width = width + 'px';
            validateObj.style.left = (x+xOffset)+'px';
            validateObj.style.top = (y+yOffset)+'px';
            SetOpacity(validateObj, 0);

            validateShortMsgObj = iconObj;
            validateShortMsgHTML = iconObj.innerHTML;
            validateMsgObj = errorMsgObj;
            validateMsgHTML = errorMsgObj.innerHTML;
            validateMsgObj.innerHTML = '<div style="position:absolute;top:7px;left:5px;"><img src="/images/validate_warn_icon.gif" alt="" width="20" height="17" border="0"/></div>' +
                '<div style="position:absolute;top:3px;left:' + (width - 12) + 'px;"><a href="javascript:void(ValidateFadeOut(100))"><img src="/images/validate_close.gif" alt="" width="7" height="7" border="0"/></a></div><div style="padding-left:35px;padding-right:20px;">' + validateMsgObj.innerHTML + '</div>';
            
            MoveChildren(validateMsgObj, validateObj);

            validateShowing = true;
            validateObj.style.display = 'block';
            ValidateFadeIn(0);
            validateLinkObj = linkObj;

            HideShowCovered(validateObj);
            iconObj.innerHTML = '<div style="position:absolute;top:' + (y + 3) + 'px;left:' + (x - 22) + 'px;display:inline;z-index:20001;"><img src="/images/validate_window_arrow_right.gif" alt="" width="14" height="8" border="0" align="absmiddle"/></div>';
        }
        else
        {
            var xOffset = 13;
            var yOffset = -10;

            validateObj.style.width = width + 'px';
            validateObj.style.left = (x+xOffset)+'px';
            validateObj.style.top = (y+yOffset)+'px';
            SetOpacity(validateObj, 0);

            validateShortMsgObj = iconObj;
            validateShortMsgHTML = iconObj.innerHTML;
            validateMsgObj = errorMsgObj;
            validateMsgHTML = errorMsgObj.innerHTML;
            validateMsgObj.innerHTML = '<div style="position:absolute;top:7px;left:5px;"><img src="/images/validate_warn_icon.gif" alt="" width="20" height="17" border="0"/></div>' +
                '<div style="position:absolute;top:3px;left:' + (width - 12) + 'px;"><a href="javascript:void(ValidateFadeOut(100))"><img src="/images/validate_close.gif" alt="" width="7" height="7" border="0"/></a></div><div style="padding-left:35px;padding-right:20px;">' + validateMsgObj.innerHTML + '</div>';
            
            MoveChildren(validateMsgObj, validateObj);

            validateShowing = true;
            validateObj.style.display = 'block';
            ValidateFadeIn(0);
            validateLinkObj = linkObj;

            HideShowCovered(validateObj);
            iconObj.innerHTML = '<div style="position:absolute;top:' + (y + 3) + 'px;left:' + x + 'px;display:inline;z-index:20001;"><img src="/images/validate_window_arrow.gif" alt="" width="14" height="8" border="0" align="absmiddle"/></div>';
        }
    }
}

function ValidateFadeIn(opacity)
{
	if (validateObj)
	{
		if (opacity <= 100)
		{
			opacity += 4;
			SetOpacity(validateObj, opacity);
			setTimeout("ValidateFadeIn("+opacity+")", 4);
		}
	}
}

function ValidateFadeOut(opacity)
{
	if (validateObj)
	{
	    if (opacity == 100)
	    {
            if (validateShortMsgObj)
                validateShortMsgObj.innerHTML = validateShortMsgHTML;
            ResetValidationIcon();
        }
    
		if (opacity > 0)
		{
		    opacity -= 8;
			SetOpacity(validateObj, opacity);
		    setTimeout("ValidateFadeOut("+opacity+")", 8);
		}
		else
		    HideValidateWindow();
	}
}

function HideValidateWindow()
{
    if (!validateObj)
        return false;

    validateObj.style.display = 'none';
    validateLinkObj = 'null';
    validateShowing = false;

    MoveChildren(validateObj, validateMsgObj);
    HideShowCovered(validateObj);
    
    if (validateMsgObj)
        validateMsgObj.innerHTML = validateMsgHTML;
    return false;
}