﻿function deliniate(str) {
    point = str.lastIndexOf("=");
    return (str.substring(point + 1, str.length));
}
window.onload = function() {
    var itemTag = document.location.toString();
    var newTag = deliniate(itemTag);
    if (newTag.indexOf("http://") < 0 && newTag.indexOf("https://") < 0) {
        toggle(newTag);
    } else {
        toggle("welcome");
    }
}

function toggle(contentSet) {
    //alert(contentSet);
    var textContainer = contentSet + "-text";
    var navItem = contentSet + "-switch";
    var UserTypeCookie=readCookie("UserType");
    var LinkUpStatusCookie=readCookie("LinkUpStatus");    
    if ( UserTypeCookie== null|| LinkUpStatusCookie== null ||UserTypeCookie==""|| LinkUpStatusCookie=="Incomplete") 
        {
            var welcome = document.getElementById("welcome-switch");
            if (welcome != null) 
            {
                welcome.className = "";
                var welcomeText = document.getElementById("welcome-text");
                welcomeText.style.visibility = 'hidden';
                welcomeText.style.display = 'none';
            }

            var mail = document.getElementById("mail-switch");
            if (mail != null) 
            {
                mail.className = "";
                var mailText = document.getElementById("mail-text");
                mailText.style.visibility = 'hidden';
                mailText.style.display = 'none';
            }

            var money = document.getElementById("money-switch");
            if (money != null) 
            {
                money.className = "";
                var moneyText = document.getElementById("money-text");
                moneyText.style.visibility = 'hidden';
                moneyText.style.display = 'none';
            }
            var calendar = document.getElementById("calendar-switch");
            if (calendar != null)
            {
                calendar.className = "";
                var calendarText = document.getElementById("calendar-text");
                calendarText.style.visibility = 'hidden';
                calendarText.style.display = 'none';
            }
            var currentNav = document.getElementById(navItem);
            if (currentNav != null) 
            {
                currentNav.className = "current";
                var currentText = document.getElementById(textContainer);
                currentText.style.visibility = 'visible';
                currentText.style.display = 'block';
            }
        }  
        else if(contentSet=="mail" && UserTypeCookie!="Admin")
        {
         window.location="Dashboard/Mail-Room/Default.aspx"            
        } 
        else if(contentSet=="calendar" && UserTypeCookie!="Admin")
        {
         window.location="Dashboard/Calendar/By-Month.aspx"            
        } 
        else if(contentSet=="money" && UserTypeCookie=="Parent")
        {
         window.location="Dashboard/Money-Matters/Default.aspx"            
        }            
        else
        {
            var welcome = document.getElementById("welcome-switch");

            if (welcome != null) 
            {    
                welcome.className = "";
                var welcomeText = document.getElementById("welcome-text");
                welcomeText.style.visibility = 'hidden';
                welcomeText.style.display = 'none'; 
            }            
            var mail = document.getElementById("mail-switch");
            if (mail != null) 
            {            
                mail.className = "";
                var mailText = document.getElementById("mail-text");
                mailText.style.visibility = 'hidden';
                mailText.style.display = 'none';               
            }                                   
            var money = document.getElementById("money-switch");
            if (money != null) 
            {            
                money.className = "";
                var moneyText = document.getElementById("money-text");
                moneyText.style.visibility = 'hidden';
                moneyText.style.display = 'none';   
            }
            var calendar = document.getElementById("calendar-switch");
            if (calendar != null)
            {            
                calendar.className = "";
                var calendarText = document.getElementById("calendar-text");
                calendarText.style.visibility = 'hidden';
                calendarText.style.display = 'none';
            }
            var currentNav = document.getElementById(navItem);
            if (currentNav != null) 
            {            
                currentNav.className = "current";
                var currentText = document.getElementById(textContainer);
                currentText.style.visibility = 'visible';
                currentText.style.display = 'block';  
            }              
        }
                                                                 
}

function GetLinkupStatus(Source)
{
      var Screen=Source;
      var LinkUpStatusCookie=readCookie("LinkUpStatus");
      var UserTypeCookie=readCookie("UserType");
      if(Source=="MailRoom")
      {
          if((LinkUpStatusCookie== null || LinkUpStatusCookie=="Incomplete" || LinkUpStatusCookie=="Denied") && UserTypeCookie=="Parent")
          {         
             alert('Once the Co-Parent is Signed Up and Your Accounts are Linked You Will Be Able to Use Functions on the Website.  When Both Parents are Signed Up the First Parent Who Signs Up Needs To Accept the Co-Parent Via a Prompt Below the Message On the Dashboard.');
             return false;    
          }  
          else
          {
            window.location="Mail-Room/Default.aspx"               
          }       
      }      
      else if(Source=="NewMail")
      {
          if((LinkUpStatusCookie== null || LinkUpStatusCookie=="Incomplete" || LinkUpStatusCookie=="Denied") && UserTypeCookie=="Parent")
          {         
             alert('Once the Co-Parent is Signed Up and Your Accounts are Linked You Will Be Able to Use Functions on the Website.  When Both Parents are Signed Up the First Parent Who Signs Up Needs To Accept the Co-Parent Via a Prompt Below the Message On the Dashboard.');
             return false;   
          }  
          else
          {
            window.location="Mail-Room/Message.aspx"                  
          }          
      }      
      else if(Source=="Calender")
      {
          if((LinkUpStatusCookie== null || LinkUpStatusCookie=="Incomplete" || LinkUpStatusCookie=="Denied") && UserTypeCookie=="Parent")
          {         
             alert('Once the Co-Parent is Signed Up and Your Accounts are Linked You Will Be Able to Use Functions on the Website.  When Both Parents are Signed Up the First Parent Who Signs Up Needs To Accept the Co-Parent Via a Prompt Below the Message On the Dashboard.');
             return false;   
          }  
          else
          {
             window.location="Calendar/By-Month.aspx"               
          }          
      }
      else if(Source=="NewCalender")
      {
          if((LinkUpStatusCookie== null || LinkUpStatusCookie=="Incomplete" || LinkUpStatusCookie=="Denied") && UserTypeCookie=="Parent")
          {         
             alert('Once the Co-Parent is Signed Up and Your Accounts are Linked You Will Be Able to Use Functions on the Website.  When Both Parents are Signed Up the First Parent Who Signs Up Needs To Accept the Co-Parent Via a Prompt Below the Message On the Dashboard.');
             return false;   
          }  
          else
          {
             window.location="Calendar/Edit-Event.aspx"               
          }          
      }
      else if(Source=="DayCalender")
      {
          if((LinkUpStatusCookie== null || LinkUpStatusCookie=="Incomplete" || LinkUpStatusCookie=="Denied") && UserTypeCookie=="Parent")
          {         
             alert('Once the Co-Parent is Signed Up and Your Accounts are Linked You Will Be Able to Use Functions on the Website.  When Both Parents are Signed Up the First Parent Who Signs Up Needs To Accept the Co-Parent Via a Prompt Below the Message On the Dashboard.');
             return false;   
          }  
          else
          {
             window.location="Calendar/Default.aspx"               
          }          
      }
      else if(Source=="WeekCalender")
      {
          if((LinkUpStatusCookie== null || LinkUpStatusCookie=="Incomplete" || LinkUpStatusCookie=="Denied") && UserTypeCookie=="Parent")
          {         
             alert('Once the Co-Parent is Signed Up and Your Accounts are Linked You Will Be Able to Use Functions on the Website.  When Both Parents are Signed Up the First Parent Who Signs Up Needs To Accept the Co-Parent Via a Prompt Below the Message On the Dashboard.');
             return false;   
          }  
          else
          {
             window.location="Calendar/By-Week.aspx"               
          }          
      }
      else if(Source=="MonthCalender")
      {
          if((LinkUpStatusCookie== null || LinkUpStatusCookie=="Incomplete" || LinkUpStatusCookie=="Denied") && UserTypeCookie=="Parent")
          {         
             alert('Once the Co-Parent is Signed Up and Your Accounts are Linked You Will Be Able to Use Functions on the Website.  When Both Parents are Signed Up the First Parent Who Signs Up Needs To Accept the Co-Parent Via a Prompt Below the Message On the Dashboard.');
             return false;   
          }  
          else
          {
             window.location="Calendar/By-Month.aspx"               
          }          
      }   
      else if(Source=="HolidayCalender")
      {
          if((LinkUpStatusCookie== null || LinkUpStatusCookie=="Incomplete" || LinkUpStatusCookie=="Denied") && UserTypeCookie=="Parent")
          {         
             alert('Once the Co-Parent is Signed Up and Your Accounts are Linked You Will Be Able to Use Functions on the Website.  When Both Parents are Signed Up the First Parent Who Signs Up Needs To Accept the Co-Parent Via a Prompt Below the Message On the Dashboard.');
             return false;   
          }  
          else
          {
             window.location="Calendar/Holiday.aspx"               
          }          
      }                            
      else if(Source=="ExpenseListing")
      {
          if((LinkUpStatusCookie== null || LinkUpStatusCookie=="Incomplete" || LinkUpStatusCookie=="Denied") && UserTypeCookie=="Parent")
          {         
             alert('Once the Co-Parent is Signed Up and Your Accounts are Linked You Will Be Able to Use Functions on the Website.  When Both Parents are Signed Up the First Parent Who Signs Up Needs To Accept the Co-Parent Via a Prompt Below the Message On the Dashboard.');
             return false;   
          }  
          else
          {
             window.location="Money-Matters/Default.aspx"               
          }          
      }  
      else if(Source=="NewExpense")
      {
          if((LinkUpStatusCookie== null || LinkUpStatusCookie=="Incomplete" || LinkUpStatusCookie=="Denied") && UserTypeCookie=="Parent")
          {         
             alert('Once the Co-Parent is Signed Up and Your Accounts are Linked You Will Be Able to Use Functions on the Website.  When Both Parents are Signed Up the First Parent Who Signs Up Needs To Accept the Co-Parent Via a Prompt Below the Message On the Dashboard.');
             return false;   
          }  
          else
          {
             window.location="Money-Matters/ExpenseUpdate.aspx"               
          }          
      }
      else if(Source=="ExpenseCategories")
      {
          if((LinkUpStatusCookie== null || LinkUpStatusCookie=="Incomplete" || LinkUpStatusCookie=="Denied") && UserTypeCookie=="Parent")
          {         
             alert('Once the Co-Parent is Signed Up and Your Accounts are Linked You Will Be Able to Use Functions on the Website.  When Both Parents are Signed Up the First Parent Who Signs Up Needs To Accept the Co-Parent Via a Prompt Below the Message On the Dashboard.');
             return false;   
          }  
          else
          {
             window.location="Money-Matters/CategoryList.aspx"               
          }          
      }  
      else if(Source=="Renew")
      {
         if((LinkUpStatusCookie== null || LinkUpStatusCookie=="Incomplete" || LinkUpStatusCookie=="Denied") && UserTypeCookie=="Parent")
          {         
             alert('Once the Co-Parent is Signed Up and Your Accounts are Linked You Will Be Able to Use Functions on the Website.  When Both Parents are Signed Up the First Parent Who Signs Up Needs To Accept the Co-Parent Via a Prompt Below the Message On the Dashboard.');
             return false; 
          }  
          else
          {
             window.location="Renew.aspx"               
          } 
      }      
      else if(Source=="Accounts")
      {
         if((LinkUpStatusCookie== null || LinkUpStatusCookie=="Incomplete"  || LinkUpStatusCookie=="Denied") && UserTypeCookie=="Parent")
          {         
             alert('Once the Co-Parent is Signed Up and Your Accounts are Linked You Will Be Able to Use Functions on the Website.  When Both Parents are Signed Up the First Parent Who Signs Up Needs To Accept the Co-Parent Via a Prompt Below the Message On the Dashboard.');
             return false;   
          }  
          else
          {
             window.location="Accounts.aspx"               
          }       
      }  
      else if(Source=="Children")
      {
         if((LinkUpStatusCookie== null || LinkUpStatusCookie=="Incomplete" || LinkUpStatusCookie=="Denied") && UserTypeCookie=="Parent")
          {         
             alert('Once the Co-Parent is Signed Up and Your Accounts are Linked You Will Be Able to Use Functions on the Website.  When Both Parents are Signed Up the First Parent Who Signs Up Needs To Accept the Co-Parent Via a Prompt Below the Message On the Dashboard.');
             return false;   
          }  
          else
          {
             window.location="Child-List.aspx"               
          }
      }

      else if (Source == "ThirdParty") {
            window.location = "AccountListing.aspx"
          }
                
}

function readCookie(name)
{
  var ca = document.cookie.split(';');
  var nameEQ = name + "=";
  for(var i=0; i < ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1, c.length); //delete spaces
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
  return null;
}