(function ($) {
	$(document).ready(function($) {
		$("#comment-text").val('Votre commentaire...');
		$(".comment-text").val('Votre commentaire...');
	});
	
	//For store fo first question yes click.
	$('.pg-first-yes').live("click", function(e) {  
      $('#post-question-container .pq-second-block').show();
      $('#post-question-container .pg-first-no').addClass('in-active');
	});
	$('.pg-second-no').live("click", function(e) { 
      $('#post-question-container .pq-third-block').show();
      $('#post-question-container .pg-second-yes').addClass('in-active');
	});
	
	/**
	 * Post Comment Ajax Callback
	 */
	$(".post-comment").live("click", function(e) { 
      $("#comment-msg").hide();
      var comment_id = this.id;
      var comment_id_val = comment_id.split("##"); 
      
      var user_comment = $("#comment-text").val();
      var entity_type = comment_id_val[0];
      var entity_id = comment_id_val[1];
      var c_store_uid = comment_id_val[2];
      var c_typology_id = comment_id_val[3];
      var c_area_id = comment_id_val[4];

      if (user_comment && user_comment != 'Votre commentaire...' && entity_id && entity_type && c_store_uid && c_typology_id && c_area_id) {
        $.ajax({
          type: 'POST',
          dataTypeString: 'text',
          url: '/store/post_comment',
          data: {'type' : 'comment', 'entity_type' : entity_type, 'entity_id' : entity_id, 'user_comment' : user_comment,
                  'c_store_uid' : c_store_uid, 'c_typology_id' : c_typology_id, 'c_area_id' : c_area_id	
          }, 
          success: function(data) {
            if (data == 'success') {
              $("#comment-msg").show();
              $("#comment-post-block").hide();
            } else {
              $("#comment-msg").html(Drupal.t('Comment posting failed.'));
              $("#comment-msg").show();
            }
          }
        }); 
      } else {
         $("#comment-msg").html(Drupal.t('Comment posting failed.'));
         $("#comment-msg").show();
      }
    });  
	
	/**
	 * Post Question Ajax Callback
	 */
	$(".post-question").live("click", function(e) { 
      $("#question-msg").hide();
		
      var question_id = this.id;
      var question_id_val = question_id.split("##"); 
      
      var user_question = $("#question-text").val();
      var q_store_uid = question_id_val[1];

      if (user_question && user_question != 'Saisissez votre question' && q_store_uid) {
        $.ajax({
          type: 'POST',
          dataTypeString: 'text',
          url: '/store/post_comment',
          data: {'type' : 'question', 'user_comment' : user_question, 'c_store_uid' : q_store_uid }, 
          success: function(data) {
            if (data == 'success') {
              $("#question-msg").show();
              $("#question-post-block").hide();
            } else {
              $("#question-msg").html(Drupal.t('Question posting failed.'));
              $("#question-msg").show();
            }
          }
        }); 
      } else {
        $("#question-msg").html(Drupal.t('Question posting failed.'));
        $("#question-msg").show();
      }
    });
	
	/**
	 * Survey Homepage - Post Comment Ajax Callback
	 */
	$(".survet-post-comment").live("click", function(e) { 
	      $(".survey-comment-msg").hide();
	      var comment_id = this.id;
	      var comment_id_val = comment_id.split("##"); 
	      
	      var entity_type = comment_id_val[0];
	      var entity_id = comment_id_val[1];
	      var c_store_uid = comment_id_val[2];
	      var c_typology_id = comment_id_val[3];
	      var c_area_id = comment_id_val[4];
	      
	      var survey_text_id = '#survey-comment-text_'+entity_id;    	  
	      var user_comment = $(survey_text_id).val();
	      var msg_div_id = '#survey-comment-msg_'+entity_id;
	      var comment_div_id = '#survey-comment-post-block_'+entity_id;

	      if (user_comment && user_comment != 'Votre commentaire...' && entity_id && entity_type && c_store_uid && c_typology_id && c_area_id) {
	        $.ajax({
	          type: 'POST',
	          dataTypeString: 'text',
	          url: '/store/post_comment',
	          data: {'type' : 'comment', 'entity_type' : entity_type, 'entity_id' : entity_id, 'user_comment' : user_comment,
	                  'c_store_uid' : c_store_uid, 'c_typology_id' : c_typology_id, 'c_area_id' : c_area_id	
	          }, 
	          success: function(data) {
	            if (data == 'success') {
	              $(msg_div_id).show();
	              $(comment_div_id).hide();
	            } else {
	              $(msg_div_id).html(Drupal.t('Comment posting failed.'));
	              $(msg_div_id).show();
	            }
	          }
	        }); 
	      } else {
	         $(msg_div_id).html(Drupal.t('Comment posting failed.'));
	         $(msg_div_id).show();
	      }
	});    
	
	// For the store FAQ page.
    if ($("#question-answer").length) {  	 
  	  $(".store-faq-category").click(function (e) {
  		 var que_div_id = $(this).attr('id');
  		 var ans_div_id = que_div_id + '-ans';
  		 
  		 if ($("#" + ans_div_id).hasClass("collapsed")) {
  			$("#" + ans_div_id).removeClass("collapsed");
  			$("#" + que_div_id).addClass("active");
  		 }
  		 else {
  			$("#" + ans_div_id).addClass("collapsed");
  			$("#" + que_div_id).removeClass("active");
  		 }  		 
  		 
  		 //return false;
		});  	  
    }
	
})(jQuery);

/** Code for the accordin in the Comments section*/
function see(id)
{
	var display = document.getElementById(id).style.display;
	id = "#"+id;
	if(display == "")
		if(jQuery( id ).hasClass("hide") == false)
			display="inline";
		else
			display="none";
	
	if (display == "none"){
		jQuery(id).show( "slow" );
		jQuery('#comment-section .comment-section-head h2').addClass('active');
	}
	else{
	  jQuery('#comment-section .comment-section-head h2').removeClass('active');
		jQuery( id).hide( "slow" );
		}
}