function showBasket()
{
	
	 /* bodyContent = $.ajax({
      url: "ajax/getAjaxBasket.php",
      global: false,
      type: "POST",
	  data: ({action: "showBasket",date : new Date().getTime()}),
      dataType: "html",
      success: function(html){
	  if(html!="")
	  {
			
			$("#basket").html(html);
			if($("#basket").html()!="")
				$("#basketTool").html("<h3>Baskets</h3><div   class='showHide'>Show/Hide Basket</div><br>");
			
	  }
         	
      }
   }
	).responseText;*/
}

function showAllUserBaskets(userID)
{
	 
	  bodyContent = $.ajax({
      url: "ajax/getAjaxBasket.php",
      global: false,
      type: "POST",
	  data: ({userID:userID, action: "showAllBaskets",date : new Date().getTime()}),
      dataType: "html",
      success: function(html){
	  if(html!="")
	  {
			$("#basket").html(html);
	  }
         	
      }
   }
	).responseText;
}

function editSavedBasket(id)
{
		 bodyContent = $.ajax({
		  url: "ajax/getAjaxBasket.php",
		  global: false,
		  type: "POST",
		  data: ({id:id, action: "editSavedBasket",date : new Date().getTime()}),
		  dataType: "html",
		  success: function(html){
		  if(html!="")
		  {
			
				$("#basket").html(html);
		  }
				
		  }
	   }
		).responseText;
}

function viewSavedBasket(id)
{
		//alert("View")
		 bodyContent = $.ajax({
		  url: "ajax/getAjaxBasket.php",
		  global: false,
		  type: "POST",
		  data: ({id:id, action: "viewSavedBasket",date : new Date().getTime()}),
		  dataType: "html",
		  success: function(html){
		  if(html!="")
		  {
			
				$("#basket").html(html);
		  }
				
		  }
	   }
		).responseText;
}

function updateQuantity(id,symbol)
{
	//var arr = $.session('basketArr');
	//alert($.session('basketArr'));
	//$_SESSION['basketArr'][$_SESSION['basketID']][id]['quantity']++;
	$("#plus").attr('disabled','disabled');
	$("#min").attr('disabled','disabled');
	 bodyContent = $.ajax({
      url: "ajax/getAjaxBasket.php",
      global: false,
      type: "POST",
	  data: ({itemID:id,symbol: symbol, action: "quantity",date : new Date().getTime()}),
      dataType: "html",
      success: function(html){
	  if(html!="")
	  {
	  	
			//alert(id+" SYM: "+symbol)
			$("#errorBox").html(html);
			if($("#basket").html()!="")
				showBasket();
				
		/*$("#plus").attr('disabled','false');
		$("#min").attr('disabled','false');*/
	  }
         	
      }
   }
	).responseText;
}

function updateQuantityValue(id,value)
{
	//alert("UPDATE")
	//$("#infoBox").html("Please wait re-calculating price...");
	//var arr = $.session('basketArr');
	//alert($.session('basketArr'));
	//$_SESSION['basketArr'][$_SESSION['basketID']][id]['quantity']++;
	$("#plus").attr('disabled','disabled');
	$("#min").attr('disabled','disabled');
	 bodyContent = $.ajax({
      url: "ajax/getAjaxBasket.php",
      global: false,
      type: "POST",
	  data: ({itemID:id,value: value, action: "quantityValue",date : new Date().getTime()}),
      dataType: "html",
      success: function(html){
	  if(html!="")
	  {
		  	//alert("Done")
	  		$("#infoBox").html("");
			//alert(id+" SYM: "+symbol)
			$("#errorBox").html(html);
			if($("#basket").html()!="")
				showBasket();
				
	/*	$("#plus").attr('disabled','false');
		$("#min").attr('disabled','false');*/
	  }
         	
      }
   }
	).responseText;
}

function saveBasket(mystatus)
{
	//alert(mystatus)
	  bodyContent = $.ajax({
      url: "ajax/getAjaxBasket.php",
      global: false,
      type: "POST",
	  data: ({status: mystatus, deliver:$("#deliver").html(), bill:$("#bill").html(), action: "Save",date : new Date().getTime()}),
      dataType: "html",
      success: function(html){
	  if(html!="")
	  {
	  	//alert("Save")
			$("#errorBox").html(html);
			if($("#basket").html()!="")
				showBasket();
	  }
         	
      }
   }
	).responseText;
}

function removeItem(id,cnt)
{
	
	 bodyContent = $.ajax({
      url: "ajax/getAjaxBasket.php",
      global: false,
      type: "POST",
	  data: ({id: id, action: "remove", cnt: cnt,date : new Date().getTime()}),
      dataType: "html",
      success: function(html){
	  if(html!="")
	  {
			$("#errorBox").html(html);
			if($("#basket").html()!="")
				showBasket();
	  }
         	
      }
   }
	).responseText;
}

function hideBasket()
{
	$("#errorBox").html("");
	$("#basketTool").html("<h3>Baskets</h3><div  class='showHide'>Show/Hide Basket</div>");
	$("#basket").slideToggle(1000);
}


function addToBasket(id,db)
{
 //alert(id)
 
	 bodyContent = $.ajax({
      url: "ajax/getAjaxBasket.php",
      global: false,
      type: "POST",
	  data: ({id: id, action: "add", db:db,date : new Date().getTime()}),
      dataType: "html",
      success: function(html){
	  if(html!="")
	  {
			$("#errorBox").html(html);
			showBasket();
	  }
         	
      }
   }
	).responseText;
}

function showProfile()
{
	 bodyContent = $.ajax({
      url: "ajax/getAjaxProfile.php",
      global: false,
      type: "POST",
	  data: ({id: id, action: "showProfile",date : new Date().getTime()}),
      dataType: "html",
      success: function(html){
	  if(html!="")
	  {
			$("#basket").html(html);
			
	  }
         	
      }
   }
	).responseText;	
}


function checkLogin()
{
	 bodyContent = $.ajax({
      url: "ajax/getCheckLogin.php",
      global: false,
      type: "POST",
	  data: ({password : $("#password").val(), username : $("#username").val(),date : new Date().getTime()}),
      dataType: "html",
      success: function(html){
	  if(html!="")
	  {
			if($("#basket").html()!="")
				$("#basketTool").html("<div   class='showHide'>Show Basket</div>");
			$("#login").html("");
			$("#signIn").html("<a href='index.php?logout=yes'>logout</a>");
			//products.php?action=showBasket
			$("#loginTools").html("User: <font color='#000000'>"+html+" </font><ul><li><a href='javascript:document.showBasket()' onClick='showBasket()'>My Basket</a></li></ul>" );
			
			/*
			$("#loginTools").html("User: <font color='#000000'>"+html+" </font><ul><li><a href='javascript:document.showBasket()' onClick='showBasket()'>My Basket</a></li><li><a href='javascript:document.showProfile()' onClick='showProfile()'>My Profile</a></li></ul>" );
			*/
	
			$("#loginHeader").html("Logged In");
	  }
         	
      }
   }
	).responseText;
}

function Login()
{
	//$("#loginSpan").load("ajax/getAjaxLogin.php"); 
	//alert("LOGIN")
	 bodyContent = $.ajax({
      url: "ajax/getAjaxLogin.php",
      global: false,
      type: "POST",
      data: ({password : $("#password").val(), username : $("#username").val()}),
      dataType: "html",
      success: function(html){
	  	//alert(html.indexOf("Welcome"))
		if(html.indexOf("Welcome")!=-1)
		{
			if($("#basket").html()!="")
				$("#basketTool").html("<div   class='showHide'>Hide Basket</div>");
			$("#signIn").slideToggle();
			$("#loginHeader").html("Welcome")
			$("#loginSpan").html(html);
			$("#login").slideToggle(1000);
			checkLogin();
		}
         	
      }
   }
	).responseText;

	
}

function getProductContent(tmpID)
{
	//$("#loginSpan").load("ajax/getAjaxLogin.php"); 
	id=tmpID;
	if(id!=0)
		$("#contentProductID").html("Loading content. Please wait..."); 
		
	 bodyContent = $.ajax({
      url: "ajax/getAjaxProductContent.php",
      global: false,
      type: "GET",
      data: ({id : id,date : new Date().getTime()}),
      dataType: "html",
      success: function(html){
	 
         $("#contentProductID").html(html);
      }
   }
	).responseText;

	
}
