
  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=yes,resizable=no,width="
                   + width + ",height=" + height + ',left=' + wleft + ',top=' + wtop; 
		window.open(url, name, settings);
	}

  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 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 popup(url, name, width, height) {
		var settings = "titlebar=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width="+width+",height="+height; 
		window.open(url, name, settings);
	}

	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 countWords (theEditor, theUpdateField) {
    var theValue = theEditor.getHTMLBody().replace(/(<([^>]+)>)/ig, "");
    var theValue = theValue.replace(/&nbsp;/ig, " ");
    var char_count = theValue.length;
    var fullStr = theValue + " ";
    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 == 1) {
      wordOrWords = " word";
    } else {
      wordOrWords = " words";
    }
    var theUpdateField = document.getElementById(theUpdateField);
    if (theUpdateField != null) {
      theUpdateField.innerHTML = word_count + wordOrWords;
    }
    return word_count;
  }
