function openWindow(tiedosto, nimi, w, h, scrollBars) {
  if(typeof(w) == 'undefined') w = 1024;
  if(typeof(h) == 'undefined') h = 800;
  if(typeof(scrollBars) == 'undefined') scrollBars = 1;
  specs = "toolbar=1,location=1,scrolling=1,directories=0,status=1,menubar=1,scrollbars="+scrollBars+",resizable=1,copyhistory=0,width="+w+",height="+h;
  window.open(tiedosto, nimi, specs);
  return false;
}
function valueIfEmpty(input, text){
  if(input.value.length == 0){input.value = text;}
}
function emptyIfValue(input, text){
  if(input.value == text){input.value = '';}
}
function showPollResult(obj) {
    var poll = jQuery(obj).parent();
    jQuery(poll).find('.results').slideDown();
    jQuery(poll).find('.showPollResult').addClass('removed');
}
/* Returns true if the user has already voted this poll */
function hasVotedPoll(articleId){
  var votes = getPollCookie();
  if(votes==null) return false;
  else return votes.indexOf(articleId+"M") >=0 ;
}
/* Return value of poll cookie, or null */
function getPollCookie()
{
  var name = "mentometer";
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1){
    begin = dc.indexOf(prefix);
    if (begin != 0){
      return null;
    }
  }
  else{
    begin += 2;
  }
  var end = document.cookie.indexOf(";", begin);
  if (end == -1){
    end = dc.length;
  }
  begin += prefix.length;
  if (begin >= end){
    return null;
  }
  return dc.substring(begin, end);
}
function replaceLineBreaks(text) {
  return text.replace(/\n\r?/g, '<br />');
}
// encode/decode troublesome chars for hidden fields and JSON
function encodeHidden(value){
  return value.replace(/"/g,'&quot;').replace(/</g,'&lt;').replace(/>/g,'&gt;'); 
} 
function decodeHidden(value){ 
  return value.replace(/&quot;/g,'"').replace(/&lt;/g,'<').replace(/&gt;/g,'>'); 
}
function strToDate(str)
{
	if (!str)
	{
        return undefined;
	}
    var arr = str.split(".");
    if(arr.length != 3)
    {
        return undefined;
    }
    if(arr[0].substr(0, 1) == "0")
    {
        arr[0] = arr[0].substr(1);
    }
    if(arr[1].substr(0, 1) == "0")
    {
        arr[1] = arr[1].substr(1);
    }
    return new Date(parseInt(arr[2]), parseInt(arr[1]) - 1, parseInt(arr[0]), 0, 0, 0, 0);
}

