// KCHP

var currentItem = "";

$(document).ready(function()
{
    //Toggle story's
    var OpenString = $(".story .toggle:first").text();
    var CloseString = 'Hide';

    $('a.toggle').click(function(){
      
    var clikItem = $(this).siblings('.detail');

    if(currentItem != "")
    {
      $(".story .toggle").text('Open to read more');
      if(currentItem.attr("id") != clikItem.attr("id"))
      {
        currentItem.slideUp('fast',function(){clikItem.slideDown('fast');})
        $(this).text(CloseString);
      }
      else
      {
        currentItem.slideUp('fast');
        $(this).text(OpenString);
        clikItem = "";
      }
    }
    else
    {
      clikItem.slideDown('fast');
      $(this).text(CloseString);
    }
    
    currentItem = clikItem;
		
		return false;
  });

  //Hide and show helps in quote
    var openBgColor = "#eff0ec";
	var openBgImage = "/templates/images/bg-help-msg.gif";

  $('fieldset li.help select, fieldset li.help input').focus(function() {
    $(this).parent().children('.help').show();
    $(this).parent().children('.help').css('background-color', openBgColor)
    $(this).parent().css('background', "url("+openBgImage+") repeat-y");
  });

  $('fieldset li.help select, fieldset li.help input').blur(function() {
    $(this).parent().children('.help').hide();
    $(this).parent().children('.help').css('background-color', '#ffffff')
    $(this).parent().css('background', 'none');								   
  });

  //Handle treatment disclaimer text
  if($('.TreatmentsYes:checked').val())
  {
    $('.treatmentDisclaimer').show();
  }
  
  $('.TreatmentsYes').click(function() {
    $('.treatmentDisclaimer').show();
  });
  
  $('.TreatmentsNo').click(function() {
    $('.treatmentDisclaimer').hide();
  });

  //replace dog name
	$('fieldset li.dogName input').blur(function() {
		if($('fieldset li.dogName input').val() != "")
			$('strong.quote, span.quote').text(firstCharacterToUpperCase($('fieldset li.dogName input').val()));											
	});
	
  //replace postcode
	$('fieldset li.postcode input').blur(function() {
		if($('fieldset li.postcode input').val() != "")
			$('strong.postcode, span.postcode').text($('fieldset li.postcode input').val().toUpperCase());												
		else
			$('strong.postcode, span.postcode').html("&nbsp;");
	});


});


function firstCharacterToUpperCase(string)
{
  return string.substring(0,1).toUpperCase()+string.substring(1);
}