<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
function runTestimonials(optObj) {
	// Variables
	var optObj = optObj || {}
	var slide = optObj.slide || 0;
	var nextSlide = optObj.slide+1;
	var duration = optObj.duration || 3000;
	var container = $(document.getElementById(optObj.insertDiv)) || '';
	var insertDiv = optObj.insertDiv;
	var testimonials = optObj.testimonials || {}
	// Make sure the next slide doesn't go past the length of the testimonials array
	if (nextSlide > testimonials.length-1) {nextSlide = 0;}
	container.innerHTML = testimonials[slide];
	Effect.Fade(container,{from:0.01,to:1.0})
	setTimeout("Effect.Fade('"+insertDiv+"',{from:1.0,to:0.01});",duration);
	setTimeout("initTestimonials({slide:"+nextSlide+",insertDiv:'"+insertDiv+"'});",duration+1000);
}
function initTestimonials(optObj) {
	// Variables
	var optObj = optObj || {}
	var insertDiv = optObj.insertDiv;
	// Create testimonials array
	myTestimonials = Array();
	myTestimonials[0] = '"Thank you for all you did for us.<br>We really appreciate your hard work."<br>-<strong>Beth and Josh</strong>';
	myTestimonials[1] = '"Thank you for all your help!<br>I wish all Lenders were as<br>accommodating as you have been!"<br>-<strong>Dawn</strong>';
	myTestimonials[2] = '"Once we found the house of our dreams, the Four Star team patiently worked with us, and answered our every question..."<br>-<strong>Dave & Geri</strong>';
	myTestimonials[3] = '"Thank you so much for the quick loan approval and closing."<br>-<strong>Tricia</strong>';
	myTestimonials[4] = '"Thanks again for all you did. Keep up the great work."<br>-<strong>Michelle Steffrey</strong>';
	myTestimonials[5] = '"Thank you so much for helping make our dream house come true, you are truly appreciated.  P.S. We\'re in and the whole family loves it including the kittens!"<br />-<strong>The Grembowski\'s</strong>';
	// Determine slide, if not defined, choose random slide
	var slide = optObj.slide || Math.floor(Math.random()*(myTestimonials.length-1));
	// Initialize testimonials
	runTestimonials({testimonials:myTestimonials,insertDiv:insertDiv,duration:5000,slide:slide})
}
function showContent() {
	// Variables
	var container = $('showContent');
	var cookie = readCookie('4starShowContent');
	// If cookie exists...
	if (cookie) {
		// Set variable "sC" to the content on the page.
		sC = container.innerHTML;
		// Add the welcome message to content and append to page
		container.innerHTML = showContent_welcome(cookie) + sC;
	// If cookie does not exist...
	} else {
		// Grab pages content
		sC = container.innerHTML;
		// Replace content with the e-mail form
		container.innerHTML = showContent_form();
	}
}
function showContent_form() {
	// Default CSS for form
	CSSRule('.sc_tbl td',{fontFamily:'verdana',fontSize:'11px'})
	CSSRule('.sc_form',{width:'310px',border:'2px solid #CCC',padding:'5px'})
	// Build form HTML
	var form;
	form  = '<div align=center><div class="sc_form"><form name="showContentForm" id="showContentForm">';
	form += '	<table width="100%" border="0" cellspacing="0" cellpadding="4" class="sc_tbl">';
	form += '		<tr>';
	form += '			<td colspan="2" style="color:#666;text-align:justify;line-height:145%">Please fill out the form below for more information. We promise we will never sell or lease your contact information to anybody.</td>';
	form += '		</tr>';
	form += '		<tr>';
	form += '			<td width="70"><strong>Name</strong></td>';
	form += '			<td align="right"><input type="text" name="sc_name" id="sc_name" size="32" onkeydown="if(event.keyCode==13) {showContent_submit();}"></td>';
	form += '		</tr>';
	form += '		<tr>';
	form += '			<td><strong>E-mail</strong></td>';
	form += '			<td align="right"><input type="text" name="sc_email" id="sc_email" size="32" onkeydown="if(event.keyCode==13) {showContent_submit();}"></td>';
	form += '		</tr>';
	form += '		<tr>';
	form += '			<td align="right" colspan="2"><input type="button" onclick="showContent_submit()" value="Submit"></td>';
	form += '		</tr>';
	form += '	</table>';
	form += '</form></div></div>';
	return form;
}
function showContent_submit() {
	// Variables
	var container = $('showContent');
	var form = $('showContentForm');
	var form_name = $('sc_name');
	var form_email = $('sc_email');

	if((!form_name.value.empty() || !form_email.value.empty()) && testEmail(form_email.value)) {
		// Create cookie
		createCookie('4starShowContent',form_name.value,340,'fourstarmortgagemidland.com');
		// Set the html to the submitted name and the content on the page
		container.innerHTML = showContent_welcome(form_name.value) + sC;
		// Using ajax, send email
		new Ajax.Request('/wwwroot/f/fourstarmortgagemidland/ajax/showcontent.cfm', {
			// Grab form data and submit
			postBody:'sc_email='+form_email.value+'&sc_name='+form_name.value,
			// Eval returned result from ajax request
			onSuccess: function(transport){
				eval(transport.responseText);
			}
		});
	} else {
		// Form was not filled out completely, or the e-mail entered is invalid
		alert('Please fill out the form completely.');
	}
}
function showContent_welcome(name) {
	return 'Hello <strong>' + name + '</strong>,<br><br>';
}

function showReports() {
	// Variables
	var container = $('showReports');
	var cookie = readCookie('4starShowReports');
	// If cookie exists...
	if (cookie) {
		// Set variable "sC" to the content on the page.
		sR = container.innerHTML;
		// Add the welcome message to content and append to page
		container.innerHTML = showReports_welcome(cookie) + sR;
	// If cookie does not exist...
	} else {
		// Grab pages content
		sR = container.innerHTML;
		// Replace content with the e-mail form
		container.innerHTML = showReports_form();
	}
}
function showReports_form() {
	// Default CSS for form
	CSSRule('.sr_tbl td',{fontFamily:'verdana',fontSize:'11px'})
	CSSRule('.sr_form',{width:'310px',border:'2px solid #CCC',padding:'5px'})
	// Build form HTML
	var form;
	form  = '<div align=center><div class="sr_form"><form name="showReportsForm" id="showReportsForm">';
	form += '	<table width="100%" border="0" cellspacing="0" cellpadding="4" class="sr_tbl">';
	form += '		<tr>';
	form += '			<td colspan="2" style="color:#666;text-align:justify;line-height:145%">Please fill out the form below to access the free reports. We promise we will never sell or lease your contact information to anybody.</td>';
	form += '		</tr>';
	form += '		<tr>';
	form += '			<td width="70"><strong>Name</strong></td>';
	form += '			<td align="right"><input type="text" name="sr_name" id="sc_name" size="32" onkeydown="if(event.keyCode==13) {showReports_submit();}"></td>';
	form += '		</tr>';
	form += '		<tr>';
	form += '			<td><strong>Phone</strong></td>';
	form += '			<td align="right"><input type="text" name="sr_phone" id="sc_phone" size="32" onkeydown="if(event.keyCode==13) {showReports_submit();}"></td>';
	form += '		</tr>';
	form += '		<tr>';
	form += '			<td><strong>E-mail</strong></td>';
	form += '			<td align="right"><input type="text" name="sr_email" id="sc_email" size="32" onkeydown="if(event.keyCode==13) {showReports_submit();}"></td>';
	form += '		</tr>';
	form += '		<tr>';
	form += '			<td align="right" colspan="2"><input type="button" onclick="showReports_submit()" value="Submit"></td>';
	form += '		</tr>';
	form += '	</table>';
	form += '</form></div></div>';
	return form;
}
function showReports_submit() {
	// Variables
	var container = $('showReports');
	var form = $('showReportsForm');
	var form_name = $('sr_name');
	var form_email = $('sr_email');
	var form_phone = $('sr_phone');

	if((!form_name.value.empty() && !form_phone.value.empty() || !form_email.value.empty()) && testEmail(form_email.value)) {
		// Create cookie
		createCookie('4starShowReports',form_name.value,340,'fourstarmortgagemidland.com');
		// Set the html to the submitted name and the content on the page
		container.innerHTML = showReports_welcome(form_name.value) + sR;
		// Using ajax, send email
		new Ajax.Request('/wwwroot/f/fourstarmortgagemidland/ajax/showReports.cfm', {
			// Grab form data and submit
			postBody:'sr_email='+form_email.value+'&sr_name='+form_name.value+'&sr_phone='+form_phone.value,
			// Eval returned result from ajax request
			onSuccess: function(transport){
				eval(transport.responseText);
			}
		});
	} else {
		// Form was not filled out completely, or the e-mail entered is invalid
		alert('Please fill out the form completely.');
	}
}
function showReports_welcome(name) {
	return 'Hello <strong>' + name + '</strong>,<br><br>';
}

function preForm_submit() {
	var form = $('pre_form');
	var form_borrower = $('app_b_borrower');
	var form_phone = $('app_b_homephone');
	var form_ss = $('app_b_ss');
	var form_dob = $('app_b_dob');
	var form_address = $('app_b_present_address');
	var form_city = $('app_b_city');
	var form_zip = $('app_b_zip');
	var form_state = $('app_b_state');
	var error_msg = '';
	
	if (form_borrower.value.empty()) {
		error_msg += '- Borrower is required.\n';
		form_borrower.style.border = '1px solid red';
	} else {
		form_borrower.style.border = '1px solid #7f9db9';
	}
	if (form_phone.value.empty()) {
		error_msg += '- Borrower is required.\n';
		form_phone.style.border = '1px solid red';
	} else {
		form_phone.style.border = '1px solid #7f9db9';	
	}
	if (form_ss.value.empty()) {
		error_msg += '- Social Security Number is required.\n';
		form_ss.style.border = '1px solid red';
	} else {
		form_ss.style.border = '1px solid #7f9db9';	
	}
	if (form_dob.value.empty()) {
		error_msg += '- Date of Birth is required.\n';
		form_dob.style.border = '1px solid red';
	} else {
		form_dob.style.border = '1px solid #7f9db9';	
	}
	if (form_address.value.empty()) {
		error_msg += '- Address is required.\n';
		form_address.style.border = '1px solid red';
	} else {
		form_address.style.border = '1px solid #7f9db9';	
	}
	if (form_city.value.empty()) {
		error_msg += '- City is required.\n';
		form_city.style.border = '1px solid red';
	} else {
		form_city.style.border = '1px solid #7f9db9';
	}
	if (form_zip.value.empty()) {
		error_msg += '- Zip is required.\n';
		form_zip.style.border = '1px solid red';
	} else {
		form_zip.style.border = '1px solid #7f9db9';
	}
	if (form_state.value.empty()) {
		error_msg += '- State is required.\n';
		form_state.style.border = '1px solid red';
	} else {
		form_state.style.border = '1px solid #7f9db9';
	}
	
	if (error_msg > '') {
		alert(error_msg);
	} else {
		var postString = form.serialize();
		new Ajax.Request('/wwwroot/f/fourstarmortgagemidland/ajax/prequal.cfm', {
			// Serialize form and submit
			postBody:postString,
			// Eval returned result from ajax request
			onSuccess: function(transport){
				eval(transport.responseText);
			},
			onComplete: function(transport) {
				//alert(transport.status);
			}
		});
		form.style.display = 'none';
		$('submitted').style.display='';
	}
}
