/* The following function creates an XMLHttpRequest object... */
var current_recipe = false;
var current_page = 1;
function createRequestObject()
{
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	var notIECompatibleXMLHTTP;
	
	try
	{
		request_o = new ActiveXObject( "Microsoft.XMLHTTP" );
	}
	catch( e )
	{
		var notIECompatibleXMLHTTP=true;
	}
	if( notIECompatibleXMLHTTP == true )
	{
		try
		{
			request_o = new XMLHttpRequest();
		}
		catch( e )
		{
			request_o = false;
		}
	}
	
	return request_o; //return the object
}

/* The variable http will hold our new XMLHttpRequest object. */
var http = createRequestObject(); 

/* Function called to get the product categories list */
function call_recipe(recipe_id)
{
	/* Create the request. The first argument to the open function is the method (POST/GET),
		and the second argument is the url... 
		document contains references to all items on the page
		We can reference document.form_category_select.select_category_select and we will
		be referencing the dropdown list. The selectedIndex property will give us the 
		index of the selected item. 
	*/
	http.open('get', 'index_revised.php?action=get_recipe&id=' + recipe_id + '&show=' + recipe_id + '&current_view=ajax');
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	http.onreadystatechange = handleProducts; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	http.send(null);
}

function get_recipes( start, count, pagenum )
{
	/* Create the request. The first argument to the open function is the method (POST/GET),
		and the second argument is the url... 
		document contains references to all items on the page
		We can reference document.form_category_select.select_category_select and we will
		be referencing the dropdown list. The selectedIndex property will give us the 
		index of the selected item. 
	*/
	
	if( pagenum )
	{
		document.getElementById( 'page' + pagenum ).style.display = 'inline';
		document.getElementById( 'link_page' + pagenum ).style.display = 'none';
		document.getElementById( 'page' + current_page ).style.display = 'none';
		document.getElementById( 'link_page' + current_page ).style.display = 'inline';
		current_page = pagenum;
		
		http.open('get', 'index.php?action=get_recipe&start=' + start + '&count=' + count );
	}
	else
	{
		first = parseInt(start) + 1;
		last = parseInt(start) + 10;
		if( last > total_num_recipes )
		{
			last = total_num_recipes;
		}
		document.getElementById( 'recipe_list_title' ).innerHTML = first + ' - ' + last;
		http.open('get', 'review.php?ajax=1&letter=1&start=' + start + '&count=' + count );
	}
	
	
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	http.onreadystatechange = handleProducts; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	http.send(null);
}

/* Function called to handle the list that was returned from the internal_request.php file.. */
function handleProducts()
{
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(http.readyState == 4)
	{ //Finished loading the response
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
		var response = http.responseText;
		/* And now we want to change the product_categories <div> content.
			we do this using an ability to get/change the content of a page element 
			that we can find: innerHTML. */
		
		if( document.getElementById('style2') )
		{
			document.getElementById('style2').innerHTML = response;
		}
		else if( document.getElementById( 'recipe_list_names' ) )
		{
			document.getElementById( 'recipe_list_names' ).innerHTML = response;
		}
	}
}

function show_recipe_specifics(x)
{
	info = document.getElementById(x);
	if( !info || ( info.style.display != 'block' ) )
	{ 
		current_recipe = x;
		http.open('get', 'index_revised.php?recipe_details=' + x );
		http.onreadystatechange = handleRecipe; 
		http.send(null);
	}
	else
	{
		info.style.display = 'none';
		current_recipe = null;
	}
	
}

/* Function called to handle the list that was returned from the internal_request.php file.. */
function handleRecipe()
{
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(http.readyState == 4)
	{ //Finished loading the response
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
		var response = http.responseText;
		/* And now we want to change the product_categories <div> content.
			we do this using an ability to get/change the content of a page element 
			that we can find: innerHTML. */
		document.getElementById( 'recipe_specs_' + current_recipe ).innerHTML = response;
		document.getElementById( current_recipe ).style.display = 'block';
	}
}

function page_init( start, count, total )
{
	current_page = ( start/count ) + 1;
}

function get_single_recipe( id, image )
{
	if( image && document.getElementById( 'recipe_image' ) )
	{
		document.getElementById( 'recipe_image' ).src = image;
	}
	
	http.open('get', 'review.php?view=all&ajax=1&recipe_id=' + id );
	http.onreadystatechange = handle_single_recipe;
	http.send(null);
}
function handle_single_recipe()
{
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(http.readyState == 4)
	{	
		//Finished loading the response
		
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
		var response = http.responseText;
		
		/* And now we want to change the product_categories <div> content.
			we do this using an ability to get/change the content of a page element 
			that we can find: innerHTML. */
		document.getElementById( 'left_content' ).innerHTML = response;
	}
}

function get_recipes_by_letter( letter )
{
	http.open('get', 'review.php?ajax=1&letter=' + letter );
	document.getElementById( 'recipe_list_title' ).innerHTML = letter;
	http.onreadystatechange = handle_recipes_by_letter; 
	http.send(null);
}
function handle_recipes_by_letter()
{
	if( http.readyState == 4 )
	{	
		var response = http.responseText;
		document.getElementById( 'recipe_list_names' ).innerHTML = response;
	}
}
function borderSpread( dir )
{
	noBorder = document.getElementsByTagName('span');
	for (i=0; i<noBorder.length; i++)
	{
		if (noBorder[i].className == 'spreadsActive')
		{
			noBorder[i].className = 'spreads';
		}
	}
	
	document.getElementById(dir).className = 'spreadsActive';
}



function changeCopy(x)
{
	document.getElementById('opt1').style.color = '#C8C8C8';
	document.getElementById('opt2').style.color = '#C8C8C8';
	document.getElementById(x).style.color = 'black';
	if (x == 'opt2')
	{
		document.getElementById('divCopy').innerHTML = "Founded in 1974, Eisenberg And Associates is one of the nation’s most successful and respected full-service creative firms. This is because we begin with your end goal in mind. We ask questions, and ask more questions. We then combine our creative firepower with strategic planning. We’ll help you brand your product so it breaks through all the clutter and we have an eye-opening portfolio to prove it.";
	}
	else
	{
		document.getElementById('divCopy').innerHTML = "ColorDynamics is a combination sheetfed and web commercial printer. Our facility is state of the art, from Electronic Prepress through Bindery, Mailing and Distribution. Our commitment to quality and service has earned us numerous awards. Every project is important to us and we pride ourselves in being flexible and creative to exceed our clients' needs and expectations.";
	}
}
function showDiv()
{
	div1 = document.getElementById('EandA');
	if (div1.style.display == 'block')
	{
		div1.style.display = 'none';
	}
	else
	{
		div1.style.display = 'block';
	}
}
function onArrow( direction )
{
	document.getElementById(direction).src = "images/cookieCard/" + direction + "_arrow.jpg";
}
function offArrow( direction )
{
	document.getElementById(direction).src = "images/cookieCard/" + direction + "_arrow.png";
}