function popDisclaimer() {
	mywindow = window.open ("disclaimer.php","site_terms_of_use","location=1,status=1,scrollbars=1,width=680,height=500");
}

function launchClientArea(membername) {
	var url = "https://www.secureccnet.com/" + membername + "/client_area.php";
	mywindow = window.open (url,"site_terms_of_use","location=1,status=1,scrollbars=1,width=880,height=600");
}


function stopEvent(e) {
	if (!e) e = window.event;
	if (e.stopPropagation) {
		e.stopPropagation();
	} else {
		e.cancelBubble = true;
	}
}

function cancelEvent(e) {
	if (!e) e = window.event;
	if (e.preventDefault) {
		e.preventDefault();
	} else {
		e.returnValue = false;
	}
}
function fixNavLinks() {

	// Sidebar Children
	var navigations = ['sidebar', 'main_navigation_area', 'secondary_navigation_area'];
	var navs = [];
	
	for( var i = navigations.length - 1; i >= 0; i--)
	{
		if( document.getElementById(navigations[i]) )
		{
			navs.push(document.getElementById(navigations[i]));
		}
	}
	
	// Loop through the different navs
	for( var x = navs.length - 1; x >= 0; x--)
	{
		// No reason so have long weird names.
		var sbC = navs[x];
		
		// Find the collection of links. This could be a UL/LI or bunch of divs.
		while( sbC && sbC.childNodes )
		{
			sbC = sbC.firstChild.nodeType == 1 ? sbC.firstChild.childNodes : sbC.childNodes[1].childNodes;
		}

		for( var i = sbC.length - 1; i >= 0; i--)
		{
			if( sbC[i].nodeType == 1 ) {
				var item = sbC[i];

				// Drill down until the link is found. Will quit when the first link is found.
				while( item.firstChild && item.nodeName != "A" ) {
					item = item.firstChild;
				}
				
				item.onmouseup = item.onclick = function(e) {
					cancelEvent(e);
					stopEvent(e);
					var membername = window.location.toString().split(window.location.host)[1].split('/')[1];
					var newURL = "http://www.afsb.net/" + membername + '/' + this.href.split('/').pop();
					location.href = newURL;
					return false;
				}
			}
		}
		
	}
}
/**
 * Image slideshow functions
 */
var Slideshow = {
    init:function(element, interval) {
        if (!interval)
        {
            interval = 5000;
        }
        
        $(element + ' div').css('min-height', $(element).css('min-height'));

        $(element + ' li:first').show();
        setInterval('Slideshow.rotate("' + element + '")', interval);
    },
    rotate:function(element) {
        var imageCount = $(element + ' li').length;
        var next = 0;

        $(element + ' li').each(function(i) {
            if ($(this).is(':visible'))
            {
                if (i < imageCount - 1)
                {
                    next = i + 1;
                }

                $(this).fadeOut(null,function() {
                    $(element + ' li:eq(' + next + ')').fadeIn();
                });

                return;
            }
        });
    }
}


// Loads Fancy Box and it's dependents
function loadFancyBox()
{
    // Loads Clue Tip For Calendar Data Hovering
    $('head').append('<script src="scripts/dimensions.js" type="text/javascript"></script>');
    $('head').append('<script src="scripts/jquery.cluetip.js" type="text/javascript"></script>');
    $('head').append('<link rel="stylesheet" href="scripts/fancybox/jquery.fancybox.css" type="text/css" />');
    $('head').append('<script language="javascript" src="scripts/fancybox/jquery.fancybox.js"/></script>');
}

// Load Pretty Photo
function loadPrettyPhoto()
{
    $('head').append('<link rel="stylesheet" href="scripts/prettyphoto/prettyPhoto.css" type="text/css" />');
    $('head').append('<script language="javascript" src="scripts/prettyphoto/jquery.prettyPhoto.js "/></script>');
}

//window.onload = fixNavLinks;

$(document).ready(function() {
    // Loads Fancybox
    loadPrettyPhoto();
    /*
    $(".iframe").fancybox({
        'width' : 1000,
        'height' : 775,
        'autoScale' : true,
        'type' : 'iframe'
    });
    */

    $('#email_subscription_form #emailAddress').focus(function() {
        if (this.value == this.defaultValue){
            this.value = '';
        }
        
        if(this.value != this.defaultValue){
            this.select();
        }
    });
    
    $('#email_subscription_form #emailAddress').blur(function() {
        if ($.trim(this.value) == ''){
            this.value = (this.defaultValue ? this.defaultValue : '');
        }fanc
    });
    
    $('#email_subscription_form').submit(function(event) {
        event.preventDefault();
        
        var reg = 
/^(?:[a-zA-Z0-9\+!#$%&'*/=?^_`{|}~-]+(?:\.[a-zA-Z0-9\+!#$%&'*/=?^_`{|}~-]+)*|""(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*"")@(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-zA-Z0-9-]*[a-zA-Z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/;
        var address = $.trim($('#emailAddress', this).val());
        if(!reg.test(address)) {
           alert('A valid email address is required.');
           return false;
        }

        $.ajax({
            type: 'POST',
            url: 'email_subscription_form.php',
            data: $(this).serialize(),
            dataType: 'json',
            success: function(data, textStatus, XMLHttpRequest) {
                        var cssClass = data.isSuccess ? 'success' : 'error';
                        $('#result', this).removeClass('error').removeClass(cssClass).addClass(cssClass);
                        $('#result', this).text(data.message).show();
                     },
            error: function(data, textStatus, XMLHttpRequest) {
                       $('#result', this).removeClass('success').removeClass('error').addClass('error');
                       $('#result').text('Email subscription was unsuccessful.').show();
                   }
        });
    });
});

