// JavaScript Document
$(document).ready(function()
{
	$("#jqRateImage").click(rateAlbumImage);
	$(".jqRatingCancel").click(closeRating);
	$(".jqPostRating").click(submitRating);
	$("#jqRateProduct").click(rateProduct);
	$(".jqProductRatingCancel").click(closeProductRating);
	$(".star").click(ratingStarValue);
	
	$(".jqPostProductRating").click(submitProductRating);
	
	$("#jqSellerRating").click(rateSeller);
	
	$(".jqSellerRatingCancel").click(closeSellerRating);

	$(".jqSellerRating").click(submitSellerRating);

	
	
});

function rateAlbumImage()
{
	//alert('rrrrrrrr'); return false;
	var windowWidth             = $(window).width();
    var windowHeight            = $(window).height();
    var popupHeight             = $("#jqStarRatingPop").height();
    var popupWidth              = $("#jqStarRatingPop").width();
    var pageScrollTop           = document.documentElement.scrollTop ? document.documentElement.scrollTop : (document.body.scrollTop ? document.body.scrollTop : 0);
    var addCommentBoxTop        = pageScrollTop + (windowHeight - popupHeight) /2;
    var addCommentBoxLeft       = (windowWidth - popupWidth) / 2;
   //alert(addCommentBoxTop);
    //return false;

    $("#jqStarRatingPop").css({
                    position : "absolute",
                    left : addCommentBoxLeft,
                    top: addCommentBoxTop
                }).fadeIn("slow");
	
      return false;
}

function rateProduct()
{
	//alert('rrrrrrrr'); return false;
	var windowWidth             = $(window).width();
    var windowHeight            = $(window).height();
    var popupHeight             = $("#jqRatingPop").height();
    var popupWidth              = $("#jqRatingPop").width();
    var pageScrollTop           = document.documentElement.scrollTop ? document.documentElement.scrollTop : (document.body.scrollTop ? document.body.scrollTop : 0);
    var addCommentBoxTop        = pageScrollTop + (windowHeight - popupHeight) /2;
    var addCommentBoxLeft       = (windowWidth - popupWidth) / 2;
   //alert(addCommentBoxTop);
    //return false;

    $("#jqRatingPop").css({
                    position : "absolute",
                    left : addCommentBoxLeft,
                    top: addCommentBoxTop
                }).fadeIn("slow");
	
      return false;
}

function closeRating()
{
    $("#jqStarRatingPop").fadeOut("fast");
    //$("#txtShareEmail").val("");
    return false;
}

function closeProductRating()
{
    $("#jqRatingPop").fadeOut("slow");
    //$("#txtShareEmail").val("");
    return false;
}

function ratingStarValue()
{
	
    var clickedStarVal = $('input[name=star1]:checked').val();
	
    $("#hidProductid").val(clickedStarVal);
    //alert(clickedStarVal);
    return false;
}

function setDefaultRating()
{
    var clickedStarVal = 0;
    $("#hidProductid").val(clickedStarVal);
    //alert(clickedStarVal);
    return false;
}

function submitRating()
{
    var review   		= 	$.trim($("#txtReview").val());
    var productid 	    = 	$("#hidPostId").val();
    var imageid 		=  	$("#jqHidImageId").val();
	var state_id		=	$("#hidStateId").val();
	var state_name		=	$("#hidStateName").val();
	var hidTrailId		=	$("#hidTrailId").val();
	var member_id		=	$("#member_id").val();
	
	//lert('ggggggggg');return false;
	//dateFormat(now, "yyyy/mm/dd");
  
	 if(review == '')
	{
		alert(msgReviewProduct);
        return false;
	}
	else
    {
        var ajaxSubmitOption 	= {
                            url      : "product-review-ajax.php",
                            data     : {productid : productid, review : review},
                            type     : "post",
                            dataType : "json",
                            success  : function(data)
                                       {
										   //alert(data);return false;
                                            if(data.error)
                                            {
                                                 alert(MSG_REVIEW_NOT_UPDATED);
                                            }
											  if(data.duplicate)
                                            {
                                                 alert(MSG_REVIEW_ALREADY_POSTED);
                                            }
                                            else if(data.success)
                                            {
                                               $("#txtReview").val('');
                                               $("#jqStarRatingPop").fadeOut("slow");
											   //$("#jqNewComment").html('');
											   $("#norecords").hide();
											   $("#jqNewComment1").prepend(unescape(data.comment));
											   
											   alert(MSG_REVIEW_UPDATED_SUCCESS);
                                            }
                                      },
                         beforeSend : function()
                                      {
                                            //alert(url);
                                      },
                           complete : function()
                                      {
                                        // hideAjaxLoader();
                                      }
                                  };
        $.ajax(ajaxSubmitOption);
    }
    return false;
}


function submitProductRating()
{
    var hidProductid 	    = 	$("#hidProductid").val();
	var state_id		=	$("#hidStateId").val();
	var state_name		=	$("#hidStateName").val();
	var hidTrailId		=	$("#hidTrailId").val();
	var member_id		=	$("#member_id").val();
	var hidProductSellerid	= $("#hidProductSellerid").val();
	
	//lert('ggggggggg');return false;
	//dateFormat(now, "yyyy/mm/dd");
	 var clickedStarVal  = $('input[name=star1]:checked').val();
	 
	 if(clickedStarVal  == 0 ||  typeof clickedStarVal=="undefined")
    {
        alert(msgRateProduct);
        return false;
    }
	else
    {
        var ajaxSubmitOption 	= {
                            url      : "product-review-ajax.php",
                            data     : {hidProductid : hidProductid, clickedStarVal : clickedStarVal},
                            type     : "post",
                            dataType : "json",
                            success  : function(data)
                                       {
										   //alert(data);return false;
                                            if(data.error)
                                            {
                                                 alert(MSG_RATING_NOT_UPDATED);
                                            }
											  if(data.duplicate)
                                            {
                                                 alert(MSG_RATING_ALREADY_POSTED)
                                            }
                                            else if(data.success)
                                            {
                                               $("#jqRatingPop").fadeOut("slow");
											   $("#jqNewComment").html('');
											   $("#norecords").hide();
                                                                                           											   
											   document.getElementById("jqRateProduct").style.display="none";
											   //document.getElementById("rating_"+clickedStarVal).style.display="";
											   
											   $("#jqRateProduct").hide();
                                                                                           $("#jqNewComment").addClass("rating_"+clickedStarVal);
                                                                                           // $("#jqNewComment").addClass("rating_3");
											   //$("#jqNewComment").prepend(unescape(data.comment));
											   
											   alert(MSG_RATING_UPDATED_SUCCESS);
                                            }
                                      },
                         beforeSend : function()
                                      {
                                            //alert(url);
                                      },
                           complete : function()
                                      {
                                        // hideAjaxLoader();
                                      }
                                  };
        $.ajax(ajaxSubmitOption);
    }
    return false;
}


function rateSeller()
{
	//alert('rrrrrrrr'); return false;
	var windowWidth             = $(window).width();
    var windowHeight            = $(window).height();
    var popupHeight             = $("#jqSellerRatingPop").height();
    var popupWidth              = $("#jqSellerRatingPop").width();
    var pageScrollTop           = document.documentElement.scrollTop ? document.documentElement.scrollTop : (document.body.scrollTop ? document.body.scrollTop : 0);
    var addCommentBoxTop        = pageScrollTop + (windowHeight - popupHeight) /2;
    var addCommentBoxLeft       = (windowWidth - popupWidth) / 2;
   //alert(addCommentBoxTop);
    //return false;

    $("#jqSellerRatingPop").css({
                    position : "absolute",
                    left : addCommentBoxLeft,
                    top: addCommentBoxTop
                }).fadeIn("slow");
	
      return false;
}

function closeSellerRating()
{
    $("#jqSellerRatingPop").fadeOut("slow");
    //$("#txtShareEmail").val("");
    return false;
}

function submitSellerRating()
{
    var sellerreview   		= 	$.trim($("#txtSellerReview").val());
    var hidSellerPostId = 	$("#hidSellerPostId").val();
	
	//lert('ggggggggg');return false;
	//dateFormat(now, "yyyy/mm/dd");
	
	
   var clickedStarVal  = $('input[name=star2]:checked').val();
   
	 if(clickedStarVal  == 0 ||  typeof clickedStarVal=="undefined")
    {
        alert(msgRateSeller);
        return false;
    }
	else  if(sellerreview == '')
	{
		alert(msgSellerFeedback);
        return false;
	}
	else
    {
        var ajaxSubmitOption 	= {
                            url      : "product-review-ajax.php",
                            data     : {hidSellerPostId : hidSellerPostId, sellerreview : sellerreview,sellerRatingval:clickedStarVal},
                            type     : "post",
                            dataType : "json",
                            success  : function(data)
                                       {
										   //alert(data);return false;
                                            if(data.error)
                                            {
                                                 alert(msgFeedbackNotUpdated);
                                            }
											  if(data.duplicate)
                                            {
                                                 alert(msgFeedbackPosted);
                                            }
                                            else if(data.success)
                                            {
                                               $("#txtSellerReview").val('');
                                               $("#jqSellerRatingPop").fadeOut("slow");
											   //$("#jqNewComment").html('');
											   $("#norecords").hide();
											   $("#jqNewSellerComment").prepend(unescape(data.comment));
											   
											   alert(msgFeedbackPostedSuccess);
                                            }
                                      },
                         beforeSend : function()
                                      {
                                            //alert(url);
                                      },
                           complete : function()
                                      {
                                        // hideAjaxLoader();
                                      }
                                  };
        $.ajax(ajaxSubmitOption);
    }
    return false;
}

function funcShowUserFullComment(innerCommentID, fullCommentID, linkID)
{
	contentHeight = $("#" + innerCommentID).height();
	currentHeight = $("#" + fullCommentID).height();
	
	if (currentHeight == 43)
	{
		$("#" + linkID).html(msgHideDetails);
		$("#" + fullCommentID).animate({height : contentHeight + "px"}, "slow");
	}
	else
	{
		$("#" + linkID).html(msgClickForMore);
		$("#" + fullCommentID).animate({height : "43px"}, "slow");
	}
	
	return false;
}
