        // formvalidation.js
         // Declaring valid date character, minimum year and maximum year
        var emailRe = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/
        var phoneRe = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{2,6}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/

        var dtCh = "/";
        var minYear = 1900;
        var maxYear = 2100;
        //------------------------------------
function toForm() {
//document.form.login.focus();
// $("input:visible:enabled:first").focus();
//thisform = $('topform');
//thisform.focusFirstElement();
}

 function passwordChanged() {
    var strength = document.getElementById('strength');
 //   var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
    var strongRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
    var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
    var enoughRegex = new RegExp("(?=.{6,}).*", "g");
    var pwd = document.getElementById("data_passwordhash");
    if (pwd.value.length==0) {
            strength.innerHTML = 'Type Password';
        } else if (false == enoughRegex.test(pwd.value)) {
            strength.innerHTML = 'More Characters';
        } else if (strongRegex.test(pwd.value)) {
            strength.innerHTML = '<span style="color:green">Strong!</span>';
        } else if (mediumRegex.test(pwd.value)) {
            strength.innerHTML = '<span style="color:orange">Medium!</span>';
        } else {
            strength.innerHTML = '<span style="color:red">Weak!</span>';
        }
    }



function CurrencyFormatted(amount)
{
    var i = parseFloat(amount);
    if(isNaN(i)) { i = 0.00; }
    var minus = '';
    if(i < 0) { minus = '-'; }
    i = Math.abs(i);
    i = parseInt((i + .005) * 100);
    i = i / 100;
    s = new String(i);
    if(s.indexOf('.') < 0) { s += '.00'; }
    if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
    s = minus + s;
    return "$ " + s;
}


        function resubmit()
        {
            document.time_form.submit();
        }

        function processavailtime(p)
        {
            document.time_form.action="prep_myavailsaver.php?prep=" + p;
            document.time_form.submit();
        }


                // radio button normalizer
 function getCheckedValue(radioObj) {
    if(!radioObj)
        return "";
    var radioLength = radioObj.length;
    if(radioLength == undefined)
        if(radioObj.checked)
            return radioObj.value;
        else
            return "";
    for(var i = 0; i < radioLength; i++) {
        if(radioObj[i].checked) {
            return radioObj[i].value;
        }
    }
    return "";
}


          function CheckValidityQuickHelp(theForm)
            {
            var returnval = true;
            var errormessage = new String();
           errormessage="";

      // Put field checks below this point.
            if (WithoutContent(theForm.quicknote.value))
                {
                errormessage += "\nNeed something to send.";
                }

            // Put field checks above this point.
            if (errormessage.length > 2)
                {
                alert('NOTE:' + errormessage);
                return false;
                }
            else
                {
                return true;
                }
          }



        function CheckValidityPrepClose(theForm)
                {
                var returnval = true;
                var errormessage = new String();
            errormessage="";

                // Put field checks below this point.
         if (theForm.newdispo.value == 19)  //escalate
            {

                if (WithoutContent(theForm.statusnote.value))
                    {
                    errormessage += "\nFor Escalation, please enter an explanation in the Notes field.";
                    }

                 }  // escalated.

                if (theForm.newdispo.value == 0)
                    {
                    errormessage += "\nPlease indicate the Disposition for this assignment.";
                    }

                // Put field checks above this point.
                if (errormessage.length > 2)
                    {
                    alert('NOTE:' + errormessage);
                    return false;
                    }

                else
                    {
                    return true;
                    }
                }


       function CheckValidityReassign(theForm)
                {
                var returnval = true;
                var errormessage = new String();
            errormessage="";
                     alert("see you");
                // Put field checks below this point.

                  if (theForm.newpreparer.value == 0)
                    {
                    errormessage += "\nPlease indicate the New Preparer for this project.";
                    }

                // Put field checks above this point.
                if (errormessage.length > 2)
                    {
                    alert('NOTE:' + errormessage);
                    return false;
                    }

                else
                    {
                    return true;
                    }
             }


        function CheckValidityReview(theForm)
                {
                var returnval = true;
                var errormessage = new String();
            errormessage="";

                // Put field checks below this point.
          if ((theForm.newdispo.value == 3) || (theForm.newdispo.value == 19) ) // return / escalate
            {

                if (WithoutContent(theForm.statusnote.value))
                    {
                    errormessage += "\nFor Return to Preparer - or Escalation, please enter an explanation in the Notes field.";
                    }

                 }  // escalated.


                  if (theForm.newdispo.value == 0)
                    {
                    errormessage += "\nPlease indicate the Disposition for this review.";
                    }

                // Put field checks above this point.
                if (errormessage.length > 2)
                    {
                    alert('NOTE:' + errormessage);
                    return false;
                    }

                else
                    {
                    return true;
                    }
             }


            function CheckValidityUserDetail(theForm)
                {
                var returnval = true;
                var errormessage = new String();
           errormessage="";
         //      alert(document.getElementById('strength').innerHTML);
                // Put field checks below this point.
                if (document.getElementById('strength').innerHTML.indexOf("Strong!") == -1 )
                    {
                    errormessage += "\nInsufficient password strength.";
                    }
                if (WithoutContent(theForm.data_lname.value))
                    {
                    errormessage += "\nNeed User's last name.";
                    }

                if (WithoutContent(theForm.data_fname.value))
                    {
                    errormessage += "\nNeed User's first name.";
                    }

                if (WithoutContent(theForm.data_username.value))
                    {
                    errormessage += "\nNeed User's username.";
                    }
                if (WithoutContent(theForm.data_passwordhash.value))
                    {
                    errormessage += "\nNeed a password for this User.";
                    }

                if (WithoutContent(theForm.data_email.value))
                    {
                    errormessage += "\nNeed User's email address.";
                    }

              if (!(theForm.canIntake.checked ||
                    theForm.canPreparer.checked ||
                    theForm.canReviewer.checked ||
                    theForm.canCoordinator.checked ||
                    theForm.canAdmin.checked))
                    {
                       errormessage += "\nC'mon, now... you need to give this user a job.";
                    }

              // Put field checks above this point.
                if (errormessage.length > 2)
                    {
                    alert('NOTE:' + errormessage);
                    return false;
                    }

                else
                    {
                    return true;
                    }
                }

            function CheckValidityPrepDetail(theForm)
                {
                var returnval = true;
                var errormessage = new String();
            errormessage="";

                // Put field checks below this point.
               if (document.getElementById('strength').innerHTML.indexOf("Strong!") == -1 )
                    {
                    errormessage += "\nInsufficient password strength.";
                    }
                 if (WithoutContent(theForm.data_lname.value))
                    {
                    errormessage += "\nNeed Preparer's last name.";
                    }

                if (WithoutContent(theForm.data_fname.value))
                    {
                    errormessage += "\nNeed Preparer's first name.";
                    }
               if (WithoutContent(theForm.data_username.value))
                    {
                    errormessage += "\nNeed Preparer's username (a new one can be assigned here).";
                    }
                if (WithoutContent(theForm.data_passwordhash.value))
                    {
                    errormessage += "\nNeed a password for this Preparer.";
                    }

                if (WithoutContent(theForm.data_email.value))
                    {
                    errormessage += "\nNeed Preparer's email address.";
                    }

                if (WithoutContent(theForm.data_taxid.value))
                    {
                    errormessage += "\nNeed Preparer's SSN for payment purposes";
                    }

                if (WithoutContent(theForm.data_addr1.value))
                    {
                    errormessage += "\nNeed Preparer's street address.";
                    }

                if (WithoutContent(theForm.data_city.value))
                    {
                    errormessage += "\nNeed Preparer's city.";
                    }

                if (WithoutContent(theForm.data_state.value))
                    {
                    errormessage += "\nNeed the State code.";
                    }

                if (WithoutContent(theForm.data_zipcode.value))
                    {
                    errormessage += "\nNeed Preparer's ZIP code.";
                    }

                if (WithoutContent(theForm.data_priority.value))
                    {
                    errormessage += "\nLet's assign the priority, please.";
                    }

                if (WithoutContent(theForm.data_pipeline1max.value))
                    {
                    errormessage += "\nNeed Preparer's maximum assignment pipeline.";
                    }


                // Put field checks above this point.
                if (errormessage.length > 2)
                    {
                    alert('NOTE:' + errormessage);
                    return false;
                    }

                else
                    {
                    return true;
                    }
                }



        function CheckValidityFormDetail(theForm)
                {
                var returnval = true;
                var errormessage = new String();
                errormessage="";
                // Put field checks below this point.
               var ftype=theForm.formtype.value;

               if (WithoutContent(theForm.email.value))
                    {
                    errormessage += "\nPlease enter an email address.";
                    }

                    switch (ftype)
                    {
                    case "contact":
                 if (theForm.subject.value == "null")
                    {
                    errormessage += "\nPlease select a Subject or Staff Member.";
                    }
                 if (WithoutContent(theForm.message.value))
                    {
                    errormessage += "\nPlease enter a Message, Inquiry or Suggestion.";
                    }

                      break;
                    case "sendnews":
                        if (WithoutContent(theForm.message.value))
                            {
                            errormessage += "\nPlease enter news text.";
                            }

                       break ;
                    case "sendevents":
                        if (WithoutContent(theForm.message.value))
                            {
                            errormessage += "\nPlease enter event information.";
                            }

                       break ;
                    }



            // alert("CheckValidityBoatDetail");

              // Put field checks above this point.
                if (errormessage.length > 2)
                    {
                    alert('NOTE:' + errormessage);
                    return false;
                    }

                else
                    {
                    return true;
                    }
                }


        function WithoutContent(ss) { if (ss.length > 0) { return false; }

        return true; }

        function NoneWithContent(ss) { for (var i = 0; i < ss.length; i++)
                    {
                    if (ss[i].value.length > 0)
                        {
                        return false;
                        }
                    }

                return true;
                }

            function NoneWithCheck(ss)
                {
                for (var i = 0; i < ss.length; i++)
                    {
                    if (ss[i].checked)
                        {
                        return false;
                        }
                    }

                return true;
                }

            function WithoutCheck(ss)
                {
                if (ss.checked)
                    {
                    return false;
                    }

                return true;
                }

            function WithoutSelectionValue(ss)
                {
                for (var i = 0; i < ss.length; i++)
                    {
                    if (ss[i].selected)
                        {
                        if (ss[i].value.length)
                            {
                            return false;
                            }
                        }
                    }

                return true;
                }

            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 OnDDChange(dropdown)
                {
                var SelValue = dropdown.options[dropdown.selectedIndex].value;

                if (SelValue == "K")
                    document.getElementById("btnSave").value = "Delete Record";

                else
                    document.getElementById("btnSave").value = "Save Changes";

                return true;
                }
