var refcodeWelcomeLast = "";
var refcodeWelcomeOk = 0;
function formRefcodeProcessWelcome () {
	rcValue = document.refcodeWelcomeForm.rc.value;
	if (refcodeWelcomeOk == 1 && rcValue.length == 10) {
		location.href = "/welcome/" + rcValue + "/";
	}
}
function formRefcodeValidationWelcome (formField) {
	justBackspace = 0;
	if (refcodeWelcomeLast != "") {
		refcodeTrim = refcodeWelcomeLast.substring(0,refcodeWelcomeLast.length-1);
		if (refcodeTrim == formField.value) {
			justBackspace = 1;
			refcodeWelcomeLast = formField.value;
		}
	}
	if (refcodeWelcomeLast == "" || justBackspace == 0) {
		allowedChars = "acdhmrstwyACDHMRSTWY";
		tmpValue = "";
		for (i = 0; i < formField.value.length; i++) {
			if (allowedChars.indexOf(formField.value.charAt(i)) != -1) {
				tmpValue = tmpValue + formField.value.charAt(i);
			}
		}
		tmpValue = tmpValue.toUpperCase();
		tmpValueDash = "";
		for (i = 0; i < tmpValue.length; i++) {
			tmpValueDash = tmpValueDash + tmpValue.charAt(i);
			if (i == 0 || i == 6) {
				tmpValueDash = tmpValueDash + "-";
			}
		}
		tmpValue = tmpValueDash;
		if (tmpValue != formField.value) {
			formField.value = tmpValue;
			refcodeWelcomeLast = tmpValue;
		}
		if (tmpValue.length == 10) {
			new Ajax.Request("/data/acct_add.php?ax=checkRef&ref_code=" + tmpValue, {onSuccess: formRefcodeValidationWelcomeDraw});
		} else {
			$("welcomeRefBtn").src = "/images/dw/home_welcome_btn_r_off.png";
			refcodeWelcomeOk = 0;
		}
	}
}
function formRefcodeValidationWelcomeDraw (t) {
	var tmpResponse = t.responseText;
	if (tmpResponse == 1) {
		refcodeWelcomeOk = 1;
		$("welcomeRefBtn").src = "/images/dw/home_welcome_btn_r_on.png";
		$("welcomeRefBtn").style.cursor = "pointer";
	} else {
		refcodeWelcomeOk = 0;
		$("welcomeRefBtn").src = "/images/dw/home_welcome_btn_r_off.png";
	}
}