// mail encryption stuff
function UnCryptMailto( s ){
  var n = 0;
  var r = "";
  for( var i = 0; i < s.length; i++) {
    n = s.charCodeAt( i );
    if( n >= 8364 ){
        n = 128;
    }
    r += String.fromCharCode( n - 1 );
  }
   return r;
}
function linkTo_UnCryptMailto( s ){
  location.href=UnCryptMailto( s );
}

// trim whitespace
function trim(stringToTrim) {
  return stringToTrim.replace(/^\s+|\s+$/g,"");
}

// check donate form
function checkDonate(frm, msg) {
  // check amount
  if (trim(frm.amount.value) == "" || trim(frm.amount.value) == 0) {
    alert(msg);
    frm.amount.value = "";
    frm.amount.focus();
    return false;
  }
  return true;
}

// limit characters in textarea
function limitChars(textid, limit, infodiv) {
  var text = $('#'+textid).val(); 
  var textlength = text.length;
  if(textlength > limit) {
    $('#'+textid).val(text.substr(0,limit));
    return false;
  } else {
    $('#' + infodiv).html(limit - textlength);
    return true;
  }
}

// init div
function initDiv(delay, page, dv) {
  getDiv(page, dv);
  window.setTimeout("initDiv(" + delay + ",'" + page + "','" + dv + "')", delay );
}

// populate div
function getDiv(page, dv) {
  // submit to php
  $.ajax({
    cache: false,
    async: true,
    url: page,
    dataType: "html",
    success: function(data) {
      // if data not error
      if (data != "error") {
        // set html
        $('#' + dv).html(data);
      }
    },
    error: function() {
    }
  });
}

