// 2007.02.15 KJD: Image Location
// 2007.04.23 KJD: Update to Bundles and code cleanup
// 2007.09.06 KJD: Removed $ sign from prices


if( !( window.ImageLocation ) )
{

	// var ImageLocation 			= "/content/en/us/home_homeoffice/pagecopy/cx/ABM/images/";
	
	// 2007.05.03 KJD: Updated to new folder
	var ImageLocation			= "/content/en/us/home_homeoffice/images/ABM/";
	
	// 2007.03.01 KJD: Only for Dev
	/*	
	var BoxShotLocation			= "/content/en/us/home_homeoffice/images/prodbox/";
	var BoxShotLocation_large	= "large/";
	var BoxShotLocation_small	= "small/";
	
	var ProductImageLocation	= ImageLocation + "product_images/";

	BoxShotLocation				= ProductImageLocation;
	BoxShotLocation_large		= ProductImageLocation;
	BoxShotLocation_small		= ProductImageLocation;
	*/
		
	var BoxShotLocation			= "";
	var BoxShotLocation_large	= "";
	var BoxShotLocation_small	= "";
	
	var ProductImageLocation	= "";
	
	// 2007.05.03 KJD: Updated to new folder
	// var XMLLocation 	= "/content/en/us/home_homeoffice/pagecopy/cx/ABM/xml";
	var XMLLocation		= "/content/en/us/home_homeoffice/ABM";
	
	/*
	var ImageLocation 	= "images/product_images/";
	var XMLLocation 	= "xml";
	*/
}

var FinderLoaded	= 1;
	
// define global variable for global scope
var xmlDoc;
var singleWindowsProductArray	= new Array(); // define new array to hold values for all Windows single products
var bundleWindowsProductArray	= new Array(); // define new array to hold values for all Windows bundle products
var singleMacProductArray 		= new Array(); // define new array to hold values for all Mac products
var bundleMacProductArray 		= new Array();
var thisPID; // set array for product IDs
var thisPlatform; // set array for product platforms
var thisType; // set array for product types (single/bundle)
var productNodes; // set array for product nodes
var arrAssocActID2s 			= new Array(); // associated activity IDs for products
var arrAssocFtrIDs 				= new Array(); // associated feature IDs for products
//var selectedProductNodes = new Array(); // set array for selected product nodes

var productImages 				= new Array(); // set array for all product images
var productTitles 				= new Array(); // set array for all product titles
var productAddToCartLinks 		= new Array(); // set array for all product add to cart links
var productPrices 				= new Array(); // set array for all product prices
var productDiscountAmts 		= new Array(); // set array for all product discount amounts
var productKeyFeatures 			= new Array(); // set array for all product key features
var productIndexes 				= new Array(); // set array to keep indexes of products as they appear in product_finder.xml
var productIncludedProducts 	= new Array(); // set array for all included products in bundles
var productSystemRequirements 	= new Array(); // set array for all system requirements
var productShowsHere 			= new Array(); // set array for all 

var firstload 					= 1;

var thisProduct;
var thisProdID;

//var selectedProducts;
var activitiesToShow;
//var selectedProductNodes;
var xmlDocProduct; 
var xmlDocActivities;
var prodIndexes 				= new Array();

// 2007.02.13 KJD: Text Headings:
/*Moving to xml
var productHeading_single 		= "Other products that also meet your needs:";
var productHeading_bundle 		= "Products in the bundle above:";
var productHeading_other		= "This product also meets your needs:";
var productHeading_FallBack		= "These products meet all your needs:";

var recommendHeader				= "We recommend this product:";


var title_KeyFeatures 			= "Key Features of ";
var title_SystemRequirements 	= "System Requirements of ";
var LearnMoreLinkText			= "Learn more ";
var SystemRequirementsText		= "View All System Requirements ";

var tooltipText					= "The highlighted activities at the left are addressed with this product";
*/
// 2007.02.21 KJD: Default product arrays
var defaultWindowsProducts 		= new Array( "n360", 		"nav2007", 	"nis2007" 	);
var defaultMacProducts 			= new Array( "nis30mac", 	"nav10mac", "ncomac" 	);

// 2007.02.22 KJD: All in one bin
var SelectedItems				= new Array();

// load product_finder.xml
// if IE
if (window.ActiveXObject) {
	xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
	xmlDoc.async="false"
	xmlDoc.load( XMLLocation + "/product_finder.xml");
	populateArrays();
// if Firefox
} else if(document.implementation && document.implementation.createDocument) {
	try {
		xmlDoc = document.implementation.createDocument("","",null);
		xmlDoc.onload = populateArrays;
		xmlDoc.load( XMLLocation + "/product_finder.xml");
	} catch (e) {
		if (window.XMLHttpRequest) {
			xmlDoc = new XMLHttpRequest();
			xmlDoc.onreadystatechange = processReqChange;
			xmlDoc.open("GET",  XMLLocation + "/product_finder.xml", true);
			xmlDoc.send(null);
		}
	}
}

// 2007.02.22 KJD: Check if #8 is selected
function CheckSaveRestore()
{
	if( document.getElementById( 'wtask_activity_9' ).checked )
	{
		AllInOne( true, 0 );
	}
	else
	{
		getInfo();
	}
}


// 2007.02.22 KJD: Added for All-in-one product
function AllInOne( checkedstatus, savestatus )
{
	// 2007.02.22 KJD: Check if selected
	if( checkedstatus )
	{
		if( savestatus )
		{
			SelectedItems = getChosenActivities();
			// alert(SelectedItems);
		}
	
		DoFade( 'outfast', 'readout' );
		
		var products 	= new Array();
		var activities 	= new Array();
		
		if( document.getElementById( 'wtask_activity_8' ).checked )
		{
			// 2007.02.22 KJD: Display N360
			products 	= new Array( "n360" ); // have to hard code because not using getAssociatedProducts
			activities 	= new Array( "activity_8", "activity_9");

		}
		else
		{
			products 	= new Array( "n360" );
			activities 	= new Array( "activity_9" );
		}
		
		setTimeout( function(){displayProducts(activities,products);}, 125 );
		setTimeout( "DoFade( 'infast', 'readout' );", 150 );
	
		// 2007.02.26 KJD: Hide Restore checkbox
		// 2007.09.06 KJD: Placed in try
		try{
		document.getElementById( 'wtask_activity_8' ).checked 			= false;
		document.getElementById( 'wtask_activity_8_row' ).style.color 	= "#aaaaaa";
		document.getElementById( 'wtask_activity_8_row' ).disabled 		= true;
		document.getElementById( 'wtask_activity_8' ).disabled 			= true;
		}catch(e){}
	}
	else
	{
		// 2007.02.26 KJD: Show Restore checkbox
		try{
		document.getElementById( 'wtask_activity_8_row' ).disabled 		= false;
		document.getElementById( 'wtask_activity_8' ).disabled 			= false;
		document.getElementById( 'wtask_activity_8_row' ).style.color 	= "";
		}catch(e){}
	}
	
	// 2007.02.22 KJD: Set Checkboxes
	for( var i = 1; i < 8; i++ )
	{
		if( document.getElementById( 'wtask_activity_' + i ) )
		{
			try{
			document.getElementById( 'wtask_activity_' + i ).checked 	= checkedstatus;
			document.getElementById( 'wtask_activity_' + i ).disabled 	= checkedstatus;
			}catch(e){}
		}
	}
	
	if( !( checkedstatus ) )
	{
		CheckActivities( SelectedItems );
		getInfo();
	}
}

// 2007.02.22 KJD: Check Selected activities
function CheckActivities( ActivityList )
{
	var thisactivity = "";
	for( var i=0; i < ActivityList.length; i++ )
	{
		thisactivity = ActivityList[i].replace('activity_','');
		if( thisactivity != "9" )
		{
			document.getElementById( 'wtask_activity_' + thisactivity ).checked 	= true;
		}
	}
}


function processReqChange() {
    // only if req shows "loaded"
    if (xmlDoc.readyState == 4) {
        // only if "OK"
        if (xmlDoc.status == 200) {
			xmlDoc = xmlDoc.responseXML;
            populateArrays();
         } else {
            alert("There was a problem retrieving the XML data");
         }
    }
}


// functon to traverse XML DOM (cross-browser, whew!) and populate JavaScript arrays for association later
function populateArrays()
{
	thisPID 				= xmlDoc.getElementsByTagName("pid");
	thisPlatform 			= xmlDoc.getElementsByTagName("platform");
	thisType 				= xmlDoc.getElementsByTagName("type");
	productNodes 			= xmlDoc.getElementsByTagName("product");
	arrAssocActID2s 		= xmlDoc.getElementsByTagName("associated_activities");
	productImages 			= xmlDoc.getElementsByTagName("image");
	productNames 			= xmlDoc.getElementsByTagName("name");
	productAddToCartLinks 	= xmlDoc.getElementsByTagName("add_to_cartlink");
	productPrices 			= xmlDoc.getElementsByTagName("price");
	productDiscountAmts 	= xmlDoc.getElementsByTagName("discount_amt");
	
	productDiscountNotes 	= xmlDoc.getElementsByTagName("discount_note");
	
	productKeyFeatures 		= xmlDoc.getElementsByTagName("key_features");
	productIncludedProducts = xmlDoc.getElementsByTagName("inc_prods");
	productShowsHere 		= xmlDoc.getElementsByTagName("display");
	
	// populate JavaScript arrays
	for(i=0;i < thisPID.length;i++)
	{
		// only if this product is set to show in the product finder logic (B or F)
		if (productShowsHere[i].childNodes[0].nodeValue != "C")
		{
			if (thisPlatform[i].childNodes[0].nodeValue == "Windows")
			{
				if (thisType[i].childNodes[0].nodeValue == "Product")
				{
					// 2007.02.14 LPB: 
					singleWindowsProductArray.push( thisPID[i].childNodes[0].nodeValue );
				}
				else
				{
					bundleWindowsProductArray.push( thisPID[i].childNodes[0].nodeValue );
				}
			}
			else
			{
				if (thisType[i].childNodes[0].nodeValue == "Product")
				{
					singleMacProductArray.push( thisPID[i].childNodes[0].nodeValue );
				}
				else
				{
					bundleMacProductArray.push( thisPID[i].childNodes[0].nodeValue );
				}
			}
			
		}
		productIndexes.push(thisPID[i].childNodes[0].nodeValue);
	}
}

//This method returns all the activities that are selected by the user 
function getChosenActivities()
{
	var checkboxList 	= document.taskForm.task;
	var checkboxArray 	= new Array();
	
	for (i=0;i < checkboxList.length;i++)
	{
		if (checkboxList[i].checked == true)
		{
			checkboxArray.push( checkboxList[i].value );// checkboxArray contains values which have been selected
		}
	}

	return checkboxArray;
}

// 2007.02.14 KJD: Compare arrays
function ValuesInArray( array1, array2 )
{
	var myresult 	= false;
	var mycount 	= 0;
	
	for( var i=0; i < array1.length; i++ )
	{
		for( var j=0; j < array2.length; j++ )
		{
			if( array1[i] == array2[j] )
			{
				mycount++;
			}
		}
	}
	
	if( mycount == array1.length )
	{
		myresult = true;
	}
	
	return myresult;
}


// This method returns products that satisfies the given list of activities chosen 
function getAssociatedProducts(platform,activities)
{
	var prodsForAllActivities 	= new Array();
	
	// 2007.02.14 KJD: Set up some temporary arrays
	var tempProductList 		= new Array();
	var commonproducts 			= new Array();

	// 2007.02.14 KJD: Use Mac or Windows arrays
	if( platform == "win" )
	{
		tempProductList = singleWindowsProductArray;
	}
	else
	{
		tempProductList = singleMacProductArray;
	}
	
	for (var j=0; j < tempProductList.length; j++)
	{
		// get prod acts
		var productactivities = getProductActivities( tempProductList[j] );

		// check for acts in prods
		if( ValuesInArray( activities, productactivities ) )
		{
			prodsForAllActivities.push( tempProductList[j] );
		}
	}
	
	
	if( !( prodsForAllActivities.length ) )
	{
		prodsForAllActivities = getAssociatedBundles(platform,activities);
	}
	else
	{

		if( activities.length )
		{
			// only get the top 3, if there are any
			if (prodsForAllActivities.length > 3)
			{
				prodsForAllActivities.splice(3, prodsForAllActivities.length - 3);
			}

			// alert( "ProdActs:" + prodsForAllActivities );
			var tempArray = ScoreProducts( 'sequence', prodsForAllActivities, activities );
		}
		else
		{
			// 2007.02.20 KJD: Set for no activities selected
			if( platform == "win" )
			{
				prodsForAllActivities = defaultWindowsProducts;
			}
			else
			{
				prodsForAllActivities = defaultMacProducts;
			}
			
			document.getElementById( 'considerDefault' ).innerHTML = displayDefaults( prodsForAllActivities );
		}
	}
	
	return prodsForAllActivities;
}

// 2007.02.21 KJD: Display default products
function displayDefaults( productarray )
{
	var thisstring 			= "";
	var thisproductname 	= "";
	var thisproductimage 	= "";
	var thisproductprice 	= "";
	var thiscartlink 		= "";
	
	for( var i =0; i < productarray.length; i++ )
	{
		thisproductname 	= ProductValue( productarray[i], "name" );
		thisproductimage 	= ProductValue( productarray[i], "image" );
		thisproductprice 	= ProductValue( productarray[i], "price" );
		thiscartlink		= ProductValue( productarray[i], "add_to_cartlink" );
	
		if( !( i ) )
		{
			thisstring += "<div class=\"considerItem\" style=\"background:transparent\">"
		}
		else
		{
			thisstring += "<div class=\"considerItem\">"
		}

		thisstring += ""
			+ "		<div class=\"product-image\"><a href=\"#\" onClick=\"popin('" + productarray[i] + "'); return false;\" onMouseover=\"javascript:hiliteTask('" + productarray[i] + "','on');\" onMouseout=\"javascript:hiliteTask('" + productarray[i] + "','off');\"><img class=\"product\" src=\"" + BoxShotLocation_small + thisproductimage + "\"  TITLE=\"The highlighted activities at the left are addressed with this product\"/></a></div>"
			+ "		<div class=\"product-features\">"
			+ "			<h4><a href=\"#\" onClick=\"popin('" + productarray[i] + "'); return false;\" onMouseover=\"javascript:hiliteTask('" + productarray[i] + "','on');\" onMouseout=\"javascript:hiliteTask('" + productarray[i] + "','off');\" TITLE=\"" + tooltipText + "\">" + thisproductname + "</a></h4>"
			+ "			<p class=\"price\">" + thisproductprice + "<a href=\"" + thiscartlink + "\"><img class=\"add\" src=\"" + ImageLocation + "button_add_to_cart.gif\" alt=\"Add To Cart\"></a></p>"
			+ "		</div>"
			+ "	</div>";
	}

	return thisstring;
}

// 2007.02.20 KJD: Added
function SetCompareButton( buttontype )
{
	var buttonname = ImageLocation + "button_compare";
	
	if( buttontype ){ buttonname += "_" + buttontype; }
	
	buttonname += ".gif";
	
	var buttoninfo = "&nbsp;";

	if( !( buttontype ) )
	{
		buttoninfo = '<a href="#" onClick="javascript:displayCompareDiv();"><img src="' + buttonname + '"></a>';
	}
	
	document.getElementById('compare').innerHTML = buttoninfo;
}


// 2007.02.16 KJD: Order the products by a specific score
function ScoreProducts( scoretype, productslist, activitiesselected )
{
	var featuretotalcount 	= 0;
	var featureproductcount = 0;
	
	var tempproductorder	= new Array();
	var productorder 		= new Array();

	var debugtext = "";
	
	if( scoretype == 'sequence' )
	{
		// 2007.02.16 KJD: Get score of products
		for( var i=0; i < productslist.length; i++ )
		{
			featureproductcount = FeatureProductCount( productslist[i], activitiesselected );
			
			tempproductorder[ productslist[i] ] = featureproductcount;
			
			debugtext += productslist[i] + " = " + featureproductcount + "\n";
		}

		if( featureproductcount )
		{
			// productslist.reverse();
			productorder = SortProductOrder( productslist.reverse(), tempproductorder );
			productorder.reverse();

			debugtext += "Ordered:" + productorder;
			// alert( debugtext );
		}
		else
		{
			productorder = productslist;
		}
	}

	return productorder;
}

// 2007.02.16 KJD: Sort the product order
function SortProductOrder(keyArray, valueMap)
{ 
  return keyArray.sort(function(a,b){return valueMap[a]-valueMap[b];}); 
} 


// 2007.02.16 KJD: Get the count of features in a product for selected activities
function FeatureProductCount( myProductID, activitiesselected )
{
	var featurecount 		= 0;
	
	var activityfeatures 	= new Array();
	var productfeatures 	= new Array();
	
	var productcount 		= 0;
	
	for( var i=0; i < activitiesselected.length; i++ )
	{
		// 2007.02.16 KJD: Get the feature IDs for the selected activity
		activityfeatures = getFeatureIDs( activitiesselected[i] );
		
		// 2007.2.16 KJD: Get the feature IDs for a product
		productfeatures = getProductFeatures( myProductID );
		
		featurecount = 0;
		// 2006.02.16 KJD: Count the features that are the same
		for( var j=0; j < activityfeatures.length; j++ )
		{
			for( var k=0; k < productfeatures.length; k++ )
			{
				if( productfeatures[k] == activityfeatures[j] )
				{
					featurecount++;
				}
			}
		}
		
		productcount += ( featurecount / activityfeatures.length );
	}

	featurecount = ( productcount / i );
	return featurecount;
}

// 2007.02.21 KJD: Go to the overview page for a product
function GoToProductPage( myProductID )
{
	var productlink = ProductValue( myProductID, "pop_in_learn_more" );
	
	location.href = productlink + "&inid=ABM";
}


// 2007.02.16 KJD: Get the list of features in a product
function getProductFeatures( myProductID )
{
	var productfeatures = new Array();
	
	var productNode = getProductNode( myProductID );
	
	var thesefeatures = productNode.getElementsByTagName("feature_id");
	
	for( var i =0; i < thesefeatures.length; i++ )
	{
		productfeatures.push( thesefeatures[i].childNodes[0].nodeValue );
	}
	
	return productfeatures;
}

// 2007.02.16 KJD: Get the feature IDs of an activity
function getFeatureIDs( activityID )
{
	var featureIDs = new Array();
	
	var activitynode = getMyActivityNode( activityID );

	// 2007.02.16 KJD: Get items
	var activityitems = activitynode.getElementsByTagName("item");
	
	for( var i=0; i < activityitems.length; i++ )
	{
		featureIDs.push( activityitems[i].getAttribute("id") );
	}
	
	return featureIDs;
}

// 2007.02.16 KJD: Get the number of features for an activity
function ActivityFeatureCount( activity )
{
	var featurecount = 0;
	
	var activitynode = getMyActivityNode( activity );

	// 2007.02.16 KJD: Get items
	var activityitems = activitynode.getElementsByTagName("item");
	featurecount = activityitems.length;

	return featurecount;
}

// 2007.02.16 KJD: Load the available options xml file
// ( I'm not thrilled about this one )
function LoadActivityOptions()
{
	if (window.ActiveXObject) {
		xmlDocActivities = new ActiveXObject("Microsoft.XMLDOM")
		xmlDocActivities.async="false"
		xmlDocActivities.load( XMLLocation + "/available_options.xml");
	} else if(document.implementation && document.implementation.createDocument) {
		try {
			xmlDocActivities = document.implementation.createDocument("","",null);
			xmlDocActivities.load( XMLLocation + "/available_options.xml");
		} catch (e) {
			if (window.XMLHttpRequest) {
				xmlDocActivities = new XMLHttpRequest();
				xmlDocActivities.open("GET",  XMLLocation + "/available_options.xml", true);
				xmlDocActivities.send(null);
			}
		}
	}
}


// 2007.02.16 KJD: HS version doesn't work properly, so I wrote my own
function getMyActivityNode( activityID )
{
	var activityNode = null;

	var acts = xmlDocActivities.getElementsByTagName("activity_option");

	for(var x=0; x < acts.length; x++)
	{
		var theseacts = acts[x].getElementsByTagName("activity_id");

		if( theseacts[0].childNodes[0].nodeValue == activityID )
		{
			activityNode = acts[x];
		}
	}

	return activityNode;
}


function getAssociatedBundles(platform,activities)
{
	var bundsForAllActivities 	= new Array();
	var tempBundleList 			= new Array();
	var productactivities		= new Array();
	var tempBund				= new Array();
	
	if( platform == "win" )
	{
		tempBundleList = bundleWindowsProductArray;
	}
	else
	{
		tempBundleList = bundleMacProductArray;
	}

	// each bund
	for (var j=0; j < tempBundleList.length; j++)
	{
		// get bund acts
		// 2007.02.26 KJD: Wrap in try block for if bundle isn't found
		try
		{
			productactivities = getProductActivities( tempBundleList[j] );

			// check for acts in bunds
			if( ValuesInArray( activities, productactivities ) )
			{
				bundsForAllActivities.push( tempBundleList[j] );
				break;
			}
		}
		catch(e)
		{
		}
	}

	
	// 2007.02.14 KJD: Get included products of bundle
	tempBund 					= getProductsInBundle( bundsForAllActivities );

	if( !( bundsForAllActivities.length ) && !( tempBund.length ) )
	{
		// alert('show n360 and nsr');
		bundsForAllActivities = FallBackRules();
	}
	else
	{
		bundsForAllActivities[1] 	= tempBund[0];
		bundsForAllActivities[2] 	= tempBund[1];
	}
	
	// 2007.02.26 KJD: Check if 8 & 9 aren't checked
	if( 
		!( document.getElementById( 'wtask_activity_9' ).checked ) &&
		!( document.getElementById( 'wtask_activity_8' ).checked )
	)
	{
		// 2007.02.22 KJD: Check for N360
		bundsForAllActivities = N360Display( bundsForAllActivities );
	}
	
	return bundsForAllActivities;
}

// 2007.02.27 KJD: Create fall back rules
function FallBackRules()
{
	var theseProducts = new Array( "n360" );
	if( 
		( document.getElementById( 'wtask_activity_8' ).checked )
		// ( document.getElementById( 'wtask_activity_7' ).checked )
	)
	{
		theseProducts.push( "nsr" );
	}

	return theseProducts;
}


// 2007.02.22 KJD: Get value of include N360
function N360Display( bundsForAllActivities )
{
	var productNode 		= getProductNode( bundsForAllActivities[0] );

	var include360node		= productNode.getElementsByTagName("also_recommend_n360");
	var include360 			= 0;
	
	if( include360node.length )
	{
		include360 = parseInt( include360node[0].childNodes[0].nodeValue );

		if( include360 == 1 )
		{
			bundsForAllActivities[1] 		= bundsForAllActivities[0];
			bundsForAllActivities[0] 		= 'n360';
			bundsForAllActivities.length 	= 2;
		}
		else if( include360 == 2 )
		{
			bundsForAllActivities[1] 		= 'n360';
			bundsForAllActivities.length 	= 2;
		}
		else if( include360 == 3 )
		{
			bundsForAllActivities[0] 		= 'n360';
			bundsForAllActivities.length 	= 1;
		}
	}
	
	return bundsForAllActivities;
}

// 2007.02.22 KJD: Determine section Header
function HeadingText( productlist )
{
	var thisstring = "";

	// 2007.02.13 KJD: Check if bundle
	if( isBundle( productlist ) )
	{
		// 2007.02.13 KJD: Adjust text
		thisstring = productHeading_bundle;

		if( N360Shown( productlist ) )
		{
			// 2007.02.22 KJD: Adjust text
			thisstring = productHeading_other;
		}
	}
	else
	{
		// 2007.02.13 KJD: Adjust text
		thisstring = productHeading_single;
	}
		
	return thisstring;
}

// 2007.02.22 KJD: See if N360 is showing
function N360Shown( productlist )
{
	var showtext = false;
	for( var i=0; i < productlist.length; i++ )
	{
		if( ( productlist[i] == 'n360' ) && ( productlist.length == 2 ) )
		{
			return true;
		}
	}
	
	return showtext;
}


function getInfo() {
	var activities = new Array();
	var products = new Array();
	var thisPlatform;
	
	if( !firstload )
	{
		DoFade( 'outfast', 'readout' );
	}
	else
	{
		firstload = 0;
		// alert('check');
	}
	
	
	activities = getChosenActivities(); // how many and what activities are chosen by the user.
	
	if (document.getElementById("radioPlatform1").checked == true) {
		thisPlatform = "win";
	} else if (document.getElementById("radioPlatform2").checked == true) {
		thisPlatform = "mac";
	}
	
	products = getAssociatedProducts(thisPlatform,activities);// all user selected activities are passed to the method
	
	
	setTimeout( function(){displayProducts(activities,products);}, 125 );// displays products according to the user choice
	
	setTimeout( "DoFade( 'infast', 'readout' );", 150 );
}



function displayProducts(activities,products)
{
	
	// 2007.02.20 KJD: Set compare button
	if( products.length == 1 )
	{
		SetCompareButton( 'disable' );
	}
	else
	{
		SetCompareButton(  );
	}

	
	if (activities.length == 0)
	{ 
		// if there are no activities selected
		// show the default product offering and hide all results
		document.getElementById("scenario_0").style.display 		= "block";
		document.getElementById("scenario_all").style.display 		= "none";
		document.getElementById("considerContainer").style.display 	= "none";
	}
	else
	{
		// hide the default product offering
		document.getElementById("scenario_0").style.display 		= "none";
		document.getElementById("consprod1").style.display 			= "none";
		document.getElementById("consprod2").style.display 			= "none";
		document.getElementById("considerContainer").style.display 	= "none";
		
		if (document.getElementById("recprod_img").childNodes.length == 1)
		{
			document.getElementById("recprod_img").removeChild(document.getElementById("recprod_img").childNodes[0]);
			document.getElementById("recprod_ul").innerHTML = "";
		}
		
		if (document.getElementById("consprod1_img").childNodes.length == 1)
		{
			document.getElementById("consprod1_img").removeChild(document.getElementById("consprod1_img").childNodes[0]);
			document.getElementById("consprod1_ul").innerHTML = "";
		}
		
		if (document.getElementById("consprod2_img").childNodes.length == 1)
		{
			document.getElementById("consprod2_img").removeChild(document.getElementById("consprod2_img").childNodes[0]);
			document.getElementById("consprod2_ul").innerHTML = "";
		}
		
		//populate the product finder result area with the proper results
		// create image for recommended product
		var rec_img = document.createElement("img");
		rec_img.className = "product";		

		// 2007.02.26 KJD: Get the product index
		for( var thisProductIndex = 0; thisProductIndex < productIndexes.length; thisProductIndex++ )
		{
			if( productIndexes[ thisProductIndex ] == products[0] )
			{
				break;
			}
		}
		
		rec_img.setAttribute("src", BoxShotLocation_small + productImages[ thisProductIndex ].childNodes[0].nodeValue);

		rec_img.setAttribute('title',tooltipText); // 2007.02.20 KJD: Use browser's tooltip

		document.getElementById("recprod_img").appendChild(rec_img);

		// give attributes to a tag for recommended product image and add the image
		
		// 2007.02.15 SP: Fixed for IE highlighting
		document.getElementById("recprod_img").setAttribute("href","javascript:popin('" + products[0] + "');");
		
		// 2007.02.15 KJD: For IE
		document.getElementById("recprod_img").setAttribute("onmouseover",function anonymous(){hiliteTask(products[0],'on');});
		document.getElementById("recprod_img").setAttribute("onmouseout",function anonymous(){hiliteTask(products[0],'off');});
	
		
		// 2007.02.20 KJD: Added for tooltips
		document.getElementById("recprod_title").setAttribute("title",tooltipText );
	
		// 2007.02.15 KJD: For FF
		document.getElementById("recprod_img").setAttribute("onMouseOver","hiliteTask('" + products[0] + "','on');");
		document.getElementById("recprod_img").setAttribute("onMouseOut","hiliteTask('" + products[0] + "','off');");
	
		document.getElementById("recprod_title").setAttribute("href","javascript:popin('" + products[0] + "');");
		
		// 2007.02.15 KJD: For IE
		document.getElementById("recprod_title").setAttribute("onmouseover",function anonymous(){hiliteTask(products[0],'on'); });
		document.getElementById("recprod_title").setAttribute("onmouseout",function anonymous(){hiliteTask(products[0],'off'); });
		
		// 2007.02.15 KJD: For FF
		document.getElementById("recprod_title").setAttribute("onMouseOver","hiliteTask('" + products[0] + "','on'); ");
		document.getElementById("recprod_title").setAttribute("onMouseOut","hiliteTask('" + products[0] + "','off'); ");	
		

		document.getElementById("recprod_title").innerHTML = productNames[ thisProductIndex ].childNodes[0].nodeValue;

		// give attributes to span tag for recommended product price and add the copy
		if ( productDiscountAmts[ thisProductIndex ].childNodes[0] )
		{
	
			var PriceString = "" 
				+ productPrices[ thisProductIndex ].childNodes[0].nodeValue 
				+ "&nbsp;<font color='#ff0000'>SAVE " 
				+ productDiscountAmts[ thisProductIndex ].childNodes[0].nodeValue 
				+ "!</font>"
				+ "<br /><SPAN CLASS='disclaimer'>"
				+ productDiscountNotes[ thisProductIndex ].childNodes[0].nodeValue
				+ "</SPAN>";
				
			document.getElementById("recprod_price").innerHTML = PriceString;
		}
		else
		{	if(productPrices[ thisProductIndex ].childNodes[0]){
			 document.getElementById("recprod_price").innerHTML = productPrices[ thisProductIndex ].childNodes[0].nodeValue;
			}
		}
		
		// 2007.02.27 KJD: Create Add to Cart Link
		document.getElementById( "recprod_add_link" ).setAttribute( "href", productAddToCartLinks[ thisProductIndex ].childNodes[0].nodeValue );
		
		
		// add the list of features for recommended product
		var rec_ftr_list = "";

		for (var x=0; x < productKeyFeatures[ thisProductIndex ].getElementsByTagName("feature").length; x++)
		{
			rec_ftr_list += "<li>" + productKeyFeatures[ thisProductIndex ].getElementsByTagName("feature")[x].childNodes[0].nodeValue + "</li>";
		}
		document.getElementById("recprod_ul").innerHTML = rec_ftr_list;
		


		document.getElementById( 'recprod' ).style.display 		= "block";
		document.getElementById( 'recprod' ).style.visibility 	= "visible";
		
		document.getElementById( 'considerHeader' ).style.display 		= "block";
		document.getElementById( 'considerHeader' ).style.visibility 	= "visible";

		document.getElementById( 'recommendHeader' ).innerHTML 	= recommendHeader;

		// 2007.02.27 KJD: Manual check for n360 and nsr
		if( products.length == 2 )
		{
			if( ( products[0] == 'n360' ) && ( products[1] == 'nsr' ) )
			{
				
				products[2] = products[1];
				products[1] = products[0];
				
				document.getElementById( 'recprod' ).style.display 		= "none";
				document.getElementById( 'recprod' ).style.visibility 	= "hidden";
				
				document.getElementById( 'recommendHeader' ).innerHTML 	= productHeading_FallBack;
				
				document.getElementById( 'considerHeader' ).style.display 		= "none";
				document.getElementById( 'considerHeader' ).style.visibility 	= "hidden";
				
			}
		}
		
		
		if (products.length > 1) {
			for (var x=1; x < products.length; x++)
			{
				var rec_img = document.createElement("img");
				rec_img.className = "product";
				
				// 2007.02.26 KJD: Get the product index
				for( var thisProductIndex = 0; thisProductIndex < productIndexes.length; thisProductIndex++ )
				{
					if( productIndexes[ thisProductIndex ] == products[x] )
					{
						break;
					}
				}
		
				rec_img.setAttribute("src", BoxShotLocation_small + productImages[ thisProductIndex ].childNodes[0].nodeValue);
				
				rec_img.setAttribute('title',tooltipText); // 2007.02.20 KJD: Use browser's tooltip
				
				document.getElementById("consprod" + x + "_img").appendChild(rec_img);
				
				// give attributes to a tag for recommended product image and add the image
				document.getElementById("consprod" + x + "_img").setAttribute("href","javascript:popin('" + products[x] + "');");
				document.getElementById("consprod" + x + "_title").setAttribute("href","javascript:popin('" + products[x] + "');");

				// 2007.02.20 KJD: Added for tooltips
				document.getElementById("consprod" + x + "_title").setAttribute("title",tooltipText );

				
				// 2007.02.15 SP: Updated for highlight in IE
				if (x == 1)
				{

					document.getElementById("consprod" + x + "_img").setAttribute("onmouseover",function anonymous(){hiliteTask(products[1],'on'); 		});
					document.getElementById("consprod" + x + "_img").setAttribute("onmouseout",function anonymous(){hiliteTask(products[1],'off'); 		});
					document.getElementById("consprod" + x + "_title").setAttribute("onmouseover",function anonymous(){hiliteTask(products[1],'on');	});
					document.getElementById("consprod" + x + "_title").setAttribute("onmouseout",function anonymous(){hiliteTask(products[1],'off');	});
				}
				else
				{
					document.getElementById("consprod" + x + "_img").setAttribute("onmouseover",function anonymous(){hiliteTask(products[2],'on'); 		});
					document.getElementById("consprod" + x + "_img").setAttribute("onmouseout",function anonymous(){hiliteTask(products[2],'off'); 		});
					document.getElementById("consprod" + x + "_title").setAttribute("onmouseover",function anonymous(){hiliteTask(products[2],'on'); 	});
					document.getElementById("consprod" + x + "_title").setAttribute("onmouseout",function anonymous(){hiliteTask(products[2],'off'); 	});
				}
				
				// 2007.02.15 KJD: Highlighting ror FF
				document.getElementById("consprod" + x + "_title").setAttribute("onMouseOver","hiliteTask('" + products[x] + "','on'); 	");
				document.getElementById("consprod" + x + "_title").setAttribute("onMouseOut","hiliteTask('" + products[x] + "','off'); 	");	
				document.getElementById("consprod" + x + "_img").setAttribute("onMouseOver","hiliteTask('" + products[x] + "','on'); 	");
				document.getElementById("consprod" + x + "_img").setAttribute("onMouseOut","hiliteTask('" + products[x] + "','off'); 	");	
				
				
				document.getElementById("consprod" + x + "_title").innerHTML = productNames[ thisProductIndex ].childNodes[0].nodeValue;
				
				// give attributes to span tag for recommended product price and add the copy
				if (productDiscountAmts[ thisProductIndex ].childNodes[0])
				{
					document.getElementById("consprod" + x + "_price").innerHTML = productPrices[ thisProductIndex ].childNodes[0].nodeValue + "&nbsp;<font color='#ff0000'>SAVE " + productDiscountAmts[productIndexes.indexOf(products[x])].childNodes[0].nodeValue + "!</font>";
				}
				else
				{	if(productPrices[ thisProductIndex ].childNodes[0]){
						document.getElementById("consprod" + x + "_price").innerHTML = productPrices[ thisProductIndex ].childNodes[0].nodeValue;
					}
				}

				// 2007.02.27 KJD: Create Add to Cart Link
				if( document.getElementById( "consprod" + x + "_add_link" ) )
				{
					document.getElementById( "consprod" + x + "_add_link" ).setAttribute( "href", productAddToCartLinks[ thisProductIndex ].childNodes[0].nodeValue );
				}
				
				// add the list of features for recommended product
				var rec_ftr_list = "";
				
				for (var y=0; y < productKeyFeatures[ thisProductIndex ].getElementsByTagName("feature").length; y++)
				{
					rec_ftr_list += "<li>" + productKeyFeatures[ thisProductIndex ].getElementsByTagName("feature")[y].childNodes[0].nodeValue + "</li>";
				}
				document.getElementById("consprod" + x + "_ul").innerHTML = rec_ftr_list;
				document.getElementById("consprod" + x).style.display = "block";
			}
			document.getElementById("considerContainer").style.display = "block";
			
		}

		// 2007.02.22 KJD: Determine Header text
		document.getElementById( "productlist_header" ).innerHTML = HeadingText( products );

		document.getElementById("scenario_all").style.display = "block";
	}
}

// 2007.02.13 KJD: Is bundle?
function isBundle( products )
{
	for( var z=0; z< products.length; z++ )
	{
		if( ProductType( products[z] ) == "Bundle" )
		{
			return true;
		}
	}
	
	return false;
}


// 2007.02.13 KJD: Get product Type
function ProductType( myProductID )
{
	var producttype = "Product";
	
	var productNode = getProductNode( myProductID );
	
	var thisproducttype = productNode.getElementsByTagName("type");
	producttype = thisproducttype[0].childNodes[0].nodeValue;
	
	return producttype;
}


// 2007.02.21 KJD: Re-written to work properly
function filterActivities( platformName )
{
	HideActivities();
	
	document.getElementById( platformName ).style.display = "block";

	// 2007.02.26 KJD: Set the platform
	if( platformName == 'windowsActivities' )
	{
		document.getElementById("radioPlatform1").checked = true;
	}
	else
	{
		document.getElementById("radioPlatform2").checked = true;
	}
	
	// 2007.03.01 KJD: Clear all checkboxes
	ClearActivities();
	
	
	getInfo();

  	return;
}




// 2007.02.21 KJD: Hide activity list
function HideActivities()
{
	ClearActivities();
	document.getElementById("windowsActivities").style.display 	= "none";
  	document.getElementById("macActivities").style.display 		= "none";
}

// 2007.02.21 KJD: Clear checked activities
function ClearActivities()
{
	AllInOne( 0 );

	var field = document.taskForm.task;
	for (i = 0; i < field.length; i++)
	{
		field[i].checked 	= false;
		field[i].disabled 	= false;
	}
}

// need to correct these for each specific product
// 2007.02.15 SP: Updated highlighting for IE
function hiliteTask(obj, direction)
{
	// 2007.02.26 KJD: Get the product index
	for( var thisProductIndex = 0; thisProductIndex < productIndexes.length; thisProductIndex++ )
	{
		if( productIndexes[ thisProductIndex ] == obj )
		{
			break;
		}
	}

	var assocActivities = arrAssocActID2s[thisProductIndex].getElementsByTagName("activities_id");
	var thisPlatform;

	if (document.getElementById("radioPlatform1").checked == true)
	{
		thisPlatform = "wtask_";
	}
	else if (document.getElementById("radioPlatform2").checked == true)
	{
		thisPlatform = "mtask_";
	}

	if (direction == "on")
	{
		for (k=0; k < assocActivities.length; k++)
		{
			thisActivity = thisPlatform + assocActivities[k].childNodes[0].nodeValue + "_row";
			
			if( document.getElementById(thisActivity) )
			{
				document.getElementById(thisActivity).style.backgroundColor = "#feed9f";
			}
		}
	} 
	else if (direction == "off") 
	{
		for (k=0; k < assocActivities.length; k++)
		{
			thisActivity = thisPlatform + assocActivities[k].childNodes[0].nodeValue + "_row";
			if( document.getElementById(thisActivity) )
			{
				document.getElementById(thisActivity).style.backgroundColor = "transparent";
			}
		}
	}
}

function blurDD() {
	if (document.getElementById("compareTable").style.display == "block") {
		if (cursorX < leftPos || cursorX > rightPos+40 || cursorY < topPos || cursorY > bottomPos) {
			document.getElementById("compareTable").style.display = "none";
			document.getElementById("blur").style.display = "none";
			document.getElementById("popin").style.display = "none";
		}
	}
}

function blur() {
	topPos = document.getElementById("compareTable").offsetTop;
	leftPos = document.getElementById("compareTable").offsetLeft;
	rightPos = leftPos + document.getElementById("compareTable").offsetWidth;
	bottomPos = document.getElementById("compareTable").offsetHeight;
	
	//set background blur attributes and display. See below for IE6's background blur.
	document.getElementById("blur").style.height = document.body.scrollHeight+"px";
	document.getElementById("blur").style.width = document.body.scrollWidth+"px";
	document.getElementById("blur").style.display = "block";
}

function popin(pid) {
	thisProdID = pid;

	// 2007.02.13 KJD: Added mask
	DoMask( 'popin', 'visible' );

	populatePopInAreas(pid);
}


// 2007.02.15 KJD: Get the popin values (multiple) for an area of a product
function PopinProductItems( myProductID, myTagName )
{
	var productNode 	= getProductNode( myProductID );
	var productinfo		= new Array();

	try
	{
		var thisproductdata = productNode.getElementsByTagName( myTagName );

		for( var i=0; i< thisproductdata.length; i++)
		{
			productinfo.push(thisproductdata[i].childNodes[0].nodeValue);
		}
	}
	catch(e){}

	return productinfo;
}

// 2007.02.15 KJD: Get a single value for a product item
function ProductValue( myProductID, myTagName )
{
	var productNode = getProductNode( myProductID );
	var itemname	= "";
	
	try
	{
		itemname 	= productNode.getElementsByTagName( myTagName );
		
		itemname = itemname[0].childNodes[0].nodeValue;
	}
	catch(e){}
	
	return itemname;
}

// 2007.02.14 KJD: Get the products in the bundle
function getProductsInBundle( myProductID )
{
	var productsInBundle 	= new Array();
	var productNode 		= getProductNode( myProductID );
	

	var PIDNodes 			= productNode.getElementsByTagName("inc_prod");
	
	for (var i=0; i < PIDNodes.length; i++)
	{
		productsInBundle[i] = PIDNodes[i].childNodes[0].nodeValue;
	}

	return productsInBundle;
}


// 2007.02.15 KJD: Added productID
function populatePopInAreas( productID )
{

	var productNodes 					= xmlDoc.getElementsByTagName("pid");
	var productPopInImages 				= xmlDoc.getElementsByTagName("pop_in_image");
	var productPopInTitleImages 		= xmlDoc.getElementsByTagName("pop_in_title_image");
	var productPopInSubtitles 			= xmlDoc.getElementsByTagName("pop_in_subtitle_text");
	var productPopInAddToCartLinks 		= xmlDoc.getElementsByTagName("pop_in_add_to_cartlink");
	
	var productPopInViewSysReqLinks 	= xmlDoc.getElementsByTagName("system_requirements_link");
	var productPopInLearnMoreLink 		= xmlDoc.getElementsByTagName("pop_in_learn_more");
	var productSystemRequirements 		= xmlDoc.getElementsByTagName("system_requirements");
	
	var productPopInPrices 				= xmlDoc.getElementsByTagName("price");
	var productPopInDiscounts 			= xmlDoc.getElementsByTagName("discount_amt");
	
	// 2007.04.23 KJD: Added for Discount Notes
	var productPopInDiscountNotes		= xmlDoc.getElementsByTagName("discount_note");
	
	var productPopInSupportedPlatforms 	= xmlDoc.getElementsByTagName("supported_platforms");
	
	
	for(var i=0; i < productNodes.length; i++)
	{
		if (productNodes[i].childNodes[0].nodeValue == thisProdID)
		{
			thisProduct = i;
			break;
		}
	}
	
	document.getElementById("popInImg").src 			= BoxShotLocation_large + productPopInImages[thisProduct].childNodes[0].nodeValue;
	document.getElementById("popInTitleImg").src 		= BoxShotLocation_large + productPopInTitleImages[thisProduct].childNodes[0].nodeValue;
	document.getElementById("popInSubTxt").innerHTML 	= productPopInSubtitles[thisProduct].childNodes[0].nodeValue;
	document.getElementById("priceLink").href 			= productPopInAddToCartLinks[thisProduct].childNodes[0].nodeValue;
	//correction for price is blank ash 9-16-07
	if (productPopInPrices[thisProduct].childNodes[0]!=null){
		document.getElementById("price_span").innerHTML 	= productPopInPrices[thisProduct].childNodes[0].nodeValue;
	
	}else{
		
		document.getElementById("price_span").innerHTML="";
	}
	if (productPopInDiscounts[thisProduct].childNodes[0])
	{
		document.getElementById("price_span").innerHTML += "&nbsp;<font color='#ff0000'>SAVE " + productPopInDiscounts[thisProduct].childNodes[0].nodeValue + "!</font>";
	}
	
	// 2007.02.15 KJD: Put these into variables instead of writting directly to page
	var ProductFeatures 			= "";
	var ProductSystemRequirements 	= "";
	var ProductPlatforms 			= "";
	var ProductKeyFeatures			= "";
	
	var showProducts				= new Array();

	
	var ProductKeyFeaturesBlock = "<h6><DIV STYLE='margin-right:30px;' ID='popin_title_keyfeatures'>" 
								+ "####FeaturesTitle#### ####ProductTitle####"
								+ "</DIV></h6>"
								+ "<ul class='features' id='popin_ftrs'>"
								+ "####ProductFeatureList####"
								+ "</ul>"
								+ "<a id='popin_learnmore_link' class='learn-more' href='####LearnMoreLink####'>" + LearnMoreLinkText + "&#155;</a>";

	var ProductSystemRequirementsBlock = "<h6><DIV STYLE='display:inline' ID='popin_title_systemrequirements'>"
								+ "####SystemRequirementsTitle#### ####ProductTitle####"
								+ "</DIV></h6>"
								+ "<ul class='features' id='popin_sysreqs'>"
								+ "####SystemRequirementsList####"
								+ "</ul>"
								+ "<DIV><a href='####SystemRequirementsLink####' CLASS='learn-more'>" + SystemRequirementsText + "&#155;</a></DIV>";
	
	// 2007.04.23 KJD: Added for bundles price
	var ProductDisclaimerBlock = "";
	try
	{
		ProductDisclaimerBlock = ""
				+ "<br /><SPAN CLASS='disclaimer'>"
				+ productPopInDiscountNotes[ thisProduct ].childNodes[0].nodeValue
				+ "</SPAN>";
	}
	catch( e ){}
				
	if( ProductType( productID ) == "Bundle" )
	{
		// Get product features of each product in bundle
		showProducts = getProductsInBundle( productID );
	}
	else
	{
		// 2007.02.15 KJD: Single product
		showProducts[0] = productID;
	}
		
	for( var i=0; i < showProducts.length; i++ )
	{
		
		var thisProductName 		= ProductValue( showProducts[i], "name" );
		
		// 2007.02.15 KJD: Added for Key Features
		var thisProductFeatures 	= "<LI>" + PopinProductItems( showProducts[i], "pop_in_feature" ).join("<li>");
		ProductKeyFeatures		+= ProductKeyFeaturesBlock;
		ProductKeyFeatures 		= ProductKeyFeatures.replace( "####FeaturesTitle####", 		title_KeyFeatures );
		ProductKeyFeatures 		= ProductKeyFeatures.replace( "####ProductTitle####", 		thisProductName );
		ProductKeyFeatures 		= ProductKeyFeatures.replace( "####ProductFeatureList####", thisProductFeatures );
		ProductKeyFeatures 		= ProductKeyFeatures.replace( "####LearnMoreLink####", 		ProductValue( showProducts[i], "pop_in_learn_more" ) );
		
		// 2007.02.15 KJD: Added for System Requirements
		var thisProdRequirements 	= PopinProductItems( showProducts[i], "requirement_item" );
		var thisProdPlatforms		= PopinProductItems( showProducts[i], "sup_platform" );
		var thisRequirements 		= "";
		var thisPlatforms 			= "";
		
		if( thisProdPlatforms.length )
		{
			thisRequirements += "<LI>" + thisProdPlatforms.join("<li>");
		}
		
		if( thisProdRequirements.length )
		{
			thisRequirements += "<LI>" + thisProdRequirements.join("<li>");
		}
		

		
		ProductSystemRequirements 	+= ProductSystemRequirementsBlock;
		ProductSystemRequirements	= ProductSystemRequirements.replace( "####SystemRequirementsTitle####", 	title_SystemRequirements );
		ProductSystemRequirements 	= ProductSystemRequirements.replace( "####ProductTitle####", 				thisProductName );
		ProductSystemRequirements 	= ProductSystemRequirements.replace( "####SystemRequirementsList####", 		thisRequirements );
		ProductSystemRequirements 	= ProductSystemRequirements.replace( "####SystemRequirementsLink####", 		ProductValue( showProducts[i], "system_requirements_link" ) );
	}
		


	document.getElementById("popin").style.display 			= "block";
	
	// 2007.02.15 KJD: Popin Feature elements
	document.getElementById("popin_featureelements").innerHTML = ""
		+  ProductKeyFeatures
		+ "<div class='horiz-divider'>"
		+ ProductSystemRequirements
		+ "<h7 id='popin_prod_name'></h7>"
		+ ProductDisclaimerBlock
		+ "</div>";	
	
}

function closePopin()
{
	DoMask( 'popin', 'hidden' );
}


// 2007.02.16 KJD: Create a mask
function DoMask( fadeitem, maskaction )
{

	var element2 = document.getElementById( fadeitem );

		
	if( maskaction == 'visible' )
	{
		document.getElementById( "maskdiv_" + fadeitem ).style.visibility = maskaction;
		
		if( fadeitem == 'compareTable' )
		{
			document.getElementById( fadeitem ).style.display = 'block';
		}
	
		document.getElementById( fadeitem ).style.visibility = maskaction;
	
		// 2007.02.14 KJD: Fade-in
		DoFade( 'in', fadeitem );
	}
	else
	{
		// 2007.02.14 KJD: Fade-out
		DoFade( 'out', fadeitem );
		
		if( fadeitem == 'compareTable' )
		{
			setTimeout(function() { document.getElementById( fadeitem ).style.display = 'none'; }, 250);
			setTimeout(function() { clearCompareTable(0); }, 275);
		}

		setTimeout(function() { document.getElementById( "maskdiv_" + fadeitem ).style.visibility 	= "hidden"; }, 300);

		setTimeout(function() { document.getElementById( fadeitem ).style.visibility 	= "hidden"; }, 325);
	}
}

// 2007.02.21 KJD: When clicked on mask layer
function MaskClick()
{
	// 2007.02.21 KJD: If the popin is open, else if compare table open, close it
	if( document.getElementById( 'popin' ).style.visibility == 'visible' )
	{
		closePopin();
	}
	else if( document.getElementById( 'compareTable' ).style.visibility == 'visible' )
	{
		CloseComparison();
	}

}


// stole some code from ITM

var ABMnewCount_itm 				= 0;

var ABMvisibilityTimeoutId_itm 		= null;

var ABMopacityTimeoutId1_itm 		= null;
var ABMopacityTimeoutId2_itm 		= null;
var ABMopacityTimeoutId3_itm 		= null;
var ABMopacityTimeoutId4_itm 		= null;
var ABMopacityTimeoutId5_itm 		= null;
var ABMopacityTimeoutId6_itm 		= null;
var ABMopacityTimeoutId7_itm 		= null;
var ABMopacityTimeoutId8_itm 		= null;
var ABMopacityTimeoutId9_itm 		= null;

var ABMnewOpacityLevel_itm 		= 0;

function ABMsetOpacity_itm(element2, ABMnewCount_itm)
{
	ABMnewOpacityLevel_itm = ABMnewCount_itm;

	if(document.all){
		element2.style.filter = "alpha(opacity=" + ( 100 * ABMnewCount_itm ) + ")";
		
			
	}else if(document.getElementById){
    	element2.style.opacity = ABMnewCount_itm;
	}
}

// 2007.02.20 KJD: Fade in
function DoFade( fadeaction, itemname )
{
	var element2 = document.getElementById( itemname );

	
	if( fadeaction == 'in' )
	{
		ABMsetOpacity_itm(element2, .01);
		
		ABMopacityTimeoutId1_itm = setTimeout(function() { ABMsetOpacity_itm(element2, .15); }, 10	);
		ABMopacityTimeoutId3_itm = setTimeout(function() { ABMsetOpacity_itm(element2, .35); }, 50	);
		ABMopacityTimeoutId4_itm = setTimeout(function() { ABMsetOpacity_itm(element2, .45); }, 75	);
		ABMopacityTimeoutId5_itm = setTimeout(function() { ABMsetOpacity_itm(element2, .55); }, 100	);
		ABMopacityTimeoutId6_itm = setTimeout(function() { ABMsetOpacity_itm(element2, .65); }, 125	);
		ABMopacityTimeoutId7_itm = setTimeout(function() { ABMsetOpacity_itm(element2, .75); }, 150	);
		ABMopacityTimeoutId9_itm = setTimeout(function() { ABMsetOpacity_itm(element2, .99); }, 200	);
	}
	if( fadeaction == 'infast' )
	{
		ABMsetOpacity_itm(element2, .01);
		
		ABMopacityTimeoutId1_itm = setTimeout(function() { ABMsetOpacity_itm(element2, .15); }, 10);
		ABMopacityTimeoutId3_itm = setTimeout(function() { ABMsetOpacity_itm(element2, .35); }, 25);
		ABMopacityTimeoutId5_itm = setTimeout(function() { ABMsetOpacity_itm(element2, .55); }, 50);
		ABMopacityTimeoutId7_itm = setTimeout(function() { ABMsetOpacity_itm(element2, .75); }, 75);
		ABMopacityTimeoutId9_itm = setTimeout(function() { ABMsetOpacity_itm(element2, .99); }, 100);
	}
	else if( fadeaction == 'out' )
	{
		ABMopacityTimeoutId9_itm = setTimeout(function() { ABMsetOpacity_itm(element2, .99); }, 10	);
		ABMopacityTimeoutId7_itm = setTimeout(function() { ABMsetOpacity_itm(element2, .75); }, 50	);
		ABMopacityTimeoutId6_itm = setTimeout(function() { ABMsetOpacity_itm(element2, .65); }, 75	);
		ABMopacityTimeoutId5_itm = setTimeout(function() { ABMsetOpacity_itm(element2, .55); }, 100	);
		ABMopacityTimeoutId4_itm = setTimeout(function() { ABMsetOpacity_itm(element2, .45); }, 125	);
		ABMopacityTimeoutId3_itm = setTimeout(function() { ABMsetOpacity_itm(element2, .35); }, 150	);
		ABMopacityTimeoutId2_itm = setTimeout(function() { ABMsetOpacity_itm(element2, .25); }, 175	);
		ABMopacityTimeoutId1_itm = setTimeout(function() { ABMsetOpacity_itm(element2, .05); }, 225	);
	}
	else if( fadeaction == 'outfast' )
	{
		ABMopacityTimeoutId9_itm = setTimeout(function() { ABMsetOpacity_itm(element2, .99); }, 10);
		ABMopacityTimeoutId7_itm = setTimeout(function() { ABMsetOpacity_itm(element2, .75); }, 25);
		ABMopacityTimeoutId5_itm = setTimeout(function() { ABMsetOpacity_itm(element2, .55); }, 50);
		ABMopacityTimeoutId3_itm = setTimeout(function() { ABMsetOpacity_itm(element2, .35); }, 75);
		ABMopacityTimeoutId1_itm = setTimeout(function() { ABMsetOpacity_itm(element2, .01); }, 100);
	}	
}

