function showValues(val)
{
	$('.dummy').each(function(index,item){
		$(item).removeClass("active");
	});

	  $.ajax({
                   type: "POST",
                   url: basurl+"/ExploreAssam/getCategoryPlacesHome",
                   data: {val:val}, // serializes the form's elements.
                   success: function(data)
                   {
                   	$("#placeList").html('');
                     var content=$.parseJSON(data);
                       $.each(content.places, function (index, value) {
                       	var place='<li class="hg25"><a href="'+basurl+'/ExploreAssam/Place/'+value.slug+'"><img src="'+value.image+'" alt=""><div class="hlist-title"><h3>'+stripslashes(value.heading)+'</h3><h2>'+stripslashes(value.placeName)+'</h2></div><div class="hlist-icon"><img src="'+value.icon+'" ></div></a></li>';
                        	$("#placeList").append(place);
                       });
                  
                   }
	  		});
}

function showeventValues(val)
{
	
	$('.dummyevent').each(function(index,item){
		$(item).removeClass("active");
	});

	  $.ajax({
                   type: "POST",
                   url: basurl+"/Welcome/getEventsHome",
                   data: {val:val}, // serializes the form's elements.
                   success: function(data)
                   {
                   	$("#eventArea").html('');
                     var content=$.parseJSON(data); 
					 
					 var imageBase = $('#eventBackground').attr('data-url');
					 
					
                       $.each(content.events, function (index, value) {
						   
						   console.log(value);
						   
							 $('#eventBackground').attr('src',imageBase+value.back_image);
						  
						  
						   var events ='<h4>'+value.title+'</h4>'+
									   '<div class="desc"><p></p></div>'+
									   '<h1><span>'+ordinal(value.from_date)+' '+value.from_month+
											' - '+ordinal(value.to_date)+' '+value.to_month+'</span>,'+
										'<br><span>'+value.year+'</span></h1>'
                         	$("#eventArea").append(events);
							
                       });
                  
                   }
	  		});
}

function stripslashes(str) {
    str = str.replace(/\\'/g, '\'');
    str = str.replace(/\\"/g, '"');
    str = str.replace(/\\0/g, '\0');
    str = str.replace(/\\\\/g, '\\');
    return str;
}

function ordinal(number)
{
	var ends = ['th','st','nd','rd','th','th','th','th','th','th'];
	if (((number % 100) >= 11) && ((number%100) <= 13))
										return number+ 'th';
									else
										return number+'<sup>'+ends[number % 10]+'</sup>';
}


$(document).ready(function() {

 
    $(".dummy").on('click', function() {
       $(this).addClass('active');
    });
	
	    $(".dummyevent").on('click', function() {
       $(this).addClass('active');
    });

    $(".chCategories").on('click', function() {
      //alert($(this).val());
      if($(this).val()!='')
      { 
        $("#chCategories").prop("checked",false);
      }else
        {
           $(".chCategories").prop("checked",false);
           $("#chCategories").prop("checked",true);
        }
      //alert("test");
    });

     $(".chCatechVisitCategorygories").on('click', function() {
      //alert($(this).val());
      if($(this).val()!='')
      { 
        $("#chCategories").prop("checked",false);
      }else
        {
           $(".chCatechVisitCategorygories").prop("checked",false);
           $("#chCategories").prop("checked",true);
        }
      //alert("test");
    });



$(".chCategories").click(function(){
                 $("#placeDetails").html('');
                 $.ajax({
                   type: "POST",
                   url: basurl+"/ExploreAssam/getExploreList",
                   data: $('#frmCategories').serialize(), // serializes the form's elements.
                   success: function(data)
                   {
                    $("#hdRecords").val(6);

                     var content=$.parseJSON(data);
                     var srLength=content.exploreList;
                     var exId=srLength.length;
                     //alert(srLength.length);
                     if(exId==0)
                         $("#placeDetails").html('<div class="col-md-12 col-xs-12" style="text-align:center;">No Records found.</div>');
                      console.log(content);                  
                      appendExploreResult(content);
                     // alert(content.totalPlaces.cnt);
                      if(content.totalPlaces.cnt>6)
                         $("#btnExploreMore").show();
                          else
                            $("#btnExploreMore").hide();

                   }
                 });
            });


$("#btnExploreMore").click(function(){

               $.ajax({
                   type: "POST",
                   url: basurl+"/ExploreAssam/getExploreMoreResults",
                   data: $('#frmCategories').serialize(), // serializes the form's elements.
                   success: function(data)
                     {
                       var content=$.parseJSON(data);
                        $("#hdRecords").val(content.nextset);
                        if(content.showMore==1)
                          $("#btnExploreMore").show();
                          else
                            $("#btnExploreMore").hide();

                          //console.log(content);
                        appendExploreResult(content)
                     }
                 });
});

function appendExploreResult(content)
{
    var expContent='';
    var bgImage='';
    var desc='';
    var converted='';
   $.each(content.exploreList, function (index, value)
       {
        expContent='';
        desc=value.description;
        converted=desc.replace(/(<([^>]+)>)/ig,"")
        bgImage=basurl+"/assets/exploreplaces/"+value.id+"/"+value.thumbnail;
        expContent='<li class="col-md-4"><a href="'+basurl+'/ExploreAssam/Place/'+value.name_slug+'"><img src="'+bgImage+'" alt=""><div class="hlist-title"><h3>'+stripslashes(value.heading)+'</h3><h2>'+stripslashes(value.name)+'</h2></div><div class="hlist-icon"><img src="'+basurl+'/assets/icons/'+value.icon_image+'" class="img-fluid" alt="wildlife icon"></div></a><div class="clistbottom"><p>'+stripslashes(converted.substr(0, 200))+'</p><a href="'+basurl+'/ExploreAssam/Place/'+value.name_slug+'" class="btn btn-outline-dark custombtn">Read More</a></div></li>';
        $("#placeDetails").append(expContent);
        });
}


 $(".chCatechVisitCategorygories").click(function(){
                 $("#placeDetails").html('');
                 $.ajax({
                   type: "POST",
                   url: basurl+"/Places/getPlaces",
                   data: $('#frmCategories').serialize(), // serializes the form's elements.
                   success: function(data)
                   {
                    $("#hdRecords").val(6);
                     var content=$.parseJSON(data);
                     var srLength=content.exploreList;
                     var exId=srLength.length;
                     //alert(srLength.length);
                     if(exId==0)
                         $("#placeDetails").html('<div class="col-md-12 col-xs-12" style="text-align:center;">No Records found.</div>');

                      if(content.totalPlaces>6)
                         $("#btnPlaceMore").show();
                         else
                          $("#btnPlaceMore").hide();
                       appendVisitPlaceMore(content);
                   }
                 });
            });

  $("#btnPlaceMore").click(function(){

                 $.ajax({
                     type: "POST",
                     url: basurl+"/Places/getVisitMorePlaces",
                     data: $('#frmCategories').serialize(), // serializes the form's elements.
                     success: function(data)
                       {
                         var content=$.parseJSON(data);
                          $("#hdRecords").val(content.nextset);
                          if(content.showMore==1)
                            $("#btnPlaceMore").show();
                            else
                              $("#btnPlaceMore").hide();

                            //console.log(content);
                          appendVisitPlaceMore(content);
                       }
                   });
  });
  
  $("#btnEventMenuLoadMore").click(function(){
                 $.ajax({
                     type: "POST",
                     url: basurl+"/Places/getEventLoadMoreData",
                     data: $('#frmEvent').serialize(), // serializes the form's elements.
                     success: function(data)
                       {
                         var content=$.parseJSON(data);
						
						 
                          $("#hdRecords").val(content.nextset);
                          if(content.showMore==1)
                            $("#btnEventMenuLoadMore").show();
                            else
                              $("#btnEventMenuLoadMore").hide();

                          appendEventMoreData(content);
                       }
                   });
  });



  $("#btnLoadmoreImages").click(function(){

       $.ajax({
                   type: "POST",
                   url: basurl+"/ExploreAssam/getMoreImages",
                   data: $('#galleryImages').serialize(), // serializes the form's elements.
                   success: function(data)
                     {
                       var content=$.parseJSON(data);
                        $("#hdRecords").val(content.nextset);
                        if(content.showMore==1)
                          $("#btnLoadmoreImages").show();
                          else
                            $("#btnLoadmoreImages").hide();

                          //console.log(content);
                        appendExploreGallery(content)
                     }
                 });
  });


  $("#loadNearByGallery").click(function(){
        var placeId=$("#hdPlaceId").val();
       $.ajax({
                   type: "POST",
                   url: basurl+"/Places/getMoreImages",
                   data: $('#galleryImages').serialize(), // serializes the form's elements.
                   success: function(data)
                     {
                       var content=$.parseJSON(data);
                        $("#hdRecords").val(content.nextset);
                        if(content.showMore==1)
                          $("#loadNearByGallery").show();
                          else
                            $("#loadNearByGallery").hide();

                          //console.log(content);
                        appendVisitGallery(content,placeId)
                     }
                 });
  });



  $("#txtSearch").keyup(function(){ 
                var search=$("#txtSearch").val();
               // alert(search.length);
                var searchResult='';
                $("#searchResult").html('');
                if(search.length>=3)
                {  
                     $.post(basurl+"/ExploreAssam/getSearchResult", {searchText: search}, function(result){
                            var content=$.parseJSON(result);
                            var srLength=content.properties;
                            $("#searchCount").html(srLength.length+" RESULTS");
                            $.each(content.properties, function (index, value) {
                                    var desc=value.description;
                                    var converted=desc.replace(/(<([^>]+)>)/ig,"")
                                    var link='';
                                    var image='';
									
									if(value.place_id == "event")
									{
										link=basurl+'/Page/eventdetails/'+value.url;
                                        image=basurl+'/assets/exploreplaces/'+value.id+'/'+value.url;
									}else if(value.place_id!=0)
                                    {
                                        link=basurl+'/ExploreAssam/Place/'+value.name_slug;
                                        image=basurl+'/assets/exploreplaces/'+value.id+'/'+value.thumbnail;
                                    }else{
                                        link=basurl+'/Places/PlaceDetails/'+value.name_slug;
                                        image=basurl+'/assets/places/'+value.id+'/'+value.thumbnail;
                                    }
                                   // alert(image);
                                    searchResult='<li><a href="'+link+'" style="color:#444"><div class="simgbkk"><img src="'+image+'" alt=""></div><h4>'+value.name+'</h4><p>'+converted.substr(0, 100)+'...</p></a></li>';
                                    $("#searchResult").append(searchResult);
                                   // alert(searchResult);
                                    //console.log(value);
                                });
                        });
                }

            });



 }); 


function appendVisitGallery(content,placeId)
{
    var galImages='';
    $.each(content.galleryImages, function (index, value) {
        galImages='<a href="'+basurl+'/assets/places/'+placeId+'/thumbs/'+value.url+'" class="meimg" data-fancybox="images"><img src="'+basurl+'/assets/places/'+placeId+'/thumbs/'+value.url+'" alt="Alt text" border="0" /></a>';
    $("#divGallery").append(galImages);
    });
}


function appendExploreGallery(content)
{
    var galImages='';
    $.each(content.galleryImages, function (index, value) {
        galImages='<a href="'+basurl+'/assets/exploreplaces/'+value.place_id+'/medium/'+value.url+'" class="meimg" data-fancybox="images"><img src="'+basurl+'/assets/exploreplaces/'+value.place_id+'/medium/'+value.url+'" alt="Alt text" border="0" /></a>';
    $("#gallery").append(galImages);
    });
}




function appendVisitPlaceMore(content)
{

  var expContent='';
  var bgImage='';
  var desc='';
  var converted='';
  $.each(content.exploreList, function (index, value) {
       expContent='';
       desc=value.description;
       converted=desc.replace(/(<([^>]+)>)/ig,"")
       bgImage=basurl+"/assets/places/"+value.place_id+"/"+value.thumbnail;
       expContent='<li class="col-md-4"><a href="'+basurl+'/Places/PlaceDetails/'+value.name_slug+'"><img src="'+bgImage+'" alt=""><div class="hlist-title"><h3>'+stripslashes(value.heading)+'</h3><h2>'+stripslashes(value.name)+'</h2></div><div class="hlist-icon"><img src="'+basurl+'/assets/icons/'+value.icon_image+'" class="img-fluid" alt="wildlife icon"></div></a><div class="clistbottom"><p>'+stripslashes(converted.substr(0, 200))+'</p><a href="'+basurl+'/Places/PlaceDetails/'+value.name_slug+'" class="btn btn-outline-dark custombtn">Read More</a></div></li>';
       $("#placeDetails").append(expContent);
       });
}



function appendEventMoreData(content)
{
	
	/*<li class="col-md-4">
				<a href="<?php echo $baseURL;?>/Page/eventdetails/<?php echo $place->id;?>">
					<img src="<?php echo $baseURL;?>/assets/events/<?php echo $place->image;?>" alt="">
				</a>
				<div class="eventlistbottom">
					<h4 class="evph4"><?php echo stripslashes($place->title);?></h4>
					<p><?php echo stripslashes($place->description);?></p>
					<a href="<?php echo $baseURL;?>/Page/eventdetails/<?php echo $place->id;?>" class="btn btn-outline-dark custombtn">Read More</a>
				</div>
			</li>*/

  var expContent='';
  var bgImage='';
  var desc='';
  var converted='';
  $.each(content.eventList, function (index, value) {
	
	  var eventHtm = '<li class="col-md-4">'+
						'<a href="'+basurl+'/Page/eventdetails/'+value.id+'">'+
							'<img src="'+basurl+'/assets/events/'+value.image+'" alt="">'+
						'</a>'+
						'<div class="eventlistbottom">'+
						'<h4 class="evph4">'+stripslashes(value.title)+'</h4>'+
						'<p>'+stripslashes(value.description)+'</p>'+
						'<a href="'+basurl+'/Page/eventdetails/'+value.id+'" class="btn btn-outline-dark custombtn">Read More</a>'+
						'</div>'+
					   '</li>';
	  $("#eventData").append(eventHtm);
	  
	  
       /*expContent='';
       desc=value.description;
       converted=desc.replace(/(<([^>]+)>)/ig,"")
       bgImage=basurl+"/assets/places/"+value.place_id+"/"+value.thumbnail;
       expContent='<li class="col-md-4"><a href="'+basurl+'/Places/PlaceDetails/'+value.name_slug+'"><img src="'+bgImage+'" alt=""><div class="hlist-title"><h3>'+stripslashes(value.heading)+'</h3><h2>'+stripslashes(value.name)+'</h2></div><div class="hlist-icon"><img src="'+basurl+'/assets/icons/'+value.icon_image+'" class="img-fluid" alt="wildlife icon"></div></a><div class="clistbottom"><p>'+stripslashes(converted.substr(0, 200))+'</p><a href="'+basurl+'/Places/PlaceDetails/'+value.name_slug+'" class="btn btn-outline-dark custombtn">Read More</a></div></li>';
       $("#placeDetails").append(expContent);*/
  });
}