/******************************************************************************
* utils.js
*
* Funcions varies genèriques utilitzables a qualsevol lloc i independents de
*	la base de dades o d'una aplicació en concret.
*
*	Albert Sunyer @ 2008
******************************************************************************/

function isMail(txt){ 
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	return filter.test(txt);
}

function isURL(txt){ 
	var filter  = /^http|https/;
	
	return filter.test(txt);
}

function right(str, n){
	/***
	IN: str - the string we are RIGHTing
			n - the number of characters we want to return
	
	RETVAL: n characters from the right side of the string
	***/
	
	if(n<=0) return ""; // Invalid bound, return blank string
	else if(n>String(str).length) return str; // Invalid bound, return entire string
	else { // Valid bound, return appropriate substring
		 var iLen=String(str).length;
		 return String(str).substring(iLen, iLen-n);
	}
}

function mid(str, start, len){
	/***
	IN: str - the string we are LEFTing
			start - our string's starting position (0 based!!)
			len - how many characters from start we want to get
	
	RETVAL: The substring from start to start+len
	***/
	// Make sure start and len are within proper bounds
	if(start<0 || len<0) return "";

	var iEnd, iLen=String(str).length;
	
	if(start+len>iLen) iEnd=iLen;
	else iEnd=start+len;

	return String(str).substring(start,iEnd);
}

function focusit(c){
	document.getElementById(c).focus();
}


var myWin; 

function popup(url, id, w, h, scroll){
	if(!myWin || myWin.closed){
		myWin = window.open(''+url+'',''+id+'','width='+w+',height='+h+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+scroll+',resizable=yes,top='+((screen.height/2)-(200))+',left='+((screen.width/2) - (150)) + '');
	}else{
		myWin.focus();
	};
	
	void(0); 
}

function popupNoToolsFull(url, nom, scroll){
	settings='height='+screen.availHeight+',width='+screen.availWidth+',top=0,left=0,scrollbars='+scroll+',resizable,toolbar=no,status=no,resizable=yes';
	win=window.open(url, nom, settings);
}

/*
 * tools.tooltip 1.0.2 - Tooltips done right.
 * 
 * Copyright (c) 2009 Tero Piirainen
 * http://flowplayer.org/tools/tooltip.html
 *
 * Dual licensed under MIT and GPL 2+ licenses
 * http://www.opensource.org/licenses
 *
 * Launch  : November 2008
 * Date: 2009-06-12 11:02:45 +0000 (Fri, 12 Jun 2009)
 * Revision: 1911 
 */
(function(c){c.tools=c.tools||{version:{}};c.tools.version.tooltip="1.0.2";var b={toggle:[function(){this.getTip().show()},function(){this.getTip().hide()}],fade:[function(){this.getTip().fadeIn(this.getConf().fadeInSpeed)},function(){this.getTip().fadeOut(this.getConf().fadeOutSpeed)}]};c.tools.addTipEffect=function(d,f,e){b[d]=[f,e]};c.tools.addTipEffect("slideup",function(){var d=this.getConf();var e=d.slideOffset||10;this.getTip().css({opacity:0}).animate({top:"-="+e,opacity:d.opacity},d.slideInSpeed||200).show()},function(){var d=this.getConf();var e=d.slideOffset||10;this.getTip().animate({top:"-="+e,opacity:0},d.slideOutSpeed||200,function(){c(this).hide().animate({top:"+="+(e*2)},0)})});function a(f,e){var d=this;var h=f.next();if(e.tip){if(e.tip.indexOf("#")!=-1){h=c(e.tip)}else{h=f.nextAll(e.tip).eq(0);if(!h.length){h=f.parent().nextAll(e.tip).eq(0)}}}function j(k,l){c(d).bind(k,function(n,m){if(l&&l.call(this)===false&&m){m.proceed=false}});return d}c.each(e,function(k,l){if(c.isFunction(l)){j(k,l)}});var g=f.is("input, textarea");f.bind(g?"focus":"mouseover",function(k){k.target=this;d.show(k);h.hover(function(){d.show()},function(){d.hide()})});f.bind(g?"blur":"mouseout",function(){d.hide()});h.css("opacity",e.opacity);var i=0;c.extend(d,{show:function(q){if(q){f=c(q.target)}clearTimeout(i);if(h.is(":animated")||h.is(":visible")){return d}var o={proceed:true};c(d).trigger("onBeforeShow",o);if(!o.proceed){return d}var n=f.position().top-h.outerHeight();var k=h.outerHeight()+f.outerHeight();var r=e.position[0];if(r=="center"){n+=k/2}if(r=="bottom"){n+=k}var l=f.outerWidth()+h.outerWidth();var m=f.position().left+f.outerWidth();r=e.position[1];if(r=="center"){m-=l/2}if(r=="left"){m-=l}n+=e.offset[0];m+=e.offset[1];h.css({position:"absolute",top:n,left:m});b[e.effect][0].call(d);c(d).trigger("onShow");return d},hide:function(){clearTimeout(i);i=setTimeout(function(){if(!h.is(":visible")){return d}var k={proceed:true};c(d).trigger("onBeforeHide",k);if(!k.proceed){return d}b[e.effect][1].call(d);c(d).trigger("onHide")},e.delay||1);return d},isShown:function(){return h.is(":visible, :animated")},getConf:function(){return e},getTip:function(){return h},getTrigger:function(){return f},onBeforeShow:function(k){return j("onBeforeShow",k)},onShow:function(k){return j("onShow",k)},onBeforeHide:function(k){return j("onBeforeHide",k)},onHide:function(k){return j("onHide",k)}})}c.prototype.tooltip=function(d){var e=this.eq(typeof d=="number"?d:0).data("tooltip");if(e){return e}var f={tip:null,effect:"slideup",delay:30,opacity:1,position:["top","center"],offset:[0,0],api:false};if(c.isFunction(d)){d={onBeforeShow:d}}c.extend(f,d);this.each(function(){e=new a(c(this),f);c(this).data("tooltip",e)});return f.api?e:this}})(jQuery);

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/*------------------------------------------------------------------------------------------------------
jQuery browserSizr

tested with jQuery v1.3+
©2009 CSSLab.cl
free for any use, of course... :D
instructions: http://www.csslab.cl/2009/07/22/jquery-browsersizr/

------------------------------------------------------------------------------------------------------ */

var resizeTimer = null;

jQuery.fn.browserSizr = function(options){
	// default plugin settings
	settings = jQuery.extend({
		containerDiv: '#wrapper',		// value: any HTML tag of #id, default to #container
		debug: 'off', 					// value: on | off, default to 'off'
		smartphones: 'off',				// value: on | off, default to 'off'
		lower1024: 'on',				// value: on | off, default to 'on'
		over1024: 'on',					// value: on | off, default to 'on'
		over1280: 'off'					// value: on | off, default to 'off'
	}, options);

	// do you want to debug the browser width?
	var debug = settings.debug;

	$(function(){
		// let's draw the debug window
		if(settings.debug=='on') {
			$('body').append('<div id="debug" style="position:absolute;right:1em;top:1em;background:rgba(0,0,0,0.7);-moz-box-shadow:#000 0 0 0.5em;-webkit-box-shadow:#000 0 0 0.5em;border: 2px solid rgba(255,255,255,0.7);padding:0.5em;-moz-border-radius:1em;-webkit-border-radius:1em;color:#fff;text-align:center;"><small style="font-size:0.7em;">El ancho actual del navegador es:</small><br /><big id="currentWidth" style="font-size:2em;text-shadow:#000 0 0 0.2em"></big><br /><small style="font-size:0.7em;">La clase del contenedor actual es:</small><br /><big id="currentClass" style="font-size:1.6em;text-shadow:#000 0 0 0.2em"></big></div>')
		}
	});

	$(window).bind('resize load', function(e) {
		// get browser width
		var browserWidth = $('body').width();

		// search for the layout's container to inject the class'es
		var containerDiv = settings.containerDiv;
		
		// get de current class of the container an insert it to the debug window
		var containerClass = $(settings.containerDiv).attr('class');
		
		// filling the debug window with the current browser's width
		if(settings.debug=='on') {
			$('#debug #currentWidth').text(browserWidth+'px');
			if(containerClass == "") {
				$('#debug #currentClass').text('-');
			} else {
				$('#debug #currentClass').text(containerClass);
			};
		};

		// if statements for each resolution
		if(settings.lower1024=='on'){
			if(browserWidth>311 && browserWidth<1023) {
				$(containerDiv).removeClass();
				if (resizeTimer) clearTimeout(resizeTimer);
				resizeTimer = setTimeout(lower1024, 10);
			};
		} else if(settings.lower1024=='off') {
			if(browserWidth<1023 && browserWidth>311) {
				$(containerDiv).removeClass();
			};
		};
		if(settings.smartphones=='on'){
			if(browserWidth<310) {
				if (resizeTimer) clearTimeout(resizeTimer);
				resizeTimer = setTimeout(smartphones, 10);
			};
		};
		if(settings.over1024=='on'){	
			if(browserWidth>1024 && browserWidth<1279 || browserWidth==1024) {
				if (resizeTimer) clearTimeout(resizeTimer);
				resizeTimer = setTimeout(over1024, 10);
			};
		} else if(settings.over1024=='off') {
			if(browserWidth>1024 && browserWidth<1279 || browserWidth==1024) {
				$(containerDiv).removeClass();
			};
		};
		if(settings.over1280=='on'){	
			if(browserWidth>1280 || browserWidth==1280) {
				if (resizeTimer) clearTimeout(resizeTimer);
				resizeTimer = setTimeout(over1280, 10);
			};
		};

		function lower1024() {
			$(containerDiv).removeClass().addClass('lower1024');
		};
		function smartphones() {
			$(containerDiv).removeClass().addClass('smartphones');
		};
		function over1024() {
			$(containerDiv).removeClass().addClass('over1024');
		};
		function over1280() {
			$(containerDiv).removeClass().addClass('over1280');
		};

	});
	
};


// ColorBox v1.2.9b - a full featured, light-weight, customizable lightbox based on jQuery 1.3

(function(C){var I,X,Y,d,A,k,b,H,c,T,F,f,s,j,m,R,l,J,t,E,Z,i,g,a,w,S,p,B,V,x,K,q="colorbox",o="hover",z,e,U,N,M,L,r,O,y="cbox_open",Q="cbox_load",u="cbox_complete",h="cbox_close",n="cbox_closed",D={transition:"elastic",speed:350,width:false,height:false,initialWidth:"400",initialHeight:"400",maxWidth:false,maxHeight:false,resize:true,inline:false,html:false,iframe:false,photo:false,href:false,title:false,rel:false,opacity:0.9,preloading:true,current:"imagen {current} de {total}",previous:"anterior",next:"siguiente",close:"cerrar",open:false,overlayClose:true,slideshow:false,slideshowAuto:true,slideshowSpeed:2500,slideshowStart:"iniciar slideshow",slideshowStop:"parar slideshow"};function P(aa){if(aa.keyCode===37){aa.preventDefault();J.click()}else{if(aa.keyCode===39){aa.preventDefault();l.click()}}}function G(aa,ab){ab=ab==="x"?document.documentElement.clientWidth:document.documentElement.clientHeight;return(typeof aa==="string")?(aa.match(/%/)?(ab/100)*parseInt(aa,10):parseInt(aa,10)):aa}function v(aa){return V.photo?true:aa.match(/\.(gif|png|jpg|jpeg|bmp)(?:\?([^#]*))?(?:#(\.*))?$/i)}function W(){for(var aa in V){if(typeof(V[aa])==="function"){V[aa]=V[aa].call(p)}}}C.fn.colorbox=function(ab,aa){if(this.length){this.each(function(){var ac=C(this).data(q)?C.extend({},C(this).data(q),ab):C.extend({},D,ab);C(this).data(q,ac).addClass("cboxelement")})}else{C(this).data(q,C.extend({},D,ab))}C(this).unbind("click.colorbox").bind("click.colorbox",function(ad){p=this;V=C(p).data(q);W();C().bind("keydown.cbox_close",function(ae){if(ae.keyCode===27){ae.preventDefault();t.click()}});if(V.overlayClose===true){I.css({cursor:"pointer"}).one("click",O)}p.blur();K=aa||false;var ac=V.rel||p.rel;if(ac&&ac!=="nofollow"){c=C(".cboxelement").filter(function(){var ae=C(this).data(q).rel||this.rel;return(ae===ac)});B=c.index(p);if(B<0){c=c.add(p);B=c.length-1}}else{c=C(p);B=0}if(!x){C.event.trigger(y);t.html(V.close);I.css({opacity:V.opacity}).show();x=true;M(G(V.initialWidth,"x"),G(V.initialHeight,"y"),0);if(C.browser.msie&&C.browser.version<7){T.bind("resize.cboxie6 scroll.cboxie6",function(){I.css({width:T.width(),height:T.height(),top:T.scrollTop(),left:T.scrollLeft()})}).trigger("scroll.cboxie6")}}r();N();ad.preventDefault()});if(ab&&ab.open){C(this).triggerHandler("click.colorbox")}return this};U=function(){function aa(ab){return C('<div id="cbox'+ab+'"/>')}T=C(window);X=C('<div id="colorbox"/>');I=aa("Overlay").hide();Y=aa("Wrapper");d=aa("Content").append(F=aa("LoadedContent").css({width:0,height:0}),f=aa("LoadingOverlay"),s=aa("LoadingGraphic"),j=aa("Title"),m=aa("Current"),R=aa("Slideshow"),l=aa("Next"),J=aa("Previous"),t=aa("Close"));Y.append(C("<div/>").append(aa("TopLeft"),A=aa("TopCenter"),aa("TopRight")),C("<div/>").append(k=aa("MiddleLeft"),d,b=aa("MiddleRight")),C("<div/>").append(aa("BottomLeft"),H=aa("BottomCenter"),aa("BottomRight"))).children().children().css({"float":"left"});C("body").prepend(I,X.append(Y));if(C.browser.msie&&C.browser.version<7){I.css("position","absolute")}d.children().addClass(o).mouseover(function(){C(this).addClass(o)}).mouseout(function(){C(this).removeClass(o)}).hide();Z=A.height()+H.height()+d.outerHeight(true)-d.height();i=k.width()+b.width()+d.outerWidth(true)-d.width();g=F.outerHeight(true);a=F.outerWidth(true);X.css({"padding-bottom":Z,"padding-right":i}).hide();l.click(e);J.click(z);t.click(O);d.children().removeClass(o)};M=function(ad,ac,ab,ae){var af=document.documentElement.clientHeight,ah=af/2-ac/2,ag=document.documentElement.clientWidth/2-ad/2,aa;if(ac>af){ah-=(ac-af)}if(ah<0){ah=0}if(ag<0){ag=0}ah+=T.scrollTop();ag+=T.scrollLeft();ad=ad-i;ac=ac-Z;aa=(X.width()===ad&&X.height()===ac)?0:ab;Y[0].style.width=Y[0].style.height="9999px";function ai(aj){A[0].style.width=H[0].style.width=d[0].style.width=aj.style.width;s[0].style.height=f[0].style.height=d[0].style.height=k[0].style.height=b[0].style.height=aj.style.height}X.dequeue().animate({height:ac,width:ad,top:ah,left:ag},{duration:aa,complete:function(){ai(this);Y[0].style.width=(ad+i)+"px";Y[0].style.height=(ac+Z)+"px";if(ae){ae()}},step:function(){ai(this)}})};L=function(af){if(!x){return}T.unbind("resize.cbox_resize");var ab,al,ag,ae,ac,ai,am,aa,ad=V.transition==="none"?0:V.speed;F.remove();F=C(af);function aj(){if(V.width){ab=w}else{ab=w&&w<F.width()?w:F.width()}return ab}function ah(){if(V.height){al=S}else{al=S&&S<F.height()?S:F.height()}return al}F.hide().appendTo("body").attr({id:"cboxLoadedContent"}).css({width:aj()}).css({height:ah()}).prependTo(d);if(C.browser.msie&&C.browser.version<7){C("select:not(#colorbox select)").filter(function(){return C(this).css("visibility")!=="hidden"}).css({visibility:"hidden"}).one(h,function(){C(this).css({visibility:"inherit"})})}aa=C("#cboxPhoto")[0];if(aa&&V.height){ag=(al-parseInt(aa.style.height,10))/2;aa.style.marginTop=(ag>0?ag:0)+"px"}function ak(ao){var an=ab+a+i,ap=al+g+Z;M(an,ap,ao,function(){if(!x){return}if(C.browser.msie){if(aa){F.fadeIn(100)}X.css("filter","")}d.children().show();C("#cboxIframeTemp").after("<iframe id='cboxIframe' name='iframe_"+new Date().getTime()+"' frameborder=0 src='"+(V.href||p.href)+"' />").remove();f.hide();s.hide();R.hide();if(c.length>1){m.html(V.current.replace(/\{current\}/,B+1).replace(/\{total\}/,c.length));l.html(V.next);J.html(V.previous);C().unbind("keydown",P).bind("keydown",P);if(V.slideshow){R.show()}}else{m.hide();l.hide();J.hide()}j.html(V.title||p.title);C.event.trigger(u);if(K){K.call(p)}if(V.transition==="fade"){X.fadeTo(ad,1,function(){if(C.browser.msie){d.css("filter","")}})}T.bind("resize.cbox_resize",function(){M(an,ap,0)})})}if(V.transition==="fade"){X.fadeTo(ad,0,function(){ak(0)})}else{ak(ad)}if(V.preloading&&c.length>1){ae=B>0?c[B-1]:c[c.length-1];ai=B<c.length-1?c[B+1]:c[0];am=C(ai).data(q).href||ai.href;ac=C(ae).data(q).href||ae.href;if(v(am)){C("<img />").attr("src",am)}if(v(ac)){C("<img />").attr("src",ac)}}};N=function(){var aa,ad,ab,ac;p=c[B];V=C(p).data(q);W();C.event.trigger(Q);aa=V.height?G(V.height,"y")-g-Z:false;ad=V.width?G(V.width,"x")-a-i:false;ab=V.href||p.href;f.show();s.show();t.show();if(V.maxHeight){S=V.maxHeight?G(V.maxHeight,"y")-g-Z:false;aa=aa&&aa<S?aa:S}if(V.maxWidth){w=V.maxWidth?G(V.maxWidth,"x")-a-i:false;ad=ad&&ad<w?ad:w}S=aa;w=ad;if(V.inline){C('<div id="cboxInlineTemp" />').hide().insertBefore(C(ab)[0]).bind(Q+" "+h,function(){F.children().insertBefore(this);C(this).remove()});L(C(ab).wrapAll("<div/>").parent())}else{if(V.iframe){L(C("<div><div id='cboxIframeTemp' /></div>"))}else{if(V.html){L(C("<div/>").html(V.html))}else{if(v(ab)){ac=new Image();ac.onload=function(){ac.onload=null;if((S||w)&&V.resize){var ag=this.width,ae=this.height,ai=0,ah=this,af=function(){ae+=ae*ai;ag+=ag*ai;ah.height=ae;ah.width=ag};if(w&&ag>w){ai=(w-ag)/ag;af()}if(S&&ae>S){ai=(S-ae)/ae;af()}}L(C("<div />").css({width:this.width,height:this.height}).append(C(this).css({width:this.width,height:this.height,display:"block",margin:"auto",border:0}).attr("id","cboxPhoto")));if(c.length>1){C(this).css({cursor:"pointer"}).click(e)}if(C.browser.msie&&C.browser.version==7){this.style.msInterpolationMode="bicubic"}};ac.src=ab}else{C("<div />").load(ab,function(ae,af){if(af==="success"){L(C(this))}else{L(C("<p>Request unsuccessful.</p>"))}})}}}}};e=function(){B=B<c.length-1?B+1:0;N()};z=function(){B=B>0?B-1:c.length-1;N()};r=function(){var ab,aa,ac="cboxSlideshow_";R.bind(h,function(){clearTimeout(aa);R.unbind()});function ad(){R.text(V.slideshowStop).bind(u,function(){aa=setTimeout(e,V.slideshowSpeed)}).bind(Q,function(){clearTimeout(aa)}).one("click",function(){ab();C(this).removeClass(o)});X.removeClass(ac+"off").addClass(ac+"on")}ab=function(){clearTimeout(aa);R.text(V.slideshowStart).unbind(u+" "+Q).one("click",function(){ad();aa=setTimeout(e,V.slideshowSpeed);C(this).removeClass(o)});X.removeClass(ac+"on").addClass(ac+"off")};if(V.slideshow&&c.length>1){if(V.slideshowAuto){ad()}else{ab()}}};O=function(){C.event.trigger(h);x=false;C().unbind("keydown",P).unbind("keydown.cbox_close");T.unbind("resize.cbox_resize resize.cboxie6 scroll.cboxie6");I.css({cursor:"auto"}).fadeOut("fast");d.children().hide();X.stop(true,false).removeClass().fadeOut("fast",function(){F.remove();X.css({opacity:1});C.event.trigger(n)})};E=C.fn.colorbox;E.init=U;E.next=e;E.prev=z;E.close=O;E.load=N;E.position=M;E.dimensions=L;E.element=function(){return p};E.settings=D;C(function(){U()})}(jQuery));

$.fn.search = function() {
	return this.focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
};

/*
 * Copyright (c) 2007 Josh Bush (digitalbush.com)
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:

 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE. 
 */
 
/*
 * Version: Beta 1
 * Release: 2007-06-01
 */ 
(function($) {
	var map=new Array();
	$.Watermark = {
		ShowAll:function(){
			for (var i=0;i<map.length;i++){
				if(map[i].obj.val()==""){
					map[i].obj.val(map[i].text);					
					map[i].obj.css("color",map[i].WatermarkColor);
				}else{
				    map[i].obj.css("color",map[i].DefaultColor);
				}
			}
		},
		HideAll:function(){
			for (var i=0;i<map.length;i++){
				if(map[i].obj.val()==map[i].text)
					map[i].obj.val("");					
			}
		}
	}
	
	$.fn.Watermark = function(text,color) {
		if(!color)
			color="#aaa";
		return this.each(
			function(){		
				var input=$(this);
				var defaultColor=input.css("color");
				map[map.length]={text:text,obj:input,DefaultColor:defaultColor,WatermarkColor:color};
				function clearMessage(){
					if(input.val()==text)
						input.val("");
					input.css("color",defaultColor);
				}

				function insertMessage(){
					if(input.val().length==0 || input.val()==text){
						input.val(text);
						input.css("color",color);	
					}else
						input.css("color",defaultColor);				
				}

				input.focus(clearMessage);
				input.blur(insertMessage);								
				input.change(insertMessage);
				
				insertMessage();
			}
		);
	};
})(jQuery);