

/* ANSO ADVANTAGE 2009 - BASIC SITE JAVASCRIPT (sitescripts.js) - 
   this file contains basic site JavaScript and is included on all pages. 
   Now that popup menus are done with Superfish, only init call for menus
   is needed here. */


// init for all pages except index, called when ready. requires jQuery.
$(document).ready(function(){
	// doc is ready for any init calls, init popup menu:
	
	// initialize popup-menu - call supersubs first, then superfish, so that subs are 
    // not display:none when measuring. Call before initialising 
    // containing tabs for same reason. 
	$("ul.sf-menu").supersubs({ 
        minWidth:    12,   // minimum width of sub-menus in em units 
        maxWidth:    18,   // maximum width of sub-menus in em units 
        extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
                           // due to slight rounding differences and font-family 
    }).superfish({ 
        animation: {height:'show'},   // slide-down effect without fade-in 
        delay:     500                // delay on mouseout 
    }); 

	// if needed (tokens were passed in url, ie for VSpider), add tokens to all links on page
	try {
		if (addtokens) 
			// tokens were set (as flag above) in JS written by CF function WriteVspiderJS() at top of page head tag
			addTokensToLinks(cfid, cftoken);
	} catch(e) {
		
	}
	
});	


/* DMS added 3-12-10 - ajax/modal related functions to control opacity and display -
 * 	NOTE: need to update opacity checks for IE8 (thanks MS)
 */
	function setElementOpacity(obj, opacity) {
		// update opacity of element as requested. probably really only need the first and last versions,
		// but keeping the middle two in just to help some older browsers. 
		
		opacity = (opacity == 100)?99.999:opacity;
		  
		// IE/Win
		obj.style.filter = "alpha(opacity:"+opacity+")";
		  
		// Safari<1.2, Konqueror
		obj.style.KHTMLOpacity = opacity/100;
		  
		// Older Mozilla and Firefox
		obj.style.MozOpacity = opacity/100;
		 
		// Safari 1.2, newer Firefox and Mozilla, CSS3
		obj.style.opacity = opacity/100;
	}
	
	function getElementOpacity(obj) {
		// try to retrive current opacity value of this object. if undefined, probably has not been set, so 
		// just return 1 (100%) which is effectively the value.

		var opacity = null;
		if (obj.filters) {
			opacity = obj.style.opacity;
		}
		else if (obj.style) {
			opacity = obj.style.opacity;
		} 
		if (opacity == null)
			opacity = 1;
		
		//alert('opacity = ' + opacity.toString());
		return opacity;
	}	
	
	function setElementDisplay (obj, mode) {
		// update display of element requested
		if (document.getElementsByTagName && document.getElementById) {
			//Netscape 6+ model (also works in IE 6)
			document.getElementById(obj).style.display = mode;
		} else {
			if (document.all) {
				//IE model (at least, versions prior to 6)
				document.all(obj).style.display = mode;
			}	
		}		
	}	



	function addTokensToLinks(cfid, cftoken) {
		// this utility function will add CF tokens passed in to all links on a page
		// for use with verity spider (which does not seem to support cookies and therefore does not maintain sessions)
		
		// should return all elements that are links to a CF page with query parameters
		var linksQuery = $("a[href*=cfm?]");
		// should return all elements that are links to a CF page with no query string (href ends in 'cfm')
		var linksNoQuery = $("a[href$=cfm]");
		
		// add CF tokens to all query-strung links as additional query parameters
		$.each(linksQuery, function(){
			$(this).attr("href", $(this).attr("href") + "&CFID=" + cfid + "&CFTOKEN=" + cftoken);
		});
	
		// add CF tokens to all basic no-query links as first query parameters
		$.each(linksNoQuery, function(){
			$(this).attr("href", $(this).attr("href") + "?CFID=" + cfid + "&CFTOKEN=" + cftoken);
		});
		
		//debugger;
	}
	
	
	/* DMS 3-12-10 - no longer used with CSS menu scheme
	function RollOffMenu(imgName) {
		//before calling roll off function for this nav graphic, see if corresponding
		//menu is open. if so, don't roll off.
		var uspos, basestr, menunm;
		var stat = null;
		
		if (imgName.length > 0) {
			//this is corresponding level one menu name, see if it is visible
			menunm = "menublock_" + imgName;
		    if (document.getElementsByTagName && document.getElementById) {
				//Netscape 6+ model (also works in IE 6)
				stat = document.getElementById(menunm).style.visibility;
		    } else {
		    	if (document.all) {
					//IE model (at least, versions prior to 6)
					stat = document.all(menunm).style.visibility;	
				}	
			}	
			if (stat != "visible")
				RollOffBasic(imgName);		
		}
	}
	*/
	   
	function RollOnBasic(imgName) {
		if (document.images){
			imgFileName = "";
			imgOld = document.images[imgName].src;
			dotPos = imgOld.lastIndexOf('.');
			imgExt = imgOld.substring(dotPos+1, dotPos+4); 
			imgFileName = imgOld.substring(0, imgOld.lastIndexOf('_'));
			imgFileName = imgFileName + "_2." + imgExt;
			document.images[imgName].src = imgFileName;
		}
	}
	
	function RollOffBasic(imgName) {
		if (document.images){
			imgFileName = "";
			imgOld = document.images[imgName].src;
			dotPos = imgOld.lastIndexOf('.');
			imgExt = imgOld.substring(dotPos+1, dotPos+4); 
			imgFileName = imgOld.substring(0, imgOld.lastIndexOf('_'));
			imgFileName = imgFileName + "_1." + imgExt;
			document.images[imgName].src = imgFileName;
		}
	}
	
	function openHelp(path_maindir){
		var wURL, wAttrs;
	
		wURL = path_maindir + "/help/helpcenter.html";
		wAttrs = "height=464,width=620,resizable=no,scrollbars=no,status=no,toolbar=no,location=no";
		window.open(wURL, "", wAttrs);
		window.focus;
	}
	
	function hideOrShowItem (obj, stat) {
		var vis;
		if (stat == 1) {
			vis = "visible";
			lastVisDiv = obj;
		} else {
			vis = "hidden";
			lastVisDiv = "";
		}
		if (document.getElementsByTagName && document.getElementById) {
			//Netscape 6+ model (also works in IE 6)
			document.getElementById(obj).style.visibility = vis;
		} else {
			if (document.all) {
				//IE model (at least, versions prior to 6)
				document.all(obj).style.visibility = vis;	
			}	
		}
	}
	
	function toggleFldMode(obj, basenm) {
		var stat = null;
		var setstyl = null;
		var fldid;
		
		fldid = obj + '_id';
		//toggle mode from whatever it is now, so need to check current status
		if (document.getElementsByTagName && document.getElementById) {
			//Netscape 6+ model (also works in IE 6)
			stat = document.getElementById(obj).style.visibility;
		} else {
			if (document.all) {
				//IE model (at least, versions prior to 6)
				stat = document.all(obj).style.visibility;	
			}	
		}
				
		//set to opposite of current status
		if (stat == 'visible')
			setstyl = 'hidden';
		else
			setstyl = 'visible';
					
		//now set mode of object	
		if (document.getElementsByTagName && document.getElementById) {
			//Netscape 6+ model (also works in IE 6)
			document.getElementById(obj).style.visibility = setstyl;
			//disable the field if hidden, so only one field passed
			if (setstyl == 'hidden')
				document.getElementById(fldid).disabled = true;
			else
				document.getElementById(fldid).disabled = false;
		} else {
			if (document.all) {
				//IE model (at least, versions prior to 6)
				document.all(obj).style.visibility = setstyl;
				//disable the field if hidden, so only one field passed
				if (setstyl == 'hidden')
					document.all(fldid).disabled = true;
				else
					document.all(fldid).disabled = false;	
			}
		}
		return setstyl;	
	}	
	
	function updateText(obj, str) {
		// update text of element requested - this is for debugging popup script above
		var str;
		str = str + "<br>" + getElementText(obj);
		setElementText (obj, str);
	}
	
	function setElementText (obj, str) {
		// update HTML of element requested
		if (document.getElementsByTagName && document.getElementById) {
			//Netscape 6+ model (also works in IE 6)
			document.getElementById(obj).innerHTML = str;
		} else {
			if (document.all) {
				//IE model (at least, versions prior to 6)
				document.all(obj).innerHTML = str;	
			}	
		}		
	}	
	
	function getElementText (obj) {
		// get HTML of element requested
		var str;
		if (document.getElementsByTagName && document.getElementById) {
			//Netscape 6+ model (also works in IE 6)
			str = document.getElementById(obj).innerHTML;
		} else {
			if (document.all) {
				//IE model (at least, versions prior to 6)
				str = document.all(obj).innerHTML;	
			}	
		}	
		return str;
	}	
	
	function setElementBkgdColor (obj, clr) {
		// update background-color of element requested
		if (document.getElementsByTagName && document.getElementById) {
			//Netscape 6+ model (also works in IE 6)
			document.getElementById(obj).style.backgroundColor = clr;
		} else {
			if (document.all) {
				//IE model (at least, versions prior to 6)
				document.all(obj).style.backgroundColor = clr;	
			}	
		}		
	}	
	
	function setElementColor (obj, clr) {
		// update background-color of element requested
		if (document.getElementsByTagName && document.getElementById) {
			//Netscape 6+ model (also works in IE 6)
			document.getElementById(obj).style.color = clr;
		} else {
			if (document.all) {
				//IE model (at least, versions prior to 6)
				document.all(obj).style.color = clr;	
			}	
		}		
	}
	
	// *** DMS 5-12-06: pasted in Sarah's IE active content kluge:
	// this function lets javascript output the necessary Flash object and embed tags
	// to workaround IE 6's new 'active content' security warnings 
	// *** DMS 5-13-06: added width & height params so can use for Help or other Flash content as well
	function RunFlash(flashfile, flashW, flashH) {
	   document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab##version=6,0,0,0" width="' + flashW + '" height="' + flashH + '">\n');
	    document.write(' <param name=movie value="' + flashfile + '" />\n');
		document.write(' <param name=quality value=high />\n');
		document.write(' <embed src="' + flashfile + '" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="' + flashW + '" height="' + flashH + '">\n');
		document.write('</embed>\n');
	    document.write('</object>\n');
	}	
		
	