var ctx;
var delay = 5000;

function alert(message) {

	iziToast.show({
		title: message,
		timeout: false
	})

}

function log(log, delay = 5000) {

	iziToast.show({
		title: log,
		timeout: delay,
		position: 'bottomLeft'
	});
	
}

function success(message, delay = 5000) {

	iziToast.show({
		title: 'Başarılı',
		message: message,
		timeout: delay,
		position: 'center'
	});

}

function error(message, delay = 5000) {

	iziToast.show({
		title: 'Hata',
		message: message,
		timeout: delay,
		position: 'center'
	});

}

function post(action, data) {
	var request_url = _url + action;
	$.post(request_url, data, function(response) {
		if(response.delay) {
			delay = response.delay;
		}
		if (response.error) {
			error(response.error, delay);
		} else if(response.success) {
			success(response.success, delay);
		} else if(response.log) {
			log(response.log, delay);
		} else if(response.alert) {
			alert(response.alert);
		} else if(response.reload) {
			window.location.reload(!0);
		}
		if(response.edit) {
			if(response.type == "html") {
				$(response.item).html(response.text);
			} else if(response.type == "value") {
				$(response.item).val(response.text);
			}
		}
		if(response.redirect) {
			var delay = 0;
			if(response.delay) {
				delay = response.delay;
			}
			if(response.newtab) {
				setTimeout(function () {
					window.open(response.location, "_top");
				}, response.delay);
			} else {
				setTimeout(function () {
					window.location.href = response.location;
				}, response.delay);
			}
			
		}
		if(response.html){
			$("#online-pay").html(response.html);
		}
	}, 'json').fail(function() {
		error(messages["UNKNOWN_ERROR"]);
	});
}

$(document).delegate('form', 'submit', function(event) {
	var form = $(this);
	var id = form.attr('id');
	var data = form.serialize();
	if(id != null && id != undefined && id != "") {
		if(!form.hasClass("loading")) {
			form.addClass("loading");
			var request_url = _url + id;
			$.post(request_url, data, function(response) {
				if($(".g-recaptcha").length) {
					grecaptcha.reset();
				}
				if(response.delay) {
					delay = response.delay;
				}
				if (response.error) {
					error(response.error, delay);
				} else if(response.success) {
					success(response.success, delay);
					if(id == "new_order") {
						$("#balance").html(response.balance);
						$("#drip-group").addClass("hide");
						$("#comment-group").addClass("hide");
						$("#link").val("");
						$("#quantity").val("");
						$("#amount").val("0");
					} else {
						if(form.data("reset") == "1") {
							form[0].reset();
						}
					}
				} else if(response.log) {
					log(response.log, delay);
				} else if(response.alert) {
					alert(response.alert);
				} else if(response.reload) {
					window.location.reload(!0);
				}
				if(response.edit) {
					if(response.type == "html") {
						$(response.item).html(response.text);
					} else if(response.type == "value") {
						$(response.item).val(response.text);
					}
				}
				if(response.redirect) {
					var delay = 0;
					if(response.delay) {
						delay = response.delay;
					}
					if(response.newtab) {
						setTimeout(function () {
							window.open(response.location, "_top");
						}, response.delay);
					} else {
						setTimeout(function () {
							window.location.href = response.location;
						}, response.delay);
					}
					
				}
			}, 'json').fail(function() {
				error(messages["UNKNOWN_ERROR"]);
			}).always(function() {
				form.removeClass("loading");
			});
		} else {
			log(messages["PROCESS_ERROR"]);
		}
	}
});

$(function() {

	$("body").toggleClass(localStorage.toggled);

	if ($("body").hasClass('dark')) {
		$('body').toggleClass('dark-mode', true);
		$('#nightIcon').html('<i class="fas fa-sun"></i>');
	} else {
		$('body').toggleClass('dark-mode', false);
		$('#nightIcon').html('<i class="fa fa-moon"></i>');
	}

	$('[data-toggle="tooltip"]').tooltip();

	$("#myInput").on("keyup", function () {
		var value = $(this).val().toLowerCase();
		$("#myTable tr").filter(function () {
			$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
		});
	});

	$("#orderModal").on("hidden.bs.modal", function () {$("#orderModalBody").html("");});
	$('.input-daterange').datepicker({format: "dd/mm/yyyy"});
	$('[data-toggle="tooltip"]').tooltip();
	$(".messages").animate({scrollTop: 10000}, 500);
	var url = window.location;
	var element = $('ul.navbar-nav li a').filter(function() {
		return this.href == url
	}).parent().addClass('active');
	var element = $('ul.nav-tabs li a').filter(function() {
		return this.href == url
	}).addClass('active');

});

function darkLight() {
	if(localStorage.toggled != 'dark') {
		$('body').toggleClass('dark-mode', true);
		$('#nightIcon').html('<i class="fas fa-sun"></i>');
		localStorage.toggled = "dark";
	}else{
		$('body').toggleClass('dark-mode', false);
		$('#nightIcon').html('<i class="fa fa-moon"></i>');
		localStorage.toggled = "";
	}
}


function change_ordering(id) {
    console.log(id);
		success('Servis sırasını artık düzenleyebilirsiniz.');
	if(id == "categories" || id == "services") {
		$("tbody#"+id).css("cursor", "move");
		$("tbody#"+id).sortable({
			stop: function(event, ui) {
				$("tbody#"+id).each(function() {
					var result = [];
					$(this).find("tr").each(function(){
					    if($(this).data("id")){
						result.push($(this).data("id"));
						
					    }
					});
					post("update_ordering", {type:id,ordering:result});
				});
			}
		});
		success('Servis sırasını artık düzenleyebilirsiniz.');
	}else if(id == "servicesrow"){
		var deneme =$('.panel-body').length;
		console.log(deneme);
		var i;
		for (i = 1; i <= deneme; i++) {
			var ev = i;
			$("tbody#services"+i).css("cursor", "move");
			$("tbody#services"+i).sortable({

				stop: function(event, ui) {
					var e;
					var result = [];
					for (e = 1; e <= deneme; e++) { 
						$("tbody#services"+e).each(function() {

							$("tbody#services"+e).find("tr").each(function(){
							    if($(this).data("id")){
								result.push($(this).data("id"));
								console.log("mert");
							    }
							});


						});
					}
					post("update_ordering", {type:'services',ordering:result});
				}
			});
		}

	}
		/*$("tbody#"+id).sortable({
			stop: function(event, ui) {
				$("tbody#"+id).each(function() {
					var result = [];
					$(this).find("tr").each(function(){
						result.push($(this).data("id"));
					});
					$('#mert').html(result+"<br>");
					post("update_ordering", {type:id,ordering:result});
				});
			}
		});*/


	}

	function saveFile(theme, file) {
		if(file != null) {
			alertify.okBtn("Kaydet");
			alertify.cancelBtn("Vazgeç");
			alertify.confirm("Emin misiniz?", function () {
				post("update_file", {theme:theme,file:file,content:editor.getValue()});
			}, function() {

			});
		}
	}

	function send_order(id) {
		var data = {id:id};
		post("send_order", data);
	}

	function cancel_order(id) {
		var data = {id:id};
		post("cancel_order", data);
	}

	function update_drip_status(id) {
		var status = $("#status_"+id).val();
		var data = {id:id,status:status};
		post("update_drip_status", data);
	}

	function delete_drip(id) {
		iziToast.show({
			theme: 'dark',
			title: 'Silme İşlemi',
			message: 'Silmek istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

			['<button>Evet</button>', function (instance, toast) {

				var data = {id:id};
				post("delete_drip", data);
				instance.hide({
					transitionOut: 'fadeOutUp',
					onClosing: function(instance, toast, closedBy){
		                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
		            }
		        }, toast, 'buttonName');

	        }, true], // true to focus
	        ['<button>Hayır</button>', function (instance, toast) {
	        	instance.hide({
	        		transitionOut: 'fadeOutUp',
	        		onClosing: function(instance, toast, closedBy){
	                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
	                }
	            }, toast, 'buttonName');
	        }]
	        ]
	    });
	}

	function delete_child(id) {
		iziToast.show({
			theme: 'dark',
			title: 'Silme İşlemi',
			message: 'Silmek istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

			['<button>Evet</button>', function (instance, toast) {

				var data = {id:id};
				post("delete_child", data);
				instance.hide({
					transitionOut: 'fadeOutUp',
					onClosing: function(instance, toast, closedBy){
		                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
		            }
		        }, toast, 'buttonName');

	        }, true], // true to focus
	        ['<button>Hayır</button>', function (instance, toast) {
	        	instance.hide({
	        		transitionOut: 'fadeOutUp',
	        		onClosing: function(instance, toast, closedBy){
	                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
	                }
	            }, toast, 'buttonName');
	        }]
	        ]
	    });
	}


	function delete_menu(id) {
		iziToast.show({
			theme: 'dark',
			title: 'Silme İşlemi',
			message: 'Silmek istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

			['<button>Evet</button>', function (instance, toast) {

				var data = {id:id};
				post("delete_menu", data);
				instance.hide({
					transitionOut: 'fadeOutUp',
					onClosing: function(instance, toast, closedBy){
		                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
		            }
		        }, toast, 'buttonName');

	        }, true], // true to focus
	        ['<button>Hayır</button>', function (instance, toast) {
	        	instance.hide({
	        		transitionOut: 'fadeOutUp',
	        		onClosing: function(instance, toast, closedBy){
	                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
	                }
	            }, toast, 'buttonName');
	        }]
	        ]
	    });
	}
	
	function delete_logo() {
		iziToast.show({
			theme: 'dark',
			title: 'Silme İşlemi',
			message: 'Silmek istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

			['<button>Evet</button>', function (instance, toast) {

				var data = {id:id};
				post("delete_logo", data);
				instance.hide({
					transitionOut: 'fadeOutUp',
					onClosing: function(instance, toast, closedBy){
		                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
		            }
		        }, toast, 'buttonName');

	        }, true], // true to focus
	        ['<button>Hayır</button>', function (instance, toast) {
	        	instance.hide({
	        		transitionOut: 'fadeOutUp',
	        		onClosing: function(instance, toast, closedBy){
	                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
	                }
	            }, toast, 'buttonName');
	        }]
	        ]
	    });
	}

	function delete_bonus(id) {
		iziToast.show({
			theme: 'dark',
			title: 'Silme İşlemi',
			message: 'Silmek istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

			['<button>Evet</button>', function (instance, toast) {

				var data = {id:id};
				post("delete_bonus", data);
				instance.hide({
					transitionOut: 'fadeOutUp',
					onClosing: function(instance, toast, closedBy){
		                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
		            }
		        }, toast, 'buttonName');

	        }, true], // true to focus
	        ['<button>Hayır</button>', function (instance, toast) {
	        	instance.hide({
	        		transitionOut: 'fadeOutUp',
	        		onClosing: function(instance, toast, closedBy){
	                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
	                }
	            }, toast, 'buttonName');
	        }]
	        ]
	    });
	}

	function delete_proxy(id) {
		iziToast.show({
			theme: 'dark',
			title: 'Silme İşlemi',
			message: 'Silmek istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

			['<button>Evet</button>', function (instance, toast) {

				var data = {id:id};
				post("delete_proxy", data);
				instance.hide({
					transitionOut: 'fadeOutUp',
					onClosing: function(instance, toast, closedBy){
		                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
		            }
		        }, toast, 'buttonName');

	        }, true], // true to focus
	        ['<button>Hayır</button>', function (instance, toast) {
	        	instance.hide({
	        		transitionOut: 'fadeOutUp',
	        		onClosing: function(instance, toast, closedBy){
	                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
	                }
	            }, toast, 'buttonName');
	        }]
	        ]
	    });
	}

	function proxy_check(id) {
		var data = {id:id};
		post("proxy_check", data);
	}

	function user_block(id) {
		iziToast.show({
			theme: 'dark',
			title: 'Kullanıcılar',
			message: 'Bu işlemi yapmak istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

			['<button>Evet</button>', function (instance, toast) {

				var data = {id:id};
				post("user_block", data);
				instance.hide({
					transitionOut: 'fadeOutUp',
					onClosing: function(instance, toast, closedBy){
		                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
		            }
		        }, toast, 'buttonName');

	        }, true], // true to focus
	        ['<button>Hayır</button>', function (instance, toast) {
	        	instance.hide({
	        		transitionOut: 'fadeOutUp',
	        		onClosing: function(instance, toast, closedBy){
	                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
	                }
	            }, toast, 'buttonName');
	        }]
	        ]
	    });
	}

	function servicestatus(id, type) {
		iziToast.show({
			theme: 'dark',
			title: '[SERVİSLER]',
			message: 'Bu işlemi uygulamak istediğinden emin misin?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

			['<button>Evet</button>', function (instance, toast) {

				var data = {id:id, type:type};
				post("update_servicestatus", data);
				instance.hide({
					transitionOut: 'fadeOutUp',
					onClosing: function(instance, toast, closedBy){
		                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
		            }
		        }, toast, 'buttonName');

	        }, true], // true to focus
	        ['<button>Hayır</button>', function (instance, toast) {
	        	instance.hide({
	        		transitionOut: 'fadeOutUp',
	        		onClosing: function(instance, toast, closedBy){
	                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
	                }
	            }, toast, 'buttonName');
	        }]
	        ]
	    });
	}

	function themeChange(id) {

		iziToast.show({
			theme: 'dark',
			title: 'Tema Yönetimi',
			message: 'Temayı değiştirmek istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

			['<button>Evet</button>', function (instance, toast) {

				var data = {id:id};
				post("theme_change", data);
				instance.hide({
					transitionOut: 'fadeOutUp',
					onClosing: function(instance, toast, closedBy){
		                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
		            }
		        }, toast, 'buttonName');

		    }, true], // true to focus
		    ['<button>Hayır</button>', function (instance, toast) {
		    	instance.hide({
		    		transitionOut: 'fadeOutUp',
		    		onClosing: function(instance, toast, closedBy){
		                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
		            }
		        }, toast, 'buttonName');
		    }]

		    ]

		});

	}

	function update_auto_status(id, status) {
		var data = {id:id,status:status};
		post("update_auto_status", data);
	}

	function delete_auto(id) {
		iziToast.show({
			theme: 'dark',
			title: 'Silme İşlemi',
			message: 'Silmek istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

			['<button>Evet</button>', function (instance, toast) {

				var data = {id:id};
				post("delete_auto", data);
				instance.hide({
					transitionOut: 'fadeOutUp',
					onClosing: function(instance, toast, closedBy){
		                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
		            }
		        }, toast, 'buttonName');

	        }, true], // true to focus
	        ['<button>Hayır</button>', function (instance, toast) {
	        	instance.hide({
	        		transitionOut: 'fadeOutUp',
	        		onClosing: function(instance, toast, closedBy){
	                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
	                }
	            }, toast, 'buttonName');
	        }]
	        ]
	    });
	}

	function updateScriptProcess() {
		post("update_script");
	}

	function updateScript() {

		iziToast.show({
			theme: 'dark',
			title: 'Güncelleme Yöneticisi',
			message: 'Güncelleme başlatılacak, veritabanı yedeğinizi aldığınızdan emin olunuz. Başlatılsın mı?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

			['<button>Evet</button>', function (instance, toast) {

				updateScriptProcess();

				instance.hide({
					transitionOut: 'fadeOutUp',
					onClosing: function(instance, toast, closedBy){
		                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
		            }
		        }, toast, 'buttonName');

	        }, true], // true to focus
	        ['<button>Hayır</button>', function (instance, toast) {
	        	instance.hide({
	        		transitionOut: 'fadeOutUp',
	        		onClosing: function(instance, toast, closedBy){
	                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
	                }
	            }, toast, 'buttonName');
	        }]
	        ]
	    });

	}

	function order_multiple_cancel(){

		var i;
		var e = [];
		for (i = 0; i < $('#totalcheckbox').val(); i++) {
		    var checkbox = document.getElementById('checkbox'+i);
		    if(checkbox) {
    			if(checkbox.checked){
    				e.push($('#checkbox'+i).val());
    			}
		    }

		}

		iziToast.show({
			theme: 'dark',
			title: 'İptal ve İade Et',
			message: 'Seçilen siparişlere bu işlemi uygulamak istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

				['<button>Evet</button>', function (instance, toast) {

					var data = {id:e};
					post("order_multiple_cancel", data);
					instance.hide({
						transitionOut: 'fadeOutUp',
						onClosing: function(instance, toast, closedBy){
					                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
					            }
					        }, toast, 'buttonName');

				        }, true], // true to focus
				['<button>Hayır</button>', function (instance, toast) {
			        	instance.hide({
			        		transitionOut: 'fadeOutUp',
			        		onClosing: function(instance, toast, closedBy){
			                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
			                }
			            }, toast, 'buttonName');
				}]
			]
		});

	}
	function service_multiple_on(){

		var i;
		var e = [];
		for (i = 0; i < $('#totalcheckbox').val(); i++) {
		    var checkbox = document.getElementById('checkbox'+i);
		    if(checkbox) {
    			if(checkbox.checked){
    				e.push($('#checkbox'+i).val());
    			}
		    }

		}

		iziToast.show({
			theme: 'dark',
			title: 'Toplu Servis Aktifleştir',
			message: 'Seçilen servislere bu işlemi uygulamak istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

				['<button>Evet</button>', function (instance, toast) {

					var data = {id:e};
					post("service_multiple_on", data);
					instance.hide({
						transitionOut: 'fadeOutUp',
						onClosing: function(instance, toast, closedBy){
					                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
					            }
					        }, toast, 'buttonName');

				        }, true], // true to focus
				['<button>Hayır</button>', function (instance, toast) {
			        	instance.hide({
			        		transitionOut: 'fadeOutUp',
			        		onClosing: function(instance, toast, closedBy){
			                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
			                }
			            }, toast, 'buttonName');
				}]
			]
		});

	}

	function log_multiple_delete(){
		console.log("test");

		var i;
		var e = [];
		for (i = 0; i < $('#totalcheckbox').val(); i++) {
		    var checkbox = document.getElementById('checkbox'+i);
		    if(checkbox) {
    			if(checkbox.checked){
    				e.push($('#checkbox'+i).val());
    			}
		    }

		}

		iziToast.show({
			theme: 'dark',
			title: 'Toplu Log Sil',
			message: 'Seçilen loglara bu işlemi uygulamak istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

				['<button>Evet</button>', function (instance, toast) {

					var data = {id:e};
					post("log_multiple_delete", data);
					instance.hide({
						transitionOut: 'fadeOutUp',
						onClosing: function(instance, toast, closedBy){
					                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
					            }
					        }, toast, 'buttonName');

				        }, true], // true to focus
				['<button>Hayır</button>', function (instance, toast) {
			        	instance.hide({
			        		transitionOut: 'fadeOutUp',
			        		onClosing: function(instance, toast, closedBy){
			                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
			                }
			            }, toast, 'buttonName');
				}]
			]
		});

	}

	function provider_multiple_delete(){

		var i;
		var e = [];
		for (i = 0; i < $('#totalcheckbox').val(); i++) {
		    var checkbox = document.getElementById('checkbox'+i);
		    if(checkbox) {
    			if(checkbox.checked){
    				e.push($('#checkbox'+i).val());
    			}
		    }

		}

		iziToast.show({
			theme: 'dark',
			title: 'Toplu Log Sil',
			message: 'Seçilen loglara bu işlemi uygulamak istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

				['<button>Evet</button>', function (instance, toast) {

					var data = {id:e};
					post("provider_multiple_delete", data);
					instance.hide({
						transitionOut: 'fadeOutUp',
						onClosing: function(instance, toast, closedBy){
					                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
					            }
					        }, toast, 'buttonName');

				        }, true], // true to focus
				['<button>Hayır</button>', function (instance, toast) {
			        	instance.hide({
			        		transitionOut: 'fadeOutUp',
			        		onClosing: function(instance, toast, closedBy){
			                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
			                }
			            }, toast, 'buttonName');
				}]
			]
		});

	}

	function automation_multiple_delete(){

		var i;
		var e = [];
		for (i = 0; i < $('#totalcheckbox').val(); i++) {
		    var checkbox = document.getElementById('checkbox'+i);
		    if(checkbox) {
    			if(checkbox.checked){
    				e.push($('#checkbox'+i).val());
    			}
		    }

		}

		iziToast.show({
			theme: 'dark',
			title: 'Toplu Log Sil',
			message: 'Seçilen loglara bu işlemi uygulamak istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

				['<button>Evet</button>', function (instance, toast) {

					var data = {id:e};
					post("automation_multiple_delete", data);
					instance.hide({
						transitionOut: 'fadeOutUp',
						onClosing: function(instance, toast, closedBy){
					                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
					            }
					        }, toast, 'buttonName');

				        }, true], // true to focus
				['<button>Hayır</button>', function (instance, toast) {
			        	instance.hide({
			        		transitionOut: 'fadeOutUp',
			        		onClosing: function(instance, toast, closedBy){
			                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
			                }
			            }, toast, 'buttonName');
				}]
			]
		});

	}
	
	function crons_multiple_delete(){

		var i;
		var e = [];
		for (i = 0; i < $('#totalcheckbox').val(); i++) {
		    var checkbox = document.getElementById('checkbox'+i);
		    if(checkbox) {
    			if(checkbox.checked){
    				e.push($('#checkbox'+i).val());
    			}
		    }

		}

		iziToast.show({
			theme: 'dark',
			title: 'Toplu Log Sil',
			message: 'Seçilen loglara bu işlemi uygulamak istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

				['<button>Evet</button>', function (instance, toast) {

					var data = {id:e};
					post("crons_multiple_delete", data);
					instance.hide({
						transitionOut: 'fadeOutUp',
						onClosing: function(instance, toast, closedBy){
					                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
					            }
					        }, toast, 'buttonName');

				        }, true], // true to focus
				['<button>Hayır</button>', function (instance, toast) {
			        	instance.hide({
			        		transitionOut: 'fadeOutUp',
			        		onClosing: function(instance, toast, closedBy){
			                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
			                }
			            }, toast, 'buttonName');
				}]
			]
		});

	}

	function service_multiple_off(){

		var i;
		var e = [];
		for (i = 0; i < $('#totalcheckbox').val(); i++) {
		    var checkbox = document.getElementById('checkbox'+i);
		    if(checkbox) {
    			if(checkbox.checked){
    				e.push($('#checkbox'+i).val());
    			}
		    }

		}

		iziToast.show({
			theme: 'dark',
			title: 'Toplu Servis Pasifleştir',
			message: 'Seçilen servislere bu işlemi uygulamak istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

				['<button>Evet</button>', function (instance, toast) {

					var data = {id:e};
					post("service_multiple_off", data);
					instance.hide({
						transitionOut: 'fadeOutUp',
						onClosing: function(instance, toast, closedBy){
					                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
					            }
					        }, toast, 'buttonName');

				        }, true], // true to focus
				['<button>Hayır</button>', function (instance, toast) {
			        	instance.hide({
			        		transitionOut: 'fadeOutUp',
			        		onClosing: function(instance, toast, closedBy){
			                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
			                }
			            }, toast, 'buttonName');
				}]
			]
		});

	}
	function service_multiple_delete(){

		var i;
		var e = [];
		for (i = 0; i < $('#totalcheckbox').val(); i++) {
		    var checkbox = document.getElementById('checkbox'+i);
		    if(checkbox) {
    			if(checkbox.checked){
    				e.push($('#checkbox'+i).val());
    			}
		    }

		}

		iziToast.show({
			theme: 'dark',
			title: 'Toplu Servis Sil',
			message: 'Seçilen servislere bu işlemi uygulamak istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

				['<button>Evet</button>', function (instance, toast) {

					var data = {id:e};
					post("service_multiple_delete", data);
					instance.hide({
						transitionOut: 'fadeOutUp',
						onClosing: function(instance, toast, closedBy){
					                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
					            }
					        }, toast, 'buttonName');

				        }, true], // true to focus
				['<button>Hayır</button>', function (instance, toast) {
			        	instance.hide({
			        		transitionOut: 'fadeOutUp',
			        		onClosing: function(instance, toast, closedBy){
			                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
			                }
			            }, toast, 'buttonName');
				}]
			]
		});

	}

	$('#modalDefault').on('show.bs.modal', function(e) {
		var request_url = _url + $(e.relatedTarget).data('action');

		$("#modal-title").html('Yükleniyor...');
		$("#modal-content").html('<div style="text-align:center;"><img style="height:100px;" src="https://i.hizliresim.com/o5k6EZ.gif"></div>');

		$.post(request_url, {id:$(e.relatedTarget).data('id') }, function(data){

			$("#modal-title").html(data.title);
			$("#modal-content").html(data.order);

		},'json');

	});

	function delete_account(id) {
		iziToast.show({
			theme: 'dark',
			title: 'Silme İşlemi',
			message: 'Silmek istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

			['<button>Evet</button>', function (instance, toast) {

				var data = {id:id};
				post("delete_account", data);
				instance.hide({
					transitionOut: 'fadeOutUp',
					onClosing: function(instance, toast, closedBy){
		                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
		            }
		        }, toast, 'buttonName');

	        }, true], // true to focus
	        ['<button>Hayır</button>', function (instance, toast) {
	        	instance.hide({
	        		transitionOut: 'fadeOutUp',
	        		onClosing: function(instance, toast, closedBy){
	                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
	                }
	            }, toast, 'buttonName');
	        }]
	        ]
	    });
	}

	function show_order(id) {
		var request_url = _url + "get_order";

		$("#modal-title").html('Yükleniyor...');
		$("#modal-content").html('<div style="text-align:center;"><img src="https://i.hizliresim.com/o5k6EZ.gif"></div>');

		$.post(request_url, {id:id}, function(response) {
			if (response.error) {
				error(response.error, delay);
			} else {

				$("#modal-title").html(response.title);
				$("#modal-content").html(response.order);

			}
		}, 'json').fail(function() {
			error(messages["UNKNOWN_ERROR"]);
		});

	}

	function openticket(id) {
		var request_url = _url + "get_ticket";

		$("#chat-body").html('<div style="text-align:center;height:662px;"><img style="height:100px;" src="https://i.hizliresim.com/o5k6EZ.gif"></div>');

		$.post(request_url, {id:id}, function(response) {
			if (response.error) {
				error(response.error, delay);
			} else {

				$("#chat-body").html(response.order);

			}
		}, 'json').fail(function() {
			error(messages["UNKNOWN_ERROR"]);
		});

	}

	function alltickets() {
		var request_url = _url + "get_alltickets";

		$("#chat-list").html('<div style="text-align:center;height:662px;"><img style="height:100px;" src="https://i.hizliresim.com/o5k6EZ.gif"></div>');

		$.post(request_url, function(response) {
			if (response.error) {
				error(response.error, delay);
			} else {

				$("#chat-list").html(response.order);

			}
		}, 'json').fail(function() {
			error(messages["UNKNOWN_ERROR"]);
		});

	}

	function show_sendsms(id) {
		var request_url = _url + "get_sendsms";

		$("#modal-title").html('Yükleniyor...');
		$("#modal-content").html('<div style="text-align:center;"><img src="https://i.hizliresim.com/o5k6EZ.gif"></div>');

		$.post(request_url, {id:id}, function(response) {
			if (response.error) {
				error(response.error, delay);
			} else {

				$("#modal-title").html(response.title);
				$("#modal-content").html(response.order);

			}
		}, 'json').fail(function() {
			error(messages["UNKNOWN_ERROR"]);
		});

	}

	function show_usersms(id) {
		var request_url = _url + "get_usersms";

		$("#modal-title").html('Yükleniyor...');
		$("#modal-content").html('<div style="text-align:center;"><img src="https://i.hizliresim.com/o5k6EZ.gif"></div>');

		$.post(request_url, {id:id}, function(response) {
			if (response.error) {
				error(response.error, delay);
			} else {

				$("#modal-title").html(response.title);
				$("#modal-content").html(response.order);

			}
		}, 'json').fail(function() {
			error(messages["UNKNOWN_ERROR"]);
		});

	}

	function show_account(id) {
		var request_url = _url + "get_account";

		$("#modal-title").html('Yükleniyor...');
		$("#modal-content").html('<div style="text-align:center;"><img src="https://i.hizliresim.com/o5k6EZ.gif"></div>');

		$.post(request_url, {id:id}, function(response) {
			if (response.error) {
				error(response.error, delay);
			} else {

				$("#modal-title").html(response.title);
				$("#modal-content").html(response.order);

			}
		}, 'json').fail(function() {
			error(messages["UNKNOWN_ERROR"]);
		});

	}

	function show_duyuru(id) {
		var request_url = _url + "get_duyuru";

		$("#modal-title").html('Yükleniyor...');
		$("#modal-content").html('<div style="text-align:center;"><img src="https://i.hizliresim.com/o5k6EZ.gif"></div>');

		$.post(request_url, {id:id}, function(response) {
			if (response.error) {
				error(response.error, delay);
			} else {

				$("#modal-title").html(response.title);
				$("#modal-content").html(response.order);

			}
		}, 'json').fail(function() {
			error(messages["UNKNOWN_ERROR"]);
		});

	}

	function show_category(id) {
		var request_url = _url + "get_category";

		$("#modal-title").html('Yükleniyor...');
		$("#modal-content").html('<div style="text-align:center;"><img src="https://i.hizliresim.com/o5k6EZ.gif"></div>');

		$.post(request_url, {id:id}, function(response) {
			if (response.error) {
				error(response.error, delay);
			} else {

				$("#modal-title").html(response.title);
				$("#modal-content").html(response.order);

			}
		}, 'json').fail(function() {
			error(messages["UNKNOWN_ERROR"]);
		});

	}

	function show_module(id) {
		var request_url = _url + "get_payment";

		$("#modal-title").html('Yükleniyor...');
		$("#modal-content").html('<div style="text-align:center;"><img src="https://i.hizliresim.com/o5k6EZ.gif"></div>');

		$.post(request_url, {id:id}, function(response) {
			if (response.error) {
				error(response.error, delay);
			} else {

				$("#modal-title").html(response.title);
				$("#modal-content").html(response.order);

			}
		}, 'json').fail(function() {
			error(messages["UNKNOWN_ERROR"]);
		});

	}

	function edit_provider(id) {
		var request_url = _url + "edit_provider";

		$("#modal-title").html('Yükleniyor...');
		$("#modal-content").html('<div style="text-align:center;"><img src="https://i.hizliresim.com/o5k6EZ.gif"></div>');

		$.post(request_url, {id:id}, function(response) {
			if (response.error) {
				error(response.error, delay);
			} else {

				$("#modal-title").html(response.title);
				$("#modal-content").html(response.order);

			}
		}, 'json').fail(function() {
			error(messages["UNKNOWN_ERROR"]);
		});

	}

	function show_ticket(id) {
		var request_url = _url + "get_ticket";

		$("#modal-title").html('Yükleniyor...');
		$("#modal-content").html('<div style="text-align:center;"><img src="https://i.hizliresim.com/o5k6EZ.gif"></div>');

		$.post(request_url, {id:id}, function(response) {
			if (response.error) {
				error(response.error, delay);
			} else {

				$("#modal-title").html(response.title);
				$("#modal-content").html(response.order);

			}
		}, 'json').fail(function() {
			error(messages["UNKNOWN_ERROR"]);
		});

	}

	function delete_duyuru(id) {

		iziToast.show({
			theme: 'dark',
			title: 'Silme İşlemi',
			message: 'Silmek istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

			['<button>Evet</button>', function (instance, toast) {

				var data = {id:id};
				post("delete_duyuru", data);
				instance.hide({
					transitionOut: 'fadeOutUp',
					onClosing: function(instance, toast, closedBy){
		                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
		            }
		        }, toast, 'buttonName');

	        }, true], // true to focus
	        ['<button>Hayır</button>', function (instance, toast) {
	        	instance.hide({
	        		transitionOut: 'fadeOutUp',
	        		onClosing: function(instance, toast, closedBy){
	                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
	                }
	            }, toast, 'buttonName');
	        }]
	        ]
	    });

	}

	function delete_blog(id) {

		iziToast.show({
			theme: 'dark',
			title: 'Silme İşlemi',
			message: 'Silmek istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

			['<button>Evet</button>', function (instance, toast) {

				var data = {id:id};
				post("delete_blog", data);
				instance.hide({
					transitionOut: 'fadeOutUp',
					onClosing: function(instance, toast, closedBy){
		                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
		            }
		        }, toast, 'buttonName');

	        }, true], // true to focus
	        ['<button>Hayır</button>', function (instance, toast) {
	        	instance.hide({
	        		transitionOut: 'fadeOutUp',
	        		onClosing: function(instance, toast, closedBy){
	                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
	                }
	            }, toast, 'buttonName');
	        }]
	        ]
	    });

	}
function delete_sayfa(id) {

		iziToast.show({
			theme: 'dark',
			title: 'Silme İşlemi',
			message: 'Silmek istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

			['<button>Evet</button>', function (instance, toast) {

				var data = {id:id};
				post("delete_sayfa", data);
				instance.hide({
					transitionOut: 'fadeOutUp',
					onClosing: function(instance, toast, closedBy){
		                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
		            }
		        }, toast, 'buttonName');

	        }, true], // true to focus
	        ['<button>Hayır</button>', function (instance, toast) {
	        	instance.hide({
	        		transitionOut: 'fadeOutUp',
	        		onClosing: function(instance, toast, closedBy){
	                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
	                }
	            }, toast, 'buttonName');
	        }]
	        ]
	    });

	}
	function update_order_status(id, status) {
		var remains = 0;
		if(status == "Partial") {
			alertify.okBtn("Güncelle").cancelBtn("Vazgeç").defaultValue("0").prompt("Kalan miktarı yazın:",
				function (val, ev) {
					ev.preventDefault();
					if(Math.floor(val) == val && $.isNumeric(val) && val > 0) {
						remains = val;
						var data = {id:id,status:status,remains:remains};
						post("update_order_status", data);
					} else {
						log("Boş veya hatalı değer!");
					}
				}, function(ev) {
					ev.preventDefault();
				});
		} else {

			iziToast.show({
				theme: 'dark',
				title: '[Siparişler]',
				message: 'Bu işlemi yapmak istediğinizden emin misiniz?',
				position: 'center',
				displayMode: 1,
				timeout: false,
				buttons: [

				['<button>Evet</button>', function (instance, toast) {

					var data = {id:id,status:status,remains:remains};
					post("update_order_status", data);
					instance.hide({
						transitionOut: 'fadeOutUp',
						onClosing: function(instance, toast, closedBy){
			                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
			            }
			        }, toast, 'buttonName');

		        }, true], // true to focus
		        ['<button>Hayır</button>', function (instance, toast) {
		        	instance.hide({
		        		transitionOut: 'fadeOutUp',
		        		onClosing: function(instance, toast, closedBy){
		                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
		                }
		            }, toast, 'buttonName');
		        }]
		        ]
		    });
		}
	}

	function update_order_count(id) {

		alertify.okBtn("Güncelle").cancelBtn("Vazgeç").defaultValue("0").prompt("Başlangıç miktarını yazın:",
			function (val, ev) {
				ev.preventDefault();
				if(Math.floor(val) == val && $.isNumeric(val) && val > 0) {
					remains = val;
					var data = {id:id,count:remains};
					post("update_order_count", data);
				} else {
					log("Boş veya hatalı değer!");
				}
			}, function(ev) {
				ev.preventDefault();
			});

	}

	function delete_order(id) {

		iziToast.show({
			theme: 'dark',
			title: 'Silme İşlemi',
			message: 'Silmek istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

			['<button>Evet</button>', function (instance, toast) {

				var data = {id:id};
				post("delete_order", data);
				instance.hide({
					transitionOut: 'fadeOutUp',
					onClosing: function(instance, toast, closedBy){
		                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
		            }
		        }, toast, 'buttonName');

	        }, true], // true to focus
	        ['<button>Hayır</button>', function (instance, toast) {
	        	instance.hide({
	        		transitionOut: 'fadeOutUp',
	        		onClosing: function(instance, toast, closedBy){
	                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
	                }
	            }, toast, 'buttonName');
	        }]
	        ]
	    });

	}

	function task_deny(id, type) {

		iziToast.show({
			theme: 'dark',
			title: '[Sipariş İşlemleri]',
			message: 'Yapacağınız işlem sağlayıcınıza iletilmez, kendiniz iletmeniz gerekiyor.<br>Bunun bilincinde olarak işlemi gerçekleştiriniz.<br>Bu işlemi yapmak istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

			['<button>Evet</button>', function (instance, toast) {

				var data = {id:id, type:type};
				post("task_deny", data);
				instance.hide({
					transitionOut: 'fadeOutUp',
					onClosing: function(instance, toast, closedBy){
		                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
		            }
		        }, toast, 'buttonName');

	        }, true], // true to focus
	        ['<button>Hayır</button>', function (instance, toast) {
	        	instance.hide({
	        		transitionOut: 'fadeOutUp',
	        		onClosing: function(instance, toast, closedBy){
	                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
	                }
	            }, toast, 'buttonName');
	        }]
	        ]
	    });

	}
    
    
    /*function sabit_fiyat_guncelle(){
        var servis_fiyat = $("#service_price").val();
        var x = document.getElementsByTagName("service_list");
        var api_fiyat = $("#service_list").children("option:selected").data('price');
        if(servis_fiyat && api_fiyat){
            var sonuc = parseFloat(servis_fiyat)-parseFloat(api_fiyat);
        $('#service_fixed_price').val(sonuc.toFixed(2));
        }
        //alert(api_fiyat);
    }*/
    
	function task_confirm(id, type) {

		iziToast.show({
			theme: 'dark',
			title: '[Sipariş İşlemleri]',
			message: 'Yapacağınız işlem sağlayıcınıza iletilmez, kendiniz iletmeniz gerekiyor.<br>Bunun bilincinde olarak işlemi gerçekleştiriniz.<br>Bu işlemi yapmak istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

			['<button>Evet</button>', function (instance, toast) {

				var data = {id:id, type:type};
				post("task_confirm", data);
				instance.hide({
					transitionOut: 'fadeOutUp',
					onClosing: function(instance, toast, closedBy){
		                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
		            }
		        }, toast, 'buttonName');

	        }, true], // true to focus
	        ['<button>Hayır</button>', function (instance, toast) {
	        	instance.hide({
	        		transitionOut: 'fadeOutUp',
	        		onClosing: function(instance, toast, closedBy){
	                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
	                }
	            }, toast, 'buttonName');
	        }]
	        ]
	    });

	}

	function delete_service(id) {

		iziToast.show({
			theme: 'dark',
			title: 'Silme İşlemi',
			message: 'Silmek istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

			['<button>Evet</button>', function (instance, toast) {

				var data = {id:id};
				post("delete_service", data);
				instance.hide({
					transitionOut: 'fadeOutUp',
					onClosing: function(instance, toast, closedBy){
		                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
		            }
		        }, toast, 'buttonName');

	        }, true], // true to focus
	        ['<button>Hayır</button>', function (instance, toast) {
	        	instance.hide({
	        		transitionOut: 'fadeOutUp',
	        		onClosing: function(instance, toast, closedBy){
	                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
	                }
	            }, toast, 'buttonName');
	        }]
	        ]
	    });

	}
	function service_indirim_sil(id) {

		iziToast.show({
			theme: 'dark',
			title: 'İndirimleri Silme İşlemi',
			message: 'İndirimleri Silmek istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

			['<button>Evet</button>', function (instance, toast) {

				var data = {id:id};
				post("delete_service_indirim", data);
				instance.hide({
					transitionOut: 'fadeOutUp',
					onClosing: function(instance, toast, closedBy){
		                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
		            }
		        }, toast, 'buttonName');

	        }, true], // true to focus
	        ['<button>Hayır</button>', function (instance, toast) {
	        	instance.hide({
	        		transitionOut: 'fadeOutUp',
	        		onClosing: function(instance, toast, closedBy){
	                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
	                }
	            }, toast, 'buttonName');
	        }]
	        ]
	    });

	}
	
	function uye_toplu_indirim_sil(id) {

		iziToast.show({
			theme: 'dark',
			title: 'İndirimleri Silme İşlemi',
			message: 'İndirimleri Silmek istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

			['<button>Evet</button>', function (instance, toast) {

				var data = {id:id};
				post("delete_service_indirim_uye", data);
				instance.hide({
					transitionOut: 'fadeOutUp',
					onClosing: function(instance, toast, closedBy){
		                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
		            }
		        }, toast, 'buttonName');

	        }, true], // true to focus
	        ['<button>Hayır</button>', function (instance, toast) {
	        	instance.hide({
	        		transitionOut: 'fadeOutUp',
	        		onClosing: function(instance, toast, closedBy){
	                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
	                }
	            }, toast, 'buttonName');
	        }]
	        ]
	    });

	}
	function delete_service_discount(id) {

		iziToast.show({
			theme: 'dark',
			title: 'İndirim Silme İşlemi',
			message: 'İndirimleri Silmek istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

			['<button>Evet</button>', function (instance, toast) {

				var data = {id:id};
				post("delete_service_discount", data);
				instance.hide({
					transitionOut: 'fadeOutUp',
					onClosing: function(instance, toast, closedBy){
		                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
		            }
		        }, toast, 'buttonName');

	        }, true], // true to focus
	        ['<button>Hayır</button>', function (instance, toast) {
	        	instance.hide({
	        		transitionOut: 'fadeOutUp',
	        		onClosing: function(instance, toast, closedBy){
	                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
	                }
	            }, toast, 'buttonName');
	        }]
	        ]
	    });

	}

	function select(id = null, element = "input") {
		if(element == "input") {
			$('input[name^="name"]').each(function() {
				$(this).addClass("hide");
			});
			if(id != null) {
				$("#lang_"+id).removeClass("hide");
			} else {
				$("#lang_"+$("#lang").val()).removeClass("hide");
			}
		} else if(element == "textarea") {
			$('.lang').each(function() {
				$(this).addClass("hide");
			});
			if(id != null) {
				$("#desclang_"+id).removeClass("hide");
			} else {
				$("#desclang_"+$("#desclang").val()).removeClass("hide");
			}
		}
	}

	function update_ticket(id, type) {
		var status;
		if($("#ticketStatus").is(':checked')) {
			status = 1;
			$("#admin_send_message").slideDown();
		} else {
			status = 0;
			$("#admin_send_message").slideUp();
		}
		var data = {id:id, type:type, status:status};
		post("update_ticket", data);
		openticket(id);
		alltickets();
	}

	function delete_api(id) {
		iziToast.show({
			theme: 'dark',
			title: 'Silme İşlemi',
			message: 'Silmek istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

			['<button>Evet</button>', function (instance, toast) {

				var data = {id:id};
				post("delete_api", data);
				instance.hide({
					transitionOut: 'fadeOutUp',
					onClosing: function(instance, toast, closedBy){
		                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
		            }
		        }, toast, 'buttonName');

	        }, true], // true to focus
	        ['<button>Hayır</button>', function (instance, toast) {
	        	instance.hide({
	        		transitionOut: 'fadeOutUp',
	        		onClosing: function(instance, toast, closedBy){
	                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
	                }
	            }, toast, 'buttonName');
	        }]
	        ]
	    });
	}

	function delete_announcement(id) {
		iziToast.show({
			theme: 'dark',
			title: 'Silme İşlemi',
			message: 'Silmek istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

			['<button>Evet</button>', function (instance, toast) {

				var data = {id:id};
				post("delete_announcement", data);
				instance.hide({
					transitionOut: 'fadeOutUp',
					onClosing: function(instance, toast, closedBy){
		                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
		            }
		        }, toast, 'buttonName');

	        }, true], // true to focus
	        ['<button>Hayır</button>', function (instance, toast) {
	        	instance.hide({
	        		transitionOut: 'fadeOutUp',
	        		onClosing: function(instance, toast, closedBy){
	                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
	                }
	            }, toast, 'buttonName');
	        }]
	        ]
	    });
	}

	function delete_language(id) {
		iziToast.show({
			theme: 'dark',
			title: 'Silme İşlemi',
			message: 'Silmek istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

			['<button>Evet</button>', function (instance, toast) {

				var data = {id:id};
				post("delete_language", data);
				instance.hide({
					transitionOut: 'fadeOutUp',
					onClosing: function(instance, toast, closedBy){
		                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
		            }
		        }, toast, 'buttonName');

	        }, true], // true to focus
	        ['<button>Hayır</button>', function (instance, toast) {
	        	instance.hide({
	        		transitionOut: 'fadeOutUp',
	        		onClosing: function(instance, toast, closedBy){
	                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
	                }
	            }, toast, 'buttonName');
	        }]
	        ]
	    });
	}

	function delete_category(id) {
		iziToast.show({
			theme: 'dark',
			title: 'Silme İşlemi',
			message: 'Silmek istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

			['<button>Evet</button>', function (instance, toast) {

				var data = {id:id};
				post("delete_category", data);
				instance.hide({
					transitionOut: 'fadeOutUp',
					onClosing: function(instance, toast, closedBy){
		                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
		            }
		        }, toast, 'buttonName');

	        }, true], // true to focus
	        ['<button>Hayır</button>', function (instance, toast) {
	        	instance.hide({
	        		transitionOut: 'fadeOutUp',
	        		onClosing: function(instance, toast, closedBy){
	                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
	                }
	            }, toast, 'buttonName');
	        }]
	        ]
	    });
	}

	function change_category_status(id) {
		iziToast.show({
			theme: 'dark',
			title: 'Kategori Durumu',
			message: 'Kategorinin durumunu değiştirmek istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

			['<button>Evet</button>', function (instance, toast) {

				var data = {id:id};
				post("change_status_category", data);
				instance.hide({
					transitionOut: 'fadeOutUp',
					onClosing: function(instance, toast, closedBy){
		                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
		            }
		        }, toast, 'buttonName');

	        }, true], // true to focus
	        ['<button>Hayır</button>', function (instance, toast) {
	        	instance.hide({
	        		transitionOut: 'fadeOutUp',
	        		onClosing: function(instance, toast, closedBy){
	                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
	                }
	            }, toast, 'buttonName');
	        }]
	        ]
	    });
	}

	function delete_bankdeposit(id) {
		iziToast.show({
			theme: 'dark',
			title: 'Silme İşlemi',
			message: 'Silmek istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

			['<button>Evet</button>', function (instance, toast) {

				var data = {id:id};
				post("delete_bankdeposit", data);
				instance.hide({
					transitionOut: 'fadeOutUp',
					onClosing: function(instance, toast, closedBy){
		                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
		            }
		        }, toast, 'buttonName');

	        }, true], // true to focus
	        ['<button>Hayır</button>', function (instance, toast) {
	        	instance.hide({
	        		transitionOut: 'fadeOutUp',
	        		onClosing: function(instance, toast, closedBy){
	                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
	                }
	            }, toast, 'buttonName');
	        }]
	        ]
	    });
	}

	function onay_bankdeposit(id) {
		iziToast.show({
			theme: 'dark',
			title: 'Banka Ödemesi',
			message: 'İşlemi onaylıyor musunuz?',
			position: 'center',
			timeout: false,
			buttons: [

			['<button>Evet</button>', function (instance, toast) {

				var data = {id:id};
				post("onay_bankdeposit", data);

	        }, true], // true to focus
	        ['<button>Hayır</button>', function (instance, toast) {
	        	instance.hide({
	        		transitionOut: 'fadeOutUp',
	        		onClosing: function(instance, toast, closedBy){
	                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
	                }
	            }, toast, 'buttonName');
	        }]
	        ]
	    });
	}

	function delete_ticket(id) {
		iziToast.show({
			theme: 'dark',
			title: 'Silme İşlemi',
			message: 'Silmek istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

			['<button>Evet</button>', function (instance, toast) {

				var data = {id:id};
				post("delete_ticket", data);
				instance.hide({
					transitionOut: 'fadeOutUp',
					onClosing: function(instance, toast, closedBy){
		                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
		            }
		        }, toast, 'buttonName');

	        }, true], // true to focus
	        ['<button>Hayır</button>', function (instance, toast) {
	        	instance.hide({
	        		transitionOut: 'fadeOutUp',
	        		onClosing: function(instance, toast, closedBy){
	                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
	                }
	            }, toast, 'buttonName');
	        }]
	        ]
	    });
	}

	function delete_user(id) {
		iziToast.show({
			theme: 'dark',
			title: 'Silme İşlemi',
			message: 'Silmek istediğinizden emin misiniz?',
			position: 'center',
			displayMode: 1,
			timeout: false,
			buttons: [

			['<button>Evet</button>', function (instance, toast) {

				var data = {id:id};
				post("delete_user", data);
				instance.hide({
					transitionOut: 'fadeOutUp',
					onClosing: function(instance, toast, closedBy){
		                console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
		            }
		        }, toast, 'buttonName');

	        }, true], // true to focus
	        ['<button>Hayır</button>', function (instance, toast) {
	        	instance.hide({
	        		transitionOut: 'fadeOutUp',
	        		onClosing: function(instance, toast, closedBy){
	                    console.info('closedBy: ' + closedBy); // The return will be: 'closedBy: buttonName'
	                }
	            }, toast, 'buttonName');
	        }]
	        ]
	    });
	}

	function get_translations(id = null) {
		if(id == null) {
			id = $("#lang").val();
		}
		var request_url = _url + "get_translations";
		$.post(request_url, {id:id}, function(response) {
			if (response.error) {
				error(response.error, delay);
			} else if(response.success) {
				success(response.success, delay);
			} else if(response.log) {
				log(response.log, delay);
			}
			if(response.translations) {
				for (translation in response.translations) {
					$("#code_"+translation).val(response.translations[translation]);
				}
			}
		}, 'json').fail(function() {
			error(messages["UNKNOWN_ERROR"]);
		});
	}

	function post(action, data) {
		var request_url = _url + action;
		$.post(request_url, data, function(response) {
			if(response.delay) {
				delay = response.delay;
			}
			if (response.error) {
				error(response.error, delay);
			} else if(response.success) {
				success(response.success, delay);
			} else if(response.log) {
				log(response.log, delay);
			} else if(response.alert) {
				alert(response.alert);
			} else if(response.reload) {
				window.location.reload(!0);
			}
			if(response.edit) {
				if(response.type == "html") {
					$(response.item).html(response.text);
				} else if(response.type == "value") {
					$(response.item).val(response.text);
				}
			}
			if(response.redirect) {
				var delay = 0;
				if(response.delay) {
					delay = response.delay;
				}
				if(response.newtab) {
					setTimeout(function () {
						window.open(response.location, "_top");
					}, response.delay);
				} else {
					setTimeout(function () {
						window.location.href = response.location;
					}, response.delay);
				}

			}
		}, 'json').fail(function() {

			error(messages["UNKNOWN_ERROR"])

		});
	}

	function get_details() {
		var start = $("input[name=start_date]").val();
		var end = $("input[name=end_date]").val();
		var request_url = _url + "get_details?start_date="+start+"&end_date="+end+"";
		window.open(request_url, '_blank');
	}

	function get_earnings() {
		var start = $("input[name=start_date]").val();
		var end = $("input[name=end_date]").val();
		getEarnings(start, end);
	}

	function getEarnings(start, end) {
		var request_url = _url + "get_earnings";
		$.post(request_url, {start_date:start,end_date:end}, function(response) {
			if(response.success) {
				var datas = response.datas;
				var datasUSD = response.datasUSD;
				var minTick = Math.floor(Math.min.apply(null, datas));
				var maxTick = Math.ceil(Math.max.apply(null, datas));
				$("#earningArea").html('<canvas id="earnings" width="100%" height="30"></canvas>');
				ctx = $("#earnings");
				var myLineChart = new Chart(ctx, {
					type: 'line',
					data: {
						labels: response.labels,
						datasets: [{
							label: "Net Gelir(₺)",
							lineTension: 0.2,
							backgroundColor: "rgba(2,117,216,0.2)",
							borderColor: "rgba(2,117,216,1)",
							pointRadius: 5,
							pointBackgroundColor: "rgba(2,117,216,1)",
							pointBorderColor: "rgba(255,255,255,0.8)",
							pointHoverRadius: 5,
							pointHoverBackgroundColor: "rgba(2,117,216,1)",
							pointHitRadius: 50,
							pointBorderWidth: 2,
							data: datas,
						},
						{
							label: "Net Gelir($)",
							lineTension: 0.2,
							backgroundColor: "rgba(0,255,0,0.2)",
							borderColor: "rgba(0,255,0,1)",
							pointRadius: 5,
							pointBackgroundColor: "rgba(0,255,0,1)",
							pointBorderColor: "rgba(0,255,0,0.8)",
							pointHoverRadius: 5,
							pointHoverBackgroundColor: "rgba(0,255,0,1)",
							pointHitRadius: 50,
							pointBorderWidth: 2,
							data: datasUSD,
						}],
					},
					options: {
						responsive: true,
						title: {
							display: true,
							text: 'Kazanç Tablosu'
						},
						scales: {
							xAxes: [{
								time: {
									unit: 'date'
								},
								gridLines: {
									display: false
								},
								ticks: {
									maxTicksLimit: 7
								}
							}],
							yAxes: [{
								ticks: {
									min: minTick,
									max: maxTick,
									maxTicksLimit: 10
								},
								gridLines: {
									color: "rgba(0, 0, 0, .125)",
								}
							}],
						},
						legend: {
							display: false
						}
					}
				});
			} else {
				if(response.error) {

					error(messages["UNKNOWN_ERROR"])

				} else if(response.log) {
					log(response.log);
				}
			}
		}, 'json');
	}


	function toplusec(){
		var i;
		for (i = 0; i < $('#totalcheckbox').val(); i++) {
			if(document.getElementById('checkbox'+i)) {
				if(!document.getElementById('checkbox'+i).disabled) {
					if(!document.getElementById('checkbox'+i).checked){
						document.getElementById('checkbox'+i).checked = true;
					}else{
						document.getElementById('checkbox'+i).checked = false;
					}
				}
			}
		}
	}


	