
// Add another lender div.
function add_lender(next) {
	document.getElementById(next).style.display="block";
	document.getElementById(next).style.visibility="visible";
	document.getElementById(next + 'add').style.display="none";
	document.getElementById(next + 'add').style.visibility="hidden";
}

function change_attorney_display(divid)
{ 
	if (document.registration_form.using_regency.value.trim() == "No")
	{ 
		document.getElementById(divid).style.display="block";
		document.getElementById(divid).style.visibility="visible";
	} 
	else
	{ 
		document.getElementById(divid).style.display="none";
		document.getElementById(divid).style.visibility="hidden";
	} 
} 


// Function prototype for trimming white space off strings.
String.prototype.trim = function() {
	a = this.replace(/^\s+/, '');
	return a.replace(/\s+$/, '');
};


//SUBMIT ABSTRACT FORM - CHECK NUMBER OF WORDS
function CheckFieldLength(fn,rn,mc) {
	var len = fn.value.length;
	if (len > mc) {
		fn.value = fn.value.substring(0,mc);
		len = mc;
	}
	document.getElementById(rn).innerHTML = mc - len;
}

function check_length(obj) {

    var total = obj.words = obj.value.getWordCount();
    var x, len = arguments.length;
    for(x=1; x<len-1; ++x) {
        if(arguments[x].words) total += arguments[x].words;
    }
	document.getElementById(obj.name + countsuffix).firstChild.data = obj.words;
	document.getElementById(remainingwords).firstChild.data = total;
	document.getElementById('word_count').value = total;
	word_limit = arguments[len-1];
	if (obj.words > word_limit) {
		document.getElementById(obj.name + '_your_words').style.color = "red";
	}
	else {
		document.getElementById(obj.name + '_your_words').style.color = "#009900";
	}
	if (total > total_limit) {
		document.getElementById('total_words_remaining').style.color = "red";
	}
	else {
		document.getElementById('total_words_remaining').style.color = "#009900";
	}	
	return true;
}

String.prototype.getWordCount = function() {
    return this.replace(/\s+/g, " ")
               .replace(/^\s*/, "")
               .replace(/\s*$/, "")
               .split(" ").length;
}


//SUBMIT ABSTRACT FORM - FORM VALIDATION
function validate(form) {
	
	var requireConsents = false;

	//Check for first name
	if ( document.registration_form.yourname.value.trim() == "" ) {
			alert ( "Please enter your name." );
		document.registration_form.yourname.focus();
		return false;
	}

	if ( document.registration_form.yourloanofficer.value.trim() == "" ) {
			alert ( "Please enter your loan officer." );
		document.registration_form.yourloanofficer.focus();
		return false;
	}

	if ( document.registration_form.youremail.value.trim() == "" ) {
			alert ( "Please enter your email." );
		document.registration_form.youremail.focus();
		return false;
	}

	if ( document.registration_form.ref1phone.value.trim() == "" ) {
			alert ( "Please enter the phone number for your referral." );
		document.registration_form.youremail.focus();
		return false;
	}

	// All is well, return true to allow submit.
	return true;
}