// JavaScript Document

function initForm() {

	$("input:text, input:password, textarea").addClass("idleField");
	$("input:text, input:password, textarea").focus(function() {  
		$(this).removeClass("idleField").addClass("focusField");  
		//if (this.value == this.defaultValue){  
		//	this.value = "";  
		//}  
		//if(this.value != this.defaultValue){  
		//	this.select();  
		//}  
	});  

	$("input:text, input:password, textarea").blur(function() {  
		$(this).removeClass("focusField").addClass("idleField");  
		/*if ($.trim(this.value == "")){  
			this.value = (this.defaultValue ? this.defaultValue : "");  
		}  
		*/
	}); 
	
	
	/* Controls toggle for location lists */
	$("#desired_location_box h3 a").click(function(e){
		e.preventDefault();
		var targetregion = "#" + $(this).parent().next().attr("id");
		$(targetregion).slideToggle(500);
	});

}

function countWords(ID){
	//nWords = ID.value.match(/\s/g).length-1;
	//alert(nWords);
	if( $(ID).val().length == "0" ) {
		return "0";
	}else {
		var nWords = $(ID).val().split(/\b[\s,\.-:;]*/).length;		// \b doesn't pick up numbers!!
//		var nWords = $(ID).val().split(/[\s,\.-:;]*/).length;		
//		var nWords = $(ID).val().split(/[\s\.\?]+/).length;
//		var lastchar = $("#cvpitch").val().substr( $("#cvpitch").val().length - 1, 1 );
//		if( ($("#cvpitch").val().lastIndexOf(" ") != $("#cvpitch").val().length - 1 || lastchar == "\n") && nWords != 1 )
//			nWords = nWords - 1;
		
		var fullStr = $(ID).val() + " ";
		var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
		var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
		var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9']+/gi;
		var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
		var splitString = cleanedStr.split(" ");
		var nWords = splitString.length -1;

		 return nWords;
	}
}


$(document).ready(function() {
	initForm();
});  

