String.prototype.lpad = function(padString, desiredLength)
{
	var i;
	var paddedString = "";

	for (i=this.length; i< desiredLength; i++)
	{
		paddedString = paddedString.concat(padString);
	}

	paddedString = paddedString.concat(this);

	return paddedString;
}

String.prototype.trim = function() {
   return (this.replace (/\s+$/, '').replace (/^\s+/, ''));
};

String.prototype.ltrim = function () {
   return (this.replace (/^\s+/, ''));
};

String.prototype.rtrim = function () {
   return (this.replace (/\s+$/, ''));
};

String.prototype.strim = function() {
   return (this.replace (/\s+$/, '').replace (/^\s+/, '').replace (/\s+/g, ' '));
};

String.prototype.ucfirst = function() {
   var buffer1 = this.substring (0, 1).toUpperCase ();
   var buffer2 = this.substr (1).toLowerCase ();

   return buffer1+buffer2;
};

String.prototype.ucwords = function() {
   var arr = this.split (/\s+/g);

   for (i=0; i < arr.length; i++) {
      var buffer1 = arr [i].substring (0, 1).toUpperCase ();
      var buffer2 = arr [i].substr (1).toLowerCase ();

      arr [i] = buffer1+buffer2;
   }
   // '^(\w)(.*)', '\u\1\2'
   return arr.join (' ');
};

String.prototype.strtoupper = function() {
   return this.toUpperCase ();
};

String.prototype.strtolower = function() {
   return this.toLowerCase ();
};

String.prototype.wordcount = function() {
   var arr = this.split (/\s+/g);
   return arr.length ();
};



var template = {

   clock : {

      timer : window.setInterval ("template.clock.refresh()", 2500),

      refresh : function () {
   	   var now = new Date ();
         var wochentag = new Array ("sonntag", "montag", "dienstag", "mittwoch", "donnerstag", "freitag", "samstag");
         var monat = new Array ("jänner", "februar", "märz", "april", "mai", "juni", "juli", "august", "september", "oktober", "november", "dezember");

         var buffer = wochentag [now.getDay()]
                    + ' | '
                    + now.getDate() + ". " + monat [now.getMonth()] + " " + now.getFullYear()
                    + ' | '
                    + now.getHours().toString().lpad("0",2) + ":" + now.getMinutes().toString().lpad("0",2);

      	$("#cms-sysdate").html(buffer);
      }

   },

   mailto : function (recipiant, domain) {
      window.open ("mailto:"+recipiant+"@"+domain);
   }

}

function cms_mailto (recipiant)
{
   window.open ("mailto:"+recipiant);
}

