﻿// Javascript files for SSE Monitor
// Date Created 28th May 2008
// Created by Suzanne McCulley
// Updated 18th June 2008


$( function() {

    //Jscript for the Print link on Application Thank You
     var thankYouMess = $(".thankYouMess") 
     if (thankYouMess.length) {
       $('<p class="printPageLnk"><a href="#">Print this page for your records</a></p>').appendTo(thankYouMess);
       $('.thankYouMess .printPageLnk a').click(function (){   
            window.print();
       }); 
     }
 
    //Jscript for the FAQ's Page
    if ( $(".freqAskedQ").length) {  
    $(".freqAskedQ .questionList,.questionList .question .answer")
        .hide();
    
    $(".freqAskedQ .mainArea").each( function() {
        $(this).html('<a href="#">' + $(this).text() + '</a>');
    });
 
    $(".questionList .question span").each( function() {
        $(this).html('<a href="#">' + $(this).html() + '</a>');
    });    
       
    $(".freqAskedQ .mainArea a,.questionList .question span a").click(function (){
        if( $(this).parent(".mainArea").length )
            $(this).toggleClass("expand");
        
        $(this).parent().next().slideToggle();
        return false;
      });
    }
  
    //Jscript for the Monitor Solutions Popup
    var installInstruc = $(".installInstr") 
    
    if (installInstruc.length) {
  //  $(installInstruc).css("display","none");
  //  $(".popup").css("display","none");
      var popup = $('<div class="popup"></div><div class="popupBox"><div class="inner"><div class="content"></div></div></div>').css("display","none");
      
      popup.filter(".popup").css("opacity","0.5").click( function(){popup.fadeOut()});
      installInstruc
        .before('<span class="install"><a href="#">Find out how to install the system here</a></span>')
        .prev()
        .find("a").click(function (){
         popup.fadeIn().eq(0).height( document.body.scrollHeight );
         popup.get(1).style.top = (getScrollXY()[1] + 40 ) + "px";
         $(window).bind( "scroll" , function(){
            popup.eq(1).stop().animate({top: getScrollXY()[1] + 40} , 500 );
         });
         return false;
        })
        .end();
        
       installInstruc.find("h2").after('<span class="button"><a href="#">Close</a></span>')
        .next()
        .find("a").click(function (){
         popup.fadeOut();
         $(window).unbind("scroll");
         return false;
        });
        
       popup.find(".content").append(installInstruc);
       $("body").append( popup );
             
       }
    
    //Jscript for toggling Accessory Description
    var accessoryHold = $(".purProcess .accessories .accessoryHold");
    $(".accessory .desc")
        .hide()
        .after('<p class="toggleProduct"><a href="#nogo">Show details</a></p>')
        
        .next().find("a").click(function (){
            $(this).parent().prev().toggle();
            if ($(this).text()=="Show details"){
                $(this).text("Hide details")
            }
            else{$(this).text("Show details")} 
        });
        
        var productID = location.href.match(/#.+$/);
        if (productID)
        {
            $(productID[0]).find(".toggleProduct a").click();
            
        }
   
   
    //Jscript to generate Optional Accessories Links (open & close)

     var accessoryID = location.href.match(/#editAcc$/);
     if (!accessoryID)
     {
        accessoryHold
        .hide()
        .before('<p class="viewAccessories"><a href="#purchase">View and purchase additional accessories with your plan.</a></p>')  
        .prev().find("a").click(function (){
            accessoryHold.slideDown();
            $(this).parent().hide();
            $("#closeAccessories").show();
        })
    
        $(".accessories")
            .after('<p id="closeAccessories" class="closeAccessories"><a href="#nogo">Close accessories panel</a></p>')
            .next()
            .hide()
            .find("a")
            .click(function (){
                accessoryHold
                    .hide()
                    .prev()
                    .show();
                $(this).parent().hide();
            })
        
    }
       

    //Jscript for the Security Code Popup
    
    var securityCode = $(".securityCodeInfo");
    if (securityCode.length) {
     
    var secpopup = $('<div class="popup"></div><div class="secpopupBox"><div class="inner"><div class="content"></div></div></div>').hide();
      secpopup.filter(".popup").css("opacity","0.5").click( function(){secpopup.fadeOut()});
      securityCode
        .prev()
        .append('<p><a href="#">What is this?</a></p>')
        .find("a").click(function (){
         secpopup.fadeIn().eq(0).height( document.body.scrollHeight );
         secpopup.get(1).style.top = (getScrollXY()[1] + 40 ) + "px";
         $(window).bind( "scroll" , function(){
            secpopup.eq(1).stop().animate({top: getScrollXY()[1] + 40} , 500 );
         });
         return false;
        })
        .end();
        
       securityCode.find("h2").after('<span class="button"><a href="#">Close</a></span>')
        .next()
        .find("a").click(function (){
         secpopup.fadeOut();
         $(window).unbind("scroll");
         return false;
        });
        
       secpopup.find(".content").append(securityCode);
       $("body").append( secpopup );
       
             
       }
       
       
       
       //Javacript for show hide 'Where did you hear about us?*'
       /* var formItem = $(".frmAboutUs .lrgFormItem");
        if (formItem.length)
        {
            formItem.hide()

            $(".frmAboutUs select").change( function() {
                if( $(this).val() == 'Other' ) formItem.show();
                else formItem.hide();
             });
            
            
        }*/

      
        

    });
    
    
    
    
    //Jscript to generate window height (this is used with Monitor Solutions Popup)
    function getWindowSize() {
      var myWidth = 0, myHeight = 0;
      if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
      } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
      } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
      }
      return [ myWidth , myHeight ];
    }

    function getScrollXY() {
      var scrOfX = 0, scrOfY = 0;
      if( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
      } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
      } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
      }
      return [ scrOfX, scrOfY ];
    }
