// JavaScript Document
var $j = jQuery.noConflict();

$j(document).ready(function(){							
	$j('.update_id').keyup(function() {
		var value = this.value.replace(',','').replace('.','').replace(' ','');
		if(!isNaN(value)) {
			$j('#'+this.name).html('If your 1st mortgage payment is more than ' + addCommas(Math.floor((31*(value/100)))) + ' which is 31% of your income, than answer yes, if it is less than answer no.');
		} else {
			$j('#'+this.name).html('Inalid Number');	
		}
	});
	
	var submitted = false;
	
	function submitForm() {
		submitted = true;
		$j('#quick_form').submit();
	}
	
	$j('#quick_form').submit(function() {
		if(validate_80572()) {
				$j('#quick_form_box').html('<table border="0" align="center" style="margin-right:8px"><tr><td><p>please wait while we send your information....</p></td></tr></table>');
				$j.post('http://www.cdloanmod.com/ajax_mail.php',{
					'quick_form':1,
					'name':$j('#quick_form input[name=name]').val(),
					'contact_first_name':$j('#quick_form input[name=contact_first_name]').val(),
					'contact_last_name':$j('#quick_form input[name=contact_last_name]').val(),
					'phone':$j('#quick_form input[name=phone]').val(),
					'email':$j('#quick_form input[name=email]').val(),
					'property_state':$j('#quick_form select[name=property_state]').val(),
					'col_1st_loan_balance':$j('#quick_form input[name=col_1st_loan_balance]').val(),
					'total_revolving_debt':$j('#quick_form input[name=total_revolving_debt]').val(),
					'how_far_behind':$j('#quick_form select[name=how_far_behind]').val()
				},function(data) {
					window.location.href="http://www.cdloanmod.com/success/";
					return false;
				});
				return false;
			} else {
				return false;
			}
	});
});

function validate_80572(){
             // Solutions Partners/jam jam 20080818...begin
               var validation_message = '';
               var form = document.form_80572;
			   if(isNaN(form.txtPhone.value) || form.txtPhone.value == '' || isNaN(form.txtPhone2.value) || form.txtPhone2.value == '' || isNaN(form.txtPhone3.value) || form.txtPhone3.value == '') { validation_message += 'Invalid phone Number (numbers only - 10 numbers in length)\n';}

				if (form.txtFirstName.value == ''){      validation_message += 'Please enter a First Name\n';}
               if (form.txtLastName.value == ''){     validation_message += 'Please enter a Last Name\n';}
				if (form.DDV_State_StateOfRes.value == 'SE'){      validation_message += 'Please select a State\n';}

// Solutions Partners/jam 20080818...end
               if (form.txtEmail.value == ''){		validation_message += 'Please enter a valid Email\n';}
                form.txtPhone1.value = form.txtPhone.value + '-' + form.txtPhone2.value + '-' + form.txtPhone3.value;
				if (validation_message != '') {			
                    alert(validation_message);
                    return false;
                }	else {
					
                    return true;	
                }
}

function validate_80573(){
             // Solutions Partners/jam jam 20080818...begin
               var validation_message = '';
               var form = document.form_80573;
			   if(isNaN(form.txtPhone.value) || form.txtPhone.value == '' || isNaN(form.txtPhone2.value) || form.txtPhone2.value == '' || isNaN(form.txtPhone3.value) || form.txtPhone3.value == '') { validation_message += 'Invalid phone Number (numbers only - 10 numbers in length)\n';}

				if (form.txtFirstName.value == ''){      validation_message += 'Please enter a First Name\n';}
               if (form.txtLastName.value == ''){     validation_message += 'Please enter a Last Name\n';}
				if (form.DDV_State_StateOfRes.value == 'SE'){      validation_message += 'Please select a State\n';}

// Solutions Partners/jam 20080818...end
               if (form.txtEmail.value == ''){		validation_message += 'Please enter a valid Email\n';}
                form.txtPhone1.value = form.txtPhone.value + '-' + form.txtPhone2.value + '-' + form.txtPhone3.value;
				if (validation_message != '') {			
                    alert(validation_message);
                    return false;
                }	else {
					
                    return true;	
                }
}
	
	
var newwindow;
function poptastic(url)
{
	newwindow=window.open(url,'name','height=550,width=400');
	if (window.focus) {newwindow.focus()}
}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}
