function validateCaptcha(str) {
	if (str.length != 6) {
		return false;
	}

	for (var i = 0; i < str.length; i++) {
		var ch = str.charAt(i);
		if ((ch >= '0') && (ch <= '9')) {
		} else {
			return false;
		}
	}

	return true;
}

function validatePhonePassword(str) {
	if (str.length < 3) {
		return false;
	}
	return true;
}

function validatePassword(str) {
	var hasDigit = 0;
	var hasAlpha = 0;

	if (str.length < 5) {
		return false;
	}
	if (str.length > 12) {
		return false;
	}

	for (var i = 0; i < str.length; i++) {
		var ch = str.charAt(i);
		if ((ch >= '0') && (ch <= '9')) {
			hasDigit = 1;
		}
		if ((ch >= 'a') && (ch <= 'z')) {
			hasAlpha = 1;
		}
		if ((ch >= 'A') && (ch <= 'Z')) {
			hasAlpha = 1;
		}
	}

	if ((hasDigit + hasAlpha) != 2) {
		return false;
	}

	return true;
}

function validateEmail(str) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at) == -1) {
		return false;
	}

	if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {
		return false;
	}

	if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {
		return false;
	}

	if (str.indexOf(at,(lat + 1)) != -1) {
		return false;
	}

	if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {
		return false;
	}

	if (str.indexOf(dot, (lat + 2)) == -1) {
		return false;
	}
		
	if (str.indexOf(" ") != -1) {
		return false;
	}
	if (str.indexOf(";") != -1) {
		return false;
	}

	return true;
}

function createAccount_checkName(elID, imgAcceptSrc, imgRejectSrc) {
	createAccount_checkEditField(elID, imgAcceptSrc, imgRejectSrc);
}

function createAccount_checkEmail(elID, imgAcceptSrc, imgRejectSrc) {
	var el = document.getElementById(elID);
	if (el == null) {
		return;
	}
	var condition = validateEmail(el.value);

	createAccount_checkEditField_condition(elID, imgAcceptSrc, imgRejectSrc, condition);
}

function createAccount_checkPhonePassword(elID, imgAcceptSrc, imgRejectSrc) {
	var el = document.getElementById(elID);
	if (el == null) {
		return;
	}
	var condition = validatePhonePassword(el.value);

	createAccount_checkEditField_condition(elID, imgAcceptSrc, imgRejectSrc, condition);
}

function createAccount_checkCity(elID, imgAcceptSrc, imgRejectSrc) {
	createAccount_checkEditField(elID, imgAcceptSrc, imgRejectSrc);
}

function createAccount_checkCaptcha(elID, imgAcceptSrc, imgRejectSrc) {
	var el = document.getElementById(elID);
	if (el == null) {
		return;
	}
	var condition = validateCaptcha(el.value);

	createAccount_checkEditField_condition(elID, imgAcceptSrc, imgRejectSrc, condition);
}

function createAccount_checkEditField(elID, imgAcceptSrc, imgRejectSrc) {
	var el = document.getElementById(elID);
	if (el == null) {
		return;
	}

	var checkElID = "check_" + elID;
	var checkEl = document.getElementById(checkElID);

	if (el.value == "") {
		el.className = 'contentEditFieldRejected';
		if (checkEl != null) {
			checkEl.src = imgRejectSrc;
			checkEl.style.visibility = "visible";
		}
	} else {
		el.className = 'contentEditFieldAccepted';
		if (checkEl != null) {
			checkEl.src = imgAcceptSrc;
			checkEl.style.visibility = "visible";
		}
	}
}

function createAccount_checkEditField_condition(elID, imgAcceptSrc, imgRejectSrc, condition) {
	var el = document.getElementById(elID);
	if (el == null) {
		return;
	}

	var checkElID = "check_" + elID;
	var checkEl = document.getElementById(checkElID);

	if (!condition) {
		el.className = 'contentEditFieldRejected';
		if (checkEl != null) {
			checkEl.src = imgRejectSrc;
			checkEl.style.visibility = "visible";
		}
	} else {
		el.className = 'contentEditFieldAccepted';
		if (checkEl != null) {
			checkEl.src = imgAcceptSrc;
			checkEl.style.visibility = "visible";
		}
	}
}

function createAccount_checkPassword(elID, celID, imgAcceptSrc, imgRejectSrc) {
	var el = document.getElementById(elID);
	if (el == null) {
		return;
	}
	var cel = document.getElementById(celID);
	if (cel == null) {
		return;
	}

	var checkElID = "check_" + elID;
	var checkEl = document.getElementById(checkElID);
	var ccheckElID = "check_" + celID;
	var ccheckEl = document.getElementById(ccheckElID);

	var condition = validatePassword(el.value);

	if (condition) {
		el.className = 'contentEditFieldAccepted';
		if (checkEl != null) {
			checkEl.src = imgAcceptSrc;
			checkEl.style.visibility = "visible";
		}
	} else {
		el.className = 'contentEditFieldRejected';
		if (checkEl != null) {
			checkEl.src = imgRejectSrc;
			checkEl.style.visibility = "visible";
		}
	}

	if ((el.value == cel.value) && (condition)) {
		cel.className = 'contentEditFieldAccepted';
		if (ccheckEl != null) {
			ccheckEl.src = imgAcceptSrc;
			ccheckEl.style.visibility = "visible";
		}
	} else {
		cel.className = 'contentEditFieldRejected';
		if (ccheckEl != null) {
			ccheckEl.src = imgRejectSrc;
			ccheckEl.style.visibility = "visible";
		}
	}
}
