$(document).ready(function(){   
    var home = site+'home/getJson'
	$.getJSON(home,function(data){
		$.each(data.posts, function(i,post){
		    detail = post.detail;	   
			$("#contents").html(detail);   
		        
		});
	});      
	 
	//delete soal
	$('a.soalDelete').click(function(e) {
		var agree=confirm("Hapus soal ini..?");
		if (agree)
		{
			e.preventDefault();
			var id = $(this).attr("id");
			var dataString = 'id='+ id ;

			var parent = $(this).parent();
			$.ajax({
				type: "POST",
				url: ""+site+"guru/soal/delete",
				data: "id="+ id,

				beforeSend: function() {
					parent.animate({'backgroundColor':'#fb6c6c'},300);
				},
				success: function() {
					$('#id-'+ id).remove();
				}
			});
			}else
			{
				return false ;
			}
		});
		
		//accept soal
		$('a.soalAccept').click(function(e) {
			var agree=confirm("Accept soal ini..?");
			if (agree)
			{
				e.preventDefault();
				var id = $(this).attr("id");
				var dataString = 'id='+ id ;

				var parent = $(this).parent();
				$.ajax({
					type: "POST",
					url: ""+site+"operator/soal/accept",
					data: "id="+ id,

					beforeSend: function() {
						parent.animate({'backgroundColor':'#fb6c6c'},300);
					},
					success: function() {
						$('#id-'+ id).remove();
					}
				});
				}else
				{
					return false ;
				}
			});
			
			//accept soal
			$('a.soalChangeAccept').click(function(e) {
				var agree=confirm("Accept soal ini..?");
				if (agree)
				{
					e.preventDefault();
					var id = $(this).attr("id");
					var dataString = 'id='+ id ;

					var parent = $(this).parent();
					$.ajax({
						type: "POST",
						url: ""+site+"operator/soal/accept",
						data: "id="+ id,

						beforeSend: function() {
							parent.animate({'backgroundColor':'#fb6c6c'},300);
						},
						success: function() {
							$('#id-'+ id).remove();
						}
					});
					}else
					{
						return false ;
					}
				});  
                


		//delete user
		$('a.userDelete').click(function(e) {
			var agree=confirm("Hapus user ini..?");
			if (agree)
			{
				e.preventDefault();
				var id = $(this).attr("id");
				var dataString = 'id='+ id ;

				var parent = $(this).parent();
				$.ajax({
					type: "POST",
					url: ""+site+"operator/user/delete",
					data: "id="+ id,

					beforeSend: function() {
						parent.animate({'backgroundColor':'#fb6c6c'},300);
					},
					success: function() {
						$('#id-'+ id).remove();
					}
				});
				}else
				{
					return false ;
				}
			}); 
			
			//delete user temp
			$('a.userTempDelete').click(function(e) {
				var agree=confirm("Hapus user ini..?");
				if (agree)
				{
					e.preventDefault();
					var id = $(this).attr("id");
					var dataString = 'id='+ id ;

					var parent = $(this).parent();
					$.ajax({
						type: "POST",
						url: ""+site+"operator/user/tempdelete",
						data: "id="+ id,

						beforeSend: function() {
							parent.animate({'backgroundColor':'#fb6c6c'},300);
						},
						success: function() {
							$('#id-'+ id).remove();
						}
					});
					}else
					{
						return false ;
					}
				}); 
				
				//delete berita
				$('a.beritaDelete').click(function(e) {
					var agree=confirm("Hapus berita ini..?");
					if (agree)
					{
						e.preventDefault();
						var id = $(this).attr("id");
						var dataString = 'id='+ id ;

						var parent = $(this).parent();
						$.ajax({
							type: "POST",
							url: ""+site+"operator/berita/delete",
							data: "id="+ id,

							beforeSend: function() {
								parent.animate({'backgroundColor':'#fb6c6c'},300);
							},
							success: function() {
								$('#id-'+ id).remove();
							}
						});
						}else
						{
							return false ;
						}
					});
				//delete Soal Paket
				$('a.paketDelete').click(function(e) {
					var agree=confirm("Hapus soal pada paket ini..?");
					if (agree)
					{
						e.preventDefault();
						var id = $(this).attr("id");
						var dataString = 'id='+ id ;

						var parent = $(this).parent();
						$.ajax({
							type: "POST",
							url: ""+site+"guru/soal/deletePaket",
							data: "id="+ id,

							beforeSend: function() {
								parent.animate({'backgroundColor':'#fb6c6c'},300);
							},
							success: function() {
								$('#id-'+ id).remove();
							}
						});
						window.location.reload(); 
						}else
						{
							return false ;
						}
					});
				
				
	 
   //login  proses
   $("#login > form").submit(function(){
        //$('#ajax_loading').show();
		$('#kirim_response').hide();
     
		var str = $(this).serialize();  

		// -- Start AJAX Call --
		$.ajax({  
		    type: "POST",
		    url: site+"login/cek",  // controller login
			enctype: 'multipart/form-data',
		    data: str,  
		    success: function(msg){  

				$("#login").ajaxComplete(function(event, request, settings){  

				// loading image hilang
				$('#ajax_loading').hide();  
					if(msg == 'OK') // LOGIN OK?
					{  
						$('#kirim_response').hide();
						function direct()
						{
							document.location= site;
						}
						setTimeout(direct(), 10000);
					}  
					else // ERROR?
					{  
						var kirim_responses = msg;
						
						//$('#kirim_response').html(kirim_response);
						//$('#kirim_response').show();      
						jQuery.facebox(kirim_responses)
					}
				});  

			 }  

		  });  
        return false;  

	});
});
	