﻿setInterval(function()
{
	$.post('keep_alive.php');
	timer=0;
},60000);
$(document).on("focus",".datepicker", function()
{
	$('.datepicker').not('.hasDatePicker').datepicker(
	{
		dateFormat: 'dd-mm-yy',
		showButtonPanel: true
	});
});
$(document).on("click","a",function()
{
	$(".loader").fadeIn();
});
/*window.old_alert = window.alert;
window.alert = function(message, fallback)
{
    if(fallback)
    {
        old_alert(message);
        return;
    }
    $("#alert_result").html(message);
    var w=$(window).width();
    var h=$(window).height();
    var ah=$("#alert").height()/2;
    var top=(h/2)-ah;
    var left=(w/2)-150;
     $("#alert").css(
     {
     	top:top+"px",
     	left:left+"px"
     });
     $("#alert_close").show();
     $("#alert_head").show();
     $("#alert").fadeIn("fast");
     $("#overlay").fadeIn("fast");
}*/
$(document).on("click",".order_status",function(e)
{
	$("#fancy").html($("#key").html());
	$.fancybox.open(
	{
		href:'#fancy'
	});
});
$(document).on("click",".product_box",function(e)
{
	console.log(e.target);
	if($(this).hasClass("options"))
	{
		return false;
	}
	if($(this).find(".overlay").hasClass("shown"))
	{
		return false;
	}
	else
	{
		$(".overlay").css("height","0%").removeClass("shown");
		$(this).find(".overlay").animate(
		{
			height:'100%'
		}).addClass("shown");
	}
});
$(document).on("click","#cgi",function()
{
	var cgi_link=$(this).attr("cgi_link");
	$.post("product_detail.php",
	{
		cgi_link:cgi_link
	},function(data)
	{
		//var w=$(window).width()-30+"px";
		//var h=$(window).height()-30+"px";
		$("#fancy").html(data);
		//$("#cgi_ar").css(
		//{
		//	height:w,
		//	width:h
		//});
		$.fancybox.open(
		{
			href:'#fancy'
		});
	});
});
$(document).on("click",".basket_row",function()
{
	var r=confirm("This will remove the line from your basket, are you sure?");
	if(r==false)
	{
		return false;
	}
	var basket_row=$(this).attr("key");
	$.post("info.php",
	{
		basket_row:basket_row
	},function(data)
	{
		$("#info").html(data);
	});
});
var dragTimer;
$(document).on('dragover', function(e) 
{
	var dt = e.originalEvent.dataTransfer;
	if (dt.types && (dt.types.indexOf ? dt.types.indexOf('Files') != -1 : dt.types.contains('Files'))) 
	{
    	$(".dropzone").fadeIn();
    	window.clearTimeout(dragTimer);
	}
});
$(document).on("dragover",".dropzone",function(e)
{
	$(this).css(
	{
		'background-color':'#01b7cd45',
		'opacity':'0.5'
	});
});
$(document).on("dragleave",".dropzone",function(e)
{
	$(this).css(
	{
		'background-color':'#fff',
		'opacity':'0.5'

	});
});
$(document).on('drop', function(e) 
{
    window.clearTimeout(dragTimer);
    dragTimer = window.setTimeout(function() 
    {
        $(".dropzone").fadeOut();
    }, 85);
});
$(document).on('dragleave', function(e) 
{
    window.clearTimeout(dragTimer);
    dragTimer = window.setTimeout(function() 
    {
        $(".dropzone").fadeOut();
    }, 85);
});
$(document).on("change",".input_text",function()
{
	var json=$(this).attr("data");
	var obj=JSON.parse(json);
	var value=$(this).val();
	var this_=$(this);
	$.ajax(
	{
		url:'../3/save/input_save.php',
		type:'post',
		data:
		{
			json:json,
			value:value
		},
		success:function(data)
		{
			$(this_).addClass("saved");
			setTimeout(function()
			{
				$(this_).removeClass("saved");
			}, 1000);		
		}
	});
});
$(document).on("keyup",".input_text",function(e)
{
	if (e.which == 13)
	{
		$(this).blur();
	}
});
