/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options=$.extend({},options);options.expires=-1;}var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000));}else{date=options.expires;}expires='; expires='+date.toUTCString();}var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('');}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break;}}}return cookieValue;}};

/*
 * jQuery autoResize (textarea auto-resizer)
 * @copyright James Padolsey http://james.padolsey.com
 * @version 1.04
 */

(function(a){a.fn.autoResize=function(j){var b=a.extend({onResize:function(){},animate:true,animateDuration:150,animateCallback:function(){},extraSpace:20,limit:1000},j);this.filter('textarea').each(function(){var c=a(this).css({resize:'none','overflow-y':'hidden'}),k=c.height(),f=(function(){var l=['height','width','lineHeight','textDecoration','letterSpacing'],h={};a.each(l,function(d,e){h[e]=c.css(e)});return c.clone().removeAttr('id').removeAttr('name').css({position:'absolute',top:0,left:-9999}).css(h).attr('tabIndex','-1').insertBefore(c)})(),i=null,g=function(){f.height(0).val(a(this).val()).scrollTop(10000);var d=Math.max(f.scrollTop(),k)+b.extraSpace,e=a(this).add(f);if(i===d){return}i=d;if(d>=b.limit){a(this).css('overflow-y','');return}b.onResize.call(this);b.animate&&c.css('display')==='block'?e.stop().animate({height:d},b.animateDuration,b.animateCallback):e.height(d)};c.unbind('.dynSiz').bind('keyup.dynSiz',g).bind('keydown.dynSiz',g).bind('change.dynSiz',g)});return this}})(jQuery);

/*
 * jQuery MaxLength 
 *
 */
 jQuery.fn.maxLength = function(options){  
    
	var settings = jQuery.extend(
	{
		events:				      [], // Array of events to be triggerd
		maxCharacters:		  10, // Characters limit
		status:				      true, // True to show status indicator bewlow the element
		statusClass:		    "status", // The class on the status div
		statusText:			    "character left", // The status text
		notificationClass:	"error"	// Will be added to the emement when maxlength is reached
	}, options );
	
	this.each(function(){  
        //Get the type of the matched element  
        var type = this.tagName.toLowerCase();  
        //If the type property exists, save it in lower case  
        var inputType = this.type? this.type.toLowerCase() : null;  		
        //Check if is a input type=text OR type=password  
        if(type == "input" && inputType == "text" || inputType == "password"){  
            //Apply the standard maxLength  
            this.maxLength = settings.maxCharacters;  
        }  
        //Check if the element is a textarea  
        else if(type == "textarea"){  
            //Add the key press event  
            this.onkeypress = function(e){  
                //Get the event object (for IE)  
                var ob = e || event;  
                //Get the code of key pressed  
                var keyCode = ob.keyCode;  
                //Check if it has a selected text  
                var hasSelection = document.selection? document.selection.createRange().text.length > 0 : this.selectionStart != this.selectionEnd;  
				// Set character count text
				$(this).siblings('.status').html(settings.maxCharacters-this.value.length + ' ' + settings.statusText);
				if(settings.maxCharacters-this.value.length == 0)
					$(this).siblings('.status').addClass(settings.notificationClass);				
                //return false if can't write more  
                return !(this.value.length >= settings.maxCharacters && (keyCode > 50 || keyCode == 32 || keyCode == 0 || keyCode == 13) && !ob.ctrlKey && !ob.altKey && !hasSelection);  
            };  
            //Add the key up event  
            this.onkeyup = function(){  
                //If the keypress fail and allow write more text that required, this event will remove it  
                if(this.value.length > settings.maxCharacters){  
                    this.value = this.value.substring(0,settings.maxCharacters);  
                }  
            };  
        }  
    });  
};  

