////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//  File name   : main.js                                                     //
//  Last edited : May 26, 2005                                                //
//  Author      : Ralph Mayer                                                 //
//  Contact     : Ralph Mayer ( ralmayo20_at_dokie_dot_ca )                   //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////



////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//                     Global variables for lowest rates.                     //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////

var five  = '3.95 ';
var seven  = '4.69 ';
var ten   = '5.35 ';



////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//                      Ensure errors don't crash script.                     //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////

window.onerror = function() { return true; }


////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//                       Ensure  site is not in frames.                       //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////

//if ( top.location != location ) { top.location.href = document.location.href; }


////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//                             lowest_rates_bar()                             //
//             Produces the'lowest rates' bar on the index page.              //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////

function lowest_rates_bar() {
    var html = '<table cellspacing = "0" id = "top_bar">' +
               '<caption>' +
               'Best mortage rates we&#8217;ve found over the past week.' +
               '</caption>' +
               '<tbody>' +
               '<tr>' +
               '<th>' +
               '<a href = "https://www.canadamortgageservices.com/rates.html"' +
               'title = "Go to current rates page">' +
               'Lowest rates for the past week:</a></th>' +
               '<td>' +
               '<a href = "https://www.canadamortgageservices.com/rates.html"' +
               'title = "Go to current rates page">' +
               '5 year: '  + five  + '%</a></td>' +
               '<td>' +
               '<a href = "https://www.canadamortgageservices.com/rates.html"' +
               'title = "Go to current rates page">' +
               '7 year: '  + seven  + '%</a></td>' +
               '<td>' +
               '<a href = "https://www.canadamortgageservices.com/rates.html"' +
               'title = "Go to current rates page">' +
               '10 year: '  + ten  + '%</a></td>' +
               '</tr>' +
               '</tbody>' +
               '</table>';
    document.write( html );
}


////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//                           lowest_rates_buttons()                           //
//              Produces the'lowest rates' buttons on each page.              //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////

function lowest_rates_buttons() {
/* The HTML-formatted output of the function:
    <h1>
        Lowest rates for the past week:
    </h1>
    <dl id = "lowest_rates">
        <dt>
            <a
                class = "five"
                href  = "rates.html"
                title = "Go to current rates page"
            >Lowest 5<br />year rate
            <span class = "low_rate">6.5%</span></a>
        </dt>
        <dd>
            Lowest rate we've found for a typical five year mortgage.
        </dd>
        <dt>
            <a
                class = "seven"
                href  = "rates.html"
                title = "Go to current rates page"
            >Lowest 7<br />year rate
            <span class = "low_rate">5.5%</span></a>
        </dt>
        <dd>
            Lowest rate we've found for a typical seven year mortgage.
        </dd>
        <dt>
            <a
                class = "ten"
                href  = "rates.html"
                title = "Go to current rates page"
            >Lowest 10<br />year rate
            <span class = "low_rate">4.5%</span></a>
        </dt>
        <dd>
            Lowest rate we've found for a typical ten year mortgage.
        </dd>
    </dl>
*/
    var html = '<h1>Lowest rates for the past week:</h1>' + 
               '<dl id = "lowest_rates"><dt><a class = "five"' +
               'href = "https://www.canadamortgageservices.com/rates.html" title = "Go to current rates page">' +
               'Lowest 5<br />year rate <span class = "low_rate">' + 
               five + '%</span></a></dt><dd>' +
               'Lowest rate we\'ve found for a typical five year mortgage.' +
               '</dd><dt><a class = "seven"' +
               'href = "https://www.canadamortgageservices.com/rates.html" title = "Go to current rates page">' +
               'Lowest 7<br />year rate <span class = "low_rate">' + 
               seven + '%</span></a></dt><dd>' +
               'Lowest rate we\'ve found for a typical seven year ' +
               'mortgage.</dd><dt><a class = "ten"' +
               'href = "https://www.canadamortgageservices.com/rates.html" title = "Go to current rates page">' +
               'Lowest 10<br />year rate <span class = "low_rate">' + 
               ten + '%</span></a></dt><dd>' +
               'Lowest rate we\'ve found for a typical ten year mortgage.' +
               '</dd></dl>';
    document.write( html );
}


////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//                                apply_img()                                 //
//                        Rotate the 'apply now' image.                       //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////
function apply_img() {
    if ( document.all ) {
        var dom = 'all["';
        var dom_parens = '"]';
    } else if ( document.getElementById ) {
        var dom = 'getElementById("';
        var dom_parens = '")';
    }
    var obj = eval( 'document.' + dom + 'apply_now' + dom_parens );
    var img_number  = Math.floor( Math.random() * 11 ) + 1;
    key_pic  = 'logos_graphics/apply_' + img_number + '.jpg';
    obj.src =  key_pic;
}
