<!--
<!--hide this script from non-javascript-enabled browsers

/* Functions that swaps images. */

/* Functions that handle preload. */

// stop hiding -->


//-->
    //  Call function like this:  <form onsubmit="return verify(this);">
    // If you want verification to occur you must define field type:
    // document.RequestForm.login.input_type='text';
    // You can define the name that appears in the error message like this
    // document.RequestForm.myfield.desc='Login Name';
    // You can select from the following input types:
    //
    //text              Text or textarea must not be blank
    //select            single select - first value is a dummy ie "<option>Please Select"
    //select_multiple   a multiple select box - user must select at least one
    //phone             a phone number - reformats to XXX-XXX-XXXX
    //email             an email address
    //float             a
    //currency          a number with 2 decimal places
    //numeric           a number
    //adate             Date 3/4/2000
    //radio             a series of radio or checkboxes. At least on must be checked
    //                  define radio buttons using the first element ie:
    //                  document.RequestForm.myradio[0].input_type='radio';
    // The following length/value options are also available:
    //
    //  document.RequestForm.myfield.lmin=10;  Minimum length
    //  document.RequestForm.myfield.lmax=10;  Max Length
    //  document.RequestForm.myfield.min=10;   Min number value
    //  document.RequestForm.myfield.max=10;   Max numeric value
    //
    //Questions:  email me at jonb@davidandgoliath.com
    // Enjoy!


    
    function testit(ftype)
    {
      var theForm = document.forms[0]

      for(i=0; i<theForm.elements.length; i++){            
         if(theForm.elements[i].type == "text" || theForm.elements[i].type == "textarea" ){
           strOrig = theForm.elements[i].value;
           strTemp = theForm.elements[i].value;
           strTemp = strTemp.replace(/\%|\;/g,"[SC]");
           strTemp = strTemp.replace(/\</g,"[LT]");
           strTemp = strTemp.replace(/\>/g,"[GT]");
                
           if (strOrig != strTemp){
	        theForm.elements[i].value = strTemp;
           } 
         } 
	  }  //if type send in, complaint form needs to be checked
 	  if (ftype == '1') {
 	    whattodo = valcomplaintform(theForm);
 	    if (whattodo){
 	      theForm.alt_submit.value = 'YES';
 	      theForm.submit();
	    }
	    else
	      return false
      }
 	  else {
	 	whattodo = verify(theForm);
	 	if (whattodo)
 	      theForm.submit();
 	    else
 	      return false;
	  }	  
	  	    
	}  // end of function to test for special characters and remove when found
    
    function replace(myString,char_to_replace,char_to_substitute)
    {
        var output = "";
        for(var i = 0; i < output.length; i++){
            var c = output.charAt(i);
            if (c == char_to_replace ) {
                output = output + char_to_substitute;
            }else{
                output = output + c;
            }
        }
        return true;
    }

    function isblank(myString)
    {
        for(var i = 0; i < myString.length; i++){
            var c = myString.charAt(i);
            if ((c != ' ') && (c != '\n') && (c != '\t') && (c != '\r')) return false;
        }
        return true;
    }



    function isValidSize(myString,theMin,theMax)
    {
        if ((theMax != null) && (myString.length > theMax)) return false;
        if ((theMin != null) && (myString.length < theMin)) return false;
        return true;
    }

    function isInNumericRange(myString,theMin,theMax)
    {
        if ((theMax != null) && (myString > theMax)) return false;
        if ((theMin != null) && (myString < theMin)) return false;
        return true;
    }

    function isSelect(select_obj,least_valid_selectIndex)
    {
        if (select_obj.selectedIndex < least_valid_selectIndex) return false;
        return true;
    }

    function isInteger(numString)
    {

                for(var i = 0; i < numString.length; i++){
                    var c = numString.charAt(i);
                    if ((c != '\n') && (c != '\t') && (c != '\r') && (c != '1') && (c != '2') && (c != '3') && (c != '4') && (c != '5') && (c != '6') && (c != '7') && (c != '8') && (c != '9') && (c != '0') ) return false;
                }
                return true;
    }

    function isEmail(theEmail)
    {
     var sEmail = "" + theEmail;
     if (sEmail.indexOf('@') == -1) return false;
     if (sEmail.indexOf('.') == -1) return false;
     return true;
    }


    function isPhone(theNumber)
    {
        var phone = "";
        var area = "";
        var lastfour = "";
        for(var i = 0; i < theNumber.length; i++){
            var c = theNumber.charAt(i);
            if ((c != '\n') && (c != '\t') && (c != '\r') && (c != '1') && (c != '2') && (c != '3') && (c != '4') && (c != '5') && (c != '6') && (c != '7') && (c != '8') && (c != '9') && (c != '0') && (c != '-') && (c != ' ') && (c != '(') && (c != ')') ) return false;
            if ((c == '1') || (c == '2') || (c == '3') || (c == '4') || (c == '5') || (c == '6') || (c == '7') || (c == '8') || (c == '9') || (c == '0') ) phone = phone + c;
        }
        if (phone.length != 10) return false;
        area = phone.charAt(0) + phone.charAt(1) + phone.charAt(2);
        local = phone.charAt(3) + phone.charAt(4) + phone.charAt(5);
        lastfour = phone.charAt(6) + phone.charAt(7) + phone.charAt(8) + phone.charAt(9);
        if ((area == '111') || (area == '222') || (area == '333') || (area == '444') || (area == '555') || (area == '666') || (area == '777') || (area == '999') || (area == '000') ) return false;
        return area + "-" + local + "-" +  lastfour;

    }

    function isRadio(radioObj)
    {
                for(var i = 0; i < radioObj.length; i++){
                    if (radioObj[i].checked) return true;
                }
                return false;
    }



    function isFloat(numString)
    {

                for(var i = 0; i < numString.length; i++){
                    var c = numString.charAt(i);
                    if ((c != '\n') && (c != '\t') && (c != '\r') && (c != '1') && (c != '2') && (c != '3') && (c != '4') && (c != '5') && (c != '6') && (c != '7') && (c != '8') && (c != '9') && (c != '0') && (c != '.') ) return false;
                }
                return true;
    }

    function isCurrency(numString)
    {

                for(var i = 0; i < numString.length; i++){
                    var c = numString.charAt(i);
                    if ((c != '\n') && (c != '\t') && (c != '\r') && (c != '1') && (c != '2') && (c != '3') && (c != '4') && (c != '5') && (c != '6') && (c != '7') && (c != '8') && (c != '9') && (c != '0') && (c != '.') ) return false;
                }
                return true;
    }

    function isDate(myString)
    {
        var x = 0;
        var m = 0;
        var d = 0;
        var y = 0;
        var count = 0;
        for(var i = 0; i < myString.length; i++){
            var c = myString.charAt(i);
            if (c == "/") {
                if (count == 0) m = parseInt(x);
                if (count == 1) d = parseInt(x);
                count++;
                x = "";
            }else if (isInteger(c)) {
                x = x + c ;
            }else if ((c == " ") || (c == '\n') || (c == '\t') || (c == '\r')) {

            }else{
                return false;
            }
        }
        y = parseInt(x);
        var maxday = 31;
        if ((m > 12) || (m < 1)) return false;
        if ((m == 4) || (m == 9) || (m == 11) || (m == 6) ) maxday = 30;
        if ((m == 2) ){
            if (y % 4 != 0) {
                maxday = 28;
            }else if  (y % 400 == 0){
                maxday = 29;
            }else if (y % 100 == 0){
                maxday = 28;
            }else{
                maxday = 29;
            }
        }
        if (d > maxday) return false;
        if (y < 0 ) return false;
        return true;
    }

    function verify(myField)
    {
        var msg;
        msg="";

        var empty_fields = "";
        var errors = "";
        for(var i = 0; i < myField.elements.length; i++){
            var e = myField.elements[i];
            var description = e.desc;
            var value = e.value;
            if (description == null) description = e.name;

            if (e.input_type == null) {
            }else if (e.input_type == "radio") {
                if (!isRadio(myField.elements[e.name])) msg = msg + description + " has not been selected.\n";
            }else if (e.input_type == "text") {
                if (isblank(value)) {
                    msg = msg + description + " is blank.\n";
                }else if (!isValidSize(value,e.lmin,e.lmax)){
                    msg = msg + description + " must be ";
                    if (e.lmin != null) msg = msg + "longer than or equal to " + e.lmin + " characters";
                    if (e.lmax != null) msg = msg + " and shorter than or equal to " + e.lmax + " characters" ;

                    msg = msg + " characters.\n";
                }
            }else if (e.input_type == "select") {
                if (!isSelect(e,1)) msg = msg + description + " has not been selected.\n";
            }else if (e.input_type == "select_multiple") {
                if (!isSelect(e,0)) msg = msg + description + " has not been selected.\n";
            }else if (e.input_type == "phone") {
                if ((isblank(value)) || (!isPhone(value))) {
                    msg = msg + description + " is not a valid phone number.\n";
                }else{
                    e.value = isPhone(value);
                }
            }else if (e.input_type == "email") {
                if ((isblank(value)) || (!isEmail(value))) msg = msg + description + " is not a valid email address.\n";
            }else if (e.input_type == "integer") {
                if ((isblank(value)) || (!isInteger(value))) {
                    msg = msg + description + " is not a valid integer value.\n";
                }else if ((!isInNumericRange(value,e.min,e.max)) || (!isValidSize(value,e.lmin,e.lmax))) {
                    msg = msg + description + " must be ";
                    if (e.min != null) msg = msg + "greater than or equal to " + e.min ;
                    if (e.max != null) msg = msg + " and less than or equal to " + e.max ;
                    if (e.lmin != null) msg = msg + "longer than or equal to " + e.lmin + " characters";
                    if (e.lmax != null) msg = msg + " and shorter than or equal to " + e.lmax + " characters";


                    msg = msg + ".\n";
                }
            }else if (e.input_type == "float") {
                if ((isblank(value)) || (!isFloat(value))) {
                    msg = msg + description + " is not valid decimal value.\n";
                }else if ((!isInNumericRange(value,e.min,e.max)) || (!isValidSize(value,e.lmin,e.lmax))){
                    msg = msg + description + " must be ";
                    if (e.min != null) msg = msg + "greater than or equal to " + e.min ;
                    if (e.max != null) msg = msg + " and less than or equal to " + e.max ;
                    if (e.lmin != null) msg = msg + "longer than or equal to " + e.lmin + " characters";
                    if (e.lmax != null) msg = msg + " and shorter than or equal to " + e.lmax + " characters";


                    msg = msg + ".\n";
                }
            }else if (e.input_type == "currency") {
                if ((isblank(value)) || (!isCurrency(value))) {
                    msg = msg + description + " is not a valid dollar value.\n";
                }else if ((!isInNumericRange(value,e.min,e.max)) || (!isValidSize(value,e.lmin,e.lmax))){
                    msg = msg + description + " must be ";
                    if (e.min != null) msg = msg + "greater than or equal to " + e.min ;
                    if (e.max != null) msg = msg + " and less than or equal to " + e.max ;
                    if (e.lmin != null) msg = msg + "longer than or equal to " + e.lmin + " characters";
                    if (e.lmax != null) msg = msg + " and shorter than or equal to " + e.lmax + " characters";

                    msg = msg + ".\n";
                }
            }else if (e.input_type == "numeric") {
                if ((isblank(value)) || (!isFloat(value))) {
                    msg = msg + description + " is not a valid numeric value.\n";
                }else if ((!isInNumericRange(value,e.min,e.max)) || (!isValidSize(value,e.lmin,e.lmax))){
                    msg = msg + description + " must be ";
                    if (e.min != null) msg = msg + "greater than or equal to " + e.min ;
                    if (e.max != null) msg = msg + " and less than or equal to " + e.max ;
                    if (e.lmin != null) msg = msg + "longer than or equal to " + e.lmin + " characters";
                    if (e.lmax != null) msg = msg + " and shorter than or equal to " + e.lmax + " characters";

                    msg = msg + ".\n";
                }
            }else if (e.input_type == "adate") {
                if (!isDate(value)) {
                    msg = msg + description + " is not a valid date.\n";
                }
            }
        }
        if (msg.length > 0){
            alert("Warning!  The following optional fields have the current values: \n\n" + msg);
            temp=window.confirm('Would you like the send to proceed?');
            return temp;
        }else{
            return true;
        }

    }//verify
function valcomplaintform(form)
{
  var msg;
    // array holding the required variables
    //frmName is the name of the form
    frmLength = form.length;
    // Loop through the fields and validate based on type and value.
    for (i=0; i<frmLength;i++)
    {
        // bypass hidden fields since they are control fields
        if (form[i].type!="hidden")
        {
           if (form[i].requiredfield==true) {
              if ((form[i].value == ""))
              {
                   alert('Item must be entered');
                   form[i].focus();
                   closethis='no';
                   return false;
              }  // validate the field for null, not entered
           } else  {
              if (form.last_name.value=="")
                 form.last_name.value = "Anonymous";
              if (form.email_address.value=="")
                 form.email_address.value = "N/A";
           }
        }  // end if form type = hidden
    } // end of for
    return true;
} // end of the function

parent.RecordEdited = true;

//Allows the user to abort the current changes
function AbortChangesButton(redirectpagename)
{
    if (document.forms[0].AbortChanges.value == 'Abort Changes')
        {
            if (confirm('Abort changes to this record?') == false)
                {
                    return false;
                }
            else
                {
                    location.href=redirectpagename;
                }

        }
    else
        {
            location.href=redirectpagename;
        }
    return true;
}

function SetAbortButton()
{

    if (document.forms[0].AbortChanges != null)
    {
        // Change "BACK" button to "Abort Change" when a field is changed
        document.forms[0].AbortChanges.value="Abort Changes";

        // Enable the "Save Changes" button when a field is changed
        if (document.forms[0].AbortChanges.disabled == false)
            document.forms[0].SaveChanges.disabled = false;
    }
}

function GetThisURL()
{
    GetThisURL=location.href;
}

function DisableSearchButton()
{
    // Disable the "Search" button when a field is changed
    document.forms[0].Search.disabled = true;
}

function SetChangeFlag(index)
{

    e = eval('document.forms[0].ChangeFlag' + index);
    e.value = 'True';

}

function SearchGuestResponses(redirectpagename, string)
{
    redirectpagename = redirectpagename + '&Search_String=' + string;
    location.href=redirectpagename;
}

function PopAllCategories(category_id)
{
    responsecount = document.forms[0].TotalUncategorizedResponses.value;
    //Set all categories for the un-categorized resonses
    //to the chosen default value
    for(index = 1 ; index <= responsecount ; index++)
        {
        PopCategory(category_id, index);
        PopSubCategory(category_id, index);
        }

}

function validlength(obj, maxlength)
{
    if(obj.value.length > maxlength) {
        alert("This field may not be longer than " + maxlength + " characters.")
        obj.focus()
    }
 }

function KeepOnTop()
{
    do
        window.focus();
    while (1 > 0);
}

function detectWindow(){
    if ((window.modal_window == null) || (window.modal_window.closed == true)) {
            return false;
        } else {
            modal_window.focus();
        }
    }

function openWindow(url, windowname){
    modal_window = window.open(url,windowname,'screenx=30,screeny=30,height=500,width=700,top=70,left=40,resizable=yes,toolbar=yes,location=yes,scrollbars=yes');
        }

// Shows the surveypctreport.cfm report to the user
// in a new window with the toolbar available for
// printing and emailing.
function ShowPrintableReport(Survey_Id)
{
    windowURL  =  'surveypctreport.cfm';
    windowURL  += '?SurveyId=' + Survey_Id + '&Printable=Yes';
    windowName =  'PrintSurveyReport';
    windowInfo =  'height='+(screen.availHeight - 30);
    windowInfo += ',width='+(screen.availWidth - 5);
    windowInfo += ',toolbar=yes,scrollbars=yes';
    windowInfo += ',resizable=yes';

    tWnd = window.open(windowURL,windowName,windowInfo);
    tWnd.moveTo(0,0);
}

function validlength(obj, maxlength) {
    if(obj.value.length > maxlength) {
        alert("This field may not be longer than " + maxlength + " characters.")
        obj.focus()
}
}

// Specialized function that verifies that the
// user had entered information on the edit_question.cfm form.
// This function utilizes the generic verify() function
// defined in this file.
function VerifyQuestion(f)
{
    // If we need to delete this record, confirm with the user
    // and then submit the page.

    if (document.edit_question.DeleteRecord.checked == true)
    {
        if (window.confirm('Are you sure you want to permanently delete this question?') == true)
        {
            document.edit_question.submit();
        }
    }
    else    // Otherwise validate the input and submit the page
    {
        f.Question_Text.optional = false;
        if (verify(f) == true)
        {
            document.edit_question.submit();
        }
    }

}

// Specialized function that verifies that the
// user had entered information on the edit_answer.cfm form.
// This function utilizes the generic verify() function
// defined in this file.
function VerifyAnswer(f)
{
    // If we need to delete this record, confirm with the user
    // and then submit the page.

    if (document.edit_answer.DeleteRecord.checked == true)
    {
        if (window.confirm('Are you sure you want to permanently delete this answer?') == true)
        {
            document.edit_answer.submit();
        }
    }
    else    // Otherwise validate the input and submit the page
    {
        f.Answer_Text.optional = false;
        if (verify(f) == true)
        {
            document.edit_answer.submit();
        }
    }
}

// Specialized function that verifies that the
// user had entered information on the edit_category.cfm form.
// This function utilizes the generic verify() function
// defined in this file.
function VerifyCategory(f)
{
    // If we need to delete this record, confirm with the user
    // and then submit the page.

    if (document.edit_category.DeleteRecord.checked == true)
    {
        if (window.confirm('Are you sure you want to permanently delete this categlry?') == true)
        {
            document.edit_category.submit();
        }
    }
    else    // Otherwise validate the input and submit the page
    {
        f.Category_Name.optional = false;
        if (verify(f) == true)
        {
            document.edit_category.submit();
        }
    }
}

// Specialized function that verifies that the
// user had entered information on the edit_subcategory.cfm form.
// This function utilizes the generic verify() function
// defined in this file.
function VerifySubCategory(f)
{
    // If we need to delete this record, confirm with the user
    // and then submit the page.

    if (document.edit_subcategory.DeleteRecord.checked == true)
    {
        if (window.confirm('Are you sure you want to permanently delete this subcategory?') == true)
        {
            document.edit_subcategory.submit();
        }
    }
    else    // Otherwise validate the input and submit the page
    {
        f.SubCategory_Name.optional = false;
        if (verify(f) == true)
        {
            document.edit_subcategory.submit();
        }
    }
}

// Specialized function that verifies that the
// user had entered information on the edit_survey.cfm form.
// This function utilizes the generic verify() function
// defined in this file.
function VerifySurvey(f)
{
    // If we need to delete this record, confirm with the user
    // and then submit the page.

    if (document.edit_survey.DeleteRecord.checked == true)
    {
        message = '                                     WARNING:\n';
        message += 'All data associated with this survey ';
        message += 'will be deleted, including all responses! \n';
        message += 'Reports for this survey will no longer be available!\n';
        message += 'Are you sure you want to permanently delete this survey?';

        if (window.confirm(message) == true)
        {
            document.edit_survey.submit();
        }
    }
    else    // Otherwise validate the input and submit the page
    {
        f.Item_Copy.optional = false;
        if (verify(f) == true)
        {
            document.edit_survey.submit();
        }
    }
}

// Specialized function that verifies that the
// user had entered information on the edit_surveytype.cfm form.
// This function utilizes the generic verify() function
// defined in this file.
function VerifySurveyType(f)
{
    // If we need to delete this record, confirm with the user
    // and then submit the page.

    if (document.edit_surveytype.DeleteRecord.checked == true)
    {
        if (window.confirm('Are you sure you want to permanently delete this survey type?') == true)
        {
            document.edit_surveytype.submit();
        }
    }
    else    // Otherwise validate the input and submit the page
    {
        f.Type_Name.optional = false;
        f.Template_Filename.optional = false;
        if (verify(f) == true)
        {
            document.edit_surveytype.submit();
        }
    }
}

// A utility function that returns true if a string contains only
// whitespace characters.
function isblank(s)
{
    for (var i = 0; i < s.length; i++){
        var c = s.charAt(i);
        if ((c != " ") && (c != '\n') && (c != '/t')) return false;
    }
    return true;
}

// This is a function that performs form generic verification.
// The handler should return whatever value this function returns.
//
// This function loops throught the elements of the form passed to it,
// looking for all text and textarea elements that don't have an "optional"
// property defined.  then, checks for fields that are empty and makes
// a list of them.  Also, if any of the elements have a "min" or a "max"
// property defined, it verifies that they are numbers and that they
// are in the right range. If the element has a "number" property
// defined, verify that it is a number, but don't check its range.

function verifyall(f)
{
    var msg;
    var empty_fields = "";
    var errors = "";

    // Loop through the elements of the form.
    // Put together error messsages for fields that are wrong.
    for(var i = 0; i < f.length; i++) {
        var e = f.elements[i];
        if (((e.type == "text") || (e.type == "textarea")) && !e.optional) {
            // first check if the field is empty
            if ((e.value == null) || (e.value == "") || isblank(e.value)) {
                empty_fields += "\n          " + e.name;
                continue;
            }

            // Now check for fields that are supposed to be numeric.
            if (e.numeric || (e.min != null) || (e.max != null)) {
                var v = parseFloat(e.value);
                if (isNaN(v) ||
                    ((e.min != null) && (v < e.min)) ||
                    ((e.max != null) && (v > e.max))) {
                    errors += "- The field " + e.name + " must be a number";
                    if (e.min != null)
                        errors += " that is greater than " + e.min;
                    if (e.max != null && e.min != null)
                        errors += " and less than " + e.max;
                    else if (e.max != null)
                        errors += " that is less than " + e.max;
                    errors += ".\n";
                }
            }
        }
    }

    // Now if there were any errors, display the message, and
    // return false to prevent the form from being submitted.
    // Otherwise return true.
    if (!empty_fields && !errors) return true;

    msg = "_____________________________________________\n\n"
    msg += "The form was not submitted because of the following error(s).\n";
    msg += "Please correct these error(s) and re-submit.\n";
    msg += "____________________________________________\n\n"

    if (empty_fields) {
        msg += "- The following required field(s) are empty:"
        + empty_fields + "\n";
        if (errors) msg += "\n";
    }
    msg += errors;
    alert(msg);
    return false;
}

//-->
