// /javascript/checkForm.js
//-----------------------------
function markActive(id){
	var box = document.getElementById(id);
	box.style.borderColor='#919401';
	box.style.backgroundColor='#FCFE96';
}
//-----------------------------
function removeActive(id){
	var box = document.getElementById(id);
	box.style.borderColor='';
	box.style.backgroundColor='';		
}
//-----------------------------
function clearError(id){
	var box = document.getElementById(id);
	var errDiv = document.getElementById(id+'Error');			
	if(errDiv != null){
		errDiv.parentNode.removeChild(errDiv);
	}
}
//-----------------------------
function setValid(id){
	var box = document.getElementById(id);
	box.style.borderColor='#7fba00';
	box.style.backgroundColor='#E9FFB9';
}
//-----------------------------
function setInvalid(id){
	var box = document.getElementById(id);
	box.style.borderColor='#CE0A0A';
	box.style.backgroundColor='#FDCCCC';
}
//-----------------------------
function checkValid(id, regexp, msg, required){
	clearError(id);
	var inputBox = document.getElementById(id);
	if(inputBox.value.length == 0 && required != true){
		removeActive(id);
		return true;
	}
	if(inputBox.value.search(regexp) == -1){
		setInvalid(id);
		createError(id,msg);
		return false;
	} else {
		setValid(id);
	}
	return true;
}
//-----------------------------
function createError(id,msg){
	var divClassName = 'formError';
	var parent = document.getElementById(id).parentNode;
	var divIdName = id+'Error';
	var errDiv = document.createElement('div');
	var errTxt = document.createTextNode(msg);
	errDiv.appendChild(errTxt);
	//errDiv.setAttribute('class',divClassName);
	errDiv.style.color = '#FF0000';
	errDiv.style.fontWeight = 'bold';
	errDiv.setAttribute('id',divIdName);
	if(document.getElementById(divIdName)==null){
		parent.appendChild(errDiv);
	}
}
