	$.fn.utf8EncodeVal = function() {
		var utftext = "";
		var string = $(this).val().replace(/\r\n/g,"\n");
		for (var n = 0; n < string.length; n++) {
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
		}
		return utftext;
	};
	
	$.fn.utf8DecodeVal = function(){
		var utftext = $(this).val();
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 		while ( i < utftext.length ) {
 			c = utftext.charCodeAt(i);
 			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 		}
 		return string;
	};
	
	$.fn.serializeForm = function() {
		var string = "";
		var value  = "";
		$(this).find("input,textarea,select").each(function(){
			value = $(this).val().replace(/[\u00A0-\u2666]/g, function(c) { //Convert unicode to html entities
				return '&#'+c.charCodeAt(0)+';';
			});
			value = value.replace(/\+/g,'%2B'); //Url encode '+' symbol
			string += (string==''?"":"&")+($(this).attr("name")+"="+ encodeURIComponent(value) );
		});
		return string;
	};
	
	$.fn.clearForm = function() {
	  return this.each(function() {
	    var type = this.type, tag = this.tagName.toLowerCase();
	    if (tag == 'form')
	      return $(':input',this).clearForm();
	    if (type == 'text' || type == 'password' || tag == 'textarea')
	      this.value = '';
	    else if (type == 'checkbox' || type == 'radio')
	      this.checked = false;
	    else if (tag == 'select')
	      this.selectedIndex = -1;
	  });
	};
	
	
	$.fn.image = function(src, f){ 
		   return this.each(function(){ 
		     var i = new Image(); 
		     i.src = src; 
		     i.onload = f; 
		     this.appendChild(i);
		   }); 
	 }; 
	 
	 $.clientHeight = function(){
		if(window.innerHeight){
		    return window.innerHeight;
		}
		else{
			return document.documentElement.clientHeight;
		}
	 };
	 
	 $.clientWidth = function(){
		if(window.innerWidth){
		    return window.innerWidth;
		}
		else{
			return document.documentElement.clientWidth;
		}
	 };

	 $.fn.addAjaxLoader=function(absolute){
		var w = $(this).outerWidth();
		var h = $(this).outerHeight();
		absolute = absolute==undefined?false:absolute;
		
		if(typeof(DIR_PREFIX) == "undefined"){
			window.DIR_PREFIX = '';
		}
		
		if($(this).find(".ajax_loader").length==0){
			if(absolute){
				$(this).css("position","relative");
				$(this).prepend('<div class="ajax_loader" style="z-index:9999;position:absolute;left:0;margin:0px;padding:0px;width:'+w+'px;height:'+h+'px; background: url('+DIR_PREFIX+'images/admin/ajax-loader.gif) no-repeat center center  #FFFFFF;filter: alpha(opacity=60);opacity:0.6"></div>');
			}
			else{
				$(this).append('<div class="ajax_loader" style="margin:0px;padding:0px;margin-top:-'+h+'px;width:'+w+'px;height:'+h+'px; background: url('+DIR_PREFIX+'images/admin/ajax-loader.gif) no-repeat center center  #FFFFFF;filter: alpha(opacity=60);opacity:0.6"></div>');
			}
		}
	 };
	 $.fn.removeAjaxLoader=function(absolute){
		 $(this).find(".ajax_loader").remove();
	 };
	 
	 
	 function createXMLStringParser(XMLString){
	    try{
	        var xmlParser = new DOMParser();
	        var xmlDoc = xmlParser.parseFromString(XMLString, "text/xml");
	    }
	    catch(Err){
	        try{
	            var xmlDoc= new ActiveXObject("Microsoft.XMLDOM");
	            xmlDoc.async="false";
	            xmlDoc.loadXML(XMLString);
	        }
	        catch(Err){
	            window.alert("Browser does not support XML parsing.");
	            return false;
	        }
	    }
	    return xmlDoc;
	}
	
	function emailCheck (emailStr) {
			var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
			return reg.test(emailStr) == false?false:true;
	}
	 
	
	function checkDate(y,m,d){
		y=document.getElementById(y);
		m=document.getElementById(m);
		d=document.getElementById(d);
		if(m.value==2){
			if(y.value % 4==0){
				if(d.value>29){
					d.value=29;
				}
			}
			else{
				if(d.value>28){
					d.value=28;
				}
			}
	   }
	   else{
		   if(m.value==4||m.vlaue==6||m.value==9||m.value==11){
			   if(d.value>30){
				   d.value=30;
			   }
		   }
	   }	 
	}	
	 
	 function checkFormFields(frm,animate,animate_msg,field_font_color,field_background_color){ //(formulario, array de campos a validar,idioma,animar(1|0)?,mostrar alerta(1|0)?)
			var msg="";
			var verify = true;
			var show_alert  = false;
			$("#"+frm+" input,#"+frm+" select,#"+frm+" textarea,#"+frm+" div").each(function(){
				
				if($(this).hasClass("required")){
					
					if($(this).attr('id').indexOf('captcha')!=-1){
						verify = isCaptchaCodeCorrect($(this).val());
					}
					//If parent has "no_display" class, field check will be ignored
					if( (jQuery.trim($(this).val())=='' || ($(this).attr('id').toLowerCase().indexOf('email')!=-1 && !emailCheck($(this).val())) || ($(this).attr('type')=='checkbox' && !$(this).attr('checked')) ||  ($(this).attr('id').lastIndexOf("_confirmation")!=-1 && $(this).val()!= $("#"+$(this).attr('id').replace("_confirmation","")).val()) || verify==false) && ( $(this).parents(".no_display").length==0 ) ){
						show_alert = true;
						msg=msg+"\n"+$(this).attr('title');
						if($(this).attr('type')!='checkbox' && $(this).attr('type')!='radio'){
							if(animate==1){
								if(animate_msg!=1){   
									$(this).effect("highlight", {color:"#FF0000"},1000,function(){});
								}
								else{
									$(this).css("backgroundColor","#FF0000");
									$(this).css("color","#FFFFFF");
								}
							}
						}
						if(($(this).attr('type')=='checkbox' || $(this).attr('type')=='radio') && $(this).attr('checked')!=true){
							var type = $(this).attr('type');
							/*
							var w=$(this).outerWidth();
							var	h=$(this).outerHeight();
							*/
							var w=15;
							var	h=15;
							
							var style = $(this).attr("style");
							var className = $(this).attr("class");
							var title = $(this).attr("title");
							var chk_id = "chk_"+getMicrotime();
							var div = '<div onclick="$(this).replaceWith(\'<input title=&quot;'+$(this).attr('title')+'&quot; id=&quot;'+$(this).attr('id')+'&quot;  checked=&quot;checked&quot; class=&quot;'+className+'&quot; type=&quot;'+type+'&quot;/>\');" class="'+className+'" title="'+title+'" style="background-color:#FF0000;height:'+h+'px;width:'+w+'px"></div>';
							var div = '<div id="'+chk_id+'" class="'+className+'" title="'+title+'" style="background-color:#FF0000;height:'+h+'px;width:'+w+'px"></div>';
							$(this).replaceWith(div);
							$("#"+chk_id).click(function(){
								var chk = '<input checked="checked" type="'+type+'" class="'+className+'" style="'+style+'" title="'+title+'"/>';
								$(this).replaceWith(chk);
							});
						}
						$(this).one("click", function(){
							$(this).css("backgroundColor",field_background_color);
					   		$(this).css("color",field_font_color);
					   		//$(this).val("");
						});
						$(this).one("focus", function(){
							$(this).css("backgroundColor",field_background_color);
					   		$(this).css("color",field_font_color);
					   		//$(this).val("");
						});
						$(this).one("keypress", function(){
					   		$(this).css("backgroundColor",field_background_color);
						   	$(this).css("color",field_font_color);
						   	//$(this).val("");
					   		
						});
					}	
				}
			});
		  
		   if(show_alert){
				if(animate!=1){
					try{
						msg = getTranslateEntry("complete_following_fields")+": "+msg;	
					}
					catch(ex){
						msg = getDictionaryEntry("complete_following_fields")+": "+msg;
					}
					alert(msg);
			   	}
				else{
					if(animate_msg==1){
						try{
							showAlertMessage(getTranslateEntry("complete_required_fields"),"error",1);
						}
						catch(ex){
							showAlertMessage(getDictionaryEntry("complete_required_fields"),"error",1);
						}
					}
				}
				return false;
		   }
		   else{
				return true;
		   }	
		}	
		
	
		function showAlertMessage(message,icon,close_on_click){
			/* ICONS:ajax,info,alert,error */
			var img_icon="";
			close_on_click = close_on_click == '' || close_on_click == undefined  ? false: close_on_click;
			if(typeof(DIR_PREFIX) == "undefined"){
				window.DIR_PREFIX = '';
			}
			if(icon=='ajax'){img_icon=DIR_PREFIX+"images/admin/ajax-loader.gif";}
			else if (icon=='info'){img_icon=DIR_PREFIX+"images/admin/icon-dialog-info.png";}
			else if (icon=='error'){img_icon=DIR_PREFIX+"images/admin/icon-dialog-error.png";}
			else if (icon=='password'){img_icon=DIR_PREFIX+"images/admin/icon-dialog-password.png";}
			else if (icon=='warning'){img_icon=DIR_PREFIX+"images/admin/icon-dialog-warning.png";}
			else{img_icon=DIR_PREFIX+"images/admin/icon-dialog-warning.png";}
			
			var html ='<div id="alert_msg" style="width:600px;background-color:#FFFFFF;border: 1px solid #999999; cursor:pointer;float:left" onclick="MySimpleLightBox.close();">';
			html+='<div style="float:left"><img style="margin:10px" src="'+img_icon+'"></div>';
			html+='<div style="float:left"><div style="color:#000;font-size:12px;padding-top:30px;">'+message+'</div></div>';
			html+='</div>';
			
			MySimpleLightBox.border='1px solid #999999';
			MySimpleLightBox.loadHTML(html);
			
			$("#lbox").bind("click",function(){
				if(close_on_click){
					MySimpleLightBox.close();
				}	
			});
		}
		
		function restrictInputLength(form_id){
			var inputs=null;
			if(form_id!='' && form_id!=undefined){
				inputs = $("#"+form_id+" input[type='text'],input[type='password'], textarea");
			}
			else{
				inputs = $("input[type='text'],input[type='password'], textarea");
				
			}
			inputs.each(function(){
				var maxlength = 0;
				
				var class_name = $(this).attr("class").split(" ");
			 	for(var i=0; i<class_name.length;i++){
					if(jQuery.trim(class_name[i]).indexOf("maxlength_")!=-1){
						maxlength = parseInt(jQuery.trim(class_name[i]).replace("maxlength_",""));
					}
				}
				
			 	if(maxlength > 0){
					$(this).keypress(function(evt){
						textCounter(this,maxlength,evt);
					});
					$(this).change(function(evt){
						textCounter(this,maxlength,evt);
					});
					
					if(document.all){
						this.onpaste = function(){
							maxLengthPaste(this,maxlength);
						};
					}
					else{
						$(this).attr("oninput",'textCounter(this,'+maxlength+',event)');
					}	
					
				}
			 	
			});	
		}
		
		function maxLengthPaste(field,maxChars){
		    event.returnValue=false;
		    if((field.value.length + window.clipboardData.getData("Text").length) > maxChars){
		       return false;
		    }
		    event.returnValue=true;
		} 
		
		function textCounter(field,maxlimit,evento) {
			
			var ex=new Array('8','46','37','38','39','40','116');
			if(in_array(ex,evento.keyCode)){
				return;	
			}
			if (field.value.length >= maxlimit){ // if too long...trim it!
					cancelEvent(evento);
					field.value = field.value.substring(0, maxlimit);
			}
		}		
		
		function in_array(mat,field){
				var i;
				for(i=0;i<mat.length;i++){
					if(mat[i].toLowerCase()==new String(field).toLowerCase()){
						return true;
					}	
				}
				return false;	
		}
		
		function onlyMoneyInputAllowed(e){
			var keynum;
			var keychar;
			var numcheck;
			if(window.event) // IE
			{
			keynum = e.keyCode;
			}
			else if(e.which) // Netscape/Firefox/Opera
			{
			keynum = e.which;
			} 
			keychar = String.fromCharCode(keynum);
			numcheck = /\d/;
			
			if(numcheck.test(keychar)==false && keynum!=8 && keynum!=undefined){
				if(keychar=='.'){
					var input = eventTrigger(e);
					if(input.value.indexOf('.')!=-1){
						cancelEvent(e);
					}
				}
				else{
					cancelEvent(e);
				}
			}
		}
		
		function onlyIntegerInputAllowed(e){
			var keynum;
			var keychar;
			var numcheck;
			if(window.event){ // IE
				keynum = e.keyCode;
			}
			else if(e.which){ // Netscape/Firefox/Opera
				keynum = e.which;
			} 
			keychar = String.fromCharCode(keynum);
			numcheck = /\d/;
			
			if(numcheck.test(keychar)==false && keynum!=8 && keynum!=undefined){
				cancelEvent(e);
			}
		} 


		function eventTrigger (e) {
		    	if (! e) e = event;
			    return e.target || e.srcElement;
		}
			
		function cancelEvent(e){
				if(navigator.userAgent.indexOf("MSIE")!=-1){
					e.returnValue=0;	
				}
				if(navigator.userAgent.indexOf("Gecko")!=-1){
					e.preventDefault();	
				}
		}
		
		