﻿/* UI scripts */

// Uses http://jQuery.com

// Fix for tabbing to inline anchors in IE
// Wraps anchors without a href in a span with a class of anchor
$(document).ready(function() {
	$("a[@id]").not("[@href]").wrap("<span class='anchor'></span>");
});

// Subscription form tabs - works in combination with CSS
$(document).ready(function() {
	$("body").addClass("js")/* Maybe separate this if used elsewhere too? */
	.find("#panelgroup1 > ul a").click(
		function() {
			$(this).parents("#panelgroup1")
			.removeClass("tab1").removeClass("tab2").removeClass("tab3")
			.addClass($(this).parent().attr("class"));
			return false;
		})
	.end();
});

function SetRegistrationTabClass(className)
{
    $(document).ready(function() {
        $("body").addClass("js")
        .find("#container")
            .removeClass("tab1").removeClass("tab2").removeClass("tab3")
            .addClass(className)
        .end();
    });
}

function SetLoginLabelErrorClass(usernamevalidator,passwordvalidator)
{
    var rfv = document.getElementById(usernamevalidator);
    SetLabelClass(rfv);
    rfv = document.getElementById(passwordvalidator);
    SetLabelClass(rfv);
    document.location = "#form";
}

function SetLabelClass(validator)
{
    if(!validator.isvalid)
    {
        $(document).ready(function() {
            $("body").find("#"+validator.id).siblings("label")
                    .addClass("error")
            .end();
        });
    }
    else
    {
        $(document).ready(function() {
            $("body").find("#"+validator.id).siblings("label")
                    .removeClass("error")
            .end();
        });
    }
}


function AddHtmlAfter(insertafter, htmltoinsert, count, defaultinsertbefore)
{
    htmltoinsert = htmltoinsert.replace(/COUNT/g,count).replace(/###/g,"'");
    $(document).ready(function() {
        if (document.getElementById(insertafter))
        {
            $("body").find("#"+insertafter)
                .after(htmltoinsert)
            .end();
        }
        else
        {
            
            $("body").find("#"+defaultinsertbefore)
                .before(htmltoinsert)
            .end();
        }
    });
}

function RemoveHtml(id)
{
    $(document).ready(function() {
        $("body").find("#"+id)
            .remove()
        .end();
    });
}