/* collapsible accordion
-------------------------------------------------------------------*/
jQuery(document).ready(function($) {
    $(".collapse_content").hide();
    $(".collapse_content_open").show();
    $('.collapse_content_open').prev('h3').addClass('active')
        $(".collapse h3").each(function() {

        $(this).click(function() {
            if ($(this).hasClass("active")) {
                $(this).removeClass("active");
                $(this).next().slideUp("fast");
            } else {
                $(this).addClass("active");
                $(this).next().slideDown("fast");
            }
        });
    });

    $('.collapse-expand').click(function() {
        if ($(this).hasClass("active")) {
            $(this).removeClass("active");
		    
			$(".collapse h3").each(function() {
				$(this).removeClass("active");	     
        	});
			$('.collapse h3').next().hide();
        	$(".collapse-expand").html("+expand all");
        } else {
            $(this).addClass("active");
			 $(".collapse h3").each(function() {
				$(this).addClass("active");	
        });
            $('.collapse h3').next().show();
            $(".collapse-expand").html("-collapse all");
        }
    });

});

/* tabbed content
-------------------------------------------------------------------*/

$(document).ready(function() {

    // When a link is clicked
    $("a.tab").click(function() {

        // switch all tabs off
        $(".tabbed_area .active").removeClass("active");

        // switch this tab on
        $(this).addClass("active");

        // slide all content up
        $(".tab_content").hide();

        // slide this content up
        var content_show = $(this).attr("title");
        $("#" + content_show).show();

    });

});

/* show/hide the my account contact form 
-------------------------------------------------------------------*/

jQuery(document).ready(function($) {
    $('a.btn_contact_aha').click(function() {
        if ($(this).hasClass("active")) {
            $(this).removeClass("active");
            $('#contact_aha').fadeOut("slow");
        } else {
            $(this).addClass("active");
            $('#contact_aha').fadeIn("slow");
        }
    });
});

/* show/hide the my account contact form if errors are returned
-------------------------------------------------------------------*/

jQuery(document).ready(function($) {
    $('#contact_aha').each(function() {
        if ($('#contact_aha span').hasClass("EditingFormErrorLabel")) {
            $('a.btn_contact_aha').addClass("active");
            $(this).show();
        }
		    if ($('#contact_aha span').hasClass("EditingFormInfoLabel")) {
            $('div#myAccContact').remove();
            $(this).show();
        }
		
		
    });
});

/* stripe the purchases and expired purchases divs

jQuery(document).ready(function($) {
$('#tab_content_1 div.entry:even').addClass('alt');

   });

-------------------------------------------------------------------*/

/* my account no product message / removal of expired purchases header if no products present
-------------------------------------------------------------------*/
jQuery(document).ready(function($) {
								
								
/*								
    $('#tab_content_1').each(function() {
        if ($('#tab_content_1 div').hasClass('.purchase')) {
			} else {
                   $('#tab_content_1').prepend('<br /><br /><ul class="icon_list"><li class="attn"><strong>You do not have any purchased products currently available.</strong></li></ul><div class="clr"></div>');
		}
    });
*/									  
	
									  
	
	
if( $('#tab_content_1 div').hasClass('expired') ) {	 } else { 
	$('.hdr_2').remove();	
}
	
});



/* my account error message when purchase history bug is present
-------------------------------------------------------------------*/

jQuery(document).ready(function($) {
    if ($('table#plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneContent_RoyMorganMemberOrders_gridOrders').length) {
        // something happens when the table is present
        } else {
        $('#tab_content_2').html('<br /><br /><div id="scrollBox" class="sidebox"><div class="boxhead"><div>&nbsp;</div></div><div class="boxbody"><ul class="icon_list"><li class="attn"><strong>Sorry something has gone wrong.</strong><br />To view your purchase history please click the &lsquo;My Account&rsquo; link again.</li></ul><div class="clr"></div></div></div>');
    }
});



/* product feedbdack form script
-------------------------------------------------------------------*/

jQuery(document).ready(function($) {
    // Insert product name and sku into product feedback form								
    var productName = $('.info h1').text();
    var sku = $('span.number-product').text();
    $("input.form_productName").val(productName).addClass('disabled');
    $("input.form_sku").val(sku).addClass('disabled');
    // if errors are present show the form - if submit successfull show the form for 7 seconds								
    $('#browse_contact_box').each(function() {
        if ($('#browse_contact_box span').hasClass('ErrorLabel')) {
            $('a.open-popup').click();
        } else if ($('#browse_contact_box span').hasClass('EditingFormInfoLabel')) {
            //hide heading and red text on submit
            $('#browse_contact_box h2').hide();
            $('#browse_contact_box p.red').hide();
            //fire the lightbox script				
            $('a.open-popup').click();
            // when the lightbox has submitted allow close on AnyClick				
            $('#browse_contact_box').addClass('closeBoxAnyClick');
            //lightbox is shown for 7 seconds - change the delay value in milliseconds to increase or decrease				
            $('a.close').delay(7000).queue(function() {
                $('a.close').click();
                $(this).dequeue();
            })
            }
    });
});

/* close the lightbox when faded area is clicked - 
.addClass('.closeBoxOuterClick') will close the box when the faded area is clicked
.addClass('.closeBoxAnyClick') will close the box when the faded area or the lightbox div is clicked
---------------------------------------------------------------------------------*/

jQuery(document).ready(function($) {
    if ($('#browse_contact_box').hasClass('closeBoxOuterClick')) {
        $('.lightbox-fader').click(function() {
            $('a.close').click();
        });
    } else if ($('#browse_contact_box').hasClass('closeBoxAnyClick')) {
        $('.lightbox-fader, #browse_contact_box').click(function() {
            $('a.close').click();
        });
    }
});

/* Remove text field default value on focus - replace if nothing new has been typed */
/*http://buildinternet.com/2009/01/changing-form-input-styles-on-focus-with-jquery/ 
---------------------------------------------------------------------------------*/

// to fire this script add class .focusFieldRemove to the text input
$(document).ready(function() {
    $('.focusFieldRemove').addClass("idleField");

    $('.focusFieldRemove').focus(function() {
        // alert ("focus true");
        $(this).removeClass("idleField").addClass("focusField");
        if (this.value == this.defaultValue) {
            this.value = '';
        }
        if (this.value != this.defaultValue) {
            this.select();
        }
    });
    //the BELOW section is not working need to debug the blur and if statement.	 
    $('.focusFieldRemove').blur(function() {
	
        $(this).removeClass("focusField").addClass("idleField");

        if ($.trim(this.value == '')) {
            this.value = (this.defaultValue ? this.defaultValue: '');
        }
    });
});

/* hide the contact form instruction when the form is submitted - used on Contact page only
---------------------------------------------------------------------------------*/

$(document).ready(function() {
    if ($('#plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneContent_MainContent_BizFormControl1_Bizform1 span').hasClass('EditingFormInfoLabel')) {
        $('p.contact_form_ins').hide();
    }
});
