/**
 * jQuery Placeholder Labels
 *
 * Pass a collection of label elements in, and it will set the placeholder attribute of the associated (via the "for" atttibute) input to the value of the label.
 * If placeholder attribute is not supported, it will (what? set the position to absolute? Set the class so external CSS can be used?)
 * If the "for" attribute is empty, it will act on the next input element.
 *
 * @name placeholderLabels
 * @type jQuery
 * @requires jQuery 1.5.1
 * @author   Designkitchen
 */

if ( typeof jQuery != "undefined" ) {
    (function( $ ) {
        $.fn.placeholderLabels = function() {
            /**
             * Check for native placeholder support
             *
             * @see http://diveintohtml5.org/detect.html#input-placeholder
             */

            var supportsInputPlaceholder = (function() {
                var i = document.createElement("input");
                return "placeholder" in i;
            }());

            /**
             * Keep the chain alive and bind the events
             */

            return this.each(function(i) {

                var labelEl = $( this );
                var labelElText = labelEl.text();
                var inputEl = labelEl.next( "input" );
                var inputElPlaceholder = inputEl.attr( "placeholder" );
                var inputElValue = inputEl.attr( "value" );

                /**
                 * If the placeholder attribute is supported natively and is empty,
                 * hide the label element and set the placeholder value to the text
                 * of the label.
                 */

                if ( supportsInputPlaceholder ) {
                    labelEl.hide();
                    inputEl.attr( "placeholder", labelElText );
                }

                /**
                 * If the placeholder attribute is not supported,
                 * absolutely position the label over the input,
                 * bind event handlers on focus and blur, and an
                 * extra one on click for the label.
                 */

                else {
                    labelEl.css( { "position" : "absolute", "top" : inputEl.position().top + "px" } ).show();
                    labelEl.click( function() {
                        inputEl.focus();
                    });
                    inputEl.focus( function() {
                        labelEl.hide();
                    });
                    inputEl.blur( function() {
                        if ( this.value === "" ) {
                            labelEl.show();
                        }
                    });
                }

                /**
                 * If the input has a value set, hide our label.
                 */

                if ( inputElValue ) {
                    labelEl.hide();
                }

            });

        };

    })( jQuery );
}

/**
 * WebFont Loader
 * As soon as jQuery is ready, hide H1 elements.
 */

var elementList = "#hgroup h1";

if ( typeof jQuery != "undefined" ) {
    $( elementList ).css({ "visibility" : "hidden" });
}

if ( typeof WebFont != "undefined" ) {
    try {
        WebFont.load({
            custom: {
                families: ["HelveticaNeueW01-45Ligh", "HelveticaNeueW01-46Ligh"],
                urls: ["//fast.fonts.com/cssapi/1f170ae9-f6b0-44d1-882e-9e4ce2e3bbe7.css"]
            },
//             loading: function() {
//                 console.log( "Loading!" );
//             },
//             active: function() {
//                 console.log( "Active!" );
//             },
//             inactive: function() {
//                 console.log( "Inactive!" );
//             },
//             fontloading: function(familyName, fvd) {
//                 console.log( familyName + " " + fvd + " Loading!" );
//             },
            fontactive: function(familyName, fvd) {
//                 console.log( familyName + " " + fvd + " Active!" );

                if ( familyName === "HelveticaNeueW01-45Ligh" ) {
                    if ( jQuery.support.opacity ) {
                        $( elementList ).css( "visibility", "visible").hide().fadeIn();
                    }
                    else {
                        $( elementList ).css( "visibility", "visible");
                    }
                }
            },
            fontinactive: function(familyName, fvd) {
//                 console.log( familyName + " " + fvd + " Inactive!" );

                if ( familyName === "HelveticaNeueW01-45Ligh" ) {
                    $( elementList ).css( "visibility", "visible");
                }
            }
        });
    }
    catch( err ) {
        $( elementList ).css( "visibility", "visible");
    }
}
else {
    $( elementList ).css( "visibility", "visible");
}

/**
 * Box shadow for browsers that without box-shadow support
 */

if ( typeof jQuery != "undefined" ) {
    (function( $ ) {
        $.fn.boxShadow = function() {
            return this.each(function() {
                for ( i = 1; i < 6; i++ ) {
                    $( this ).wrap('<div class="box-shadow-' + i + ' ' + $( this ).attr( "class" ) + '-box-shadow-' + i + '" />');
                }
            });
        }
    })( jQuery );
};

/**
 * Zebra striped table rows for browsers without :odd support.
 */

if ( typeof jQuery != "undefined" ) {
    (function( $ ) {
        $.fn.zebraTable = function() {
            return this.each(function() {
                $( "tbody tr", $( this ) ).filter(":even").addClass( "odd" );
            });
        }
    })( jQuery );
};

/**
 * Tab Container
 */

if ( typeof $.fn.easyTabs != "undefined" ) {
    (function( $ ) {
        $.fn.tabContainer = function() {
            return this.each(function() {

                var lastPos = '0';
				if( $('html').hasClass("ie7") || $('html').hasClass("ie6") ){
					var shouldRemoveFilter = true;
				}

                $( this ).easytabs().bind({
                    "easytabs:before": function() {
                        lastPos = $(window).scrollTop();
                    },
                    "easytabs:after": function() {
                        if ( $(window).scrollTop() != lastPos ) {
                            $(window).scrollTop(lastPos);
                        }
						if(shouldRemoveFilter){
							$('.tab-container-content.active')[0].style.removeAttribute('filter');
						}
                    }
                });
            });
        }
    })( jQuery );
};

/**
 * Accordion
 *
 * HTML: /html/modules/accordion.html
 * CSS:  /css/100-accordion.css
 *
 * A simple accordion.
 *
 * @requires jQuery
 * @author   Designkitchen
 */

if ( typeof jQuery != "undefined" ) {
    (function( $ ) {
        $.fn.accordion = function() {

            var accordionContentClass = "accordion-content";
            var accordionContentOpenClass = "accordion-content-open";
            var accordionHeadingClass = "accordion-heading";
            var accordionHeadingOpenClass = "accordion-heading-open";

            return this.each(function() {

                /**
                 * Start by hiding all the accordion content elements.
										this is only on the compare page && search results sidebar
                 */
								if ($('#content').hasClass('compare-providers') || $(this).parents('#provider-sidebar')) {
                	$( "." + accordionContentClass, this ).hide();
								};
								
                /**
                 * Set the “open” class name on the default accordion header element.
										this is for non search results page
                 */
								if (!($('#content').hasClass('compare-providers'))) {
									$( "." + accordionHeadingClass + ".accordion-default", this ).addClass( accordionHeadingOpenClass );
								}
                /**
                 * Set the “open” class name on the default accordion content element and show it.
										this is for non search results page
                 */
									if (!($('#content').hasClass('compare-providers'))) {
                		$( "." + accordionHeadingClass + ".accordion-default", this ).next( "." + accordionContentClass ).show().addClass( accordionContentOpenClass );
									};
									
								/**
								 * Set the first accordion item to open for the search results sidebar
								 */
								//if ($(this).parents('#provider-sidebar')) {
									$( "." + accordionHeadingClass + ".accordion-default", this ).addClass( accordionHeadingOpenClass );									
							//	}
                /**
                 * Listen for click events on the accordion heading elements.
                 */
                $( "." + accordionHeadingClass, this ).live('click', function( e ) {

                    e.stopImmediatePropagation();

                    var accordionContent = $( this ).next( "." + accordionContentClass );
                    var accordionParent = $( this ).parent( ".accordion" );

                    /**
                     * If the click was on a closed item…
                     */
                    if ( accordionContent.is( ":hidden" ) ) {

                        /**
                         * Close the visible accordion content element.
                         */
												
												/**
                         * If the accordian is set to have multiple open items
                         */

												if(!(accordionParent.hasClass('multiple-opens'))) {
	                        $( "." + accordionContentClass + ":visible", accordionParent ).slideUp( "fast", function() {

	                            /**
	                             * Once closed, remove the “open” class names from
	                             * the accordion content and heading elements.
	                             */
	                             $( this ).removeClass( accordionContentOpenClass ).prev( "." + accordionHeadingClass ).removeClass( accordionHeadingOpenClass );
	                        });
												}

                        /**
                         * Open the current accordion content element.
                         */
                        $( accordionContent ).slideDown( "fast", function() {

                            /**
                             * Once open, add the “open” class names to
                             * the accordion content and heading elements.
                             */
                             $( this ).addClass( accordionContentOpenClass ).prev( "." + accordionHeadingClass ).addClass( accordionHeadingOpenClass );
                        });
                    }
                    /**
                     * If the click was on an open item…
                     */
                    else {

                        /**
                         * Close the current accordion content element.
                         */
                        $( accordionContent ).slideUp( "fast", function() {

                            /**
                             * Once closed, remove the “open” class names from
                             * the accordion content and heading elements.
                             */
                             $( this ).removeClass( accordionContentOpenClass ).prev( "." + accordionHeadingClass ).removeClass( accordionHeadingOpenClass );
                        });
                    }

                });
            });
        };
    })( jQuery );
};

/**
 * Lightbox
 *
 * HTML: /html/modules/lightbox.html
 * CSS:  /css/100-lightbox.css
 *
 * @requires jQuery
 * @author   Designkitchen
 *
 */

if ( typeof jQuery != "undefined" ) {
    (function( $ ) {
        $.fn.lightbox = function() {
            return this.each(function() {
                $( this ).live('click', function( e ) {
									$('#print-options').removeClass('open');
                    e.preventDefault();
					$('#support-options').removeClass('open');
                    e.preventDefault();
										var directoryList = $('#faux-directory-list').html();
                    //$.modal('<iframe width="640" height="363" src="' + this.href +  '" frameborder="0" allowfullscreen></iframe><h3>' + this.title +  '</h3><p>' + $( ".figure-img", this ).attr( "alt" ) + '</p>', {
                      $.modal($('#faux-directory-list').html(), {
											  opacity: 50,
                        overlayId: "lightbox-overlay",
                        containerId: "lightbox-container",
                        dataId: "lightbox-data",
                        minHeight: 510,
                        minWidth: 670,
                        maxHeight: 600,
                        maxWidth: 670,
                        closeHTML: '<a id="lightbox-close">Close</a>',
                        closeClass: "lightbox-close",
                        escClose: true,
                        overlayClose: false
                    });
                });
            });
        }
    })( jQuery );
};


$(document).ready(function() {
	$('.narrow-option').change(function(){
		$('#narrow-results').submit();	
	});
	var url=location.href;
	var script = url.substring(url.lastIndexOf('/')+1)
	if(script.search('step2') != -1)
	{
		var autoCompleteOptions =
		{
			cacheLength: 1,
			scroll: true,
			minChars: 1,
			scrollHeight: 200,
			max: 10,
			autoFill: true,
			selectFirst: true,
			delay: 400,
			width: 0,
			mustMatch: false
			
		};
		if($("#provider_city-state-zip").length > 0)
			$("#provider_city-state-zip").autocomplete('get_cities.php', autoCompleteOptions);
		if($("#speciality_city-state-zip").length > 0)
			$("#speciality_city-state-zip").autocomplete('get_cities.php', autoCompleteOptions);
		if($("#medical-need_city-state-zip").length > 0)
			$("#medical-need_city-state-zip").autocomplete('get_cities.php', autoCompleteOptions);
		if($("#speciality_specialty").length > 0)
			$("#speciality_specialty").autocomplete('get_key_words.php', autoCompleteOptions);
    }
	$("#provider_city-state-zip").blur(function(){
		$("input.provider-CSZ").attr('value',$(this).val());
		if($("input.provider-CSZ").val() != "")
		{
			$( "label[for='provider-city-state-zip']" ).hide();
			$( "label[for='speciality_city-state-zip']" ).hide();
			$( "label[for='medical-need_city-state-zip']" ).hide();
		}
		else
		{
			$( "label[for='provider-city-state-zip']" ).show();
			$( "label[for='speciality_city-state-zip']" ).show();
			$( "label[for='medical-need_city-state-zip']" ).show();

		}
	});
	$("#speciality_city-state-zip").blur(function(){
		$("input.provider-CSZ").attr('value',$(this).val());
		if($("input.provider-CSZ").val() != "")
		{
			$( "label[for='provider-city-state-zip']" ).hide();
			$( "label[for='speciality_city-state-zip']" ).hide();
			$( "label[for='medical-need_city-state-zip']" ).hide();
		}
		else
		{
			$( "label[for='provider-city-state-zip']" ).show();
			$( "label[for='speciality_city-state-zip']" ).show();
			$( "label[for='medical-need_city-state-zip']" ).show();

		}
	});
	$("#medical_city-state-zip").blur(function(){
		$("input.provider-CSZ").attr('value',$(this).val());
		if($("input.provider-CSZ").val() != "")
		{
			$( "label[for='provider-city-state-zip']" ).hide();
			$( "label[for='speciality_city-state-zip']" ).hide();
			$( "label[for='medical-need_city-state-zip']" ).hide();
		}
		else
		{
			$( "label[for='provider-city-state-zip']" ).show();
			$( "label[for='speciality_city-state-zip']" ).show();
			$( "label[for='medical-need_city-state-zip']" ).show();

		}
	});
	$("#provider_city-state-zip").focusout(function(){
		$("input.provider-CSZ").attr('value',$(this).val());
                if($("input.provider-CSZ").val() != "")
		{
			$( "label[for='provider-city-state-zip']" ).hide();
			$( "label[for='speciality_city-state-zip']" ).hide();
			$( "label[for='medical-need_city-state-zip']" ).hide();
		}
		else
		{
			$( "label[for='provider-city-state-zip']" ).show();
			$( "label[for='speciality_city-state-zip']" ).show();
			$( "label[for='medical-need_city-state-zip']" ).show();

		}
	});
	$("#speciality_city-state-zip").focusout(function(){
		$("input.provider-CSZ").attr('value',$(this).val());
		if($("input.provider-CSZ").val() != "")
		{
			$( "label[for='provider-city-state-zip']" ).hide();
			$( "label[for='speciality_city-state-zip']" ).hide();
			$( "label[for='medical-need_city-state-zip']" ).hide();
		}
		else
		{
			$( "label[for='provider-city-state-zip']" ).show();
			$( "label[for='speciality_city-state-zip']" ).show();
			$( "label[for='medical-need_city-state-zip']" ).show();

		}
	});
	$("#medical_city-state-zip").focusout(function(){
		$("input.provider-CSZ").attr('value',$(this).val());
		if($("input.provider-CSZ").val() != "")
		{
			$( "label[for='provider-city-state-zip']" ).hide();
			$( "label[for='speciality_city-state-zip']" ).hide();
			$( "label[for='medical-need_city-state-zip']" ).hide();
		}
		else
		{
			$( "label[for='provider-city-state-zip']" ).show();
			$( "label[for='speciality_city-state-zip']" ).show();
			$( "label[for='medical-need_city-state-zip']" ).show();

		}
	});	
	/**
     * Placeholder Labels
     */

    if ( $.fn.placeholderLabels ) {
        $( "label.placeholder" ).placeholderLabels();
    }


    /**
     * External Links
     */

    $( "a[href^=\"http://\"], a[href^=\"https://\"]" ).attr({ target: "_blank" }).addClass( "external-link" );

    /**
     * Box shadow for browsers that without box-shadow support
     */

    if ( $.fn.boxShadow ) {
		
		//$(".no-boxshadow .bucket, .no-boxshadow #content").boxShadow();
	
		//	$(".no-boxshadow .bucket, .no-boxshadow #content, .no-boxshadow .tooltip-info").boxShadow();
		
		//$(".no-boxshadow #content, .no-boxshadow .tooltip .tooltip-info, .no-boxshadow .tooltip-info, .no-boxshadow #print-options").not(".ie7 #content, .ie7 .tooltip-info, .ie7 .tooltip .tooltip-info, .ie7 #print-options").boxShadow();
		
		//$(".no-boxshadow #page, .no-boxshadow .gradient-callout" ).not(".ie7 #page, .ie7 .gradient-callout").boxShadow();
    }

    /**
     * Zebra striped table rows for browsers without :odd support.
     */

    if ( $.fn.zebraTable ) {
        $( ".ie6 table, .ie7 table, .ie8 table" ).zebraTable();
    }

    /**
     * Tab Container
     */

    if ( $.fn.tabContainer ) {
        $( ".tab-container" ).tabContainer();
    }

    /**
     * Accordion
     */

    if ( $.fn.accordion ) {
        $( ".accordion" ).accordion();
    }

    /**
     * Timeline
     */

    if ( $.fn.timeline ) {
        $( ".timeline" ).timeline();
    }

    /**
     * LightBox
     */

		if ( $.fn.lightbox ) {
			$( "#create-directory" ).lightbox();
		}
		
		if ( $.fn.lightbox ) {
			$( ".map" ).lightbox();
		}

    /**
     * AddThis
     */

    if ( typeof addthis != "undefined" ) {
        var addthis_ui = {
//          data_ga_tracker      : "",
            ui_508_compliant     : true,
            ui_cobrand           : "BCBSA",
            ui_header_background : "#0099d8",
            ui_header_color      : "#FFFFFF",
            ui_offset_top        : -24
        };
        addthis.button( ".legal-social-media-share", addthis_ui );
        addthis.button( ".get-connected-social-media-share", addthis_ui );

        if ($(".news-list-item-share").length) {
            $(".news-list-item-share").each(function() {
            share_url = $(this).parent().parent().find(".news-list-item-heading").find("a").attr("href");
                share_title = $(this).parent().parent().find(".news-list-item-heading").find("a").text();
                $(this).attr("addthis:url", share_url);
                $(this).attr("addthis:title", share_title);
            });
        }

        addthis.button( ".news-list-item-share", addthis_ui );

    }


    /**
     * SWFobject
     */

    if ( typeof swfobject != "undefined" ) {
        swfobject.embedSWF( "../../swf/swfobject-2.2/test.swf", "flash_content", "660", "240", "10.0.0", "../../swf/swfobject-2.2/expressInstall.swf" );
    }

		/**
		 * Hospital and Doctor Finder
		 */
		
		// show/hide main choices

		$('.main-choice > fieldset input:radio').change(function() {
			//alert("Change!");
			var mainChoice = $(this).parents('.main-choice');
			mainChoice.siblings('.main-choice').find('.sub-choice').slideUp('slow');
			mainChoice.find('.sub-choice').slideDown('slow');
			mainChoice.find('.sub-choice input:text').val('');
			mainChoice.find('.sub-choice input:radio').attr('checked', false);
			if(!($('html').hasClass('ie6'))){
				mainChoice.find('.sub-choice .sub-choice').hide();
			}
			mainChoice.parents('.tab-container-content').find('.caution-network .button-link-medium').addClass('deactivated');
			mainChoice.parents('.tab-container-content').find('.caution-network p').hide();
		});
		
		$('input.sub-choice_product.has-droplist').click(function() {
			$(this).parent().siblings('.sub-choice').show();

			if($('#broker-plan').length > 0)
			{
				if($('#broker-plan').val() == '')
				{
					$('#broker-disclaimer').hide();
					$('#broker-plan').hide();
					$('#broker-mappo').attr('value','');
				}
				else
				{
					if($(this).val() == 'MCR')
					{
						var competing_plan_selected = $('#broker-plan').val();
						$.post( 'get_plans.php',{mappo:$('#broker-mappo').val(),product:'MCR',plan_selected:competing_plan_selected},
						function( data ){
							$("#broker-overlapping").html( data );	

						});	
					}
				}
			}
		});
		
		$('input:radio.sub-choice_product').click(function() {
			if($(this).val() != 'MCR')
			{
				$(this).parents('.tab-container-content').find('.caution-network .button-link-medium').removeClass('deactivated');
				$(this).parents('.tab-container-content').find('.caution-network p').show();			
			}
			if($(this).val() == 'MCR')
			{
				$(this).parents('.tab-container-content').find('.caution-network .button-link-medium').addClass('deactivated');
				$(this).parents('.tab-container-content').find('.caution-network p').hide();			
			}
		});
		$('select.mappo-plans').change(function() {
			$(this).parents('.tab-container-content').find('.caution-network .button-link-medium').removeClass('deactivated');
			$(this).parents('.tab-container-content').find('.caution-network p').show();			
		});
		
		// activate button for ones with input
		$('#member_id, #guest_temp-code').keyup(function() {
			$(this).removeClass("error");
			$('.prefix-error-message').hide();			
			if ($(this).val().length === 3) {
				if($(this).val() === "R12" || $(this).val() === "123"){
					$(this).addClass("error");
					$('.prefix-error-message').show();
				}else{
					$(this).parents('.tab-container-content').find('.caution-network .button-link-medium').removeClass('deactivated');
					$(this).parents('.tab-container-content').find('.caution-network p').show();
				}
			} else {	
				$(this).parents('.tab-container-content').find('.caution-network .button-link-medium').addClass('deactivated');
				$(this).parents('.tab-container-content').find('.caution-network p').hide();
			}
		});
		
		// activate button for step 2 and advanced search
		$('.provider-CSZ').keyup(function() {
			var tabContainer = $('input.provider-CSZ').parents('.tab-container-content');
			if(tabContainer.length > 0){
				if($(this).val().length >= 1) {
					tabContainer.find('.button-link-medium.deactivated').removeClass('deactivated');
				} else {
					tabContainer.find('.button-link-medium:eq(1)').addClass('deactivated');
				}				
			}else{
				if($(this).val().length >= 1) {
					$(this).parents('#content').find('.button-link-medium.deactivated').removeClass('deactivated');
				} else {
					$(this).parents('#content').find('.button-link-medium:eq(1)').addClass('deactivated');
				}				
			}
		});		
		
		/**
		 * Font Resizer
		 */
		
		$('ul.text-size li a').click(function(evt) {
			evt.preventDefault();
			var fontChoice = $(this).attr('id');
			
			switch(fontChoice) {
				
				case 'font-size_small' :
					$("body").css("font-size", "14px");
				break;			
				
				case 'font-size_large' :
					$("body").css("font-size", "18px");	
				break;
				
				default :
					$("body").css("font-size", "16px");
			}
			
			$('ul.text-size li.current').removeClass('current');
			$(this).parent('li').addClass('current');
		});
		
		/**
		 * Provider Prefix Popover
		 */
		
		$('.prefix-example a, .prefix-example-popover a').click(function(evt) {
			evt.preventDefault();
			$('.prefix-example-popover').toggle();
		});		
		
		/**
		 * Print Options show/hide
		 */
		
		$('#print-options .open-close').click(function(evt) {
			evt.preventDefault();
			$('#print-options').toggleClass('open');
		});
		$('#support-options .open-close').click(function(evt) {
			evt.preventDefault();
			$('#support-options').toggleClass('open');
		});

		/**
		 * Choosing Compare options
		 */
		
		$('.result-cell_compare input').click(function(evt) {
			var compareCount = $('.provider-result.compare').length;
			var compareTitle = $(this).parents('.provider-result').find('.provider-name').text();
			var compareProviderId = $(this).attr('id');
			if(compareCount < 3) {
				if($(this).parents('.provider-result').hasClass('compare')) {
					$(this).parents('.provider-result').removeClass('compare');
					$(this).next('label').html('Compare');
					$('#compare-these .compare#compare-' + compareProviderId + ' span').html('Compare Provider');
					$('#compare-these .compare#compare-' + compareProviderId).attr('id', '').removeClass('compare').addClass('empty-compare');					
				} else {	
					$(this).addClass('compare');
					$(this).parents('.provider-result').addClass('compare');
					$(this).next('label').html('Selected');
					$('#compare-these .empty-compare:first span').html(compareTitle);
					$('#compare-these .empty-compare:first').attr('id', 'compare-' + compareProviderId).addClass('compare').removeClass('empty-compare');	
				}
			} else {			
				if($(this).parents('.provider-result').hasClass('compare')) {
					$(this).removeClass('compare');
					$(this).parents('.provider-result').removeClass('compare');
					$(this).next('label').html('Compare');
					$('#compare-these .compare#compare-' + compareProviderId + ' span').html('Compare Provider');
					$('#compare-these .compare#compare-' + compareProviderId).attr('id', '').removeClass('compare').addClass('empty-compare');
				} else {				
					evt.preventDefault();
					alert('You can compare up to three providers.');
				}
			}
			
			countCompare();
			
		});
		
		$('#compare-these .open-close').click(function(evt) {
			evt.preventDefault();
			if ($(this).parent('.compare')) {
				var compareIdFull = $(this).parent('.compare').attr('id');
				var compareProviderId = compareIdFull.substr(8);
				$(this).prev('span').html('Compare Provider');
				$(this).parent('.compare').removeClass('compare').addClass('empty-compare');
				document.getElementById(compareProviderId).checked = false;
				$(compareProviderId).removeClass('compare');
				$('input#' + compareProviderId).next('label').html('Compare').parents('.provider-result').removeClass('compare');
				countCompare();	
			}			
		});
		
		// show more/less results
		
		/*$('a.show-results').click(function(evt) {
			evt.preventDefault();
			if ($(this).hasClass('show-more')) {
				$(this).parent('h6').prev('div.show-results').slideDown('slow');
				$(this).removeClass('show-more').addClass('show-less');
				$(this).html('See Less');
			} else {
				$(this).parent('h6').prev('div.show-results').slideUp('slow');
				$(this).removeClass('show-less').addClass('show-more');
				$(this).html('Show All Results');
			}
		});*/
		
		// detect show/hide
		$('a.show-results').each(function() {
			if ($(this).hasClass('show-more')) {
				$(this).parent('h6').prev('div.show-results').hide();
			}		
		});
		
		// advanced search mini-accordion
		$('.add-plus_accordion span.toggler').live('click',function() {
			$(this).parent().find('.bh_accordion-content').slideToggle('fast')
			$(this).toggleClass('open');
		});
		
		// advanced search mini-accordion select toggler 
		$('.add-plus_accordion .add-toggler').live('click',function() {
			if($(this).attr('checked')) {
				$(this).parent().next('.bh_accordion-content').find('input[type="checkbox"]').attr('checked', 'checked');
			} else {
				$(this).parent().next('.bh_accordion-content').find('input[type="checkbox"]').removeAttr('checked');
			}
		});
		
			// advanced search mini-accordion select toggler disabler
			$('.bh_accordion-content input[type="checkbox"]').live('click',function() {
				var totalCheckboxes = $(this).parents('.bh_accordion-content').find('input[type="checkbox"]').length;
				var currentlyChecked = $(this).parents('.bh_accordion-content').find('input[type="checkbox"]:checked').length;
				if (currentlyChecked != totalCheckboxes) {
					$(this).parents('.add-plus_accordion').find('.add-toggler').removeAttr('checked');
				} else if (currentlyChecked == totalCheckboxes) {
					$(this).parents('.add-plus_accordion').find('.add-toggler').attr('checked', 'checked');
				}
			})

		// clear search criteria
		$('.clear-search').live('click',function(evt) {
			evt.preventDefault();
			$('input:checkbox').each(function() {
				if(!($(this).hasClass('compare'))) {
					$(this).removeAttr('checked')
				}				
			});
			$('input:radio').each(function() {
				$(this).attr('checked', false);
			});				
			$('input[type="text"]').val('');
			$('select').val('');
			get_specialty_categories();
		});
		
		// clear/select all advanced search criteria
		$('.cb-togglers a').live('click',function(evt) {
			evt.preventDefault();
			if ($(this).hasClass('select-all')) {
				$(this).parents('.accordion-content').find('input[type="checkbox"]').attr('checked', 'checked');
				$(this).parents('.accordion-content').find('input[type="radio"]').attr('checked', 'checked');
			} else {
				$(this).parents('.accordion-content').find('input[type="checkbox"]').removeAttr('checked');
				$(this).parents('.accordion-content').find('input[type="radio"]').attr('checked', false);
				$(this).parents('.accordion-content').find('input[type="text"]').attr('value', '');
				$(this).parents('.accordion-content').find('select').attr('value', '');
			}
			if($(this).parents('.accordion-content').find('#provider-types-selection').length > 0)
				get_specialty_categories();
		})
		
		// tooltip
		$('.tooltip').hover(
			function() {
				$(this).addClass("on-top").find('.tooltip-info').show();
			}, function() {
				$(this).removeClass("on-top").find('.tooltip-info').hide();				
			}			
		);
		
		var providerDetailSelect = $('select.provider-detail-dd');
		providerDetailSelect.bind('change', function(e){
			var ddName = $(this).attr('name');
			var ddVersion = ddName.replace("-data-option", "");
			var ddDataObject = providerDetailData[ddVersion].options[$(this).val()];
			$(this).parent().next('.sub-header_two').find('p span').text(ddDataObject.detail);
			$('.dd-section').show().not('.'+ddDataObject.className).hide();
			window.location.hash = $(this).val();
			if($('option:selected', this).index() > 0){
				$('.provider-name p').show();
			}else{
				$('.provider-name p').hide();
			}
		});
		if(providerDetailSelect.length > 0){
			// Check to see if there's a hash
			var hash = window.location.hash;
			var returner = hash.substring(1);
			if(returner !== ""){
				if($('.dd-section').filter('.'+returner).length > 0){
					providerDetailSelect.val(returner);
					providerDetailSelect.trigger("change");
				}
			}else{
				// Hide all but the first section
				$('.dd-section:gt(0):not(.perf)').hide();				
			}
		}
		
		// Popup Disclaimers
		var disclaimerModalOptions = {
			opacity: 50,
			overlayId: "lightbox-overlay",
			containerId: "lightbox-container",
			dataId: "lightbox-data",
			minWidth: 670,
			maxWidth: 670,
			closeHTML: '<a id="lightbox-close">Close</a>',
			closeClass: "lightbox-close",
			escClose: true,
			overlayClose: false			
		}
		$('a.modal-disclaimer').live('click',function(evt){
			evt.preventDefault();
			$.modal($(this).next('.disclaimer-content'), disclaimerModalOptions);
		});
		$('input.modal-disclaimer').live('click',function(evt){
			if($(this).prop("checked")){
				$.modal($(this).siblings('.disclaimer-content'), disclaimerModalOptions);				
			}
		});	
		
		$("#searchform2").submit(function()
		{
			var city = '';
			var state = '';
			var zip = '';
			var address = '';
			var chosen_body_parts = '';
			
			ParseAddress($('#speciality_city-state-zip').val());
			
			var ib;
			for(ib = 1; ib <= 10; ib++)
			{
				$('#bodypart'+ib+' input:checkbox:checked').each(function()
				{
					if($(this).val() != 'on')
						chosen_body_parts += ','+$(this).val();
				});	
			}
			chosen_body_parts = chosen_body_parts.slice(1);
			
			$('input.body_parts_selection').attr('value',chosen_body_parts);
			$('input.conditions').attr('value',chosen_body_parts);
			
			address1 = $(".address1").val();
			if( address1 == ''  )
			{
				$(".address1").attr('value','');	
			}
			city = $(".city").val();
			state = $(".state").val();
			zip = $(".zip").val();
			country = $("#country-fld").val();
			if( city == city_temp )
			{
				city = '';
			}
			if( state == state_temp )
			{
				state = '';
			}
			if( zip == zip_temp )
			{
				zip = '';
			}
			
			if( validate_csz && proceed == 1 )
			{
				if( city == '' && state == '' && zip == '' )
				{
					if(address1 == "")
					{
					alert( 'Please enter City and State or Zip' );
					return false;
					}
				}
				if( city == '' && state != '' && zip == '' )
				{
					alert( 'Please enter City and State or Zip' );
					return false;
				}
				if( city != '' && state == '' && zip == '' )
				{
					alert ( 'Please enter City and State or Zip' );
					return false;
				}
				if( zip != '' && zip.length < 5 )
				{
					alert( 'Please enter a valid Zip' );
					return false;
				}
				if( state != '' && zip != '' )
				{
					//Validate zip and state combination
					var valid_zip_state = validate_zip_state( zip, state );
					if( valid_zip_state == 'invalid' )
					{
						alert( 'Please enter a valid Zip and State' );
						return false;
					}
				}
				else if( state == '' && zip != '' )
				{
					var valid_zip = validate_zip( zip );
					if( valid_zip == 'invalid' )
					{
						alert( 'Please enter a valid Zip' );
						return false;
					}
				}
			}
			else if( country == '' && proceed == 1)
			{
				alert( 'Please select the country or territory from the drop-down' );
				return false;
			}
			if(proceed == 1)
			{
				$("#proceed").attr("value","yes");
			}
			if($("#consumer_type").val() == "fep" && proceed == 1)
			{
				$("#searchform2").attr("target","_blank");
			}
			else
			{
				$("#searchform2").attr("target","_self");
			}
			var sub_specialties = Array();
			var prim_specialties = Array();
			for(var x = 1; x <= category_count; x++)
			{
				var found = Array();
				var arr = $('#spec'+x+'1 > div').map(function(){
					    return this.id;
				}).get().join(',');
				if(arr.search(',') < 0){
					$("#spec"+x+"1 :checked").each(function() {  
						sub_specialties[sub_specialties.length] = $(this).val();  
						found[found.length] = $(this).val();  
					});
					if(found.length > 0)
					{
						prim_specialties[prim_specialties.length] = $('#check'+x).val();
					}
				}
				else{
					$("#spec2211 :checked").each(function() {  
						sub_specialties[sub_specialties.length] = $(this).val();  
						found[found.length] = $(this).val();  
					});
					if(found.length > 0)
					{
						prim_specialties[prim_specialties.length] = $('#check221').val();
					}
					found = Array();
					$("#spec2221 :checked").each(function() {  
						sub_specialties[sub_specialties.length] = $(this).val();  
						found[found.length] = $(this).val();  
					});
					if(found.length > 0)
					{
						prim_specialties[prim_specialties.length] = $('#check222').val();
					}
				}
			}
			
			/*$('#other_spec :selected').each(function(i, selected){
			   other_specialties[other_specialties.length] = $(selected).val();
			});*/
			
			var prim_selected_specs = prim_specialties.join(',');
			var sub_selected_specs = sub_specialties.join(',');
			var other_selected_specs = other_specialties.join(',');
			/*alert(sub_selected_specs);
			alert(other_selected_specs);*/
			/*$.ajax({
					type: "GET",
					url: 'update_specialties.php',
					async: false,
					data: 'other_selected_specialties='+other_selected_specs+'&sub_selected_specialties='+sub_selected_specs,
					success: function( data ){
					}
				});*/
			$('input.prim_spec_selection').attr("value",prim_selected_specs);
			$('input.sub_spec_selection').attr("value",sub_selected_specs);
			$('input.other_spec_selection').attr("value",other_selected_specs);

			/*$('#other_spec option').each(function(i, selected){
			   $(selected).attr('selected',false);
			});
			
			$("#prime_cat").find(':checkbox').attr('checked', false );
			
			for(var x = 1; x <= category_count; x++)
			{
				$("#spec"+x+"1").find(':checkbox').attr('checked', false );
			}*/
		});	
		
		$("#searchform3").submit(function()
		{
			var city = '';
			var state = '';
			var zip = '';
			var address = '';
			var chosen_body_parts = '';
			
			ParseAddress($('#medical-need_city-state-zip').val());
			
			var ib;
			for(ib = 1; ib <= 10; ib++)
			{
				$('#bodypart'+ib+' input:checkbox:checked').each(function()
				{
					if($(this).val() != 'on')
						chosen_body_parts += ','+$(this).val();
				});	
			}
			chosen_body_parts = chosen_body_parts.slice(1);
			
			$('input.body_parts_selection').attr('value',chosen_body_parts);
			$('input.conditions').attr('value',chosen_body_parts);
			
			address1 = $(".address1").val();
			if( address1 == '' )
			{
				$(".address1").attr('value','');	
			}
			city = $(".city").val();
			state = $(".state").val();
			zip = $(".zip").val();
			country = $("#country-fld").val();
			if( city == city_temp )
			{
				city = '';
			}
			if( state == state_temp )
			{
				state = '';
			}
			if( zip == zip_temp )
			{
				zip = '';
			}
			
			if( validate_csz && proceed == 1 )
			{
				if( city == '' && state == '' && zip == '' )
				{
					if(address1 == '')
					{
					alert( 'Please enter City and State or Zip' );
					return false;
					}
				}
				if( city == '' && state != '' && zip == '' )
				{
					alert( 'Please enter City and State or Zip' );
					return false;
				}
				if( city != '' && state == '' && zip == '' )
				{
					alert ( 'Please enter City and State or Zip' );
					return false;
				}
				if( zip != '' && zip.length < 5 )
				{
					alert( 'Please enter a valid Zip' );
					return false;
				}
				if( state != '' && zip != '' )
				{
					//Validate zip and state combination
					var valid_zip_state = validate_zip_state( zip, state );
					if( valid_zip_state == 'invalid' )
					{
						alert( 'Please enter a valid Zip and State' );
						return false;
					}
				}
				else if( state == '' && zip != '' )
				{
					var valid_zip = validate_zip( zip );
					if( valid_zip == 'invalid' )
					{
						alert( 'Please enter a valid Zip' );
						return false;
					}
				}
			}
			else if( country == '' && proceed == 1)
			{
				alert( 'Please select the country or territory from the drop-down' );
				return false;
			}
			if(proceed == 1)
			{
				$("#proceed").attr("value","yes");
			}
			if($("#consumer_type").val() == "fep" && proceed == 1)
			{
				$("#searchform3").attr("target","_blank");
			}
			else
			{
				$("#searchform3").attr("target","_self");
			}
			var sub_specialties = Array();
			var prim_specialties = Array();
			for(var x = 1; x <= category_count; x++)
			{
				var found = Array();
				var arr = $('#spec'+x+'1 > div').map(function(){
					    return this.id;
				}).get().join(',');
				if(arr.search(',') < 0){
					$("#spec"+x+"1 :checked").each(function() {  
						sub_specialties[sub_specialties.length] = $(this).val();  
						found[found.length] = $(this).val();  
					});
					if(found.length > 0)
					{
						prim_specialties[prim_specialties.length] = $('#check'+x).val();
					}
				}
				else{
					$("#spec2211 :checked").each(function() {  
						sub_specialties[sub_specialties.length] = $(this).val();  
						found[found.length] = $(this).val();  
					});
					if(found.length > 0)
					{
						prim_specialties[prim_specialties.length] = $('#check221').val();
					}
					found = Array();
					$("#spec2221 :checked").each(function() {  
						sub_specialties[sub_specialties.length] = $(this).val();  
						found[found.length] = $(this).val();  
					});
					if(found.length > 0)
					{
						prim_specialties[prim_specialties.length] = $('#check222').val();
					}
				}
			}
			sub_specialties = Array();
			var other_specialties = Array();
			$("#specialty-cart :input").each(function() {  
						sub_specialties[sub_specialties.length] = $(this).val();  
			});
			
			var prim_selected_specs = prim_specialties.join(',');
			var sub_selected_specs = sub_specialties.join(',');
			var other_selected_specs = other_specialties.join(',');
			/*$.ajax({
					type: "GET",
					url: 'update_specialties.php',
					async: false,
					data: 'other_selected_specialties='+other_selected_specs+'&sub_selected_specialties='+sub_selected_specs,
					success: function( data ){
					}
				});*/
			$('input.prim_spec_selection').attr("value",prim_selected_specs);
			$('input.sub_spec_selection').attr("value",sub_selected_specs);
			$('input.other_spec_selection').attr("value",other_selected_specs);
			
			/*$('#other_spec option').each(function(i, selected){
			   $(selected).attr('selected',false);
			});
			
			$("#prime_cat").find(':checkbox').attr('checked', false );
			
			for(var x = 1; x <= category_count; x++)
			{
				$("#spec"+x+"1").find(':checkbox').attr('checked', false );
			}*/
		});		
		
		$("#searchform").submit(function()
		{
			var city = '';
			var state = '';
			var zip = '';
			var address = '';
			var chosen_body_parts = '';
			
			ParseAddress($('#provider_city-state-zip').val());
			
			var ib;
			for(ib = 1; ib <= 10; ib++)
			{
				$('#bodypart'+ib+' input:checkbox:checked').each(function()
				{
					if($(this).val() != 'on')
						chosen_body_parts += ','+$(this).val();
				});	
			}
			chosen_body_parts = chosen_body_parts.slice(1);
			
			$('input.body_parts_selection').attr('value',chosen_body_parts);
			$('input.conditions').attr('value',chosen_body_parts);
			
			address1 = $(".address1").val();
			if( address1 == '' )
			{
				$(".address1").attr('value','');	
			}
			city = $(".city").val();
			state = $(".state").val();
			zip = $(".zip").val();
			country = $("#country-fld").val();
			var full_name = $("#full_name").val();
			if( city == city_temp )
			{
				city = '';
			}
			if( state == state_temp )
			{
				state = '';
			}
			if( zip == zip_temp )
			{
				zip = '';
			}
			if( full_name == both_temp || full_name == provider_temp || full_name == facility_temp )
			{
				full_name = '';
			}
			
			if( validate_csz && proceed == 1 )
			{
				if( city == '' && state == '' && zip == '' )
				{
					if(address1 == '')
					{
					alert( 'Please enter City and State or Zip' );
					return false;
					}
				}
				if( city == '' && state != '' && zip == '' )
				{
					alert( 'Please enter City and State or Zip' );
					return false;
				}
				if( city != '' && state == '' && zip == '' )
				{
					alert ( 'Please enter City and State or Zip' );
					return false;
				}
				if( zip != '' && zip.length < 5 )
				{
					alert( 'Please enter a valid Zip' );
					return false;
				}
				if( state != '' && zip != '' )
				{
					//Validate zip and state combination
					var valid_zip_state = validate_zip_state( zip, state );
					if( valid_zip_state == 'invalid' )
					{
						alert( 'Please enter a valid Zip and State' );
						return false;
					}
				}
				else if( state == '' && zip != '' )
				{
					var valid_zip = validate_zip( zip );
					if( valid_zip == 'invalid' )
					{
						alert( 'Please enter a valid Zip' );
						return false;
					}
				}
			}
			else if( country == '' && proceed == 1)
			{
				alert( 'Please select the country or territory from the drop-down' );
				return false;
			}
			if(proceed == 1)
			{
				$("#proceed").attr("value","yes");
			}
			if($("#consumer_type").val() == "fep" && proceed == 1)
			{
				$("#searchform").attr("target","_blank");
			}
			else
			{
				$("#searchform").attr("target","_self");
			}
			if( full_name.length && full_name.length < 2 )
			{
				alert( 'Please enter 2 or more characters in the name field' );
				return false;
			}
			var sub_specialties = Array();
			var prim_specialties = Array();
			category_count = $('.primary-categories').length;
			if(category_count > 0)
			{
			for(var x = 1; x <= category_count; x++)
			{
				var found = Array();
				var arr = $('#spec'+x+'1 > div').map(function(){
					    return this.id;
				}).get().join(',');
				if(arr.search(',') < 0){
					$("#spec"+x+"1 :checked").each(function() {  
						sub_specialties[sub_specialties.length] = $(this).val();  
						found[found.length] = $(this).val();  
					});
					if(found.length > 0)
					{
						prim_specialties[prim_specialties.length] = $('#check'+x).val();
					}
				}
				else{
					$("#spec2211 :checked").each(function() {  
						sub_specialties[sub_specialties.length] = $(this).val();  
						found[found.length] = $(this).val();  
					});
					if(found.length > 0)
					{
						prim_specialties[prim_specialties.length] = $('#check221').val();
					}
					found = Array();
					$("#spec2221 :checked").each(function() {  
						sub_specialties[sub_specialties.length] = $(this).val();  
						found[found.length] = $(this).val();  
					});
					if(found.length > 0)
					{
						prim_specialties[prim_specialties.length] = $('#check222').val();
					}
				}
			}
			}
			var other_specialties = Array();
			$("#spec23 :checked").each(function() { 
						other_specialties[other_specialties.length] = $(this).val();  
						//found[found.length] = $(this).val();  
			});
			/*$('#other_spec :selected').each(function(i, selected){
			   other_specialties[other_specialties.length] = $(selected).val();
			});*/
			
			var prim_selected_specs = prim_specialties.join(',');
			var sub_selected_specs = sub_specialties.join(',');
			var other_selected_specs = other_specialties.join(',');
			/*$.ajax({
					type: "GET",
					url: 'update_specialties.php',
					async: false,
					data: 'other_selected_specialties='+other_selected_specs+'&sub_selected_specialties='+sub_selected_specs,
					success: function( data ){
					}
				});*/
			$("input.prim_spec_selection").attr("value",prim_selected_specs);
			$("input.sub_spec_selection").attr("value",sub_selected_specs);
			$("input.other_spec_selection").attr("value",other_selected_specs);

			/*$('#other_spec option').each(function(i, selected){
			   $(selected).attr('selected',false);
			});
			
			$("#prime_cat").find(':checkbox').attr('checked', false );
			
			for(var x = 1; x <= category_count; x++)
			{
				$("#spec"+x+"1").find(':checkbox').attr('checked', false );
			}*/
		});	
});

$('.print-page').click(function(evt) {
	evt.preventDefault();
	$('#print-options').removeClass('open');
	window.print();
});


function loadImage()
{
	$('#DisabledArea').show();
	$('#DisabledMessage').show();
	if ($('#DisabledMessage').is(":visible")) {
		$('#DisabledMessage').html("<p>Processing...</p><div class=\"WorkingIconHolder\">	</div>");
	}
}

function submit_filters()
{
	//$('#narrow-results').submit();	
}
function updateSelected() {
	var selectedProviders = $('.provider-addTo input:checked').length;
	$('.selected-results span').html(selectedProviders);
	if(selectedProviders <= 0){
		$("#lightbox-data").find('button').addClass("deactivated");
	}else{
		$("#lightbox-data").find('button.deactivated').removeClass("deactivated");		
	}
};

function update_all_checkboxes(status) {
	$("#lightbox-data").find(':checkbox').attr('checked', status);
	updateSelected();
}


function countCompare() {
	compareCount = $('.provider-result.compare').length;	
	// activate the compare button
	if (compareCount > 1) {
		$('.compare_button').removeClass('deactivated');
	} else {
		$('.compare_button').addClass('deactivated');
	}
};

function ParseAddress(address) {
	var addressTrimmed = $.trim(address);
	var queryString = "";
	var parts = addressTrimmed.split(",", 2);
	if (parts.length == 1 && addressTrimmed.length == 5 && addressTrimmed.match(/^\d{5}$/)){
		$('input.zip').attr('value',addressTrimmed);
		$('input.city').attr('value','');
		$('input.state').attr('value','');
	}
	else {
		//attempt to split with comma or space
		parts = addressTrimmed.split(",", 2);
		if (parts.length == 2 && $.trim(parts[1]).length == 2) {
			$('input.city').attr('value',$.trim(parts[0]));
			$('input.state').attr('value',$.trim(parts[1]));
			$('.address1').attr('value','');
		}
		else
		{
			$('.address1').attr('value',addressTrimmed);
			$('input.city').attr('value','');
			$('input.state').attr('value','');

		}
		$('input.zip').attr('value','');

	}
}
function validate_zip( zip )
	{
		var valid_zip;
		$.ajax({
				type:"GET",
				url:"validate_zip_state.php",
				data:"zip="+zip+"&validation=zip",
				async:false,
				success:function( returnvalue)
				{
					valid_zip = returnvalue;
				}	
			});
		return valid_zip;
	}

	function validate_zip_state( zip, state )
	{
		var valid_zip_state;
		$.ajax({
				type:"GET",
				url:"validate_zip_state.php",
				data:"zip="+zip+"&state="+state+"&validation=zip_state",
				async:false,
				success:function( returnvalue)
				{
					valid_zip_state = returnvalue;
				}	
			});
		return valid_zip_state;
	}

	function close_hint( value )
	{
		$("#"+value+"").hide();
	}
	
	function close_bodypart( value )
	{
		for(var x = 1; x <= 11; x++)
		{
			if(x != value)
			{
				$("#bodypart"+x+"").hide();
			}
		}
	}
	
	function select_specialties( condition_key, primary_cat_key, other_spec_key, sub_spec_key, is_checked, reload)
	{
		var condition_values = '';
		var primary_cat_values = '';
		var other_spec_values = '';
		var sub_spec_values = '';
		
		if( condition_key )
		{	
			if( is_checked == true )
			{
				conditions[conditions.length] = condition_key;
			}
			else
			{
				var temp = Array();
				//If the value is false remove it from the array
				for( i=0;i<conditions.length;i++ )
				{
					if( condition_key != conditions[i] )
					{	
						temp[temp.length] = conditions[i];
					}	
				}
				conditions = temp;
				$.ajax({
					type: "GET",
					url: 'get_condition_sub_specialties.php',
					async: false,
					data: 'cond_key='+condition_key+'&conditions='+conditions,
					success: function( data ){
						var temp_sub_specs = data.split( ',' );
						var temp = Array();
						for( i=0;i<other_spec.length;i++ )
						{
							if( !in_array( other_spec[i], temp_sub_specs) )
							{
								temp[temp.length] = other_spec[i];
							}
							other_spec = temp;
						}
					}
				});
			}
		}
		if( primary_cat_key )
		{
			if( is_checked == true )
			{
				primary_cat_selection[primary_cat_selection.length] = primary_cat_key;
				
				//Check if amy of the secondary specialties exist in sub_spec array and remove them
				$.get( 'get_subspecialties.php',{primary_cat_key:primary_cat_key},
			function( data ){
				var temp_sub_specs = data.split( ',' );
				var temp = Array();
				for( i=0;i<sub_spec.length;i++ )
				{
					if( !in_array( sub_spec[i], temp_sub_specs ) )
					{
						temp[temp.length] = sub_spec[i];
					}
				}
				sub_spec = temp;
				});
				
				var temp = Array();
				//If the value is true remove it from the exclude array
				for( i=0;i<exclude_primary_spec.length;i++ )
				{
					if( primary_cat_key != exclude_primary_spec[i] )
					{	
						temp[temp.length] = exclude_primary_spec[i];
					}	
				}
				exclude_primary_spec = temp;
			}
			else
			{
				exclude_primary_spec[exclude_primary_spec.length] = primary_cat_key;
				var temp = Array();
				//If the value is false remove it from the array
				for( i=0;i<primary_cat_selection.length;i++ )
				{
					if( primary_cat_key != primary_cat_selection[i] )
					{	
						temp[temp.length] = primary_cat_selection[i];
					}	
				}
				primary_cat_selection = temp;
			}
		}
		if( other_spec_key )
		{	
			if( is_checked == true )
			{
				var other_spec_temp = Array();
				var exclude_other_temp = Array();
				other_spec_temp = other_spec_key.split( ',' );

				for( var i=0;i<other_spec.length;i++ )
				{
					if( !in_array(other_spec[i],other_spec_temp) )
					{
						if( !in_array( other_spec[i],exclude_other_spec ) )
						{
							exclude_other_temp[i] = other_spec[i];
						}
					}
				}

				for( var i=0;i<exclude_other_spec.length;i++ )
				{
					if( !in_array(exclude_other_spec[i],other_spec_temp) )
					{
						exclude_other_temp[exclude_other_temp.length] = exclude_other_spec[i];
					}
				}
				other_spec = other_spec_temp;
				exclude_other_spec = exclude_other_temp;
			}
			else
			{
				exclude_other_spec[exclude_other_spec.length] = other_spec_key;
				var temp = Array();
				//If the value is false remove it from the array
				for( i=0;i<other_spec.length;i++ )
				{
					if( other_spec_key != other_spec[i] )
					{	
						temp[temp.length] = other_spec[i];
					}	
				}
				other_spec = temp;
			}
		}
		if( sub_spec_key )
		{	
			if( is_checked == true )
			{
				sub_spec[sub_spec.length] = sub_spec_key;
				var temp = Array();
				//If the value is true remove it from the exclude array
				for( i=0;i<exclude_secondary_spec.length;i++ )
				{
					if( sub_spec_key != exclude_secondary_spec[i] )
					{	
						temp[temp.length] = exclude_secondary_spec[i];
					}	
				}
				exclude_secondary_spec = temp;
			}
			else
			{
				exclude_secondary_spec[exclude_secondary_spec.length] = sub_spec_key;
				var temp = Array();
				//If the value is false remove it from the array
				for( i=0;i<sub_spec.length;i++ )
				{
					if( sub_spec_key != sub_spec[i] )
					{	
						temp[temp.length] = sub_spec[i];
					}	
				}
				sub_spec = temp;
			}
		}
		
		primary_cat_values = primary_cat_selection.join( ',' );
		condition_values = conditions.join( ',' ); 
		other_spec_values = other_spec.join( ',' );
		sub_spec_values = sub_spec.join( ',' );
		
		if(primary_cat_values == '' && condition_values == '' && other_spec_values == '' && sub_spec_values == '')
		{
			exclude_other_spec = Array();
			exclude_secondary_spec = Array();
			exclude_primary_spec = Array();	
		}

		exclude_other_spec_values = exclude_other_spec.join( ',' );
		exclude_secondary_spec_values = exclude_secondary_spec.join( ',' );
		exclude_primary_spec_values = exclude_primary_spec.join( ',' );
		$.post( 'update_spec_cat.php',{conditions:condition_values,primary_cat_values:primary_cat_values,other_spec:other_spec_values,sub_spec:sub_spec_values,exclude_other_spec:exclude_other_spec_values,exclude_secondary_spec:exclude_secondary_spec_values,exclude_primary_spec:exclude_primary_spec_values,search_box:search_box},
			function( data ){
				if(reload == true)
				{
					$("#specialty-container").html( data );	
				}
				/*var other_spec_temp_arr = $("#other_spec").selectedValues();
				if(other_spec_temp_arr.length > 0)
				{
					other_spec = other_spec_temp_arr;
				}*/
			});
		
		$.post( 'specialty_cart.php',{conditions:condition_values,primary_cat_values:primary_cat_values,other_spec:other_spec_values,sub_spec:sub_spec_values,exclude_other_spec:exclude_other_spec_values,exclude_secondary_spec:exclude_secondary_spec_values,exclude_primary_spec:exclude_primary_spec_values,search_box:search_box},
			function( data ){
				if(condition_values != '' || primary_cat_values != '' || sub_spec_values != '' || other_spec_values != '')
				{
					$("#specialty-cart").show();
				}
				else
				{
					$("#specialty-cart").hide();
				}
				$("#specialty-cart").html( data );	
			});
		$("#bodypart-front-"+condition_key).attr("checked",is_checked);
		$("#bodypart-back-"+condition_key).attr("checked",is_checked);	
	}
	function in_array( value, search_array )
	{
		var found = false;
		for( var i=0;i<search_array.length;i++ )
		{
			if( value == search_array[i] )
			{
				found = true;
				break;
			}
		}
		return found;
	}
	
	function check_specialty( divname, checkbox_value, specialty_name, div_img )
	{
		$("#"+divname).find(':checkbox').attr('checked', checkbox_value );
		if( specialty_name == "Behavioral Health" || specialty_name == "Salud conductual")
		{
			/*if(checkbox_value == true)
			{
				$("#behavioral_note").show();
			}
			else
			{
				$("#behavioral_note").hide();	
			}*/		
		}
		/*if( ( checkbox_value && !($('#'+divname).is(':visible')) ) || ( !checkbox_value && $('#'+divname).is(':visible') ) )
		{
			toggle_divs(div_img,'1');
		}*/
	}
	function check_sub_cat( divname, specialty_name, checkbox_value )
	{
		if( specialty_name == "Behavioral Health" || specialty_name == "Salud conductual")
		{
			if($("#"+divname+' :checked').size() > 0)
			{
				$("#behavioral_note").show();	
			}
			else
			{
				$("#behavioral_note").hide();	
			}
		}
	}
	$("#head_link").live('click',function()
		{
			$("#bodypart1").show();
			$("#bodypart1").find(':checkbox').focus();
			close_bodypart( 1 );

		});
		
		$("#b_head_link").live('click',function()
		{
			$("#bodypart7").show();
			$("#bodypart7").find(':checkbox').focus();
			close_bodypart( 7 );
		});
		
		$("#f_right_arm_link").live('click',function()
		{
			$("#bodypart2").show();
			$("#bodypart2").find(':checkbox').focus();
			close_bodypart( 2 );
		});
		
		$("#l_right_arm_link").live('click',function()
		{
			$("#bodypart2").show();
			$("#bodypart2").find(':checkbox').focus();
			close_bodypart( 2 );
		});
		
		$("#b_right_arm_link").live('click',function()
		{
			$("#bodypart8").show();
			$("#bodypart8").find(':checkbox').focus();
			close_bodypart( 8 );
		});
		
		$("#b_left_arm_link").live('click',function()
		{
			$("#bodypart8").show();
			$("#bodypart8").find(':checkbox').focus();
			close_bodypart( 8 );
		});

		$("#chest_link").live('click',function()
		{
			$("#bodypart3").show();
			$("#bodypart3").find(':checkbox').focus();
			close_bodypart( 3 );
		});
		
		$("#back_link").live('click',function()
		{
			$("#bodypart9").show();
			$("#bodypart9").find(':checkbox').focus();
			close_bodypart( 9 );
		});
		
		$("#abs_link").live('click',function()
		{
			$("#bodypart4").show();
			$("#bodypart4").find(':checkbox').focus();
			close_bodypart( 4 );
		});
		
		$("#buttocks_link").live('click',function()
		{
			$("#bodypart10").show();
			$("#bodypart10").find(':checkbox').focus();
			close_bodypart( 10 );
		});
		
		$("#groin_link").live('click',function()
		{
			$("#bodypart5").show();
			$("#bodypart5").find(':checkbox').focus();
			close_bodypart( 5 );
		});
		
		$("#f_left_leg_link").live('click',function()
		{
			$("#bodypart6").show();
			$("#bodypart6").find(':checkbox').focus();
			close_bodypart( 6 );
		});
		
		$("#f_right_leg_link").live('click',function()
		{
			$("#bodypart6").show();
			$("#bodypart6").find(':checkbox').focus();
			close_bodypart( 6 );
		});
		
		$("#b_left_leg_link").live('click',function()
		{
			$("#bodypart11").show();
			$("#bodypart11").find(':checkbox').focus();
			close_bodypart( 11 );
		});
		
		$("#b_right_leg_link").live('click',function()
		{
			$("#bodypart11").show();
			$("#bodypart11").find(':checkbox').focus();
			close_bodypart( 11 );
		});	

