/* MISC FUNCTIONS */
function doUnload(webpath, cmpy_cd) {
	if (event.clientY < 0) {
		window.open(webpath + 'form_templates/exit_survey.cfm?cmpy_cd=' + cmpy_cd, 'exit_survey', 'height=400,width=400,scrollbars=yes,location=no,status=no,resizeable=no');
	}
}

function hideSubs() {
	document.getElementById("curriculum_rollover").style.display='none';
	document.getElementById("assessment_rollover").style.display='none';
	document.getElementById("se_info_rollover").style.display='none';
	document.getElementById("ed_learning_rollover").style.display='none';
	document.getElementById("fam_learning_rollover").style.display='none';
	document.getElementById("curriculum_early_rollover").style.display='none';
	document.getElementById("curriculum_elem_rollover").style.display='none';
	document.getElementById("curriculum_second_rollover").style.display='none';
	document.getElementById("assessment_early_rollover").style.display='none';
	document.getElementById("assessment_individual_rollover").style.display='none';
	document.getElementById("ed_professional_rollover").style.display='none';
}

function showSub(subname) {
	document.getElementById(subname + "_rollover").style.display='block';
}

function checkMouse(e) {
	if (!e) var e = window.event;
	var tg = (window.event) ? e.srcElement : e.target;
	if (tg.nodeName != 'DIV') return;
	var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
	while (reltg != tg && reltg.nodeName != 'BODY')
		reltg= reltg.parentNode
	if (reltg== tg) return;

	hideSubs();
}

function hideSelect()
{if (document.all){document.all.searchpageselect.style.visibility="hidden";}}

function unhideSelect()
{if (document.all){document.all.searchpageselect.style.visibility="visible";}}


/* Used by Main Navigation drop downs to simulate Hover on an A tag */
sfHover = function() {

	var sfEls = document.getElementById("nav").getElementsByTagName("LI");	
	for (var i=0; i<sfEls.length; i++) {	
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}			
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

//if (window.attachEvent) window.attachEvent("onload", sfHover);


/* IMAGE RELATED CODE */

/* Exchanges Broken images with a hidden alternate and Switches the blank image to a missing image image - Used with PMDb */
function UpdateBrokenImages(img, imgAlt) {

	if(imgAlt) {
		img.hide();
		imgAlt.show();
	}

	img.src = '/live/images/imgNAThumb.gif';

	/* Suppress any further onerror errors if the missing image isn't available */
	img.onerror=null;
}



/* PRODUCT RELATED CODE */

// Used to open and close product descriptions.
function descriptionUpDown(obj) {

	Effect.toggle(obj, 'slide', {duration:0.5, queue: {position:'end', scope: 'eventDropDown', limit:3}});
}



// Used to filter the component product list.
function ProductFilter() {

	this.productFilterList = new Array(); // Contains the classes of all the filters we want to see

	this.toggleFilter = function(criteria) {



		// Loop through filters, to see if the new filter has already been selected or not.

		var foundCriteria = false;

		var criteriaIndex = "";



		for(var i = 0; i < this.productFilterList.length; i++) {

				// If filter is in array, then remember where.

				if (this.productFilterList[i] == criteria) {

					foundCriteria = true;
					criteriaIndex = i;

				}

		}

		// If filter already in array, remove it.

		if(foundCriteria) {

			this.productFilterList.splice(criteriaIndex,1);

			$(criteria).removeClassName('selectedFilter');

		// Else add filter to array.

		} else {

			this.productFilterList.push(criteria);

			$(criteria).addClassName('selectedFilter');

		}


		// If no filters chosen, then show all products.

		if (this.productFilterList.length == 0) {

			// Show all products

			var arrayOfProducts = $$('.prodFilters');

			for(var i = 0; i < arrayOfProducts.length; i++) {

					arrayOfProducts[i].show();

			}

		// Else hide all products, then show the ones with the selected filters.

		} else {

			// Hide all products

			var arrayOfProducts = $$('.prodFilters');

			for(var i = 0; i < arrayOfProducts.length; i++) {

					arrayOfProducts[i].hide();

			}

			// Show selected products

			for(var i = 0; i < this.productFilterList.length; i++) {

				var arrayOfProducts = $$('.' + this.productFilterList[i]);

				for(var j = 0; j < arrayOfProducts.length; j++) {

						arrayOfProducts[j].show();

				}

			}

		}


		return false;

	}
}