// Change the link and icon of the toolkit link based on the current location.
function onload_changeToolkitLink() {
    var payrollTax = [
		'payroll',
		'/forms/index.php?subcategory=10',
		'/legislation-rulings/public-rulings/index.php?subcategory=70',
		'/online-multimedia/osrconnect/index.php?subcategory=386',
		'/online-multimedia/osrconnect/index.php?subcategory=423',
		'/online-multimedia/osrconnect/dge-adjustment.shtml'
	];

    var loc = document.location.toString();

    for (var i = 0; i < payrollTax.length; i++) {
        if (loc.indexOf(payrollTax[i]) != -1) {
            var anchor = $("#nav-primary a.icon-toolbox-top");

            if (anchor.length == 1) {
                anchor.attr("href", "/payroll-tax/toolkit/index.shtml");
                anchor.attr("class", "icon-toolkit-top-yellow");
            }

            break;
        }
    }
};

// Regex URL
function getURLParameterByName(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else
        return decodeURIComponent(results[1].replace(/\+/g, " "));
}

// hidden fields array values
function validateFormField(hideFields) {
    $('.form form ol').children().removeClass("hideThis");
    if (hideFields != null) {
        var arrayItem = hideFields.split(",");
        for (var i = 0; i < arrayItem.length; i++) {
            $('li.' + (arrayItem[i]).replace(/ /, "")).addClass("hideThis");
        }
    } else {
        return false;
    }
}

$(document).ready(function () {
    onload_changeToolkitLink();

    // Remove from screen
    $('.tabbed-content .tab-title').hide();
    $('.additional-info-text').hide();

    // Toolbox
    $(".btn-slide").click(function () {
        $("#panel").slideToggle("slow");
        $(this).toggleClass("active"); return false;
    });


    // Page Tools
    $('#layout-2col #column1').append('<div class="page-tools container"><h2>Page tools</h2><ul><li class="font-size-large"><a href="#" title="Increase page text size">Increase page text size</a></li><li class="font-size-small"><a href="#" title="Decrease page text size">Decrease page text size</a></li><li class="print"><a href="#" title="Print friendly">Print friendly</a></li><li class="share"><a href="#" title="Email this page">Email this page</a></li></ul></div>')


    // Corners
    $('.container').corner("6px");
    $('.toc').corner("5px");
    $('.toc ul').corner("5px");
    $('.main-content .ruling-info .info-panel').corner("5px");
    $('.latest-news  h2').corner("3px");
    $('.container-promo h2').corner("3px");
    $('.container-list h2').corner("3px");


    $('.nav-homepage').corner("5px");
    $('.nav-roles .common-links h3').corner("5px");
    $('.news .date').corner("6px");

    // Navigation Style Fixes
    $('.nav-secondary ul li:first').addClass("no-border");

    $('.nav-secondary ul li .xcc').parent().addClass("selected");
    $('.nav-secondary ul li .xcc').parent().next().addClass("no-border");

    $('.nav-secondary ul li .xcx a').replaceWith('<a href="#" title="Hide / Show more menu options" class="hidden"></a>');
    $('.nav-secondary ul li .xcc a').replaceWith('<span href="#" class="show"></span>');
    $('.nav-secondary ul li .xcx, .nav-secondary ul li .xcc').show();

    $('.nav-secondary ul li .xcx a').click(function () {
        if ($(this).hasClass("hidden") == true) {
            $(this).addClass("show");
            $(this).removeClass("hidden");
            $(this).parent().parent().children("ul").slideDown();
            return false;
        } else {
            $(this).addClass("hidden");
            $(this).removeClass("show");
            $(this).parent().parent().children("ul").slideUp();
            return false;
        }
    });


    if ($('.breadcrumb').width() > 680) {

        charLimit = 20;
        $('.breadcrumb ul li a, .breadcrumb ul li.selected').each(function (i) {
            this.title = $(this).html();
            breadcrumbName = $(this).html();
            charCount = breadcrumbName.length;
            if (charCount > charLimit) {
                breadcrumbName = breadcrumbName.substr(0, charLimit) + '...';
                $(this).html(breadcrumbName);
            };
        });

    };

    $('.breadcrumb').show();


    // Promo Margin Fixes
    $('.promos .promo-text:first').addClass("first");

    // Main Links
    $('.main-links-2col ul li').addClass("float");
    $('.main-links-2col ul li:odd').after('<li class="clearfix" style="display: block"></li>');

    $('.main-links-3col ul li').addClass("float");
    $('.main-links-3col ul li:eq(2)').after('<li class="clearfix" style="display: block"></li>');





    // Print Links
    $('.page-tools .print').click(function () {
        window.print();
        return false;
    });

    $('.page-tools .font-size-large').click(function () {
        $("body").css("font-size", "75%");
        return false;
    });

    $('.page-tools .font-size-small').click(function () {
        $("body").css("font-size", "68%");
        return false;
    });

    $('.page-tools .share a, .i-want-to .icon-share').attr('href', "mailto:?subject=Thought you might be interested in this ...&body=I've found this on the Queensland Office of State Revenue website and I thought you might be interested:  " + location.href);

    if (window.opera) {
        if ($(".i-want-to .icon-bookmark").attr("rel") != "") { // don't overwrite the rel attrib if already set
            $(".i-want-to .icon-bookmark").attr("rel", "sidebar");
        }
    }

    $(".i-want-to .icon-bookmark").click(function (event) {
        event.preventDefault(); // prevent the anchor tag from sending the user off to the link
        var url = document.location;
        var title = document.title;

        if (window.sidebar) { // Mozilla Firefox Bookmark
            window.sidebar.addPanel(title, url, "");
        } else if (window.external) { // IE Favorite
            window.external.AddFavorite(url, title);
        } else if (window.opera) { // Opera 7+
            return false; // do nothing - the rel="sidebar" should do the trick
        } else { // for Safari, Konq etc - browsers who do not support bookmarking scripts (that i could find anyway)
            alert('Unfortunately, this browser does not support the requested action,'
			 + ' please bookmark this page manually.');
        }
    });

    // Inline Tabs
    var lastTab = false;
    var lastTabNumber = 0;

    var totalTabNumbers = $('.tabbed-content .tabs').size();
    if (totalTabNumbers == 9) {
        var TabWidths = 76.77
    } else {
        var TabWidths = 700 / totalTabNumbers - 1;
    };

    $('.tabbed-content').prepend('<div id="tabs-nav"><ul></ul></div>')
    $('.tabs').hide();

    $('.tabbed-content .tabs').each(function (i) {
        this.id = 'tab' + i;
        next = i + 1;
        nextTab = 'tab' + next;
        previous = i - 1;
        previousTab = 'tab' + previous;
        var texttitle = $(this).children("h2.tab-title").text();
        var title = (texttitle) ? texttitle : this.id;
        var link = '<a href="#' + this.id + '"><span>' + title + '</span></a>';
        $('#tabs-nav ul').append('<li>' + link + '</li>');
        if (i === 0) $('.tabs:not(#' + this.id + ')').hide();
        if (i > 0) {
            previousText = '<div class="previous-tab"><a href="#' + previousTab + '" id="' + previous + '" class="icon-previous">Show previous</a></div>';
        } else {
            previousText = '';
        };
        nextText = '<div class="next-tab"><a href="#' + nextTab + '" id="' + next + '" class="icon-next">Show next</a></div>';
        $(this).append('<div class="tab-switcher">' + previousText + '' + nextText + '</div>');
    });

    $('.tabbed-content #tabs-nav li').width(TabWidths);
    $('.tabbed-content #tabs-nav li:last').css('background', 'none');

    var tabHeight = 0;
    $('#tabs-nav ul li a span').each(function (i) {
        if ($(this).height() > tabHeight) {
            tabHeight = $(this).height();
        };
    });

    $("#tabs-nav ul li a span").height(tabHeight);

    // Tab Switch based on QueryString
    var defaultTab = true;

    if ($('.news-tabs').length > 0) {
        lastTab = true;
        lastTabNumber = totalTabNumbers - 1;
    };

    if ($.query.get('tab').length > 0) {
        tabNumber = $.query.get('tab');
        tabNumber = tabNumber.split('tab')[1];
        defaultTab = false;
    } else {
        if ($.query.get('showtab')) {
            tabNumber = $.query.get('showtab') - 1;
            defaultTab = false;
        } else {
            if (lastTab == true) {
                tabNumber = lastTabNumber;
                defaultTab = false;
            } else {
                defaultTab = true;
            };
        };
    };

    if (defaultTab == true) {
        $('#tabs-nav ul li:first a').addClass("selected");
        $('.tabs:first').show();
    } else {
        $("#tabs-nav ul li a:eq(" + tabNumber + ")").addClass("selected");
        $(".tabs:eq(" + tabNumber + ")").show();
    };


    $('.tabbed-content .tabs:last .tab-switcher .next-tab').hide();

    $('.tabbed-content #tabs-nav a').click(function () {
        $('#tabs-nav ul li a').removeClass();
        $(this).addClass("selected");
        var id = '#' + this.href.split('#')[1];
        $('.tabs').hide();
        $(id).show();
        return false;
    })

    $('.tabbed-content .tab-switcher a').click(function () {
        $('#tabs-nav ul li a').removeClass();
        $('#tabs-nav ul li a:eq(' + this.id + ')').addClass("selected");
        var id = '#' + this.href.split('#')[1];
        $('.tabs').hide();
        $(id).show();
        return false;
    })



    // Additional Info Panel
    $('.additional-info-link').click(function () {
        $(".additional-info-text").slideToggle("slow");
    })

    // Additional Info Panel
    $(".dropdown-list .list").hide();

    $(".dropdown-list h4").hover(
		  function () { $(".dropdown-list h4").addClass("hover"); },
		  function () { $(".dropdown-list h4").removeClass("hover"); }
		);

    $('.dropdown-list .button-link').click(function () {
        $(".dropdown-list").toggleClass("open");
        $(".dropdown-list .list").slideToggle("fast");
    })




    // Expandable Content
    $('.expandable-content dd, .accordion dd').hide();
    $('.expandable-content dl').after('<div class="expand-all all-link"><span class="link">Expand all</span> <span class="indicator">[<span class="expand">+</span>]</span></div>')
    $('.expandable-content dl').after('<div class="collapse-all all-link"><span class="link">Collapse all</span> <span class="indicator">[<span class="collapse">-</span>]</span></div>')
    $('.expandable-content .collapse-all').hide();

    $('.expandable-content dt, .accordion dt').prepend('<span class="expand-item indicator">[<span class="expand">+</span>]</span>')
    $('.expandable-content dt, .accordion dt').prepend('<span class="collapse-item indicator">[<span class="collapse">-</span>]</span>')
    $('.expandable-content .collapse-item, .accordion .collapse-item').hide();
    $(".expandable-content dd, .accordion dd").wrapInner('<span class="block"></span>');

    $('.expandable-content dt').click(function () {
        if ($(this).hasClass('expanded') == false) {
            $(this).next().slideDown();
            $(this).children('.expand-item').hide();
            $(this).children('.collapse-item').show();
            $(this).addClass('expanded');
        } else {
            $(this).next().slideUp();
            $(this).children('.expand-item').show();
            $(this).children('.collapse-item').hide();
            $(this).removeClass('expanded');
        }
    });

    $('.expandable-content .expand-all').click(function () {
        $('.expandable-content dd').slideDown();
        $('.expandable-content .expand-all').hide();
        $('.expandable-content .collapse-all').show();
        $('.expandable-content .expand-item').hide();
        $('.expandable-content .collapse-item').show();
        $('.expandable-content dt').addClass('expanded');
    });

    $('.expandable-content .collapse-all').click(function () {
        $('.expandable-content dd').slideUp();
        $('.expandable-content .expand-all').show();
        $('.expandable-content .collapse-all').hide();
        $('.expandable-content .expand-item').show();
        $('.expandable-content .collapse-item').hide();
        $('.expandable-content dt').removeClass('expanded');
    });

    $('.accordion dt').click(function () {
        if ($(this).hasClass('expanded') == false) {
            $('.accordion dt').removeClass('expanded');
            $('.accordion .expand-item').show();
            $('.accordion .collapse-item').hide();
            $('.accordion dt').next().slideUp();
            $(this).next().slideDown();
            $(this).addClass('expanded');
            $(this).children('.expand-item').hide();
            $(this).children('.collapse-item').show();
        } else {
            $('.accordion dt').next().slideUp();
            $(this).removeClass('expanded');
            $('.accordion .expand-item').show();
            $('.accordion .collapse-item').hide();
        }
    });


    // System Requirements
    var SystemRequirementsGood = '<div class="system-check supported">Your browser is fully supported.</div>';
    //var SystemRequirementsUntested = '<div class="system-check semi-supported">Your browser has not been fully tested and may not work properly with our system.</div>';
    var SystemRequirementsBad = '<div class="system-check unsupported">Your browser is not supported.</div>';
    var SystemRequirementsIs = SystemRequirementsBad;

    var userAgent = navigator.userAgent;

    // Windows XP or Vista only.
    if (userAgent.indexOf("Windows NT 5.1") != -1 || userAgent.indexOf("Windows NT 6.0") != -1) {

        // Firefox 2 only.
        if ($.browser.mozilla) {
            var version = $.browser.version;
            if (isNaN(version)) {
                var parts = version.split('.');
                version = parts.shift() + "." + parts.join('');
            }

            if (version >= 1.81 && version < 1.9) {
                SystemRequirementsIs = SystemRequirementsGood;
            }
        }

        // Internet Explorer 7 only.
        if ($.browser.msie) {
            if ($.browser.version >= 7 && $.browser.version < 8) {
                SystemRequirementsIs = SystemRequirementsGood;
            }
        }
    }

    $('.system-requirements').append(SystemRequirementsIs);




    // Homepage tabs
    $("#primary-nav-roles a, #primary-nav-browse a, #primary-nav-search a").attr("href", "javascript:void(0);");
    $(".homepage #nav-primary li").removeClass("selected");




    if ($.query.get('show').length > 0) {
        $(".nav-homepage div[class*='" + $.query.get('show') + "']").show();
        $(".homepage #nav-primary li[id*='" + $.query.get('show') + "']").addClass("selected");
    } else {

        // Check Cookie
        var homepageTabCookie = $.cookie('homepageTabCookie');
        if (homepageTabCookie == null) {
            $("#primary-nav-roles").addClass("selected");
            $(".nav-roles").show();
        } else {
            $(".nav-homepage div[class*='" + homepageTabCookie + "']").show();
            $(".homepage #nav-primary li[id*='" + homepageTabCookie + "']").addClass("selected");
        };
    };


    $("#primary-nav-roles").click(function () {
        $(".nav-browse, .nav-search").hide();
        $("#nav-primary li:not(#" + this.id + ")").removeClass("selected");
        $(this).addClass("selected");
        $(".nav-roles").show();
        // Set Cookie
        $.cookie('homepageTabCookie', 'nav-roles');
    });
    $("#primary-nav-browse").click(function () {
        $(".nav-roles, .nav-search").hide();
        $("#nav-primary li:not(#" + this.id + ")").removeClass("selected");
        $(this).addClass("selected");
        $(".nav-browse").show();
        // Set Cookie
        $.cookie('homepageTabCookie', 'nav-browse');
    });
    $("#primary-nav-search").click(function () {
        $(".nav-roles, .nav-browse").hide();
        $("#nav-primary li:not(#" + this.id + ")").removeClass("selected");
        $(this).addClass("selected");
        $(".nav-search").show();
        $("#large-search #large-search-query").focus('');
        // Set Cookie
        $.cookie('homepageTabCookie', 'nav-search');
    });

    // Role based navigation
    $(".nav-roles .panel h2").hide();

    $('.nav-roles .inner').prepend('<div class="navigation"><ul></ul></div>')
    var numPanels = $('.nav-roles .panel').length;
    $('.nav-roles .panel').each(function (i) {
        if (!$(this).hasClass("introduction")) {
            this.id = 'tab' + i;
            var texttitle = $(this).find("h2").text();
            var title = (texttitle) ? texttitle : this.id;
            var link;

            if (i === 1) {
                var link = '<li><a href="#' + this.id + '"><span class="bottomright"></span><span class="topleft"></span><span class="bottomleft"></span>' + title + '</a></li>';
            } else if (i === (numPanels - 1)) {
                var link = '<li class="last-child"><a href="#' + this.id + '"><span class="topright"></span><span class="topleft"></span><span class="bottomleft"></span>' + title + '</a></li>';
            } else {
                var link = '<li><a href="#' + this.id + '"><span class="topright"></span><span class="bottomright"></span><span class="topleft"></span><span class="bottomleft"></span>' + title + '</a></li>';
            }
            $('.nav-roles .navigation ul').append(link);
            $('.nav-roles .panel').hide();
        }
    });

    // Check Cookie
    var homepageBrowseTabCookie = $.cookie('homepageBrowseTabCookie');
    if (homepageBrowseTabCookie == null) {
        $('.nav-roles .introduction').show();
    } else {
        $(homepageBrowseTabCookie).parent("li").addClass("selected");
        $(".nav-roles .navigation li a[href^='" + homepageBrowseTabCookie + "']").parent("li").addClass("selected");
        $('.nav-roles .panel').hide();
        $(homepageBrowseTabCookie).show();
    };

    $('.nav-roles .navigation a').click(function () {
        $('.nav-roles ul li').removeClass("selected");
        $(this).parent("li").addClass("selected");
        var id = '#' + this.href.split('#')[1];
        $('.nav-roles .panel').hide();
        $(id).show();
        // Set Cookie
        $.cookie('homepageBrowseTabCookie', id);
        return false;
    })

    // Form
    $("form .textbox, form .textarea, form .dropdown").hover(
      function () {
          $(this).addClass("hover");
      },
      function () {
          $(this).removeClass("hover");
      }
    );
    $("form .textbox, form .textarea, form .dropdown").focus(function () {
        $(this).addClass("active");
    });
    $("form .textbox, form .textarea, form .dropdown").blur(function () {
        $(this).removeClass("active");
    });



    // Glossary
    $(".glossary h2").hide();
    $('.glossary dl').hide();

    $('.glossary').prepend('<div class="navigation"><ul></ul></div>')
    var numLetters = $('.glossary h2').length;
    $('.glossary h2').each(function (i) {
        var title = $(this).text();
        var link;
        if ($('.glossary #' + title).length > 0) {
            link = '<li class="' + title + '"><a href="#' + title + '"">' + title + '<span class="bottom"></span></a></li>';
        } else {
            link = '<li><span class="noitems">' + title + '</span></li>';
        }
        $('.glossary .navigation ul').append(link);
    });

    $('.glossary .navigation a').click(function () {
        $('.glossary .navigation ul li').removeClass("selected");
        $(this).parent("li").addClass("selected");
        var id = '#' + this.href.split('#')[1];
        $('.glossary dl').hide();
        $(id).show();
        return false;
    });


    if ($.query.get('letter').length > 0) {
        letter = $.query.get('letter');
        letter = letter.toUpperCase();

        $(".glossary .navigation li." + letter + "").addClass("selected");
        $(".glossary dl#" + letter + "").show();
    } else {
        $(".glossary dl:first").show();
        $(".glossary .navigation li:first").addClass("selected");
    };





    $(".nav-paging li.selected a").append('<span class="bottom"></span>');


    // Blur and focus events for search textbox
    $(".nav-search .search-form #large-search-query").attr("value", "Type what you're looking for...");
    $(".nav-search .search-form #large-search-query").focus(function () {
        if ($(this).attr("value") == "Type what you're looking for...") {
            $(this).attr("value", "");
        }
    });
    $(".nav-search .search-form #large-search-query").blur(function () {
        if ($(this).attr("value") == "") {
            $(this).attr("value", "Type what you're looking for...");
        }
    });




    // Blur and focus events for filter search textbox
    $(".filter .search #filter-search-query").attr("value", "Enter keywords ...");
    $(".filter .search #filter-search-query").addClass("not-active");

    $(".filter .search #filter-search-query").focus(function () {
        if ($(this).attr("value") == "Enter keywords ...") {
            $(this).toggleClass("not-active");
            $(this).attr("value", "");
        }
    });
    $(".filter .search #filter-search-query").blur(function () {
        if ($(this).attr("value") == "") {
            $(this).toggleClass("not-active");
            $(this).attr("value", "Enter keywords ...");
        }
    });



    if ($('table.sortable').length > 0) {
        // Table Sorting
        //		$('table.sortable tbody').each(function (){
        //			$(this).children('tr:odd').addClass('odd');
        //			$(this).children('tr:even').addClass('even');
        //		});		

        $("table.sortable thead th").hover(
		  function () { $(this).addClass("hover"); },
		  function () { $(this).removeClass("hover"); }
		);

        $("table.sortable").tablesorter({ widgets: ['zebra'], headers: {
            // assign the secound column (we start counting zero) 
            0: {
                // disable it by setting the property sorter to false 
                sorter: false
            }
        }
        });

        //		$("table.sortable thead tr th").click(function (){ 

        //			$(this).parent().parent().parent().children("tbody").children("tr").removeClass();

        //			$(this).parent().parent().parent().children("tbody").children("tr:odd").addClass('odd');
        //			$(this).parent().parent().parent().children("tbody").children("tr:even").addClass('even');

        //		});		
    }

    // Open all SAP links in a new browser window.
    $("a[href*='amun.osr.qld.gov.au']").attr("target", "_blank");
    $("a[href*='troy.osr.qld.gov.au']").attr("target", "_blank");

    var now = new Date();
    var days = new Array(
			'Sunday', 'Monday', 'Tuesday',
			'Wednesday', 'Thursday', 'Friday', 'Saturday');
    var months = new Array(
			'January', 'February', 'March', 'April', 'May',
			'June', 'July', 'August', 'September', 'October',
			'November', 'December');
    var date = ((now.getDate() < 10) ? "0" : "") + now.getDate();
    function fourdigits(number) {
        return (number < 1000) ? number + 1900 : number;
    }
    today = days[now.getDay()] + ", " +
				months[now.getMonth()] + " " +
				date + ", " +
				(fourdigits(now.getYear()));

    // Print Header
    //	$('#header').after('<div id="print-header" class="clearfix"><div class="titles"><div class="qld-logo"><img src="../../images/qglogo.gif"></div><h3>Queensland Treasury</h3><h2>Office of State Revenue</h2></div><div class="date">This page was printed on <strong>' + today +'</strong></div><div class="website">http://www.osr.qld.gov.au</div></div>');

    $('#header').before('<div id="print-header" class="clearfix"><div class="titles"><img src="/_assets/images/print-header.jpg"/></div><div class="date">This page was printed on <strong>' + today + '</strong></div></div>');




    if ($('.AddToEnquiryForm a').length > 0) {
        if ($('#Enquirytype').length > 0) {
            $('.AddToEnquiryForm a').each(function (i) {
                thisAddress = $(this).text();
                $("#Enquirytype").append('<option value="' + thisAddress + '">' + $(this).attr("title") + '</option>');
                $(this).replaceWith('<div class="view-more-link"><span class="text-button"><a href="#EnquiryForm" title="' + $(this).attr("title") + '" class="blue-button"><span>' + $(this).attr("title") + '</span></a></span></div>');
            });
            $('.AddToEnquiryForm h4').hide()
        };

        /* click on AddToEnquiryForm button */
        $('.AddToEnquiryForm a').click(function () {
            if ($('.email AddToEnquiryForm').length > 0) {
                alert("Over here");
            };
            $("#Enquirytype option:contains('" + $(this).attr("title") + "')").attr('selected', 'selected');
            // $(".form form .enquiry").effect("highlight", { color: '#b9f3af' }, 1500);
						
						checkData();
        });

        /* click on header title */
        $('.contactUs dt').click(function () {
            $("#Enquirytype option:contains('" + $(this).attr("title") + "')").attr('selected', 'selected');

            // set avaliablity fields
            var hideFields = $(this).next().find('.hideFields').stop().html();
            validateFormField(hideFields);
        });

    };


    // Contact Us Form
    if ($('.contact-us').length > 0) {
        /* set to default fields when choose a tab*/
        $('#tabs-nav ul li a').click(function () {
            //clearAccordion();
            $('.form form ol').children().removeClass("hideThis");
            $('dt').removeAttr("class").each(function () {
                $(this).find('.collapse-item').stop().css({ 'display': 'none' });
                $(this).find('.expand-item').stop().css({ 'display': 'block' });
                $(this).next().css({ 'display': 'none' });
            });
        });

        function openAccordion(className) {
            $('dt.' + className).each(function () {
                   
            var title = $(this).attr("title");
            $("#Enquirytype option:contains('" + title + "')").attr('selected', 'selected');
                                              
                $(this).addClass("expanded");
                $(this).find('.collapse-item').stop().css({ 'display': 'block' });
                $(this).find('.expand-item').stop().css({ 'display': 'none' });
                $(this).next().css({ 'display': 'block' });               

                // set avaliablity fields
                var hideFields = $(this).next().find('.hideFields').stop().html();
                validateFormField(hideFields);
            });
        }

        var enqType = getURLParameterByName("enquiry");
        if (enqType != "") {
            //fire the right accordion
            switch (enqType) {
                case "duties-taxes-and-grants-duties":
                    openAccordion("duties-taxes-and-grants-duties");
                    break;
                case "duties-taxes-and-grants-payroll-tax":
                    openAccordion("duties-taxes-and-grants-payroll-tax");
                    break;
                case "duties-taxes-and-grants-land-tax":
                    openAccordion("duties-taxes-and-grants-land-tax");
                    break;
                case "duties-taxes-and-grants-first-home-owner-grant":
                    openAccordion("duties-taxes-and-grants-first-home-owner-grant");
                    break;
                case "duties-taxes-and-grants-queensland-building-boost-grant":
                    openAccordion("duties-taxes-and-grants-queensland-building-boost-grant");
                    break;
                case "duties-taxes-and-grants-royalty":
                    openAccordion("duties-taxes-and-grants-royalty");
                    break;
                case "duties-taxes-and-grants-gambling-taxes":
                    openAccordion("duties-taxes-and-grants-gambling-taxes");
                    break;
                case "buying-a-home-first-home-owner-grant":
                    openAccordion("buying-a-home-first-home-owner-grant");
                    break;
                case "buying-a-home-queensland-building-boost-grant":
                    openAccordion("buying-a-home-queensland-building-boost-grant");
                    break;
                case "buying-a-home-land-tax-clearance":
                    openAccordion("buying-a-home-land-tax-clearance");
                    break;
                case "confidential-and-compliance-complaintshome":
                    openAccordion("confidential-and-compliance-complaints");
                    break;
                case "confidential-and-compliance-right-to-information":
                    openAccordion("confidential-and-compliance-right-to-information");
                    break;
                case "confidential-and-compliance-investigations":
                    openAccordion("confidential-and-compliance-investigations");
                    break;
                case "osrconnect-osrconnect":
                    openAccordion("osrconnect-osrconnect");
                    break;
                case "osrconnect-returntransaction-payments":
                    openAccordion("osrconnect-returntransaction-payments");
                    break;
                case "osrconnect-change-my-details":
                    openAccordion("osrconnect-change-my-details");
                    break;
                case "payments-payment-plans":
                    openAccordion("payments-payment-plans");
                    break;
                case "payments-debt-management":
                    openAccordion("payments-debt-management");
                    break;
                case "payments-account-management":
                    openAccordion("payments-account-management");
                    break;
                case "investigations":
                    openAccordion("investigations");
                    break;
                case "corporate-enquiries-general-enquiries":
                    openAccordion("corporate-enquiries-general-enquiries");
                    break;
                case "corporate-enquiries-corporate-mail":
                    openAccordion("corporate-enquiries-corporate-mail");
                    break;
                case "corporate-enquiries-service-of-documents":
                    openAccordion("corporate-enquiries-service-of-documents");
                    break;
                case "corporate-enquiries-natural-disasters":
                    openAccordion("corporate-enquiries-natural-disasters");
                    break;

                default:

                    break;

            }
        }
    }


    // replace standard-button
    if ($('a.standard-button').length > 0) {
        $('a.standard-button').each(function () {
            if ($(this).parent().attr("class") != "text-button") {
                $(this).replaceWith('<span class="text-button"><a href="' + $(this).attr("href") + '" title="' + $(this).attr("title") + '" class="standard-button"><span>' + $(this).html() + '</span></a></span>');
            }
        });
    }




    if ($('.promos').length > 0) {
        var promo1 = $(".promos .container:first").height();
        var promo2 = $(".promos .container:last").height();
        if (promo1 > promo2) {
            $(".promos .container:last").height(promo1);
        } else {
            $(".promos .container:first").height(promo2);

        };


    };

    // Remove the subheaders before the table is sorted.
    $("table.sortable").bind("sortStart", function () {
        $("table.sortable .table-header").remove();
        $("table.sortable").trigger("update");
    });

});


