function make_payment(form)   {
    value_initialize();
    
    if (document.calc_form.first_time_buyer.checked == true)	status_buyer = 1; else status_buyer = 0;
    if (document.calc_form.dealer.checked == true)	dealer_status = 1; else dealer_status = 0;
    if (document.calc_form.ex_buyer.checked == true)	ex_buyer_status = 1; else ex_buyer_status = 0;
    
    P=form.amount.value;
    var objRegExp = /[$$,]/g;
    P = eval(P.replace(objRegExp,''));
    
    if (form.amount.value.length == 0) P = "0";
    
    if ($('residence_purchase').checked == true){
        action =1
    }
    else{
        action =2
    }   
    
    switch(action)
    
    {
        case 1:   
        // purchase
        purchase_show();
        if (P == '') P = 0;
        Fees = INTIAL_AMT;
        
        L = Ontrio_tax_transfer(P);//ONTARIO TRANSFER TAX
        rebate_ontario = rebare_on_ontario_loc(P,status_buyer,dealer_status,ex_buyer_status);
        
        TL = toronto_tax_transfer(P);
        TOR = rebare_on_toronto_loc(P,status_buyer,dealer_status,ex_buyer_status);
        
        TCC = Fees + L - rebate_ontario + TL - TOR;
        NCC = Fees + L- rebate_ontario;
        
        if (rebate_ontario) {
            rebate_msg = "  <i>(after $"+comma_add(rebate_ontario) +" rebate)</i>  ";
        }
        else{
            rebate_msg = '';
        }
        
        if (TOR) {
            toronto_rebate_msg = "  <i>(after $"+comma_add(TOR) +" rebate)</i>  ";
        }
        else {
            toronto_rebate_msg = '';
        }
        
        legal_fees.innerHTML = "$" + comma_add(Fees);
        if ($('within_toronto').checked == true){
            tax_toronto.innerHTML = "$"+place_two_decimal(TL-TOR) + toronto_rebate_msg;
            tax_ontario.innerHTML = "$"+place_two_decimal(L-rebate_ontario) + rebate_msg;
            total_amount.innerHTML = "$" + place_two_decimal(TCC);
        }
        else{
            tax_toronto.innerHTML = "$0.00"
            tax_ontario.innerHTML = "$"+place_two_decimal(L-rebate_ontario) + rebate_msg;
            total_amount.innerHTML = "$" + place_two_decimal(NCC);
        }   
        
        ; break
        
        case 2:
        // sell 
        div_hidden('property');
        div_hidden('ValueRow');
        div_hidden('Rebates');
        div_hidden('send_mail');
        div_hidden('purchase_bottom_text');
        block_div('sales_bottom_text');
        block_div('sale_disbursements');
        div_hidden('purchse_disbursements');
        total_amount.innerHTML = FIXED_AMT
        ; break
    }
    
}


function Ontrio_tax_transfer(obj) {
    var data = obj -0;
    
    if( obj == '' ) {
        return 0.0;
    }	
    
    if ( data <= FIFTY_FIVE_THOUAND ) {
        return 0.005 * data;
    }
    else if (data <= TWO_LACK_FIFTY_THOUSAND ){
             return (0.01 * data) - 275
        }
        else if (data <= FOUR_LACK ){
                return (0.015 * data) - 1525
        }
        else{
             return (0.02 * data) - 3525
        }		
} // end function

function toronto_tax_transfer(obj) {
    var data = obj -0;
    if( obj == '' ) {
        return 0.0;
    }	
    
    if ( data <= FIFTY_FIVE_THOUAND ) {
        return 0.005 * data;
    }
    else if (data <= FOUR_LACK ){
         return (0.01 * (data-FIFTY_FIVE_THOUAND)) + 275;
    }else {
        return (0.02 * (data-FOUR_LACK)) + 3725;
    }		
}

function rebare_on_ontario_loc(obj,buyer_first_time,dealers,ex_seller) {
    var data = obj - 0;
    if ( buyer_first_time || dealers)   { 
        if ( buyer_first_time && dealers) {
            ratio = 1;
        }
        else if ( ex_seller || buyer_first_time == 0 ) {
             ratio = 0.5;
        }
        else{
            ratio = 1;
        }

        if ( data <= FIFTY_FIVE_THOUAND ) {
            Rebate = (0.005 * data);
        }
        else if (data <= TWO_LACK_FIFTY_THOUSAND ){
        Rebate = ((0.01 * data) - 275);
        }
        else if (data <= FOUR_LACK ){
        Rebate = ((0.015 * data) - 1525);
        }
        else {
        Rebate = 2000;
        }
        if (Rebate > 2000) Rebate = 2000;
        return Rebate * ratio;
        }
        else {
        return 0;
        }
}



function rebare_on_toronto_loc(obj,buyer_first_time,dealers,ex_seller) {
    var data = obj - 0;
    if ( buyer_first_time || dealers )   {
        if ( buyer_first_time && dealers ) {
            ratio = 1;
        }
        else if ( ex_seller || buyer_first_time == 0 ) {
                ratio = 0.5;
        }
        else {
            ratio = 1;
        }

        if ( data <= FIFTY_FIVE_THOUAND ) {
            Rebate = (0.005 * data);
        }
        else if (data <= FOUR_LACK ){
            Rebate = ((0.01 * data) - 275);
        }
        else {
            Rebate = 3725;
        }
        if (Rebate > 3725) Rebate = 3725;
        return Rebate * ratio;
      }
      else {
        return 0;
      }
}