function populateAddress (chkbox)
{
   if (!chkbox.checked) {
	    document.getElementById('address1_billing').value = document.getElementById('address1_personal').value;
	    document.getElementById('address2_billing').value = document.getElementById('address2_personal').value;
	    document.getElementById('city_billing').value = document.getElementById('city_personal').value;
	    document.getElementById('state_billing').value = document.getElementById('state_personal').value;
	    document.getElementById('zip_billing').value = document.getElementById('zip_personal').value;
	    document.getElementById('phone_billing').value = document.getElementById('phone_personal').value;
   }
	else {
	    document.getElementById('address1_billing').value = "";
	    document.getElementById('address2_billing').value = "";
	    document.getElementById('city_billing').value = "";
	    document.getElementById('state_billing').value = "";
	    document.getElementById('zip_billing').value = "";
	    document.getElementById('phone_billing').value = "";
    }
}

function validateAdminPassword(oldpwd,newpwd,confpwd,errElt)
{
    if (oldpwd == "") {
		errElt.innerHTML = "Admin password cannot be blank.";
	    return false;	
	}
    if (newpwd == "") {
		errElt.innerHTML = "New password cannot be blank.";
	    return false;	
	}
    if (confpwd == "") {
		errElt.innerHTML = "Password confirmation cannot be blank.";
	    return false;	
	}
    if (newpwd.length < 5) {
		errElt.innerHTML = "Password must be at least 5 characters long.";
	    return false;	
	}
    if (newpwd.indexOf(' ') != -1) {
		errElt.innerHTML = "New password cannot contain spaces.";
	    return false;	
	}
    if (newpwd != confpwd) {
		errElt.innerHTML = "New password and confirm password must match.";
	    return false;	
	}
	return true;

} 
function validatePassword(oldpwd,newpwd,confpwd,errElt) 
{
    if (oldpwd == "") {
		errElt.innerHTML = "Old password cannot be blank.";
	    return false;	
	}
    if (newpwd == "") {
		errElt.innerHTML = "New password cannot be blank.";
	    return false;	
	}
    if (confpwd == "") {
		errElt.innerHTML = "Password confirmation cannot be blank.";
	    return false;	
	}
    if (newpwd.length < 4) {
		errElt.innerHTML = "Password must be at least 4 characters long.";
	    return false;	
	}
    if (newpwd.indexOf(' ') != -1) {
		errElt.innerHTML = "New password cannot contain spaces.";
	    return false;	
	}
    if (newpwd != confpwd) {
		errElt.innerHTML = "New password and confirm password must match.";
	    return false;	
	}
	return true;
}

function classAdd()
{
	var scopes = document.getElementById('current_classes').options;

	for (var i = 0; i < scopes.length; i++) {
      if (scopes[i].selected) 
	  {
		  var selectedScopes = document.getElementById('sclasses[]').options;
		  var notThere = true;
		  for (var j = 0; j < selectedScopes.length; j++) {
			  if (selectedScopes[j].value == scopes[i].value)
			  {
				  notThere = false;
			  }
		  }
		  
		  if (notThere) {
	          var newOpt = document.createElement('option');
	          newOpt.innerHTML = scopes[i].text;
		      newOpt.value = scopes[i].value;
		      newOpt.selected = 'selected';
	          document.getElementById('sclasses[]').appendChild(newOpt);
		  }
	  }
	}
}

function classRemove()
{
	var scopes = document.getElementById('sclasses[]').options;
	
	for (var i = 0; i < scopes.length; i++) {
      if (scopes[i].selected) 
	  {
	      document.getElementById('sclasses[]').removeChild(scopes[i]);
	  }
	}
}

