if (typeof __init == 'function') window.addEvent('domready', __init);

try {
   var cp = new cpaint();
   if (cp.capable) {
      cp.set_response_type("XML");
      //cp.set_debug(true);
   } else {
      alert ("cpaint funzt nicht...")
   }
} catch(e) {
   
}


function showRollover(which) {
   var sRolloverDiv = $(which + '_rollover');
   if(sRolloverDiv) {
      hideRollover(sRolloverDiv);
      sRolloverDiv.setStyle('display', 'block');
   }
}

function hideRollover(except) {
   var divs = ['navi_news_rollover', 'navi_agenda_rollover', 'navi_verband_rollover', 'navi_ntt_rollover'];

   divs.each(function(name) {
      var div = $(name);

      if (div && div != except) {
         div.setStyle('display', 'none');
      }
   });

   $('rollout_area').setStyle('visibility', 'hidden');
   return;


   if(document.getElementById) {
      /*Effect.Queues.get('navi_news').each(function(e) { e.cancel() });
      Effect.Queues.get('navi_agenda').each(function(e) { e.cancel() });
      Effect.Queues.get('navi_verband').each(function(e) { e.cancel() });
      Effect.Queues.get('navi_ntt').each(function(e) { e.cancel() }); */

      //new Effect.Fade('navi_news', {queue: {position: 'end': scope: which}, duration : 0.01});
      //new Effect.Fade('navi_agenda', {queue: {position: 'end': scope: which}, duration : 0.01});
      //new Effect.Fade('navi_verband', {queue: {position: 'end': scope: which}, duration : 0.01});
      //new Effect.Fade('navi_ntt', {queue: {position: 'end': scope: which}, duration : 0.01});

      if (except != 'navi_news_rollover' && document.getElementById('navi_news_rollover'))
//         new Effect.Fade('navi_news_rollover', { queue: { scope: 'navi_news'}, duration: 0.5});
         document.getElementById('navi_news_rollover').style.display = 'none';

      if (except != 'navi_agenda_rollover' && document.getElementById('navi_agenda_rollover'))
//         new Effect.Fade('navi_agenda_rollover', { queue: { scope: 'navi_agenda'}, duration: 0.5});
         document.getElementById('navi_agenda_rollover').style.display = 'none';

      if (except != 'navi_verband_rollover' && document.getElementById('navi_verband_rollover'))
//         new Effect.Fade('navi_verband_rollover', { queue: { scope: 'navi_verband'}, duration: 0.5});
         document.getElementById('navi_verband_rollover').style.display = 'none';

      if (except != 'navi_ntt_rollover' && document.getElementById('navi_ntt_rollover'))
//         new Effect.Fade('navi_ntt_rollover', { queue: { scope: 'navi_ntt'}, duration: 0.5});
         document.getElementById('navi_ntt_rollover').style.display = 'none';

      if (document.getElementById('rollout_area'))
         document.getElementById('rollout_area').style.visibility = 'hidden';
   }
}

function showRolloutArea() {
   var area = $('rollout_area');

   if (area) {
      area.setStyle('visibility', 'visible');
   }
}


function encode_utf8(rohtext) {
	// dient der Normalisierung des Zeilenumbruchs
	rohtext = rohtext.replace(/\r\n/g,"\n");
	var utftext = "";
	for(var n=0; n<rohtext.length; n++)
		{
		// ermitteln des Unicodes des  aktuellen Zeichens
		var c=rohtext.charCodeAt(n);
		// alle Zeichen von 0-127 => 1byte
		if (c<128)
			utftext += String.fromCharCode(c);
		// alle Zeichen von 127 bis 2047 => 2byte
		else if((c>127) && (c<2048)) {
			utftext += String.fromCharCode((c>>6)|192);
			utftext += String.fromCharCode((c&63)|128);}
		// alle Zeichen von 2048 bis 66536 => 3byte
		else {
			utftext += String.fromCharCode((c>>12)|224);
			utftext += String.fromCharCode(((c>>6)&63)|128);
			utftext += String.fromCharCode((c&63)|128);}
		}
	return utftext;
}

function decode_utf8(utftext) {
   var plaintext = ""; var i=0; var c=c1=c2=0;
   // while-Schleife, weil einige Zeichen uebersprungen werden
   while(i<utftext.length)
   	{
   	c = utftext.charCodeAt(i);
   	if (c<128) {
   		plaintext += String.fromCharCode(c); i++;}
   	else if((c>191) && (c<224)) {
   		c2 = utftext.charCodeAt(i+1);
   		plaintext += String.fromCharCode(((c&31)<<6) | (c2&63));
   		i+=2;}
   	else {
   		c2 = utftext.charCodeAt(i+1); c3 = utftext.charCodeAt(i+2);
   		plaintext += String.fromCharCode(((c&15)<<12) | ((c2&63)<<6) | (c3&63));
   		i+=3;}
   	}
   return plaintext;
}

function showLogin() {
   var d = document.getElementById('UserSession');

   new Effect.toggle(d, 'slide');
}


// Removes leading whitespaces
function LTrim( value ) {

	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");

}

// Removes ending whitespaces
function RTrim( value ) {

	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");

}

// Removes leading and ending whitespaces
function trim( value ) {

	return LTrim(RTrim(value));

}

function printeMail(user, domain, text) {
   if (domain == '') domain = 'env-afgn.ch';

   email = user + '@' + domain;

   if (text == '') text = user + '(at)' + domain;

   document.write('<a href="mailto:' + email + '">' + text + '</a>');
}
