﻿/* ---------------------------
' (C) Copyright 2007
' Niro Solutions Pty Limited
' ABN 89 106 967 140
' ---------------------------
' Revision: 1.2.0
' Author: Miles Glisovic
' Modtime: 14/11/07
'Updated by: Roland Beerling
'Modtime: 3/6/08
' --------------------------- */
var numberOfTabs = 4
// parameter STRINGS to be retreived from DB and used in initialise()
var initGrossSalary = "";
var initGrossSalaryFreq = "";

var cCol = "";
var fcs = false
var msgW = null
var navigator_appName = ""
var noOfTabs = 3
var s;
function preLoadImages1(noOfTabs) {
    //divPreLoad.style.display = "";
    expand = new Image()
    expand.src = "../images/info_expand.gif"
    collapse = new Image()
    collapse.src = "../images/info_collapse.gif"

    var i;
    for (i = 1; i <= noOfTabs; i++) {
        eval("img" + i + "on = new Image();")
        eval("img" + i + "on.src = '../images/step" + i + "on.gif';")
        eval("img" + i + "off = new Image();")
        eval("img" + i + "off.src = '../images/step" + i + "off.gif';")
    }
}

function showDIV(myDIV, noOfTabs) {
    var setDIV = myDIV.getAttribute("ID");
    for (i = 1; i <= noOfTabs; i++) {
        // disable all DIVs
        eval("divTab" + i + ".style.display = 'none';")
        // change element's class to another class:
        eval("tabStep" + i + ".className='';")
        eval("document['i" + i + "'].src = img" + i + "off.src;")
    }
    myDIV.style.display = "";
    for (i = 1; i <= noOfTabs; i++) {
        eval("if(setDIV == 'divTab" + i + "')	{	tabStep" + i + ".className='active'; document['i" + i + "'].src = img" + i + "on.src;}")
    }
}
function showDIV_CSRF(myDIV, noOfTabs) {
    var setDIV = myDIV.getAttribute("ID");
    for (i = 1; i <= noOfTabs; i++) {
        // disable all DIVs
        eval("divTab" + i + ".style.display = 'none';")
        // change element's class to another class:
        eval("tabStep" + i + ".className='tabOff';")
    }
    myDIV.style.display = "";
    for (i = 1; i <= noOfTabs; i++) {
        eval("if(setDIV == 'divTab" + i + "')	{	tabStep" + i + ".className='tabOn';}")
    }
}
function cursorH(e) {
    e.style.cursor = "pointer";
}
function cursorA(e) {
    e.style.cursor = "default";
}
function doChanges(e) {
    // get this 'e' element's table and set backgroundColor
    // of rows to cCol
    var rr = getMyTable(e);
    for (i = 0; i < rr.rows.length - 3; i++)
        rr.rows[i].style.backgroundColor = cCol
    e.style.backgroundColor = "#f1f1f2";

}


function restore(e) {
    var rr = getMyTable(e);
    for (i = 0; i < rr.rows.length - 3; i++)
        rr.rows[i].style.backgroundColor = cCol
    e.style.backgroundColor = cCol;
}
function select(field) {
    if ((navigator.appName).toUpperCase() != "NETSCAPE") {
        try {
            field.focus()
            field.select()
        }
        catch (e) {
            ; //alert(e)
        }
    }
}
function getMyDIV(x) {
    // start with an element and go up through the tree trying to find
    // a <DIV> HTML element;
    // return a reference to an object of type <DIV>
    // or, if not found, return null
    if (x != null && x.tagName != "DIV")
        return (getMyDIV(x.parentNode));
    else
        return x;
}
function getMyTable(x) {
    if (x != null && x.tagName != "TABLE")
        return (getMyTable(x.parentNode));
    else
        return x;
}
function switchToDIV(field) {
    var rr = getMyDIV(field);
    if (rr.style.display == "none")
        showDIV_CSRF(rr, numberOfTabs)
}



function goToStep2(e, tabNumber) {
    var f = document.forms.frmName
    if (validStep1(f)) {
        CalcTotalIncome()
        showTab(tabNumber);

    }
}

function goToStep3(e, tabNumber) {
    var f = document.forms.frmName
    if (validStep1(f)) {
        showTab(tabNumber);
    }
}
function showTab(tabNumber) {
    if (!fcs)
        stopGIF(true);
    s = 1
    document.getElementById("divPreLoad").style.display = "none";
    document.getElementById("div1July2007").style.display = "";
    document.getElementById("divIntro").style.display = "";
    document.getElementById("divIntro1").style.display = "none";
    document.getElementById("divHowToUse").style.display = "";
    document.getElementById("divMain").style.display = "";
    document.getElementById("divAssumption").style.display = "";
    document.getElementById("divDisclaimer").style.display = "";
    //document.getElementById("tblAssumptions").style.display = "none";
    //document.getElementById("tblDisclaimer").style.display = "none";

    document.getElementById('tabStep1').className = ''
    document.getElementById('tabStep2').className = ''
    document.getElementById('tabStep3').className = ''
    /*  disable all DIVs */
    document.getElementById("divTab1").style.display = "none";
    document.getElementById("divTab2").style.display = "none";
    document.getElementById("divTab3").style.display = "none";

    document["i1"].src = img1off.src;
    document["i2"].src = img2off.src;
    document["i3"].src = img3off.src;

    switch (tabNumber) {
        case 1:
            document.getElementById('tabStep1').className = 'active'
            document["i1"].src = img1on.src;
            document.getElementById("divTab1").style.display = "";
            if (fcs) {
                window.location.href = "#top1"
                mySelect(document.forms.frmName.txtIncomeG);
            }
            break;
        case 2:
            document.getElementById('tabStep2').className = 'active'
            document["i2"].src = img2on.src;
            document.getElementById("divTab2").style.display = "";
            window.location.href = "#top1"
            break;
        case 3:
            document.getElementById('tabStep3').className = 'active'
            document["i3"].src = img3on.src;
            document.getElementById("divTab3").style.display = "";
            window.location.href = "#top1"
            break;
    }
}
function selectGender(i) {
    document.forms.frmName.rdGender[i].click()
}

function jsLRTrim(s) {
    return s.replace(/(^\s+)|(\s+$)/g, "");
}
function getMinIncome(f, cmb) {
    return (Math.ceil(MIN_SALARY / cmb.value))
}
function initialise() {
    try {
        var f = document.forms.frmName

        f.cmbIncomeG.value = 1;
        f.cmbIncomeI.value = 1;
        f.cmbDollarAmountFreq.value = 1;
        //CalcTotalIncome()

    }
    catch (e) {
        alert(e)
    }
}
function openInMain(page1) {
    try {
        (window.opener).location = page1
        window.opener.focus()
    }
    catch (e) {
        msgWindow1 = null;
        msgWindow1 = window.open(page1, 'mainWindow');
        self.close()
    }
}

function openWin(page1) {
    try {
        msgW.close()
        msgW = null
    }
    catch (e)
{ }

    try {
        msgW = null;
        msgW = window.open(page1, 'CSF_Window');
        msgW.focus()
    }
    catch (e)
{ }
}
function setCursorHand(e) {
    e.style.cursor = "pointer";
}
function setActiveTab(e, s) {
    if (e.className == 'active')
        e.className = 'active hov'
    else
        e.className = 'hov'
    setCursorHand(e);
    showStatus(s)
}
function setInactiveTab(e) {
    if ((e.className).indexOf("active") < 0)
        e.className = ''
    else
        e.className = 'active'
    showStatus('')
}
function showStatus(s) {
    window.status = s;
    return true;
}




function stopGIF(stopIt) {
    if (stopIt) {
        document.getElementById("loading").style.display = "none";
        document.getElementById("loading").src = null;
    }
    else {
        ;
    }
}
function pctOrDollar() {
    var f = document.forms.frmName
    if (f.rdMemberCont[0].checked) {
        f.txtPctOfSalary.disabled = false
        f.txtPctOfSalary.className = ''
        document.getElementById("ccc2").className = '';
        select(f.txtPctOfSalary)

        f.txtDollarAmount.value = ""
        f.txtDollarAmount.disabled = true
        f.txtDollarAmount.className = 'InputBorderGray'
        document.getElementById("ccc0").className = 'CellDimmed';
        document.getElementById("ccc01").className = 'CellDimmed';

        f.cmbDollarAmountFreq.disabled = true
        f.cmbDollarAmountFreq.selectedIndex = 3
    }
    else {
        f.txtDollarAmount.disabled = false
        f.txtDollarAmount.className = ''
        f.cmbDollarAmountFreq.disabled = false
        document.getElementById("ccc0").className = '';
        document.getElementById("ccc01").className = '';
        select(f.txtDollarAmount)

        f.txtPctOfSalary.value = ""
        f.txtPctOfSalary.disabled = true
        f.txtPctOfSalary.className = 'InputBorderGray'
        document.getElementById("ccc2").className = 'CellDimmed';
    }
}
function selectRD(i) {
    document.forms.frmName.rdMemberCont[i].click()
}


function get_max(f, cmb, _max) {
    return Math.floor(_max / cmb.value)
}
function limitNoDecimalPlaces(field, n) {
    // find if '.' entered
    var li = (field.value).indexOf(".")
    if (li < 0) {
        if ((field.value).length > (n + 2))
            field.value = (field.value).substring(0, (n + 2))
    }
    else {
        var s1 = (field.value).substring(0, li)
        var s2 = ((field.value).substring(li + 1, (field.value).length))
        if (s2.length > n)
            field.value = s1 + "." + s2.substring(0, n)
    }
}

function loadAndShow() {
    initialise();
    document.getElementById("topbar").style.opacity = 1
    document.getElementById("topbar").style.filter = 'alpha(opacity=100)'
    showAccept()
}
function showAccept() {
    s = 0
    document.getElementById("divPreLoad").style.display = "none";
    document.getElementById("div1July2007").style.display = "";
    document.getElementById("divDisclaimer").style.display = "";
    document.getElementById("divAssumption").style.display = "";
    document.getElementById("tblAssumptions").style.display = "";
    document.getElementById("tblDisclaimer").style.display = "";

    window.location.href = "#top0"
}
function ToggleDisclaimer(t) {
    if (s == 1) {
        var x = document["imgDisclaimer"].src
        if (x == expand.src) {
            document["imgDisclaimer"].src = collapse.src;
            document.getElementById("tblDisclaimer").style.display = "";
        }
        else {
            document["imgDisclaimer"].src = expand.src;
            document.getElementById("tblDisclaimer").style.display = "none";
        }
    }
}

function ToggleAssumption(t) {
    if (s == 1) {
        var x = document["imgAssumption"].src
        if (x == expand.src) {
            document["imgAssumption"].src = collapse.src;
            document.getElementById("tblAssumptions").style.display = "";
        }
        else {
            document["imgAssumption"].src = expand.src;
            document.getElementById("tblAssumptions").style.display = "none";
        }
    }
}

function accepted() {
    s = 1
    document.getElementById("divIntro").style.display = "";
    document.getElementById("divIntro1").style.display = "none";
    document.getElementById("divHowToUse").style.display = "";
    document.getElementById("divAccept").style.display = "none";
    document.getElementById("topbar").style.display = "none";
    document.getElementById("tblAssumptions").style.display = "none";
    document.getElementById("imgAssumption").style.display = "";
    document.getElementById("tblDisclaimer").style.display = "none";
    document.getElementById("imgDisclaimer").style.display = "";

    document.forms.frmName.rdMemberCont[0].click()
    showTab(1);
    window.location.href = "#top0"
    fcs = true
}
function notAccepted() {
    if (confirm("You cannot access the calculator unless you accept the Assumptions and Disclaimer. Click on 'OK' to close the calculator or 'Cancel' to return to the Assumptions and Disclaimer.")) {
        window.close()
    }
}
/***********************************************
* Floating Top Bar script- ?Dynamic Drive (www.dynamicdrive.com)
* Sliding routine by Roy Whittle (http://www.javascript-fx.com/)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var persistclose = 0 //set to 0 or 1. 1 means once the bar is manually closed, it will remain closed for browser session
var startX = 0 //set x offset of bar in pixels
var startY = 5 //set y offset of bar in pixels
var verticalpos = "fromtop" //enter "fromtop" or "frombottom"

function iecompattest() {
    return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body
}

function get_cookie(Name) {
    var search = Name + "="
    var returnvalue = "";
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search)
        if (offset != -1) {
            offset += search.length
            end = document.cookie.indexOf(";", offset);
            if (end == -1) end = document.cookie.length;
            returnvalue = unescape(document.cookie.substring(offset, end))
        }
    }
    return returnvalue;
}
function closebar() {
    if (persistclose)
        document.cookie = "remainclosed=1"
    document.getElementById("topbar").style.visibility = "hidden"
}

function staticbar() {
    barheight = document.getElementById("topbar").offsetHeight
    barwidth = document.getElementById("topbar").offsetWidth
    var ns = (navigator.appName.indexOf("Netscape") != -1) || window.opera;
    var d = document;
    function ml(id) {
        var el = d.getElementById(id);
        if (!persistclose || persistclose && get_cookie("remainclosed") == "")
            el.style.visibility = "visible"
        if (d.layers)
            el.style = el;
        el.sP = function(x, y) { this.style.left = x + "px"; this.style.top = y + "px"; };
        el.x = ns ? startX + innerWidth / 2 - 8 - barwidth / 2 : startX + iecompattest().scrollLeft + document.body.clientWidth / 2 - barwidth / 2// - iecompattest().clientWidth/2;

        if (verticalpos == "fromtop")
            el.y = startY;
        else {
            el.y = ns ? pageYOffset + innerHeight : iecompattest().scrollTop + iecompattest().clientHeight;
            el.y -= startY;
        }
        return el;
    }





    window.stayTopLeft = function() {
        if (verticalpos == "fromtop") {
            var pY = ns ? pageYOffset : iecompattest().scrollTop;
            ftlObj.y += (pY + startY - ftlObj.y) / 8;
        }
        else {
            var pY = ns ? pageYOffset + innerHeight - barheight : iecompattest().scrollTop + iecompattest().clientHeight - barheight;
            ftlObj.y += (pY - startY - ftlObj.y) / 8;
            ftlObj.x = ns ? startX + innerWidth / 2 - 8 - barwidth / 2 : startX + iecompattest().scrollLeft + document.body.clientWidth / 2 - barwidth / 2
        }
        ftlObj.sP(ftlObj.x, ftlObj.y);
        setTimeout("stayTopLeft()", 10);
    }
    ftlObj = ml("topbar");
    stayTopLeft();
}

if (window.addEventListener)
    window.addEventListener("load", staticbar, false)
else if (window.attachEvent)
    window.attachEvent("onload", staticbar)
else if (document.getElementById)
    window.onload = staticbar

function cursorHU(e) {
    e.style.cursor = "pointer";
    e.className = 'hrHoover1';
}
function cursorHU0(e) {
    e.className = 'hrHoover0';
}
function numberValidDecimalNumber(_val, _sPrompt, _promptYesNo) {
    var int1 = /^\d{1,}(\.\d{1,})?$/;
    var reg = new RegExp(int1);
    var ret = reg.test(_val);
    if (!ret) {
        if (_promptYesNo)
            alert(_sPrompt)
    }
    return ret
}
function calcTotalIncome0() {
    var f = document.forms.frmName
    var ret = 0.00
    if (validIncomeEmpl(f, false) && validInvestIncome(f, false) && validOtherIncome(f, false) && validFringeBenefits(f, false) && validTotalIncome(f, false)) {
        ret = myRound(getSafeDecimalFieldValue(f.txtIncomeG) * f.cmbIncomeG.value + getSafeDecimalFieldValue(f.txtIncomeI) * f.cmbIncomeI.value + getSafeDecimalFieldValue(f.txtIncomeO) + getSafeDecimalFieldValue(f.txtIncomeF), 2)
    }
    document.getElementById("IncomeTotal").innerHTML = '<B>' + formatted_toFixed1(ret, 2, "") + '</B>';
}
