function setLoading(action)
{
	 	//alert(action)
	if(action=="show")
		$("#loading").show();
	else if(action=="hide")
		$("#loading").hide();
	else
		$("#loading").toggle();
}

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("");
			$("#reportBox").html("");
	  }
         	
      }
   }
	).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)
{
	setLoading('show');
		 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!="")
		  {
					setLoading('hide');
				$("#basket").html(html);
				
		  }
				
		  }
	   }
		).responseText;
}

function viewSavedBasket(id)
{
	setLoading('show');
		//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!="")
		  {
				setLoading('hide');
				$("#basket").html(html);
				
		  }
				
		  }
	   }
		).responseText;
}

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

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

function removeItem(id,cnt)
{
	 setLoading('show');
	 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!="")
	  {
		  setLoading('hide');
			$("#errorBox").html(html);
			if($("#basket").html()!="")
				showBasket();
				
			
	  }
         	
      }
   }
	).responseText;
}

function hideBasket()
{
	$("#errorBox").html("");
	$("#basketTool").html("<h3>Baskets</h3>");
	$("#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!="")
	  {
		 	 setLoading("hide");
		
			
		 
			$("#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("");
			$("#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;

	
}
