// This section is used to autotab from field to field based on the text length	
var isNN = (navigator.appName.indexOf("Netscape") != -1);
var uwLoadWin;

function autoTab(input, len, e) {
    // temporarily disabling autotab because of skipping field bug 2/2/2005
    return;

    var keyCode = (isNN) ? e.which : e.keyCode;
    var filter = (isNN) ? [0, 8, 9] : [0, 8, 9, 16, 17, 18, 37, 38, 39, 40, 46];
    if (input.value.length >= len && !containsElement(filter, keyCode)) {
        input.value = input.value.slice(0, len);
        input.form[(getIndex(input) + 1) % input.form.length].focus();
        input.form[(getIndex(input) + 1) % input.form.length].select();
    }

    function containsElement(arr, ele) {
        var found = false, index = 0;
        while (!found && index < arr.length)
            if (arr[index] == ele)
            found = true;
        else
            index++;
        return found;
    }

    function getIndex(input) {
        var index = -1, i = 0, found = false;
        while (i < input.form.length && index == -1)
            if (input.form[i] == input) index = i;
        else i++;
        return index;
    }
    return true;
}
// end of autotab section

function TrapKeyDown(btn, event) {
    if (document.all) {
        if (event.keyCode == 13) {
            event.returnValue = false;
            event.cancel = true;
            btn.click();
        }
    }
    else if (document.getElementById) {
        if (event.which == 13) {
            event.returnValue = false;
            event.cancel = true;
            btn.click();
        }
    }
    else if (document.layers) {
        if (event.which == 13) {
            event.returnValue = false;
            event.cancel = true;
            btn.click();
        }
    }
}

function KeyDownHandler(search) {
    // process only the Enter key
    if (event.keyCode == 13) {
        // cancel the default submit
        event.returnValue = false;
        event.cancel = true;
        // submit the form by programmatically clicking the specified button
        search.click();
    }
}
function CheckNumeric() {
    //Allows only numeric characters using the keypress event

    // Get ASCII value of key that user pressed
    var key = window.event.keyCode;

    // Was key that was pressed a numeric character (0-9) ?
    // note if want to add a 'minus' sign, also allow key 45
    if ((key > 47 && key < 58))
        return; // if so, do nothing
    else
        window.event.returnValue = null; // otherwise, discard character
}

//Function to Allow users to enter numeric value
function IsNumeric(string, obj, error)
//  check for valid numeric strings	
{
    var validChars = "0123456789";
    var selectedChar;
    var result = true;
    for (i = 0; i < string.length && result == true; i++) {
        selectedChar = string.charAt(i);
        if (validChars.indexOf(selectedChar) == -1) {
            error.innerText = "Please check - value should be numeric"
            document.getElementById(obj).value = '';
            //alert("Please check - value should be numeric!");
            document.getElementById(obj).focus();
            return;
        }
    }
    error.innerText = '';
    return result;
}

function IsAlphanumeric(name, obj, error) {
    var valid = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
    var selectedChar;
    var result = true;

    for (i = 0; i < name.length && result == true; i++) {
        selectedChar = name.charAt(i);
        if (valid.indexOf(selectedChar) == -1) {
            error.innerText = "Please check - value should be alphanumeric!"
            //document.getElementById(obj).value = ''; 
            //alert("Please check - value should be alphanumeric!");
            document.getElementById(obj).focus();
            return;
        }
    }
    //error.innerText = '';          
    return result;
}

function IsAlpha(name, obj, error) {
    var valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'- ";
    var selectedChar;
    var result = true;

    for (i = 0; i < name.length && result == true; i++) {
        selectedChar = name.charAt(i);
        if (valid.indexOf(selectedChar) == -1) {
            error.innerText = "Please check - Invalid value!"
            document.getElementById(obj).value = '';
            //alert("Please check - Invalid value!");
            document.getElementById(obj).focus();
            return;
        }
    }
    error.innerText = " "
    return result;
}

//****DATE VALIDATION*******************
// Declaring valid date character, minimum year and maximum year
var dtCh = "/";
var minYear = 1900;
var maxYear = 2100;

function isInteger(s) {
    var i;
    for (i = 0; i < s.length; i++) {
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag) {
    var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary(year) {
    // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28);
}
function DaysArray(n) {
    for (var i = 1; i <= n; i++) {
        this[i] = 31
        if (i == 4 || i == 6 || i == 9 || i == 11) { this[i] = 30 }
        if (i == 2) { this[i] = 29 }
    }
    return this
}

function IsDate(dtStr, monthObj, dateObj, yearObj, error) {
    var daysInMonth = DaysArray(12)
    var pos1 = dtStr.indexOf(dtCh)
    var pos2 = dtStr.indexOf(dtCh, pos1 + 1)
    var strMonth = dtStr.substring(0, pos1)
    var strDay = dtStr.substring(pos1 + 1, pos2)
    var strYear = dtStr.substring(pos2 + 1)


    if (document.getElementById(monthObj).value == "" || isNaN(document.getElementById(monthObj).value) == true) {
        error.innerHTML = "Please enter a valid month."
        //alert("Please enter a valid date")
        document.getElementById(monthObj).focus();
        return false
    }
    if (document.getElementById(dateObj).value == "" || isNaN(document.getElementById(dateObj).value) == true) {
        error.innerHTML = "Please enter a valid day."
        //alert("Please enter a valid date")
        document.getElementById(dateObj).focus();
        return false
    }
    if (document.getElementById(yearObj).value == "" || isNaN(document.getElementById(yearObj).value) == true) {
        error.innerHTML = "Please enter a valid year."
        //alert("Please enter a valid date")
        document.getElementById(yearObj).focus();
        return false
    }


    strYr = strYear
    if (strDay.charAt(0) == "0" && strDay.length > 1) strDay = strDay.substring(1)
    if (strMonth.charAt(0) == "0" && strMonth.length > 1) strMonth = strMonth.substring(1)
    for (var i = 1; i <= 3; i++) {
        if (strYr.charAt(0) == "0" && strYr.length > 1) strYr = strYr.substring(1)
    }
    month = parseInt(strMonth)
    day = parseInt(strDay)
    year = parseInt(strYr)
    if (pos1 == -1 || pos2 == -1) {
        document.getElementById(monthObj).value = '';
        document.getElementById(dateObj).value = '';
        document.getElementById(yearObj).value = '';
        error.innerHTML = "The date format should be : mm/dd/yyyy"
        //alert("The date format should be : mm/dd/yyyy")
        document.getElementById(monthObj).focus();
        return false
    }
    if (strMonth.length < 1 || month < 1 || month > 12) {
        document.getElementById(monthObj).value = '';
        error.innerHTML = "Please enter a valid month"
        //alert("Please enter a valid month")
        document.getElementById(monthObj).focus();
        return false
    }
    if (strDay.length < 1 || day < 1 || day > 31 || (month == 2 && day > daysInFebruary(year)) || day > daysInMonth[month]) {
        document.getElementById(dateObj).value = '';
        error.innerHTML = "Please enter a valid day"
        //alert("Please enter a valid day")
        document.getElementById(dateObj).focus();
        return false
    }
    if (strYear.length != 4 || year == 0 || year < minYear || year > maxYear) {
        document.getElementById(yearObj).value = '';
        error.innerHTML = "Please enter valid 4-digit year."
        //alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
        document.getElementById(yearObj).focus();
        return false
    }
    if (dtStr.indexOf(dtCh, pos2 + 1) != -1 || isInteger(stripCharsInBag(dtStr, dtCh)) == false) {
        document.getElementById(monthObj).value = '';
        document.getElementById(dateObj).value = '';
        document.getElementById(yearObj).value = '';
        error.innerHTML = "Please enter a valid date"
        //alert("Please enter a valid date")
        document.getElementById(monthObj).focus();
        return false
    }
    error.innerHTML = " "
    return true
}


//****EMAIL VALIDATION*******************
function emailCheck(email, obj, error) {
    /* The following pattern is used to check if the entered e-mail address
    fits the user@domain format.  It also is used to separate the username
    from the domain. */
    var emailPat = /^(.+)@(.+)$/
    /* The following string represents the pattern for matching all special
    characters.  We don't want to allow special characters in the address. 
    These characters include ( ) < > @ , ; : \ " . [ ]    */
    var specialChars = "\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
    /* The following string represents the range of characters allowed in a 
    username or domainname.  It really states which chars aren't allowed. */
    var validChars = "\[^\\s" + specialChars + "\]"
    /* The following pattern applies if the "user" is a quoted string (in
    which case, there are no rules about which characters are allowed
    and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
    is a legal e-mail address. */
    var quotedUser = "(\"[^\"]*\")"
    /* The following pattern applies for domains that are IP addresses,
    rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
    e-mail address. NOTE: The square brackets are required. */
    var ipDomainPat = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
    /* The following string represents an atom (basically a series of
    non-special characters.) */
    var atom = validChars + '+'
    /* The following string represents one word in the typical username.
    For example, in john.doe@somewhere.com, john and doe are words.
    Basically, a word is either an atom or quoted string. */
    var word = "(" + atom + "|" + quotedUser + ")"
    // The following pattern describes the structure of the user
    var userPat = new RegExp("^" + word + "(\\." + word + ")*$")
    /* The following pattern describes the structure of a normal symbolic
    domain, as opposed to ipDomainPat, shown above. */
    var domainPat = new RegExp("^" + atom + "(\\." + atom + ")*$")

    /* Begin with the coarse pattern to simply break up user@domain into
    different pieces that are easy to analyze. */
    var matchArray = email.match(emailPat)
    if (matchArray == null) {
        /* Too many/few @'s or something; basically, this address doesn't
        even fit the general mould of a valid e-mail address. */
        error.innerText = "Email address seems incorrect (check @ and .'s)"
        //alert("Email address seems incorrect (check @ and .'s)")
        document.getElementById(obj).focus();
        return false
    }
    var user = matchArray[1]
    var domain = matchArray[2]

    // See if "user" is valid 
    if (user.match(userPat) == null) {
        // user is not valid
        error.innerText = "The username doesn't seem to be valid."
        //alert("The username doesn't seem to be valid.")
        document.getElementById(obj).focus();
        return false
    }

    /* if the e-mail address is at an IP address (as opposed to a symbolic
    host name) make sure the IP address is valid. */
    var IPArray = domain.match(ipDomainPat)
    if (IPArray != null) {
        // this is an IP address
        for (var i = 1; i <= 4; i++) {
            if (IPArray[i] > 255) {
                error.innerText = "Destination IP address is invalid!"
                //alert("Destination IP address is invalid!")
                document.getElementById(obj).focus();
                return false
            }
        }
        error.innerText = " "
        return true
    }

    // Domain is symbolic name
    var domainArray = domain.match(domainPat)
    if (domainArray == null) {
        error.innerText = "The domain name doesn't seem to be valid."
        //alert("The domain name doesn't seem to be valid.")
        document.getElementById(obj).focus();
        return false
    }

    /* domain name seems valid, but now make sure that it ends in a
    three-letter word (like com, edu, gov) or a two-letter word,
    representing country (uk, nl), and that there's a hostname preceding 
    the domain or country. */

    /* Now we need to break up the domain to get a count of how many atoms
    it consists of. */
    var atomPat = new RegExp(atom, "g")
    var domArr = domain.match(atomPat)
    var len = domArr.length
    if (domArr[domArr.length - 1].length < 2 ||
    domArr[domArr.length - 1].length > 3) {
        // the address must end in a two letter or three letter word.
        error.innerText = "The address must end in a three-letter domain, or two letter country."
        //alert("The address must end in a three-letter domain, or two letter country.")
        document.getElementById(obj).focus();
        return false
    }

    // Make sure there's a host name preceding the domain.
    if (len < 2) {
        var errStr = "This address is missing a hostname!"
        error.innerText = errStr
        //alert(errStr)
        document.getElementById(obj).focus();
        return false
    }
    error.innerText = " "
    return true;
}

//this function is used to show or hide the html row on the basis of status of checkbox
function ShowHide(chkBoxID, rowID) {
    if (document.getElementById(chkBoxID).checked) {
        document.getElementById(rowID).style.display = "none";
    }
    else {
        document.getElementById(rowID).style.display = "";
    }
    return true;
}

//this function is used to autotab from field to field depending upon its text length	
function ChangeFocus(length, lostFocusID, setFocusID) {
    if (document.getElementById(lostFocusID).value.length == length) {
        document.getElementById(setFocusID).focus();
    }
}


//this function is used on PrintSaveApplicationDetails
function checkClick(frm, elementId) {
    if (!document.getElementById(elementId).checked)
        document.getElementById(elementId).focus()

}

// ====================================================================
// Asks for confirmation for Delete a quote in find client
// ====================================================================
function Delete_Quote() {
    if (confirm("Delete Quote?"))
        return true
    else
        return false
}

// ====================================================================
// Calculates difference between two specified dates (in days)
// ====================================================================
function DateDiff(date1, date2) {
    // The number of milliseconds in one day
    var one_day = 1000 * 60 * 60 * 24;

    // Convert both dates to milliseconds
    var date1_ms = date1.getTime()
    var date2_ms = date2.getTime()

    // Calculate the difference in milliseconds
    var difference_ms = Math.abs(date1_ms - date2_ms)

    // Convert back to days and return
    return Math.ceil(difference_ms / one_day)
}

// =================================================================
// Compares two dates. Returns 0 if date1=date2, returns 1 if date1 > date2 and
// returns -1 if date1 < date2.
// =================================================================
function DateCompare(date1, date2) {
    // The number of milliseconds in one day
    var one_day = 1000 * 60 * 60 * 24;

    // Convert both dates to milliseconds
    var date1_ms = date1.getTime()
    var date2_ms = date2.getTime()

    // Calculate the difference in milliseconds
    var difference_ms = date1_ms - date2_ms

    // Convert back to days and return
    var noofdays = Math.ceil(difference_ms / one_day)
    if (noofdays == 0)
        return 0
    else if (noofdays > 0)
        return 1
    else if (noofdays < 0)
        return -1
}





// ====================================================================
// Checks whether an application is a day old application and needs a 
// change in its effective date for find client
// ====================================================================
function OpenApplication(month1, day1, year1, month2, day2, year2) {
    var proposedEffectiveDate = new Date(year1, month1 - 1, day1);

    var lastSavedDate = new Date(year2, month2 - 1, day2);
    var currentDate = new Date()
    document.getElementById('FindClientSearchResults1_Flag').value = "FALSE"
    var today = new Date(currentDate.getYear(), currentDate.getMonth(), currentDate.getDate())

    document.forms[0].submit();
    return true
}
function ConfirmDateChange() {
    var WinSettings = "help:no;status:no;center:yes;resizable:no;dialogHeight:90px;dialogWidth:345px";
    var MyArgs = window.showModalDialog("ChangeProposedEffectiveDateConfirmation.htm", "", WinSettings);

    if (MyArgs != null) {
        return MyArgs
    }
    else
        return false
}
function OpenChild() {
    var WinSettings = "help:no;status:no;center:yes;resizable:no;dialogHeight:120px;dialogWidth:450px";
    var MyArgs = window.showModalDialog("ViewPrintProposalPopup.htm", "", WinSettings);

    if (MyArgs != null) {
        document.getElementById('FindClientSearchResults1_ProposedNewEffectiveDate').value = MyArgs;
        document.getElementById('FindClientSearchResults1_Flag').value = "TRUE";
        return true
    }
    else {
        document.getElementById('FindClientSearchResults1_Flag').value = "FALSE";
        return false
    }
}

// ====================================================================
// Function sets and submits the changed effective date in find client
// ====================================================================	
function SubmitDate(proposedNewEffectiveDate, CurrentCellId, applicationFolderId) {
    if (CheckDate(proposedNewEffectiveDate) == true) {
        document.getElementById("FindClientSearchResults1_ProposedNewEffectiveDate").value = proposedNewEffectiveDate.value
        document.getElementById("FindClientSearchResults1_RowIndex").value = CurrentCellId
        document.getElementById("FindClientSearchResults1_ApplicationFolderId").value = applicationFolderId
        document.FindClientSearchResults.submit()
        return true
    }
    else {
        return false
    }
}

// ====================================================================
// Functions for validating date
// ====================================================================
var dtCh = "/";
var minYear = 1900;
var maxYear = 2100;

function isInteger(s) {
    var i;
    for (i = 0; i < s.length; i++) {
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag) {
    var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary(year) {
    // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28);
}
function DaysArray(n) {
    for (var i = 1; i <= n; i++) {
        this[i] = 31
        if (i == 4 || i == 6 || i == 9 || i == 11) { this[i] = 30 }
        if (i == 2) { this[i] = 29 }
    }
    return this
}

function CheckDate(dateObject) {
    var dtStr = dateObject.value
    var daysInMonth = DaysArray(12)
    var pos1 = dtStr.indexOf(dtCh)
    var pos2 = dtStr.indexOf(dtCh, pos1 + 1)
    var strMonth = dtStr.substring(0, pos1)
    var strDay = dtStr.substring(pos1 + 1, pos2)
    var strYear = dtStr.substring(pos2 + 1)
    strYr = strYear
    if (strDay.charAt(0) == "0" && strDay.length > 1) strDay = strDay.substring(1)
    if (strMonth.charAt(0) == "0" && strMonth.length > 1) strMonth = strMonth.substring(1)
    for (var i = 1; i <= 3; i++) {
        if (strYr.charAt(0) == "0" && strYr.length > 1) strYr = strYr.substring(1)
    }
    month = parseInt(strMonth)
    day = parseInt(strDay)
    year = parseInt(strYr)
    if (pos1 == -1 || pos2 == -1) {
        alert("The date format should be : mm/dd/yyyy")
        dateObject.focus()
        return false
    }
    if (strMonth.length < 1 || month < 1 || month > 12) {
        alert("Please enter a valid month")
        dateObject.focus()
        return false
    }
    if (strDay.length < 1 || day < 1 || day > 31 || (month == 2 && day > daysInFebruary(year)) || day > daysInMonth[month]) {
        alert("Please enter a valid day")
        dateObject.focus()
        return false
    }
    if (strYear.length != 4 || year == 0 || year < minYear || year > maxYear) {
        alert("Please enter valid 4-digit year.")
        dateObject.focus()
        return false
    }
    if (dtStr.indexOf(dtCh, pos2 + 1) != -1 || isInteger(stripCharsInBag(dtStr, dtCh)) == false) {
        alert("Please enter a valid date")
        dateObject.focus()
        return false
    }
    return true
}

//////////////////////////////////////////////////////
/// These functions used by EditableDropDown control
//////////////////////////////////////////////////////	
function fnKeyDownHandler(getdropdown, e) {
    var vEventKeyCode = FindKeyCode(e);
    // backspace key pressed
    if (vEventKeyCode == 8 || vEventKeyCode == 127) {
        if (e.which) //Netscape
        {
            //e.which = ''; //this property has only a getter.
        }
        else //Internet Explorer
        {
            //To prevent backspace from activating the -Back- button of the browser
            e.keyCode = '';
            if (window.event.keyCode) {
                window.event.keyCode = '';
            }
        }
        return true;
    }
}


function FindKeyCode(e) {
    if (e.which) {
        keycode = e.which;  //Netscape
    }
    else {
        keycode = e.keyCode; //Internet Explorer
    }
    if ((keycode == 8) || (keycode == 127)) {
        if (e.which) {
            //e.which = '';  // this property has only a getter
        }
        else {
            e.keyCode = ''; //Internet Explorer
            if (window.event.keyCode) {
                window.event.keyCode = '';
            }
        }
    }
    return keycode;
}

function FindKeyChar(e) {
    keycode = FindKeyCode(e);
    switch (keycode) {
        case 8:
        case 127:
            character = "backspace";
            break;
        case keycode == 46:
            character = "delete";
            break;
        case 191:
            character = event.shiftKey ? '?' : '/';
            break;
        default:
            character = String.fromCharCode(keycode);
    }
    return character;
}

function autocomplete(source, array) {
    var key = FindKeyCode(event);
    //check key codes
    if (!((key > 47 && key < 59) || (key > 62 && key < 126) || (key == 32) || (key == 8) || (key == 127) || (key == 191))) {
        return;
    }

    var chr = FindKeyChar(event);

    var foundWords = new Array();
    //var srcText = document.getElementById("$_providerInput_$");
    if (source.options.length == 0)
        IntiDropDown(source);

    var text = source.options(0).text;

    // check if we have at least 3 chars
    if (text != null) {
        if (key == 8) {
            if (text.length > 0)
                text = text.substr(0, text.length - 1);
            else
                return;
        }
        else
            text += chr;

        // add this at the top of our list								
        var vp = new Object();
        vp.value = -1;
        vp.descr = text;
        foundWords[foundWords.length] = vp;

        if (text.length > 2) {
            var z; // couter of words in incomming array
            var tmp; // holds input
            var tmp2; // word from incomming array
            var count; // count of found words 
            tmp = new String(text);
            // the loop takes word by word and searches those that matches incomming sequence.
            for (z = 0, count = foundWords.length; z < array.length; z++) {
                var w = array[z].substr(0, tmp.length);

                // if matchig was found, create a TextRange to continue.
                if (w.toUpperCase() == tmp.toUpperCase()) {
                    vp = new Object();
                    vp.value = count;
                    vp.descr = array[z];
                    foundWords[count++] = vp;
                }
            }
            // if nothing was found, then do not updated dropdown, but 
            // simply leave the function.
            if (count == 1 && text.length > 3) {
                return 0;
            }
        }

        // add this at the bottom of our list								
        vp = new Object();
        vp.value = 999; 	// this hard coded value has been taken from database table OtherCoverageCompany.
        vp.descr = "Other"; // it presents Other
        foundWords[foundWords.length] = vp;
        fillDropDown(source, foundWords);
    }
    return 0;
}

function fillDropDown(dropdown, words) {
    var i;
    for (; dropdown.options.length > 0; ) {
        dropdown.options.remove(dropdown.options.length - 1);
    }

    for (i = 0; i < words.length; i++) {
        var word = words[i];
        var option = document.createElement("option");
        option.value = word.value;
        dropdown.options.add(option);
        dropdown.options(i).text = words[i].descr;
    }
}

function IntiDropDown(dropdown) {
    if (document.all == null)
        return;
    var words = new Array();
    var vp = new Object();
    vp.value = -1;
    vp.descr = "";
    words[words.length] = vp;
    vp = new Object();
    vp.value = 999; 	// this hard coded value has been taken from database table OtherCoverageCompany.
    vp.descr = "Other";
    words[words.length] = vp;
    fillDropDown(dropdown, words);
}

function OnGetFocus(dropdown) {
    if (dropdown != null && dropdown.options.length == 0) {
        IntiDropDown(dropdown);
    }
}

function OnSelectionChanged(dropdown, tb) {
    tb.value = dropdown.options(dropdown.options.selectedIndex).text + ":" +
				dropdown.options(dropdown.options.selectedIndex).value;
}

///////////////////////////////////////////////////////////////////////
/// End of EditableDropDown 
///////////////////////////////////////////////////////////////////////


function OpenWin(URL, NAME, w, h, showMenu) {
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    winprops = 'height=' + h + ',width=' + w + ',top=' + wint + ',left=' + winl + ',scrollbars=' + showMenu + ',menubar=' + showMenu + ',status=' + showMenu + ',toolbar=' + showMenu + ',resizable=' + showMenu
    var newWin;

    if (URL.indexOf('nc=0') < 0) {
        if (URL.indexOf('?') < 0) {
            URL = URL + '?nc=0'
        }
        else {
            URL = URL + '&nc=0'
        }
    }

    newWin = window.open(URL, NAME, winprops);
    newWin.focus();
}

function OpenScrollbarWin(URL, NAME, w, h) {
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    winprops = 'height=' + h + ',width=' + w + ',top=' + wint + ',left=' + winl + ',scrollbars=Yes,menubar=No,status=No,toolbar=No,resizable=No'
    var newWin;

    if (URL.indexOf('nc=0') < 0) {
        if (URL.indexOf('?') < 0) {
            URL = URL + '?nc=0'
        }
        else {
            URL = URL + '&nc=0'
        }
    }

    newWin = window.open(URL, NAME, winprops);
    newWin.focus();
}

function OpenHelp(URL, NAME, w, h) {
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    winprops = 'height=' + h + ',width=' + w + ',top=' + wint + ',left=' + winl + ',scrollbars=Yes,menubar=No,status=No,toolbar=No,resizable=Yes'

    if (URL.indexOf('nc=0') < 0) {
        if (URL.indexOf('?') < 0) {
            URL = URL + '?nc=0'
        }
        else {
            URL = URL + '&nc=0'
        }
    }
    var newWin = window.open(URL, NAME, winprops);
    newWin.focus()
}

function OpenNewWin(URL, NAME) {
    if (URL.indexOf('nc=0') < 0) {
        if (URL.indexOf('?') < 0) {
            URL = URL + '?nc=0'
        }
        else {
            URL = URL + '&nc=0'
        }
    }
    window.open(URL, NAME)
}

function OpenStreamedDoc() {
    var win = window.open('ViewCounterOffer.EASEDoc?nc=0', 'EASEDoc', 'menubar=yes,scrollbars=yes,resizable=yes,width=750,height=430,left=20,top=20,screenX=0,screenY=100');
    //win.location = 'ViewCounterOffer.EASEDoc';
    //win.location = docName;
    return;
}

function onKeyPress() {
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;
    if (keycode == 13) {
        return false
    }
    return true
}
document.onkeypress = onKeyPress;

function ButtonEnterKey(btnID) {
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;
    if (keycode == 13) {
        btn = document.getElementById(btnID);
        btn.click();
    }
}

function DisableSelectButton(btnID) {
    btn = document.getElementById(btnID);
    btn.disabled = true;
}

function disableHyperlink(linkID) {
    var link = document.getElementById(linkID);
    link.onclick = function() { return false; };
}

function OpenPrintWindow() {
    if (window.print) window.print();
}

function CheckNewNotesExit() {
    if (document.getElementById('PersonalNotes1_NewNotes').value.length > 0) {
        var val = confirm("Do you wish to continue without saving ?");
        return val;
    }
    return true;


}

function PrintPage() {
    document.getElementById('printbutton').style.visibility = 'hidden';
    if (window.print) window.print();
    return true;
}

function ClosePage() {
    window.close();
    return true;
}

function refreshParent() {

    // Submit the parent form (cause it to postback)
    //self.opener.form1.submit();
    self.opener.document.forms[0].submit();
    // Close this page
    self.close();

}

function AddUWLoad() {

    var winl = (screen.width - 400) / 2;
    var wint = (screen.height - 200) / 2;
    winprops = 'height=200,width=400,top=' + wint + ',left=' + winl + ',scrollbars=No,menubar=No,status=No,toolbar=No,resizable=No'
    uwLoadWin = window.open('AddUWLoad.aspx?nc=0', '', winprops);
    uwLoadWin.focus();

}

function CloseUWLoadWin() {
    if (uwLoadWin) { uwLoadWin.close(); }
}


/*
Access Layer Style Properties
Jim Cummins - http://www.conxiondesigns.com
Required components:  Javascript Browser Sniff 1.0
*/
function aLs(layerID) {
    var returnLayer;
    if (isNN) {
        returnLayer = eval("document.getElementById('" + layerID + "').style");
    }
    else {
        returnLayer = eval("document.all." + layerID + ".style");
    }
    return returnLayer;
}
/*
End of Accessing Layer Style Properties
*/


function CoverageInfoHideAll() {
    aLs('CollectCoverageInformation1_PrimaryCompanySect').visibility = "hidden";
}

function CoverageInfoIndCov() {
    aLs('CollectCoverageInformation1_PrimaryCompanySect').visibility = "visible";

    if (document.all.CollectCoverageInformation1_IndividualContinuity.value == "Y") {
        aLs('CollectCoverageInformation1_PrimaryDateContainer').visibility = "visible";
    }
    else {
    }
}
function CoverageInfoCoveredSelection(selection) {
    if (selection == "Y") {
        aLs('CollectCoverageInformation1_PriorCoverages').visibility = "visible";
    }
    else {
        aLs('CollectCoverageInformation1_PriorCoverages').visibility = "hidden";
    }

    //document.all.CollectCoverageInformation1_NextScr.disabled=false;

}


function nameDefined(ckie, nme) {
    var splitValues
    var i
    for (i = 0; i < ckie.length; ++i) {
        splitValues = ckie[i].split("=");
        if (splitValues[0] == nme) return true
    }
    return false
}

function delBlanks(strng) {
    var result = ""
    var i
    var chrn
    for (i = 0; i < strng.length; ++i) {
        chrn = strng.charAt(i)
        if (chrn != " ") result += chrn
    }
    return result
}

function getCookieValue(ckie, nme) {
    var splitValues
    var i
    for (i = 0; i < ckie.length; ++i) {
        splitValues = ckie[i].split("=")
        if (splitValues[0] == nme) return splitValues[1]
    }
    return ""
}


function testCookie(cname, cvalue) {
    var cookie = document.cookie
    var chkdCookie = delBlanks(cookie)
    var nvpair = chkdCookie.split(";")
    if (nameDefined(nvpair, cname)) {
        tvalue = getCookieValue(nvpair, cname)
        if (tvalue == cvalue) return true
        else return false
    }
    else
        return false;
}

function DisableQuestion(radiobuttonid, questioncontrolidtodisable) {
    var radbut = document.getElementById(radiobuttonid);
    var strTemp = (radbut.value).substring(0, 3);
    if (strTemp.toUpperCase() == "NO") {
        // disable questions 2 and 3

        //find control
        var ctrl = document.getElementById(questioncontrolidtodisable);

        //disable it
        ctrl.enabled = false;
    }
}


// Following functions control the medical questions process
function UserResponse1(placeholderid, radioboxselectedvalue, conditionclientids, thirdPlaceHolderid) {
    var placeholder = document.getElementById(placeholderid)
    var thirdplaceholder = document.getElementById(thirdPlaceHolderid)
    var strTemp = radioboxselectedvalue
    if (strTemp.toUpperCase() == "YES") {
        placeholder.style.display = ""
    }
    else {
        if (placeholder.style.display == "none") {
            placeholder.style.display = "none"
            thirdplaceholder.style.display = "none"
        }
        if (placeholder.style.display == "") {
            placeholder.style.display = "none"
            thirdplaceholder.style.display = "none"
        }

        //clear all selections below
        if (conditionclientids != "") {
            var index = conditionclientids.indexOf("*")
            var start = 0
            var found = false

            while (index >= 0) {
                if (document.getElementById(conditionclientids.substring(start, index)) != null) {
                    document.getElementById(conditionclientids.substring(start, index)).checked = false;
                }
                start = index + 1;
                index = conditionclientids.indexOf("*", start);
            }

            if (document.getElementById(conditionclientids.substring(start)) != null) {
                document.getElementById(conditionclientids.substring(start)).checked = false;
            }
        }
    }


}
function UserResponse2(placeholderid, conditionclientids, radioboxselectedvalue) {

    var placeholder = document.getElementById(placeholderid)

    //var radbut = document.getElementById(radioboxselectedvalue)
    //var strTemp = (radbut.value).substring(0,3)
    var strTemp = radioboxselectedvalue

    if (strTemp.toUpperCase() == "YES") {
        if (placeholder.style.display == "none") {
            placeholder.style.display = ""
        }

        else {
            placeholder.style.display = ""
        }
    }
    else {
        if (placeholder.style.display == "none") {
            placeholder.style.display = "none"

        }
        if (placeholder.style.display == "") {
            placeholder.style.display = "none"

        }

        //clear all selections below
        if (conditionclientids != "") {
            var index = conditionclientids.indexOf("*")
            var start = 0
            var found = false

            while (index >= 0) {
                if (document.getElementById(conditionclientids.substring(start, index)) != null) {
                    document.getElementById(conditionclientids.substring(start, index)).checked = false;
                }
                start = index + 1;
                index = conditionclientids.indexOf("*", start);
            }

            if (document.getElementById(conditionclientids.substring(start)) != null) {
                document.getElementById(conditionclientids.substring(start)).checked = false;
            }
        }
    }

}
function JetUserResponse1(placeholderid, radioboxselectedvalue, thirdPlaceHolderid) {

    var placeholder = document.getElementById(placeholderid)
    var thirdplaceholder = document.getElementById(thirdPlaceHolderid)
    //var radbut = document.getElementById(radioboxselectedvalue)
    var strTemp = radioboxselectedvalue
    if (strTemp.toUpperCase() == "YES") {
        if (placeholder.style.display == "none") {
            placeholder.style.display = ""
        }

        else {
            placeholder.style.display = ""
        }
    }
    else {
        if (placeholder.style.display == "none") {
            placeholder.style.display = "none"
            thirdplaceholder.style.display = "none"
        }
        if (placeholder.style.display == "") {
            placeholder.style.display = "none"
            thirdplaceholder.style.display = "none"
        }
    }


}

function JetUserResponse2(placeholderid, radioboxselectedvalue) {

    var placeholder = document.getElementById(placeholderid)

    var radbut = document.getElementById(radioboxselectedvalue)
    var strTemp = (radbut.value).substring(0, 3)


    if (strTemp.toUpperCase() == "YES") {
        if (placeholder.style.display == "none") {
            placeholder.style.display = ""
        }

        else {
            placeholder.style.display = ""
        }
    }
    else {
        if (placeholder.style.display == "none") {
            placeholder.style.display = "none"

        }
        if (placeholder.style.display == "") {
            placeholder.style.display = "none"

        }
    }

}

function AppliesToResponse(placeholderid, chkboxid, conditionclientids) {

    var placeholder = document.getElementById(placeholderid)
    var chkbox = document.getElementById(chkboxid)
    if (chkbox.checked) {
        placeholder.style.display = ""
    }
    else {
        placeholder.style.display = "none"

        //clear all selections below
        if (conditionclientids != "") {
            var index = conditionclientids.indexOf("*")
            var start = 0
            var found = false

            while (index >= 0) {
                if (document.getElementById(conditionclientids.substring(start, index)) != null) {
                    document.getElementById(conditionclientids.substring(start, index)).checked = false;
                }
                start = index + 1;
                index = conditionclientids.indexOf("*", start);
            }

            if (document.getElementById(conditionclientids.substring(start)) != null) {
                document.getElementById(conditionclientids.substring(start)).checked = false;
            }
        }
    }
}


function showHideIDQLevelControls(applicantQuestionplaceholderid, subQuestionplaceholderid, radioboxid, conditionclientids, thirdPlaceHolderid) {

    var applicantQuestionplaceholder = document.getElementById(applicantQuestionplaceholderid)
    var SubQuestionplaceholder = document.getElementById(subQuestionplaceholderid)
    var thirdplaceholder = document.getElementById(thirdPlaceHolderid)
    var radiobox = document.getElementById(radioboxid)

    //Applicantlevel yesRadionbtn
    if (radiobox.checked) {

        if (SubQuestionplaceholder != null) { SubQuestionplaceholder.style.display = "" }
        if (thirdplaceholder != null) {
            thirdplaceholder.style.display = ""
            var primaryLevelCollection = applicantQuestionplaceholder.getElementsByTagName("input")
            var idqLevelCollection = thirdplaceholder.getElementsByTagName("input")

            //Initially set visibility as hide for all IdqLevel applicants
            for (var j = 0; j < idqLevelCollection.length; j++) {
                var idqLevelid = idqLevelCollection[j].id
                if (idqLevelid.indexOf("YesRadiobtn") != -1) {
                    var idqYesRadioBtn = document.getElementById(idqLevelCollection[j].id)
                    var tbl = document.getElementById(idqYesRadioBtn.parentNode.attributes["placeholderTable"].value)
                    tbl.style.visibility = "hidden"
                    tbl.style.display = "none"
                   
                }
            }

            //Set visibility as visible for IdqLevel applicant if applicable
            for (var i = 0; i < primaryLevelCollection.length; i++) {
                var primaryLevelid = primaryLevelCollection[i].id
                if (primaryLevelid.indexOf("YesRadiobtn") != -1) {
                    var primaryYesBtn = document.getElementById(primaryLevelCollection[i].id)

                    for (var j = 0; j < idqLevelCollection.length; j++) {

                        var idqLevelid = idqLevelCollection[j].id
                        if (idqLevelid.indexOf("YesRadiobtn") != -1) {

                            var idqYesRadioBtn = document.getElementById(idqLevelCollection[j].id)

                            var attributeVal = idqYesRadioBtn.parentNode.attributes["applicantid"].value
                            if (attributeVal != null && primaryYesBtn.checked) {

                                // Display IDQs radio buttons
                                if (attributeVal == primaryYesBtn.parentNode.attributes["applicantid"].value) {
                                    var tbl = document.getElementById(idqYesRadioBtn.parentNode.attributes["placeholderTable"].value)
                                    tbl.style.visibility = "visible"
                                    tbl.style.display = ""
                                }
                            }
                        }
                    }
                }
            }
        }
 }
    else {
        // Check if any applicantlevel yesradioBtn is checked
        var anyYesRadiobtnChecked = false

        if (SubQuestionplaceholder != null) {

            var oCollection = applicantQuestionplaceholder.getElementsByTagName("input")

            for (var i = 0; i < oCollection.length; i++) {
                var str = oCollection[i].id
                if (str.indexOf("YesRadiobtn") != -1) {

                    if (document.getElementById(oCollection[i].id).checked) {
                        anyYesRadiobtnChecked = true
                        break
                    }
                }
            }
            //If all applicantlevel "NO" radio buttons checked
            if (anyYesRadiobtnChecked == false) {
                SubQuestionplaceholder.style.display = "none"
                if (thirdplaceholder != null) {
                    thirdplaceholder.style.display = "none"
                }
            }
            if (thirdplaceholder != null) {

                var oCollection = thirdplaceholder.getElementsByTagName("input")
                for (var i = 0; i < oCollection.length; i++) {
                    var str = oCollection[i].id
                    if (str.indexOf("YesRadiobtn") != -1 ) {
                        var yesRadioBtn = document.getElementById(oCollection[i].id)
                        var attributeVal = yesRadioBtn.parentNode.attributes["applicantid"].value
                        if (attributeVal != null && attributeVal == radiobox.parentNode.attributes["applicantid"].value) {
                            var tbl = document.getElementById(yesRadioBtn.parentNode.attributes["placeholderTable"].value)
                            var conditionclientids = yesRadioBtn.parentNode.attributes["conditionclientids"].value
                            var ConditionsPanel = yesRadioBtn.parentNode.attributes["ConditionsPanel"].value
                            //Clear all selection for the IDQs
                            yesRadioBtn.checked = false
                            AppliesToResponse(ConditionsPanel, oCollection[i].id, conditionclientids)
                            tbl.style.visibility = "hidden"
                            tbl.style.display = "none"
                            break
                        }
                    }
                }
            }
        }
    }
}

function AppliesToResponseForIDQs(placeholderid, radioBoxSelectedValue, conditionclientids) {
    var placeholder = document.getElementById(placeholderid)
    var strTemp = radioBoxSelectedValue
    if (strTemp.toUpperCase() == "YES") {
        placeholder.style.display = ""
    }

    else {
        placeholder.style.display = "none"

        //clear all selections below
        if (conditionclientids != "") {
            var index = conditionclientids.indexOf("*")
            var start = 0
            var found = false

            while (index >= 0) {
                if (document.getElementById(conditionclientids.substring(start, index)) != null) {
                    document.getElementById(conditionclientids.substring(start, index)).checked = false;
                }
                start = index + 1;
                index = conditionclientids.indexOf("*", start);
            }

            if (document.getElementById(conditionclientids.substring(start)) != null) {
                document.getElementById(conditionclientids.substring(start)).checked = false;
            }
        }
    }
}

function NoMedicationScript(val0, val1, val2, val3, val4, val5, val6) {
    var panel1 = document.getElementById(val1)
    var panel2 = document.getElementById(val2)
    var ADDMedicationCB = document.getElementById(val5)
    var NoMedicationCB = document.getElementById(val0)
    var panel5 = document.getElementById(val6);
    if (NoMedicationCB.checked) {
        panel1.style.display = "none"
        panel2.style.display = "none"

        ADDMedicationCB.style.visibility = "hidden"
        var panel3 = document.getElementById(val3);
        var panel4 = document.getElementById(val4);

        panel3.style.display = "none"
        panel4.style.display = "none"
        panel5.style.display = "none"

    }
    else {
        panel1.style.display = ""
        panel2.style.display = ""
        ADDMedicationCB.style.visibility = "visible"
        ADDMedicationCB.checked = false
        panel5.style.display = ""

    }
}
function AddMedicationScript(val0, val1, val2) {
    var panel3 = document.getElementById(val1)
    var panel4 = document.getElementById(val2)
    var ADDMedicationCB = document.getElementById(val0)
    if (ADDMedicationCB.checked) {
        panel3.style.display = ""
        panel4.style.display = ""

    }
    else {
        panel3.style.display = "none"
        panel4.style.display = "none"
    }
}

function CurrentStatusScript(val0, val1) {
    var curStatusTB = document.getElementById(val0)
    var curStatusRBL = document.getElementById(val1)
    var displayst = false
    for (var i = 0; i < curStatusRBL.cells.length; i++) {
        if (curStatusRBL.cells[i].firstChild.checked && curStatusRBL.cells[i].firstChild.value == '5') {
            displayst = true
            curStatusTB.style.display = ""
        }

    }
    if (!displayst) {
        curStatusTB.style.display = "none"
    }
}


function CurrentTextBoxDisabledScript(val0, val1) {
    var currentTB = document.getElementById(val0)
    var currentCB = document.getElementById(val1)
    if (currentCB.checked) {
        currentTB.innerHTML = ""
        currentTB.disabled = true

    }
    else {
        currentTB.disabled = false

    }


}

function AddMedScript(val0, val1) {
    var AddMedicationCheckBox = document.getElementById(val0)
    var Table = document.getElementById(val1)

    var ilen = AddMedicationCheckBox.id.length
    var strNum = AddMedicationCheckBox.id.substring((ilen - 1), ilen)
    var strName = AddMedicationCheckBox.id.substring(0, (ilen - 1))

    var iTableLen = Table.id.length
    var strTableNum = Table.id.substring((iTableLen - 1), iTableLen)
    var strTableName = Table.id.substring(0, (iTableLen - 1))


    if (AddMedicationCheckBox.checked) {
        Table.style.display = ""
        for (var i = (parseInt(strNum) + 1); i < 4; i = i + 1) {
            var findCB = document.getElementById(strName + i)
            findCB.checked = false
        }
    }
    else {
        Table.style.display = "none"
        for (var i = (parseInt(strNum) + 1); i < 4; i = i + 1) {
            var findCB = document.getElementById(strName + i)
            findCB.checked = false
        }
        for (var j = (parseInt(strTableNum) + 1); j < 5; j = j + 1) {
            var findTable = document.getElementById(strTableName + j)
            findTable.style.display = "none"
        }
    }
}
function NoMedScript(val0, val1, val2, val3, val4, val5, val6) {
    var Table2, Table3, Table4
    var Table1 = document.getElementById(val1)
    var Table2 = document.getElementById(val2)
    var Table3 = document.getElementById(val3)
    var Table4 = document.getElementById(val4)
    var NoMedicationCB = document.getElementById(val0)
    var TableMed = document.getElementById(val5)
    var addMedCB = document.getElementById(val6)

    if (NoMedicationCB.checked) {
        Table1.style.display = "none"
        Table2.style.display = "none"
        Table3.style.display = "none"
        Table4.style.display = "none"
        TableMed.style.display = "none"
        addMedCB.checked = false;
    }
    else {
        Table1.style.display = ""
        TableMed.style.display = ""
    }
}

function EnableDisableRelatedQuestionPanel(val0, val1, val2, val3, val4, val5, val6, lbl2, ques2, lbl3, ques3, lbl4, ques4, otherApplicant) {
    var currentRadioButtionList1 = document.getElementById(val0)
    var label2 = document.getElementById(lbl2)
    var question2 = document.getElementById(ques2)
    var label3 = document.getElementById(lbl3)
    var question3 = document.getElementById(ques3)
    var label4 = document.getElementById(lbl4)
    var question4 = document.getElementById(ques4)
    var panelq2 = document.getElementById(val1)
    var panelq3 = document.getElementById(val2)
    var panelq4 = document.getElementById(val3)
    var otherappl
    var yesradiobuttonotherappl
    otherappl = document.getElementById(otherApplicant)
    if (otherappl != undefined && otherappl != null) {
        yesradiobuttonotherappl = document.getElementById(otherappl.id + "_0")
    }
    var yesradiobutton = document.getElementById(currentRadioButtionList1.id + "_0")
    if (yesradiobutton.checked) {
        label2.removeAttribute("disabled")
        question2.removeAttribute("disabled")
        label3.removeAttribute("disabled")
        question3.removeAttribute("disabled")
        label4.removeAttribute("disabled")
        question4.removeAttribute("disabled")
        label2.style.color = "black";
        label3.style.color = "black";
        label4.style.color = "black";
        question2.style.color = "black";
        question3.style.color = "black";
        question4.style.color = "black";
        panelq2.disabled = false
        panelq3.disabled = false
        panelq4.disabled = false
        disableRadioButtonList(val4, false)
        disableRadioButtonList(val5, false)
        disableRadioButtonList(val6, false)
    }
    else {
        label2.setAttribute("disabled", "disabled")
        label3.setAttribute("disabled", "disabled")
        label4.setAttribute("disabled", "disabled")
        label2.style.color = "gray"
        label3.style.color = "gray"
        label4.style.color = "gray"
        if (yesradiobuttonotherappl != null && !yesradiobuttonotherappl.checked) {
            question2.setAttribute("disabled", "disabled")
            question3.setAttribute("disabled", "disabled")
            question4.setAttribute("disabled", "disabled")
            question2.style.color = "gray"
            question3.style.color = "gray"
            question4.style.color = "gray"
        }
        if (otherappl == undefined) {
            question2.setAttribute("disabled", "disabled")
            question3.setAttribute("disabled", "disabled")
            question4.setAttribute("disabled", "disabled")
            question2.style.color = "gray"
            question3.style.color = "gray"
            question4.style.color = "gray"
        }
        panelq2.disabled = true
        panelq3.disabled = true
        panelq4.disabled = true
        disableRadioButtonList(val4, true)
        disableRadioButtonList(val5, true)
        disableRadioButtonList(val6, true)
    }
}
function EndDateMedicationCheckBoxScript(val0, val1) {
    var currentCB = document.getElementById(val0)
    var currentTB = document.getElementById(val1 + "_DateTB")
    if (currentCB.checked) {
        currentTB.value = ""
        currentTB.disabled = true
    }
    else {
        currentTB.disabled = false
    }

}

function ValidateWordcount(evt, val0) {
    var currentTB = document.getElementById(val0)
    var keyCode = evt.which ? evt.which : evt.keyCode;
    if (keyCode == 46 || keyCode == 8)// 46 and 8 or delete and backspace char.
    {
        evt.returnValue = true
        return
    }
    else if (currentTB.value.length > 999) {
        if (keyCode == 46 || keyCode == 8) {
            evt.returnValue = true
            return
        }
        else {
            evt.returnValue = false
            return
        }
    }

    else {
        evt.returnValue = true
        return
    }
}
function CheckUncheckAll(spanChk) {
    var xState = spanChk.checked;
    var theBox = spanChk;
    var elm = theBox.form.elements;
    for (i = 0; i < elm.length; i++)
        if (elm[i].type == "checkbox" && elm[i].id != theBox.id) {
        elm[i].checked = xState;
    }
}
function AllowNumbers(evt) // event on key down
{
    var keyCode = evt.keyCode ? evt.keyCode : evt.charCode
    // 35-hOME,36-end,8-BackSpace,46-Delete,191-/,9-TabKey
    if (keyCode == 35 || keyCode == 36 || keyCode == 8 || keyCode == 9 || keyCode == 191) {
        evt.returnValue = true
        return true
    }
    if (keyCode > 47 && keyCode < 58) {
        evt.returnValue = true
        return true
    }
    evt.returnValue = false
    return false
}


function FormatTelephone(TextboxId, evt) {
    var keyCode = evt.keyCode ? evt.keyCode : evt.charCode
    if (!(keyCode == 8 || keyCode == 46)) {
        var CurrentTB = document.getElementById(TextboxId)
        var TBText = CurrentTB.value
        if (TBText != null) {
            if (TBText.length == 1) {
                CurrentTB.value = "(" + TBText
            }
            if (TBText.length == 4) {
                CurrentTB.value = TBText + ") "
            }
            if (TBText.length == 9) {
                CurrentTB.value = TBText + "-"
            }
        }
    }
}

function FormatPhoneNumber(TextboxId) {
    var CurrentTB = document.getElementById(TextboxId)
    var TBText = CurrentTB.value.replace(/\D/g, "")
    var FormatedTBText = new Array()
    var TBFormatedText = new String()
    if (TBText != null) {
        var itemp = 0
        for (var i = 0; i < TBText.length; i++) {
            if (!(isNaN(parseInt(TBText.substring(i, i + 1))))) {
                FormatedTBText[itemp] = TBText.substring(i, i + 1)
                itemp++
            }
        }
        var icount = 0
        CurrentTB.value = ""
        for (var j = 0; j < FormatedTBText.length; j++) {
            icount++
            CurrentTB.value = CurrentTB.value + FormatedTBText[j]
            if (icount == 1) {
                CurrentTB.value = "(" + CurrentTB.value
            }
            if (icount == 3) {
                CurrentTB.value = CurrentTB.value + ") "
            }
            if (icount == 6) {
                CurrentTB.value = CurrentTB.value + "-"
            }
        }
    }
}
function FormatSSNNumber(TextboxId, evt) {
    var keyCode = evt.keyCode ? evt.keyCode : evt.charCode
    if (!(keyCode == 8 || keyCode == 46)) {
        var CurrentTB = document.getElementById(TextboxId)
        var TBText = CurrentTB.value
        if (TBText != null) {
            if (TBText.length == 3) {
                CurrentTB.value = TBText + "-"
            }
            if (TBText.length == 6) {
                CurrentTB.value = TBText + "-"
            }
        }
    }
}

function FormatSSN(TextboxId) {
    var CurrentTB = document.getElementById(TextboxId)
    var TBText = CurrentTB.value.replace(/\D/g, "")
    var FormatedTBText = new Array()
    var TBFormatedText = new String()
    if (TBText != null) {
        var itemp = 0
        for (var i = 0; i < TBText.length; i++) {
            if (!(isNaN(parseInt(TBText.substring(i, i + 1))))) {
                FormatedTBText[itemp] = TBText.substring(i, i + 1)
                itemp++
            }
        }
        var icount = 0
        CurrentTB.value = ""
        for (var j = 0; j < FormatedTBText.length; j++) {
            icount++
            CurrentTB.value = CurrentTB.value + FormatedTBText[j]
            if (icount == 3)
                CurrentTB.value = CurrentTB.value + "-"
            if (icount == 5)
                CurrentTB.value = CurrentTB.value + "-"
        }
    }
}
function FormatPartialDateNumber(TextboxId, evt) {
    var keyCode = evt.keyCode ? evt.keyCode : evt.charCode
    if (!(keyCode == 8 || keyCode == 46)) {
        var CurrentTB = document.getElementById(TextboxId)
        var TBText = CurrentTB.value
        if (TBText != null) {
            if (TBText.length == 2) {
                CurrentTB.value = TBText + "/"
            }
        }
    }
}

function FormatPartialDate(TextboxId) {
    var CurrentTB = document.getElementById(TextboxId)
    var TBText = CurrentTB.value.replace(/\D/g, "")
    var FormatedTBText = new Array()
    var TBFormatedText = new String()
    if (TBText != null) {
        var itemp = 0
        for (var i = 0; i < TBText.length; i++) {
            if (!(isNaN(parseInt(TBText.substring(i, i + 1))))) {
                FormatedTBText[itemp] = TBText.substring(i, i + 1)
                itemp++
            }
        }
        var icount = 0
        CurrentTB.value = ""
        for (var j = 0; j < FormatedTBText.length; j++) {
            icount++
            CurrentTB.value = CurrentTB.value + FormatedTBText[j]
            if (icount == 2)
                CurrentTB.value = CurrentTB.value + "/"
        }
    }
}
function IsNumber(evt) {
    var keyCode;
    if (document.all) {
        var keyCode = evt.keyCode ? evt.keyCode : evt.charCode
    }
    else {
        keyCode = evt.which ? evt.which : evt.charCode
    }
    if ((keyCode > 47 && keyCode < 58) || keyCode == 0 || keyCode == 8) {
        evt.returnValue = true
        return true
    }

    evt.returnValue = false
    return false

}
function validateNonNumber(evt) {
    var keyCode;
    if (document.all) {
        var keyCode = evt.keyCode ? evt.keyCode : evt.charCode
    }
    else {
        keyCode = evt.which ? evt.which : evt.charCode
    }
    if ((keyCode >= 47 && keyCode < 58) || keyCode == 0 || keyCode == 8) {
        evt.returnValue = true
        return true
    }

    evt.returnValue = false
    return false

}
function FormatDate(TextboxId, evt) {
    var CurrentTB = document.getElementById(TextboxId)
    var pos = getCaretPosition(CurrentTB)
    if (pos == 1 || pos == 4 || pos == 5 || pos == 2 || CurrentTB.value.length == 10) {
        return
    }
    var keyCode = evt.keyCode ? evt.keyCode : evt.charCode
    var TBText = CurrentTB.value
    var FormatedTBText
    // 35-hOME, 36->end, 8->BackSpace, 47->'/', 46->Delete, 37-> leftarrow,  39->rightarrow, 16-Shift+Tabkey.
    if (TBText != null && !(keyCode == 8 || keyCode == 47 || keyCode == 37 || keyCode == 39 || keyCode == 46 || keyCode == 9 || keyCode == 16)) {
        var arrayofDate = TBText.split("/")
        if (arrayofDate[0] != null) {
            if (arrayofDate[0].length == 2) {
                FormatedTBText = arrayofDate[0] + "/"
            }
            else if (arrayofDate[0].length == 1 && arrayofDate[1] != null) {
                FormatedTBText = 0 + arrayofDate[0] + "/"
            }
            else {
                FormatedTBText = arrayofDate[0]
            }
            CurrentTB.value = FormatedTBText
        }
        if (arrayofDate[1] != null) {
            if (arrayofDate[1].length == 2) {
                FormatedTBText = FormatedTBText + arrayofDate[1] + "/"
            }
            else if (arrayofDate[1].length == 1 && arrayofDate[2] != null) {
                FormatedTBText = FormatedTBText + 0 + arrayofDate[1] + "/"
            }
            else if (arrayofDate[1].length == 1 && arrayofDate[2] == null) {
                FormatedTBText = FormatedTBText + arrayofDate[1]
            }
            else {
                FormatedTBText = FormatedTBText
            }
            CurrentTB.value = FormatedTBText
        }
        if (arrayofDate[2] != null) {
            FormatedTBText = FormatedTBText + arrayofDate[2].substring(0, 4)
            CurrentTB.value = FormatedTBText
        }

    }
}
// onkeydown
function DateFormatter(TextboxId, evt) {
    var CurrentTB = document.getElementById(TextboxId)
    var pos = getCaretPosition(CurrentTB)
    if (pos == 1 || pos == 4) {
        return
    }
    var keyCode = evt.keyCode ? evt.keyCode : evt.charCode
    if (!(keyCode == 8 || keyCode == 47 || keyCode == 9 || keyCode == 16)) {
        if (CurrentTB != null) {
            if (CurrentTB.value.length == 2) {
                var arrayofDate = CurrentTB.value.split("/")
                if (arrayofDate[0].length == 2) {
                    CurrentTB.value = arrayofDate[0] + "/"
                }
            }
            if (CurrentTB.value.length == 5) {
                var arrayofDate = CurrentTB.value.split("/")
                if (arrayofDate[1].length == 2) {
                    CurrentTB.value = arrayofDate[0] + "/" + arrayofDate[1] + "/"
                }
            }
        }
    }
    return CurrentTB
}

function getCaretPosition(objTextBox) {
    var i = objTextBox.value.length + 1;
    if (objTextBox.createTextRange) {
        objCaret = document.selection.createRange().duplicate();
        while (objCaret.parentElement() == objTextBox &&
                        objCaret.move("character", 1) == 1) --i;
    }
    return i;
}
function disableRadioButtonList(val0, val1) {
    var isIE = (navigator.appName.indexOf("Microsoft") != -1);
    var panelq2 = document.getElementById(val0)
    if (isIE) {
        if (panelq2.rows != null) {
            for (var i = 0; i < panelq2.rows.length; i++) {
                for (var j = 0; j < panelq2.rows[i].cells.length; j++) {
                    if (typeof panelq2.rows[i].cells[j].firstChild.firstChild == 'object') {
                        panelq2.rows[i].cells[j].firstChild.disabled = val1;
                        panelq2.rows[i].cells[j].firstChild.firstChild.disabled = val1;
                        if (val1) { panelq2.rows[i].cells[j].firstChild.firstChild.checked = !val1; }
                    }
                    else {
                        panelq2.rows[i].cells[j].firstChild.disabled = val1;
                        if (val1) { panelq2.rows[i].cells[j].firstChild.checked = !val1; }
                    }
                }
            }
        }
    }
    else {
        var inputs = panelq2.getElementsByTagName("input");
        for (var i = 0; i < inputs.length; i++) {
            if (inputs[i].type == "radio") {
                inputs[i].disabled = val1;
                if (val1) { inputs[i].checked = !val1; }
            }
        }
    }
}

function EnableDisableMedicationControl(clientid, val0, val1, val2, val3) {
    var isIE = (navigator.appName.indexOf("Microsoft") != -1  && navigator.appVersion.indexOf("MSIE 6") != -1);
    var cb = document.getElementById(clientid);
    var id = clientid.split(val0)
    var arrayoftable = val1.split(";");
    var arrayoftable2 = val2.split(";");
    if (cb.checked) {
        if (val0 == "NoMED") {
            for (var j = 0; j < arrayoftable.length - 1; j++) {
                (document.getElementById(arrayoftable[j])).style.display = "none";
            }
            document.getElementById(id[0] + "MEDCB1").checked = false
            document.getElementById(id[0] + "MEDCB2").checked = false
            document.getElementById(id[0] + "MEDCB3").checked = false
        }
        if (val0 == "MEDCB1") {
            for (var j = 0; j < arrayoftable.length - 1; j++) {
                (document.getElementById(arrayoftable[j])).style.display = "";
            }
        }
        if (val0 == "MEDCB2") {
            for (var j = 0; j < arrayoftable.length - 1; j++) {
                (document.getElementById(arrayoftable[j])).style.display = "";
            }
            // Medication 3	
        }
        if (val0 == "MEDCB3") {
            for (var j = 0; j < arrayoftable.length - 1; j++) {
                (document.getElementById(arrayoftable[j])).style.display = "";
            }
            // Medication 4		
        }
    }
    else {
        if (val0 == "NoMED") {
            for (var j = 0; j < arrayoftable2.length - 1; j++) {
                (document.getElementById(arrayoftable2[j])).style.display = "";
            }
        }
        if (val0 == "MEDCB1") {
            for (var j = 0; j < arrayoftable2.length - 1; j++) {
                (document.getElementById(arrayoftable2[j])).style.display = "none";
            }
            document.getElementById(id[0] + "MEDCB2").checked = false
            document.getElementById(id[0] + "MEDCB3").checked = false
        }
        if (val0 == "MEDCB2") {
            for (var j = 0; j < arrayoftable2.length - 1; j++) {
                (document.getElementById(arrayoftable2[j])).style.display = "none";
            }
            document.getElementById(id[0] + "MEDCB3").checked = false
        }
        if (val0 == "MEDCB3") {
            for (var j = 0; j < arrayoftable2.length - 1; j++) {
                (document.getElementById(arrayoftable2[j])).style.display = "none";
            }
        }
    }
}

function DisableorEnableMedicationEndDate(val0, val1, val4, val5, val2, val3) {
    var isIE = (navigator.appName.indexOf("Microsoft") != -1 && navigator.appVersion.indexOf("MSIE 6") != -1);
    var cb = document.getElementById(val0);
    var enddate = document.getElementById(val1);
    var enddateMonth = document.getElementById(val4);
    var enddateYear = document.getElementById(val5);

    if (cb.checked) {
        enddate.disabled = true;
        enddateMonth.disabled = true;
        enddateYear.disabled = true;
        enddateYear.options.selectedIndex = 0;
        enddateMonth.options.selectedIndex = 0;
        if (isIE) {
            ValidatorEnable(document.getElementById(val1 + "_rvMonth"), false)
            ValidatorEnable(document.getElementById(val1 + "_rvyear"), false)
        }
        enddate.setAttribute('controlisunique', 'false')
        var val = enddate.getAttribute("controlisunique")
    }
    else {
        enddate.disabled = false;
        enddateMonth.disabled = false;
        enddateYear.disabled = false;
        if (isIE) {
            ValidatorEnable(document.getElementById(val1 + "_rvMonth"), true)
            ValidatorEnable(document.getElementById(val1 + "_rvyear"), true)
        }
        enddate.getAttribute("controlisunique", "true")
    }
}

function DisableorEnableTextBox(val0, val1) {
    var rb = document.getElementById(val0);
    var txt = document.getElementById(val1);
    if (rb.checked) {
        txt.style.display = "";
    }
    else {
        txt.style.display = "none";
    }
}
function DisableorEnableRadioTextBox(val0, val1) {
    var rb = document.getElementById("RadioTextBoxList1_" + val0);
    var txt = document.getElementById("RadioTextBoxList1_" + val1);
    if (rb.checked && txt != null) {
        txt.style.display = "";
    }
    var tbl = document.getElementsByName("RadioTextBoxList1:radiobuttonListGroupName");
    for (i = 0; i < tbl.length; i++) {
        if (tbl[i].checked) {
            var txttemp = tbl[i].id.substring(tbl[i].id.length - 1, tbl[i].id.length)
            var tb = document.getElementById("RadioTextBoxList1_txtBox" + txttemp);
            if (tb != null) {
                tb.style.display = "";
            }
        }
        else {
            var txttemp = tbl[i].id.substring(tbl[i].id.length - 1, tbl[i].id.length)
            var tb = document.getElementById("RadioTextBoxList1_txtBox" + txttemp);
            if (tb != null) {
                tb.style.display = "none";
            }
        }
    }

}

function AllowNumbers(evt) // event on key down
{
    var keyCode = evt.keyCode ? evt.keyCode : evt.charCode
    // 35-hOME,36-end,8-BackSpace,46-Delete,191-/,9-TabKey
    if (keyCode == 35 || keyCode == 36 || keyCode == 8 || keyCode == 9 || keyCode == 191) {
        evt.returnValue = true
        return true
    }
    if (keyCode > 47 && keyCode < 58) {
        evt.returnValue = true
        return true
    }
    evt.returnValue = false
    return false
}


function FormatTelephone(TextboxId, evt) {
    var keyCode = evt.keyCode ? evt.keyCode : evt.charCode
    if (!(keyCode == 8 || keyCode == 46)) {
        var CurrentTB = document.getElementById(TextboxId)
        var TBText = CurrentTB.value
        if (TBText != null) {
            if (TBText.length == 1) {
                CurrentTB.value = "(" + TBText
            }
            if (TBText.length == 4) {
                CurrentTB.value = TBText + ") "
            }
            if (TBText.length == 9) {
                CurrentTB.value = TBText + "-"
            }
        }
    }
}

function FormatPhoneNumber(TextboxId) {
    var CurrentTB = document.getElementById(TextboxId)
    var TBText = CurrentTB.value.replace(/\D/g, "")
    var FormatedTBText = new Array()
    var TBFormatedText = new String()
    if (TBText != null) {
        var itemp = 0
        for (var i = 0; i < TBText.length; i++) {
            if (!(isNaN(parseInt(TBText.substring(i, i + 1))))) {
                FormatedTBText[itemp] = TBText.substring(i, i + 1)
                itemp++
            }
        }
        var icount = 0
        CurrentTB.value = ""
        for (var j = 0; j < FormatedTBText.length; j++) {
            icount++
            CurrentTB.value = CurrentTB.value + FormatedTBText[j]
            if (icount == 1) {
                CurrentTB.value = "(" + CurrentTB.value
            }
            if (icount == 3) {
                CurrentTB.value = CurrentTB.value + ") "
            }
            if (icount == 6) {
                CurrentTB.value = CurrentTB.value + "-"
            }
        }
    }
}

function EnableDisableCheckBoxFreeForm(val0, val1) {
    var cb = document.getElementById(val0)
    var txt = document.getElementById(val1)
    var txtbox = document.getElementById(val0.replace(/CheckBoxFreeFormCheckBox/, "CheckBoxFreeFormTextBox"))
    //if condition added as this method has been used with radio button also
    if (val0 != txtbox.id) {
        txtbox.value = "";
    }
    if (cb.checked) {
        txt.style.display = "";
    }
    else {
        txt.style.display = "none";
    }
}

function ValidateFreeFormControl(sender, args) {
    var cb = document.getElementById(sender.getAttribute("checkboxid"))
    var txt = document.getElementById(sender.getAttribute("textBoxid"))
    if (cb.checked || txt.value.length > 0) {
        args.IsValid = true;
    }
    else {
        args.IsValid = false;
    }
}

function ValidateFreeFormControl(sender, args) {
    var cb = document.getElementById(sender.getAttribute("checkboxid"))
    var txt = document.getElementById(sender.getAttribute("textBoxid"))
    if (cb.checked || txt.value.length > 0) {
        args.IsValid = true;
    }
    else {
        args.IsValid = false;
    }
}

function ValidateFreeFormControl(sender, args) {
    var cb = document.getElementById(sender.getAttribute("checkboxid"))
    var txt = document.getElementById(sender.getAttribute("textBoxid"))
    if (cb.checked || txt.value.length > 0) {
        args.IsValid = true;
    }
    else {
        args.IsValid = false;
    }
}

function CheckBoxFreeFormClientSideValidation(sender, args) {
    var cb = document.getElementById(sender.getAttribute("checkboxid"))
    var txt = document.getElementById(sender.getAttribute("textBoxid"))
    if (cb.checked && txt.value.length > 0) {
        args.IsValid = true;
    }
    else if ((!cb.checked) && txt.value.length == 0) {
        args.IsValid = true;
    }
    else {
        args.IsValid = false;
    }
}

function RadioButtonFreeFormClientSideValidation(sender, args) {
    var rb = document.getElementById(sender.getAttribute("radiobuttonid"))
    var txt = document.getElementById(sender.getAttribute("textBoxid"))
    if (rb.checked && txt.value.length > 0) {
        args.IsValid = true;
    }
    else if ((!rb.checked) && txt.value.length == 0) {
        args.IsValid = true;
    }
    else {
        args.IsValid = false;
    }
}

function RadioButtonFreeFormListClientSideScript(val0) {
    var rbffArray = val0.split("#")
    for (i = 0; i <= rbffArray.length - 1; i++) {
        var rbffArray1 = rbffArray[i].split(";")
        var rd = document.getElementById(rbffArray1[0])
        var tableid = document.getElementById(rbffArray1[1])
        if (tableid != null) {
            EnableDisableCheckBoxFreeForm(rbffArray1[0], rbffArray1[1]);
        }
    }
}

function EnableDisableCheckBoxPartialDate(val0, val1) {
    var isIE = (navigator.appName.indexOf("Microsoft") != -1 && navigator.appVersion.indexOf("MSIE 6") != -1);
    var cb = document.getElementById(val0)
    var sdaterow = document.getElementById(val1)
    if (cb.checked) {
        sdaterow.style.display = "";
        if (isIE) {
            ValidatorEnable(document.getElementById(sdaterow.getAttribute("shortdateid") + "_rvMonth"), true)
            ValidatorEnable(document.getElementById(sdaterow.getAttribute("shortdateid") + "_rvYear"), true)
        }
    }
    else {
        sdaterow.style.display = "none";
        if (isIE) {
            ValidatorEnable(document.getElementById(sdaterow.getAttribute("shortdateid") + "_rvMonth"), false)
            ValidatorEnable(document.getElementById(sdaterow.getAttribute("shortdateid") + "_rvYear"), false)
        }
    }
}

function EnableDisableRadioButtonDate(val0, var2) {
    var isIE = (navigator.appName.indexOf("Microsoft") != -1 && navigator.appVersion.indexOf("MSIE 6") != -1);
    var radioboxControl = document.getElementById(val0)
    var radiobuttontablecell;
    var splited = val0.split("RadioButtonDate_RadioButton_")
    var parentcell = splited[0] + "row1Cell1_" + splited[1]
    radiobuttontablecell = document.getElementById(parentcell)
    var dateControlCell = document.getElementById(radiobuttontablecell.getAttribute("tablecell"))
    var dateControl = document.getElementById(radiobuttontablecell.getAttribute("dateControl"))
    if (radioboxControl.checked) {
        dateControlCell.style.display = "";
        if (isIE) {
            ValidatorEnable(document.getElementById(dateControl.getAttribute("daterequiredfieldvalidator")), true)
        }
    } else {
        dateControlCell.style.display = "none";
        if (isIE) {
            ValidatorEnable(document.getElementById(dateControl.getAttribute("daterequiredfieldvalidator")), false)
        }
    } //End of if		
    if (var2) {
        var rdArray = document.getElementsByName(radioboxControl.name)
        for (var i = 0; i < rdArray.length; i++) {
            var rdbut = document.getElementById(rdArray[i].id)
            var splited2 = rdArray[i].id.split("RadioButtonDate_RadioButton_")
            if (splited2.length > 1) {//1
                radiobuttontablecell = document.getElementById(splited2[0] + "row1Cell1_" + splited2[1])
                if (radiobuttontablecell.getAttribute("dateControl") == null) {//2
                    EnableDisableRadioButtonShortDate(rdArray[i].id, false)
                } else {
                    EnableDisableRadioButtonDate(rdArray[i].id, false)
                } //End of if 2
            } // End of if	1			
        } // End of for		
    } // End of Var2 if
} // End of Function

function EnableDisableRadioButtonShortDate(val0, var2) {
    var isIE = (navigator.appName.indexOf("Microsoft") != -1 && navigator.appVersion.indexOf("MSIE 6") != -1);
    var radioboxControl = document.getElementById(val0)
    var radiobuttontablecell;
    var splited = val0.split("RadioButtonDate_RadioButton_")
    var parentcell = splited[0] + "row1Cell1_" + splited[1]
    radiobuttontablecell = document.getElementById(parentcell)
    var dateControlCell = document.getElementById(radiobuttontablecell.getAttribute("tablecell"))
    var dateControl = document.getElementById(radiobuttontablecell.getAttribute("shortdateControl"))
    if (radioboxControl.checked) {
        dateControlCell.style.display = "";
        if (isIE) {
            ValidatorEnable(document.getElementById(dateControl.id + "_rvMonth"), true)
            ValidatorEnable(document.getElementById(dateControl.id + "_rvYear"), true)
        }
    } else {
        dateControlCell.style.display = "none";
        if (isIE) {
            ValidatorEnable(document.getElementById(dateControl.id + "_rvMonth"), false)
            ValidatorEnable(document.getElementById(dateControl.id + "_rvYear"), false)
        }
    }
    if (var2) {
        var rdArray = document.getElementsByName(radioboxControl.name)
        for (var i = 0; i < rdArray.length; i++) {
            var rdbut = document.getElementById(rdArray[i].id)
            var splited2 = rdArray[i].id.split("RadioButtonDate_RadioButton_")
            if (splited2.length > 1) {
                radiobuttontablecell = document.getElementById(splited2[0] + "row1Cell1_" + splited2[1])
                if (radiobuttontablecell.getAttribute("shortdateControl") == null) {
                    EnableDisableRadioButtonDate(rdArray[i].id, false)
                } else {
                    EnableDisableRadioButtonShortDate(rdArray[i].id, false)
                }
            } // End of if				
        } // End of for
    } // End of if(var2)	
}

function validateRadioButtoFrequencyListControl(var0, var1) {

    var isIE = (navigator.appName.indexOf("Microsoft") != -1 && navigator.appVersion.indexOf("MSIE 6") != -1);
    var rdbutYes

    if (var1 != null) {
        rdbutYes = document.getElementById(var1)
        rdbutYes.checked = false;
    }

    if ((rdbutYes.parentNode != null && rdbutYes.parentNode.id != "") || (rdbutYes.parentElement != null && rdbutYes.parentElement.id != "")) {
        if (isIE) {
            radiobuttontablecell = document.getElementById(document.getElementById(var1).parentElement.id)
        }
        else {
            radiobuttontablecell = document.getElementById(document.getElementById(var1).parentNode.id)
        }


        if (radiobuttontablecell.getAttribute("dateControl") != null)
        { EnableDisableRadioButtonFrequencyDate(var1, false) }
        if (radiobuttontablecell.getAttribute("shortdateControl") != null)
        { EnableDisableRadioButtonFrequencyShortDate(var1, false) }
    }
}


function EnableDisableRadioButtonFrequencyShortDate(val0, var2, var3) {
    var radioboxControl = document.getElementById(val0)
    var radiobuttontablecell
    var isIE = (navigator.appName.indexOf("Microsoft") != -1 && navigator.appVersion.indexOf("MSIE 6") != -1);

    if (var3 != null) {
        var rdbutno = document.getElementById(var3);
        rdbutno.checked = false;
    }

    if (isIE) {
        if (radioboxControl.parentElement.id == "") { validateRadioButtoFrequencyListControl(radioboxControl.name) }
        radiobuttontablecell = document.getElementById(document.getElementById(val0).parentElement.id)
    }
    else {
        radiobuttontablecell = document.getElementById(document.getElementById(val0).parentNode.id)
    }

    var dateControlCell = document.getElementById(radiobuttontablecell.getAttribute("tablecell"))
    var dateControl = document.getElementById(radiobuttontablecell.getAttribute("shortdateControl"))
    if (radioboxControl.checked) {
        dateControlCell.style.display = "";

        if (isIE) {
            try {
                //ValidatorEnable(document.getElementById(dateControl.id+"_rvMonth"),true)
                //ValidatorEnable(document.getElementById(dateControl.id+"_rvYear"),true)
                ValidatorEnable(document.getElementById(radiobuttontablecell.getAttribute("frequencydropdownlistvalidator")), true)
                ValidatorEnable(document.getElementById(radiobuttontablecell.getAttribute("shotsdropdownlistvalidator")), true)
            }
            catch (e) {
            }
        }
    }
    else {
        dateControlCell.style.display = "none";
        if (isIE) {
            try {
                //ValidatorEnable(document.getElementById(dateControl.id+"_rvMonth"),false)
                //ValidatorEnable(document.getElementById(dateControl.id+"_rvYear"),false)
                ValidatorEnable(document.getElementById(radiobuttontablecell.getAttribute("frequencydropdownlistvalidator")), false)
                ValidatorEnable(document.getElementById(radiobuttontablecell.getAttribute("shotsdropdownlistvalidator")), false)
            }
            catch (e) {
            }
        }
    }
    if (var2) {
        var rdArray = document.getElementsByName(radioboxControl.name)
        for (var i = 0; i < rdArray.length; i++) {
            var rdbut = document.getElementById(rdArray[i].id)
            if ((rdbut.parentNode != null && rdbut.parentNode.id != "") || (rdbut.parentElement != null && rdbut.parentElement.id != "")) {
                if (isIE) {
                    radiobuttontablecell = document.getElementById(rdbut.parentElement.id)
                }
                else {
                    radiobuttontablecell = document.getElementById(rdbut.parentNode.id)
                }

                if (radiobuttontablecell.getAttribute("dateControl") != null)
                { EnableDisableRadioButtonFrequencyDate(rdArray[i].id, false) }
                if (radiobuttontablecell.getAttribute("shortdateControl") != null)
                { EnableDisableRadioButtonFrequencyShortDate(rdArray[i].id, false) }
            }
        }
    }
}

function EnableDisableRadioButtonFrequencyDate(val0, var2) {
    var radioboxControl = document.getElementById(val0)
    var radiobuttontablecell
    var isIE = (navigator.appName.indexOf("Microsoft") != -1 && navigator.appVersion.indexOf("MSIE 6") != -1);
    if (isIE) {
        if (radioboxControl.parentElement.id == "") { return }
        radiobuttontablecell = document.getElementById(radioboxControl.parentElement.id)
    }
    else {
        if (radioboxControl.parentNode.id == "") { return }
        radiobuttontablecell = document.getElementById(radioboxControl.parentNode.id)
    }
    var dateControlCell = document.getElementById(radiobuttontablecell.getAttribute("tablecell"))
    var dateControl = document.getElementById(radiobuttontablecell.getAttribute("dateControl"))
    if (radioboxControl.checked) {
        dateControlCell.style.display = "";
        try {
            if (isIE) {
                ValidatorEnable(document.getElementById(dateControl.getAttribute("daterequiredfieldvalidator")), true)
                ValidatorEnable(document.getElementById(radiobuttontablecell.getAttribute("frequencydropdownlistvalidator")), true)
                ValidatorEnable(document.getElementById(radiobuttontablecell.getAttribute("shotsdropdownlistvalidator")), true)
            }
        }
        catch (e) {
        }
    }
    else {
        dateControlCell.style.display = "none";
        try {
            if (isIE) {
                ValidatorEnable(document.getElementById(dateControl.getAttribute("daterequiredfieldvalidator")), false)
                ValidatorEnable(document.getElementById(radiobuttontablecell.getAttribute("frequencydropdownlistvalidator")), false)
                ValidatorEnable(document.getElementById(radiobuttontablecell.getAttribute("shotsdropdownlistvalidator")), false)
            }
        }
        catch (e) {
        }
    }
    if (var2) {
        var rdArray = document.getElementsByName(radioboxControl.name)
        for (var i = 0; i < rdArray.length; i++) {
            var rdbut = document.getElementById(rdArray[i].id)
            if (rdbut.parentElement.id != "") {
                if (isIE) {
                    radiobuttontablecell = document.getElementById(rdbut.parentElement.id)
                }
                else {
                    radiobuttontablecell = document.getElementById(rdbut.parentNode.id)
                }

                if (radiobuttontablecell.getAttribute("dateControl") != null)
                { EnableDisableRadioButtonFrequencyDate(rdArray[i].id, false) }
                if (radiobuttontablecell.getAttribute("shortdateControl") != null)
                { EnableDisableRadioButtonFrequencyShortDate(rdArray[i].id, false) }
            }
        }
    }
}

function EnableDisableCheckBoxFrequency(val0, val1) {
    var isIE = (navigator.appName.indexOf("Microsoft") != -1 && navigator.appVersion.indexOf("MSIE 6") != -1);
    var cb = document.getElementById(val0)
    var sdaterow = document.getElementById(val1)
    if (cb.checked) {
        sdaterow.style.display = "";
        if (isIE) {
            ValidatorEnable(document.getElementById(sdaterow.getAttribute("shortdateid") + "_rvMonth"), true)
            ValidatorEnable(document.getElementById(sdaterow.getAttribute("shortdateid") + "_rvYear"), true)
            ValidatorEnable(document.getElementById(sdaterow.getAttribute("rvDDLVisits")), true)
        }
    }
    else {
        sdaterow.style.display = "none";
        if (isIE) {
            ValidatorEnable(document.getElementById(sdaterow.getAttribute("shortdateid") + "_rvMonth"), false)
            ValidatorEnable(document.getElementById(sdaterow.getAttribute("shortdateid") + "_rvYear"), false)
            ValidatorEnable(document.getElementById(sdaterow.getAttribute("rvDDLVisits")), false)
        }
    }
}

function EnableDisableRadioButtonPartialDateList(val0) {
    var isIE = (navigator.appName.indexOf("Microsoft") != -1 && navigator.appVersion.indexOf("MSIE 6") != -1);
    var rd//= document.getElementById(event.srcElement.id)
    var radiobuttontablecell
    if (isIE) {
        rd = document.getElementById(event.srcElement.id)
        radiobuttontablecell = document.getElementById(rd.parentElement.getAttribute("cellid"))
        // radiobuttontablecell = document.getElementById(val0)}//rd.parentElement.id) 
    }
    else {
        rd = document.getElementById(val0).childNodes[0].childNodes[0]
        radiobuttontablecell = document.getElementById(rd.parentNode.getAttribute("cellid"))
    }

    if (radiobuttontablecell != null) {
        var splitarray = radiobuttontablecell.id.split("RadioButtonPartialDateCell1_")
        var radiobuttontablecell1 = document.getElementById(splitarray[0] + "RadioButtonPartialDateCell2_" + splitarray[1])
        if (rd.checked) {
            radiobuttontablecell1.style.display = ""
            var cont = radiobuttontablecell1.getAttribute("sdControls")
            if (cont != null && isIE) {
                var splitarraysdcontrols = cont.split("#")
                for (var i = 0; i < splitarraysdcontrols.length - 1; i++) {
                    var shdatecontrol = document.getElementById(splitarray[0] + splitarraysdcontrols[i])
                    //ValidatorEnable(document.getElementById(shdatecontrol.id +"_rvMonth"),true)
                    //ValidatorEnable(document.getElementById(shdatecontrol.id +"_rvYear"), true)
                }
            }
        } else {
            radiobuttontablecell1.style.display = "none"
            radiobuttontablecell1.style.display = ""
            var cont = radiobuttontablecell1.getAttribute("sdControls")
            if (cont != null && isIE) {
                var splitarraysdcontrols = cont.split("#")
                for (var i = 0; i < splitarraysdcontrols.length - 1; i++) {
                    var shdatecontrol = document.getElementById(splitarray[0] + splitarraysdcontrols[i])
                    //ValidatorEnable(document.getElementById(shdatecontrol.id +"_rvMonth"),false)
                    //ValidatorEnable(document.getElementById(shdatecontrol.id +"_rvYear"), false)
                }
            }
        }
    }
    var rbutonslist = document.getElementsByName(rd.name)
    for (var j = 0; j < rbutonslist.length; j++) {
        SubFunctionEnableDisableRadioButtonPartialDateList(rbutonslist[j].id)
    }
}
function SubFunctionEnableDisableRadioButtonPartialDateList(var0) {
    var isIE = (navigator.appName.indexOf("Microsoft") != -1 && navigator.appVersion.indexOf("MSIE 6") != -1);
    var rd = document.getElementById(var0)
    var radiobuttontablecell
    if (isIE) {
        radiobuttontablecell = document.getElementById(rd.parentElement.getAttribute("cellid"))//document.getElementById(rd.parentElement.parentElement.id) 
    }
    else {
        radiobuttontablecell = document.getElementById(rd.parentNode.getAttribute("cellid"))
    }

    if (radiobuttontablecell != null) {
        var splitarray = radiobuttontablecell.id.split("RadioButtonPartialDateCell1_")
        var radiobuttontablecell1 = document.getElementById(splitarray[0] + "RadioButtonPartialDateCell2_" + splitarray[1])
        if (rd.checked) {
            radiobuttontablecell1.style.display = ""
            var cont = radiobuttontablecell1.getAttribute("sdControls")
            if (cont != null) {
                var splitarraysdcontrols = cont.split("#")
                for (var i = 0; i < splitarraysdcontrols.length - 1; i++) {
                    var shdatecontrol = document.getElementById(splitarray[0] + splitarraysdcontrols[i])
                    if (isIE) {
                        ValidatorEnable(document.getElementById(shdatecontrol.id + "_rvMonth"), true)
                        ValidatorEnable(document.getElementById(shdatecontrol.id + "_rvYear"), true)
                    }
                }
            }
        } else {
            radiobuttontablecell1.style.display = "none"
            var cont = radiobuttontablecell1.getAttribute("sdControls")
            if (cont != null) {
                var splitarraysdcontrols = cont.split("#")
                for (var i = 0; i < splitarraysdcontrols.length - 1; i++) {
                    var shdatecontrol = document.getElementById(splitarray[0] + splitarraysdcontrols[i])
                    if (isIE) {
                        ValidatorEnable(document.getElementById(shdatecontrol.id + "_rvMonth"), false)
                        ValidatorEnable(document.getElementById(shdatecontrol.id + "_rvYear"), false)
                    }
                }
            }
        }
    }
}

function DisableClientSideValidations() {
    //new function("Page_ValidationActive=false;");
    Page_ValidationActive = false;
}



function ClientSideValdiation(sender, args) {
    args.IsValid = false;
    var groupid = sender.getAttribute("groupid");
    var radiobutton = document.getElementById(groupid);
    if (groupid != null) {
        var arrayofradiobuttons = document.getElementsByName(radiobutton.name);
        for (var i = 0; i < arrayofradiobuttons.length; i++) {
            if (arrayofradiobuttons(i).checked) {
                args.IsValid = true;
            }
        }
    }
}
function ClientsSideCheckBoxValidation(sender, args) {
    args.IsValid = false;
    var arrayofCBControls = sender.getAttribute("validatecontrols").split(";")
    for (var i = 0; i < arrayofCBControls.length - 1; i++) {
        if (document.getElementById(arrayofCBControls[i]).checked) {
            args.IsValid = true;
        }
    }
}


function AllowNumeric(tbox, varlength) {
    //Allows only numeric characters using the keypress event

    // Get ASCII value of key that user pressed
    var key = window.event.keyCode;

    // Was key that was pressed a numeric character (0-9) ?
    // note if want to add a 'minus' sign, also allow key 45
    if ((key > 47 && key < 58) && (tbox.value.length < varlength))
        return; // if so, do nothing
    else
        window.event.returnValue = null; // otherwise, discard character
}

function ClientSideCustomCheckBoxListValidation(sender, args) {
    args.IsValid = false;
    var senderparent = sender.id.split("CheckBoxListValidator_");
    var cblist = document.getElementById(senderparent[0] + sender.getAttribute("controltovalidate"));
}


function ClearRemainingCheckBoxes(val0, val1, val2) {
    var checkbox = document.getElementById(val0)
    var arrayofCBControls = val1.split(";")
    var arrayofCBControls2 = val2.split(";")
    for (var i = 0; i < arrayofCBControls.length - 1; i++) {
        if (checkbox.checked) {
            document.getElementById(arrayofCBControls[i]).checked = false;
            document.getElementById(arrayofCBControls[i]).onclick();
        }
    }
    if (arrayofCBControls2.length > 0) {
        for (var i = 0; i < arrayofCBControls2.length - 1; i++) {
            if (checkbox.checked) {
                if (checkbox.id != document.getElementById(arrayofCBControls2[i]).id) {
                    document.getElementById(arrayofCBControls2[i]).checked = false;
                }
            }
        }
    }
}

function ClearSpecialCheckBox(val0, val1) {
    var checkbox = document.getElementById(val0)
    var specialcheckbox = document.getElementById(val1)
    if (checkbox.checked) {
        specialcheckbox.checked = false;
    }
}

function showLines(max, val0) {
    var currentTB = document.getElementById(val0)
    max--;
    var text = currentTB.value;
    text = "" + text;
    var temp = "";
    var chcount = 0;
    for (var i = 0; i < text.length; i++) // for each character ... 
    {
        var ch = text.substring(i, i + 1); // first character
        var ch2 = text.substring(i + 1, i + 2); // next character
        if (ch == '\n') // if character is a hard return
        {
            temp += ch;
            chcount = 1;
        }
        else {
            if (chcount == max) // line has max chacters on this line
            {
                temp += '\n' + ch; // go to next line
                chcount = 1; // reset chcount
            }
            else  // Not a newline or max characters ...
            {
                temp += ch;
                chcount++; // so add 1 to chcount
            }
        }
    }
    currentTB.innerText = temp;
    return (temp); // sends value of temp back
}

var oText;
function GetMedications(val0, val1) {
    var val2 = document.forms[0].getAttribute("medicationDrugNames")
    var medicalNames = val2.split(";")
    oText = document.getElementById(val0) //document.forms['Form1'].Textbox2
    var input = oText.value;
    var len = input.length;
    var div = document.getElementById("AutoDiv_" + val1)
    // clear the popup-div.
    while (div.hasChildNodes())
        div.removeChild(div.firstChild);
    if (input.length > 1) {
        // get matching country from array
        for (ele in medicalNames) {
            if (medicalNames[ele].substr(0, len).toLowerCase() == input.toLowerCase()) {
                var oDiv = document.createElement('div');
                div.appendChild(oDiv);
                oDiv.innerHTML = medicalNames[ele];
                oDiv.onmousedown = GetMedications.prototype.onDivMouseDown;
                oDiv.onmouseover = GetMedications.prototype.onDivMouseOver;
                oDiv.onmouseout = GetMedications.prototype.onDivMouseOut;
                oDiv.onkeypress = GetMedications.prototype.onDivMouseDown;
                oDiv.AutoComplete = this;
            }
        }
        div.style.visibility = "visible";
        //		div.style.left=findPosX(oText)+"px";	
        //		div.style.top=findPosY(oText)+oText.offsetHeight+"px";	 
        //		div.style.width=oText.offsetWidth+"px";	
    }
    if (div.childNodes.length == 1 && div.firstChild.innerHTML.toUpperCase() == input.toUpperCase()) {
        while (div.hasChildNodes())
            div.removeChild(div.firstChild);

        div.style.visibility = "hidden";
    }
    if (div.childNodes.length == 1 && div.firstChild.innerHTML.toUpperCase() == "") {
        while (div.hasChildNodes())
            div.removeChild(div.firstChild);

        div.style.visibility = "hidden";
    }
    if (div.childNodes.length == 0) {
        div.style.visibility = "hidden";
    }
}


GetMedications.prototype.onDivMouseDown = function() {
    oText.value = this.innerHTML;
}

GetMedications.prototype.onDivMouseOver = function() {
    this.className = "AutoCompleteHighlight";
    this.style.cursor = "pointer";
}

GetMedications.prototype.onDivMouseOut = function() {
    this.className = "AutoCompleteBackground";
}

function findPosX(obj) {
    xPos = eval(obj).offsetLeft;
    tempEl = eval(obj).offsetParent;
    while (tempEl != null) {
        xPos += tempEl.offsetLeft;
        tempEl = tempEl.offsetParent;
    }
    return xPos;
}
function findPosY(obj) {
    yPos = eval(obj).offsetTop;
    tempEl = eval(obj).offsetParent;
    while (tempEl != null) {
        yPos += tempEl.offsetTop;
        tempEl = tempEl.offsetParent;
    }
    return yPos;
}

function CloseMedicationsNameList(val0) {
    var div = document.getElementById("AutoDiv_" + val0)
    // clear the popup-div.
    while (div.hasChildNodes())
        div.removeChild(div.firstChild);

    div.style.visibility = "hidden";
}


function fnTrapKD(btnID, event) {
    btn = findObj(btnID);
    //if(btn != null) alert(btn.id);
    if (document.all) {
        if (event.keyCode == 13) {
            event.returnValue = false;
            event.cancel = true;
            btn.click();
        }
    }
    else if (document.getElementById) {
        if (event.which == 13) {
            event.returnValue = false;
            event.cancel = true;
            btn.focus();
            btn.click();
        }
    }
    else if (document.layers) {
        if (event.which == 13) {
            event.returnValue = false;
            event.cancel = true;
            btn.focus();
            btn.click();
        }
    }
}


function findObj(n, d) {
    var p, i, x;
    if (!d)
        d = document;
    if ((p = n.indexOf('?')) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document;
        n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all)
        x = d.all[n];
    for (i = 0; !x && i < d.forms.length; i++)
        x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++)
        x = findObj(n, d.layers[i].document);
    if (!x && d.getElementById)
        x = d.getElementById(n);
    return x;
}

function AllowOnlyNumberKeys(evt) {
    var keyCode = evt.keyCode ? evt.keyCode : evt.charCode
    //  35-hOME, 36-end, 8-BackSpace,  9-TabKey, 16-Shift+TabKey
    if (keyCode == 8 || keyCode == 9 || keyCode == 46) {
        evt.returnValue = true
        return true
    }
    if (keyCode > 47 && keyCode < 58) {
        evt.returnValue = true
        return true
    }

    evt.returnValue = false
    return false
}

function CloseThisWindow() {
    //Normal window closing does not work in Firefox.
    //You need to open one initially and then close it.

    window.open('', '_parent', '');
    window.close();

}

function EnableDropDownList(checkBoxId, dropDownId, panelId, dropDownValidatorId, authorizedLiteralId, textBoxValidatorId, fullNameLiteralId, textBoxId) {

    var checkBox = document.getElementById(checkBoxId);
    var dropDown = document.getElementById(dropDownId);
    var panel = document.getElementById(panelId);
    var dropDownValidator = document.getElementById(dropDownValidatorId);
    var literal = document.getElementById(authorizedLiteralId);
    var textBoxValidator = document.getElementById(textBoxValidatorId);
    var fullNameLiteral = document.getElementById(fullNameLiteralId);
    var textBox = document.getElementById(textBoxId);

    if (checkBox.checked) {
        panel.style.display = '';
        dropDown.style.display = '';
        literal.style.display = '';
        dropDown.selectedIndex = 0;
        textBox.style.display = "none";
        fullNameLiteral.style.display = "none";
        ValidatorEnable(dropDownValidator, true);

    }
    else {
        dropDown.style.display = "none";
        literal.style.display = "none";
        panel.style.display = "none";
        ValidatorEnable(dropDownValidator, false);
        ValidatorEnable(textBoxValidator, false);
    }

}


function EnableTextBox(dropDownId, fullNameLiteralId, textBoxId, dropDownValidatorId, textBoxValidatorId, authorizedLiteralId) {
    var dropDown = document.getElementById(dropDownId);
    var textBox = document.getElementById(textBoxId);
    var dropDownValidator = document.getElementById(dropDownValidatorId);
    var fullNameLiteral = document.getElementById(fullNameLiteralId);
    var authorizedByLiteral = document.getElementById(authorizedLiteralId);
    var textBoxValidator = document.getElementById(textBoxValidatorId);
    var value = dropDown.options[dropDown.selectedIndex].value;
    if (value == 'ParentLegalGuardian') {
        dropDown.style.display = '';
        authorizedByLiteral.style.display = '';
        textBox.style.display = '';
        fullNameLiteral.style.display = '';
        ValidatorEnable(dropDownValidator, false);
        ValidatorEnable(textBoxValidator, true);
    }

    else {
        textBox.style.display = "none";
        fullNameLiteral.style.display = "none";
        dropDown.style.display = '';
        authorizedByLiteral.style.display = '';
        ValidatorEnable(textBoxValidator, false);
        ValidatorEnable(dropDownValidator, true);

    }

}


function CheckAllCheckboxes(clientId) {
    var counter;
    var checkboxes = document.forms[0].elements;
    for (i = 0; i < checkboxes.length; i++) {
        if (checkboxes[i].type == "checkbox" && checkboxes[i].id.indexOf("AcceptAllCheckBox") > 0 || checkboxes[i].id.indexOf("PrimarySpouseGuardianCheckBox") > 0) {
            if (!checkboxes[i].checked) {
                counter = parseInt(document.getElementById(clientId).value)

                if (counter == 0) {
                    if (typeof (Page_ClientValidate) == 'function') Page_ClientValidate();
                    alert("To speed the application process, the MBE may be accepted online. Proceeding without accepting the MBEs will require the standard underwriting processes and follow up signatures will be required prior to issue.");
                    counter++;
                    document.getElementById(clientId).value = counter
                    return false;
                }

            }

        }

    }
    if (typeof (Page_ClientValidate) == 'function') Page_ClientValidate();

}

function DisableOtherTextBoxes(val0, val1) {
    var checkbox = document.getElementById(val0);
    var arrayofTextBoxControls = val1.split(";");
    for (var i = 0; i < arrayofTextBoxControls.length - 1; i++) {
        if (checkbox.checked) {
            document.getElementById(arrayofTextBoxControls[i]).disabled = true;
        }
        else {
            document.getElementById(arrayofTextBoxControls[i]).disabled = false;
        }
    }
}

function OpenSurvey(url, windowName) {
    var newWin = window.open(url, windowName, 'height=500,width=600,left=225,top=125,scrollbars=Yes,menubar=No,status=No,toolbar=No,resizable=Yes').blur();
    self.close();
}

function GoToTopOfPage() {
    var theform;

    if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
        theform = document.forms[0];
    }
    else {
        theform = document.forms[0];
    }
    document.forms[0].scrollTop = 0;
}

function OpenPdfInNewBrowserWindow(DocumentFileName, ValidationFunctionName) {
    var validationSuccessful = true;

    if (ValidationFunctionName != '') {
        validationSuccessful = eval(ValidationFunctionName);
    }

    if (validationSuccessful) {
        window.open(DocumentFileName, '', 'status=yes,toolbar=no,location=no,scrollbars=yes,resizable=yes');
    }
    return;
}
function FormatIncome(TextboxId, evt) {
    var CurrentTB = document.getElementById(TextboxId)
    var keyCode;
    if (evt != null) {
        if (document.all) {
            keyCode = evt.keyCode ? evt.keyCode : evt.charCode
        }
        else {
            keyCode = evt.which ? evt.which : evt.charCode
        }
    }
    if (CurrentTB.value != null && !(keyCode == 47 || keyCode == 37 || keyCode == 39 || keyCode == 46 || keyCode == 9 || keyCode == 9)) {
        if (keyCode != 8 && CurrentTB.value.indexOf("$") == -1) {
            CurrentTB.value = "$" + CurrentTB.value;
        }

        var formattedText;
        formattedText = CurrentTB.value.replace(/,/gi, "");
        CurrentTB.value = '';

        if (formattedText.length == 8) {
            var i;
            for (i = 0; i < formattedText.length; i++) {
                CurrentTB.value = CurrentTB.value + formattedText.charAt(i);
                if (i == 1 || i == 4) {
                    CurrentTB.value = CurrentTB.value + ",";
                }
            }
        }
        else if (formattedText.length == 7) {
            for (i = 0; i < formattedText.length; i++) {
                CurrentTB.value = CurrentTB.value + formattedText.charAt(i);
                if (i == 3) {
                    CurrentTB.value = CurrentTB.value + ",";
                }
            }
        }
        else if (formattedText.length == 6) {
            for (i = 0; i < formattedText.length; i++) {
                CurrentTB.value = CurrentTB.value + formattedText.charAt(i);
                if (i == 2) {
                    CurrentTB.value = CurrentTB.value + ",";
                }
            }
        }
        else if (formattedText.length == 5) {
            for (i = 0; i < formattedText.length; i++) {
                CurrentTB.value = CurrentTB.value + formattedText.charAt(i);
                if (i == 1) {
                    CurrentTB.value = CurrentTB.value + ",";
                }
            }
        }
        else {
            CurrentTB.value = formattedText
        }

    }
}

function SelectAll(TextboxId) {
    var CurrentTB = document.getElementById(TextboxId);

    if (document.selection.type == 'Text') {
        CurrentTB.select();

    }
    else {
        if (document.selection) {
            document.selection.empty();
            CurrentTB.blur();
        }
        else {
            window.getSelection().removeAllRanges();
        }
    }
    CurrentTB.focus();

}
