// JavaScript Document

var retStr = "";

function procForm(){
	if (checkForm(document.getElementById('newReg'))){
		var sc = new SecureContext(retStr);
		sc.secure('Password');
		cQStr = sc.strText;
		cQStr = cQStr.replaceAll(' ', '~\~');
		document.location="its_decrypt_newreg.asp?" + cQStr;
	}
		
		//document.location="its_regproc.asp?" + retStr;}
}


function checkForm(form) { 

	var cMsg = "";
	var bFocus = false;

	 if(form.lastname.value == "") { 
		 cMsg = cMsg + "\nYour Name cannot be blank!"; 
		 if (!bFocus){
		 bFocus=true;
		 form.lastname.focus(); }} 

	 if(form.username.value == "") { 
		 cMsg = cMsg + "\nUsername cannot be blank!"; 
		 if (!bFocus){
		 bFocus=true;
		 form.username.focus(); }} 

	 if(form.username.value.length < 4) { 
		cMsg = cMsg + "\nUsername must contain at least four characters!"; 
		 if (!bFocus){
		 bFocus=true;
		 form.username.focus(); }} 

	 var re = /^\w+$/; 
	 if(!re.test(form.username.value)) { 
		 cMsg = cMsg + "\nUsername must contain only letters, numbers and underscores!"; 
		 if (!bFocus){
		 bFocus=true;
		 form.username.focus(); }} 

	 if (!isValidEmail(form.email.value)){ 
		 cMsg = cMsg + "\nThe email address is not valid!"; 
		 if (!bFocus){
		 bFocus=true;
		 form.email.focus(); }} 

	 if(form.pwd1.value == form.username.value) { 
		cMsg = cMsg + "\nPassword must be different from username!"; 
		 if (!bFocus){
		 bFocus=true;
		 form.pwd1.focus(); }} 

	 if(form.pwd1.value == "") { 
		cMsg = cMsg + "\nPlease enter and re-type a valid password!"; 
		 if (!bFocus){
		 bFocus=true;
		 form.pwd1.focus(); }} 
		 
	 if (form.pwd1.value !== form.pwd2.value) { 
		cMsg = cMsg + "\nThe two password fields do not match!"; 
		 if (!bFocus){
		 bFocus=true;
		 form.pwd1.focus(); }} 

	 if(form.pwd1.value.length < 6) { 
		cMsg = cMsg + "\nPassword must contain at least six characters!"; 
		 if (!bFocus){
		 bFocus=true;
		 form.pwd1.focus(); }} 

	 re = /[0-9]/; 
	 if(!re.test(form.pwd1.value)) { 
		 cMsg = cMsg + "\nPassword must contain at least one number (0-9)!"; 
		 if (!bFocus){
		 bFocus=true;
		 form.pwd1.focus(); }} 
	 
	 re = /[a-z]/; 
	 if(!re.test(form.pwd1.value)) { 
		 cMsg = cMsg + "\nPassword must contain at least one lowercase letter (a-z)!"; 
		 if (!bFocus){
		 bFocus=true;
		 form.pwd1.focus(); }} 
	 
	 re = /[A-Z]/; 
	 if(!re.test(form.pwd1.value)) { 
		 cMsg = cMsg + "\nPassword must contain at least one uppercase letter (A-Z)!"; 
		 if (!bFocus){
		 bFocus=true;
		 form.pwd1.focus(); }} 

	 if(form.portfolio.value == "") { 
		 cMsg = cMsg + "\nThe portfolio cannot be blank!"; 
		 if (!bFocus){
		 bFocus=true;
		 form.portfolio.focus(); }} 
		 
	 if(!form.terms.checked) { 
		 cMsg = cMsg + "\nYou must agree to the terms!"; 
		 if (!bFocus){
		 bFocus=true;
		 form.terms.focus(); }} 
	 
	 if (cMsg!==""){
		cMsg = "Please correct these fields:\n" +cMsg;
		form.pwd1.value = "";
		form.pwd2.value = ""; 
	 	alert(cMsg);
		return false; }
	 
	 retStr="fn="+form.firstname.value+"&ln="+form.lastname.value+"&co="+form.company.value+
	 			"&un="+form.username.value+"&em="+form.email.value+"&pw="+form.pwd1.value+"&po="+form.portfolio.value+"&uip="+form.uip.value
	 
	 return true; 
} 


function isValidEmail(str) {
	return (str.lastIndexOf(".") > 2) && (str.indexOf("@") > 0) && (str.lastIndexOf(".") > (str.indexOf("@")+1)) && (str.indexOf("@") == str.lastIndexOf("@"));
} 


function bodyOnLoad(){}

function bodyOnUnload(){}
