﻿
function createHTML(newid) {
    document.writeln('<div id="YMM_calcbox' + newid + '"> </div>');

    var calcbox = document.getElementById('YMM_calcbox' + newid);
    if (calcbox.getAttribute('className') != null) {
        calcbox.setAttribute('className', 'YMM_storybox')
    } else {
        calcbox.setAttribute('class', 'YMM_storybox')
    }

    var calctitle = document.createElement('h2');
    calctitle.setAttribute('id', 'YMM_calctitle' + newid);
    if (calctitle.getAttribute('className') != null) {
        calctitle.setAttribute('className', 'YMM_storytitle')
    } else {
        calctitle.setAttribute('class', 'YMM_storytitle')
    }


    var ahreflogo = document.createElement('a');
    ahreflogo.setAttribute('id', 'YMM_calclogo' + newid);
    ahreflogo.href = "http://www.yourmortgage.com.au";
    ahreflogo.innerHTML = "<img src=\"http://www.yourmortgage.com.au/images/mortgage_logo.gif\" width=\"76\" height=\"24\" border=\"0\" alt=\"mortgage_logo\" align=\"right\" />";

    var calcContent = document.createElement('div');
    calcContent.setAttribute("id", "YMM_calcContent" + newid);
    if (calcContent.getAttribute('className') != null) {
        calcContent.setAttribute('className', 'YMM_storyContent')
    } else {
        calcContent.setAttribute('class', 'YMM_storyContent')
    }

    var calcfooter = document.createElement('div');
    if (calcfooter.getAttribute('className') != null) {
        calcfooter.setAttribute('className', 'YMM_storyfooter')
    } else {
        calcfooter.setAttribute('class', 'YMM_storyfooter')
    }

    var afooterhref = document.createElement('a');
    afooterhref.setAttribute("id", "YMM_calcfooterhref" + newid);
    afooterhref.setAttribute("target", "_blank");
    afooterhref.innerHTML = "Free Mortgage Calculator & Content Widget";

    calcbox.appendChild(calctitle);
    calcbox.appendChild(ahreflogo);
    calcbox.appendChild(calcContent);
    calcbox.appendChild(calcfooter);
    calcfooter.appendChild(afooterhref);

}


function Calculator(width, calcName, title, ticks) {

    var newid = "_" + ticks;

    createHTML(newid);

    var calcbox = document.getElementById('YMM_calcbox' + newid);
    calcbox.style.width = width + "px";

    var calctitle = document.getElementById('YMM_calctitle' + newid);
    calctitle.innerHTML = title;
    var YMM_calcfooterhref = document.getElementById('YMM_calcfooterhref' + newid);
    YMM_calcfooterhref.href = "http://www.yourmortgage.com.au/widget/";

    var calcContent = document.getElementById('YMM_calcContent' + newid);

    calcContent.innerHTML = "<iframe id=\"calc_" + ticks + "\" src=\"http://www.yourmortgage.com.au/widget/Calculators/" + calcName + "/\" width=\"" + width + "\" height=\"215px\" scrolling=\"no\" frameborder=\"0\"  vspace=\"0\" hspace=\"0\" marginwidth=\"0\" marginheight=\"0\" ></iframe>";
}



