
  function MM_swapImgRestore() { //v3.0
    var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
  }

  function MM_preloadImages() { //v3.0
    var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
  }

  function MM_findObj(n, d) { //v4.01
    var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
      d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
    if(!x && d.getElementById) x=d.getElementById(n); return x;
  }

  function MM_swapImage() { //v3.0
    var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
     if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
  }

  function toggleBorder(obj, color) {
    obj.style.border = color + ' 1px solid';
  }

  function popup(url, name, width, height) {
    wleft = (screen.width - width) / 2;
    wtop = (screen.height - height) / 2;
		var settings = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width="
                   + width + ",height=" + height + ',left=' + wleft + ',top=' + wtop; 
		window.open(url, name, settings);
	}

  function cleanFloat(obj) {
    num = obj.value;
    num = num.toString().replace(/\,/g,'');
    if (isNaN(num)) {
      num = "0";
    }
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num * 100 + 0.50000000001);
    dec = num % 100;
    num = Math.floor(num / 100).toString();
    if (dec < 10) {
      dec = "0" + dec;
    }
    return parseFloat((((sign)?'':'-') + num + '.' + dec));
  }

  function formatNumber(obj) {
    num = obj.value;
    num = num.toString().replace(/\,/g,'');
    if (isNaN(num)) {
      num = "0";
    }
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num * 100 + 0.50000000001);
    num = Math.floor(num / 100).toString();
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) {
      num = num.substring(0, num.length - (4 * i + 3)) + ',' + num.substring(num.length - (4 * i + 3));
    }
    obj.value = (((sign)?'':'-') + num);
  }

  function formatCurrency(obj) {
    num = obj.value;
    num = num.toString().replace(/\$|\,/g,'');
    if (isNaN(num)) {
      num = "0";
    }
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num * 100 + 0.50000000001);
    cents = num % 100;
    num = Math.floor(num / 100).toString();
    if (cents < 10) {
      cents = "0" + cents;
    }
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) {
      num = num.substring(0, num.length - (4 * i + 3)) + ',' + num.substring(num.length - (4 * i + 3));
    }
    obj.value = (((sign)?'':'-') + '$' + num + '.' + cents);
  }

  function formatFloat(obj) {
    num = obj.value;
    num = num.toString().replace(/\,/g,'');
    if (isNaN(num)) {
      num = "0";
    }
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num * 100 + 0.50000000001);
    dec = num % 100;
    num = Math.floor(num / 100).toString();
    if (dec < 10) {
      dec = "0" + dec;
    }
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) {
      num = num.substring(0, num.length - (4 * i + 3)) + ',' + num.substring(num.length - (4 * i + 3));
    }
    obj.value = (((sign)?'':'-') + num + '.' + dec);
  }

  function formatPercentage(obj) {
    num = obj.value;
    num = num.toString().replace(/\%|\,/g,'');
    if (isNaN(num)) {
      num = "0";
    }
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num * 100 + 0.50000000001);
    dec = num % 100;
    num = Math.floor(num / 100).toString();
    if (dec < 10) {
      dec = "0" + dec;
    }
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) {
      num = num.substring(0, num.length - (4 * i + 3)) + ',' + num.substring(num.length - (4 * i + 3));
    }
    obj.value = (((sign)?'':'-') + num + '.' + dec + '%');
  }

  function urlEncode(sStr) {
    return escape(sStr).replace(/\+/g, '%2B').replace(/\"/g,'%22').replace(/\'/g, '%27').replace(/\//g,'%2F');
  }

  function SetCookie(cookieName,cookieValue,nDays) {
    var today = new Date();
    var expire = new Date();
    if (nDays==null || nDays==0) nDays=1;
    expire.setTime(today.getTime() + 3600000*24*nDays);
    document.cookie = cookieName+"="+escape(cookieValue)+ ";expires="+expire.toGMTString();
  }

	function ValidateColor(string) {
		string = string || '';
		string = string + "";
		string = string.toUpperCase();
		var chars = '0123456789ABCDEF';
		var out   = '';
		for (var i=0; i<string.length; i++) {
			var schar = string.charAt(i);
			if (chars.indexOf(schar) != -1) {
				out += schar;
			}
		}
		if (out.length != 6) {
			return null;
		}
		return out;
	}

	function updateColorSample(txtid, sampleid) {
		var color = ValidateColor(document.getElementById(txtid).value);
		if (color != null) {
			document.getElementById(sampleid).style.backgroundColor = '#' + color;
		}
	}

  function loadMap(elementid, streetaddress, cityaddress, locationname) {
    if (GBrowserIsCompatible()) {
      var map = new GMap2(document.getElementById(elementid));
      map.addControl(new GSmallMapControl());
      map.addControl(new GMapTypeControl());      
      geocoder = new GClientGeocoder();
      geocoder.getLatLng(
        streetaddress,
        function(point) {
          if (point) {
            map.setCenter(point, 13);
            var marker = new GMarker(point);
            map.addOverlay(marker);
            //marker.openInfoWindowHtml("<h3>" + locationname + "</h3><br>" + streetaddress);
          } else {
              geocoder.getLatLng(
                cityaddress,
                function(point) {
                  if (point) {
                    map.setCenter(point, 9);
                    var marker = new GMarker(point);
                    map.addOverlay(marker);
                    //marker.openInfoWindowHtml("<h3>" + locationname + "</h3><br>" + cityaddress);
                  }/* else {
                    document.getElementById(elementid).style.display = "none";
                  }*/
                }
              );
          }
        }
      );
    }
  }

  function loadMenuHover() {

    // Set the hovers for the list items
    var offset = 0;
    if (((navigator.appVersion.indexOf('MSIE') > 0) && (navigator.userAgent.indexOf('Opera') < 0))) {
      var sfEls = document.getElementById("dropdownnav").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"), "");
        }
      }
      offset = 2;
    }

    // Set the lists
    var ulEls = document.getElementById("dropdownnav").getElementsByTagName("UL");
    for (var i=0; i<ulEls.length; i++) {
      if ((ulEls[i].parentNode.className == "dropdownnavparent") || (ulEls[i].parentNode.className == "dropdownnavparent last")) {
        var obj = ulEls[i].parentNode;
        var max = 0;
        do {
          if (obj.firstChild != null) {
            if (obj.firstChild.offsetWidth > max) {
              max = obj.firstChild.offsetWidth;
            }
          }
          obj = obj.nextSibling;
        } while (obj != null);
        ulEls[i].style.margin = "-" + (ulEls[i].parentNode.offsetHeight - offset).toString() + "px 0px 0px " + max.toString() + "px";
      }
    }
  }

  function initInnovaStudioEditor(oEditor, elementid, height, css_path, customtags, features) {
    oEditor.height = height;
    oEditor.css = css_path;
    oEditor.useDIV = false;
    oEditor.useBR = true;
    if (customtags != null) {
      oEditor.arrCustomTag = customtags;
      oEditor.features = ["Search","PasteWord","|","Undo","Redo","|",
                          "ForeColor","BackColor","|","Hyperlink","Image","Flash","Media","|",
                          "Characters","Line","Form","Table","Guidelines","Absolute","|","CustomTag","XHTMLSource","BRK",
                          "StyleAndFormatting","TextFormatting","ListFormatting","BoxFormatting",
                          "ParagraphFormatting","|",
                          "Paragraph","FontName","FontSize","|",
                          "Bold","Italic","Underline","Strikethrough","|",
                          "JustifyLeft","JustifyCenter","JustifyRight","JustifyFull","|",
                          "Numbering","Bullets","|","Indent","Outdent","BRK"];
    } else {
      if (features != null) {
        oEditor.features = features;
      } else {
      oEditor.features = ["Search","PasteWord","|","Undo","Redo","|",
                          "ForeColor","BackColor","|","Hyperlink","Image","Flash","Media","|",
                          "Characters","Line","Form","Table","Guidelines","Absolute","|","XHTMLSource","BRK",
                          "StyleAndFormatting","TextFormatting","ListFormatting","BoxFormatting",
                          "ParagraphFormatting","|",
                          "Paragraph","FontName","FontSize","|",
                          "Bold","Italic","Underline","Strikethrough","|",
                          "JustifyLeft","JustifyCenter","JustifyRight","JustifyFull","|",
                          "Numbering","Bullets","|","Indent","Outdent","BRK"];
      }
    }
    
    //oEditor.publishingPath = "";
    oEditor.initialRefresh = true;
    oEditor.REPLACE(elementid);
  }

  function limitWordCount(theEditFieldID, theLimit) {
    var theEditField = document.getElementById(theEditFieldID);
    var char_count = theEditField.value.length;
    var fullStr = theEditField.value + " ";
    var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
    var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
    var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9.!]+/gi;
    var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
    var splitString = cleanedStr.split(" ");
    var word_count = splitString.length -1;
    if (fullStr.length < 2) {
      word_count = 0;
    }
    if (word_count <= theLimit) {
      return true;
    } else {
      var newsplitString = splitString.slice(0, theLimit);
      theEditField.value = newsplitString.join(" ");
      return false;
    }
  }

  function updateWordCount(theEditFieldID, theUpdateFieldID, theLimit) {
    var theEditField = document.getElementById(theEditFieldID);
    var char_count = theEditField.value.length;
    var fullStr = theEditField.value + " ";
    var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
    var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
    var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9.!]+/gi;
    var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
    var splitString = cleanedStr.split(" ");
    var word_count = splitString.length -1;
    if (fullStr.length < 2) {
      word_count = 0;
    }
    if (word_count > theLimit) {
      var newsplitString = splitString.slice(0, theLimit);
      theEditField.value = newsplitString.join(" ");
      word_count = theLimit;
    }
    var theUpdateField = document.getElementById(theUpdateFieldID);
    if (theUpdateField != null) {
      theUpdateField.innerHTML = "(" + word_count.toString() + " of " + theLimit.toString() + ") words";
    }
  }

  function keepAlive(url) {
    new Ajax.Updater("keepAliveDiv", url, {parameters: "id=" + Math.random(), asynchronous:true}); 
  }

  function CopyToClipboard(theInput) {
    var theClipboard = document.getElementById("jvf_clipboard");
    if (theClipboard != null) {
      theClipboard.innerText = Base64.decode(theInput);
      Copied = theClipboard.createTextRange();
      Copied.execCommand("RemoveFormat");
      Copied.execCommand("Copy");
    }
  }

  function toggleExpandingDiv(controlToggleId, controlShortDivId, controlDivId) {
    var theControlToggle = document.getElementById(controlToggleId);
    if (theControlToggle.src.indexOf("arrow_up") != -1) {
      theControlToggle.src = theControlToggle.src.replace(new RegExp("arrow_up"), "arrow_down");
      Element.hide(controlDivId);
      Element.show(controlShortDivId);
    } else {
      theControlToggle.src = theControlToggle.src.replace(new RegExp("arrow_down"), "arrow_up");
      Element.show(controlDivId);
      Element.hide(controlShortDivId);
    }
  }

  function loadURL(theURL) {
    window.location.href = theURL; 
  }

  function GenerateThumbnailLink(theURL, theFilename, theFilePath, theHeightControlID, theWidthControlID, theLinkControlID) {
    var theHeight = document.getElementById(theHeightControlID);
    var theWidth = document.getElementById(theWidthControlID);
    var theLink = document.getElementById(theLinkControlID);
    if ((theHeight != null) && (theWidth != null) && (theLink != null)) {
      theLink.value = theURL + Base64.encode("height=" + theHeight.value + "|width=" + theWidth.value + "|file=" + theFilePath + "|fh=1") + "/" + theFilename;
    }
  }

  function toggleObject(controlToggleId) {
    var theControlToggle = document.getElementById(controlToggleId);
    var theValue = theControlToggle.getAttribute("toggle");
    if (theValue == "1") {
      theControlToggle.setAttribute("toggle", "0");
      Element.show(controlToggleId);
      return true;
    } else {
      theControlToggle.setAttribute("toggle", "1");
      Element.hide(controlToggleId);
      return false;
    }
  }

  function toggleObjectWithLabel(controlToggleId, labelId, onText, offText) {
    var theControlToggle = document.getElementById(controlToggleId);
    var theLabel = document.getElementById(labelId);
    var theValue = theControlToggle.getAttribute("toggle");
    if (theValue == "0") {
      if (theLabel != null) {
        theLabel.innerHTML = onText;
      }
      theControlToggle.setAttribute("toggle", "1");
      Element.hide(controlToggleId);
      return false;
    } else {
      if (theLabel != null) {
        theLabel.innerHTML = offText;
      }
      theControlToggle.setAttribute("toggle", "0");
      Element.show(controlToggleId);
      return true;
    }
  }

  function toggleObjectAndInputWithLabel(controlToggleId, labelId, inputId, onText, offText) {
    var theInput = document.getElementById(inputId);
    if (theInput != null) {
      theInput.value = toggleObjectWithLabel(controlToggleId, labelId, onText, offText);
    }
  }

  function toggleRangeFields(selectId, controlToggleId) {
    var theSelect = document.getElementById(selectId);
    if (theSelect != null) {
      if (theSelect.value == "B") {
        Element.show(controlToggleId);
      } else {
        Element.hide(controlToggleId);
      }
    }
  }

  function updateChildSelect(selectId, updateControlId, url) {
    var theSelect = document.getElementById(selectId);
    if (theSelect != null) {
      new Ajax.Updater(updateControlId, url, {method:"get"});
    }
  }

