var $d=$(document);
var IE=$.browser.msie,FF=$.browser.mozilla,WK=$.browser.webkit;

String.prototype.bool=function(){return (/^true$/i).test(this);};
String.prototype.esc=function(){return escape(this);};
String.prototype.unesc=function(){return unescape(this);};
String.prototype.escHTML=function(){var _esch_div=document.createElement('div'),_esch_text=document.createTextNode(this);_esch_div.appendChild(_esch_text);return _esch_div.innerHTML;};

function gup(name){
	name=name.replace(/[\[]/,'\\\[').replace(/[\]]/,'\\\]');
	var regexS='[\\?&]'+name+'=([^&#]*)';
	var regex=new RegExp( regexS );
	var results=regex.exec(window.location.href);
  if(results==null)return '';
	else return results[1];
}

function scrollbarWidth(){ 
	var $_sbw_div=$('<div style="width:50px;height:50px;overflow:hidden;position:absolute;top:-200px;left:-200px;"><div style="height:100px;"></div></div>');
	// Append our div, do our calculation and then remove it
	$('body').append($_sbw_div);
	var _sbw_w1=$('div',$_sbw_div).innerWidth();
	$_sbw_div.css('overflow-y',(IE?'scroll':'visible'));
	var _sbw_w2=$('div',$_sbw_div).innerWidth();
	$_sbw_div.remove();
	return (_sbw_w1-_sbw_w2);
}

/*
 * Date Format 1.2.3
 * (c) 2007-2009 Steven Levithan <stevenlevithan.com>
 * MIT license
 *
 * Includes enhancements by Scott Trenda <scott.trenda.net>
 * and Kris Kowal <cixar.com/~kris.kowal/>
 *
 * Accepts a date, a mask, or a date and a mask.
 * Returns a formatted version of the given date.
 * The date defaults to the current date/time.
 * The mask defaults to dateFormat.masks.default.
 */

var dateFormat = function () {
	var	token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,
		timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
		timezoneClip = /[^-+\dA-Z]/g,
		pad = function (val, len) {
			val = String(val);
			len = len || 2;
			while (val.length < len) val = "0" + val;
			return val;
		};

	// Regexes and supporting functions are cached through closure
	return function (date, mask, utc) {
		var dF = dateFormat;

		// You can't provide utc if you skip other args (use the "UTC:" mask prefix)
		if (arguments.length == 1 && Object.prototype.toString.call(date) == "[object String]" && !/\d/.test(date)) {
			mask = date;
			date = undefined;
		}

		// Passing date through Date applies Date.parse, if necessary
		date = date ? new Date(date) : new Date;
		if (isNaN(date)) throw SyntaxError("invalid date");

		mask = String(dF.masks[mask] || mask || dF.masks["default"]);

		// Allow setting the utc argument via the mask
		if (mask.slice(0, 4) == "UTC:") {
			mask = mask.slice(4);
			utc = true;
		}

		var	_ = utc ? "getUTC" : "get",
			d = date[_ + "Date"](),
			D = date[_ + "Day"](),
			m = date[_ + "Month"](),
			y = date[_ + "FullYear"](),
			H = date[_ + "Hours"](),
			M = date[_ + "Minutes"](),
			s = date[_ + "Seconds"](),
			L = date[_ + "Milliseconds"](),
			o = utc ? 0 : date.getTimezoneOffset(),
			flags = {
				d:    d,
				dd:   pad(d),
				ddd:  dF.i18n.dayNames[D],
				dddd: dF.i18n.dayNames[D + 7],
				m:    m + 1,
				mm:   pad(m + 1),
				mmm:  dF.i18n.monthNames[m],
				mmmm: dF.i18n.monthNames[m + 12],
				yy:   String(y).slice(2),
				yyyy: y,
				h:    H % 12 || 12,
				hh:   pad(H % 12 || 12),
				H:    H,
				HH:   pad(H),
				M:    M,
				MM:   pad(M),
				s:    s,
				ss:   pad(s),
				l:    pad(L, 3),
				L:    pad(L > 99 ? Math.round(L / 10) : L),
				t:    H < 12 ? "a"  : "p",
				tt:   H < 12 ? "am" : "pm",
				T:    H < 12 ? "A"  : "P",
				TT:   H < 12 ? "AM" : "PM",
				Z:    utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
				o:    (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
				S:    ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10]
			};

		return mask.replace(token, function ($0) {
			return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
		});
	};
}();

// Some common format strings
dateFormat.masks={
	'default':      'ddd mmm dd yyyy HH:MM:ss',
	shortDate:      'm/d/yy',
	mediumDate:     'mmm d, yyyy',
	longDate:       'mmmm d, yyyy',
	fullDate:       'dddd, mmmm d, yyyy',
	shortTime:      'h:MM TT',
	mediumTime:     'h:MM:ss TT',
	longTime:       'h:MM:ss TT Z',
	isoDate:        'yyyy-mm-dd',
	isoTime:        'HH:MM:ss',
	isoDateTime:    "yyyy-mm-dd'T'HH:MM:ss",
	isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"
};

// Internationalization strings
dateFormat.i18n={
	dayNames:[
		'Dom','Seg','Ter','Qua','Qui','Sex','Sáb',
		'Domingo','Segunda-feira','Terça-feira','Quarta-feira','Quinta-feira','Sexta-feira','Sábado'
	],
	monthNames:[
		'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec',
		'January','February','March','April','May','June','July','August','September','October','November','December'
	]
};

// For convenience...
Date.prototype.format=function(mask,utc){
	return dateFormat(this,mask,utc);
};

function GetDECFromHEX(h){
	var nRet;
	switch(h){
		case 'A':nRet=10;break;
		case 'B':nRet=11;break;
		case 'C':nRet=12;break;
		case 'D':nRet=13;break;
		case 'E':nRet=14;break;
		case 'F':nRet=15;break;
		default:nRet=eval(h);
	}

	return nRet;
}

function GetHEXFromDEC(d){
	var sRet;
	switch(d){
		case 10:sRet='A';break;
		case 11:sRet='B';break;
		case 12:sRet='C';break;
		case 13:sRet='D';break;
		case 14:sRet='E';break;
		case 15:sRet='F';break;
		default:sRet=''+d;break;
	}

	return sRet;
}

function HEX2RGB(h){
	var RGB=new Object();RGB.R=RGB.G=RGB.B=0;
	h=h.replace(/#/gi,'').toUpperCase();
	var nA=GetDECFromHEX(h.substring(0,1));
	var nB=GetDECFromHEX(h.substring(1,2));
	var nC=GetDECFromHEX(h.substring(2,3));
	var nD=GetDECFromHEX(h.substring(3,4));
	var nE=GetDECFromHEX(h.substring(4,5));
  var nF=GetDECFromHEX(h.substring(5,6));

	RGB.R=(nA*16)+nB;
	RGB.G=(nC*16)+nD;
	RGB.B=(nE*16)+nF;

	return RGB;
}

function RGB2HEX(RGB){
	nA=GetHEXFromDEC(Math.floor(RGB.R/16));
	nB=GetHEXFromDEC(Math.floor(RGB.R%16));
	nC=GetHEXFromDEC(Math.floor(RGB.G/16));
	nD=GetHEXFromDEC(Math.floor(RGB.G%16));
	nE=GetHEXFromDEC(Math.floor(RGB.B/16));
	nF=GetHEXFromDEC(Math.floor(RGB.B%16));

	nZ=nA+nB+nC+nD+nE+nF;

	return nZ;
}

function RGB2HSL(RGB){
	var HSL=new Object();HSL.H=HSL.S=HSL.L=0;
	var Min=0;
	var Max=0;
	RGB.R=(eval(RGB.R)/51)*.2;
	RGB.G=(eval(RGB.G)/51)*.2;
	RGB.B=(eval(RGB.B)/51)*.2;

	if(eval(RGB.R)>=eval(RGB.G))Max=eval(RGB.R);else Max=eval(RGB.G);
	if(eval(RGB.B)>eval(Max))Max=eval(RGB.B);
	
	if (eval(RGB.R)<=eval(RGB.G))Min=eval(RGB.R);else	Min=eval(RGB.G);
	if (eval(RGB.B)<eval(Min))Min=eval(RGB.B);

	HSL.L=(eval(Max)+eval(Min))/2;
	if(eval(Max)==eval(Min)){HSL.S=0;HSL.H=0;} 
	else{
		if(HSL.L<.5)HSL.S=(eval(Max)-eval(Min))/(eval(Max)+eval(Min));
		if(HSL.L>=.5)HSL.S=(eval(Max)-eval(Min))/(2-eval(Max)-eval(Min));
		if(RGB.R==Max)HSL.H=(eval(RGB.G)-eval(RGB.B))/(eval(Max)-eval(Min));
		if(RGB.G==Max)HSL.H=2+((eval(RGB.B)-eval(RGB.R))/(eval(Max)-eval(Min)));
		if(RGB.B==Max)HSL.H=4+((eval(RGB.R)-eval(RGB.G))/(eval(Max)-eval(Min)));
	}
	HSL.H=Math.round(HSL.H*60);
	if(HSL.H<0)HSL.H+=360;
	if(HSL.H>=360)HSL.H-=360;
	HSL.S=Math.round(HSL.S*100);
	HSL.L=Math.round(HSL.L*100);

	return HSL;
}

function HSL2RGB(HSL){
	var RGB=new Object();RGB.R=RGB.G=RGB.B=0;
	var p1,p2;

	HSL.L/=100;
	HSL.S/=100;
	if(HSL.L<=0.5)p2=HSL.L*(1+HSL.S);else p2=HSL.L+HSL.S-(HSL.L*HSL.S);
	p1=2*HSL.L-p2;
	if(HSL.S==0){RGB.R=l;RGB.G=l;RGB.B=l;} 
	else{
		RGB.R=FindRGB(p1,p2,HSL.H+120);
		RGB.G=FindRGB(p1,p2,HSL.H);
		RGB.B=FindRGB(p1,p2,HSL.H-120);
	}
	RGB.R*=255;RGB.G*=255;RGB.B*=255;
	RGB.R=Math.round(RGB.R);RGB.G=Math.round(RGB.G);RGB.B=Math.round(RGB.B);

	return RGB;
}

function FindRGB(q1,q2,hue){
	if(hue>360)hue=hue-360;
	if(hue<0)hue=hue+360;
	if(hue<60)return(q1+(q2-q1)*hue/60);
	else{
		if(hue<180)return(q2);
		else{
			if(hue<240)return(q1+(q2-q1)*(240-hue)/60);else return(q1);
		}
	}
}

function LightenScheme(RGB,L){
	var HSL=RGB2HSL(RGB);
  HSL.L+=L;
  if(HSL.L>100)HSL.L=100;
	return HSL2RGB(HSL);
}

function DarkenScheme(RGB,L){
	var HSL=RGB2HSL(RGB);
  HSL.L-=L;
  if(HSL.L<0)HSL.L=0;
	return HSL2RGB(HSL);
}

function DarkenHEXScheme(HEX,L){return RGB2HEX(DarkenScheme(HEX2RGB(HEX),L));}

function LightenHEXScheme(HEX,L){return RGB2HEX(LightenScheme(HEX2RGB(HEX),L));}

// FUNÇÃO QUE UTILIZA $ajax PARA ENVIAR FORM
function formSend(_fmsnd_p){
	var _fmsnd_ret={complete:false,returnBeforeSubmit:false},_fmsnd_xT1,_fmsnd_sT1='',_fmsnd_bLoadError,_fmsnd_bXMLError;
	if(typeof _fmsnd_p.url=='undefined')_fmsnd_p.url='';

	if(_fmsnd_p.url!=''){
		if(typeof _fmsnd_p.data=='undefined')_fmsnd_p.data={};
		if(typeof _fmsnd_p.type=='undefined')_fmsnd_p.type='POST';
		if(typeof _fmsnd_p.cache=='undefined')_fmsnd_p.cache=false;
		if(typeof _fmsnd_p.dataType=='undefined')_fmsnd_p.dataType='xml';
		if(typeof _fmsnd_p.beforeSubmit=='undefined'){_fmsnd_p.beforeSubmit=null;_fmsnd_ret.returnBeforeSubmit=true;}
		if(typeof _fmsnd_p.complete=='undefined')_fmsnd_p.complete=null;

		if(_fmsnd_p.beforeSubmit!=null)if(!(_fmsnd_ret.returnBeforeSubmit=_fmsnd_p.beforeSubmit))return _fmsnd_ret;

		$.ajax({
			url:_fmsnd_p.url,data:_fmsnd_p.data,type:_fmsnd_p.type,cache:_fmsnd_p.cache,dateType:_fmsnd_p.dateType,
			beforeSubmit:function(){return _fmsnd_ret.returnBeforeSubmit;},
			success:function(data,status,xhr){_fmsnd_xT1=data;},
			error:function(xhr,status,data){_fmsnd_sT1=data;},
			complete:function(xhr,status){
				var _fmsnd_bLoadError=true;// ERRO AO CARREGAR A PÁGINA OU A CONVERSÃO DO RESULTADO PARA XML
				var _fmsnd_bXMLError=true;// NODE STATUS DO RESULTADO DO XML = error
				if(status=='success'){
					$d.data('xmlerror',false);_fmsnd_xT1=$.xmlDOM(_fmsnd_xT1);
					if(!$d.data('xmlerror')){
						_fmsnd_bLoadError=false;
						if($(':first>status',_fmsnd_xT1).text()!='error')_fmsnd_bXMLError=false;
					}
				}

				// ERROR OU STATUS=ERROR
				if(_fmsnd_bLoadError||_fmsnd_bXMLError){
					if(status=='success'){
						$('#__OUTNOTIFY').val($(':first>notification',_fmsnd_xT1).text());
						if($(':first>exception>number',_fmsnd_xT1).text()!='')$('#__OUTNOTIFY').val($('#__OUTNOTIFY').val()+'<br /><br /><strong>Mensagem original de erro</strong><br /><br />Número: '.esc()+$(':first>exception>number',_fmsnd_xT1).text());
						if($(':first>exception>source',_fmsnd_xT1).text()!='')$('#__OUTNOTIFY').val($('#__OUTNOTIFY').val()+'<br />Origem: '.esc()+$(':first>exception>source',_fmsnd_xT1).text());
						if($(':first>exception>message',_fmsnd_xT1).text()!='')$('#__OUTNOTIFY').val($('#__OUTNOTIFY').val()+'<br />Descrição: '.esc()+$(':first>exception>message',_fmsnd_xT1).text());
						if($(':first>exception>stacktrace',_fmsnd_xT1).text()!='')$('#__OUTNOTIFY').val($('#__OUTNOTIFY').val()+'<br />Codificação: '.esc()+$(':first>exception>stacktrace',_fmsnd_xT1).text());

						crash($('#__OUTNOTIFY').val(),$(':first>runscript',_fmsnd_xT1).text(),5000);
					}else $d.trigger('xmlParseError',[_fmsnd_sT1]);
				}else _fmsnd_ret.complete=true;
				if(_fmsnd_p.complete!=null)_fmsnd_p.complete(_fmsnd_bLoadError,_fmsnd_bXMLError,_fmsnd_xT1);
			}
		});
	}

	return _fmsnd_ret;
}

// FUNÇÃO DE MENSAGEM E REDIRECIONAMENTO CASO HAJA ERRO NA LEITURA DE XML ADVINDO DAS PÁGINAS BASES
function crash(_cr_msg,_cr_prg,_cr_tmr){
	if(typeof _cr_msg=='undefined')_cr_msg='';_cr_msg=_cr_msg==''?'Saída XML inválida.<br /><br />Contate o suporte.<br /><br />... carregando página inicial.'.esc():_cr_msg;
	if(typeof _cr_prg=='undefined')_cr_prg='';
	if(typeof _cr_tmr=='undefined')_cr_tmr=5000;
	$.msgbox(_cr_msg.unesc());setTimeout(function(){eval(_cr_prg.unesc());},_cr_tmr);
}

// IMPLEMENTA O EVENTO PERSONALIZADO xmlParseError EM $d, O QUAL RESPONSE A ERROS OCORRIDOS NA UTILIZAÇÃO DA FUNÇÃO xmlDOM
$d.bind('xmlParseError',function(event,error){
	var _xmlparerr_sT1=_xmlparerr_sT2=_xmlparerr_sT3='';
	$d.data('xmlerror',true);
	_xmlparerr_sT1='error';
	_xmlparerr_sT2='Saída XML inválida<br /><br />Descrição do erro: \''+error+'\'<br /><br/>Contate o suporte.<br /><br />... carregando página inicial.';
	_xmlparerr_sT3='location.href=\'start.aspx\'';
	if($.Exists($('#__STATUS')))$('#__STATUS').val(_xmlparerr_sT1);
	if($.Exists($('#__OUTNOTIFY')))$('#__OUTNOTIFY').val(_xmlparerr_sT2);
	if($.Exists($('#__RUNSTRING')))$('#__RUNSTRING').val(_xmlparerr_sT3);
	crash(_xmlparerr_sT2.esc(),_xmlparerr_sT3.esc(),5000);
});

// VERIFICA SE AS PÁGINAS DE REFERÊNCIA E DE RESPOSTA A PÁGINA DE ORIGEM ESTÃO DISPONÍVEIS
var _ichk_aT1,_ichk_xT1;
function initialChecking(){
	if($d.data('tmrInLoad').status=='run'&&$d.data('tmrInLoad').excProc&&$d.data('misc')._ichk_aT1.length>0){
		$d.data('tmrInLoad').excProc=false;
		formSend({url:$d.data('misc')._ichk_aT1[0],type:'GET',complete:
			function(_ichk_bLoadError,_ichk_bXMLError,_ichk_xT1){
				if(_ichk_bLoadError||_ichk_bXMLError){$d.data('tmrInLoad').status='error';clearInterval(tT1);}
				else{
					$d.data('misc')._ichk_aT1.splice(0,1);
					if($d.data('misc')._ichk_aT1.length==0){$d.data('tmrInLoad').status='';$d.trigger('iniSettings');}
					else $d.data('tmrInLoad').excProc=true;
				}
			}
		});
	}
}

(function($){
	var nT1=0,nT2=0;

	$.fn.extend({
		escHTML:function(){var _esch_div=document.createElement('div'),_esch_text=document.createTextNode(this);_esch_div.appendChild(_esch_text);return _esch_div.innerHTML;}
	});

	$.fn.extend({
		esc:function(){return escape($(this));}
	});

	$.fn.extend({
		unesc:function(){return unescape($(this));}
	});

	$.extend({
		Exists:function(selector){return ($(selector).length>0);}
	});

	$.fn.extend({
		hasVerticalScrollBar:function(){alert($(this).get(0).scrollHeight);return $(this).get(0).scrollHeight>this.height();}
	});

	$.fn.extend({
		hasHorizontalScrollBar:function(){return this.get(0).scrollWidth>this.width();}
	});

	$.fn.extend({
		center:function(options){
			var options=$.extend({	//Default values
				inside:window,				// element, center into window
				transition:0,					// millisecond, transition time
				minX:0,								// pixel, minimum left element value
				minY:0,								// pixel, minimum top element value
				vertical:true,				// booleen, center vertical
				withScrolling:true,		// booleen, take care of element inside scrollTop when minX < 0 and window is small or when window is big
				horizontal:true				// booleen, center horizontal
			},options);
			return this.each(function(){
				var props={};//={position:'absolute'}; eu que fiz essa alteração. quando não há transition, a propriedade position:'absolute' é aceita no CSS, caso contrário, não sei o que acontence, hahahahahaha
				if(options.vertical){
					var top=($(options.inside).height()-$(this).outerHeight())/2;
					if(options.withScrolling)top+=$(options.inside).scrollTop()||0;
					top=(top>options.minY?top:options.minY);
					$.extend(props,{top:top+'px'});
				}
				if(options.horizontal){
					var left=($(options.inside).width()-$(this).outerWidth())/2;
					if(options.withScrolling)left+=$(options.inside).scrollLeft()||0;
					left=(left>options.minX?left:options.minX);
					$.extend(props,{left:left+'px'});
				}
				$(this).css({position:'absolute'});// necessário pela supressão da instrução acima comentada
				if(options.transition>0){$(this).animate(props,options.transition);}
				else $(this).css(props);
				return $(this);
			});
		}
	});
	
	$.fn.extend({
		send:function(c){
			c=(typeof c=='undefined'?false:c);//checar campos
			var bRet=false;//esse bRet é false (diferente dos demais) para evitar que, numa eventual falha no script, caso a instrução continue, não seja executado o submit do form
			var fm=$(this).get(0);

			if(c){if((bRet=$(fm).formValidation()))fm.submit();}
			else{bRet=true;fm.submit();}
	/*		if(fm.elements['cpAct'].value!='2'){bRet=true;fm.submit();}
			else{
				if((bRet=$(fm).formValidation()))fm.submit();
				else{
					$.ShowNotification({html:'Verifique os campos obrigat&oacute;rios (<font color="#ff0000"><strong>*</strong></font>) e o tipo de dado (num&eacute;rico, data ou texto) informado!'});
				}
			}
	*/
			return bRet;
		}
	});

	//'$.extend' extende a bibliteca jquery, isto é, a chamada da função é feita da seguinte maneira: $.nomedafunçãoextendida
	//'$.fn.extend' extende os elementos da biblioteca jquery, isto é, a chamada do método é feito da seguinte maneira: $('elemento').nomedométodoextendido 
	$.fn.extend({
		formValidation:function(){
			var bRet=true,v;

			$.each(($(this).get(0).elements),function(index,domEle){if($(domEle).attr('requerid')||$(domEle).attr('verify')){bRet=!(v=$(domEle).valid(true,bRet))?v:bRet;}});

			return bRet;

		}
	});

	$.fn.extend({formValidation2:function(grp){
		var bRet=true,v;

		$(grp).each(function(i,o){
			if(o.change){
				$(o.requeridfields).each(function(i1,o1){
					if($('input[id="'+o1+'"],select[id="'+o1+'"],textarea[id="'+o1+'"]').size()>1){
						$('input[id="'+o1+'"],select[id="'+o1+'"],textarea[id="'+o1+'"]').each(function(i2,o2){
							if($(o2).attr('requerid')||$(o2).attr('verify')){bRet=!(v=$(o2).valid(true,bRet))?v:bRet;}
						});
					}else if($('#'+o1).attr('requerid')||$('#'+o1).attr('verify')){bRet=!(v=$('#'+o1).valid(true,bRet))?v:bRet;}
				});
			}
		});

		return bRet;
	}});

	$.fn.extend({
		valid:function(_vld_clear,_vld_focus){
			_vld_clear=(typeof _vld_clear=='undefined'?false:_vld_clear);_vld_focus=(typeof _vld_focus=='undefined'?false:_vld_focus);
			var _vld_ret=true,_vld_r,_vld_v;

			if($(this).attr('requerid')||$(this).attr('verify')){
				_vld_r=$('#r'+$(this).attr('id'));
				_vld_v=true;_vld_t='';

				if($(this).attr('type').search(/text|password|textarea|hidden/gi)!=-1){_vld_t='text';_vld_v=$(this).val().replace(/^\s+|\s+$/gi,'')!='';}
				if($(this).attr('type').search(/checkbox|radio/gi)!=-1){_vld_t='option';_vld_v=$(this).is('[checked]');}
				if($(this).attr('type').search(/select/gi)!=-1){_vld_t='list';_vld_v=$(this).get(0).selectedIndex!=-1;_vld_v=(_vld_v?($(this).get(0).options[$(this).get(0).selectedIndex].value!=''):_vld_v);}
				if($(_vld_r)!='undefined')$(_vld_r).css('visibility',(_vld_v?'hidden':'visible'));
				if(!_vld_v){
					if(_vld_clear&&_vld_t=='text')$(this).value='';
					if(_vld_focus)$(this).focus();
					_vld_ret=false;
				}
			}

			return _vld_ret;
		}
	});

	$.extend({
		ShowNotification:function(options){
			var _snret=false,_nsbkcolor='#E4F0F2';
			var options=$.extend({	//Default values
				html:'',							// text or html for to message
				type:'default',				// type of message
				waitshow:400,					// millisecond, wait time for show
				delayshow:400,				// millisecond, show time complete
				waithidden:5000,			// millisecond, wait time for hidden
				delayhidden:400				// millisecond, hidde time complete
			},options);

			if(options.type=='default'||options.type=='info')_nsbkcolor='#E4F0F2';
			if(options.type=='error')_nsbkcolor='#FF8080';//#F5E1C5

			if($('#notificationsBox').css('display')=='none'){
				$('#notificationsBox').html(options.html).css({'background-color':_nsbkcolor});
				$('#notificationsBox').delay(options.waitshow).slideDown(options.delayshow).delay(options.waithidden).slideUp(options.delayhidden);
				_snret=true;
			}

			return _snret;
		}
	});

	$.fn.extend({
		populate:function(list,selected){
			var sT1="";
			$(list).each(function(index,elem){
				sT1+='<option value="'+$(elem).attr('key')+'"'+($(elem).attr('key')==selected?' selected':'')+'>'+unescape($(elem).attr('description'))+'</option>';
			});
			$(this).html(sT1);
		}
	});

	$.fn.extend({
		populate2:function(_pop_par){
			var _pop_ret=true,_pop_sT1='',_pop_sT2='',_pop_sT3='',_pop_func;
			if(typeof _pop_par.beforePop!='undefined'){_pop_func=_pop_par.beforePop;_pop_ret=_pop_func();}

			if(_pop_ret){
				if(typeof _pop_par.selected=='undefined')_pop_par.selected='';

				_pop_sT1='<option value="#"§>%</option>';
				$(_pop_par.list).each(function(_pop_i1,_pop_o1){
					_pop_sT2=_pop_sT1;
					_pop_sT2=_pop_sT2.replace(/#/gi,$(_pop_o1).attr('key'));
					_pop_sT2=_pop_sT2.replace(/%/gi,unescape($(_pop_o1).attr('description')));
					_pop_sT2=_pop_sT2.replace(/§/gi,($(_pop_o1).attr('key')==_pop_par.selected?' selected':''));
					_pop_sT3+=_pop_sT2;
				});
				$(this).html(_pop_sT3);

				if(typeof _pop_par.complete!='undefined'){_pop_func=_pop_par.complete;_pop_ret=_pop_func();}
			}

			return _pop_ret;
		}
	});

	$.fn.extend({
		lenlimit:function(l,e,c,f){//l=limit,e=event,c=clear(boolean),f=callback function
			var bRet=true;
			nOLen=typeof ($(this).get(0))=='object'?$(this).val().length:$(this).length;
			if(typeof e!='undefined')if(e.type=='keypress')--l;
			if(nOLen>0){
				if(nOLen>l){
					if(c){
						if(e.type=='keypress')e.preventDefault();
						if(e.type=='change')$(this).val($(this).text().substr(0,l));
						bRet=false;
					}
				}
			}
			return bRet;
		}
	});

	$.fn.extend({
		eventExists:function(ev){
			//var sRet='';
			//$('#ids_em').listHandlers(ev,function(ele,data){sRet=data;});
			//return sRet!='';
			var $dat=$(this).data('events');
			try{$ev=eval('$dat.'+$ev);}catch(e){return false;}
			return ($(this)!=null&&typeof($ev)!=='undefined');
		}
	});

	$.fn.listHandlers=function(events,outputFunction){
		return this.each(function(i){
			var elem=this,
					dEvents=$(this).data('events');
			if(!dEvents){return;}
			$.each(dEvents,function(name,handler){
				if((new RegExp('^('+(events==='*'?'.+':events.replace(',','|').replace(/^on/i,''))+')$','i')).test(name)){
					$.each(handler,function(i,handler){
						outputFunction(elem,'\n'+i+': ['+name+'] : '+handler);
					});
				}
			});
		});
	};

})(jQuery);
