// GENERAL FUNCTIONS FOR SPOTWAY 
// Release date 2014-01-22
// www.getspotway.com

// GENERAL THINGS TO LOAD ON LOADING DOCUMENT;

$(function() 
{	
	
	myAccordion();
	$( "#start_date" ).datepicker({ altFormat: "yy-mm-dd",  dateFormat: 'yy-mm-dd'});
	$( "#end_date" ).datepicker({ altFormat: "yy-mm-dd",  dateFormat: 'yy-mm-dd'});
	
		var x = 1;
	$( "#resp_menu" ).click(function() {
  	x++;
  	if(x%2==0)
  	{
	  $(".menu").css({"display":"block"});
  	}
   	if(x%2==1)
  	{
	  $(".menu").css({"display":"none"});
  	}
	});
});

$('.switcher').simpleCheckbox();
$('.switcher').change(function () {
	
	unique = $(this).attr('id');
	value = $(this).is(':checked');
	$.post("app_needed/ajax.functions.php",{unique:unique,value:value,change_hold:1},function(result){
	$.simplyToast(result,'success');
		
	});
 });
$('.tip').tipsy({fade: true});
$('.tipform').tipsy({trigger: 'focus', gravity: 'w'});
function logout()
{	
	$.post("app_needed/ajax.functions.php",{logout:1},function(result){
		 if(result==1){window.location = "login.php";}
		
	});
}
function hold_tag()
{
	if($("#hold").val() == 1)
	{	
		$("#hold").val(2);
		$("#buttonHold").text("Unhold");
	}else
	{	
		$("#hold").val(1);
		$("#buttonHold").text("Hold");
	}
		
}
function logout()
{	
	confirm("Are you sure you want to logout?", function () {
		$.simplyToast("logout",'success');
	$.post("app_needed/ajax.functions.php",{logout:1},function(result){
		 if(result==1){window.location = "login.html";}
		
	});
	});
}
function delete_campaign(unique)
{
	confirm("Are you sure you want to delete this campaign?", function () {
		
	$.post("app_needed/ajax.functions.php",{unique:unique,delete_campaign:1},function(result){
			$.simplyToast(result,'success');
			$("#"+unique).css("display","none");
		
	});
	});
}
function delete_tag(unique)
{
	confirm("Are you sure you want to delete this Tag?", function () {
		
	$.post("app_needed/ajax.functions.php",{unique:unique,delete_tag:1},function(result){
			$.simplyToast(result,'success');
			$("#"+unique).css("display","none");
		
	});
	});
}
function delete_size(unique)
{
	confirm("Are you sure you want to delete this Size?", function () {
		
	$.post("app_needed/ajax.functions.php",{unique:unique,delete_size:1},function(result){
			$.simplyToast(result,'success');
			$("#"+unique).css("display","none");
		
	});
	});
}

function restore_colors()
{
	confirm("Are you sure you want to restore the default colors?", function () {
		
	$.post("app_needed/ajax.colors.php",{restore:1},function(result){
			$.simplyToast(result,'success');
			$("#response").text(result);
		
	});
	});
}

	var x = 1;
	$( "#resp_menu" ).click(function() {
  	x++;
  	if(x%2==0)
  	{
	  $(".menu").css({"display":"block"});
  	}
   	if(x%2==1)
  	{
	  $(".menu").css({"display":"none"});
  	}
	});
function confirm(message, callback) {
	$('#confirm').modal({
		closeHTML: "",
		position: ["20%",],
		overlayId: 'confirm-overlay',
		containerId: 'confirm-container', 
		onShow: function (dialog) {
			var modal = this;

			$('.message', dialog.data[0]).append(message);

			// if the user clicks "yes"
			$('.yes', dialog.data[0]).click(function () {
				// call the callback
				if ($.isFunction(callback)) {
					callback.apply();
				}
				// close the dialog
				modal.close(); // or $.modal.close();
			});
		}
	});
}