function searchHomes(type){
	
        var form;
        
        if(type == 'quick') {
            form = document.quickSearchForm;
        }else{
            form = document.searchForm;
        }
        
        var errorMessage = "";
	
	if(form.priceFrom.value > form.priceTo.value) errorMessage += 'Home price from cannot be greater than price to.\n';
	
        if(type != 'quick'){
            if(form.sizeFrom.value > form.sizeTo.value) errorMessage += 'SQ. FT. size from cannot be greater than size to.\n';
        }
	
	if(errorMessage.length > 0){
		alert('-Please correct the following errors:\n\n' + errorMessage)
		return false;
	}	else {
		form.submit();
	}
}	


function JSRecalc() {
	form = document.calcForm;
	LoanAmount= form.LoanAmount.value;
	DownPayment= "0";
	AnnualInterestRate = form.InterestRate.value/100;
	Years= form.NumberOfYears.value;
	MonthRate=AnnualInterestRate/12;
	NumPayments=Years*12;
	Prin=LoanAmount-DownPayment;
	
	MonthPayment=Math.floor((Prin*MonthRate)/(1-Math.pow((1+MonthRate),(-1*NumPayments)))*100)/100;
	form.NumberOfPayments.value=NumPayments;
	form.MonthlyPayment.value=MonthPayment;
}


function newWindow(newContent){
  winContent = window.open(newContent, 'nextWin', 'right=0, top=20,width=780,height=540, toolbar=yes,scrollbars=yes, resizable=yes')         
}

function newWindow2(newContent){
  winContent = window.open(newContent, 'nextWin', 'right=0, top=20,width=900,height=700, toolbar=yes,scrollbars=yes, resizable=yes')         
}

function sendToFriend(){
    
    if($('#email_address').val() == ''){
        $('#email_address').effect("pulsate", { times:2 }, 1000);
    }else if($('#your_name').val() == ''){
        $('#your_name').effect("pulsate", { times:2 }, 1000);
    }else{
        $.post('sendToFriend.php?action=send&email_address=' + $('#email_address').val() + '&your_name=' + $('#your_name').val() + '&message=' + $('#message').val(), function(data){
            $('#thankYouMessage').html(data);
            $('#friendDialog').fadeOut(2000, function() {
                $('#friendDialog').dialog('close');
            });
        });
    }
  //winContent = window.open('sendToFriend.php', 'nextWin', 'right=0, top=20,width=300,height=200, toolbar=no,scrollbars=no, resizable=no')             
}

function submitWarranty(){
	var form = document.warrantyForm;
	var errorMessage = "";
	
	if($('#name').val() == '') {
            $('#warranty_message').text("Please fill in all boxes marked with a red *.").slideDown();
            $('#name').css('backgroundColor', 'lightyellow').effect("pulsate", { times:2 }, 1000);
        }else if($('#address').val() == '') {
            $('#warranty_message').text("Please fill in all boxes marked with a red *.").slideDown();
            $('#address').css('backgroundColor', 'lightyellow').effect("pulsate", { times:2 }, 1000);
        }else if($('#number').val() == '') {
            $('#warranty_message').text("Please fill in all boxes marked with a red *.").slideDown();
            $('#number').css('backgroundColor', 'lightyellow').effect("pulsate", { times:2 }, 1000);
        }else if($('#email').val() == '') {
            $('#warranty_message').text("Please fill in all boxes marked with a red *.").slideDown();
            $('#email').css('backgroundColor', 'lightyellow').effect("pulsate", { times:2 }, 1000);
        } else if($('#community').val() == '') {
            $('#warranty_message').text("Please fill in all boxes marked with a red *.").slideDown();
            $('#community').css('backgroundColor', 'lightyellow').effect("pulsate", { times:2 }, 1000);
        }else if($('#closedate').val() == '' || $('#closedate').val() == 'MM/YYYY') {
            $('#warranty_message').text("Please fill in all boxes marked with a red *.").slideDown();
            $('#closedate').css('backgroundColor', 'lightyellow').effect("pulsate", { times:2 }, 1000);
        } else {
            //form.submit();
            $('#warrantyArea').fadeOut();
            $.post('admin/inc/_handleWarrantyRequest.php?action=add&' + $('#warrantyForm').serialize(), function(data){
                $('#warrantyArea').html(data).fadeIn();   
            });
	}	
}

function submitRequestInfo(){
	
	if($('#first_name').val() == '') {
            $('#requestInfo_message').text("Please fill in all boxes marked with a red *.").slideDown();
            $('#first_name').css('backgroundColor', 'lightyellow').effect("pulsate", { times:2 }, 1000);
        }else if($('#last_name').val() == '') {
            $('#requestInfo_message').text("Please fill in all boxes marked with a red *.").slideDown();
            $('#last_name').css('backgroundColor', 'lightyellow').effect("pulsate", { times:2 }, 1000);
        }else if($('#email').val() == '') {
            $('#requestInfo_message').text("Please fill in all boxes marked with a red *.").slideDown();
            $('#email').css('backgroundColor', 'lightyellow').effect("pulsate", { times:2 }, 1000);
        } else {
            	document.requestInfo.submit();
	}	
}

function submitContactUs(){
    
    if($('#name').val() == ''){
        $('#name').effect("pulsate", { times:2 }, 1000);
    }else if($('#email').val() == ''){
        $('#email').effect("pulsate", { times:2 }, 1000);   
    }else{
        document.contactForm.submit();    
    }
}

function submitFinancing(){
    
    if($('#name').val() == ''){
        $('#name').effect("pulsate", { times:2 }, 1000);
    }else if($('#email').val() == ''){
        $('#email').effect("pulsate", { times:2 }, 1000);   
    }else if($('#number').val() == ''){
        $('#number').effect("pulsate", { times:2 }, 1000);   
    }else{
        document.financingForm.submit();    
    }
}

