﻿function evalCheckedRadioButton(pobj_RadioButton) {
    try {
        var zobj_HTML = pobj_RadioButton.getElementsByTagName('input');
        for (var k = 0; k < zobj_HTML.length; k++) {
            if (zobj_HTML[k].type == 'radio') {
                if (zobj_HTML[k].checked) {
                    zobj_HTML = null; //clean out
                    return true;
                }
            }
        }
        zobj_HTML = null; //clean out
        return false;
    } catch (err) {
        alert("evalCheckedRadioButton Error: " + err.description);
    }
}

function Replicate_PhysicalAddress(obj) {
    try{
        if (obj.checked) {
            var zobj_Address1 = $get('<%=txt_Address2.ClientID%>');
            var zobj_Address2 = $get('<%=txt_Address1.ClientID%>');

            alert(zobj_Address1.Value);
        }
    } catch (err) {
        alert("Replicate_PhysicalAddress Error: " + err.description);
    }

}

function onkeypressTxtFein(e, o) {
    try {
        var unicode = (e.charCode) ? e.charCode : e.keyCode;
        if (unicode != 8 && (unicode < 48 || unicode > 57)) {
            return false;
        } else {            
            var zstrValue = o.value;
            if (zstrValue.length == 2) {
                zstrValue += "-";
            } else {
                if (zstrValue.length == 10) {
                    return false;
                }
            }

            o.value = zstrValue;
            return true;
        }
    } catch (err) {
        alert("onkeypressTxtFein Error: " + err.description);
    }
}

function FormatTxtFein(value){
    try {            
        if (value.length > 2) {
            if (value.indexOf("-") == -1) {
                value = value.substring(0, 2) + "-" + value.substring(2);
            }
        }
        
        return value;        
    } catch (err) {
        alert("onchangeTxtFein Error: " + err.description);
    }
}

function isCheckedAsYes(pobj_RadioButton) {
    try {
        var zobj_HTML = pobj_RadioButton.getElementsByTagName('input');
        for (var k = 0; k < zobj_HTML.length; k++) {
            if (zobj_HTML[k].type == 'radio') {
                if (zobj_HTML[k].checked && zobj_HTML[k].value == '1') {
                    zobj_HTML = null; //clean out
                    return true;
                }
            }
        }
        zobj_HTML = null; //clean out
        return false;
    } catch (err) {
        alert("isCheckedAsYes Error: " + err.description);
    }
}

function hasAnyUser(pobj_HTML) {
    try {

        if (pobj_HTML != null && pobj_HTML != 'undefined') {
            if (pobj_HTML.rows.length > 1) return true;
        }        
        return false;
    } catch (ex) {
        alert("hasAnyUser Error: " + err.description);
    }
}

function hasAdminUsers(pobj_HTML) {
    try{
        for (k = 1; k < pobj_HTML.rows.length; k++) {
            if (document.all) {
                if (pobj_HTML.rows[k].cells[1].innerText.indexOf("Yes") > -1) return true;
            }
            else {
                if (pobj_HTML.rows[k].cells[1].textContent.indexOf("Yes") > -1) return true;
            }
        }
        return false;
    } catch (ex) {
        alert("hasAdminUsers Error: " + err.description);
    }
}

function validateUSDate(strValue) {
    /************************************************
    DESCRIPTION: Validates that a string contains only
    valid dates with 2 digit month, 2 digit day,
    4 digit year. Date separator can be ., -, or /.
    Uses combination of regular expressions and
    string parsing to validate date.
    Ex. mm/dd/yyyy 

PARAMETERS:
    strValue - String to be tested for validity

RETURNS:
    True if valid, otherwise false.

REMARKS:
    Avoids some of the limitations of the Date.parse()
    method such as the date separator character.
    *************************************************/
    var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;

    //check to see if in correct format
    if (!objRegExp.test(strValue)) {
        return false; //doesn't match pattern, bad date
    }
    else {
        try {
            var strSeparator = strValue.match(/(\/)/)[0]; //strValue.substring(2,3) 
        } catch (err) {
            return false;
        }

        var arrayDate = strValue.split(strSeparator);
        //create a lookup for months not equal to Feb.
        var arrayLookup = { '01': 31, '1': 31, '03': 31, '3': 31,
            '04': 30, '4': 30, '05': 31, '5': 31,
            '06': 30, '6': 30, '07': 31, '7': 31,
            '08': 31, '8': 31, '09': 30, '9': 30,
            '10': 31, '11': 30, '12': 31
        }
        var intDay = parseInt(arrayDate[1], 10);

        //check if month value and day value agree
        if (arrayLookup[arrayDate[0]] != null) {
            if (intDay <= arrayLookup[arrayDate[0]] && intDay != 0)
                return true; //found in lookup table, good date
        }

        //check for February (bugfix 20050322)
        //bugfix  for parseInt kevin
        //bugfix  biss year  O.Jp Voutat
        var intMonth = parseInt(arrayDate[0], 10);
        if (intMonth == 2) {
            var intYear = parseInt(arrayDate[2]);
            if (intDay > 0 && intDay < 29) {
                return true;
            }
            else if (intDay == 29) {
                if ((intYear % 4 == 0) && (intYear % 100 != 0) ||
             (intYear % 400 == 0)) {
                    // year div by 4 and ((not div by 100) or div by 400) ->ok
                    return true;
                }
            }
        }
    }
    return false; //any other values, bad date
}


function SetText(objID, tabID) {
    try {
        if (tabID == 0) {
            objID.innerText = "To become a UPA appointed agency, please complete the Agency Profile. After completing the profile page, please proceed to Agency Personnel to list agents within your organization whom you want to do business with UPA.";
        } else {
            objID.innerText = "Please add a list of agents to your profile. You may start by assigning a UserName and Password for yourself. Click “Add” to continue adding agents. Note: Each time you add another agent, please assign a unique username and password.";
        }
    } catch (ex) {
        alert("SetText Error: " + err.description);
    }
}

function OnBeforeUnloadPage() {
    try {
        return "If you have already entered information in the form on pressing OK all your changes will be lost.";
    } catch (ex) {
        alert("OnBeforeUnloadPage Error: " + err.description);
    }
}

