var ValassisOnline = function(options) { var self = this; self.options = options; /* * 0 = Proof Your Ad * 1 = Crossbow * 2 = Buy a List * 3 = Cross Sells * 4 = Profile Viewer */ var SectionDenied = { 0: '', 1: 'To request access to this service, please contact your Valassis Sales Representative.', 2: '', 3: 'To request access to this service, please contact your Valassis Sales Representative.', 4: 'To request access to this service, please contact your Valassis Sales Representative.' } var SectionClick = { 0: true, 1: hasCrossbowAccess, 2: true, 3: hasCrossSellsAccess, 4: hasProfileViewerAccess }; var showAlert = false; var alertMessage = ''; var showTips = false; var tip = ''; self.displayContent = function (index) { $('#applications-tabs-pages .article').each(function(i,e){ if(i == index) { $(this).show(); } else{ $(this).hide(); } }); } self.logout = function(e) { e.preventDefault(); // Put logout function here $('#login-success').fadeOut("fast", function(){ $('#alert').hide(); $('#alert').empty(); $('#tips').hide(); $('#tips').empty(); $('#spotlight-container').fadeIn("fast"); $('#login').fadeIn("fast"); $('#applications-container').css('margin-top', ''); document.getElementById('pv').style.display='none'; //$('#applications-tabs ul li').last().hide(); }); userAuthenticated = false; self.remember('load'); document.getElementById('password').value = ""; $.cookies.set("OAM_ID", null); //window.location="https://valvcsoam001vm.val.vlss.local:14101/oam/server/logout?end_url=http://pilot.valassisonline.com/portal/home.jsp"; } self.overlay = function (e) { if(!userAuthenticated) { e.preventDefault(); $('#overlay').show(); $('#login').css('z-index','10'); $('#login').css('position','relative'); $('#UserId').focus(); } } self.redirectUser = function (e) { var index = $(this).index(); if(userAuthenticated && hasPortalAccess) { if(SectionClick[index]) { window.location = self.options.SectionLink[index]; } else { if(SectionDenied[index] != '') { alert(SectionDenied[index]); } } } else { if(index==2) window.location = self.options.SectionLink[index]; else self.displayContent(index); //self.overlay(); } } self.showAlert = function (alertMessage) { $('#alert').append(alertMessage); $('#alert').show(); } self.showContent = function(e) { if(!userAuthenticated && hasPortalAccess){ var index = $(this).index(); self.displayContent(index); } } self.showTips = function (tip) { $('#tips').append(tip); $('#tips').show(); } self.submitLogin = function (e) { e.preventDefault(); $('#username').parent().removeClass('error'); $('#password').parent().removeClass('error'); if($.trim($('#username').val()) == '' || $.trim($('#password').val())=='') { if($.trim($('#username').val()) == '' ) { $('#username').parent().addClass('error'); } if($.trim($('#password').val())=='') { $('#password').parent().addClass('error'); } } else { $('#overlay').hide(); //Remember me self.remember('set'); doSSOLogin(); if(userAuthenticated == false){ $('#login-failure').show(); } if(userAuthenticated == true) { $('#login-failure').hide(); if(isInternal) { $('#changePassword').hide(); } else { $('#changePassword').show(); } self.getMessages(); $('#username-display').text(userName); if(hasProfileViewerAccess) document.getElementById('pv').style.display='block'; $('#login').fadeOut("fast", function(){ $('#spotlight-container').fadeOut("fast"); $('#login-success').fadeIn("fast"); $('#applications-container').css('margin-top', '70px'); if($('#tips').is(':visible') || $('#alert').is(':visible')) { $('#applications-container').css('margin-top', '20px'); } //alert("terms is "+needterms); //needterms=false; if(needterms) { self.termsAndConditionsModal($('#termsandconditionsModal')); $( "#termsandconditionsModal" ).dialog( "option", "position", "center" ); } }); if(!needterms){ SectionClick[1] = hasCrossbowAccess; SectionClick[3] = hasCrossSellsAccess; SectionClick[4] = hasProfileViewerAccess; //alert("hasProfileViewerAccess"+hasProfileViewerAccess); if(hasProfileViewerAccess) { $('#applications-tabs ul li').last().show(); document.getElementById('pv').style.display='block'; } } } } } self.termsAndConditionsModal = function (modalWindow) { $('body').scrollTop(0); $(modalWindow).dialog('open'); setTimeout(function(){ $(modalWindow).parent().offset({top:40}); },300); return false; } self.getMessages = function () { $.ajax({ cache: false, url: 'portalMessages', type: "POST", dataType: "xml", success: function(xml){ if (xml != null) { self.getAlertMessages(xml); self.getTipMessages(xml); } } }); } self.getAlertMessages = function (message) { var alertmsg = getMessage(message, 'A'); if(alertmsg!=null && $.trim(alertmsg)!=''){ self.showAlert(alertmsg); } } self.getTipMessages = function (message) { var tipmsg = getMessage(message, 'T'); if(tipmsg!=null && $.trim(tipmsg)!=''){ self.showTips(tipmsg); } } self.remember = function(action){ var cookiename="portaluser"; var uid = $.trim($('#username').val()); if(action=='load'){ var cookieval = $.cookies.get(cookiename); if (cookieval!=null){ $('#username').val(cookieval); $('input[name=RememberMe]').attr('checked',true); } }else if(action=='set'){ if($('input[name=RememberMe]').attr('checked')){ expiry = new Date(); expiry.setTime(expiry.getTime()+(365*60*1000)); //$.cookies.set(cookiename, $.trim($('#username').val()),20*365); document.cookie=cookiename+"="+uid+";expires="+ expiry.toGMTString(); }else { var d = new Date(); document.cookie = cookiename+"=1;expires=" + d.toGMTString() + ";" + ";"; } } } self.wireUp = function(options) { if(options != null) { self.options = options; } self.remember('load'); $('#applications-tabs ul li').on('click', self.redirectUser); $('#applications-tabs ul li').on('hover', self.showContent); //$('.login a').on('click', self.overlay); $('#login-submit').on('click', self.submitLogin); $('#logout-submit').on('click', self.logout); $('[data-type=terms]').on('click', function(e){ e.preventDefault(); self.termsAndConditionsModal('#termsandconditionsModal') }); $('#overlay').on('click', function(e){ $('#overlay').hide(); }); $('.nav li').hover(function(){ $(this).find('.nav2').show(); }, function(){ $(this).find('.nav2').hide(); }); $('#termsandconditionsModal').dialog({ autoOpen: false, resizeable: false, title: 'Terms and Conditions', modal: true, maxHeight: 400, minWidth: 600, maxWidth: 600, position: 'center', show: 'fade', open: function () { var self = $(this); self.css({'max-height': 400, 'overflow-y': 'auto'}) var view = 'termsandconditions.html'; //var view = 'terms.html'; self.load(view); if(userAuthenticated) { self.parent().find('button:contains("Close")').hide(); self.parent().find('button:contains("Agree")').show(); self.parent().find('button:contains("Cancel")').show(); } else { self.parent().find('button:contains("Agree")').hide(); self.parent().find('button:contains("Cancel")').hide(); self.parent().find('button:contains("Close")').show(); } }, buttons: { "Agree": function() { /*Put ajax call here to update status in database */ fnAcceptTerms(); $( this ).dialog( "close" ); }, Cancel: function() { $( this ).dialog( "close" ); }, Close: function() { $(this).dialog("close"); } } }); } }