function validateInt()
   {
      var o = document.frmInput.txtInput;
      switch (isInteger(o.value))
      {
         case true:
            alert(o.value + " is an integer")
            break;
         case false:
            alert(o.value + " is not an integer")
      }
   }

   function validateRange()
   {
      var s = document.frmInput.txtInput.value;
      var A = document.frmInput.txtA.value;
      var B = document.frmInput.txtB.value;

      switch (isIntegerInRange(s, A, B))
      {
         case true:
            alert(s + " is in range from " + A + " to " + B)
            break;
         case false:
            alert(s + " is not in range from " + A + " to " + B)
      }
   }

// isIntegerInRange (STRING s, INTEGER a, INTEGER b)
   function isIntegerInRange (s, a, b)
   {   if (isEmpty(s))
         if (isIntegerInRange.arguments.length == 1) return false;
         else return (isIntegerInRange.arguments[1] == true);

      // Catch non-integer strings to avoid creating a NaN below,
      // which isn't available on JavaScript 1.0 for Windows.
      if (!isInteger(s, false)) return false;

      // Now, explicitly change the type to integer via parseInt
      // so that the comparison code below will work both on
      // JavaScript 1.2 (which typechecks in equality comparisons)
      // and JavaScript 1.1 and before (which doesn't).
      var num = parseInt (s);
      return ((num >= a) && (num <= b));
   }

   function isInteger (s)
   {
      var i;

      if (isEmpty(s))
      if (isInteger.arguments.length == 1) return 0;
      else return (isInteger.arguments[1] == true);

      for (i = 0; i < s.length; i++)
      {
         var c = s.charAt(i);

         if (!isDigit(c)) return false;
      }

      return true;
   }

   function isEmpty(s)
   {
      return ((s == null) || (s.length == 0))
   }

   function isDigit (c)
   {
      return ((c >= "0") && (c <= "9"))
   }

   function testIfCheckboxExistsWithThisName(checkboxName){
	var d=document.survey;numMatches=0;

	for(j=0;j<d.elements.length;j++){
		if(d[j].type=='checkbox' && d[j].name==checkboxName){
			numMatches++;
		}	
	}

   	   if(numMatches>0){return true;}else{return false;};   
   }

function clearAllRadio(rb){
	var L=rb.length;
	for (var i = 0 ; i< L ; i++){
		rb[i].checked=false;
	}
}

function getRadioVal(rb){
	var L=rb.length;var ret="";
	for (var i = 0 ; i< L ; i++){
		if(rb[i].checked) { ret=rb[i].value; break; }
	}
	return(ret);
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
	var i,p,q,nm,test,val,valFormat,num,min,max,errors='',args=MM_validateForm.arguments;
	var d=document.newsletter_registration;

	for (i=0; i<(args.length-2); i+=3) { 
	
		test=args[i+2]; 
		val=MM_findObj(args[i]);
		valFormat=val.name;
		valFormat=valFormat.replace(new RegExp('_','g'), ' ');;

		valFormat1 = valFormat.substr(0,1);
		valFormat=valFormat1.toUpperCase() + valFormat.substr(1);

		if(d[args[i]].length>0){ //field is either radio or dropdown

			if(d[args[i]].type=='select-one'){ // dropdown field

				// NOTE: assumption made that index 0 contains dummy data (e.g. Please select...)
				if(d[args[i]].selectedIndex==0){
					errors += '- '+ valFormat +' requires a selection.\n';
				}

			}else{ //then it must be a radio button group

				//alert('testing radio');

				var numChecked=0;
				//loop through all options in radio group
				for(j=0;j<d[args[i]].length;j++){
					if(d[args[i]][j].checked){
						numChecked++;
					}
				}

				if(numChecked==0){
					errors += '- '+returnDescriptiveFieldName(args[i])+' requires a selection.\n';

				}else if(numChecked==1 && d[args[i]+'_other']!=undefined){ // "other" is only last if it is enabled. Therefore, first check that it exists. Otherwise, skip this check.

					// other is always last, so if the highest element is selected, then other must be filled in
					if(d[args[i]][d[args[i]].length-1].status==true && d[args[i]+'_other'].value==''){
						errors += '- If you select Other in '+returnDescriptiveFieldName(args[i])+' you must provide more detail.\n';
					}
				}				
			}
			
		}else{

			// then this must not be multi choice so use the standard validation
			if (val) 
			{
				nm=valFormat;
				if (val.type == "checkbox")
				{
					if (val.checked == false) errors+='- '+nm+' must be checked.\n';
				}
				else if ((val=val.value)!="")
				{
					if (test.indexOf('isEmail')!=-1)
					{
						p=val.indexOf('@');
						if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
					}
					else if (test!='R')
					{
						num = parseFloat(val);
						if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
						if (test.indexOf('inRange') != -1)
						{
							p=test.indexOf(':');
			  				min=test.substring(8,p);
			  				max=test.substring(p+1);
			  				if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
						}
					}
					
					// additional test for confirmation of email
					// could be done better but hacked for the minute
					if (test.indexOf('isConfirm')!=-1) {
						val=MM_findObj(args[i]);
						myConfirm=MM_findObj("confirm_"+args[i]);
						if (myConfirm.value != val.value) errors+='- Please check your '+nm+' confirmation.\n';
					}
				}
				else if (test.charAt(0) == 'R')
				{
					errors += '- '+ nm +' is required.\n';
			    	}
			}
		}
	}

   	if (errors){ alert('The following error(s) occurred:\n'+errors);}
	return (errors == '');
}