﻿/////////////////// JCAROUSEL LITE PLUGIN ///////////////////////
(function($) { $.fn.jCarouselLite = function(o) { o = $.extend({ btnPrev: null, btnNext: null, btnGo: null, mouseWheel: false, auto: null, speed: 200, easing: null, vertical: false, circular: true, visible: 3, start: 0, scroll: 1, beforeStart: null, afterEnd: null }, o || {}); return this.each(function() { var b = false, animCss = o.vertical ? "top" : "left", sizeCss = o.vertical ? "height" : "width"; var c = $(this), ul = $("ul", c), tLi = $("li", ul), tl = tLi.size(), v = o.visible; if (o.circular) { ul.prepend(tLi.slice(tl - v - 1 + 1).clone()).append(tLi.slice(0, v).clone()); o.start += v } var f = $("li", ul), itemLength = f.size(), curr = o.start; c.css("visibility", "visible"); f.css({ overflow: "hidden", float: o.vertical ? "none" : "left" }); ul.css({ margin: "0", padding: "0", position: "relative", "list-style-type": "none", "z-index": "1" }); c.css({ overflow: "hidden", position: "relative", "z-index": "2", left: "0px" }); var g = o.vertical ? height(f) : width(f); var h = g * itemLength; var j = g * v; f.css({ width: f.width(), height: f.height() }); ul.css(sizeCss, h + "px").css(animCss, -(curr * g)); c.css(sizeCss, j + "px"); if (o.btnPrev) $(o.btnPrev).click(function() { return go(curr - o.scroll) }); if (o.btnNext) $(o.btnNext).click(function() { return go(curr + o.scroll) }); if (o.btnGo) $.each(o.btnGo, function(i, a) { $(a).click(function() { return go(o.circular ? o.visible + i : i) }) }); if (o.mouseWheel && c.mousewheel) c.mousewheel(function(e, d) { return d > 0 ? go(curr - o.scroll) : go(curr + o.scroll) }); if (o.auto) setInterval(function() { go(curr + o.scroll) }, o.auto + o.speed); function vis() { return f.slice(curr).slice(0, v) }; function go(a) { if (!b) { if (o.beforeStart) o.beforeStart.call(this, vis()); if (o.circular) { if (a <= o.start - v - 1) { ul.css(animCss, -((itemLength - (v * 2)) * g) + "px"); curr = a == o.start - v - 1 ? itemLength - (v * 2) - 1 : itemLength - (v * 2) - o.scroll } else if (a >= itemLength - v + 1) { ul.css(animCss, -((v) * g) + "px"); curr = a == itemLength - v + 1 ? v + 1 : v + o.scroll } else curr = a } else { if (a < 0 || a > itemLength - v) return; else curr = a } b = true; ul.animate(animCss == "left" ? { left: -(curr * g)} : { top: -(curr * g) }, o.speed, o.easing, function() { if (o.afterEnd) o.afterEnd.call(this, vis()); b = false }); if (!o.circular) { $(o.btnPrev + "," + o.btnNext).removeClass("disabled"); $((curr - o.scroll < 0 && o.btnPrev) || (curr + o.scroll > itemLength - v && o.btnNext) || []).addClass("disabled") } } return false } }) }; function css(a, b) { return parseInt($.css(a[0], b)) || 0 }; function width(a) { return a[0].offsetWidth + css(a, 'marginLeft') + css(a, 'marginRight') }; function height(a) { return a[0].offsetHeight + css(a, 'marginTop') + css(a, 'marginBottom') } })(jQuery);

/////////////////////////////////////////////////////////////////
/////////////////////// PAGE LOAD EVENTS ////////////////////////
/////////////////////////////////////////////////////////////////

function pageLoad()
{   
    var isAsyncPostback = Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack();
    if (isAsyncPostback) 
    {
        tb_init('a.thickbox, area.thickbox, input.thickbox');
        initalizePage() 
    }
}

///////////// INSTATE ALL jQUERY EVENTS AND VARIABLES/////////
function initalizePage()
{
    
       ////////////////////// ENABLE TERMS OF USE SIDING /////////////////////////
 
      $("#termsOfUsePanelContainer").hide();
      
      $(".termsOfUseLink").click(function() 
        {
            $("#termsOfUsePanelContainer").slideToggle("slow");
            return false;
        });
       

       ////////////////////// ENABLE "[more]"('What Is Risk Management') SIDING /////////////////////////
        $("#introduction").hide();

        $("#introductionLink").click(function() {
            $("#introduction").slideToggle("slow");
            return false;
        });
       
        $("#howDoesInsuranceWorkMore").hide();
        
        $("#howDoesInsuranceWorkMoreLink").click(function() {
             $("#howDoesInsuranceWorkMore").slideToggle("slow");
             return false;
         });


         $("#factorsAffectingPremiums").hide();

         $("#factorsAffectingPremiumsLink").click(function() {
         $("#factorsAffectingPremiums").slideToggle("slow");
             return false;
         });

         $("#whatIsRiskManagement").hide();

         $("#whatIsRiskManagementLink").click(function() {
         $("#whatIsRiskManagement").slideToggle("slow");
             return false;
         });

         $("#riskManagementProcess").hide();

         $("#riskManagementProcessLink").click(function() {
         $("#riskManagementProcess").slideToggle("slow");
             return false;
         });

         //steps to implement risk management

         $("#riskIdentification").hide();

         $("#riskIdentificationLink").click(function() {
         $("#riskIdentification").slideToggle();
             return false;
         });

         $("#quantifyPrioritize").hide();

         $("#quantifyPrioritizeLink").click(function() {
         $("#quantifyPrioritize").slideToggle();
             return false;
         });

         $("#riskSensitive").hide();

         $("#riskSensitiveLink").click(function() {
         $("#riskSensitive").slideToggle();
             return false;
         });

         $("#businessDecisions").hide();

         $("#businessDecisionsLink").click(function() {
         $("#businessDecisions").slideToggle();
             return false;
         });
         
         
         //Risk Management Tips
          $("#quickTip1").hide();

          $("#quickTip1Link").click(function() {
          $("#quickTip1").slideToggle("slow");
             return false;
         });

         $("#quickTip2").hide();

         $("#quickTip2Link").click(function() {
             $("#quickTip2").slideToggle("slow");
             return false;
         });


         $("#quickTip3").hide();

         $("#quickTip3Link").click(function() {
             $("#quickTip3").slideToggle("slow");
             return false;
         });
         

         $("#quickTip4").hide();

         $("#quickTip4Link").click(function() {
             $("#quickTip4").slideToggle("slow");
             return false;
         });

         $("#quickTip5").hide();

         $("#quickTip5Link").click(function() {
             $("#quickTip5").slideToggle("slow");
             return false;
         });

         $("#quickTip6").hide();

         $("#quickTip6Link").click(function() {
             $("#quickTip6").slideToggle("slow");
             return false;
         });

         $("#quickTip7").hide();

         $("#quickTip7Link").click(function() {
             $("#quickTip7").slideToggle("slow");
             return false;
         });

         $("#quickTip8").hide();

         $("#quickTip8Link").click(function() {
             $("#quickTip8").slideToggle("slow");
             return false;
         });

         $("#quickTip9").hide();

         $("#quickTip9Link").click(function() {
             $("#quickTip9").slideToggle("slow");
             return false;
         });

         $("#quickTip10").hide();

         $("#quickTip10Link").click(function() {
             $("#quickTip10").slideToggle("slow");
             return false;
         });

         $("#quickTip11").hide();

         $("#quickTip11Link").click(function() {
             $("#quickTip11").slideToggle("slow");
             return false;
         });

         $("#quickTip12").hide();

         $("#quickTip12Link").click(function() {
             $("#quickTip12").slideToggle("slow");
             return false;
         });

////////////////////// PROFILE PAGE SAVE BUTTON /////////////////////////
         $("#saveButtonPanel").hide();


         $("#ProfilePage input").keyup(function() {
             toggleSave();
         })

         function toggleSave() {
             $("#saveButtonPanel").slideDown("slow");
         }
         
////////////////////// CHANGE PASSWORD JS VALIDATION /////////////////////////

    var changePassword1 = "";
    var changePassword2 = "";
    $("#changePasswordErrorMessageBlock").hide();
    
    $(".changePasswordErrorMessageBlock").hide();

    $(".changePasswordInput1").blur(function() {
        changePassword1 = $(this).val();
        changePasswordValidate();
    })

    $(".changePasswordInput2").blur(function() {
        changePassword2 = $(this).val();
        changePasswordValidate();
    })

    function changePasswordValidate() 
    {
        if ((changePassword1 != "") && (changePassword2 != "")) 
        {
            if (changePassword1 == changePassword2) 
            {
                if ( (changePassword1.length > 5) && (changePassword1.length < 26) )
                {
                    toggleErrorPanel(false, "Passwords Match, Good Stuff");
                }
                else 
                {
                    toggleErrorPanel(true, "Passwords must be between 6 and 25 characters.");
                }
            }
            else 
            {
                toggleErrorPanel(true, "Passwords do not match.");
            }
         
        }
    };
    
    function toggleErrorPanel( showErrorPanel, errorMessage) 
    {
        if(!showErrorPanel)
        {
            $("#changePasswordErrorMessageBlock").slideUp("slow");
            $(".changePasswordButton").removeAttr("disabled");
        } 
        else {
        
            $(".errorLabel")[0].innerHTML = errorMessage;
            $("#changePasswordErrorMessageBlock").slideDown("slow");
            $(".changePasswordButton").attr("disabled", "disabled");
        }
    };



    function checkCapsLock(e) {
        var myKeyCode = 0;
        var myShiftKey = false;
        var myMsg = 'Caps Lock is On.\n\nTo prevent entering your password incorrectly,\nyou should press Caps Lock to turn it off.';

        // Internet Explorer 4+
        if (document.all) {
            myKeyCode = e.keyCode;
            myShiftKey = e.shiftKey;

            // Netscape 4
        } else if (document.layers) {
            myKeyCode = e.which;
            myShiftKey = (myKeyCode == 16) ? true : false;

            // Netscape 6
        } else if (document.getElementById) {
            myKeyCode = e.which;
            myShiftKey = (myKeyCode == 16) ? true : false;

        }

        // Upper case letters are seen without depressing the Shift key, therefore Caps Lock is on
        if ((myKeyCode >= 65 && myKeyCode <= 90) && !myShiftKey) {
            alert(myMsg);

            // Lower case letters are seen while depressing the Shift key, therefore Caps Lock is on
        } else if ((myKeyCode >= 97 && myKeyCode <= 122) && myShiftKey) {
            alert(myMsg);

        }
    }
    
 ////////////////////// SIGN UP JS VALIDATION /////////////////////////

      $(".errorMessageBlock").hide();
      $("#passwordInvalidLength").hide();
      var username = $(".userNameBox").val();
      var email = $(".emailBox").val();
      var password1 = $(".passwordInput1").val();
      var password2 = $(".passwordInput2").val();
      var button = $(".submitButton");
      var checkBox = ($(".agreeToTermsChkBox").is(':checked'));
      var industry = $(".industryList");
      var passwordsOk = false;
      var emailIsGood = false;
      var userNameIsGood = false;
      
      $(".submitButton").attr("disabled", "disabled");

      function validatePassword() 
      {
          if ((password2 != "") && (password1 != "")) {
              if ((password1.length > 5) && (password1.length < 26)) {
                  $("#passwordInvalidLength").slideUp("slow");

                  if (password1 == password2) 
                  {
                      passwordsOk = true;
                  }
                  else 
                  {
                      passwordsOk = false;
                  }
              }
              else 
              {
                  passwordsOk = false;
                  $("#passwordInvalidLength").slideDown("slow");
              }
          }
          else {
              passwordsOk = false;
          }
         
      };

      function checkUserName() 
      {
        var username = $(".userNameBox").val();

        var match = /^([a-zA-Z0-9_\-]){3,25}$/.test(username);
        if ((username != "") && match) 
        {
            userNameIsGood = true;
            $(".usernameErrorLabel").slideUp("slow");
        }
        else if (username.length > 3 && !match) {

            $(".usernameErrorLabel").slideDown("slow");
            userNameIsGood = false;
        }
        else {
            $(".usernameErrorLabel").slideDown("slow");
            userNameIsGood = false;
        }
      }

      function checkEmail() 
      {
          var email = $(".emailBox").val();
          var match = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+[a-zA-Z0-9]{2,4}$/.test(email);
          if (match) 
          {
              return true;
          }
          else 
          {
              return false;
          }
      };

      function toggleButton() {
        emailIsGood = checkEmail();
        validatePassword();
        checkUserName();
        if (checkBox && userNameIsGood && passwordsOk && emailIsGood)
        {  
            $(".submitButton").removeAttr("disabled");  
        }
        else 
        { 
            $(".submitButton").attr("disabled", "disabled"); 
        }
      }

      $(".agreeToTermsChkBox").click(function() {
          checkBox = $(this).is(':checked');
          toggleButton();
      });
    
    ////////////////////// Validation Controls /////////////////////////

      $(".emailBox").keyup(function() {
          email = $(this).val();
          toggleButton();
      })

      $(".userNameBox").keyup(function() {
          username = $(this).val();
          toggleButton();
      })

      $(".passwordInput1").keyup(function() {
          password1 = $(this).val();
          toggleButton();
      })

      $(".passwordInput2").keyup(function() {
          password2 = $(this).val();
          toggleButton();
      })  
        
        $(".userNameBox").blur(function () {
            username = $(this).val();
            $(this).toggleClass("highlight");
            toggleButton();
        })

        $(".emailBox").blur(function() {
            email = $(this).val();
            $(this).toggleClass("highlight");
            toggleButton();
        })

        $(".passwordInput1").blur(function () {
            password1 = $(this).val();
            $(this).toggleClass("highlight");
            toggleButton();
        })

        $(".passwordInput2").blur(function () {
            password2 = $(this).val();
            $(this).toggleClass("highlight");
            toggleButton();
        })

        $(".agreeToTermsChkBox").blur(function() {
            checkBox = $(this).is(':checked');
            toggleButton();
        });
        
        
    ////////////////////// GLOW FEATURE /////////////////////////   
        $(".userNameBox").focus(function () {
          $(".userNameBox").toggleClass("highlight");
        })
    
        $(".emailBox").focus(function () {
            $(".emailBox").toggleClass("highlight");
        })
    
        $(".passwordInput1").focus(function () {
            $(".passwordInput1").toggleClass("highlight");
        })
        
         $(".passwordInput2").focus(function () {
            $(".passwordInput2").toggleClass("highlight");
        })   
               
        $(".agreeToTermsChkBox input[type=checkbox]").focus(function () {
            $(this).toggleClass("highlight");
        })
        
        $(".promoBox").focus(function () {
            $(this).toggleClass("highlight");
        })

        ///////////////////////////////////////////////////////
        //////////////////E-BOOK PAGE//////////////////////////
        ///////////////////////////////////////////////////////
        $(".submitEmailButton").load(function() {
        var match = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+[a-zA-Z0-9]{2,4}$/.test($(".emailBoxEbook").val());
            if (match) {
                $(".submitEmailButton").removeAttr("disabled");
            }
            else {
                $(".submitEmailButton").attr("disabled", "disabled");
            }
        })

        $(".ebookError").hide();


        $(".emailBoxEbook").keyup(function() {
            var match = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+[a-zA-Z0-9]{2,4}$/.test($(this).val());
            if (match) {
                $(".submitEmailButton").removeAttr("disabled");
            }
            else {
                $(".submitEmailButton").attr("disabled", "disabled");
            }
        });

        $(".emailBoxEbook").blur(function() 
        {
            var match = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+[a-zA-Z0-9]{2,4}$/.test($(this).val());
            if (match) {
                $(".ebookError").slideUp("slow");
            }
            else {
                $(".ebookError").slideDown("slow");
            }
        });
         
    };


    $(function() {

        initalizePage()

        //////////////// INITIALIZE JCAROUSEL LITE //////////////////
        $("#carousel").jCarouselLite({
            auto: 7000,
            speed: 500,
            btnNext: ".carouselNextImage",
            btnPrev: ".carouselPrevImage",
            visible: 1
        });

        /////////////////////////// FAQ /////////////////////////////
        $("#faq>blockquote").hide();
        $(".answer_section").hide();
        $(".answer_section>blockquote").hide();
        
        $("#faq p a").click(function() {
            $(this).parent().parent().next().slideToggle();
            return false;
        });

        $("#openfaq").click(function() {
        //$("#faq>blockquote").slideDown();
         $(".answer_section>blockquote").slideDown();
            $("#faq>div").slideDown();
            
            return false;
        });

        $("#closefaq").click(function() {
        //$("#faq>blockquote").slideUp();
        //$("#faq>div").slideUp();
        $(".answer_section>blockquote").slideUp();
        $("#faq>div").slideUp();
            
       
            return false;
        });


        $(".question_section").click(function() {
            $(this).parent().next().slideToggle();
            return false;
        });

    });


//////////////////Toggle more/less /////////////////////////
function toggleMoreLess(elemId) {
    var link = document.getElementById(elemId);
   
    if (link.innerHTML.indexOf("more") != -1 )
        link.innerHTML = "[less]"
    else  
        link.innerHTML = "[more]";
    
}
    
