
//public vars for allowed characters in each type of login str
var login_keepchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
var display_keepchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ.- ";
var email_keepchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_@.";
var name_keepchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ-";

var rule_matrix = new Array();
rule_matrix[0] = "first_and_last_name_rule";
rule_matrix[1] = "permalink_rule";
rule_matrix[2] = "author_name_rule";
rule_matrix[3] = "email_rule";
rule_matrix[4] = "password_rule";


function highlight_rule(idx){
	//highlight appropriate right panel
	for(i=0;i<rule_matrix.length;i++){ 
		document.getElementById(rule_matrix[i]).className = (rule_matrix[i] == idx? "signup_rule_highlighted" : "signup_rule_unhighlighted");
	}
}
function clear_rules(){
	//clear any highlighting
	//happens druing onBlur event
	for(i=0;i<rule_matrix.length;i++){ 
		document.getElementById(rule_matrix[i]).className = "signup_rule_unhighlighted";
	}
}

function auto_fill() {
	if ($("#user_last_name").val().length > 0 && $("#user_first_name").val().length > 0){
		if ($("#user_permalink").val().length == 0){
		$("#user_permalink").val(strip_it($("#user_first_name").val() + "" + $("#user_last_name").val(), login_keepchars, true).toLowerCase());
		}
		if($("#user_name").val().length == 0){
			$("#user_name").val($("#user_first_name").val() + " " + $("#user_last_name").val());
		}
	}	
}

/*
function check_login_name(val){
	var msg = "";
	
	if (val.length > 0){
		//if too short
		if (val.length < 5){
			msg = "Your login name is only " + val.length + " letter" + (val.length == 1? "" : "s") + " long. It must be at least 5 letters long.";
		} 
		//chars in str that aren't in login_keepchars
		else if(strip_it(val, login_keepchars, true).length < val.length){
			msg = "Some of the characters you entered cannot be part of your login name: \"" + strip_it(val, login_keepchars, false) + "\".";
		}	
	}
	//throw msg
	write_in("note0", msg);
}
function check_display_name(val){
	var msg="";

	if(val.length > 0){
		//look for stray periods
		var found_stray_period = false;
		found_stray_period = (val.split(".").length > val.split(". ").length) || (val.indexOf(" . ") > -1);
		
		//look for excessive dashes
		var excessive_dashes = (val.split("-").length > 3 || val.split("--").length > 1);
		
		//look for stray spaces
		var found_stray_spaces = false;
		found_stray_spaces = (val.split("  ").length > 1);
		
		//more sanity vars
		var found_bad_initial = false;
		var initial_count = 0;
		var proper = true;
		
		//split val into words
		wd_split = val.split(" ");

		//find bad initials
		for(var i=0;i<wd_split.length;i++){
			//check for straggler initials
			if (wd_split[i].length == 1){
				wd_split[i] = wd_split[i].toUpperCase() + ".";
				found_bad_initial = true;
			}
			//Get count of initials
			if(wd_split[i].length == 2 && wd_split[i].indexOf(".") > -1){
				initial_count++;
			}
			//check for periods in long strings
			if(wd_split[i].length > 2 && wd_split[i].indexOf(".") > -1){
				found_stray_period = true;
			}
			//check proper nounage
			if(wd_split[i].substring(0,1) != wd_split[i].substring(0,1).toUpperCase()){
				wd_split[i] = wd_split[i].substring(0, 1).toUpperCase() + wd_split[i].substring(1, wd_split[i].length);
				proper = false;
			}
		}	

		//error checks
		//too short
		if (val.length < 5){
			msg = "Your display name is only " + val.length + " letter" + (val.length == 1? "" : "s") + " long. It must be at least 5 letters long.";		
		}
		//too long
		else if (val.length > 50){
			msg = "Your display name is " + val.length + " letters long. It can be no longer than 50 letters long.";		
		}
		//chars in str that aren't in display_keepchars
		else if (strip_it(val, display_keepchars, true).length < val.length){
			msg = "Some of the characters you entered cannot be part of your display name: \"" + strip_it(val, display_keepchars, false) + "\".";		
		}
		//stray period/s
		else if(found_stray_period){
			msg = "Periods can only be used after initials.";
		}
		//stray space/s
		else if(found_stray_spaces){
			msg = "Only one space can be used between words.";
		}
		//excessive dashes
		else if(excessive_dashes){
			msg = "No more than two, non-consecutive dashes can be used.";
		}
		//bad initials
		else if(found_bad_initial){
			msg = "Initials must be followed by a period. We suggest the following: \"" + wd_split.join(" ") + "\".";
		}
		//too many initials
		else if(initial_count > 2){
			msg = "Hey, e.e.e.e. Cummings! Only two initials are allowed."
		}
		//not proper
		else if(!proper){
			msg = "Only proper nouns are allowed. We suggest the following: \""  + wd_split.join(" ") + "\".";
		}
	}
	
	//throw error
	write_in("note1", msg);	
}
function check_email(val){
	var msg = "";
	
	if (val.length > 0){
		//chars in str not in email_keepchars
		if (strip_it(val, email_keepchars, true).length < val.length){
			msg = "Some of the characters you entered cannot be part of your e-mail address: \"" + strip_it(val, email_keepchars, false) + "\".";		
		}
		//couldn't find @ char and/or . char
		if(val.indexOf("@")<1 || val.indexOf(".")<1){
			msg = "Your e-mail address is not correctly formatted.";
		}
	}
	
	//throw msg
	write_in("note2", msg);	
}
function check_pw(val){
	var msg = "";
	
	if(val.length > 0){
		//too short
		if (val.length < 5){
			msg = "Your password is only " + val.length + " letter" + (val.length == 1? "" : "s") + " long. It must be at least 5 letters long.";		
		}
		//too long
		else if (val.length > 25){
			msg = "Your password is " + val.length + " letters long. It can be no longer than 25 letters long.";		
		}
		//has spaces
		else if(val.indexOf(" ") > -1){
			msg = "No spaces are allowed.";
		}
		//doesn't have at least one number
		else if(strip_it(val, "0123456789", true).length == 0){
			msg = "Your password must contain at least one number.";
		}
		//same as login or display name
		else if(val == getId("user_email").value || val ==  getId("user_author_attributes_name").value){
			msg = "Your password cannot be the same as your login name or your display name.";
		}
	}
	
	//throw msg
	write_in("note3", msg);
}
function check_repw(val){
	var msg = "";
	var pw_val = getId("user_password").value
	
	//repassword not equal to password
	if(val != "" && pw_val != "" && val != pw_val){
		msg = "Uh oh. The two passwords you entered do not match."
	}
	
	//throw erro
	write_in("note4", msg);
}
function position_splash(){
	var obj = getId("dv_splash")
	obj.style.top = (Math.random()*700) + 'px';
	
	//Can randomize right margin, too
	//Dep'd for now
	//obj.style.right = (Math.random() * 100) + 'px';
}
function check_fname(val){
	var msg = "";
	
	//check for bad chars
	if (strip_it(val, name_keepchars, true).length < val.length){
		msg = "Some of the characters you entered cannot be part of your display name: \"" + strip_it(val, name_keepchars, false) + "\".";		
	}
	//check for proper noun
	else if (val.substring(0,1) != val.substring(0,1).toUpperCase()){
		msg = "Only proper nouns are allowed. We suggest: \"" + val.substring(0,1).toUpperCase() + val.substring(1, val.length) + "\".";
	}
	//check for excessive dashes
	else if (val.split("-").length > 2 || val.split("--").length > 1){
		msg = "No more than two, non-consecutive dashes can be used.";
	}
	
	//Display note
	write_in("note10", msg);
}
function check_lname(val){
	var msg = "";
	
	//check for bad chars
	if (strip_it(val, name_keepchars, true).length < val.length){
		msg = "Some of the characters you entered cannot be part of your display name: \"" + strip_it(val, name_keepchars, false) + "\".";		
	}
	//check for proper noun
	else if (val.substring(0,1) != val.substring(0,1).toUpperCase()){
		msg = "Only proper nouns are allowed. We suggest: \"" + val.substring(0,1).toUpperCase() + val.substring(1, val.length) + "\".";
	}
	//check for excessive dashes
	else if (val.split("-").length > 2 || val.split("--").length > 1){
		msg = "No more than two, non-consecutive dashes can be used.";
	}
	
	//write message
	write_in("note11", msg);
	
	//see if no errors
	if (msg == "" && getId("user_last_name").value.length > 0 && getId("user_first_name").value.length > 0 && getId("note10").innerHTML == ""){
		if (getId("author_permalink").value.length == 0){
		getId("author_permalink").value = strip_it(getId("user_first_name").value + "_" + getId("user_last_name").value, login_keepchars, true).toLowerCase();
		}
		if(getId("author_name").value.length == 0){
			getId("author_name").value = getId("user_first_name").value + " " + getId("user_last_name").value;
		}
	}
}
*/





