//##########################
// Now the really fun one.
//##########################

/* pass the values for field type (w), field display name (x),
form name (y), the index for the checkbox or radio button (a), and
the number of check boxes or radio buttons in the group (d). */

function checkme(w,x,y,z,a,d )
{

// determine whether or not the a and d are valid data for the radio button.

if(w == "radio"){
var radioIndex = parseInt(a,10);
var radioTotal = parseInt(d,10);
}

// determine whether or not the a and d are valid data for the checkbox.

if(w == "checkbox"){
var intCheckBoxIndex = parseInt(a,10);
var intCheckBoxTotal = parseInt(d,10);
}

// pass the variables to the script fields

var fieldType = w;
var displayName = x;
var formName = y;
var fieldName = z;

// create the constants to be used in concatenating the strings

var strDocument = "document.";
var strValue = ".value";
var strFocus = ".focus();";
var strChecked = ".checked";
var strTrue = "True";

// build the strings to place the curson back in the last field tested using the focus() method

var strGoToField = strDocument + formName + "." + fieldName + strFocus;

// build the string to be tested in text or text area boxes.

var b = strDocument + formName + "." + fieldName + strValue;

//build the string to be tested for a radio box

var c = strDocument + formName + "." + fieldName + "[" + radioIndex + "]" + strChecked;

//create a switch that send the script to different legs depending on the field type.

switch (fieldType)
{
case "radio":
var strButtonChecked = "false";
for(var i = 0; i < radioTotal; i++)
{

//create the string to evaluate for a radio button when there are more than one.

var e = strDocument + formName + "." + fieldName + "[" + i + "]" + strChecked;

/* if the string created above evaluates to true we change the value of

strButtonChecked to True, and then change the value of i so we exit the loop */
if(eval(e))
{
strButtonChecked = "true";
i = (radioTotal + 1);
}
}

//if the variable is not true we let the user know he needs to make a selection.

if(!eval(strButtonChecked))
{

//alert(strButtonChecked +"Checking strButtonChecked");

// Commented this out it was for testing.

alert("You did not make a selection for "+displayName+".");
}
break;
case "checkbox":
var strBoxChecked = "false";
for(var i = 0; i < intCheckBoxTotal; i++)
{
var e = strDocument + formName + "." + fieldName + "[" + i + "]" + strChecked;

//alert(e);

if(eval(e))
{
strBoxChecked = "true";
i = (intCheckBoxTotal + 1);
}
}

//if the variable is not true we let the user know he needs to make a selection.

if(!eval(strBoxChecked))
{
alert("You did not make a selection for "+displayName+".");
}
break;
case "text":

// basic textbox vaildation

if(eval(b) == "")
{
alert("You must enter your "+displayName);
var g = strDocument + formName + "." + fieldName + ".style.backgroundColor ='yellow'";
alert (g)

//eval(strDocument + formName + "." + fieldName + strFocus);

eval(g)
return false;
}
break;
default:
alert("How did you get here?")
break;
}
}