/*********************************************

 * amc.js  

 * Validation functions for the AMC registration form.

 * Author: Tim Perrin

 *********************************************/



function atoi (x) {

   x = parseInt(x);

   if (isNaN(x)) return 0;

   return x;

}



function cntTextans(value) {

   if (notEmpty(value))

     return 1;

   else 

     return 0;

}



function cntChecked(name) {

   if (name.checked)

     return 1;

   else 

     return 0;

}



function notEmpty(value)

{ return (((value != null) && (value != "")) || (value)); }



function emptyPrompt(name)

 { alert('The \"' + name + '\" field has been left empty\nPlease fill in all fields before submitting'); }



function textNotEmpty(name, field) {

   if (notEmpty(field.value))

     return true;

   else {

     emptyPrompt(name);

     field.focus();

     return false;

   }

}



function radioNotEmpty (name, radio) {

   for (var i = 0; i < radio.length; i++)

     if (radio[i].checked) return true;



   emptyPrompt(name);

   return false;

}



function selectNotEmpty(name, field) {

   if (notEmpty(field.options[field.selectedIndex].value))

     return true;

   else {

     emptyPrompt(name);

     field.focus();

     return false;

   }

}



function validate(objForm) {

  var amtflag = false;

  var actflag = false;

        computeTotal();

  if (stringToInt(objForm.Total.value) > 0 && stringToInt(objForm.Total.value) <= 100)

    amtflag = true;

  else {

                focus(objForm.Total);

          return false;

        }

        countActivities();

     if (stringToInt(objForm.Activities.value) > 0 && stringToInt(objForm.Activities.value) <= 5)

    actflag = true;

  else {

          focus(objForm.Activities);

                return false;

        }

                

     if (amtflag && actflag) 

                objForm.submit();

        else {

    alert('Error in form input');

                return false;

        }

}



function recalculate() {

  document.MainOrder.Total.value = "XXXXXXXX"

  setTimeout('computeCost()',500);

}


