// Copyright (c) 1996-1997 Athenia Associates.
// http://www.webreference.com/js/
// License is granted if and only if this entire
// copyright notice is included. By Tomer Shiran.

function setCookie (name, value, expires, path, domain, secure) {
    var curCookie = name + "=" + escape(value) + (expires ? "; expires=" + expires : "") +
        (path ? "; path=" + path : "") + (domain ? "; domain=" + domain : "") + (secure ? "secure" : "");
    document.cookie = curCookie;
}

function getCookie (name) {
    var prefix = name + '=';
    var c = document.cookie;
    var nullstring = '';
    var cookieStartIndex = c.indexOf(prefix);
    if (cookieStartIndex == -1)
        return nullstring;
    var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
    if (cookieEndIndex == -1)
        cookieEndIndex = c.length;
    return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

function deleteCookie (name, path, domain) {
    if (getCookie(name))
        document.cookie = name + "=" + ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

function fixDate (date) {
    var base = new Date(0);
    var skew = base.getTime();
    if (skew > 0)
        date.setTime(date.getTime() - skew);
}

function rememberMe (f) {
    var now = new Date();
    fixDate(now);
    now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
    now = now.toGMTString();
    if (f.author != undefined)
       setCookie('mtcmtauth', f.author.value, now, '/', '', '');
    if (f.email != undefined)
       setCookie('mtcmtmail', f.email.value, now, '/', '', '');
    if (f.url != undefined)
       setCookie('mtcmthome', f.url.value, now, '/', '', '');
}

function forgetMe (f) {
    deleteCookie('mtcmtmail', '/', '');
    deleteCookie('mtcmthome', '/', '');
    deleteCookie('mtcmtauth', '/', '');
    f.email.value = '';
    f.author.value = '';
    f.url.value = '';
}

function hideDocumentElement(id) {
    var el = document.getElementById(id);
    if (el) el.style.display = 'none';
}

function showDocumentElement(id) {
    var el = document.getElementById(id);
    if (el) el.style.display = 'block';
}

var commenter_name;

function individualArchivesOnLoad(commenter_name) {



 // comments are allowed but not required
    if (commenter_name) {
        hideDocumentElement('name-email');
    } else {
        showDocumentElement('name-email');
    }



    if (document.comments_form) {
        if (!commenter_name && (document.comments_form.email != undefined) &&
            (mtcmtmail = getCookie("mtcmtmail")))
            document.comments_form.email.value = mtcmtmail;
        if (!commenter_name && (document.comments_form.author != undefined) &&
            (mtcmtauth = getCookie("mtcmtauth")))
            document.comments_form.author.value = mtcmtauth;
        if (document.comments_form.url != undefined && 
            (mtcmthome = getCookie("mtcmthome")))
            document.comments_form.url.value = mtcmthome;
        if (document.comments_form["bakecookie"]) {
            if (mtcmtauth || mtcmthome) {
                document.comments_form.bakecookie.checked = true;

            } else {

                document.comments_form.bakecookie.checked = false;

            }

        }

    }

}



function writeTypeKeyGreeting(commenter_name, entry_id) {



    if (commenter_name) {

        document.write('<p>Thanks for signing in, ' + commenter_name +

          '. Now you can comment. '+

'(<a href="http://blogs.portentinteractive.com/mt-comments.cgi?__mode=handle_sign_in&amp;static=1&amp;logout=1&entry_id=' +
entry_id + '">sign out</a>)</p>');

    } else {



        document.write('<p>If you have a TypeKey identity, you can '+

          '<a href="https://www.typekey.com/t/typekey/login?&amp;need_email=1&amp;lang=en_US&amp;t=yEs7WgUwNbJLYxMDiocX&amp;v=1.1&amp;_return=http://blogs.portentinteractive.com/mt-comments.cgi%3f__mode=handle_sign_in%26key=TypeKey%26static=1%26entry_id=' + entry_id + '">sign in</a> '+

          'to use it here.</p>');



    }



}





if ('blogs.portentinteractive.com' != 'www.lindakeithcpa.com') {

    document.write('<script src="http://blogs.portentinteractive.com/mt-comments.cgi?__mode=cmtr_name_js"></script>');

} else {

    commenter_name = getCookie('commenter_name');

}


function showHide(state,elemID) {
	if ((document.all) && document.all[elemID]) {
		// alert('in ie4 or above');
		if (state == 'show' && document.all(elemID)) document.all[elemID].style.display = 'block';
		else if (state == 'hide' && document.all(elemID)) document.all[elemID].style.display = 'none';
		} // end if document.all is recognized
	else {
		if (document.getElementById(elemID)) {
			// Netscape 6 & IE5, access the text's ID, then use the property innerHTML
			// alert('getElementById');
			if (state == 'show' && document.getElementById(elemID)) document.getElementById(elemID).style.display = 'block';
			else if (state == 'hide' && document.getElementById(elemID)) document.getElementById(elemID).style.display = 'none';
		} // end if getElementById is recognized	
	}
	return;
	
}


//email and search form 
function toggle(id) {
	var e = document.getElementById(id);
	if(e.style.display == 'none')
	e.style.display = 'block';
	else
	e.style.display = 'none';
}

function toggleSearch () {
	toggle('searchform');
	showHide('hide','signupform');

}

function toggleSignup () {
	toggle('signupform');
	showHide('hide','searchform');
}

/*function openThanks () {
	//toggle('header-email-thanks');
	showHide('hide','signupform');
	showHide('show','header-email-thanks');
}*/

//email this page
function mailpage()
{
  mail_str = "mailto:?subject= Lender training resource - Linda Keith CPA";
  mail_str += "&body= Here's a great resource for lender training and reference materials:" + location.href; 
  mail_str += ". Linda Keith dubbed the 'CPA that likes to play!' is an accomplished trainer and knows what lender's need to know. Thought you might be interested. Her website is http://www.lindakeithcpa.com.";
  location.href = mail_str;
}

//email Validation

function checkNewsletter() {
	fm = document.forms['listctrl'];
	var missing = "";
	if (fm.email.value == "")
		missing += "E-mail is required.";
	else {
		temp = fm.email.value + " ";
		found = temp.search(/[\w\.-]+@([\w-]+\.){1,3}[a-zA-Z]{2,}\s{1}/);
		if (found != 0)
			missing += "E-mail must be in the form username@domain.com"
	}
	if (missing != "") {
		alert(missing);
		return false;
	}
	return true;
}


// form handling functions
function toggle(id) {
    var elem = document.getElementById(id);
    elem.style.display = (elem.style.display == "none")?"block":"none";
}
function openDiv(id) {
    var elem = document.getElementById(id);
    elem.style.display = "block";
}
function closeDiv(id) {
    var elem = document.getElementById(id);
    elem.style.display = "none";
}
function clearMissing(fm) {
	fm.missing.value = "";
}
function trimFormField(fm, fieldname) {
	formfield = eval("fm." + fieldname);
	formfield.value = formfield.value.replace(/^ */g, '').replace(/ *$/g, '');
}
function requiredFormField(fm, fieldname, fielddesc) {
	formfield = eval("fm." + fieldname);
	if (formfield.value == "")
		addMissing(fm, fielddesc + " is a required field");
}
function emailField(fm, fieldname, fielddesc, reqd) {
	formfield = eval("fm." + fieldname);	
	if (formfield.value == "" && reqd)
		addMissing(fm, fielddesc + " is a required field");
	else if (formfield.value != "") {
		temp = formfield.value + " ";
		found = temp.search(/[\w\.-]+@([\w-]+\.){1,3}[a-zA-Z]{2,}\s{1}/);
		if (found != 0)
			addMissing(fm, fielddesc + " must be in the form abc@def.com");
	}
}
function validateNewsletterSignup(aForm) {
	e_val = aForm.email.value + " ";
	found = e_val.search(/[\w\.-]+@([\w-]+\.){1,3}[a-zA-Z]{2,}\s{1}/);
	if (found != 0) {
		alert("Please enter a valid email address. ie: user@domain.com");
		aForm.email.focus();
		return false;
	}
}
function dateField(fm, fieldname, fielddesc, reqd) {
	formfield = eval("fm." + fieldname);
	if (formfield.value == "" && reqd)
		addMissing(fm, fielddesc + " is a required field");
	else if (formfield.value != "") {
		d = new Date(formfield.value);
		if (d.getFullYear() >= 1900 && d.getFullYear() <= 1969)
			d.setYear(d.getFullYear() + 100);
		if (isNaN(d) || d.getFullYear() < 1970)
			addMissing(fm, fielddesc + " must be in a valid date format.");
		else {
			month = d.getMonth() + 1;
			month_str = month < 10 ? "0" + month : month;
			date = d.getDate();
			date_str = date < 10 ? "0" + date : date;	
			formfield.value = month_str + "/" + date_str + "/" + d.getFullYear();
		}
	}
}
function regexpField(fm, regexp, fieldname, fielddesc, msg, reqd) {
	formfield = eval("fm." + fieldname);
	if (formfield.value != "") {
		temp = formfield.value + " ";
		found = temp.search(regexp);
		if (found != 0)
			addMissing(fm, fielddesc + msg);
	} else if (reqd) {
		addMissing(fm, fielddesc + " is a required field");
	}
}
function addMissing(fm, errmsg) {
	fm.missing.value += "," + errmsg;
}
function submitForm(fm, missingurl) {
	if (fm.missing.value != "") {
		fm.missing.value = fm.missing.value.substring(1);
		fm.action = missingurl;
	}
	fm.submit();
}


// contact form validation

function checkContactForm(fm) {
	clearMissing(fm);
	trimfields = new Array("name","email","phone","company","message");
	for (i = 0; i < trimfields.length; i++)
		trimFormField(fm, trimfields[i]);
	requiredFormField(fm, "name", "Name");
	requiredFormField(fm, "subject", "Subject");
	requiredFormField(fm, "company", "Company");
	emailField(fm, "email", "E-mail Address", true);
	tmp = fm.phone.value + " ";
	if (tmp.search(/\d{10}\s{1}/) == 0)
		fm.phone.value = fm.phone.value.substring(0, 3) + "-" + fm.phone.value.substring(3, 6) + "-" + fm.phone.value.substring(6);
	regexpField(fm, /\d{3}-\d{3}-\d{4}\s{1}/, "phone", "Phone", " must be in the form 123-555-1212", false);	
	requiredFormField(fm, "message", "Message");
	if (fm.message.value.length > 5000)
		addMissing(fm, "Your Comment was " + fm.message.value.length + " characters. Please shorten your message to no more than 5000 characters.");
	submitForm(fm, fm.action);
}