//Registration JS

function trim(a){return a.replace(/^\s*|\s*$/g,"");}

function XMLParser(arg) {
	var xmlDoc;
	  if ( window.ActiveXObject ){
	   xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
	   xmlDoc.async="false";
	   xmlDoc.loadXML(trim(arg));
	  } else if ( document.implementation.createDocument ){
	   //xmlDoc = document.implementation.createDocument("", "", null);
	   var parser = new DOMParser();
	   arg = arg.replace(/\s*\n\s*/g, "");
	   xmlDoc = parser.parseFromString(trim(arg), "text/xml"); 
	  }
	  return xmlDoc;
}

function registrationOnLoadFunction () {
	QV_SetIsValidFunction($('user.emailAddr'), isValidEmailAddress);
	QV_SetIsValidFunction($('user.secretQId'), isValidSecretQuestion);
}

function actOnAvailability (availability) {
	//$('user.userName').setAttribute('customValidation', 'Y');
	//QV_SetIsValidFunction($('user.emailAddr'), isValidEmailAddress);
	if (availability == 'AVAILABLE') {
		j('#AvailabilityContainer').css("color","#009007")
		j('#AvailabilityContainer').html('Available');
		j('#screenName').removeClass('QV_RequiredAlert');
		j('#screenName').attr('customValidation', '');
	} else if (availability == 'USER_EXISTS'){
		j('#AvailabilityContainer').css("color","#FF0000");
		j('#AvailabilityContainer').html('Not Available');
		j('#screenName').addClass('QV_RequiredAlert');
	} else if (availability == 'NOT_ALLOWED'){
		j('#AvailabilityContainer').css("color","#FF0000")
		j('#AvailabilityContainer').html('Username not allowed.');
		j('#screenName').addClass('QV_RequiredAlert');
	} else if (availability == 'NAME_FORMAT'){
		j('#AvailabilityContainer').css("color","#FF0000")
		j('#AvailabilityContainer').html('Invalid username.');
		j('#screenName').addClass('QV_RequiredAlert');
	} else {
		j('#AvailabilityContainer').html('');
		j('#screenName').removeClass('QV_RequiredAlert');
	}
}

function isNotValid () { return false; }

function userToLower(Username) {
	var lUsername = Username.toLowerCase();
	document.getElementById('screenName').value = lUsername;
}


function checkUsernameAvailability (Username) {
	if (Username) {
		   j.get('usernamecheck.jhtml?username=' + Username, function(data){
				actOnAvailability(data);
		});
	} else {
		if (document.getElementById('screenName') == '') {
			actOnAvailability('');
		}
	}
}

function submitRegistrationForm() {
	j('#registrationForm').request({
		onComplete: function(transport){ if (transport.responseText) j('#RegistrationFormContainer').html(transport.responseText); }
	});
}

function clearError() {
	if (j('#error1')) {
		j('#error1').html('');
	}
	j('#AvailabilityContainer').html('');
}
function clearError2() {
	if (j('#error2')) {
		j('#error2').html('');
	}
}
function clearError3() {
	if (j('#error3')) {
		j('#error3').html('');
	}
}
function clearError4() {
	if (j('#error4')) {
		j('#error4').html('');
	}
}
function clearError5() {
	if (j('#error5')) {
		j('#error5').html('');
	}
}
function clearError6() {
	if (j('#error6')) {
		j('#error6').html('');
	}
}
function clearErrorZip() {
	if (j('#errorZip')) {
		j('#errorZip').html('');
	}
}

function returnHome() {
	window.location.href="/home/home.jhtml";
}


function selectVal() {
	if (document.getElementById('userOptinControl').checked) {
		document.getElementById('user.emailOptinInternal').value = 'Y';
	} else {
		document.getElementById('user.emailOptinInternal').value = 'N';
	}
}
