﻿var _oNavTimer = null;
var _iCurrentImage = 1;
var _aRotating = new Array();
var _iNewImage = 0;
var _oInterval;
var _bIsAnimating = false;

function openPage(sUrl)
{
    window.location = sUrl;
}

function isEmail(sInput)
{
    var bHasAt=false;
    var bHasPeriod=false;
    if(sInput.length<6) return false;
    
    for(var  i=0;i<sInput.length;i++)
    {
        if(sInput.charAt(i)=='@' && bHasAt) return false;
        if(sInput.charAt(i)=='@' && !bHasAt) bHasAt = true;
        if(sInput.charAt(i)=='.' && bHasAt) bHasPeriod = true;
    }
    
    if(bHasAt && bHasPeriod) return true;
    return false;
}

function isNumeric(sText)
{
    var ValidChars = "0123456789.";
    var IsNumber=true;
    var Char;

    for (i = 0; i < sText.length && IsNumber == true; i++) 
    { 
        Char = sText.charAt(i); 
        if (ValidChars.indexOf(Char) == -1) 
        {
            IsNumber = false;
        }
    }
    return IsNumber;
}

function ajaxCall(sUrl, sRequest, fCallback, sType)
{
    if(sType != undefined)
    {
        $.ajax({type: "POST", url: sUrl, data:sRequest, success: fCallback, dataType: sType  });
    }
    else
    {
        $.ajax({type: "POST", url: sUrl, data:sRequest, success: fCallback });
    }
}

function loginUser()
{
    var oForm;
    var oInput;
    
    oForm = document.createElement('form');
    oForm.action = '/Secure/Login.aspx';
    oForm.style.display='none';
    oForm.method='post';
    
    oInput = document.createElement('input');
    oInput.name = 'txtEmailAddress';
    oInput.value = $$('txtLoginBoxLogin').value;
    oForm.appendChild(oInput);
    
    oInput = document.createElement('input');
    oInput.name = 'txtPassword';
    oInput.value = $$('txtLoginBoxPassword').value;
    oForm.appendChild(oInput);
    
    oInput = document.createElement('input');
    oInput.name = 'cbRememberMe';
    oInput.value = $$("cbRememberMe").checked ? "on":"";
    oForm.appendChild(oInput);
    
    document.getElementsByTagName("div")[0].appendChild(oForm);
    oForm.submit();
}

function show(item) { $(item).show(); }
function hide(item) { $(item).hide(); }

function displayMenu(item) 
{
    switch(item)
    {
        case "About" : 
            $('#aAbout').addClass("on");
            $('#aAffiliate').removeClass("on");
            $('#aPartner').removeClass("on");
            $("#divAffiliate").hide();
            $("#divPartner").hide();
            $("#divAbout").show();
            break;
        case "Affiliate" : 
            $('#aAbout').removeClass("on");
            $('#aAffiliate').addClass("on");
            $('#aPartner').removeClass("on");
            $("#divAffiliate").show();
            $("#divPartner").hide();
            $("#divAbout").hide();
            break;
        case "Partner" : 
            $('#aAbout').removeClass("on");
            $('#aAffiliate').removeClass("on");
            $('#aPartner').addClass("on");
            $("#divAffiliate").hide();
            $("#divPartner").show();
            $("#divAbout").hide();
            break;
        default :
            $('#aAbout').removeClass("on");
            $('#aAffiliate').removeClass("on");
            $('#aPartner').removeClass("on");
            $("#divAffiliate").hide();
            $("#divPartner").hide();
            $("#divAbout").hide();
    }
}

function displayNav(item)
{
    if(_oNavTimer!=null)
    {
        window.clearTimeout(_oNavTimer);
    }
    window.setTimeout(doNav, 750);
}

function displayNav(item)
{
    switch(item)
    {
        case 'divmyFPG' :
            animatedcollapse.show("divmyFPG");
            animatedcollapse.hide("divPlanningSolutions");
            animatedcollapse.hide("divProfessionalEducation");
            animatedcollapse.hide("divLifeInsurance");
            animatedcollapse.hide("divAnnuities");
            animatedcollapse.hide("divSpecialtyProducts");
            break;
        case 'divPlanningSolutions' :
            animatedcollapse.hide("divmyFPG");
            animatedcollapse.show("divPlanningSolutions");
            animatedcollapse.hide("divProfessionalEducation");
            animatedcollapse.hide("divLifeInsurance");
            animatedcollapse.hide("divAnnuities");
            animatedcollapse.hide("divSpecialtyProducts");
            break;
        case 'divProfessionalEducation' :
            animatedcollapse.hide("divmyFPG");
            animatedcollapse.hide("divPlanningSolutions");
            animatedcollapse.show("divProfessionalEducation");
            animatedcollapse.hide("divLifeInsurance");
            animatedcollapse.hide("divAnnuities");
            animatedcollapse.hide("divSpecialtyProducts");
            break;
        case 'divLifeInsurance' :
            animatedcollapse.hide("divmyFPG");
            animatedcollapse.hide("divPlanningSolutions");
            animatedcollapse.hide("divProfessionalEducation");
            animatedcollapse.show("divLifeInsurance");
            animatedcollapse.hide("divAnnuities");
            animatedcollapse.hide("divSpecialtyProducts");
            break;
        case 'divAnnuities' :
            animatedcollapse.hide("divmyFPG");
            animatedcollapse.hide("divPlanningSolutions");
            animatedcollapse.hide("divProfessionalEducation");
            animatedcollapse.hide("divLifeInsurance");
            animatedcollapse.show("divAnnuities");
            animatedcollapse.hide("divSpecialtyProducts");
            break;
        case 'divSpecialtyProducts' :
            animatedcollapse.hide("divmyFPG");
            animatedcollapse.hide("divPlanningSolutions");
            animatedcollapse.hide("divProfessionalEducation");
            animatedcollapse.hide("divLifeInsurance");
            animatedcollapse.hide("divAnnuities");
            animatedcollapse.show("divSpecialtyProducts");
            break;
    }
}

function hideMenu(item)
{
    switch(item)
    {
        case "About" : 
            $("#divAbout").hide();
            $('#aAbout').removeClass("on");
            break;
        case "Affiliate" : 
            $("#divAffiliate").hide();
            $('#aAffiliate').removeClass("on");
            break;
        case "Partner" : 
            $("#divPartner").hide();
            $('#aPartner').removeClass("on");
            break;
    }
}

function setupPods()
{
    var oItems;
    
    if(!$$('divPodMain1'))
    {
        return;
    }
    
    oItems = $$('divPodMain1').getElementsByTagName("a");
    if(oItems.length > 0)
    {
        $$('divPodMain1').onclick = function()
        {
            var oItems;
            oItems = $$('divPodMain1').getElementsByTagName("a");
            if(oItems.length == 1)
            {
                window.location = oItems[0].href;
            }
        }
    }
    
    oItems = $$('divPodMain2').getElementsByTagName("a");
    if(oItems.length > 0)
    {
        $$('divPodMain2').onclick = function()
        {
            var oItems;
            oItems = $$('divPodMain2').getElementsByTagName("a");
            if(oItems.length == 1)
            {
                window.location = oItems[0].href;
            }
        }
    }
    
    oItems = $$('divPodMain3').getElementsByTagName("a");
    if(oItems.length > 0)
    {
        $$('divPodMain3').onclick = function()
        {
            var oItems;
            oItems = $$('divPodMain3').getElementsByTagName("a");
            if(oItems.length == 1)
            {
                window.location = oItems[0].href;
            }
        }
    }
}

function $$(el) { return document.getElementById(el); }
function pageLoad() { }

function auto_currency(id)
{  
    var variable = document.getElementById(id);  
    var new_value =  variable.value.replace(/\,/g,"");  
    variable.style.textAlign = "right";  
    variable.value = digit_grouping(new_value);  
}  

function digit_grouping(nStr)
{
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) 
    {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
	  
    return x1 + x2;
}

function doRoll()
{
    if (_iCurrentImage == (_aRotating.length-1))
    {
        _iNewImage = 0;
    }
    else
    {
        _iNewImage = _iCurrentImage + 1;
    }
    
    _aRotating[_iCurrentImage].style.zIndex = 0;
    _aRotating[_iNewImage].style.zIndex = 2;
    $(_aRotating[_iNewImage]).fadeIn("slow", function()
    {
        window.setTimeout(doRoll, 5000);
        $(_aRotating[_iCurrentImage]).hide();
        _iCurrentImage = _iNewImage;
    });
}

jQuery(document).ready(function()
{
    if ($$('txtLoginBoxLogin'))
    {
        $('#txtLoginBoxLogin').focus(function()
        {
            $(this).css("background", "url(/Images/LoginTextBackgroundOn.gif) no-repeat");
        });
        
        $('#txtLoginBoxLogin').blur(function()
        {
            if($$('txtLoginBoxLogin').value == "")
            {
                $(this).css("background", "url(/Images/LoginTextBackground.gif) no-repeat");
            }
            else
            {
                $(this).css("background", "url(/Images/LoginTextBackgroundOn.gif) no-repeat");
            }
        });
        
        $('#txtLoginBoxPassword').focus(function()
        {
            $(this).css("background", "url(/Images/LoginTextBackgroundOn.gif) no-repeat");
        });
        
        $('#txtLoginBoxPassword').blur(function()
        {
            if($$('txtLoginBoxPassword').value == "")
            {
                $(this).css("background", "url(/Images/PasswordTextBackground.gif) no-repeat");
            }
            else
            {
                $(this).css("background", "url(/Images/PasswordTextBackgroundOn.gif) no-repeat");
            }
        });
        
        $('#txtLoginBoxPassword').keyup(function(eventObject)
        {
            if(eventObject.keyCode == 13)
            {
                loginUser();
            }
        });
        
        $('#txtLoginBoxLogin').blur();
        $('#txtLoginBoxPassword').blur();
    }
    
    setupPods();
    
    $("a.fancybox").fancybox(
    {
        'showNavArrows' : false,
        'overlayColor' : '#000',
        'overlayOpacity' : '0.7'
    });
    
    $("a.iframe").fancybox(
    {
        'showNavArrows' : false,
        'autoDimensions': false,
        'width' : $(window).width(),
        'height' : $(window).height(),
        'margin' : 0,
        'overlayColor' : '#000',
        'overlayOpacity' : '0.7'
    });
    
    $("a.pdf").each(function()
    {
        $(this).attr("class", $(this).attr("class") + " iframe");
        $(this).fancybox(
        {
            'showNavArrows' : false,
            'autoDimensions': false,
            'padding' : '7',
            'margin' : 0,
            'width' : $(window).width(),
            'height' : $(window).height(),
            'overlayColor' : '#000',
            'overlayOpacity' : '0.7'
        });
    });
    
    $("a[rel*=shadowbox]").each(function()
    {
        $(this).attr("class", $(this).attr("class") + " iframe");
        
        if ($(this).attr("href").indexOf(".pdf") > -1)
        {
            $(this).fancybox(
            {
                'showNavArrows' : false,
                'autoDimensions': false,
                'padding' : '7',
                'margin' : 0,
                'width' : $(window).width(),
                'height' : $(window).height(),
                'overlayColor' : '#000',
                'overlayOpacity' : '0.7'
            });
        }
        else
        {
            $(this).fancybox(
            {
                'showNavArrows' : false,
                'autoDimensions': false,
                'width' : $(window).width(),
                'height' : $(window).height(),
                'margin' : 0,
                'overlayColor' : '#000',
                'overlayOpacity' : '0.7'
            });
        }
    });
    
    
    if ($("div.rotating").length > 0)
    {
        $(".rotating img").each(function()
        {
            _aRotating[_aRotating.length] = this;
        });
        
        _iCurrentImage = 0;
	      
	      _oInterval = window.setTimeout(doRoll, 5000);
    }
    
    pageLoad();
});