  /**
    * Launches a pop-up window
    */
  function launchPopup(url, name, width, height, resizable, scrollbars, toolbar, location) {
    popup_window = window.open(url, name, 'width='+width+',height='+height+',resizable='+resizable+',scrollbars='+scrollbars+',toolbar='+toolbar+',location='+location+'');
    popup_window.focus();
  }

  /**
    * Holds a timestamp for use with cookie generation...
    */
  var timestamp = new Date();

  /**
    * Shows a element
    */
  function show(pElementName, pDisplay) {
    //alert('show(' + pElementName + ', '+ pDisplay + ')');
    var voted = document.getElementById(pElementName);
    voted.style.display = pDisplay;
  }
  
  /**
    * Hides an element
    */
  function hide(pElementName) {
    //alert('hide(' + pElementName + ')');
    var voted = document.getElementById(pElementName);
    voted.style.display = "none";
  }
  
  /**
    * Changes two element at once, switching states between them.
    */
  function change(pHideElementName, pShowElementName) {
    //alert('change(' + pHideElementName + ', '+ pShowElementName + ')');
    hide(pHideElementName);
    show(pShowElementName, 'block');
  }

  /**
    * Checkes state
    */
  function mentometerState(pollId) {
    //alert('mentometerState(' + pollId + ')');
    var cookies = document.cookie;
    var pos = cookies.indexOf('mentometer=');
    if (pos != -1) {
      var start = pos + 11;
      var end = cookies.indexOf(';', start);
      if (end == -1) {
        end = cookies.length;
      }
      var value = cookies.substring(start, end);
      value = unescape(value);
      var mentometerIds = value.split('M');
      for (var i = 0; i < mentometerIds.length; i++) {
        if (mentometerIds[i] == pollId) {
          change('vote-' + pollId, 'voted-' + pollId);
          return;
        }
      }
      change('voted-' + pollId, 'vote-' + pollId);
    }
    else {
      change('voted-' + pollId, 'vote-' + pollId);
    }
  }

  /**
    * Calculates the size of one individual width
    */
  function size(pTotalVotes, pVotes, pSize) {
    return Math.round((pSize * percent(pTotalVotes, pVotes)) / 100);
  }
  
  /**
    * Calculates the percentage value of a set
    * of votes represents...
    */
  function percent(pTotalVotes, pVotes) {
    var result = 0;
    if (pTotalVotes > 0) {
      result = (pVotes * 100) / pTotalVotes;
    }
    return Math.round(result);
  }
  
  /**
    * Read's a cookie
    */
  function readCookie(pCookieName) {
    var cookieName = pCookieName + '='
    var cookies = document.cookie;
    var pos = cookies.indexOf(cookieName);
    if (pos != -1) {
      var start = pos + cookieName.length;
      var end = cookies.indexOf(';', start);
      if (end == -1) {
        end = cookies.length;
      }
      return unescape(cookies.substring(start, end));
    }
  }

  /**
    * Set a cookie
    */
  function setCookie(pName, pValue) {
    document.cookie = pName + '=' + escape(pValue);
  }
  
  /**
    * Reads one individual poll cookie
    */
  function readPollCookie(pollId) {
    var pollCookie = readCookie('pollCache');
    if (pollCookie == null) {
      return null;
    }
    var pollCacheCookies = pollCookie.split(';');
    for (var i = 0; i < pollCacheCookies.length; i++) {
      var pollCookie = pollCacheCookies[i];
      if (pollCookie.indexOf(pollId) != -1) {
        return pollCookie;
      }
    }
  }
  
  /**
    * An array of poll cookie id's
    */
  function readPollCookieIds() {
    var pollCookie = readCookie('pollCache');
    if (pollCookie == null) {
      return null;
    }
    var pollCacheCookies = pollCookie.split(';');
    var result = new Array(pollCacheCookies.length);
    for (var i = 0; i < pollCacheCookies.length; i++) {
      var hepp = pollCacheCookies[i].split(':')
      result[i] = hepp[0];
    }
    return result;
  }
  
  /**
    * Set's a poll cookie
    */
  function setPollCookie(pollId, vote) {
    var values = '';
    var pollCookieIds = readPollCookieIds();
    if (pollCookieIds != null) {
      for (var i = 0; i < pollCookieIds.length; i++) {
        values += readPollCookie(pollCookieIds[i]) + ';';
      }
    }
    values += 'pollId-' + pollId + ':' + timestamp + ':' + vote;
    //alert(values);
    setCookie('pollCache', values);
  }

/* ART-POLLSTUFF TRULZ how do we get this reloaded? */

  /**
    * Shows a element
    */
  function showArt(pElementName, pDisplay) {
    //alert('show(' + pElementName + ', '+ pDisplay + ')');
    var votedArt = document.getElementById(pElementName);
    votedArt.style.display = pDisplay;
  }
  
  /**
    * Hides an element
    */
  function hideArt(pElementName) {
    //alert('hide(' + pElementName + ')');
    var votedArt = document.getElementById(pElementName);
    votedArt.style.display = "none";
  }
  
  /**
    * Changes two element at once, switching states between them.
    */
  function changeArt(pHideElementName, pShowElementName) {
    //alert('change(' + pHideElementName + ', '+ pShowElementName + ')');
    hideArt(pHideElementName);
    showArt(pShowElementName, 'block');
  }

  /**
    * Checkes state
    */
  function mentometerStateArt(pollId) {
    //alert('mentometerState(' + pollId + ')');
    var cookies = document.cookie;
    var pos = cookies.indexOf('mentometer=');
    if (pos != -1) {
      var start = pos + 11;
      var end = cookies.indexOf(';', start);
      if (end == -1) {
        end = cookies.length;
      }
      var value = cookies.substring(start, end);
      value = unescape(value);
      var mentometerIds = value.split('M');
      for (var i = 0; i < mentometerIds.length; i++) {
        if (mentometerIds[i] == pollId) {
          changeArt('voteArt-' + pollId, 'votedArt-' + pollId);
          return;
        }
      }
      changeArt('votedArt-' + pollId, 'voteArt-' + pollId);
    }
    else {
      changeArt('votedArt-' + pollId, 'voteArt-' + pollId);
    }
  }

    /**
      * Encoding for searchfield on frontpage.
      */
  var hexVals = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
              "A", "B", "C", "D", "E", "F");
var unsafeString = "\"<>%\\^[]`\+\$\,&@";
// deleted these chars from the include list ";", "/", "?", ":","=" and #
// so that we could analyze actual URLs

function isUnsafe(compareChar)
// this function checks to see if a char is URL unsafe.
// Returns bool result. True = unsafe, False = safe
{
if (unsafeString.indexOf(compareChar) == -1 && compareChar.charCodeAt(0) > 32
    && compareChar.charCodeAt(0) < 123)
   { return false; } // found no unsafe chars, return false
else
   { return true; }
}

function decToHex(num, radix)
// part of the hex-ifying functionality
{
var hexString = "";
while (num >= radix)
      {
       temp = num % radix;
       num = Math.floor(num / radix);
       hexString += hexVals[temp];
      }
hexString += hexVals[num];
return reversal(hexString);
}

function reversal(s) // part of the hex-ifying functionality
{
var len = s.length;
var trans = "";
for (i=0; i<len; i++)
    { trans = trans + s.substring(len-i-1, len-i); }
s = trans;
return s;
}

function convert(val) // this converts a given char to url hex form
{ return "%" + decToHex(val.charCodeAt(0), 16); }

function myURLEncode(str){
var len = str.length;
var newStr = "";
var original = str;
for (var i=0;i<len;i++){
if (str.substring(i,i+1).charCodeAt(0) < 255) // hack to eliminate the rest of unicode from this
{
if (isUnsafe(str.substring(i,i+1)) == false){
newStr = newStr + str.substring(i,i+1);
} else {
newStr = newStr + convert(str.substring(i,i+1));
}
} else // woopsie! restore.
{
alert ("Found a non-ISO-8859-1 character at position: " + (i+1) + ",\nPlease eliminate before continuing.");
return original;
}

}
    return newStr;
}
    function doSearch()
	{
		var searchQuery = myURLEncode(document.getElementById("searchQuery").value);

		if ( searchQuery.length < 1 ) {
			return;
		}

		var newLocation = "";
    newLocation="<%=siteUrl %>search_result/index.jsp?search.execute=true&show=simpleSearch&lucyStemmed=2&lucyFromDateOn=false&lucyToDateOn=false&lucySort=1&lucyField=2&lucyOptimized=false&lucyExpr=" + searchQuery;

		location.href = newLocation;
	}
