/** =============================================================== IEhM UTILITIES v1.0 Copyright (c) 2008,2009 Jason Fries, Iowa Electronic health Markets, http://iehm.uiowa.edu/iehm/index.html University of Iowa dependancies: Tween.js OpacityTween.js Sequence.js description: Various commonly used functions revisions: 2009.05.20 first release =============================================================== **/ /** ====================================== COLORS ====================================== **/ //for hotspot markets where we are unable to specify per contract colors //color scheme from the online application ColorBrewer //http://www.personal.psu.edu/cab38/ColorBrewer/ColorBrewer.html var qual12ClassColors = [0x8dd3c7,0xffffbc,0xbebada,0xfb8072,0x80b1d3,0xfdb462,0xb3de69,0xfccde5,0xd9d9d9,0xbc80bd,0xccebc5,0xffed6f ]; var qual10ClassColors = [0xf7a673,0x9cc3a5,0x523000,0xc65d00,0xe7dfed,0x92b431,0xadd7ce,0x31615a,0xbdb221,0xefb629]; /** ====================================== SORTING FUNCTIONS ====================================== **/ /** * Sort Predictions By Value */ function sortByPrediction( a, b ){ if( a.prediction == b.prediction ) return 0; if( a.prediction > b.prediction ) return -1; if (a.prediction < b.prediction ) return 1; return 0; } /** ====================================== ANIMATION EFFECTS ====================================== **/ /** * Number Tween * @description */ function numberTween( element, start, end, format ) { if(!format) format = "integer"; var tween = new Tween(new Object(),'xyz' + Math.random() ,Tween.regularEaseIn, start, end, 1); tween.onMotionChanged = function(event) { var v = parseFloat(event.target._pos); v = v.toFixed(2); if (format == "dollars") { if(element.innerHTML) element.innerHTML = "$" + v; if(element.nodeValue) element.nodeValue = "$" + v; }else if( format == "cents" ){ // element.innerHTML = parseInt(event.target._pos) + "ยข"; //assume integer number }else{ // element.innerHTML = parseInt(event.target._pos); } }; tween.start(); } /** * Hide/Show Help Screen Animation */ function playHideShowAnimation( target, start, end ) { var helpAnimation = new Tween(target.style,'height',Tween.regularEaseOut,start,end,0.55,'px'); helpAnimation.onMotionFinished = function(){ // target.style.height = end + "px"; }; helpAnimation.start(); } /** ====================================== COLOR TOOLS ====================================== **/ /** * CSS Style declaration to Hex * @description Javascript style.color member variable access returns * color in this format. Convert to hex for calculations */ function rgbStyleToHex( value ) { value = value.replace("rgb(", ""); value = value.replace(")", ""); var rgb = value.split(","); return "0x" + getHexTriple( rgbToHex(rgb[0], rgb[1], rgb[2]) ); } /** * Converts RGB elements to a hex value * * @param red int * @param green int * @param blue int * @return RGB hex number int */ function rgbToHex(r, g, b) { return (r<<16 | g<<8 | b); } /** * Converts Hex color to RGB components * * from: http://snippets.dzone.com/posts/show/214 */ function hexToRGB( hexColor ){ var c = { r:0, g:0, b:0 }; c.r = hexColor >> 16; var temp = hexColor ^ c.r << 16; c.g = temp >> 8; c.b = temp ^ c.g << 8; return c; } /** Format int for CSS style declarations (basically we pad zeros if need be) */ function getHexTriple(number) { var s= "000000" + number.toString(16); return s.substring(s.length - 6); // keep the rightmost 6 characters } function accentColor( c, darkness ) { //determine accent color var color = hexToRGB(c); return rgbToHex( color.r * darkness, color.g * darkness, color.b * darkness ); } /** * Clear Value for Form Element */ function clearInput( elementID ) { element(elementID).value = ""; } function createShadedIcon( color, height, imgPath ) { if(!height) height = "30px"; else height += "px"; var icon = document.createElement("IMG"); icon.style.height = height; icon.style.border = "1px solid #606060"; icon.style.backgroundColor = "#" + getHexTriple(color); icon.style.MozBorderRadius = "4px"; icon.style.WebkitBorderRadius = "4px"; if(imgPath != null) icon.setAttribute("src", imgPath ); else icon.setAttribute("src", "" ); icon.style.padding = "0px"; icon.style.margin = "0px"; return icon; } function createRSSFeedLink( feedURL ) { var a = document.createElement("A"); a.setAttribute("id", InformationTab.RSS_FEED_URL_ID); a.setAttribute("class", "headerLink"); a.setAttribute("className", "headerLink"); a.setAttribute("href", feedURL ); a.style.textDecoration = "none"; a.style["styleFloat"] = "right"; a.style["cssFloat"] = "right"; var img = document.createElement("IMG"); img.setAttribute("src", TabManager.IMG_ROOT + "feed-icon-20x20.png"); img.style["styleFloat"] = "right"; img.style["cssFloat"] = "right"; img.style.paddingRight = "5px"; img.style.paddingTop = "1px"; a.appendChild(document.createTextNode(" RSS") ); return [a,img]; } function createFilterPanel( controls ) { var panel = document.createElement("DIV"); panel.setAttribute("class", "filterPanel"); panel.setAttribute("className", "filterPanel"); //create optional buttons if(controls != null){ var bContainer = document.createElement("DIV"); bContainer.setAttribute("class","buttonContainer"); bContainer.setAttribute("className","buttonContainer"); for(var i=0; i