var ErrMsg = "";

function hasValue(obj, obj_type) {
    if (obj_type == "text" || obj_type == "password") {
    	if (obj.value.length == 0) 
      		return false;
    	else 
      		return true;
    } else if (obj_type == "select") {
		for (i=0; i < obj.length; i++) {
			if (obj.options[i].selected)
				return true;
		}
       	return false;	
	} else if (obj_type == "SINGLE_VALUE_RADIO" || obj_type == "SINGLE_VALUE_CHECKBOX") {
		if (obj.checked)
			return true;
		else
       		return false;	
	} else if (obj_type == "radio" || obj_type == "checkbox") {
        for (i=0; i < obj.length; i++) {
			if (obj[i].checked)
				return true;
		}
       	return false;	
	}
}

function  checkForm(thisForm) {
    if  (!hasValue(thisForm.user, "text" )) {
        thisErr = "Please fill in a User Name";
		addErr(thisErr);
	}

    if  (!hasValue(thisForm.pwd1, "text" )) {
        thisErr = "Please fill in a Password";
		addErr(thisErr);
	}

    if  (!hasValue(thisForm.pwd2, "text" )) {
        thisErr = "Please re-type your password";
		addErr(thisErr);
	}
	
	
	if (hasValue(thisForm.pwd1, "text") && hasValue(thisForm.pwd2, "text")) {
		if (thisForm.pwd1.value != thisForm.pwd2.value) {
			thisErr = "The passwords you entered do not match";
			addErr(thisErr);
		} else {
			if (thisForm.pwd1.value.length < 5) {
				thisErr = "Password must be at least 6 characters";
				addErr(thisErr);
			}
		}
	}
	
	if (ErrMsg != "") {
		alert(ErrMsg);
		ErrMsg = "";
		return false;
	}
    return true;
}

function addErr(err) {
    if (ErrMsg == "") {
		ErrMsg = err;
	} else {
		ErrMsg = ErrMsg + "\n" + err;
	}
}

function checkCookies()
{
 /* check for a cookie */
  if (document.cookie == "") 
  {
    /* if a cookie is not found - alert user -
     change cookieexists field value to false */
    alert("You must have cookies enabled within\nyour browser before you can proceed.");

    /* If the user has Cookies disabled an alert will let him know 
        that cookies need to be enabled to log on.*/ 

    document.forms["frmRegister"].cookieexists.value = "false";
  } else {
   
   /* this sets the value to true and nothing else will happen,
       the user will be able to log on*/
    document.forms["frmRegister"].cookieexists.value = "true";
  }
}

/* Set a cookie to be sure that one exists.
   Note that this is outside the function*/
document.cookie = 'killme' + escape('nothing');






