Guest User

Untitled

a guest
Oct 27th, 2016
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var j = jQuery.noConflict();
  2. j(document).ready(function($) {
  3.  
  4.     /*if($('.form-item-commerce-coupon-coupon-code').length){
  5.         $('#edit-continue').prop('disabled',false);
  6.  
  7.         $('#edit-continue').click(function(event)
  8.         {
  9.             // alert('True');
  10.     event.preventDefault();
  11.     event.stopImmediatePropagation();
  12.         $('#edit-continue').prop('disabled',false);
  13.          $('#commerce-checkout-form-checkout').submit();  
  14.         });
  15.     }*/
  16.  
  17.     if(j('a#dd-link').length > 0)
  18.     {
  19.         window.open(j('a#dd-link').attr('href'),'_blank');
  20.         j('a#dd-link').hide();
  21.         console.log('Foo 21');
  22.     }
  23.    
  24.  
  25.     /////////////////////////////////////////////////////////////////////////////////////////////////////////
  26.     // Globals:
  27.     /////////////////////////////////////////////////////////////////////////////////////////////////////////
  28.  
  29.     var g_colors = ["#0077be", "#96ca50", "#eb2d90", "#00a59a", "#00b6f0", "#f9a456", "#1ab157", "#682d8e", "#ef4937", "#dcd534"];
  30.     var speed = 150;
  31.     var x = 0;
  32.  
  33.     /////////////////////////////////////////////////////////////////////////////////////////////////////////
  34.     // Checkout
  35.     /////////////////////////////////////////////////////////////////////////////////////////////////////////
  36.  
  37.     $("#commerce-checkout-form-checkout").wrap('<div class="box triple tight"></div>');
  38.     if($(".page-cart").length || $(".page-checkout").length) {
  39.         $("#block-system-main > .content").prepend('<div class="box triple tight collapse"><h1 style="color:#ef4937;" class="page_title">Shopping Cart</h1></div>');
  40.     }
  41.     //for the checkout review page need to add in the giftaid message
  42.     if($(".form-item-terms-conditions-commerce-agree-terms-pane-field").length){
  43.         //check each line item - if membership or renewal not there then hide the gift id stuff
  44.         $(".views-field-line-item-title").each(function(){
  45.             if($('.views-field-line-item-title:contains("Membership -")').length > 0 || $('.views-field-line-item-title:contains("membership")').length > 0 || $('.views-field-line-item-title:contains("Account balance")').length > 0){
  46.                 current_dec = $('.form-item-terms-conditions-commerce-agree-terms-pane-field label').html();
  47.                 $('.form-item-terms-conditions-commerce-agree-terms-pane-field label').html('I agree to IIRSM claiming Gift Aid on my subscription until I notify you otherwise. I confirm that I am a UK tax payer and have paid Income Tax and/or Capital Gains Tax at least equal to the tax that IIRSM are allowed to reclaim on my subscriptions (maximum of 4 years). I have paid these personally on all subscriptions from the date of this declaration until I notify you otherwise. I confirm that I have not claimed tax relief on my subscriptions and I do not plan to claim tax relief on my IIRSM subscriptions. I understand that if I pay less Income Tax and/or Capital Gains Tax than the amount of Gift Aid claimed on all my Membership subscription in that tax year it is my responsibility to pay any difference. <a target="_blank" href="http://sandbox.r-evolution.co.uk/iirsm/node/518">Find out more about Gift Aid</a>');
  48.                 $('.form-item-terms-conditions-commerce-agree-terms-pane-field input').prop('checked', true);
  49.                 $('.form-item-terms-conditions-commerce-agree-terms-pane-field input').removeClass('required');
  50.             }
  51.             else{
  52.                 $('#edit-terms-conditions').css("display", "none");
  53.                 $('.form-item-terms-conditions-commerce-agree-terms-pane-field input').prop('checked', false);
  54.                 $('.form-item-terms-conditions-commerce-agree-terms-pane-field input').removeClass('required');
  55.             }
  56.         });
  57.  
  58.     }
  59.  
  60.     /////////////////////////////////////////////////////////////////////////////////////////////////////////
  61.     // Password Reset:
  62.     /////////////////////////////////////////////////////////////////////////////////////////////////////////
  63.  
  64.     if($(".page-user-password").length) {
  65.  
  66.         $(".page-user-password #user-pass h1").html("Password Reset");
  67.         $(".page-user-password #user-pass #edit-submit").val("RESET MY PASSWORD");
  68.     }
  69.  
  70.     /////////////////////////////////////////////////////////////////////////////////////////////////////////
  71.     // Checkout Login
  72.     /////////////////////////////////////////////////////////////////////////////////////////////////////////
  73.  
  74.     if($(".page-user-login").length){
  75.         $(".messages").css("display","none");
  76.         if($(".page-user-login").length && $(".messages").text().indexOf("You need to be logged in to be able to checkout.") >= 0) {
  77.             $("#user-login").addClass("checkout-login");
  78.             $(".messages").html("Please choose a checkout option:");
  79.             $("#user_login_form h1").html("I have an account and want to login");
  80.             $(".messages").css("display","block");
  81.             var new_applicant = '<div class="new_applicant_checkout" style="min-height:65px;"><h2 class="new-member-login checkout-tick-off" style="cursor:pointer;">I am a new applicant</h2><div style="display:none;" class="form-actions"><input type="submit" id="edit-continue-button" name="continue_button" value="Checkout without an account" class="form-submit-new"></div></div>';
  82.             var no_account = '<div class="no_account_checkout" style="min-height:150px;"><h2 class="new-member-login checkout-tick-off" style="cursor:pointer;">I want to checkout without an account</h2><div class="form-actions"></div></div>';
  83.             $(new_applicant).insertBefore('#user_login_form');
  84.             $(no_account).insertAfter('#user_login_form');
  85.             $("#edit-continue-button.form-submit").appendTo('.no_account_checkout .form-actions');
  86.             $("#edit-continue-button.form-submit").css("display","none");
  87.             $("#user_login_form div, #user_login_form a").css("display","none");
  88.             $("#user_login_form h1").css({"font-weight":"500","font-size":"32px","line-height":"40px","cursor":"pointer"});
  89.             $("#user_login_form h1").addClass("checkout-tick-off");
  90.             //submit handler
  91.             $(".new-member-login").on("click", function() {
  92.                 if($(this).hasClass("checkout-tick-off")){
  93.                     $(this).removeClass("checkout-tick-off");
  94.                     $(this).addClass("checkout-tick-on");
  95.                 }
  96.                 else if($(this).hasClass("checkout-tick-on")){
  97.                     $(this).removeClass("checkout-tick-on");
  98.                     $(this).addClass("checkout-tick-off");
  99.                 }
  100.                 $("#edit-continue-button").trigger("click");
  101.             });
  102.             $("#user_login_form h1").on("click", function() {
  103.                 if($(this).hasClass("checkout-tick-off")){
  104.                     $(this).removeClass("checkout-tick-off");
  105.                     $(this).addClass("checkout-tick-on");
  106.                 }
  107.                 else if($(this).hasClass("checkout-tick-on")){
  108.                     $(this).removeClass("checkout-tick-on");
  109.                     $(this).addClass("checkout-tick-off");
  110.                 }
  111.                 $("#user_login_form div, #user_login_form a").css("display","block");
  112.             });
  113.  
  114.         }
  115.         $(".messages").css("display","block");
  116.     }
  117.  
  118.     if($(".page-user.not-logged-in").length){
  119.         $(".form-item-name .description").html("Enter your IIRSM username. This is your preferred email address.");
  120.     }
  121.  
  122.     /////////////////////////////////////////////////////////////////////////////////////////////////////////
  123.     // Menus:
  124.     /////////////////////////////////////////////////////////////////////////////////////////////////////////
  125.  
  126.     // Third level menu feed markup:
  127.     if($("#block-menu-block-3").length) {
  128.  
  129.         $("#block-menu-block-3").insertAfter(".stream_3");
  130.         $("#block-menu-block-3 .menu li").wrap('<div class="box single"></div>');
  131.         setItemColors($("#block-menu-block-3 .menu .box"));
  132.         $("#block-menu-block-3 .active-trail").parents(".box").addClass("active_box");
  133.     }
  134.  
  135.     if($("body").hasClass("front")) {
  136.         setItemColors($("#right_col .box.single"));
  137.     } else {
  138.         setItemColors($("#right_col .menu-block-1 ul li"));
  139.     }
  140.  
  141.     // Add data attribute with numbering:
  142.     $("#superfish-1 > li").each(function(i) { $(this).attr("data-item-number", (i+1)); });
  143.  
  144.     // Fix position of dropdown:
  145.     var dropdown_pos_y = "";
  146.     $("#superfish-1 > li").hover(function() {
  147.         dropdown_pos_y = $(this).attr("data-item-number") <= 6 ? "65px" : "135px";
  148.         $(this).children("ul").css("top", dropdown_pos_y);
  149.     }, function() {
  150.         $(this).children("ul").hide();
  151.     });
  152.  
  153.     // Add coloured squares to footer menu:
  154.     var block_color = 0;
  155.     $(".region-footer .menu li").each(function() {
  156.         block_color % 10 == 0 ? block_color = 1 : block_color++;
  157.         $(this).addClass("bullet_" + block_color);
  158.     });
  159.  
  160.     $('#main_header .header_right .header_ecommerce.responsive span img').click(function() {
  161.         $('#main_header .header_right .header_ecommerce.responsive ul').slideToggle(250);
  162.     });
  163.  
  164.     $('.mobile_menu_show').click(function() {
  165.         $('#mobile_menu_wrapper').slideToggle(250);
  166.     });
  167.  
  168.     // Split menu links into two columns:
  169.     $(".menu_quick_link").each(function() {
  170.  
  171.         var quick_link = $(this);
  172.         var menu_parent = $(this).attr("data-parent");
  173.  
  174.         $("#superfish-1 > .sf-depth-1").each(function() {
  175.  
  176.             var menu_tab_name = $(this).children("a").clone().children().remove().end().text();
  177.  
  178.             if(menu_parent == menu_tab_name) {
  179.                 $(this).children("ul").length
  180.                 ? quick_link.appendTo($(this).children("ul"))
  181.                 : quick_link.hide();
  182.             }
  183.  
  184.         });
  185.  
  186.     });
  187.  
  188.     /////////////////////////////////////////////////////////////////////////////////////////////////////////
  189.     // Application Popups
  190.     /////////////////////////////////////////////////////////////////////////////////////////////////////////
  191.     //if the popups are on the page then work with them
  192.     if($("#block-block-1").length && $(".create_profile_step_2").length < 1 && $(".create_profile_step_3").length < 1) {
  193.         console.log("Before you start block is there");
  194.         //it is on the page so hide the application block & qual block until ok is clicked
  195.         $(".members-apply").css("display","none");
  196.         $("#block-views-99d2546dc6a0c7c17cd018d92760232e").css("display","none");
  197.         $("#block-block-1 .dismiss-button").click(function(){
  198.             $("#block-block-1").css("display","none");
  199.             $("#block-views-99d2546dc6a0c7c17cd018d92760232e").css("display","block");
  200.             $(".page-node-135 #left_col").css("overflow","visible");
  201.             console.log("dismiss button clicked");
  202.         });
  203.         $(document).on("click", "#block-views-99d2546dc6a0c7c17cd018d92760232e .dismiss-button", function(){
  204.             console.log("qual box closed")
  205.             $("#block-views-99d2546dc6a0c7c17cd018d92760232e").css("display","none");
  206.             $("#block-block-1").css("display","none");
  207.             $(".members-apply").css("display","block");
  208.         });        
  209.     }
  210.     else if($(".create_profile_step_2").length || $(".create_profile_step_3").length){
  211.         $("#block-block-1").css("display","none");
  212.         $("#block-views-99d2546dc6a0c7c17cd018d92760232e").css("display","none");
  213.     }
  214.     else{
  215.         console.log("No before you start block");
  216.     }
  217.  
  218.  
  219.     /////////////////////////////////////////////////////////////////////////////////////////////////////////
  220.     // Colouring:
  221.     /////////////////////////////////////////////////////////////////////////////////////////////////////////
  222.  
  223.     function setItemColors(items) {
  224.         var color_pos = 0;
  225.         var color_max = g_colors.length - 1;
  226.         items.each(function() {
  227.             $(this).css("background-color", g_colors[color_pos]);
  228.             if(color_pos < color_max) {
  229.                 color_pos++;
  230.             } else {
  231.                 color_pos = 0;
  232.             }
  233.         });
  234.     }
  235.  
  236.     // Colour side menu:
  237.  
  238.     function rgb2hex(rgb) {
  239.         if(rgb.search("rgb") == -1) {
  240.             return rgb;
  241.         } else {
  242.             rgb = rgb.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+))?\)$/);
  243.             function hex(x) {
  244.                 return ("0" + parseInt(x).toString(16)).slice(-2);
  245.             }
  246.             return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
  247.         }
  248.     }
  249.  
  250.     if($("#left_col .box.triple.intro").length) {
  251.         var page_color = rgb2hex($("#left_col .box.triple.intro").css("background-color"));
  252.         $("#block-menu-block-1 .menu > li > a").css("background-color", page_color);
  253.     }
  254.  
  255.     // Colour the external links section
  256.     if($(".field-name-field-external-links").length) {
  257.         var page_color = rgb2hex($("#left_col .box.triple.intro").css("background-color"));
  258.         $(".field-name-field-external-links .field-item").css("background-color", page_color);
  259.     }
  260.  
  261.     // Colour the gallery section
  262.     if($(".field-name-field-linked-gallery").length) {
  263.         var page_color = rgb2hex($("#left_col .box.triple.intro").css("background-color"));
  264.         $(".related_galleries .field-name-field-linked-gallery a").css("background-color", page_color);
  265.     }
  266.  
  267.     if($("#left_col .node-webform").length) {
  268.         var page_color = "#682d8e";
  269.         $("#block-menu-block-1 .menu > li > a").css("background-color", page_color);
  270.     }
  271.  
  272.     // Colour file boxes:
  273.     if($(".file_download_box").length) {
  274.         setItemColors($(".file_download_box"));
  275.     }
  276.  
  277.     // Colour related_link_box:
  278.     if($(".related_link_box").length) {
  279.         setItemColors($(".related_link_box"));
  280.     }
  281.  
  282.     // Colour main menu dropdowns:
  283.     $("#superfish-1 ul, #superfish-1 .menu_quick_link").each(function() {
  284.         $(this).css("background-color", $(this).closest(".sf-depth-1").css("background-color"));
  285.     });
  286.  
  287.     // Colour callouts:
  288.     $(".bottom_callout").each(function() {
  289.         $(this).css("background-color", $(this).attr("data-color"));
  290.     });
  291.  
  292.     // Colour callouts:
  293.     $("#block-views-related-links-home-block a").each(function() {
  294.         $(this).css("background-color", $(this).attr("data-color"));
  295.     });
  296.  
  297.     // Colour secondary titles in body text:
  298.     if($("#left_col .box.triple.intro").length) {
  299.         page_color = rgb2hex($("#left_col .box.triple.intro").css("background-color"));
  300.         $("#left_col .field-name-body h2").css("color", page_color);
  301.     }
  302.  
  303.  
  304.  
  305.     /////////////////////////////////////////////////////////////////////////////////////////////////////////
  306.     // Section Title in Coloured Box:
  307.     /////////////////////////////////////////////////////////////////////////////////////////////////////////
  308.  
  309.     // Basic pages:
  310.     if($("body").hasClass("node-type-page-basic")) {
  311.         var section_title = $("#superfish-1 > .active-trail > .menuparent").clone().children().remove().end().text();
  312.         //console.log(section_title);
  313.         if(section_title == ''){
  314.             $(".box.triple.intro").hide();
  315.         }
  316.         else{
  317.             $(".box.triple.intro").append('<h2>' + section_title + '</h2>');
  318.         }
  319.     }
  320.  
  321.     // Commerce pages:
  322.     if($("body").hasClass("node-type-publication")
  323.     || $("body").hasClass("node-type-merchandise")
  324.     || $("body").hasClass("node-type-publication-digital")) {
  325.         $(".box.triple.intro").append('<h2>Products & publications</h2>');
  326.         $(".box.triple.blank h2").css("color", "#ef4937");
  327.         $(".box.double.blank h4").css("color", "#ef4937");
  328.         $("#block-sharethis-sharethis-block").appendTo(".title_box");
  329.     }
  330.  
  331.     // News pages:
  332.     if($("body").hasClass("node-type-news-article")) {
  333.         $(".page_title").css("color", "#f9a456");
  334.     }
  335.  
  336.     /////////////////////////////////////////////////////////////////////////////////////////////////////////
  337.     // Breadcrumbs / ShareThis:
  338.     /////////////////////////////////////////////////////////////////////////////////////////////////////////
  339.  
  340.     // Move breadcrumbs:
  341.     if($("#block-crumbs-breadcrumb").length) {
  342.         $("#block-crumbs-breadcrumb").insertAfter("#main_content .box.triple.intro");
  343.     }
  344.  
  345.     //change breadcrumbs for events & courses
  346.     if($(".node-type-event").length){
  347.         $("<a href='http://www.iirsm.org/node/43'> » Events </a>").insertAfter(".breadcrumb a");
  348.     }
  349.     if($(".node-type-course").length){
  350.         $("<a href='http://www.iirsm.orgcourses'> » Courses </a>").insertAfter(".breadcrumb a");
  351.     }
  352.     if($(".node-type-news").length){
  353.         $("<a href='http://www.iirsm.org/news'> » News </a>").insertAfter(".breadcrumb a");
  354.     }
  355.     if($(".node-type-publication").length){
  356.         $("<a href='http://www.iirsm.org/products-publications'> » Products & Publications </a>").insertAfter(".breadcrumb a");
  357.     }
  358.  
  359.     // Move ShareThis:
  360.     if($("#block-sharethis-sharethis-block").length) {
  361.         if($(".article_date").length) {
  362.             $("#block-sharethis-sharethis-block").insertAfter(".article_date");
  363.         } else {
  364.             $("#block-sharethis-sharethis-block").insertAfter(".page_title");
  365.         }
  366.  
  367.     }
  368.  
  369.     /////////////////////////////////////////////////////////////////////////////////////////////////////////
  370.     // Masonry:
  371.     /////////////////////////////////////////////////////////////////////////////////////////////////////////
  372.  
  373.     if($(".field-name-field-external-links").length) {
  374.  
  375.         // Markup and cleanup:
  376.         $(".field-name-field-external-links > .field-items > .field-item").each(function() {
  377.  
  378.             var markup = '<div class="stream_item">' +
  379.                 '<a href="' + $(this).find("a").attr("href") + '" target="_blank">' +
  380.                     '<h3>' + $(this).find(".field-name-field-link-title").text() + '</h3>' +
  381.                     '<img src="' + $(this).find(".field-name-field-downloads-thumbnail img").attr("src") + '">' +
  382.                 '</a>' +
  383.             '</div>';
  384.  
  385.             $(this).closest(".block-views").append(markup);
  386.  
  387.         });
  388.  
  389.         $(".field-name-field-external-links").remove();
  390.     }
  391.  
  392.  
  393.     if($(".stream_item").length) {
  394.  
  395.         // Move filters to side column:
  396.         $(".view-filters").insertBefore("#right_col .soc_med");
  397.  
  398.         // Hack to make boxes work (from manual template code):
  399.         if($(".download_files_container").length) {
  400.  
  401.             if(!$(".region-feed").length) { $("#left_col").append('<div class="region-feed"></div>'); }
  402.             $(".download_files_container").appendTo(".region-feed");
  403.         }
  404.  
  405.         // Hack to make boxes work (from field collection):
  406.         if($(".external_links").length) {
  407.  
  408.             if(!$(".region-feed").length) { $("#left_col").append('<div class="region-feed"></div>'); }
  409.             $(".external_links").appendTo(".region-feed");
  410.         }
  411.  
  412.         // Find number of streams to make on page:
  413.         var streams = $(".stream_item").closest(".block-views").length;
  414.  
  415.         // Add streams and their columns:
  416.         for(var stream_id = 1; stream_id <= streams; stream_id++) {
  417.             var stream_col_id = 1;
  418.             for(var i = 0; i < 3; i++) {
  419.                 $(".region-feed").prepend('<div class="box single tight stream stream_' + stream_id + ' stream_col_' + stream_col_id + '"></div>');
  420.                 stream_col_id++;
  421.                 console.log('Foo: '+stream_col_id);
  422.             }
  423.         }
  424.  
  425.         function buildMasonryFeed() {
  426.  
  427.             // Clear streams:
  428.             $(".stream").find(".stream_item").remove();
  429.             $("#left_col .view-filters").remove();
  430.  
  431.             // Image handler:
  432.             jQuery.fn.extend({
  433.                 ensureLoad: function(handler) {
  434.                     return this.each(function() {
  435.                         if(this.complete) {
  436.                             handler.call(this);
  437.                         } else {
  438.                             $(this).load(handler);
  439.                         }
  440.                     });
  441.                 }
  442.             });
  443.  
  444.             // Check that all images are loaded (for height reliance):
  445.  
  446.             // if($(".region-feed").find('img').length) {
  447.  
  448.             //     if($(".stream_item").length) {
  449.  
  450.             //         var loadedImages = 0;
  451.             //         $('.region-feed img').ensureLoad(function() {
  452.             //             loadedImages++;
  453.             //             //console.log(loadedImages+' = '+$(".region-feed").find('img').length)
  454.             //             if(loadedImages == $(".region-feed").find('img').length
  455.             //             || $(".region-feed").find("img").length == 0) {
  456.             //                 sortStreamItems();
  457.             //             }
  458.             //             else{// dirty dirty hack
  459.             //                 sortStreamItems();
  460.             //             }
  461.             //         });
  462.             //     }
  463.             // }
  464.             // else {
  465.             //     // No images in feed, start sorting:
  466.             //     sortStreamItems();
  467.             // }
  468.  
  469.             sortStreamItems();
  470.         }
  471.  
  472.         buildMasonryFeed();
  473.  
  474.         // Add filters title:
  475.         $(".views-exposed-form").prepend('<h2>Show results for</h2>');
  476.  
  477.         $(document).ajaxComplete(function() {
  478.  
  479.             buildMasonryFeed();
  480.  
  481.         });
  482.     }
  483.  
  484.     function sortStreamItems() {
  485.  
  486.         // Add stream items into correct columns:
  487.         $(".region-feed .block-views").each(function(i) {
  488.  
  489.             var target_stream = ".stream_" + (i+1);
  490.             var stream_title = $(this).children("h2");
  491.             $(stream_title).addClass("stream_title").insertBefore(target_stream + ".stream_col_3");
  492.  
  493.             $(this).find(".stream_item").each(function() {
  494.  
  495.                 var target = "";
  496.                 var shortest = 99999;
  497.                 var item_height = $(this).height();
  498.  
  499.                 $(target_stream).each(function() {
  500.  
  501.                     var height = $(this).height();
  502.                     if(height < shortest) {
  503.                         shortest = height;
  504.                         target = $(this);
  505.                     }
  506.  
  507.                 });
  508.  
  509.                 $(this).appendTo(target);
  510.  
  511.            });
  512.  
  513.         });
  514.  
  515.         // Prepare and display:
  516.         setItemColors($(".stream_item"));
  517.         $("#block-views-blog-masonry-filter-block, .region-feed").hide().fadeIn(300);
  518.     }
  519.  
  520.     //GALLERY BOXES
  521.  
  522.     if($(".image_gallery_wrapper").length) {
  523.  
  524.         $(".image_gallery_wrapper .field-item").addClass("box single blank");
  525.     }
  526.  
  527.     /////////////////////////////////////////////////////////////////////////////////////////////////////////
  528.     // Maps
  529.     /////////////////////////////////////////////////////////////////////////////////////////////////////////
  530.  
  531.     if($(".page-node-186").length
  532.     || $(".page-node-267").length) {
  533.  
  534.         var branch_map_data = [
  535.             // UK Branches:
  536.             { "nid" : 188, "x" : 425, "y" : 475 },
  537.             { "nid" : 246, "x" : 255, "y" : 575 },
  538.             { "nid" : 247, "x" : 320, "y" : 565 },
  539.             { "nid" : 248, "x" : 370, "y" : 460 },
  540.             { "nid" : 249, "x" : 430, "y" : 500 },
  541.             { "nid" : 250, "x" : 330, "y" : 505 },
  542.             { "nid" : 251, "x" : 225, "y" : 115 },
  543.             { "nid" : 252, "x" : 365, "y" : 570 },
  544.             { "nid" : 255, "x" : 455, "y" : 450 },
  545.             { "nid" : 625, "x" : 310, "y" : 376 }, //north west england
  546.             { "nid" : 187, "x" : 305, "y" : 145 },
  547.             { "nid" : 256, "x" : 310, "y" : 325 },
  548.             { "nid" : 257, "x" : 375, "y" : 470 },
  549.             { "nid" : 259, "x" : 385, "y" : 490 },
  550.             { "nid" : 258, "x" : 145, "y" : 320 },
  551.             { "nid" : 253, "x" : 435, "y" : 545 }, //south east england
  552.             { "nid" : 260, "x" : 460, "y" : 470 },
  553.             { "nid" : 261, "x" : 372, "y" : 555 }, //south england
  554.             { "nid" : 262, "x" : 275, "y" : 470 },
  555.             { "nid" : 254, "x" : 405, "y" : 520 },
  556.             { "nid" : 263, "x" : 235, "y" : 165 },
  557.             { "nid" : 264, "x" : 355, "y" : 360 },
  558.             { "nid" : 624, "x" : 327, "y" : 321 }, //nortern england
  559.             { "nid" : 625, "x" : 285, "y" : 235 },
  560.             { "nid" : 692, "x" : 350, "y" : 459 }, //west midlands
  561.             { "nid" : 691, "x" : 278, "y" : 433 }, //north wales
  562.             { "nid" : 693, "x" : 379, "y" : 516 }, //thames valley
  563.             // International Branches:
  564.             { "nid" : 268, "x" : 435, "y" : 190 },
  565.             { "nid" : 269, "x" : 393, "y" : 200 },
  566.             { "nid" : 270, "x" : 322, "y" : 250 }
  567.         ];
  568.  
  569.         function updateLocation(branch) {
  570.             var branch_nid = parseInt(branch.find(".views-field-nid").text());
  571.             for(var i = 0; i < branch_map_data.length; i++) {
  572.                 if(branch_nid == branch_map_data[i].nid) {
  573.                     speed = $("#location_point").text() == "" ? 0 : 150;
  574.                     $("#location_point").show().animate({
  575.                         "left" : branch_map_data[i].x + "px",
  576.                         "top" : branch_map_data[i].y + "px",
  577.                     }, speed);
  578.                     var name = branch.find(".views-field-title").text();
  579.                     $("#location_name").fadeOut(speed/2, function() {
  580.                         $(this).text(name).fadeIn(speed/2);
  581.                         // Scotland style exception:
  582.                         $(this).css("left", branch_nid == 187 ? "-180px" : "-140px");
  583.                     });
  584.                 }
  585.             }
  586.             $(".selected_branch").hide();
  587.             $(".selected_branch[data-nid='" + branch_nid + "']").show();
  588.         }
  589.  
  590.         // Update location when a branch is clicked:
  591.         $("#block-views-branches-list-uk-block .views-row").on("click", function() { updateLocation($(this)); });
  592.         $("#block-views-branch-list-international-block .views-row").on("click", function() { updateLocation($(this)); });
  593.     }
  594.  
  595.     // Move branch chair members:
  596.     if($(".node-type-branch-page").length) {
  597.         $("#block-views-branch-committee-block").appendTo(".committee_box");
  598.     }
  599.  
  600.  
  601.     /////////////////////////////////////////////////////////////////////////////////////////////////////////
  602.     // Search bar:
  603.     /////////////////////////////////////////////////////////////////////////////////////////////////////////
  604.  
  605.     $("#menu-1541-1").on("click", function(e) {
  606.         e.preventDefault();
  607.         var sb = "#block-views-exp-search-results-page";
  608.         $(sb).animate({"top" : ($(sb).css("top") == "0px" ? "-60px" : "-0px")}, speed);
  609.         $('#edit-keys').focus();
  610.     });
  611.  
  612.  
  613.     /////////////////////////////////////////////////////////////////////////////////////////////////////////
  614.     // Page tabs:
  615.     /////////////////////////////////////////////////////////////////////////////////////////////////////////
  616.  
  617.     if($(".field-name-field-tab").length && !$("body").hasClass("node-type-event") && !$("body").hasClass("node-type-course")) {
  618.  
  619.         // Setting up tabs:
  620.         $(".field-name-field-tab > .field-items > .field-item").each(function(i) {
  621.  
  622.             // Add selectors:
  623.             $(this).addClass("info_tab info_tab_" + (i+1));
  624.             $(this).find(".field-name-field-tab-title").addClass("tab_name tab_name_" + (i+1));
  625.  
  626.             // Convert hex colors to classe names:
  627.             var tab_color = $(this).find(".field-name-field-page-colour").text();
  628.             switch(tab_color) {
  629.                 case "#0077be": tab_color = "blue"; break;
  630.                 case "#00b6f0": tab_color = "sky"; break;
  631.                 case "#00a59a": tab_color = "teal"; break;
  632.                 case "#f9a456": tab_color = "orange"; break;
  633.                 case "#1ab157": tab_color = "green"; break;
  634.                 case "#96ca50": tab_color = "lime"; break;
  635.                 case "#ef4937": tab_color = "red"; break;
  636.                 case "#682d8e": tab_color = "purple"; break;
  637.                 case "#eb2d90": tab_color = "pink"; break;
  638.                 case "#dcd534": tab_color = "yellow"; break;
  639.             }
  640.  
  641.             // Set color classes:
  642.             $(this).find(".tab_name").addClass(tab_color).attr("data-color", tab_color).attr("data-tab", (i+1));
  643.             if(tab_color) $(this).addClass(tab_color + "_light").attr("data-color", tab_color + "_light");
  644.  
  645.         });
  646.  
  647.         // Add tab list item toggles:
  648.         $(".field-name-field-tab-list-item-title").each(function() {
  649.             $(this).append('<div class="toggle_icon">+</div>');
  650.         }).on("click", function() {
  651.             $(this).next(".field-name-field-tab-list-item-body-wysiwyg").slideToggle(300);
  652.             $(this).find(".toggle_icon").text($(this).find(".toggle_icon").text() == "+" ? "-" : "+");
  653.         });
  654.         $(".info_tab").each(function() {
  655.              $(this).find(".toggle_icon").css("background-color", $(this).find(".field-name-field-page-colour").text());
  656.         });
  657.  
  658.         // Move tab names to tab_names container:
  659.         $(".tab_name").appendTo(".tab_names");
  660.  
  661.         // Make the first tab active:
  662.         var tab_1_color = $(".tab_name_1").attr("data-color");
  663.         $(".info_tab").hide();
  664.         $(".info_tab_1").show();
  665.         $(".tab_name_1").toggleClass(tab_1_color + " " + tab_1_color + "_light").attr("data-color", tab_1_color + "_light");
  666.  
  667.         // Switch tabs:
  668.         $(".tab_name").on("click", function() {
  669.  
  670.             var tab_selected = $(this);
  671.  
  672.             // Remove light tint from all tabs:
  673.             $(".tab_name").each(function() {
  674.                 var tab_color = $(this).attr("data-color");
  675.                 $(this).removeClass(tab_color);
  676.                 if(tab_color.indexOf("_light") >= 0) tab_color = tab_color.replace("_light", "");
  677.                 $(this).addClass(tab_color).attr("data-color", tab_color);
  678.             });
  679.  
  680.             // Add light tint to clicked tab:
  681.             var tab_color = tab_selected.attr("data-color");
  682.             tab_selected.removeClass(tab_color);
  683.             tab_color += "_light";
  684.             tab_selected.addClass(tab_color).attr("data-color", tab_color);
  685.  
  686.             // Close all toggles:
  687.             $(".field-name-field-tab-list-item-body-wysiwyg").hide();
  688.             $(".toggle_icon").text("+");
  689.  
  690.             // Show new tab's content:
  691.             var tab_to_show = $(this).attr("data-tab");
  692.             $(".info_tab").hide();
  693.             $(".info_tab_" + tab_to_show).show();
  694.  
  695.         });
  696.  
  697.         $("#tabs_box").show();
  698.     }
  699.  
  700.     if($("body").hasClass("node-type-event") || $("body").hasClass("node-type-course")) {
  701.  
  702.         $("#tabs_box").show();
  703.         $(".info_tab").hide();
  704.         $(".info_tab_1").show();
  705.  
  706.         // Switch tabs:
  707.         $(".tab_name").on("click", function() {
  708.  
  709.             var tab_selected = $(this);
  710.  
  711.             // Remove light tint from all tabs:
  712.             $(".tab_name").each(function() {
  713.                 var tab_color = $(this).attr("data-color");
  714.                 $(this).removeClass(tab_color);
  715.                 if(tab_color.indexOf("_light") >= 0) tab_color = tab_color.replace("_light", "");
  716.                 $(this).addClass(tab_color).attr("data-color", tab_color);
  717.             });
  718.  
  719.             // Add light tint to clicked tab:
  720.             var tab_color = tab_selected.attr("data-color");
  721.             tab_selected.removeClass(tab_color);
  722.             tab_color += "_light";
  723.             tab_selected.addClass(tab_color).attr("data-color", tab_color);
  724.  
  725.             // Close all toggles:
  726.             $(".field-name-field-tab-list-item-body-wysiwyg").hide();
  727.             $(".toggle_icon").text("+");
  728.  
  729.             // Show new tab's content:
  730.             var tab_to_show = $(this).attr("data-tab");
  731.             $(".info_tab").hide();
  732.             $(".info_tab_" + tab_to_show).show();
  733.  
  734.         });
  735.     }
  736.  
  737.     // Table style in tabs:
  738.     if($(".info_tab").length) {
  739.  
  740.         $(".info_tab_5 .field-name-field-tab-segment > .field-items > .field-item").each(function(i) {
  741.             $(this).addClass("segment_" + (i+1))
  742.         });
  743.         $("table").each(function() {
  744.             $(this).find("tr").each(function(i) {
  745.                 $(this).addClass("row_" + (i+1));
  746.                 $(this).find("td").each(function(i) {
  747.                     $(this).addClass("cell_" + (i+1));
  748.                 });
  749.             });
  750.         });
  751.     }
  752.  
  753.     // Gallery Lightbox
  754.  
  755.     function verticalAlign(target) {
  756.  
  757.         target.each(function() {
  758.             $(this).css("top", (($(this).parent().outerHeight() / 2) - ($(this).height() / 2) - 25) + "px");
  759.         });
  760.     }
  761.  
  762.     if($(".image_gallery_wrapper .field-item").length) {
  763.         $(".image_gallery_wrapper .field-item").on("click", function() {
  764.             var img = $(this).find("img");
  765.             img.clone().addClass("lightbox").appendTo("#gallery_overlay");
  766.             $("#gallery_overlay").fadeIn(300);
  767.             verticalAlign($("#gallery_overlay .lightbox"));
  768.         });
  769.         $("#gallery_overlay").on("click", function() {
  770.             $("#gallery_overlay").fadeOut(300, function() { $(this).html(""); });
  771.         });
  772.     }
  773.  
  774.  
  775.     /////////////////////////////////////////////////////////////////////////////////////////////////////////
  776.     // Mobile Tabs:
  777.     /////////////////////////////////////////////////////////////////////////////////////////////////////////
  778.  
  779.     if($("#tabs_box").length) {
  780.  
  781.         $("#tabs_box").append('<div id="mobile_return_button" class="mobile_hide">Back</div>');
  782.  
  783.         $(".tab_name").on("click", function() {
  784.  
  785.             $(".tab_name").removeClass("mobile_show").addClass("mobile_hide");
  786.             $(this).removeClass("mobile_hide").addClass("mobile_show");
  787.             $(".tab_content").removeClass("mobile_hide").addClass("mobile_show");
  788.             $("html, body").animate({ scrollTop : ($(this).offset().top - 125) });
  789.             if($("#mobile_return_button.mobile_hide").length) {
  790.                 $("#mobile_return_button").toggleClass("mobile_show mobile_hide");
  791.             }
  792.  
  793.         });
  794.  
  795.         $("#mobile_return_button").on("click", function() {
  796.  
  797.             $(".tab_name").removeClass("mobile_hide mobile_show").addClass("mobile_show");
  798.             $(".tab_content").removeClass("mobile_hide mobile_show").addClass("mobile_hide");
  799.             $(this).toggleClass("mobile_show mobile_hide");
  800.             $("html, body").animate({ scrollTop: 0 }, "slow");//scroll to top
  801.  
  802.         });
  803.     }
  804.  
  805.  
  806.     /////////////////////////////////////////////////////////////////////////////////////////////////////////
  807.     // Mobile Menu:
  808.     /////////////////////////////////////////////////////////////////////////////////////////////////////////
  809.  
  810.     $("#mobile_menu_button").on("click", function() {
  811.  
  812.  
  813.         if($("#mobile_menu").css("left") == "0px") {
  814.             $("#mobile_menu").animate({ left : "-280px" }, 300);
  815.             $("#main_site").removeClass("fixed").css("top", "0px").animate({ left : "0" }, 300);
  816.             $("#main_header").animate({ left : "0" }, 300);
  817.             $("#overlay").fadeOut(300);
  818.         } else {
  819.             $("#main_site").addClass("fixed").css("top", ((-x) + "px"));
  820.             $("#mobile_menu").animate({ left : "0" }, 300);
  821.             $("#main_site").animate({ left : "280px" }, 300);
  822.             $("#main_header").animate({ left : "280px" }, 300);
  823.             $("#overlay").fadeTo(300, 0.75);
  824.             window.scrollTo(0, 0);
  825.         }
  826.  
  827.     });
  828.  
  829.     $("#mobile_menu .close").on("click", function() {
  830.  
  831.         $("#mobile_menu").animate({ left : "-280px" }, 300);
  832.         $("#main_site").removeClass("fixed").css("top", "0px").animate({ left : "0" }, 300);
  833.         $("#main_header").animate({ left : "0" }, 300);
  834.         $("#overlay").fadeOut(300);
  835.  
  836.     });
  837.  
  838.     $("#mobile_menu #block-menu-block-8 .menu-level-1 > .menu > li").on("click", function() {
  839.  
  840.         $(this).find(".menu").slideToggle(300);
  841.  
  842.     });
  843.  
  844.     // Secondary mobile menu
  845.  
  846.     $("#block-menu-block-1 > h2").on("click", function() {
  847.  
  848.         $("#block-menu-block-1 > .content").slideToggle(speed);
  849.  
  850.     });
  851.  
  852.  
  853.     /////////////////////////////////////////////////////////////////////////////////////////////////////////
  854.     // Chris Code:
  855.     /////////////////////////////////////////////////////////////////////////////////////////////////////////
  856.  
  857.  
  858.     $('.members-overview .success').delay(10000).slideUp(500);
  859.     $('td.show_more').click(function(){
  860.         var thistext = $(this).text();
  861.         if(thistext=='+'){thistext='-';}else{thistext='+';}
  862.         $(this).text(thistext).toggleClass('show_less').parents('tr').next('tr.extra_hidden').slideToggle(250);
  863.     });
  864.     $('span.edit_profile').click(function(){
  865.         $('html, body').animate({
  866.             scrollTop: $("section.my_profile").offset().top
  867.         }, 250);
  868.         $(this).parents('div.profile_overview').fadeOut(150).delay(300).parents('article').animate({height: $('div.edit_profile_form').height()+65}, 250, function() {}).children('div.edit_profile_form').delay(300).fadeIn(250);
  869.     });
  870.     $('span.cancel_profile').click(function(){
  871.         $('html, body').animate({
  872.             scrollTop: $("section.my_profile").offset().top
  873.         }, 250);
  874.         $(this).parents('div.edit_profile_form').fadeOut(150).delay(300).parents('article').animate({height: $('div.profile_overview').height()+65}, 250, function() {}).children('div.profile_overview').delay(300).fadeIn(250);
  875.     });
  876.     $('span.add_cpd').click(function(){
  877.         $('html, body').animate({
  878.             scrollTop: $("section.my_cpd").offset().top
  879.         }, 250);
  880.         $(this).parents('.my_iirsm_actions').parents('.cpd_overview').parents('article').slideToggle(250);
  881.         $('div.add_cpd_form').slideToggle(250);
  882.     });
  883.     $('span.cancel_cpd').click(function(){
  884.         $('html, body').animate({
  885.             scrollTop: $("section.my_cpd").offset().top
  886.         }, 250);
  887.         if($('div.cpd_overview').length){
  888.             $('.cpd_overview').parents('article').slideDown(250);
  889.             $('div.add_cpd_form').slideUp(250);
  890.         }
  891.         else{
  892.             $(this).parents('.my_iirsm_actions').parents('article').slideUp(250);
  893.             $('div.add_cpd_form').slideDown(250);
  894.         }
  895.     });
  896.     $('span.cancel_edit_cpd').click(function(){
  897.         $('html, body').animate({
  898.             scrollTop: $("section.my_cpd").offset().top
  899.         }, 250);
  900.         if($('div.cpd_overview').length){
  901.             $('.cpd_overview').parents('article').slideDown(250);
  902.             $('div.edit_cpd_form').slideUp(250);
  903.         }
  904.         else{
  905.             $(this).parents('.my_iirsm_actions').parents('article').slideUp(250);
  906.             $('div.edit_cpd_form').slideDown(250);
  907.         }
  908.     });
  909.     $('.cpd_overview .edit_cpd_button').click(function(){
  910.         $('.edit_cpd_form form.edit_profile .hidden_cpd_id').val($(this).siblings('.hidden_cpd_details').children('.hidden_cpd_id').val());
  911.  
  912.         $('.edit_cpd_form form.edit_profile .event_title').val($(this).siblings('.hidden_cpd_details').children('.hidden_event_title').val());
  913.  
  914.         $('.edit_cpd_form form.edit_profile .start_day').val($(this).siblings('.hidden_cpd_details').children('.hidden_event_start_day').val());
  915.         $('.edit_cpd_form form.edit_profile .start_month').val($(this).siblings('.hidden_cpd_details').children('.hidden_event_start_month').val());
  916.         $('.edit_cpd_form form.edit_profile .start_year').val($(this).siblings('.hidden_cpd_details').children('.hidden_event_start_year').val());
  917.  
  918.         $('.edit_cpd_form form.edit_profile .end_day').val($(this).siblings('.hidden_cpd_details').children('.hidden_event_end_day').val());
  919.         $('.edit_cpd_form form.edit_profile .end_month').val($(this).siblings('.hidden_cpd_details').children('.hidden_event_end_month').val());
  920.         $('.edit_cpd_form form.edit_profile .end_year').val($(this).siblings('.hidden_cpd_details').children('.hidden_event_end_year').val());
  921.  
  922.         $('.edit_cpd_form form.edit_profile .event_description').val($(this).siblings('.hidden_cpd_details').children('.hidden_event_description').val());
  923.         $('.edit_cpd_form form.edit_profile .event_maintenance_points').val($(this).siblings('.hidden_cpd_details').children('.hidden_event_maintenance_points').val());
  924.         $('.edit_cpd_form form.edit_profile .event_professional_points').val($(this).siblings('.hidden_cpd_details').children('.hidden_event_professional_points').val());
  925.         $('.edit_cpd_form form.edit_profile .event_transferrable_points').val($(this).siblings('.hidden_cpd_details').children('.hidden_event_transferrable_points').val());
  926.         $('.edit_cpd_form form.edit_profile .event_status_id').val($(this).siblings('.hidden_cpd_details').children('.hidden_event_status_id').val());
  927.         $('.edit_cpd_form form.edit_profile .event_status_id option').each(function( index ) {
  928.             if($(this).val() == $(this).siblings('.hidden_cpd_details').children('.hidden_event_status_id').val()){$(this).attr('selected','selected');}
  929.         });
  930.  
  931.         // show the edit form
  932.         $('html, body').animate({
  933.             scrollTop: $("section.my_cpd").offset().top
  934.         }, 250);
  935.         $(this).parents('.cpd_overview').parents('article').slideToggle(250);
  936.         $('div.edit_cpd_form').slideToggle(250);
  937.     });
  938.     $('.show_all').click(function(){
  939.         $('html, body').animate({
  940.             scrollTop: $(this).parents('section').offset().top
  941.         }, 250);
  942.         $(this).hide().siblings('.show_less').show();
  943.         $(this).parents('.my_iirsm_actions').siblings('table').find('tbody tr.hidden').toggleClass('hidden').toggleClass('visible');
  944.         $('.my_iirsm_actions .showing').toggleClass('hidden');
  945.     });
  946.     $('.show_less').click(function(){
  947.         $('html, body').animate({
  948.             scrollTop: $(this).parents('section').offset().top
  949.         }, 250);
  950.         $(this).hide().siblings('.show_all').show();
  951.         $(this).parents('.my_iirsm_actions').siblings('table').find('tbody tr.visible').toggleClass('hidden').toggleClass('visible');
  952.         $('.my_iirsm_actions .showing').toggleClass('hidden');
  953.         $('table').find('.show_less').text('+').toggleClass('show_less').parents('tr').next('tr.extra_hidden').hide();
  954.     });
  955.  
  956.     $('.members-overview section.my_cpd .my_iirsm_actions input[type="submit"]#sbt_cpd_event').click(function(event){
  957.         var cpd_point_limit = 3;
  958.         event.preventDefault();
  959.         // start the error message
  960.         var error_msg = 'You have missed the following:-';
  961.         //check that title is present
  962.         if($('.add_cpd_form form.edit_profile .event_title').val() == ''){
  963.             error_msg += "\n"+$(this).prev('label').html();
  964.         }
  965.  
  966.         //If the CPD is set to finished we must include activity reflection text
  967.         if($('.add_cpd_form form.edit_profile .event_status_id').val() == 'cd1508eb-d433-4545-9939-d37cce17a762'){
  968.             if($('.add_cpd_form form.edit_profile .event_description').val() == ''){
  969.                 error_msg += "\n"+$(this).prev('label').html();
  970.             }
  971.         }
  972.         // construct the dates
  973.         // var start_date = $(this).find('.start_year').val()+'-'+$(this).find('.start_month').val()+'-'+$(this).find('.start_day').val();
  974.         // var end_date = $(this).find('.end_year').val()+'-'+$(this).find('.end_month').val()+'-'+$(this).find('.end_day').val();
  975.         var start_date = $('#edit_profile .date_container .start_year').val()+'-'+$('#edit_profile .date_container .start_month').val()+'-'+$('#edit_profile .date_container .start_day').val();
  976.         var end_date = $('#edit_profile .date_container .end_year').val()+'-'+$('#edit_profile .date_container .end_month').val()+'-'+$('#edit_profile .date_container .end_day').val();
  977.  
  978.         if(start_date.indexOf("day") > -1 || start_date.indexOf("month") > -1 || start_date.indexOf("year") > -1){
  979.             error_msg += "\n"+'Start date';
  980.         }
  981.         if(end_date.indexOf("day") > -1 || start_date.indexOf("month") > -1 || start_date.indexOf("year") > -1){
  982.             error_msg += "\n"+'End date';
  983.         }
  984.  
  985.         if(error_msg.length > 31){
  986.             alert(error_msg);
  987.         }
  988.         else{
  989.             error_msg = '';
  990.  
  991.             var reformatted_start_date = Date.parse(start_date);// parse string as date
  992.             var reformatted_end_date = Date.parse(end_date);// parse string as date
  993.  
  994.             if(reformatted_start_date > reformatted_end_date){
  995.                 error_msg += "Your start date can't be greater than your end date";
  996.             }
  997.             if(error_msg.length > 0){
  998.                 error_msg += "\n";
  999.             }
  1000.  
  1001.             // do the cpd points add up to 3
  1002.             var cpd_points_total = (parseInt($('.add_cpd_form #edit_profile').find('.event_maintenance_points').val()) + parseInt($('.add_cpd_form #edit_profile').find('.event_professional_points').val()) + parseInt($('.add_cpd_form #edit_profile').find('.event_transferrable_points').val()));
  1003.             if(cpd_points_total > cpd_point_limit){
  1004.                 error_msg += "Your total CPD points should not exceed "+cpd_point_limit;
  1005.             }
  1006.  
  1007.             if(error_msg.length > 0){
  1008.                 error_msg += "\n";
  1009.             }
  1010.  
  1011.             // is the event more than 3 months ago
  1012.             var d = new Date();
  1013.             d.setMonth(d.getMonth() - 12);
  1014.             var current_date_3_months = d.getFullYear()+'-'+d.getMonth()+'-'+d.getDate();// parse string as date
  1015.             var current_date_3_months_compare = Date.parse(d);// parse string as date
  1016.             if(reformatted_start_date < current_date_3_months_compare){
  1017.                 error_msg += "Your CPD must have started within the last 12 months, please edit your start date.";
  1018.             }
  1019.  
  1020.             if(error_msg.length > 0){
  1021.                 alert(error_msg);
  1022.             }
  1023.             else{
  1024.                 $('.add_cpd_form form.edit_profile').submit()
  1025.             }
  1026.         }
  1027.     });
  1028.  
  1029.     $('.members-overview section.my_cpd .my_iirsm_actions input[type="submit"]#sbt_edit_cpd_event').click(function(event){
  1030.         var cpd_point_limit = 3;
  1031.         event.preventDefault();
  1032.         // start the error message
  1033.         var error_msg = 'You have missed the following:-';
  1034.         $('.edit_cpd_form form.edit_profile input[type=text], .edit_cpd_form form.edit_profile textarea').each(function(){
  1035.             if($(this).val() == ''){
  1036.                 error_msg += "\n"+$(this).prev('label').html();
  1037.             }
  1038.         });
  1039.  
  1040.         // construct the dates
  1041.         // var start_date = $(this).find('.start_year').val()+'-'+$(this).find('.start_month').val()+'-'+$(this).find('.start_day').val();
  1042.         // var end_date = $(this).find('.end_year').val()+'-'+$(this).find('.end_month').val()+'-'+$(this).find('.end_day').val();
  1043.         var start_date = $('.edit_cpd_form .date_container .start_year').val()+'-'+$('.edit_cpd_form .date_container .start_month').val()+'-'+$('.edit_cpd_form .date_container .start_day').val();
  1044.         var end_date = $('.edit_cpd_form .date_container .end_year').val()+'-'+$('.edit_cpd_form .date_container .end_month').val()+'-'+$('.edit_cpd_form .date_container .end_day').val();
  1045.  
  1046.         // if(start_date.indexOf("day") > -1 || start_date.indexOf("month") > -1 || start_date.indexOf("year") > -1){
  1047.         //     error_msg += "\n"+'Start date';
  1048.         // }
  1049.         // if(end_date.indexOf("day") > -1 || start_date.indexOf("month") > -1 || start_date.indexOf("year") > -1){
  1050.         //     error_msg += "\n"+'End date';
  1051.         // }
  1052.  
  1053.         if(error_msg.length > 31){
  1054.             alert(error_msg);
  1055.         }
  1056.         else{
  1057.             error_msg = '';
  1058.  
  1059.             var reformatted_start_date = Date.parse(start_date);// parse string as date
  1060.             var reformatted_end_date = Date.parse(end_date);// parse string as date
  1061.             if(reformatted_start_date > reformatted_end_date){
  1062.                 error_msg += "Your start date can't be greater than your end date";
  1063.             }
  1064.             if(error_msg.length > 0){
  1065.                 error_msg += "\n";
  1066.             }
  1067.  
  1068.             // do the cpd points add up to 3
  1069.             var cpd_points_total = (parseInt($('.edit_cpd_form #edit_profile').find('.event_maintenance_points').val()) + parseInt($('.edit_cpd_form #edit_profile').find('.event_professional_points').val()) + parseInt($('.edit_cpd_form #edit_profile').find('.event_transferrable_points').val()));
  1070.             if(cpd_points_total > cpd_point_limit){
  1071.                 error_msg += "Your total CPD points should not exceed "+cpd_point_limit;
  1072.             }
  1073.  
  1074.             if(error_msg.length > 0){
  1075.                 error_msg += "\n";
  1076.             }
  1077.  
  1078.             // is the event more than 3 months ago
  1079.             var d = new Date();
  1080.             d.setMonth(d.getMonth() - 12);
  1081.             var current_date_3_months = d.getFullYear()+'-'+d.getMonth()+'-'+d.getDate();// parse string as date
  1082.             var current_date_3_months_compare = Date.parse(d);// parse string as date
  1083.             if(reformatted_start_date < current_date_3_months_compare){
  1084.                 error_msg += "Your CPD must have started within the last 12 months, edit your start date.";
  1085.             }
  1086.  
  1087.             if(error_msg.length > 0){
  1088.                 alert(error_msg);
  1089.             }
  1090.             else{
  1091.                 $('.edit_cpd_form form.edit_profile').submit()
  1092.             }
  1093.         }
  1094.     });
  1095.  
  1096.     //if member then hide non member price
  1097.     if($('.logged-in-member').length){
  1098.         $('.non-member-price').css("display","none");
  1099.     }
  1100.  
  1101.     $('.members .select_list .membership_checkbox').click(function(){
  1102.         if($(this).find('.checkbox').hasClass('checked')){
  1103.             $(this).removeClass('checked');
  1104.         }
  1105.         else{
  1106.             $(this).siblings('div.membership_checkbox').children('span.checkbox').removeClass('checked');
  1107.             $(this).find('.checkbox').addClass('checked');
  1108.         }
  1109.         var classes = $(this).find('.checkbox').attr('class');
  1110.         classes = classes.split(' ');
  1111.         $('.hid_membership_list').val(classes[2]);
  1112.  
  1113.         $('.hid_membership_application_price_value').val($(this).find('.checkbox').siblings('span').children('.membership_prices').children('.membership_application_price').children('.membership_application_price_value').text());
  1114.  
  1115.         $('.hid_membership_price_value').val($(this).find('.checkbox').siblings('span').children('.membership_prices').children('.membership_actual_price').children('.membership_price_value').text());
  1116.     });
  1117.     $('.members .select_list .option_container:not(.noclick)').click(function(){
  1118.         if($('#create_profile_step1').length){
  1119.             if($(this).find('.checkbox').hasClass('checked')){
  1120.                 $(this).find('.checkbox').removeClass('checked');
  1121.                 $('.hid_'+$(this).siblings('span').children('input').attr('name')).val('');
  1122.                 $('.hid_'+$(this).siblings('span').children('input').attr('name')+'_value').val('');
  1123.             }
  1124.             else{
  1125.                 $(this).siblings('.option_container').children('span.checkbox').removeClass('checked');
  1126.                 $(this).find('.checkbox').addClass('checked');
  1127.  
  1128.                 $('.hid_'+$(this).find('.checkbox').siblings('span').children('input').attr('name')).val(
  1129.                     $(this).find('span').children('input').attr('value')
  1130.                 );
  1131.  
  1132.                 $('.hid_'+$(this).find('.checkbox').siblings('span').children('input').attr('name')+'_value').val(
  1133.                     $(this).find('.checkbox').siblings('span').text()//children('input').attr('name')
  1134.                 );
  1135.             }
  1136.         }
  1137.         if($('#create_profile_step2').length){
  1138.             if($(this).hasClass('checked')){
  1139.                 $(this).removeClass('checked');
  1140.             }
  1141.             else{
  1142.                 $(this).parents('div.membership_checkbox').siblings('div.membership_checkbox').children('span.checkbox').removeClass('checked');
  1143.                 $(this).addClass('checked');
  1144.             }
  1145.             var classes = $(this).attr('class');
  1146.             classes = classes.split(' ');
  1147.             $('.hid_membership_list').val(classes[2]);
  1148.  
  1149.             $('.hid_membership_application_price_value').val($(this).siblings('span').children('.membership_prices').children('.membership_application_price').children('.membership_application_price_value').text());
  1150.  
  1151.             $('.hid_membership_price_value').val($(this).siblings('span').children('.membership_prices').children('.membership_actual_price').children('.membership_price_value').text());
  1152.         }
  1153.         if($('.members').hasClass('members-search')){
  1154.             if($(this).hasClass('checked')){
  1155.                 $(this).removeClass('checked');
  1156.                 $(this).parents('.select_list').siblings('.hidden_field').val('');
  1157.             }
  1158.             else{
  1159.                 $(this).siblings('span.checkbox').removeClass('checked');
  1160.                 $(this).addClass('checked');
  1161.                 var classes = $(this).attr('class');
  1162.                 classes = classes.split(' ');
  1163.                 $(this).parents('.select_list').siblings('.hidden_field').val(classes[2]);
  1164.             }
  1165.         }
  1166.     });
  1167.  
  1168.     $('.members .member_application div.create_profile_form .create_profile_step_3 form .membership_list_container .select_list .membership_checkbox').live( "click", function() {// user is selecting a new membership due to conflict in countries
  1169.         if($(this).children('span.checkbox').hasClass('checked')){
  1170.             $(this).children('span.checkbox').removeClass('checked');
  1171.         }
  1172.         else{
  1173.             $(this).siblings('div.membership_checkbox').children('span.checkbox').removeClass('checked');
  1174.             $(this).children('span.checkbox').addClass('checked');
  1175.         }
  1176.         var classes = $(this).children('span.checkbox').attr('class');
  1177.         classes = classes.split(' ');
  1178.  
  1179.         // change the stored membership id. this is the unique membership id which will be sent to vision
  1180.         $('input[name=hid_membership_option]').val(classes[2]);
  1181.         $('input[name=MembershipTypeId]').val(classes[2]);
  1182.         console.log('changing membership id');
  1183.  
  1184.         $('.hid_membership_application_price_value').val($(this).children('span.checkbox').siblings('span').children('.membership_prices').children('.membership_application_price').children('.membership_application_price_value').text());
  1185.  
  1186.         $('.hid_membership_price_value').val($(this).children('span.checkbox').siblings('span').children('.membership_prices').children('.membership_actual_price').children('.membership_price_value').text());
  1187.     });
  1188.     $('.create_profile_step_3 fieldset .checkbox_container span.checkbox').click(function(){
  1189.         /*if($(this).hasClass('checked')){
  1190.             $(this).removeClass('checked');
  1191.         }
  1192.         else{
  1193.             $(this).parents('div.checkbox_container').siblings('div.checkbox_container').children('span.checkbox').removeClass('checked');
  1194.             $(this).addClass('checked');
  1195.         }
  1196.         if($(this).siblings('span').length){
  1197.             $(this).siblings('span').val($(this).siblings('span').text());
  1198.         }
  1199.         else{
  1200.             $(this).siblings('span').val($(this).siblings('input[type=text]').val());
  1201.             if($('.checkbox_container_other').length){
  1202.                 $('.checkbox_container_other input[type=text]').focus();
  1203.             }
  1204.         }*/
  1205.         $(this).toggleClass('checked').parents('.checkbox_container').siblings('input.hid_gift_aid').val($(this).hasClass("checked"));
  1206.     });
  1207.     $('.create_profile_step_3 fieldset.interests .checkbox_container').click(function(){
  1208.         if($(this).children('input[type=hidden]').val() == ''){
  1209.             $(this).children('.checkbox').addClass('checked');
  1210.             var interest_id = $(this).children('span.label').attr('class').split(' ')[1];
  1211.             $(this).children('input[type=hidden]').val(interest_id);
  1212.         }
  1213.         else{
  1214.             $(this).children('.checkbox').removeClass('checked');
  1215.             $(this).children('input[type=hidden]').val('');
  1216.         }
  1217.     });
  1218.     $('.create_profile_step_3 fieldset.whopays .select_container select').change(function(){
  1219.         if($(this).val() == $(this).attr('original')){
  1220.             $('.members .member_application div.create_profile_form .create_profile_step_3 .section_title.gift_aid').hide();
  1221.             $('.members .member_application div.create_profile_form .create_profile_step_3 fieldset.gift_aid').hide();
  1222.         }
  1223.         else{
  1224.             if(".is_gift_aid_eligible_"+$(this).val() != false){
  1225.                 $('.members .member_application div.create_profile_form .create_profile_step_3 .section_title.gift_aid').show();
  1226.                 $('.members .member_application div.create_profile_form .create_profile_step_3 fieldset.gift_aid').show();
  1227.             }
  1228.             else{
  1229.                 $('.members .member_application div.create_profile_form .create_profile_step_3 .section_title.gift_aid').hide();
  1230.                 $('.members .member_application div.create_profile_form .create_profile_step_3 fieldset.gift_aid').hide();
  1231.             }
  1232.         }
  1233.     });
  1234.  
  1235.     $('select[name=EmploymentStatusId]').change(function() {
  1236.         var status = $(this).find('option:selected').text();
  1237.         if(status == 'Retired' || status == 'Student ' || status == 'Unemployed'){
  1238.             $('fieldset.business, .business_title').hide();
  1239.             $('fieldset.business').addClass('not_required');
  1240.  
  1241.             if(status == 'Student ')
  1242.             {
  1243.                 $('#file_instructions').html('Please upload proof of your student status.')
  1244.             }
  1245.         }
  1246.         if(status != 'Retired' && status != 'Student ' && status != 'Unemployed'){
  1247.             $('fieldset.business, .business_title').show();
  1248.             $('fieldset.business').removeClass('not_required');
  1249.         }
  1250.     });
  1251.  
  1252.  
  1253.     $('select[name=Country], select[name=CompanyCountry], #PreferredMailingAddress').change(function() {
  1254.         // find out what has been selected
  1255.         var current_country = $('input[name=hid_membership_country_value]').val();
  1256.         // look at home address country
  1257.         if($('select#PreferredMailingAddress').val() == 'Home Address'){
  1258.             // the home country for this has not been chosen yet
  1259.             var chosen_country_value = $('select[name=Country] option:selected').text().trim();
  1260.  
  1261.             if($('select[name=Country]').val() == 'Country' || chosen_country_value == current_country){
  1262.                 $('fieldset.new_membership_options').slideUp().remove();
  1263.                 return;
  1264.             }
  1265.             var chosen_country_id = $('select[name=Country]').val();
  1266.             var chosen_country = $('select[name=Country]:selected').text();
  1267.             var chosen_country_type = 'home address';
  1268.         }
  1269.         // look at business address country
  1270.         else if($('#PreferredMailingAddress').val() == 'Business Address'){
  1271.             // the business country for this has not been chosen yet
  1272.             var chosen_country_value = $('select[name=CompanyCountry] option:selected').text().trim();
  1273.  
  1274.             if($('select[name=CompanyCountry]').val() == 'Company Country' || chosen_country_value == current_country){
  1275.                 $('fieldset.new_membership_options').slideUp().remove();
  1276.                 return;
  1277.             }
  1278.             var chosen_country_id = $('select[name=CompanyCountry]').val();
  1279.             var chosen_country = $('select[name=CompanyCountry]:selected').text();
  1280.             var chosen_country_type = 'business address';
  1281.         }
  1282.         // preferred address is not yet chosen
  1283.         else if($('#PreferredMailingAddress').val() == 'Preferred mailing address'){
  1284.             $('fieldset.new_membership_options').slideUp(500).remove();
  1285.             return;
  1286.         }
  1287.         else{
  1288.             // user is selecting the original, inline with the membership they have chosen, nothing wrong here/yet
  1289.             var chosen_country = $('input[name=hid_original_membership_country_value]').val();
  1290.         }
  1291.  
  1292.         if(
  1293.             (chosen_country == 'Country')
  1294.             ||
  1295.             (chosen_country == current_country)
  1296.         )
  1297.         {
  1298.             $('fieldset.new_membership_options').slideUp(500).remove();
  1299.             return;
  1300.         }
  1301.  
  1302.         // get a new selection of memberships to choose from
  1303.         if(chosen_country_value != $('input[name=hid_membership_country_value]').val()){
  1304.  
  1305.             $('input[name=hid_membership_country_value]').val(chosen_country_value);
  1306.             $('.reminder_country').text(chosen_country_value);
  1307.  
  1308.             $('body #main_site .ajax_loading_container').width($(document).width()).height($(document).height()).show();
  1309.  
  1310.             console.log(chosen_country_id);
  1311.             console.log($('input[name=hid_membership_level').val());
  1312.             console.log($('input[name=hid_membership_duration_value').val());
  1313.  
  1314.  
  1315.             $.ajax({
  1316.                 type: "POST",
  1317.                 url: "/apply-online",
  1318.                 data: {
  1319.                     'step1': 'true',
  1320.                     'ajax': 'true',
  1321.                     'hid_country': chosen_country_id,
  1322.                     'hid_grade_level': $('input[name=hid_membership_level').val(),
  1323.                     'hid_duration': $('input[name=hid_membership_duration_value').val()
  1324.                 },
  1325.                 dataType: 'json',
  1326.                 cache: false,
  1327.                 success: function(data){
  1328.                     // does not run, guess we are not specifically returning anything
  1329.                 },
  1330.                 complete: function(data){
  1331.                     var new_options = $(data.responseText).find('.membership_list_select_list').html();
  1332.  
  1333.                     $('fieldset.new_membership_options').remove();
  1334.  
  1335.                     $('<fieldset class="new_membership_options" style="width:99.3%;display:none;"><div class="membership_list_container" style="margin-bottom:10px;"><div class="membership_list_select_list select_list">'+new_options+'</div></div></fieldset><br /><br />').insertBefore('form#create_profile_step3 fieldset:first');
  1336.  
  1337.                     // alert('The country in your '+chosen_country_type+' is different to the country of your chosen membership'+"\n"+"\n"+'Please select a new membership option.');
  1338.  
  1339.                     $('body #main_site .ajax_loading_container').hide();
  1340.  
  1341.                     $('fieldset.new_membership_options').slideDown(500);
  1342.  
  1343.                     $("html, body").animate({ scrollTop : 15000 }, 500);
  1344.  
  1345.                     /*alert($(data.responseText).find('.membership_list_select_list .membership_checkbox').length);
  1346.                     if($(data.responseText).find('.membership_list_select_list .membership_checkbox').length == 1){alert('here');
  1347.                         $('.members .member_application div.create_profile_form .create_profile_step_3 form .membership_list_container .select_list .membership_checkbox').trigger('click');
  1348.                     }*/
  1349.                 }
  1350.             });
  1351.         }
  1352.         else{
  1353.             $('fieldset.new_membership_options').slideUp().remove();
  1354.         }
  1355.     });
  1356.  
  1357.     $('.members .show_select_list').click(function(){
  1358.         $(this).toggleClass('open').siblings('div.select_list').toggle(0);
  1359.     });
  1360.  
  1361.     $('.members-overview section.my_account_balance article input[type=submit]').click(function(){
  1362.         var balance = $('.members-overview section.my_account_balance article form input[name=balance]').val();
  1363.         if (confirm("Are you sure you want to pay off your account balance?"+"\n"+"\n"+"This will create a payment for £"+balance+", the value of your whole account balance. The payment will be added to your cart and you will be taken to the checkout.")) {
  1364.             $('.members-overview section.my_account_balance article .my_iirsm_actions form#account_balance_payment').submit();
  1365.         }
  1366.         return false;
  1367.     });
  1368.     $('.frm_member_search input[type=text], .members .member_application div.create_profile_form input[type=text]').focus( function() {
  1369.         if($(this).val().trim() == $(this).attr('original')){
  1370.             $(this).val('');
  1371.         }
  1372.     });
  1373.  
  1374.     $('.frm_member_search input[type=text], .members .member_application div.create_profile_form input[type=text]').blur( function() {
  1375.         if($(this).val().trim() == ''){
  1376.             $(this).val($(this).attr('original'));
  1377.         }
  1378.     });
  1379.  
  1380.     // checkout page fix
  1381.     var temp_url = $('.entity-commerce-product').siblings('a').attr('href');
  1382.     $('.entity-commerce-product').siblings('a').remove();
  1383.     $('.commerce-product-title').find('.commerce-product-title-label').remove().html('<a href="'+temp_url+'">'+$('.commerce-product-title').text()+'</a>');
  1384.  
  1385.     // coat of arms image on page
  1386.     if($('body.page-node-124').length){
  1387.         $('.field-name-body').find('.field-items').find('.field-item').prepend('<img src="/sites/all/themes/iirsm/images/iirsm_coat_of_arms.png" style="width:250px" title="IIRSM Coat of Arms" alt="IIRSM Coat of Arms" />');
  1388.     }
  1389.  
  1390.     // coat of arms image on page
  1391.     if($('body.page-node-92').length){
  1392.         $('.field-name-body').find('.field-items').find('.field-item').prepend('<img src="/sites/all/themes/iirsm/images/iirsm_structure_diagram.png" style="width:100%" title="IIRSM Structure" alt="IIRSM Coat of Arms" />');
  1393.     }
  1394.  
  1395.     // remove the region filter on the news page
  1396.     if($('body.page-node-42').length){
  1397.         $('#edit-tid-wrapper').hide();
  1398.     }
  1399.  
  1400.     // if on HSE News page then remove the HSE News link from the right
  1401.     if($('body.page-node-365').length){
  1402.         $('#block-menu-block-1').remove();
  1403.         $('#right_col .box.double.soc_med').css('margin-top','0px');
  1404.     }
  1405.     // also remove the HSE Live feed menu item all together
  1406.     $('#menu-1493-1').children('ul').remove();
  1407.     // remove the events sub menu
  1408.     $('#menu-2139-1').children('ul').remove();
  1409.  
  1410.     // put the search results title on the search results page
  1411.     if($('.page-search').length){
  1412.         var url = window.location.href;
  1413.         var url_parts = url.split('?');
  1414.         var search_term = url_parts[1].split('=');
  1415.         search_term = search_term[1];
  1416.         $('.region-content').prepend('<h1>Your search for "'+search_term+'" returned '+$('#block-system-main .content .view-search-results .view-content .views-row').length+' results</h1>');
  1417.         $('.view-search-results').children('.more-link').hide();
  1418.     }
  1419.  
  1420.     // put the search results title on the search results page
  1421.     if($('.page-node-42').length){
  1422.         // $('#views-exposed-form-news-masonry-filter-block').find('h2').html('Showing results for  '+$('#edit-tid-1-wrapper').find('input[type=radio]:checked').siblings('.option').html());
  1423.         $('#views-exposed-form-news-masonry-filter-block').find('h2').html('Showing results for: ');
  1424.     }
  1425.     $('#edit-tid-1 input[type=radio]').click(function(){
  1426.         // $('#views-exposed-form-news-masonry-filter-block').find('h2').html('Showing results for  '+$('#edit-tid-1-wrapper').find('input[type=radio]:checked').siblings('.option').html());
  1427.         $('#views-exposed-form-news-masonry-filter-block').find('h2').html('Showing results for: ');
  1428.     });
  1429.  
  1430.     // on the corporate memberships page, remove the CPD section
  1431.     if($('.page-node-180').length){
  1432.         $('.tab_names').find('.tab_name_3').hide();
  1433.     }
  1434.  
  1435.     // on council page, remove h2 above staff members
  1436.     if($('.page-node-137').length){
  1437.         $('.region-feed .stream_title').hide();
  1438.     }
  1439.  
  1440.     // if on the checkout review page, move the word expiration into its parent div. format looks awful with out this
  1441.     if($('.page-checkout-review .commerce-credit-card-expiration').length){
  1442.         //$('#edit-commerce-payment-payment-details-credit-card-exp-month').find('label').appendTo('#payment-details .commerce-credit-card-expiration');
  1443.         $('#payment-details .commerce-credit-card-expiration').prepend($('.form-item.form-type-select.form-item-commerce-payment-payment-details-credit-card-exp-month label'));
  1444.     }
  1445.  
  1446.     if($('.page-node-135').length){
  1447.         // step 1, select membership criteria
  1448.         $('.my_iirsm_actions .sbt_profile.step1').click(function(e){
  1449.             var message = 'You need to select the following: '+"<br /><ul>";
  1450.             $('#create_profile_step1 input.required').each(function( index ) {
  1451.                 if($(this).val() == ''){
  1452.                     message += "<li>"+$(this).siblings('span').text()+"</li>";
  1453.                 }
  1454.             });
  1455.             message += "</ul>";
  1456.             if(message.length > 50){
  1457.                 e.preventDefault();
  1458.                 $('.members .member_application div.create_profile_form .message').addClass('error').html('<span>'+message+'</span>');
  1459.                 $('.members .member_application div.create_profile_form').show();
  1460.             }
  1461.             else{
  1462.                 $('#create_profile_step1').submit();
  1463.             }
  1464.         });
  1465.         // step 2, select membership
  1466.         $('.my_iirsm_actions .sbt_profile.step2').click(function(e){
  1467.             var message = '';
  1468.             if($('#create_profile_step2 input.hid_membership_list.required').val() == ''){
  1469.                 message = 'You need to select a membership option';
  1470.             }
  1471.             if(message != ''){
  1472.                 e.preventDefault();
  1473.                 $('.members .member_application div.create_profile_form .message').addClass('error').html('<span>'+message+'</span>');
  1474.                 $('.members .member_application div.create_profile_form').show();
  1475.             }
  1476.             else{
  1477.                 $('#create_profile_step2').submit();
  1478.             }
  1479.         });
  1480.         //automatically set the username to their preferred email address when the preferred email address field is changed
  1481.         $('select[name=PreferredEmailAddress]').change(function(){
  1482.             if($('select[name=PreferredEmailAddress]').val()=='Email 1'){
  1483.                $("input[name=UserName]").val($('input[name=Email1]').val());
  1484.             }
  1485.             else if($('select[name=PreferredEmailAddress]').val()=='Email 2'){
  1486.                 $("input[name=UserName]").val($('input[name=Email2]').val());
  1487.             }
  1488.         });
  1489.  
  1490.         //change username if the preferred email is updated
  1491.         $('input[name=Email1]').change(function(){
  1492.             if($('select[name=PreferredEmailAddress]').val()=='Email 1'){
  1493.                $("input[name=UserName]").val($('input[name=Email1]').val());
  1494.             }
  1495.         });
  1496.         $('input[name=Email2]').change(function(){
  1497.             if($('select[name=PreferredEmailAddress]').val()=='Email 2'){
  1498.                $("input[name=UserName]").val($('input[name=Email2]').val());
  1499.             }
  1500.         });
  1501.  
  1502.         // step 3, personal details
  1503.         $('.my_iirsm_actions .sbt_profile.step3').click(function(e){
  1504.             if($('fieldset.business').hasClass('not_required')){
  1505.                 $('fieldset.business').remove();
  1506.             }
  1507.             var message = 'You need to include the following:';
  1508.             message += '<br /><ul>';
  1509.             if($('.course_end_date').length){
  1510.                 if($('select.ced_day').val() == '' || $('select.ced_day').val() == $('select.ced_day').attr('original')){
  1511.                     message += "<li>Course end date "+$('select.ced_day').attr('original')+"</li>";
  1512.                 }
  1513.                 else if($('select.ced_month').val() == '' || $('select.ced_month').val() == $('select.ced_month').attr('original')){
  1514.                     message += "<li>Course end date "+$('select.ced_month').attr('original')+"</li>";
  1515.                 }
  1516.                 else if($('select.ced_year').val() == '' || $('select.ced_year').val() == $('select.ced_year').attr('original')){
  1517.                     message += "<li>Course end date "+$('select.ced_year').attr('original')+"</li>";
  1518.                 }
  1519.                 else{
  1520.                     // get current date and format it
  1521.                     var current_date = new Date().getTime()
  1522.  
  1523.                     // get selected date and format it
  1524.                     var selected_date = $('select.ced_year').val()+'-'+$('select.ced_month').val()+'-'+$('select.ced_day').val();
  1525.                     var selected_date = Date.parse(selected_date);// parse string as date
  1526.                     console.log(selected_date);
  1527.  
  1528.                     if(selected_date < current_date){
  1529.                         // date should be after today
  1530.                         message += "<li>Your course end date can't be in the past</li>";
  1531.                     }
  1532.                 }
  1533.             }
  1534.             $('#create_profile_step3 input.required, #create_profile_step3 select.required').each(function( index ) {
  1535.                 if($(this).is('select')){
  1536.                     if($(this).val() == '' || $(this).val() == $(this).attr('original')){
  1537.                         if($(this).attr('original') == 'Day' || $(this).attr('original') == 'Month' || $(this).attr('original') == 'Year'){
  1538.                             message += "<li>DOB "+$(this).attr('original')+"</li>";
  1539.                         }
  1540.                         else{
  1541.                             message += "<li>"+$(this).attr('original')+"</li>";
  1542.                         }
  1543.                     }
  1544.                 }
  1545.                 else{
  1546.                     console.log('Val: '+$(this).val()+' Placeholder: '+$(this).attr('placeholder'));
  1547.                     if($(this).val() == '' || $(this).val() == $(this).attr('placeholder')){
  1548.                         if(typeof $(this).attr('placeholder') != 'undefined'){
  1549.                             message += "<li>"+$(this).attr('name')+"</li>";
  1550.                         }
  1551.                     }
  1552.                     else{
  1553.                         if($(this).attr('name') == 'Username'){
  1554.  
  1555.                         }
  1556.                         if(($(this).attr('name') == 'LastName') || ($(this).attr('name') == 'FirstName'))
  1557.                         {
  1558.                             if(($(this).val() == ' ') || ($(this).val() == '.')  || ($(this).val() == '..') || ($(this).val() == '...') || ($(this).val() == '@') || ($(this).val() == '#'))
  1559.                             {
  1560.                                 message += "<li>Please enter a valid "+$(this).attr('name')+"</li>";
  1561.                             }
  1562.                         }
  1563.                         if($(this).attr('name') == 'Password'){
  1564.                             var password = $(this).val();
  1565.                             var password_confirmation = $('#Password_confirm').val();
  1566.                             console.log(password.match(/^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])([a-zA-Z0-9]{8})$/));
  1567.                             if(password != password_confirmation){
  1568.                                 message += "<li>Your chosen password does not match the password confirmation</li>";
  1569.                             }
  1570.                             if (password.length < 8) {
  1571.                                 message += "<li>Your chosen password must be at least 8 characters long</li>";
  1572.                             }
  1573.                             else if (password.search(/[a-z]/) < 0) {
  1574.                                 message += "<li>Your chosen password must contain at least one lowercase character</li>";
  1575.                             }
  1576.                             else if(password.search(/[A-Z]/) < 0) {
  1577.                                 message += "<li>Your chosen password must contain at least one uppercase character</li>";
  1578.                             }
  1579.                             else  if (password.search(/[0-9]/) < 0) {
  1580.                                 message += "<li>Your chosen password must contain at least one number</li>";
  1581.                             }
  1582.                         }
  1583.                     }
  1584.                 }
  1585.             });
  1586.            
  1587.             //validate that new membership options have been selected if present i.e. applicant changed their country from original selection
  1588.             if($('.new_membership_options').length){
  1589.                 if(!$('.checkbox.membership_input').hasClass('checked')){
  1590.                     message += "<li>You have changed your preferred mailing address to a different country. You must make a selection from the revised list of available memberships to continue your application.</li>";
  1591.                 }
  1592.             }
  1593.  
  1594.             if($('.fellowship_file_upload').length){
  1595.                 if($('.fellowship_file_upload .file_upload_container .apply_online_file_upload').val() == ""){
  1596.                     message += "<li>You must upload your Fellowship petition document</li>";
  1597.                 }
  1598.             }
  1599.             if($('.file_upload.regular').length){
  1600.                 var file_count = 0;
  1601.                 $('.file_upload.regular .file_upload_container .apply_online_file_upload').each(function( index ) {
  1602.                     if($(this).val() != ''){
  1603.                         file_count++;
  1604.                         console.log('filesize in KB = '+this.files[0].size/1000);
  1605.                         if(this.files[0].size/1000 > 2500){
  1606.                             message +="<li>Your file uploads are too large, your CV and supporting documents must not exceed 2.5Mb each</li>";
  1607.                         }
  1608.                     }
  1609.                 });
  1610.                 if(file_count < 2){
  1611.  
  1612.                     if($('.section_title').html() != 'Course end date')
  1613.                     {
  1614.                         message += " <li>You must upload your CV and supporting documents</li>";
  1615.                     }
  1616.  
  1617.                     else
  1618.                     {
  1619.                         if(file_count < 1)
  1620.                         {
  1621.                             message += " <li>You must upload your proof of student status.</li>";
  1622.                         }                        
  1623.                     }
  1624.                 }
  1625.             }
  1626.  
  1627.             message += "</ul>";
  1628.  
  1629.             console.log('Message: '+message);
  1630.  
  1631.             if(message != 'You need to include the following:<br /><ul></ul>'){
  1632.                 e.preventDefault();
  1633.                 $('.members .member_application div.create_profile_form .message').addClass('error').html('<span>'+message+'</span>');
  1634.                 $('.members .member_application div.create_profile_form').show();
  1635.                 $("html, body").animate({ scrollTop : $(".message.error").offset().top }, 500);
  1636.             }
  1637.             else{
  1638.                 //$('#create_profile_step2').submit();
  1639.             }
  1640.         });
  1641.         // add new file upload
  1642.         $('.file_upload.regular .button').click(function(){
  1643.             var new_file_upload = $('.file_upload_hidden').html();
  1644.             $(new_file_upload).insertBefore('.file_upload.regular .button.add_new');
  1645.             $('.file_upload_container .button.remove.hidden').show();
  1646.         });
  1647.         // remove new file upload
  1648.         $('.file_upload.regular .file_upload_container span.remove').live( "click", function() {
  1649.             $(this).parents('.file_upload_container').remove();
  1650.             if($('.file_upload.regular .file_upload_container').length==2){
  1651.                 $('.file_upload_container .button.remove.hidden').hide();
  1652.             }
  1653.         });
  1654.     }
  1655.  
  1656.     // on council page, remove h2 above staff members
  1657.     if(!$('body').hasClass('page-node-40') && ($('body').hasClass('node-type-page') || $('body').hasClass('node-type-page-basic'))){
  1658.         $('.menu-name-main-menu.menu-level-2 .menu .menu-mlid-2082').remove();
  1659.     }
  1660.  
  1661.     // mem and arts on click download pdf
  1662.     // IIRSM Memoradum and Articles of Association.pdf
  1663.     if($('.page-node-89').length){
  1664.         $('#block-menu-block-3 .content .menu .box .menu-mlid-1793').html('<a target="_blank" href="http://www.iirsm.org/sites/all/themes/iirsm/iirsm_memorandum_and_articles_of_association.pdf">'+$('#block-menu-block-3 .content .menu .box .menu-mlid-1793 a').html()+'</a>');
  1665.     }
  1666.  
  1667.     if($('body.page-node-69').length){
  1668.         $('#slides').superslides({
  1669.             hashchange: false,
  1670.             inherit_width_from: '.wide-container',
  1671.             inherit_height_from: '.wide-container',
  1672.             play: 15000
  1673.         });
  1674.  
  1675.         $('#slides').on('mouseenter', function() {
  1676.             $(this).superslides('stop');
  1677.             console.log('Stopped');
  1678.         });
  1679.         $('#slides').on('mouseleave', function() {
  1680.             $(this).superslides('start');
  1681.             console.log('Started');
  1682.         });
  1683.     }
  1684.  
  1685.     // change cardsave text on checkout review page
  1686.     // remove the exmaple payment
  1687.     if($('body.page-checkout-review').length && $('body.page-checkout-review').length){
  1688.         $('#edit-commerce-payment-payment-method').find('.form-item-commerce-payment-payment-method').children('label[for=edit-commerce-payment-payment-method-commerce-payment-csavecommerce-payment-commerce-payment-csave]').text('Credit/Debit Card');
  1689.  
  1690.         //$('#edit-commerce-payment-payment-method').find('.form-item-commerce-payment-payment-method').children('label[for=edit-commerce-payment-payment-method-commerce-payment-examplecommerce-payment-commerce-payment-example]').parents('.form-item-commerce-payment-payment-method').hide();
  1691.  
  1692.         //edit-commerce-payment-payment-method-commerce-payment-examplecommerce-payment-commerce-payment-example
  1693.     }
  1694.  
  1695.     // replace the value of the submit button on the last checkout page, needed the php to do this aswell otherwise it wouldnt work :-S
  1696.     if($('body.page-checkout-review').length){
  1697.         $('#edit-continue').attr('value', 'Make Purchase');
  1698.     }
  1699.  
  1700.     //Change the layout of boxes for info hub
  1701.     // if($('body.node-type-info-hub').length){
  1702.     //     $('.file_download_box_parent').click(function(e){
  1703.     //         e.preventDefault();
  1704.     //         if($('.file_download_box_parent').hasClass('open')){
  1705.     //             $(this).removeClass('open');
  1706.     //             $('.file_download_box_year_container').hide(0);
  1707.     //             $(this).siblings('.file_download_box_parent').fadeIn(50);
  1708.     //         }
  1709.     //         else{
  1710.     //             $(this).addClass('open');
  1711.     //             var this_class = $(this).attr('class');
  1712.     //             var this_classes_parts = this_class.split(' ');
  1713.     //             var this_class = this_classes_parts[0];
  1714.     //             $(this).siblings('.file_download_box_parent').hide(0);
  1715.     //             $('.file_download_box_year_container.'+this_class).fadeIn(250);
  1716.     //         }
  1717.     //     });
  1718.     // }
  1719.  
  1720.     // google translate
  1721.     //$('#goog-gt-tt').remove();
  1722.     // close language overlay
  1723.     /*$('.goog-te-menu2-item, .close_languages').click(function(event) {
  1724.         $('#language_overlay').fadeToggle(250);
  1725.         $('.goog-te-menu-frame').fadeToggle(250);
  1726.         $('.goog-te-menu-frame').css({'visibility':'hidden'});
  1727.         clearInterval(googlecookietimer);
  1728.     });*/
  1729.     // open language overlay
  1730.     /*var googlecookietimer = null;
  1731.     var googlecookieinterval = 1000;
  1732.     var googlecookievalue = readCookie('googtrans');
  1733.     $('#menu-1542-1,.change_language').click(function(event) {
  1734.         event.preventDefault();
  1735.         var originalgooglecookievalue = readCookie('googtrans');
  1736.         $('.goog-te-menu-frame').css({'visibility':'visible'});
  1737.         $('.goog-te-menu-frame').show();
  1738.         $('.goog-te-gadget-simple').hide(0);
  1739.         $('.goog-te-menu-frame').show(0);
  1740.         $('#language_overlay').fadeToggle(250);
  1741.         $('.goog-te-menu-frame').css({
  1742.             'position': 'absolute',
  1743.             'top': '100px',
  1744.             'box-shadow':'none'
  1745.         });
  1746.         $('.goog-te-menu2').css({
  1747.             'border': 'none !important',
  1748.         });
  1749.         $('.goog-te-menu2-item div, .goog-te-menu2-item:link div, .goog-te-menu2-item:visited div, .goog-te-menu2-item:active div').css({
  1750.             'color': '#ef4937 !important',
  1751.         });
  1752.         var window_width = $(window).width();
  1753.         var iframe_width = $('.goog-te-menu-frame').width();
  1754.         var diff_margin = ((window_width - iframe_width)/2);
  1755.         $('.goog-te-menu-frame').css({
  1756.             'left': diff_margin+'px'
  1757.         })
  1758.         $('.goog-te-menu-frame:nth-of-type(2)').css({
  1759.             'display': 'none !important'
  1760.         })
  1761.  
  1762.         googlecookietimer = setInterval(function () {
  1763.             googlecookievalue = readCookie('googtrans');
  1764.             if(originalgooglecookievalue != googlecookievalue){
  1765.                 var chosen_language = googlecookievalue.split('/');
  1766.                 console.log('Language changed to - '+googlecookievalue+' ('+language_codes[chosen_language[2]]+')');
  1767.                 $('.close_languages').trigger('click');
  1768.                 $('.change_language').find('a').html(language_codes[chosen_language[2]]);
  1769.                 $('#menu-1542-1').find('a').html(chosen_language[2]);
  1770.                 console.log(chosen_language[2]);
  1771.             }
  1772.             else{
  1773.                 //console.log('Language has not been changed');
  1774.             }
  1775.         }, googlecookieinterval);
  1776.     });*/
  1777.  
  1778.     /*googlecookievalue = readCookie('googtrans');
  1779.     var chosen_language = googlecookievalue.split('/');
  1780.     if(googlecookievalue){
  1781.         $('#menu-1542-1').find('a').html(chosen_language[2]);
  1782.     }
  1783.     else{
  1784.         $('#menu-1542-1').find('a').html('EN');
  1785.     }*/
  1786.  
  1787.     /*function readCookie(name) {
  1788.         var c = document.cookie.split('; '),
  1789.         cookies = {}, i, C;
  1790.  
  1791.         for (i = c.length - 1; i >= 0; i--) {
  1792.             C = c[i].split('=');
  1793.             cookies[C[0]] = C[1];
  1794.         }
  1795.  
  1796.         return cookies[name];
  1797.     }
  1798.     function listCookies() {
  1799.         var theCookies = document.cookie.split(';');
  1800.         var aString = '';
  1801.         for (var i = 1 ; i <= theCookies.length; i++) {
  1802.             aString += i + ' ' + theCookies[i-1] + "\n";
  1803.         }
  1804.         console.log(aString);
  1805.     }
  1806.     //listCookies();
  1807.     var language_codes = new Array();
  1808.     language_codes['ak'] = 'Akan';
  1809.     language_codes['sq'] = 'Albanian';
  1810.     language_codes['am'] = 'Amharic';
  1811.     language_codes['ar'] = 'Arabic';
  1812.     language_codes['hy'] = 'Armenian';
  1813.     language_codes['az'] = 'Azerbaijani';
  1814.     language_codes['eu'] = 'Basque';
  1815.     language_codes['be'] = 'Belarusian';
  1816.     language_codes['bem'] = 'Bemba';
  1817.     language_codes['bn'] = 'Bengali';
  1818.     language_codes['bh'] = 'Bihari';
  1819.     language_codes['bs'] = 'Bosnian';
  1820.     language_codes['br'] = 'Breton';
  1821.     language_codes['bg'] = 'Bulgarian';
  1822.     language_codes['km'] = 'Cambodian';
  1823.     language_codes['ca'] = 'Catalan';
  1824.     language_codes['chr'] = 'Cherokee';
  1825.     language_codes['ny'] = 'Chichewa';
  1826.     language_codes['zh-CN'] = 'Chinese (Simplified)';
  1827.     language_codes['zh-TW'] = 'Chinese (Traditional)';
  1828.     language_codes['co'] = 'Corsican';
  1829.     language_codes['hr'] = 'Croatian';
  1830.     language_codes['cs'] = 'Czech';
  1831.     language_codes['da'] = 'Danish';
  1832.     language_codes['nl'] = 'Dutch';
  1833.     language_codes['xx-elmer'] = 'Elmer Fudd';
  1834.     language_codes['en'] = 'English';
  1835.     language_codes['eo'] = 'Esperanto';
  1836.     language_codes['et'] = 'Estonian';
  1837.     language_codes['ee'] = 'Ewe';
  1838.     language_codes['fo'] = 'Faroese';
  1839.     language_codes['tl'] = 'Filipino';
  1840.     language_codes['fi'] = 'Finnish';
  1841.     language_codes['fr'] = 'French';
  1842.     language_codes['fy'] = 'Frisian';
  1843.     language_codes['gaa'] = 'Ga';
  1844.     language_codes['gl'] = 'Galician';
  1845.     language_codes['ka'] = 'Georgian';
  1846.     language_codes['de'] = 'German';
  1847.     language_codes['el'] = 'Greek';
  1848.     language_codes['gn'] = 'Guarani';
  1849.     language_codes['gu'] = 'Gujarati';
  1850.     language_codes['xx-hacker'] = 'Hacker';
  1851.     language_codes['ht'] = 'Haitian Creole';
  1852.     language_codes['ha'] = 'Hausa';
  1853.     language_codes['haw'] = 'Hawaiian';
  1854.     language_codes['iw'] = 'Hebrew';
  1855.     language_codes['hi'] = 'Hindi';
  1856.     language_codes['hu'] = 'Hungarian';
  1857.     language_codes['is'] = 'Icelandic';
  1858.     language_codes['ig'] = 'Igbo';
  1859.     language_codes['id'] = 'Indonesian';
  1860.     language_codes['ia'] = 'Interlingua';
  1861.     language_codes['ga'] = 'Irish';
  1862.     language_codes['it'] = 'Italian';
  1863.     language_codes['ja'] = 'Japanese';
  1864.     language_codes['jw'] = 'Javanese';
  1865.     language_codes['kn'] = 'Kannada';
  1866.     language_codes['kk'] = 'Kazakh';
  1867.     language_codes['rw'] = 'Kinyarwanda';
  1868.     language_codes['rn'] = 'Kirundi';
  1869.     language_codes['xx-klingon'] = 'Klingon';
  1870.     language_codes['kg'] = 'Kongo';
  1871.     language_codes['ko'] = 'Korean';
  1872.     language_codes['kri'] = 'Krio (Sierra Leone)';
  1873.     language_codes['ku'] = 'Kurdish';
  1874.     language_codes['ckb'] = 'Kurdish (Soranî)';
  1875.     language_codes['ky'] = 'Kyrgyz';
  1876.     language_codes['lo'] = 'Laothian';
  1877.     language_codes['la'] = 'Latin';
  1878.     language_codes['lv'] = 'Latvian';
  1879.     language_codes['ln'] = 'Lingala';
  1880.     language_codes['lt'] = 'Lithuanian';
  1881.     language_codes['loz'] = 'Lozi';
  1882.     language_codes['lg'] = 'Luganda';
  1883.     language_codes['ach'] = 'Luo';
  1884.     language_codes['mk'] = 'Macedonian';
  1885.     language_codes['mg'] = 'Malagasy';
  1886.     language_codes['ms'] = 'Malay';
  1887.     language_codes['ml'] = 'Malayalam';
  1888.     language_codes['mt'] = 'Maltese';
  1889.     language_codes['mi'] = 'Maori';
  1890.     language_codes['mr'] = 'Marathi';
  1891.     language_codes['mfe'] = 'Mauritian Creole';
  1892.     language_codes['mo'] = 'Moldavian';
  1893.     language_codes['mn'] = 'Mongolian';
  1894.     language_codes['ne'] = 'Nepali';
  1895.     language_codes['pcm'] = 'Nigerian Pidgin';
  1896.     language_codes['nso'] = 'Northern Sotho';
  1897.     language_codes['no'] = 'Norwegian';
  1898.     language_codes['nn'] = 'Norwegian (Nynorsk)';
  1899.     language_codes['oc'] = 'Occitan';
  1900.     language_codes['or'] = 'Oriya';
  1901.     language_codes['om'] = 'Oromo';
  1902.     language_codes['ps'] = 'Pashto';
  1903.     language_codes['fa'] = 'Persian';
  1904.     language_codes['pl'] = 'Polish';
  1905.     language_codes['pa'] = 'Punjabi';
  1906.     language_codes['qu'] = 'Quechua';
  1907.     language_codes['ro'] = 'Romanian';
  1908.     language_codes['rm'] = 'Romansh';
  1909.     language_codes['nyn'] = 'Runyakitara';
  1910.     language_codes['ru'] = 'Russian';
  1911.     language_codes['gd'] = 'Scots Gaelic';
  1912.     language_codes['sr'] = 'Serbian';
  1913.     language_codes['sh'] = 'Serbo-Croatian';
  1914.     language_codes['st'] = 'Sesotho';
  1915.     language_codes['tn'] = 'Setswana';
  1916.     language_codes['crs'] = 'Seychellois Creole';
  1917.     language_codes['sn'] = 'Shona';
  1918.     language_codes['sd'] = 'Sindhi';
  1919.     language_codes['si'] = 'Sinhalese';
  1920.     language_codes['sk'] = 'Slovak';
  1921.     language_codes['sl'] = 'Slovenian';
  1922.     language_codes['so'] = 'Somali';
  1923.     language_codes['es'] = 'Spanish';
  1924.     language_codes['su'] = 'Sundanese';
  1925.     language_codes['sw'] = 'Swahili';
  1926.     language_codes['sv'] = 'Swedish';
  1927.     language_codes['tg'] = 'Tajik';
  1928.     language_codes['ta'] = 'Tamil';
  1929.     language_codes['tt'] = 'Tatar';
  1930.     language_codes['te'] = 'Telugu';
  1931.     language_codes['th'] = 'Thai';
  1932.     language_codes['ti'] = 'Tigrinya';
  1933.     language_codes['to'] = 'Tonga';
  1934.     language_codes['lua'] = 'Tshiluba';
  1935.     language_codes['tum'] = 'Tumbuka';
  1936.     language_codes['tr'] = 'Turkish';
  1937.     language_codes['tk'] = 'Turkmen';
  1938.     language_codes['tw'] = 'Twi';
  1939.     language_codes['ug'] = 'Uighur';
  1940.     language_codes['uk'] = 'Ukrainian';
  1941.     language_codes['ur'] = 'Urdu';
  1942.     language_codes['uz'] = 'Uzbek';
  1943.     language_codes['vi'] = 'Vietnamese';
  1944.     language_codes['cy'] = 'Welsh';
  1945.     language_codes['wo'] = 'Wolof';
  1946.     language_codes['xh'] = 'Xhosa';
  1947.     language_codes['yi'] = 'Yiddish';
  1948.     language_codes['yo'] = 'Yoruba';
  1949.     language_codes['zu'] = 'Zulu';*/
  1950.  
  1951. });
  1952.  
  1953. function ValAddressType()
  1954. {
  1955.     var SelectedAddress = jQuery('#PreferredMailingAddress').val();
  1956.     var Warning;
  1957.     var Cancel;
  1958.  
  1959.     //alert('Selected Address: '+SelectedAddress);
  1960.  
  1961.     Cancel  = false;
  1962.     Warning = '';
  1963.  
  1964.     switch(SelectedAddress)
  1965.     {
  1966.         case 'Business Address':
  1967.             if (jQuery('input[name=CompanyName]').val() == "")
  1968.             {
  1969.                 Warning = Warning + 'Please enter a Company Name to use Business Address<br />';  
  1970.                 Cancel  = true;
  1971.             }
  1972.  
  1973.             if (jQuery('input[name="CompanyAddress1"]').val() == "")
  1974.             {
  1975.                 Warning = Warning + 'Please enter the First Line of Your Business Address<br />';  
  1976.                 Cancel  = true;
  1977.             }
  1978.  
  1979.             if (jQuery('input[name="CompanyTown"]').val() == "")
  1980.             {
  1981.                 Warning = Warning + 'Please enter a Town for Your Business Address<br />';  
  1982.                 Cancel  = true;
  1983.             }
  1984.  
  1985.             if (jQuery('input[name="CompanyCounty"]').val() == "")
  1986.             {
  1987.                 Warning = Warning + 'Please enter a County for Your Business Address<br />';  
  1988.                 Cancel  = true;
  1989.             }
  1990.  
  1991.             if (jQuery('input[name="CompanyCountry"]').val() == "")
  1992.             {
  1993.                 Warning = Warning + 'Please enter a Country for Your Business Address<br />';  
  1994.                 Cancel  = true;
  1995.             }
  1996.  
  1997.             if (jQuery('input[name="CompanyPostcode"]').val() == "")
  1998.             {
  1999.                 Warning = Warning + 'Please enter a Postcode for Your Business Address<br />';  
  2000.                 Cancel  = true;
  2001.             }
  2002.  
  2003.         break;
  2004.  
  2005.  
  2006.         case 'Home Address':
  2007.            
  2008.             if (jQuery('input[name="Address1"]').val() == "")
  2009.             {
  2010.                 Warning = Warning + 'Please enter the First Line of Your Home Address<br />';  
  2011.                 Cancel  = true;
  2012.             }
  2013.  
  2014.             if (jQuery('input[name="Town"]').val() == "")
  2015.             {
  2016.                 Warning = Warning + 'Please enter a Town for Your Home Address<br />';  
  2017.                 Cancel  = true;
  2018.             }
  2019.  
  2020.             if (jQuery('input[name="County"]').val() == "")
  2021.             {
  2022.                 Warning = Warning + 'Please enter a County for Your Home Address<br />';  
  2023.                 Cancel  = true;
  2024.             }
  2025.  
  2026.             if (jQuery('input[name="Country"]').val() == "")
  2027.             {
  2028.                 Warning = Warning + 'Please enter a Country for Your Home Address<br />';  
  2029.                 Cancel  = true;
  2030.             }
  2031.  
  2032.             if (jQuery('input[name="Postcode"]').val() == "")
  2033.             {
  2034.                 Warning = Warning + 'Please enter a Postcode for Your Home Address<br />';  
  2035.                 Cancel  = true;
  2036.             }
  2037.         break;
  2038.     }
  2039.  
  2040.     if(Boolean(Cancel) === true)
  2041.     {
  2042.         jQuery('#errors').html(Warning);
  2043.         jQuery('#errors').closest( "article").css('height','auto');
  2044.         return false;
  2045.     }
  2046.  
  2047.     else
  2048.     {
  2049.         return true;
  2050.     }
  2051. }
  2052.  
  2053. function CheckCountry(Action)
  2054. {
  2055.  
  2056.     switch(Action)
  2057.     {
  2058.         case false:
  2059.        
  2060.             switch(jQuery("#PreferredMailingAddress").val())
  2061.             {
  2062.                 case 'Home Address':
  2063.                    
  2064.                     console.log('Home Address');
  2065.                    
  2066.                     if(typeof OrigSlection == 'undefined')
  2067.                     {
  2068.                         OrigSlection = 'Business Address';
  2069.                         console.log('Home Address IF 1');      
  2070.                     }
  2071.  
  2072.                     if(jQuery('select[name=Country]').val().toLowerCase() == jQuery('input[name=OrigCountry]').val().toLowerCase())
  2073.                     {
  2074.                         console.log('Home Address IF 2');
  2075.  
  2076.                         if(OrigSlection == 'Home Address')
  2077.                         {
  2078.                             jQuery('#changed-tier').hide();
  2079.                             console.log('Home Address IF 3');
  2080.                         }
  2081.                     }
  2082.  
  2083.                     else if(jQuery('select[name=Country]').val().toLowerCase() != jQuery('input[name=OrigCountry]').val().toLowerCase())
  2084.                     {
  2085.                         jQuery('#changed-tier').show();
  2086.                         console.log('Home Address IF 4');
  2087.                     }
  2088.  
  2089.                 break;
  2090.  
  2091.                 case 'Business Address':
  2092.  
  2093.                     console.log('Business Address');
  2094.                    
  2095.                     if(typeof OrigSlection == 'undefined')
  2096.                     {
  2097.                         OrigSlection = 'Home Address';
  2098.                         console.log('Business Address IF 1');
  2099.                     }
  2100.  
  2101.                     if(jQuery('select[name=CompanyCountry]').val().toLowerCase() == jQuery('input[name=OrigCompanyCountry]').val().toLowerCase())
  2102.                     {
  2103.                         console.log('Business Address IF 2');
  2104.  
  2105.                         if(OrigSlection == 'Business Address')
  2106.                         {
  2107.                             jQuery('#changed-tier').hide();
  2108.                             console.log('Business Address IF 3');
  2109.                         }
  2110.                     }
  2111.  
  2112.                     else if(jQuery('select[name=CompanyCountry]').val().toLowerCase() != jQuery('input[name=OrigCompanyCountry]').val().toLowerCase())
  2113.                     {
  2114.                         console.log('Business Address IF 4');
  2115.                         jQuery('#changed-tier').show();
  2116.                     }
  2117.  
  2118.                 break;
  2119.             }
  2120.  
  2121.         break;
  2122.  
  2123.         case 'Company':
  2124.             if(jQuery("#PreferredMailingAddress").val() == 'Business Address')
  2125.             {
  2126.                 console.log('Company 1');
  2127.                 if(jQuery('select[name=CompanyCountry]').val().toLowerCase() != jQuery('input[name=OrigCompanyCountry]').val().toLowerCase())
  2128.                 {
  2129.                     jQuery('#changed-tier').show();
  2130.                     console.log('Company 2');
  2131.                 }
  2132.  
  2133.                 else
  2134.                 {
  2135.                     jQuery('#changed-tier').hide();
  2136.                     console.log('Company 3');
  2137.                 }
  2138.             }
  2139.         break;
  2140.  
  2141.         default:
  2142.             if(jQuery("#PreferredMailingAddress").val() == 'Home Address')
  2143.             {
  2144.                 console.log('Default 1');
  2145.  
  2146.                 if(jQuery('select[name=Country]').val().toLowerCase() != jQuery('input[name=OrigCountry]').val().toLowerCase())
  2147.                 {
  2148.                     jQuery('#changed-tier').show();
  2149.                     console.log('Default 2');
  2150.                 }
  2151.  
  2152.                 else
  2153.                 {
  2154.                     jQuery('#changed-tier').hide();
  2155.                     console.log('Default 3');
  2156.                 }
  2157.             }
  2158.         break;
  2159.     }
  2160.  
  2161.     jQuery("article").css('height','auto');
  2162.  
  2163.     if(jQuery('#changed-tier').is(':visible'))
  2164.     {
  2165.         jQuery('#changed-tier input').attr('required','required');      
  2166.     }
  2167.  
  2168.     else
  2169.     {
  2170.         jQuery('#changed-tier input').removeAttr('required');
  2171.     }
  2172. }
  2173.  
  2174.  
  2175.  
  2176. jQuery(document).ready(function()
  2177. {
  2178.     var CellValue;
  2179.  
  2180.     jQuery('.page-cart .views-field-line-item-title').each(function(){
  2181.         CellValue = jQuery.trim(jQuery(this).html());
  2182.  
  2183.         if(CellValue.toLowerCase().indexOf('membership') >= 0)
  2184.         {
  2185.             console.log('True');
  2186.             jQuery(this).html(CellValue+'<br /><span style="font-size:12px; color:#fff;">If you delete your membership application from the cart you will have to start again.</span>');            
  2187.         }
  2188.  
  2189.         console.log(CellValue);
  2190.     });
  2191.  
  2192.     if(jQuery('select.country').length){
  2193.         jQuery('select.country')[0].setAttribute("onchange","ShowDD(this)");
  2194.  
  2195.         jQuery(document).click(function()
  2196.         {
  2197.             jQuery('select.country')[0].setAttribute("onchange","ShowDD(this)");
  2198.         });
  2199.     }
  2200.    
  2201.    
  2202.     jQuery('input.delete-line-item').click(function(event)
  2203.     {
  2204.         var FieldText = jQuery.trim(jQuery(this).closest('tr').find('.views-field-line-item-title').html());
  2205.  
  2206.         console.log('@'+FieldText+'@');
  2207.  
  2208.         //views-field-line-item-title
  2209.         if(FieldText == 'Application Fee')
  2210.         {
  2211.             event.preventDefault();
  2212.             alert('The application fee cannot be deleted. If you have a promotional code you will be asked to enter it at the next stage.');
  2213.         }
  2214.     });
  2215.  
  2216.     if(jQuery('#edit-commerce-payment-payment-details-account-name').length < 1)
  2217.     {
  2218.         //console.log('DD True');
  2219.         jQuery('#edit-commerce-payment-payment-method-commerce-directdebitcommerce-payment-commerce-directdebit').closest('div').hide();
  2220.     }
  2221.  
  2222.     else
  2223.     {
  2224.         jQuery('#edit-commerce-payment-payment-details-sort-code').hide();
  2225.  
  2226.         jQuery('.form-item-commerce-payment-payment-details-sort-code').append('<input type="text" name="sort1" id="sort1" style="width:7%; margin-top:10px;" maxlength="2" onkeyup="PopulateSortCode(1);" /> - <input type="text" name="sort2" id="sort2" style="width:7%; margin-top:10px;" maxlength="2" onkeyup="PopulateSortCode(2);" /> - <input type="text" name="sort3" id="sort3" style="width:7%; margin-top:10px;" maxlength="2" onkeyup="PopulateSortCode(3);" />');
  2227.        
  2228.         jQuery('#edit-commerce-payment-payment-details-account-number').attr('maxlength','8');
  2229.  
  2230.         jQuery('#edit-commerce-payment-payment-details-account-name').attr('maxlength','18');        
  2231.  
  2232.         jQuery('#edit-commerce-payment-payment-details-account-number, #sort1, #sort2, #sort3').numeric();  
  2233.     }
  2234.  
  2235.     //Hide continue button on click of either option
  2236.     jQuery('#left_col input, #edit-commerce-payment input').live("click",function(event){
  2237.        
  2238.         if((event.target.id == 'edit-commerce-payment-payment-details-only-person-1') || (event.target.id == 'edit-commerce-payment-payment-details-confirm-1'))
  2239.         {
  2240.             jQuery('#edit-continue').hide();
  2241.             jQuery('#edit-commerce-coupon').hide();
  2242.         }
  2243.  
  2244.         else
  2245.         {
  2246.             jQuery('#edit-continue').show();
  2247.             jQuery('#edit-commerce-coupon').show();
  2248.         }
  2249.  
  2250.     });
  2251.  
  2252.     jQuery('.checkout-continue').click(function(event)
  2253.     {
  2254.         ShowAlert = false;
  2255.  
  2256.         //check if sort code field is available.
  2257.         if(jQuery('#edit-commerce-payment-payment-details-sort-code').length > 0)
  2258.         {
  2259.             var textarea = jQuery('#edit-commerce-payment-payment-details-sort-code');
  2260.  
  2261.             if(jQuery('#edit-commerce-payment-payment-details-sort-code').val().length != 6)
  2262.             {
  2263.                 event.preventDefault();
  2264.                 ShowAlert = true;
  2265.             }
  2266.  
  2267.  
  2268.             if(jQuery('#edit-commerce-payment-payment-details-account-number').val().length != 8)
  2269.             {
  2270.                 event.preventDefault();
  2271.                 ShowAlert = true;
  2272.             }
  2273.  
  2274.  
  2275.             if(ShowAlert)
  2276.             {
  2277.                 alert('Please ensure your bank details are correct.');
  2278.             }
  2279.         }
  2280.  
  2281.         jQuery('.checkout-continue').removeAttr('disabled');
  2282.     });
  2283.  
  2284.     if(jQuery("select.country").val() == 'GB')
  2285.     {
  2286.         jQuery('#edit-commerce-payment-payment-method-commerce-directdebitcommerce-payment-commerce-directdebit').closest('div').show();
  2287.         console.log('UK True');
  2288.     }
  2289.  
  2290.     else
  2291.     {
  2292.         jQuery('#edit-commerce-payment-payment-method-commerce-directdebitcommerce-payment-commerce-directdebit').closest('div').hide();
  2293.     }
  2294.     //edit-commerce-payment-payment-details-confirm-0
  2295. });
  2296.  
  2297. function PopulateSortCode(EleCount)
  2298. {
  2299.     if(jQuery('#sort'+EleCount).val().length == 2)
  2300.     {
  2301.         jQuery('#sort'+(EleCount+1)).focus();
  2302.     }
  2303.  
  2304.  
  2305.     jQuery('#edit-commerce-payment-payment-details-sort-code').val(jQuery('#sort1').val()+jQuery('#sort2').val()+jQuery('#sort3').val());
  2306. }
  2307.  
  2308. function ShowDD(Ele)
  2309. {
  2310.     if(jQuery(Ele).val() == 'GB')
  2311.     {
  2312.         jQuery('#edit-commerce-payment-payment-method-commerce-directdebitcommerce-payment-commerce-directdebit').closest('div').show();
  2313.     }
  2314.  
  2315.     else
  2316.     {
  2317.        jQuery('#edit-commerce-payment-payment-method-commerce-directdebitcommerce-payment-commerce-directdebit').closest('div').hide();
  2318.     }
  2319. }
Add Comment
Please, Sign In to add comment