
/*
Required field(s) validation- By NavSurf
Visit NavSurf.com at http://navsurf.com
Visit http://www.dynamicdrive.com for this script
*/

function formCheck(formobj){
     //1) Enter name of mandatory fields
     var fieldRequired =
Array("practicename","contactname","address","city","state","zip","country","phone","email","businesstype","softwareinterest","comments");
     //2) Enter field description to appear in the dialog box
     var fieldDescription = Array("Practice Name","Contact Name","Address","City","State","Zip Code","Country","Phone Number","Email Address","Business Type","Software of Interest","Comments");
     //3) Enter dialog message
     var alertMsg = "Please complete the following fields:\n";
     
     var l_Msg = alertMsg.length;
     
     for (var i = 0; i < fieldRequired.length; i++){
          var obj = formobj.elements[fieldRequired[i]];
          if (obj){
               switch(obj.type){
               case "select-one":
                    if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
                         alertMsg += " - " + fieldDescription[i] + "\n";
                    }
                    break;
               case "select-multiple":
                    if (obj.selectedIndex == -1){
                         alertMsg += " - " + fieldDescription[i] + "\n";
                    }
                    break;
               case "text":
               case "textarea":
                    if (obj.value == "" || obj.value == null){
                         alertMsg += " - " + fieldDescription[i] + "\n";
                    }
                    break;
               default:
                    if (obj.value == "" || obj.value == null){
                         alertMsg += " - " + fieldDescription[i] + "\n";
                    }
               }
          }
     }

     if (alertMsg.length == l_Msg){
          return true;
     }else{
          alert(alertMsg);
          return false;
     }
}
