var ie = (function () {

    var undef,
        v = 3,
        div = document.createElement('div'),
        all = div.getElementsByTagName('i');

    while (
        div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
        all[0]
    );

    return v > 4 ? v : undef;

}());
if (ie < 9) {
    if (window.location.pathname.substring(window.location.pathname.lastIndexOf('/') + 1) != "Oldbrowser")
        window.location = "/Oldbrowser";
}

$(document).ready(function () {
    if ($('#geoLocated').val() != undefined && $('#geoLocated').val().toLowerCase() == 'true') {
        $('#geoStateModal').foundation('reveal', 'open');
        $('.top-nav-bar a').each(function () {
            if ($(this).html().toLowerCase().indexOf('corporate') < 0 && $(this).attr('href').toLowerCase().indexOf('corporate') < 0
                && $(this).attr('href').toLowerCase().indexOf('ir.wellcare.com') < 0
                && $(this).attr('href').toLowerCase().indexOf('www.centene.com') < 0
                && $(this).attr('href').toLowerCase().indexOf('/producers') < 0
                && $(this).attr('href').toLowerCase().indexOf('/fap') < 0) {
                $(this).click(function () {
                    $('#geoStateModal').foundation('reveal', 'open');
                    return false;
                });
            }
        });
    }

    if ($('#statePage').val() != undefined && $('#statePage').val().toLowerCase() == 'true') {
        $('.location a').each(function () {
            $(this).click(function () {
                $('#geoStateModal').foundation('reveal', 'open');
                return false;
            });
        });
    }

    $('a').each(function () {
        var goingTo = this.hostname;
        var ourUrl = document.domain.split("/")[0];
        if (typeof goingTo !== 'undefined' && goingTo !== undefined && goingTo !== null && $.trim(goingTo) !== "" && $.trim(goingTo) !== "#"
            && ourUrl != goingTo && goingTo.toLowerCase().indexOf('wellcare.com') < 0
            && !(document.URL.toLowerCase().indexOf('medicare') > -1 && document.URL.toLowerCase().indexOf('/pharmacy/drug-list') > -1)
            && !(document.URL.toLowerCase().indexOf('medicaid') > -1 && document.URL.toLowerCase().indexOf('/newsletters') > -1)) {
            $(this).attr('data-reveal-id', 'leavingSiteModel');
        }
    });

    $('a[data-reveal-id="leavingSiteModel"]').click(function () {
        $('#leavingSiteModel').attr('data-url', this.href);
        $('#leavingSiteModel').attr('target', this.target);
    });

    $('a.modelOptNo').click(function () { $('#leavingSiteModel').foundation('reveal', 'close'); });
    $('a.modelOptYes').click(function () {
        var url = $('#leavingSiteModel').attr('data-url');
        if ($('#leavingSiteModel').attr('target') == "_blank") {
            window.open(url);
        } else if ($('#webAddressLink').attr('target') == "_blank") {
            window.open($('#webAddressLink').attr('href'));
        }
        else {
            /*CODE NOT FUNCTIONAL ON MOBILE -- var a = document.createElement("a");
            if (a.click) {
                a.setAttribute("href", url);
                a.style.display = "none";
                document.body.appendChild(a);
                a.click();
            } else {
                window.location = url;
            }-- CODE NOT FUNCTIONAL ON MOBILE*/
            window.location = url;
        }
    });


    $('#survey-no').click(function () { $('#surveyModal').foundation('reveal', 'close'); });

    $('#site-searchbox-submit').click(function () {
        var qParam = $("input#site-searchbox").val()
        if (qParam == "") {
            $('#searchErrorModal').foundation('reveal', 'open');
            return;
        } else {
            qParam = qParam.replace(/[^\w\s]/gi, '');
            var searchpageUrl = $('#searchPageUrl').val();
            window.location.href = searchpageUrl + "?q=" + qParam;
        }
    });

    $('.searchbox').keypress(function (e) {
        if (e.which == 13)  // the enter key code
        {
            var searchpageUrl = $('#searchPageUrl').val();
            var qParam = $(this).val()
            if (qParam == "") {
                $('#searchErrorModal').foundation('reveal', 'open');
                return;
            } else {
                qParam = qParam.replace(/[^\w\s]/gi, '');
                window.location.href = searchpageUrl + "?q=" + qParam;
            }
            return false;
        }

        var regex = new RegExp("^[\"a-zA-Z0-9\040\.-'/]+$");
        var str = String.fromCharCode(!e.charCode ? e.which : e.charCode);

        if (regex.test(str.trim())) {
            return true;
        }

        e.preventDefault();
        return false;
    });

    function ToSearch(searchpageUrl) {
        var inputValue = $('#searchHelpInput').val();

        if (inputValue == undefined) {
            inputValue = $('#searchCCGInput').val();
        }

        inputValue = inputValue.replace(/[^\w\s]/gi, '');
        searchpageUrl += "?q=" + inputValue;

        if (inputValue == "" && inputValue != undefined) {
            $('#searchErrorModal').foundation('reveal', 'open');
            return;
        }

        var dateInput = $('.open');
        var orderValue = false;

        if (dateInput != undefined) {
            orderValue = true;
        }
        if (dateInput.length > 0) {
            searchpageUrl += "&dd=" + orderValue;
        }

        var content = $("#filer-by-content-type").val();

        if (content != "" && content != undefined) {
            searchpageUrl += "&ct=" + content;
        }

        window.location.href = searchpageUrl;
    }

    $("#searchInputBtn").on('click', function () {
        var searchpageUrl = $('#searchPageUrl').val();

        ToSearch(searchpageUrl);
    });

    $("#searchInputCCGBtn").on('click', function () {
        var searchpageUrl = $('#searchPageCCGUrl').val();

        ToSearch(searchpageUrl);
    });

    $("#searchHelpInput").keypress(function (e) {
        if (e.which == 13)  // the enter key code
        {
            var searchpageUrl = $('#searchPageUrl').val();
            ToSearch(searchpageUrl);
        }
    });

    $("#searchCCGInput").keypress(function (e) {
        if (e.which == 13)  // the enter key code
        {
            var searchpageUrl = $('#searchPageCCGUrl').val();
            ToSearch(searchpageUrl);
        }
    });

    $("#searchCCGInputBtn").click(function () {
        var searchpageUrl = $('#searchPageCCGUrl').val();
        ToSearch(searchpageUrl);
    });
});
//Collapse
$('dt.collapseHeader').click(function () {
    if ($(this).hasClass('open')) {
        $(this).removeClass('open');
        $(this).next('dd.collapseContent').slideUp(300);
    } else {
        $(this).addClass('open');
        $(this).next('dd.collapseContent').slideDown(300);
    };
});

//OPEN ALL
$('.openAll').click(function () {
    $('dt.collapseHeader').each(function () {
        if (!$(this).hasClass('open')) {
            $(this).addClass('open');
            $(this).next('dd.collapseContent').slideDown(300);
        };
    });
});

//CLOSE ALL
$('.closeAll').click(function () {
    $('dt.collapseHeader').each(function () {
        if ($(this).hasClass('open')) {
            $(this).removeClass('open');
            $(this).next('dd.collapseContent').slideUp(300);
        }
    });
});
//END Collapse

//search result page - hero collapse    
// TODO: change to Angular vs custom JS
// TODO: all the JS on this page needs a QA review/refactoring
$('.toggle-advanced-filters').click(function (e) {
    if ($(this).hasClass('open')) {
        $('.advanced-filters-panel').slideToggle();
        $(this).removeClass('open');
        $(this).find('span').html('More Search Options');

    } else {
        $('.advanced-filters-panel').slideToggle();
        $('.toggle-advanced-filters').addClass('open');
        $(this).find('span').html('Less Search Options');
    }
    e.stopPropagation();
    e.preventDefault();
});

//FaqList page - search options
$('.less-options.search-row').click(function () {
    $('.row.more-search-options').toggle();
});


//menu for mobile
$('button').click(function () {
    $(this).toggleClass('expanded').siblings('div.menu').slideToggle();
    $('nav.mobile').toggleClass('active');
});

$('.header-mobile .mobile .menu ul li.collapse').click(function () {
    $(this).toggleClass('collapse-open');
});

var originalFontSize;
var fontSizeIncrement = 0.25; // increase/decrease by 25%
$(document).ready(function () {
    //script for mobile menu
    var mobileheight = $(window).height() - 68; //68 = mobile-menu-height
    $('ul.mobile-scroll').height(mobileheight);

     originalFontSize = $('html').css('font-size');
    
    // Increase Font Size
    $(".increaseFont").click(function (e) {
        var increment = parseInt(originalFontSize) * fontSizeIncrement;
        var currFontSize = $('html').css('font-size');
        var newFontSize = (parseInt(currFontSize) + increment) + "px";
        $('html').css('font-size', newFontSize);
        e.stopPropagation();
        e.preventDefault();
    });
    // Decrease Font Size
    $(".decreaseFont").click(function (e) {
        var increment = parseInt(originalFontSize) * fontSizeIncrement;
        var currFontSize = $('html').css('font-size');
        var newFontSize = (parseInt(currFontSize) - increment) + "px";
        $('html').css('font-size', newFontSize);
        e.stopPropagation();
        e.preventDefault();
      });

    // Toggle class
    $(".relevant").click(function () {
        $(this).toggleClass("open");
    });
});

function CollpaseFAP() {
    jQuery('dt.collapseHeader').click(function () {
        if (jQuery(this).hasClass('open')) {
            jQuery(this).removeClass('open');
            jQuery(this).next('dd.collapseContent').slideUp(300);
        } else {
            jQuery(this).addClass('open');
            jQuery(this).next('dd.collapseContent').slideDown(300);
        };
    });
}

function todayFunction() {
    $('.ui-datepicker-today').click();
    $('.xdsoft_today div').click();
}

//script for a sticky header
$(window).scroll(function () {
    if ($(this).scrollTop() > 1) {
        $('div.wrapper-header').addClass("sticky-header");
    }
    else {
        $('div.wrapper-header').removeClass("sticky-header");
    }
});

//TODO: Remove this since we are using Selectric?
// Iterate over each select element
$("select:not('.selectric')").each(function () {

    // Cache the number of options
    var $this = $(this),
        numberOfOptions = $(this).children('option').length;

    // Hides the select element
    $this.addClass('s-hidden');

    // Wrap the select element in a div
    $this.wrap('<div class="select"></div>');

    // Insert a styled div to sit over the top of the hidden select element
    $this.after('<div class="styledSelect"></div>');

    // Cache the styled div
    var $styledSelect = $this.next('div.styledSelect');

    // Show the first select option in the styled div
    $styledSelect.text($this.children('option').eq(0).text());

    // Insert an unordered list after the styled div and also cache the list
    var $list = $('<ul />', {
        'class': 'options'
    }).insertAfter($styledSelect);

    // Insert a list item into the unordered list for each select option
    for (var i = 0; i < numberOfOptions; i++) {
        $('<li />', {
            text: $this.children('option').eq(i).text(),
            rel: $this.children('option').eq(i).val()
        }).appendTo($list);
    }

    // Cache the list items
    var $listItems = $list.children('li');

    // Show the unordered list when the styled div is clicked (also hides it if the div is clicked again)
    $styledSelect.click(function (e) {
        e.stopPropagation();
        $('div.styledSelect.active').each(function () {
            $(this).removeClass('active').next('ul.options').hide();
        });
        $(this).toggleClass('active').next('ul.options').toggle();
    });

    // Hides the unordered list when a list item is clicked and updates the styled div to show the selected list item
    // Updates the select element to have the value of the equivalent option
    $listItems.click(function (e) {
        e.stopPropagation();
        $styledSelect.text($(this).text()).removeClass('active');
        $this.val($(this).attr('rel'));
        $list.hide();
        //alert($this.val());
    });

    // Hides the unordered list when clicking outside of it
    $(document).click(function () {
        $styledSelect.removeClass('active');
        $list.hide();
    });

});

$(document).ready(function () {
    $('select.selectric').selectric();
    $('select.selectric.url-selector').change(function () { location = this.options[this.selectedIndex].value; });
    $('.selectric-location-selector li:eq(0)').css("font-weight", "normal");
    $('.selectric-location-selector .sl-label').html("<i class='icon fi-marker'></i>" + $('.selectric-location-selector .sl-label').html());
    //check the options in the language selector
    //deselect all first
    $.each($(".language-selector option"), function () {
        
        var url = $(this).val();
        $(this).prop("selected", false);

        var searchValue = url.toLowerCase();

        var result = url.match(/es-ES(.*)/i);
        if (result != null)
        {
            searchValue = "es-es.";
        }
        result = url.match(/es-MX(.*)/i);
        if (result != null) {
            searchValue = "es-mx.";
        }
        result = url.match(/es-MX(.*)/i);
        if (result != null) {
            searchValue = "es-mx.";
        }
        result = url.match(/zh-CN(.*)/i);
        if (result != null) {
            searchValue = "chn.";
        }
        result = url.match(/ko-KR(.*)/i);
        if (result != null) {
            searchValue = "kor.";
        }
        result = url.match(/ilc-US(.*)/i);
        if (result != null) {
            searchValue = "ilc.";
        }
        result = url.match(/vi-VN(.*)/i);
        if (result != null) {
            searchValue = "vit.";
        }
        result = url.match(/chk-US(.*)/i);
        if (result != null) {
            searchValue = "chk.";
        }
        result = url.match(/tgl-US(.*)/i);
        if (result != null) {
            searchValue = "tag.";
        }


        var currentPath = location.href.toLowerCase();
        if (currentPath.toLowerCase().indexOf(searchValue.toLowerCase()) != -1 || currentPath == searchValue)
        {
            $(this).prop("selected", true);
        }

    });

    $(".language-selector").selectric("refresh");
});


/* Responsive Tables */
$(document).ready(function () {
    var switched = false;
    var updateTables = function () {
        if (($(window).width() < 767) && !switched) {
            switched = true;
            $("table.responsive").each(function (i, element) {
                splitTable($(element));
            });
            return true;
        }
        else if (switched && ($(window).width() > 767)) {
            switched = false;
            $("table.responsive").each(function (i, element) {
                unsplitTable($(element));
            });
        }
    };

    $(window).load(updateTables);
    $(window).on("redraw", function () { switched = false; updateTables(); }); // An event to listen for
    $(window).on("resize", updateTables);


    function splitTable(original) {
        original.wrap("<div class='table-wrapper' />");

        var copy = original.clone();
        copy.find("td:not(:first-child), th:not(:first-child)").css("display", "none");
        copy.removeClass("responsive");

        original.closest(".table-wrapper").append(copy);
        copy.wrap("<div class='pinned' />");
        original.wrap("<div class='scrollable' />");

        setCellHeights(original, copy);
    }

    function unsplitTable(original) {
        original.closest(".table-wrapper").find(".pinned").remove();
        original.unwrap();
        original.unwrap();
    }

    function setCellHeights(original, copy) {
        var tr = original.find('tr'),
            tr_copy = copy.find('tr'),
            heights = [];

        tr.each(function (index) {
            var self = $(this),
                tx = self.find('th, td');

            tx.each(function () {
                var height = $(this).outerHeight(true);
                heights[index] = heights[index] || 0;
                if (height > heights[index]) heights[index] = height;
            });

        });

        tr_copy.each(function (index) {
            $(this).height(heights[index]);
        });
    }

});

(function ($) {
    $(document).ready(function () {

        $('.sidebar-nav li.active').addClass('open').children('ul').show();
        $('.sidebar-nav li.has-sub').on('click', function () {
            var element = $(this);
            
            if (element.hasClass('open')) {
                element.removeClass('open');
                element.find('li').removeClass('open');
                element.find('ul').slideUp(200);
            }
            else {
                element.addClass('open');
                element.children('ul').slideDown(200);
                element.siblings('li').children('ul').slideUp(200);
                element.siblings('li').removeClass('open');
                element.siblings('li').find('li').removeClass('open');
                element.siblings('li').find('ul').slideUp(200);
            }
        });
    });
})(jQuery);

printScreen = function () {
    window.print();
}

printPDF = function () {
    var url = '/app/PrintingView/GeneratePDFForms';

    var json = JSON.stringify(getPDFQuestions());

    if (json != "[]") {
        $.ajax({
            type: "POST",
            url: window.location.protocol + "//" + window.location.host + url,
            data: json,
            dataType: "json",
            contentType: 'application/json; charset=utf-8',
            traditional: true,
            statusCode: {
                200: function (result) {
                    var url = '/app/PrintingView/DownloadPDF?id=' + result.responseText;
                    window.location = url;
                },
                500: function (error) {
                    //alert(error);
                }
            },
        });
    }
    else {
        alert("The form is empty.");
    }
}

function getPDFQuestions() {

    var anwser = "";
    var questions = [];

    $('.anwser').each(function () {
        anwser = "";
        var isChecked = false; 
        switch ($(this).attr('data-type')) {
            case "FormTextBoxProxy":
                $(this).find(':input').each(function () {
                    if ($(this).val() != '') {
                        anwser = $(this).val();
                    }
                });
                break;
            case "FormCheckboxProxy":
                $(this).find(':input').each(function () {
                    
                    if ($(this).is(':checked')) {
                        anwser = ": True";
                    }
                    else
                        anwser = ": False";

                    question = { QuestionText:  $(this).attr('data-anwser'), AnswerText: anwser };
                    questions.push(question);

                });
                isChecked = true;
                break;
            case "FormDropdownListProxy":
                var element = $(this).find(":Selected");
                if (element.val() != "") {
                    anwser = element.text();
                }
                break;
            case "FormRadioButtonProxy":
                $(this).find(':input').each(function () {
                    if ($(this).is(':checked')) {
                        anwser = $(this).attr('data-anwser');
                    }
                });
                break;
        }
        if (!isChecked) {
            var qu = '';
            if ($(this).attr('data-question') != undefined)
                qu = $(this).attr('data-question');

            question = { QuestionText: qu , AnswerText: anwser };
            questions.push(question);
        }
        
    });
    return questions;
}


$(document).ready(function () {
    adjustHeroSize();
    $(window).resize(function () {
        adjustHeroSize();
    });
});

function adjustHeroSize()
{
    // fit the width of absolutely positioned containers to parent
    var divWidth = $('.page-hero > row').width();
    $('.page-hero .abs-pos').css({ 'width': divWidth });
}





function changeImageToVideo(e, youtubeVideo) {

    if (!e)
        e = window.event;
    var sender = e.srcElement || e.target;

    var $container = $(sender).closest(".video");
    var url = "https://www.youtube.com/embed/" + youtubeVideo + "?autoplay=1&autohide=1&modestbranding=1&showinfo=0";
    $container.empty().append("<div class='custom-flex-video-class' style=\"width: 100%; height: 100%\"><embed width=\"100%\" height=\"100%\" src=\"" + url + "\"></div>");
    $(document).foundation();
}
 
(function ($) {
    var $container = $('.news-events .container'),
		colWidth = function () {
		    var columnWidth = 100;
		    if (Foundation.utils.is_large_up()) {
		        columnWidth = 31.2;
		    } else
		        if (Foundation.utils.is_medium_up()) {
		            columnWidth = 45.2;
		        } 

		    $container.find('.item').each(function () {
		        var $item = $(this);

		        $item.css({
		            width: columnWidth + "%",
		        });
		    });
		    return columnWidth;
		},
		isotope = function () {

		    $container.fadeIn().isotope({
		        resizable: false,
		        itemSelector: '.item',
		        masonry: {
		            columnWidth: colWidth(),
		            gutterWidth: 16
		        }
		    });
		    $(".news-events .preloader").hide();
		};

    $container.imagesLoaded(function () { isotope(); });

    $(window).resize(isotope);
}(jQuery));
var loginModule = angular.module('WellcareNextGenLoginModule', ['ngCookies']);


loginModule.controller('LoginController', ['$scope', '$http', '$location', '$timeout', '$filter', 'loginService', '$cookies','$timeout',
    function ($scope, $http, $location, $timeout, $filter, loginService, $cookies, $timeout) {

        $scope.loadCookie = function () {
            var cookie = $cookies.getObject("LoginOptionsCookie");

            if (cookie == undefined || cookie === '' || cookie.length == 0) {
                return null;
            }

            return cookie;
        }

        var cookie = $scope.loadCookie();
        var loadCookie = true; 
        $("#userSelect").on('change', function () {
            loginService.getConfItems($(this).val())
                    .then(function (data) {
                        if (typeof data === 'object') {
                            try {

                                if (data.listItems != null && data.listItems.length > 0) {
                                    $scope.states = data.listItems;
                                    $scope.plans = [];
                                    $scope.loginBtnUrl = null;
                                    $scope.registrtionBtnUrl = null;

                                    $timeout(function () {
                                        $scope.$apply();
                                        if (cookie != null && loadCookie) {
                                            $("#stateSelect").val(cookie.state).selectric('refresh');
                                            $("#stateSelect").trigger("change");
                                        }
                                    });

                                   
                                        
                                    
                                }
                                else {
                                    $scope.states = [];
                                    $scope.plans = [];
                                    if (data.cfgItem != null) {
                                        $scope.loginBtnUrl = data.cfgItem.Login_Url.Url;
                                        $scope.registrtionBtnUrl = data.cfgItem.Registration_Url.Url;
                                    }
                                }
                            }
                            catch (e) {
                                $scope.loginBtnUrl = null;
                                $scope.registrtionBtnUrl = null;
                                $scope.states = [];
                                $scope.plans = [];
                            }
                        }
                    }, function (data) {
                        $scope.loginBtnUrl = null;
                        $scope.registrtionBtnUrl = null;
                        $scope.states = [];
                        $scope.plans = []
                        console.log("LoginController.js Error:");
                        console.log(data.Message);
                        console.log(data.ExceptionMessage);
                        deferred.reject();
                    });
        });

        if (cookie != null) {
            $("#userSelect").val(cookie.user).selectric('refresh');
            $("#userSelect").trigger("change");
        }
            
        $scope.$watch('states', function () {
            $timeout(function () {
                if (!$scope.states || $scope.states.length <= 0) {
                    $("#stateSelect").attr("disabled", "disabled").selectric('refresh');
                }
                else {
                    $("#stateSelect").removeAttr("disabled").selectric('refresh');
                }
                if (!$scope.plans || $scope.plans.length <= 0) {
                    $("#planSelect").attr("disabled", "disabled").selectric('refresh');
                }
                else {
                    $("#planSelect").removeAttr("disabled").selectric('refresh');
                }
            }, 200);
        });

        $("#stateSelect").on('change', function () {
            loginService.getConfItems($(this).val())
                    .then(function (data) {
                        if (typeof data === 'object') {
                            try {
                                if (data.listItems != null && data.listItems.length > 0) {
                                    $scope.plans = data.listItems;
                                    $scope.loginBtnUrl = null;
                                    $scope.registrtionBtnUrl = null;

                                    $timeout(function () {
                                        $scope.$apply();
                                        if (cookie != null && loadCookie) {
                                            loadCookie = false;
                                            $("#planSelect").val(cookie.plan).selectric('refresh');
                                            $("#planSelect").trigger("change");
                                        }
                                    });
                                   
                                }
                                else {
                                    $scope.plans = [];
                                    if (data.cfgItem != null) {
                                        $scope.loginBtnUrl = data.cfgItem.Login_Url.Url;
                                        $scope.registrtionBtnUrl = data.cfgItem.Registration_Url.Url;
                                    }
                                }
                            }
                            catch (e) {
                                $scope.loginBtnUrl = null;
                                $scope.registrtionBtnUrl = null;
                                $scope.plans = [];
                            }
                        }
                    }, function (data) {
                        $scope.loginBtnUrl = null;
                        $scope.registrtionBtnUrl = null;
                        $scope.plans = [];
                        console.log("LoginController.js Error:");
                        console.log(data.Message);
                        console.log(data.ExceptionMessage);
                        deferred.reject();
                    });
        });

        $scope.$watch('plans', function () {
            $timeout(function () {
                if (!$scope.plans || $scope.plans.length <= 0) {
                    $("#planSelect").attr("disabled", "disabled").selectric('refresh');
                }
                else {
                    $("#planSelect").removeAttr("disabled").selectric('refresh');
                }
            }, 200);
        });

        $("#planSelect").on('change', function () {
            if ($(this).val() != 0) {
                loginService.getConfItems($(this).val())
                        .then(function (data) {
                            if (typeof data === 'object') {
                                try {
                                    $scope.loginBtnUrl = data.cfgItem.Login_Url.Url;
                                    $scope.registrtionBtnUrl = data.cfgItem.Registration_Url.Url;
                                    //Store in cookie
                                    var user = $("#userSelect").val();
                                    var state = $("#stateSelect").val();
                                    var plan = $("#planSelect").val();
                                    
                                    $scope.createCookie(user, state, plan);
                                }
                                catch (e) {
                                    $scope.loginBtnUrl = null;
                                    $scope.registrtionBtnUrl = null;
                                }
                            }
                        }, function (data) {
                            $scope.loginBtnUrl = null;
                            $scope.registrtionBtnUrl = null;
                            console.log("LoginController.js Error:");
                            console.log(data.Message);
                            console.log(data.ExceptionMessage);
                            deferred.reject();
                        });
            }
            else {
                $scope.loginBtnUrl = null;
                $scope.registrtionBtnUrl = null;
            }
        });

        $scope.createCookie = function (user, state, plan) {
            var today = new Date();
            var ninety = new Date(today);
            ninety.setDate(today.getDate() + 90);

            $cookies.putObject("LoginOptionsCookie", {user: user,state: state,plan: plan}, {
                expires: ninety,
                path: '/',
            });
        }
}]);

loginModule.service('loginService', ['$http', '$filter', '$q', '$location', function ($http, $filter, $q, $location) {
    
    this.getConfItems = function (guid) {

        var url = "https://" + $location.host() + '/api/Login/GetCfgItems/';
        var input = { 'Guid': guid }

        return $http.post(url, JSON.stringify(input))
            .then(
            function (response) {
                if (typeof response.data === 'object') {
                    try {
                        var res = response.data;
                        return res;
                    }
                    catch (e)
                    { return {};}
                } else {
                    // invalid response
                    return $q.reject(response.data);
                }
            },
            function (response) {
                // something went wrong
                return $q.reject(response.data);
            });

    }

}]);
