$(document).ready(function(){
$('#smtp_div').hide();
$('#mail_div').hide();
});
$(function(){
	
$('.tags').tagsinput({
  confirmKeys: [13, 44]
});
});


$(document).ready(function(){ 
	$(function() {
		$("#sort_category ul").sortable({ opacity: 0.6, cursor: 'move', update: function() {
			var order = $(this).sortable("serialize") + '&action=sort_category'; 
			$.post("ajax.php", order, function(theResponse){}); 															 
		}								  
		});
	});
});

$(document).ready(function(){ 
	$(function() {
		$("#sort_media_list ul").sortable({ opacity: 0.6, cursor: 'move', update: function() {
			var order = $(this).sortable("serialize") + '&action=sort_media_list'; 
			$.post("ajax.php", order, function(theResponse){}); 															 
		}								  
		});
	});
});

$(document).ready(function(){ 
	$(function() {
		$("#sort_pages ul").sortable({ opacity: 0.6, cursor: 'move', update: function() {
			var order = $(this).sortable("serialize") + '&action=sort_pages'; 
			$.post("ajax.php", order, function(theResponse){
				
			}); 															 
		}								  
		});
	});
});

$(function() {
  $(".remove-from-list").click(function() {
	var id = $(this).attr('id');
	var dataString = 'id='+id;
	$("a#"+id+" i").removeClass('fa-remove');
	$("a#"+id+" i").addClass('fa-spinner fa-spin');
	$.ajax({
      type: "GET",
      url: 'ajax.php?case=ajax_remove_from_list',
      data: dataString,
	  cache: false,
      success: function(result) {
		  
		  setTimeout(
		  function() 
		  {
		$('li#records_'+id).fadeOut('slow');
		}, 2000);
      }
     });
    return false;
	});
});

function changePage(newLoc)
{
   nextPage = newLoc.options[newLoc.selectedIndex].value
		
   if (nextPage != "")
   {
      document.location.href = nextPage
   }
}

$(function(){
$('[data-toggle="tooltip"]').tooltip({html:true});
$('[data-toggle="popover"]').popover({html:true});
});

$(document).ready(function () {
	
	var IsAutoUpdate = $('#auto_update:checked').length;
	if (IsAutoUpdate > 0) 
           $('#auto_update_period_div').show();
        else 
           $('#auto_update_period_div').hide();
    
	$('#auto_update').change(function () {
        if (this.checked) 
           $('#auto_update_period_div').show();
        else 
           $('#auto_update_period_div').hide();
    });
	
	var IsFeatured = $('#display_featured_slider:checked').length;
	if (IsFeatured > 0) 
           $('#featured_div').show();
        else 
           $('#featured_div').hide();
    
	$('#display_featured_slider').change(function () {
        if (this.checked) 
           $('#featured_div').show();
        else 
           $('#featured_div').hide();
    });
	
	var IsSMTP = $('input[value="smtp"]:checked').length;
	if (IsSMTP > 0) 
           $('#smtp_div').show();
        else 
           $('#smtp_div').hide();
    
	var IsMail = $('input[value="mail"]:checked').length;
	if (IsMail > 0) 
           $('#mail_div').show();
        else 
           $('#mail_div').hide();
	   
	   
	var AllowFacebook = $('#allow_facebook_login:checked').length;
	if (AllowFacebook > 0) 
           $('#facebook-login-div').show();
        else 
           $('#facebook-login-div').hide();
    
	$('#allow_facebook_login').change(function () {
        if (this.checked) 
           $('#facebook-login-div').show();
        else 
           $('#facebook-login-div').hide();
    });
	
	var AllowTwitter = $('#allow_twitter_login:checked').length;
	if (AllowTwitter > 0) 
           $('#twitter-login-div').show();
        else 
           $('#twitter-login-div').hide();
    
	$('#allow_twitter_login').change(function () {
        if (this.checked) 
           $('#twitter-login-div').show();
        else 
           $('#twitter-login-div').hide();
    });
});



function ConfirmLogOut() {
	if(confirm('Proceed To Logout ?'))
		{
		document.location.href = 'logout.php';
	} else {
		confirm.close();
	}
}

function ShowDiv(DivID) {
	if (DivID == 'smtp_div') {
           $('#smtp_div').show();
	       $('#mail_div').hide();
	}  else  {
           $('#smtp_div').hide();
	       $('#mail_div').show();
	}
}

$(function() {
$(".media_grab").click(function() {
var id = $(this).attr("id");
var dataString = 'id='+ id +'&action=media_channel_import';
$("a#"+id+" span").removeClass('fa fa-refresh');		
$("a#"+id+" span").addClass('fa fa-spinner fa-spin');
$.ajax({
   type: "POST",
   url: "ajax.php",
   data: dataString,
   dataType: "html",
   cache: false,
   success: function(result)
   {
	
	//alert(result);
	$("a#"+id+" span").removeClass('fa fa-spinner fa-spin');		
	$("a#"+id+" span").addClass('fa fa-refresh');
	document.location.href = './channels.php';
  }  
  });  
});
});


$(function() {
$(".import-single-video").click(function() {
var id = $(this).attr("id");
var category = $('#category option:selected').val();
var dataString = 'id='+ id +'&category='+ category +'&action=import_single_youtube_video';
$("a#"+id+" i").removeClass('fa fa-refresh');		
$("a#"+id+" i").addClass('fa fa-spinner fa-spin');
$.ajax({
   type: "POST",
   url: "ajax.php",
   data: dataString,
   dataType: "html",
   cache: false,
   success: function(result)
   {
	if (result == 'success') {
	$("a#"+id).removeClass('text-danger');		
	$("a#"+id).addClass('text-success');
	$("div#d"+id+" a").remove();
	$("div#d"+id).html('<span class="text-success"><i class="fa fa-check"></i> Imported</span>');
	} else {
	$("a#"+id).html('<i class="fa fa-close"></i> Error');	
	}
  }  
  });  
});
});



$(function() {
$(".import-dm-single-video").click(function() {
var id = $(this).attr("id");
var category = $('#category option:selected').val();
var dataString = 'id='+ id +'&category='+ category +'&action=import_single_dailymotion_video';
$("a#"+id+" i").removeClass('fa fa-refresh');		
$("a#"+id+" i").addClass('fa fa-spinner fa-spin');
$.ajax({
   type: "POST",
   url: "ajax.php",
   data: dataString,
   dataType: "html",
   cache: false,
   success: function(result)
   {
	if (result == 'success') {
	$("a#"+id).removeClass('text-danger');		
	$("a#"+id).addClass('text-success');
	$("div#dm"+id+" a").remove();
	$("div#dm"+id).html('<span class="text-success"><i class="fa fa-check"></i> Imported</span>');
	} else {
	$("a#"+id).html('<i class="fa fa-close"></i> Error');	
	}
  }  
  });  
});
});

$(function() {
$(".import-channel-single-video").click(function() {
var id = $(this).attr("id");
var category = $(this).attr('rel');
var channel = $(this).attr('scope');
var site = $('.video_box_channel').attr('rel');
var dataString = 'id='+ id +'&category='+ category +'&channel='+ channel +'&site='+ site +'&action=import_channel_single_video';
$("a#"+id+" i").removeClass('fa fa-refresh');		
$("a#"+id+" i").addClass('fa fa-spinner fa-spin');
$.ajax({
   type: "POST",
   url: "ajax.php",
   data: dataString,
   dataType: "html",
   cache: false,
   success: function(result)
   {
	if (result == 'success') {
	$("a#"+id).removeClass('text-danger');		
	$("a#"+id).addClass('text-success');
	$("div#udm"+id+" a").remove();
	$("div#udm"+id).html('<span class="text-success"><i class="fa fa-check"></i> Imported</span>');
	} else {
	$("a#"+id).html('<i class="fa fa-close"></i> Error');	
	}
  }  
  });  
});
});

$(function() {
$("#fetch_facebook_video").click(function() {
var facebook_video_link = $('#facebook_video_link').val();
var category = $('#category option:selected').val();
var dataString = 'facebook_video_link='+ facebook_video_link+'&category='+category+'&action=fetch_facebook_video';
$("#fetch_facebook_video span").removeClass('fa fa-refresh');		
$("#fetch_facebook_video span").addClass('fa fa-spinner fa-spin');
$.ajax({
   type: "POST",
   url: "ajax.php",
   data: dataString,
   dataType: "html",
   cache: false,
   success: function(result)
   {
	$("#fetch_facebook_video span").removeClass('fa fa-spinner fa-spin');		
	$("#fetch_facebook_video span").addClass('fa fa-refresh');
	$("#facebook-video-details").html(result);
  }  
  });  
});
});


$(function() {
$(".import-single-facebook-video").click(function() {
var id = $(this).attr("id");
var category = $('#category option:selected').val();
var dataString = 'id='+ id +'&category='+ category +'&action=import_single_facebook_video';
$("a#"+id+" i").removeClass('fa fa-refresh');		
$("a#"+id+" i").addClass('fa fa-spinner fa-spin');
$.ajax({
   type: "POST",
   url: "ajax.php",
   data: dataString,
   dataType: "html",
   cache: false,
   success: function(result)
   {
	if (result == 'success') {
	$("a#"+id).removeClass('text-danger');		
	$("a#"+id).addClass('text-success');
	$("div#f"+id+" a").remove();
	$("div#f"+id).html('<span class="text-success"><i class="fa fa-check"></i> Imported</span>');
	} else {
	$("a#"+id).html('<i class="fa fa-close"></i> Error');	
	}
  }  
  });  
});
});