﻿/* UI scripts */

// Uses http://jQuery.com

$(function(){
    $('.con-header .mod-login fieldset,.con-header .mod-search fieldset,.subscriptions-inner fieldset').addClass('js');
    $('.con-header label.overlabel,.con-header .mod-search label.overlabel,.subscriptions-inner .overlabel').overlabel();
});

// Show/hide header login form (only if validation message is hidden)

// Called by onclick on img in Login header
function closeValidationSummary(){
	$("#ctl00_lgnLogin_vdsSummary").fadeOut();
}

$(function(){
 	$("#ctl00_lgnLogin_vdsSummary:hidden").parent().find('.parent fieldset').hide();
    $(".con-header .mod-login h2 a")
        .mouseover(function(){
           $(".con-header .mod-login .parent fieldset").fadeIn('slow');
        })
        .focus(function(){
            $(".con-header .mod-login .parent fieldset").fadeIn('fast');
        });
    
     $("#mainnav").mouseover(function(){
        $("#ctl00_lgnLogin_vdsSummary:hidden").parent().find('.parent fieldset').fadeOut('slow');
    });
    
});


// 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 SetErrorClass(containerid)
{
    var blnIsValid;
    var controlid;
    //Page_ClientValidate();
    $(document).ready(function() {
        $("body").find("#" + containerid + " .validator")
        //$("body").find(".validator")
            .each(function(){
		        validator = document.getElementById($(this).attr('id'));
		        ValidatorValidate(validator);
		        var newblnIsValid = validator.isvalid;
		        var newcontrolid = validator.controltovalidate;
		        
		        //alert(validator.id + ' ' + validator.isvalid);
		        if (!newblnIsValid)
			        $(this).parents("div:first").addClass("error").end();
			    else if (newblnIsValid && ((controlid==newcontrolid && blnIsValid) || controlid!=newcontrolid))
			        $(this).parents("div:first").removeClass("error").end();
			    
			    if (controlid == newcontrolid)
			    {
			        if (!blnIsValid || !newblnIsValid)
			            blnIsValid = false;
			    }   
			    else
			    {
			        controlid = newcontrolid;
			        blnIsValid = newblnIsValid;
			    } 
	        })
    });
}

/* used for CustomValidators to check the length of text areas */
function ValidateMaxLength1000(sender, args)
{
    //alert('ValidateMaxLength1000 ' + args.Value.length);
	if (args.Value.length > 1000)
	{
		args.IsValid = false;
	}
	else 
	{
	    args.IsValid = true;
	}
}

function ValidateMaxLength4500(sender, args)
{
    //alert('ValidateMaxLength1000 ' + args.Value.length);
	if (args.Value.length > 4500)
	{
		args.IsValid = false;
	}
	else 
	{
	    args.IsValid = true;
	}
}

function ValidateMaxLength5000(sender, args)
{
    //alert('ValidateMaxLength5000 ' + args.Value.length);
	if (args.Value.length > 5000)
	{
		args.IsValid = false;
	}
	else 
	{
	    args.IsValid = true;
	}
}

