function checkEmail(email){
	var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
	if (email.search(emailRegEx) == -1) { return false; }
	else { return true; }
}

function submit_rate_watch_form() {

	if(document.rate_watch_form.first_name.value.length == 0)			{ alert("Please enter your first name.");			document.rate_watch_form.first_name.focus();			return; }
	if(document.rate_watch_form.last_name.value.length == 0)			{ alert("Please enter your last name.");			document.rate_watch_form.last_name.focus();			return; }
//	if(document.rate_watch_form.phone.value.length == 0)		{ alert("Please enter a phone number.");		document.rate_watch_form.phone.focus();			return; }
	if (!checkEmail(document.rate_watch_form.email.value)) { alert('Please provide a valid email address'); document.rate_watch_form.email.focus(); return; }



	url = "/includes/popup-rate-watch-send.php";
//    var parms = "mortgage_type="+document.rate_watch_form.mortgage_type.value;
//    parms += "&mortgage_amount="+document.rate_watch_form.mortgage_amount.value;
//    parms += "&mortgage_term="+document.rate_watch_form.mortgage_term.value;
    var parms = "first_name="+document.rate_watch_form.first_name.value;
    parms += "&last_name="+document.rate_watch_form.last_name.value;
//    parms += "&phone="+document.rate_watch_form.phone.value;
    parms += "&email="+document.rate_watch_form.email.value;
    parms += "&ihatespam=withapassion";
//    parms += "&best_time="+document.rate_watch_form.best_time.value;
//    parms += "&comments="+document.rate_watch_form.comments.value;

	new Ajax.Request(url, {
		method:'post',
		parameters: parms,
		onSuccess: function(transport){
			$('pop-container-inner').innerHTML = transport.responseText;
		}
	})
}



function submit_contact_agent_form() {

	if(document.contact_agent_form.first_name.value.length == 0)			{ alert("Please enter your first name.");			document.contact_agent_form.first_name.focus();			return; }
	if(document.contact_agent_form.last_name.value.length == 0)			{ alert("Please enter your last name.");			document.contact_agent_form.last_name.focus();			return; }
	if(document.contact_agent_form.phone.value.length == 0)		{ alert("Please enter a phone number.");		document.contact_agent_form.phone.focus();			return; }
	if (!checkEmail(document.contact_agent_form.email.value)) { alert('Please provide a valid email address'); document.contact_agent_form.email.focus(); return; }



	url = "/includes/popup-agent-contact-send.php";
    var parms = "first_name="+document.contact_agent_form.first_name.value;
    parms += "&last_name="+document.contact_agent_form.last_name.value;
    parms += "&phone="+document.contact_agent_form.phone.value;
    parms += "&email="+document.contact_agent_form.email.value;
    parms += "&best_time="+document.contact_agent_form.best_time.value;
    parms += "&comments="+document.contact_agent_form.comments.value;
    parms += "&agentID="+document.contact_agent_form.agentID.value;

	new Ajax.Request(url, {
		method:'post',
		parameters: parms,
		onSuccess: function(transport){
			$('pop-container-inner').innerHTML = transport.responseText;
		}
	})
}














function pop(url, query_string, width, iframe) {
//	$('pop-container-inner').innerHTML = 'Loadining.. need animated gif here..';
	width = (width > 0 ? width : 400);
	$('pop-container').style.width = width+'px';
    $('ol-lwd').appear({ duration: 0.3, from: 0.0, to: 0.3 });
    $('pop-band').appear({ delay:0.5, duration: 0.3, from: 0.0, to: 1.0 });
//    url = "/includes/popup-"+file+".php";
	if (!iframe) {
	    new Ajax.Request(url, {
	        method:'post',
	        parameters: query_string,
	        onSuccess: function(transport){
				$('pop-container-inner').innerHTML = transport.responseText;
	        }
	      })
	}
	else {
		$('pop-container-inner').innerHTML = " <div style = \"min-height: 350px;\"><iframe frameborder='0' style = \"height: 350px; width: 100%; float: left;border: none;\" src = \""+url+"\"></iframe></div>";


	}
}

function pop_hide() {

    $('ol-lwd').fade({ duration: 0.3, from: 0.1, to: 0.0 });
    setTimeout("$('ol-lwd').setStyle({display: 'none'});", 310);

    $('pop-band').fade({ duration: 0.3, from: 1.0, to: 0.0 });
    setTimeout("$('pop-band').setStyle({display: 'none'});", 310);

}






function validate_apply_form() {

	if(document.apply_form.first_name.value.length == 0)			{ alert("Please enter your first name.");			document.apply_form.first_name.focus();			return; }
	if(document.apply_form.last_name.value.length == 0)			{ alert("Please enter your last name.");			document.apply_form.last_name.focus();			return; }
	if (!checkEmail(document.apply_form.email.value)) { alert('Please provide a valid email address'); document.apply_form.email.focus(); return; }
	if(document.apply_form.phone.value.length == 0)		{ alert("Please enter a phone number.");		document.apply_form.phone.focus();			return; }

    document.apply_form.ihatespam.value = 'withapassion';

    document.apply_form.submit();

}



function validate_quick_form() {

	if(document.quick_form.mortgage_type.value.length == 0)			{ alert("Please enter a mortgage type.");			document.quick_form.mortgage_type.focus();			return; }
	if(document.quick_form.mortgage_purpose.value.length == 0)			{ alert("Please a mortgage purpose.");			document.quick_form.mortgage_purpose.focus();			return; }
	if(document.quick_form.mortgage_term.value.length == 0)		{ alert("Please enter a mortgage term.");		document.quick_form.mortgage_term.focus();			return; }

    document.quick_form.ihatespam.value = 'withapassion';

    document.quick_form.submit();

}


function validate_quick_long_form() {

	if(document.quick_long_form.mortgage_type.value.length == 0)			{ alert("Please enter a mortgage type.");			document.quick_long_form.mortgage_type.focus();			return; }
	if(document.quick_long_form.mortgage_purpose.value.length == 0)			{ alert("Please a mortgage purpose.");			document.quick_long_form.mortgage_purpose.focus();			return; }
	if(document.quick_long_form.mortgage_term.value.length == 0)		{ alert("Please enter a mortgage term.");		document.quick_long_form.mortgage_term.focus();			return; }

	if(document.quick_long_form.mortgage_amount.value.length == 0)		{ alert("Please enter a mortgage amount.");		document.quick_long_form.mortgage_amount.focus();			return; }
	if(document.quick_long_form.first_name.value.length == 0)			{ alert("Please enter your first name.");			document.quick_long_form.first_name.focus();			return; }
	if(document.quick_long_form.last_name.value.length == 0)			{ alert("Please enter your last name.");			document.quick_long_form.last_name.focus();			return; }
	if(document.quick_long_form.phone.value.length == 0)		{ alert("Please enter a phone number.");		document.quick_long_form.phone.focus();			return; }
	if (!checkEmail(document.quick_long_form.email.value)) { alert('Please provide a valid email address'); document.quick_long_form.email.focus(); return; }

    document.quick_long_form.ihatespam.value = 'withapassion';

    document.quick_long_form.submit();

}
























