// JavaScript Document
// Included into every page via "templates/dr_milkyway/index.php" include
//
// AJAX library - see Ajax in 10 minutes book chapter 17
//
// Used in AUSMEDIC to regular change the Specials and New Products on the Home Page.
//
//
// See "myAJAXlib.js" library

//setTimeout ( "update_new_products()", 6000 );	// set initial timeout
setTimeout ( "update_specials()", 6000 );	// set initial timeout
var busy_flag1 = 0;
var busy_flag2 = 0;

//function ajax_call_back1(message)	// New Products
//{
//	if (message.length > 0)
//	{
//		//alert(message);
//		
//		// NOW CHANGE THE PAGE HTML TO SHOW THE NEW PRODUCT
//		// ************************************************
//		document.getElementById('new_product_div').innerHTML = message;
//	}
//	setTimeout ( "update_new_products()", 6000 );	// subsequent checks at 5 second intervals
//	busy_flag1 = 0;
//}
function ajax_call_back2(message)	// Specials
{
	if (message.length > 0)
	{
		//alert(message);
		
		// NOW CHANGE THE PAGE HTML TO SHOW THE SPECIAL PRODUCT
		// ****************************************************
		document.getElementById('specials_tr_div').innerHTML = message;
	}
	setTimeout ( "update_specials()", 6000 );	// subsequent checks at 5 second intervals
	busy_flag2 = 0;
}

// New Products
// *****************
//function update_new_products()
//{
//	//alert("function update_new_products()");
//	if (busy_flag1 == 0)
//	{
//		busy_flag1 = 1;
//		var this_counter = newProductCounterArray[newProductIndex];	// initially set in "index.php"
//		
//		// ********************************************
//		// THIS IS THE KEY CALL TO THE WHOLE ENTERPRISE
//		// ********************************************
//		doAjax('update_new_products.php','counter='+this_counter,'ajax_call_back1','get','0');	// "myAJAXlib.js"
//		
//		// setup for the next New Product
//		newProductIndex++;
//		if (newProductIndex >= numNewProducts)
//		{
//			newProductIndex = 0;
//		}
//		
//	}
//}

// Specials
// *************
function update_specials()
{
	if (busy_flag2 == 0)
	{
		busy_flag2 = 1;
		var this_counter = specialsCounterArray[specialsIndex];	// initially set in "index.php"
		
		// ********************************************
		// THIS IS THE KEY CALL TO THE WHOLE ENTERPRISE
		// ********************************************
		doAjax('update_specials.php','counter='+this_counter,'ajax_call_back2','get','0');	// "myAJAXlib.js"
		
		// setup for the next Special
		specialsIndex++;
		if (specialsIndex >= numSpecials)
		{
			specialsIndex = 0;
		}
		
	}
}
