

$(document).ready(function() {
	// Member Directory Table row Hover
	
	$("#member-directory tbody tr").click( function(){
		link = $(this).find("td a").attr("href");
		window.location = link;											
	});

	
	// Creates Collapseable Categories
	
	$('.hospital-name, .qotm-archive dt').click(function() {														 
		$(this).toggleClass("selected").next().slideToggle('fast');
	if($(this).hasClass("ie7_class3"))$(this).removeClass("ie7_class3");
	if($(this).hasClass("hospital-name")){
		  if($(this).hasClass("selected")){
			$(this).css("font-weight","bold");
		  } else{
			$(this).css("font-weight","normal");
		  }
									
		}
  	});	
	$('.hospital-name, .qotm-archive dt').click();

	$('.month').prepend("::&nbsp;").append("&nbsp;:");
  	$('h2.instructions').append("<span>(Click a question to view the answer)</span>");
	$('h4.instructions').append("<span>(Click a hospital to view its details.)</span>");
  
  
  	// Form swaps class on input fields whcih changes the input color
	
	//Create an associative array to hold the default hint values
	//The  index is the ID of the element and the value is the hint
	
	var hintArr = new Array()
		hintArr["fname"] = "First Name";
		hintArr["lname"] = "Last Name";
		hintArr["doc-search"] = "Enter a Search Query...";
		hintArr["search-field"] = "Search...";
	
	$("input.initval").each(function(){
		id = $(this).attr("id");
		hint = hintArr[id];
		$(this).attr("value", hint);
												   
	});
	
	$('.initval').focus(function() {
		if($(this).hasClass("initval")){
			$(this).attr("value", "").removeClass("initval");
		}
	});
	
	$('.cha_form input, #doc-search input, #search-field').blur(function() {
		currentval = $(this).attr("value");		
		if( currentval == undefined || currentval == " "){
			id = $(this).attr("id");
			hint = hintArr[id];
			$(this).addClass("initval").attr("value", hint);
		}
	});
	$(".cha_form h4").hide();
	

	jQuery.validator.addMethod("defval", function(value, element) {
		if(value == "First Name"){
		 	return false;
		} else if( value == "Last Name"){
		 	return false;
		} else {
			return true;
		}
	}, "Required");
		
	
	
	$(".cha_form").validate({
	   groups: {
			username: "fname lname"
		  },
	   errorPlacement: function(error, element) {
		  if (element.name == "fname" || element.name == "lname" )
			   error.insertAfter("lname");
		  else
			   error.insertAfter(element);
		},
		rules: { 
            fname: {defval: true},
			lname: {defval: true}
			
        }, 
		messages: {
		   fname: "Required",
		   lname: "Required",
     	   email: "Required",
		   title: "Required",
		   org: "Required"
		},
		errorElement: "h4"
		
	});
	
	//Print an article
	$("a.print-icon").click(function(){
		window.print();
		return false;
	});
	
	// Add new window icon, opens link in new window.
	$("a[rel='external']").append("<img src='/images/external.png' />");
	$("a[rel='external'], #dl_brochure").click( function() {
        window.open( $(this).attr('href') );
        return false;
    });

  
 });//EOF


