// AJAX component //

// Suppress JS Errors 
window.onerror = function() { return true; }

var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
function buildAJAX(){
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.ActiveXObject) {
		try {
			//xmlhttp = window.createRequest();
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			//xmlhttp=false;
			
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				xmlhttp = false;
			}
			
		}
	}
}

function getMyHTML(serverPage, objID) {
if(xmlhttp) {
	var obj = document.getElementById(objID);
	try {
		xmlhttp.open("GET", serverPage);
	} catch (e) {
		alert("Error: " + serverPage );	
	}
	
	
	xmlhttp.setRequestHeader("Content-Type","text/xml;charset=UTF-8")
	xmlhttp.onreadystatechange = function() {
		/*if( xmlhttp.status == 0 )
		{
			document.getElementById('loadStatus').innerHTML="Aborted...";	
		}
		else */
		if (xmlhttp.readyState == 4) {
			
		   	try{
				if (xmlhttp.status==200) {
					var xmlResponse = xmlhttp.responseText;
					obj.innerHTML = xmlResponse;
					document.getElementById('loadStatus').innerHTML="";
					if(document.location.hash){
						var rm = document.location.hash;
						removeElem(rm.replace(/#/,""));
					}
				}
				else if (xmlhttp.status==404)  {
					alert("ERROR (JS404): Sorry, we were unable to complete the request.");
				}
				else {
					alert("Status is "+xmlhttp.status);
				}
			} catch (e) { }
		  }
		

		// If errors on request
		/*
		if( xmlhttp.status == 0 )
		  this.OnAbort();
		else if( xmlhttp.status == 200 && xmlhttp.statusText == "OK")
		  this.OnComplete(xmlhttp.responseText, xmlhttp.responseXML);
		else
		  this.OnError(xmlhttp.status, xmlhttp.statusText, xmlhttp.responseText);
		 */
	}
	xmlhttp.send(null);
	
    //s_pageName=tab;
   //s_gs(s_account);
} //Close if statement for xmlhttp validation
}


function decode_utf(s)
{
  return decodeURI(s);
}

function status(objState, objID) {
	var obj = document.getElementById(objID);
	if(objState == 1)
		getMyHTML(objID,objID); 
	else 
		obj.innerHTML = "";
}

function selectAll(){

}

// MAIN NAVIGATION CONTROLS //
var siteMainNav = new Array();
	siteMainNav[0] = '<div class="secondaryNav"><p>You\'ve been hearing more and more about flaxseed in the news or maybe noticed it at your local grocery store. So what\'s it all about? What is flax?</p><div class="container"><p><a href="/what-is-flax/#1">From the Field</a></p><p><a href="/what-is-flax/#2">Tiny Seed Making Big Changes</a></p><p><a href="/what-is-flax/#3">An Easy Addition into Everyday Life</a></p><p><a href="/what-is-flax/#4">Not Just a Food Trend</a></p></div>'; //'http://' + window.location.host + '/What-Is-Flax.html';
	siteMainNav[1] = '<div class="secondaryNav noPad"><div class="tenTips"><div class="container"><p class="smMargB"><a href="/flax-facts/#63">10 Tips for Healthy <br /></a><a href="/flax-facts/#62">Flax Habits</a></p><p>Learn how to add flax to your healthy lifestyle.</p></div></div></div>'; //'http://' + window.location.host + '/Flax-10-Tips.html';
	siteMainNav[2] = '<div class="secondaryNav"><p>Get all the facts about the health benefits of flax and how easily it can be  incorporated into a healthy diet. Our <a href="/flax-facts/#63">10 Easy Tips for Healthy Flax Habits</a> is a quick reference guide on how simple it is to add flax to your daily routine. Learn more about how flax can lower risks for heart disease, stroke, certain cancers, and type 2 diabetes. For more information, download our <a href="/files/Flax Info r0502.pdf">brochure</a> or <a href="/flax-facts/">fact sheets</a> for quick access to flax facts.</p><div class="container"><p><a href="/flax-facts/#63">10 Tips for Healthy Flax Habits</a></p><p><a href="/flax-facts/#62">Brochure</a></p><p><a href="/flax-facts/#61">Research</a></p></div><div class="clear"><div class="container narrowB"></div></div></div>'; ///'http://' + window.location.host + '/Flax-Facts.html';
	siteMainNav[3] = '<div class="secondaryNav"><div class="container"><img src="/images/icon_appet.gif" alt="" /><div class="copy narrow"><a href="/flax-recipes/#appetizers">Appetizers</a><p>Start every meal with irresistible flax appetizers.</p></div></div>		<div class="container"><img src="/images/icon_bbm.gif" alt="" /><div class="copy narrow"><a href="/flax-recipes/#Breakfast-Breads-and-Muffins">Breakfast, Breads, and Muffins</a><p>Flax recipes for breakfast, breads, and muffins! Oh my!</p></div></div>	<div class="clear"></div><div class="container"><img src="/images/icon_ss.gif" alt="" /><div class="copy narrow"><a href="/flax-recipes/#Soups-and-Salads">Soups and Salads</a><p>Flax recipes for soups and salads are sure to be a success.</p></div></div>		<div class="container"><img src="/images/icon_sides.gif" alt="" /><div class="copy narrow"><a href="/flax-recipes/#Sides">Sides</a><p>Flax side dishes compliment any meal.</p></div></div>	<div class="clear"></div><div class="container"><img src="/images/icon_md.gif" alt="" /><div class="copy narrow"><a href="/flax-recipes/#Main-Dishes">Main Dishes</a><p>These flax recipes make every main dish a meaningful meal!</p></div></div>		<div class="container"><img src="/images/icon_desserts.gif" alt="" /><div class="copy narrow"><a href="/flax-recipes/#Desserts">Desserts</a><p>Satisfy your sweet tooth with decadent flax desserts.</p></div></div><div class="clear"></div></div>'; //'http://' + window.location.host + '/Flax-Recipes.html';
	siteMainNav[4] = '<div class="secondaryNav"><p class="mdMargB">Why flax? Why now? Flax is a powerhouse of disease-fighting compounds researchers have found to prevent heart disease, protect against inflammatory disorders and certain cancers, and lower your cholesterol.</p><p>Flax is added to many products on today\'s grocery shelves because of the omega-3 fatty acids, lignans, and fiber found in the seed, all which  help deliver a unique and nutritious health boost that aids inoverall wellness. Flax can be added to your diet in a variety of <a href="/flax-facts/#63">easy ways</a> to gain these health benefits. Read on to seehow the omega 3s, lignans, and fiber found in flax can help you achieve optimal health and wellness.</p><div class="container halfA"><p><a href="/flax-health-benefits/#1">Omega-3 Fatty Acids and Heart Health</a></p><p><a href="/flax-health-benefits/#2">Lignans/Antioxidants</a></p><p><a href="/flax-health-benefits/#3">Fiber in Flax</a></p><p><a href="/flax-health-benefits/#4">Nutrition Profile</a></p><p><a href="/flax-health-benefits/#5">Balancing Good and Bad Fats </a></p></div><div class="container halfB"><p><strong>Flax in a Vegetarian Diet</strong></p><ul class="noIndent"><li><a href="/flax-health-benefits/#61">Cooking with Flax</a></li><li><a href="/flax-health-benefits/#62">Recommended Intake of Omega-3 Fatty Acids and Enriched Eggs</a></li></ul></div></div>'; //'http://' + window.location.host + '/Flax-Health.html';
	siteMainNav[5] = '<div class="secondaryNav"><p>Below are answers to some of the most commonly asked questions about flax. Feel free to <a href="/contact-us.php">contact us</a> if you have others.</p><div class="container"><img src="/images/icon_flax101.gif" alt="" /><div class="copy"><a href="/flax-faq/#41">Flax 101</a><p>Take a quick course on flax basics. Learn about where flax comes from, how to store it, and the amount you need to optimize your health.</p></div></div>		<div class="clear"></div><div class="container"><img src="/images/icon_flaxYourHealth.gif" alt="" /><div class="copy"><a href="/flax-faq/#42">Flax and Your Health</a><p>Fact or Fiction? Click here for the answers to common questions about flax\'s health benefits and how they are key to a healthy lifestyle.</p></div></div>	<div class="clear"></div><div class="container"><img src="/images/icon_flaxFood.gif" alt="" /><div class="copy"><a href="/flax-faq/#43">Flax and Food</a><p>Learn more about how to use flax and where to find it. </p></div></div><div class="clear"></div></div>'; //'http://' + window.location.host + '/Flax-FAQ.html';
	siteMainNav[6] = '<div class="secondaryNav"><p>Learn more about our flax partners at:</p><div class="container"><img src="/images/FC2015slogan.gif" alt="" /><div class="copy"><a href="http://www.fc2015.ca">FC2015</a><p>Flax Canada 2015 (FC2015) is a unique initiative established to identify and utilize value-added opportunities for flax.</p></div></div>			<div class="clear"></div>	<div class="container"><div class="partners"><a href="http://www.ameriflax.com/">Ameriflax</a><p>AmeriFlax is a nonprofit corporation that conducts promotional activities for flaxseed to consumers, the food industry, and the animal feeding industry.</p></div><div class="partners"><a href="http://www.flaxcouncil.ca/">Flax Council of Canada </a><p>The Flax Council of Canada is a national organization which promotes Canadian flax nutritional and industrial uses in domestic and international markets.</p></div><div class="partners"><a href="http://www.saskflax.com/">SaskFlax</a><p>The Saskatchewan Flax Development Commission or SaskFlax provides for the orderly and effective development of the flax industry in Saskatchewan, Canada.</p></div></div>		<div class="clear"></div></div>'; //'http://' + window.location.host + '/Flax-Partners.html';
	siteMainNav[7] = '<div class="secondaryNav"><p>Learn more about flax!</p><img src="/images/Archive-banner.jpg" width="468" height="45"><br /><p>Original Date: June 7th, 2007 <br /><a href="https://event.on24.com/eventRegistration/EventLobbyServlet?target=registration.jsp&eventid=36365&sessionid=1&key=69E8DC3B47A3883DD8970E98473513EA&sourcepage=register" target="_blank">Click Here</a> to register</p><p><br /></p><p>Original Date: April 26th, 2007 <br /><a href="https://event.on24.com/eventRegistration/EventLobbyServlet?target=registration.jsp&eventid=36365&sessionid=1&key=69E8DC3B47A3883DD8970E98473513EA&sourcepage=register" target="_blank">Click Here</a> to register</p><div class="clear"></div></div>'; //'http://' + window.location.host + '/Events.html';

function t_setNav(obj)
{
	document.getElementById("secondaryNav").innerHTML = siteMainNav[obj];
	//var thisObj = siteMainNav[obj];
	//getMyHTML(thisObj, "secondaryNav");
	//alert("TEST::Object ID: "+obj);
	var navClear = false;
	var navSet = false;
	var x = document.getElementById('mainNav');
	x = x.getElementsByTagName('LI');
	//alert(x);	
	var i;
	for (i=0;i<x.length;i++)
	{
		//alert(i);
		if (x[i].id == 'mainNavActive')
		{
			x[i].id = '';
			x[i].firstChild.className="";
			navClear = true;
			if(navClear == true && navSet == true ) { break; }
		}
		
		if (i == obj)
		{
			x[i].id = 'mainNavActive';
			x[i].firstChild.className='active';
			navSet = true;
			if(navClear == true && navSet == true ) { break; }
		}
	}

}
	
function new_Nav(cnav,obj)
{
	document.getElementById("secondaryNav").innerHTML = siteMainNav[obj];
	//buildAJAX();
	//getMyHTML(siteMainNav[obj], "secondaryNav");

	//cnav.id = 'mainNavActive';
	//cnav.firstChild.className="active";
	var navClear = false;
	var navSet = false;
	var x = document.getElementById('mainNav');
	x = x.getElementsByTagName('LI');
	//alert(x);	
	var i;
	for (i=0;i<x.length;i++)
	{
		//alert(i);
		if (x[i].id == 'mainNavActive')
		{
			x[i].id = '';
			x[i].firstChild.className="";
			navClear = true;
			if(navClear == true && navSet == true ) { break; }
		}
		
		if (i == obj)
		{
			x[i].id = 'mainNavActive';
			x[i].firstChild.className='active';
			navSet = true;
			if(navClear == true && navSet == true ) { break; }
		}
	}		
}

buildAJAX();
