// 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("Please give your review  for this product!");
        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('Sorry, your review is not updated. Please try again!')
                                            }
											  if(data.duplicate)
                                            {
                                                 alert('Sorry, You have already posted review for this product.!')
                                            }
                                            else if(data.success)
                                            {
                                               $("#txtReview").val('');
                                               $("#jqStarRatingPop").fadeOut("slow");
											   //$("#jqNewComment").html('');
											   $("#norecords").hide();
											   $("#jqNewComment").prepend(unescape(data.comment));
											   
											   alert("Your Review Posted Successfully .");
                                            }
                                      },
                         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("Please select a rating for this Product!");
        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('Sorry, your rating  is not updated. Please try again!')
                                            }
											  if(data.duplicate)
                                            {
                                                 alert('Sorry, You have already posted rating for this product.!')
                                            }
                                            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").prepend(unescape(data.comment));
											   
											   alert("Your Rating Posted Successfully .");
                                            }
                                      },
                         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("Please select a rating for this Seller!");
        return false;
    }
	else  if(sellerreview == '')
	{
		alert("Please give your feedback  about this seller!");
        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('Sorry, your feedback is not updated. Please try again!')
                                            }
											  if(data.duplicate)
                                            {
                                                 alert('Sorry, You have already posted feedback for this seller.!')
                                            }
                                            else if(data.success)
                                            {
                                               $("#txtSellerReview").val('');
                                               $("#jqSellerRatingPop").fadeOut("slow");
											   //$("#jqNewComment").html('');
											   $("#norecords").hide();
											   $("#jqNewSellerComment").prepend(unescape(data.comment));
											   
											   alert("Your feedback Posted Successfully .");
                                            }
                                      },
                         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("Hide details ...");
		$("#" + fullCommentID).animate({height : contentHeight + "px"}, "slow");
	}
	else
	{
		$("#" + linkID).html("Click for more ...");
		$("#" + fullCommentID).animate({height : "43px"}, "slow");
	}
	
	return false;
}
