(function($) {
	sprintfWrapper = {
		init : function () { 
			if (typeof arguments == "undefined") { return null; }
			if (arguments.length < 1) { return null; }
			if (typeof arguments[0] != "string") { return null; }
			if (typeof RegExp == "undefined") { return null; }
	 
			var string = arguments[0];
			var exp = new RegExp(/(%([%]|(\-)?(\+|\x20)?(0)?(\d+)?(\.(\d)?)?([bcdfosxX])))/g);
			var matches = new Array();
			var strings = new Array();
			var convCount = 0;
			var stringPosStart = 0;
			var stringPosEnd = 0;
			var matchPosEnd = 0;
			var newString = '';
			var match = null;
	 
			while (match = exp.exec(string)) {
				if (match[9]) { convCount += 1; }
	 
				stringPosStart = matchPosEnd;
				stringPosEnd = exp.lastIndex - match[0].length;
				strings[strings.length] = string.substring(stringPosStart, stringPosEnd);
	 
				matchPosEnd = exp.lastIndex;
				matches[matches.length] = {
					match: match[0],
					left: match[3] ? true : false,
					sign: match[4] || '',
					pad: match[5] || ' ',
					min: match[6] || 0,
					precision: match[8],
					code: match[9] || '%',
					negative: parseInt(arguments[convCount]) < 0 ? true : false,
					argument: String(arguments[convCount])
				};
			}
			strings[strings.length] = string.substring(matchPosEnd);
	 
			if (matches.length == 0) { return string; }
			if ((arguments.length - 1) < convCount) { return null; }
	 
			var code = null;
			var match = null;
			var i = null;
	 
			for (i=0; i<matches.length; i++) {
	 
				if (matches[i].code == '%') { substitution = '%' }
				else if (matches[i].code == 'b') {
					matches[i].argument = String(Math.abs(parseInt(matches[i].argument)).toString(2));
					substitution = sprintfWrapper.convert(matches[i], true);
				}
				else if (matches[i].code == 'c') {
					matches[i].argument = String(String.fromCharCode(parseInt(Math.abs(parseInt(matches[i].argument)))));
					substitution = sprintfWrapper.convert(matches[i], true);
				}
				else if (matches[i].code == 'd') {
					matches[i].argument = String(Math.abs(parseInt(matches[i].argument)));
					substitution = sprintfWrapper.convert(matches[i]);
				}
				else if (matches[i].code == 'f') {
					matches[i].argument = String(Math.abs(parseFloat(matches[i].argument)).toFixed(matches[i].precision ? matches[i].precision : 6));
					substitution = sprintfWrapper.convert(matches[i]);
				}
				else if (matches[i].code == 'o') {
					matches[i].argument = String(Math.abs(parseInt(matches[i].argument)).toString(8));
					substitution = sprintfWrapper.convert(matches[i]);
				}
				else if (matches[i].code == 's') {
					matches[i].argument = matches[i].argument.substring(0, matches[i].precision ? matches[i].precision : matches[i].argument.length)
					substitution = sprintfWrapper.convert(matches[i], true);
				}
				else if (matches[i].code == 'x') {
					matches[i].argument = String(Math.abs(parseInt(matches[i].argument)).toString(16));
					substitution = sprintfWrapper.convert(matches[i]);
				}
				else if (matches[i].code == 'X') {
					matches[i].argument = String(Math.abs(parseInt(matches[i].argument)).toString(16));
					substitution = sprintfWrapper.convert(matches[i]).toUpperCase();
				}
				else {
					substitution = matches[i].match;
				}
	 
				newString += strings[i];
				newString += substitution;
	 
			}
			newString += strings[i];
	 
			return newString;
	 
		},
	 
		convert : function(match, nosign){
			if (nosign) {
				match.sign = '';
			} else {
				match.sign = match.negative ? '-' : match.sign;
			}
			var l = match.min - match.argument.length + 1 - match.sign.length;
			var pad = new Array(l < 0 ? 0 : l).join(match.pad);
			if (!match.left) {
				if (match.pad == "0" || nosign) {
					return match.sign + pad + match.argument;
				} else {
					return pad + match.sign + match.argument;
				}
			} else {
				if (match.pad == "0" || nosign) {
					return match.sign + match.argument + pad.replace(/0/g, ' ');
				} else {
					return match.sign + match.argument + pad;
				}
			}
		}
	}
	

	$.gwa = $.gwa || {};
	if( $.gwa.version )
	{
		return;
	}
	
	$.extend( $.gwa,{
		version: "1.2.0",
		datas: {},
		
		addslashes: function(str)
		{
			if( !str )
				return "";
			return str.replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0');
		},
 
 
		stripslashes: function(str)
		{
			if( !str )
				return "";
			return str.replace(/\\(.?)/g, function (s, n1){switch (n1){case '\\':return '\\';case '0':return '\u0000';case '':return '';default:return n1;}});
		},

		
		numberFormat: function(number, decimals, thousands_sep, dec_point)
		{
		   number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
		    var n = !isFinite(+number) ? 0 : +number,
		        prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
		        sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
		        dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
		        s = '',
		        toFixedFix = function (n, prec) {
		            var k = Math.pow(10, prec);
		            return '' + Math.round(n * k) / k;
		        };
		    // Fix for IE parseFloat(0.55).toFixed(0) = 0;
		    s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
		    if (s[0].length > 3) {
		        s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
		    }
		    if ((s[1] || '').length < prec) {
		        s[1] = s[1] || '';
		        s[1] += new Array(prec - s[1].length + 1).join('0');
		    }
		    return s.join(dec);
		},

		ucfirst: function(str) 
		{
	    str += '';
	    var f = str.charAt(0).toUpperCase();
	    return f + str.substr(1);
		},

		clone: function(obj)
		{
			for (var i in obj) 
			{
		       if( typeof obj[i]=="object" )
		           this[i] = new Geos.clone(obj[i]);
		       else
		           this[i] = obj[i];
		    }//fin for (var i in obj) 
		},
		
		basename: function (path, suffix) 
		{
		    var b = path.replace(/^.*[\/\\]/g, '');
		     if (typeof(suffix) == 'string' && b.substr(b.length - suffix.length) == suffix) {
		        b = b.substr(0, b.length - suffix.length);
		    }
		 
		    return b;
		},
		
		dirname: function(path) 
		{
    		return path.replace(/\\/g, '/').replace(/\/[^\/]*\/?$/, '');
		},
		
		pathInfo: function(path,options)
		{
		   var opt = '',        optName = '',
		        optTemp = 0,
		        tmp_arr = {},
		        cnt = 0,
		        i = 0;    var have_basename = false,
		        have_extension = false,
		        have_filename = false;
		 
		    // Input defaulting & sanitation    
		    if( !path )
		        return false;
			    
		    if( !options )
		        options = 'PATHINFO_ALL';
		 
		    // Initialize binary arguments. Both the string & integer (constant) input is
		    // allowed
		    var OPTS = {        
		    	'PATHINFO_DIRNAME': 1,
		        'PATHINFO_BASENAME': 2,
		        'PATHINFO_EXTENSION': 4,
		        'PATHINFO_FILENAME': 8,
		        'PATHINFO_ALL': 0    
		    };
		        
		    // PATHINFO_ALL sums up all previously defined PATHINFOs (could just pre-calculate)
		    for (optName in OPTS) {
		        OPTS.PATHINFO_ALL = OPTS.PATHINFO_ALL | OPTS[optName];
		    }    if (typeof options !== 'number') { // Allow for a single string or an array of string flags
		        options = [].concat(options);
		        for (i = 0; i < options.length; i++) {
		            // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
		            if (OPTS[options[i]]) {                optTemp = optTemp | OPTS[options[i]];
		            }
		        }
		        options = optTemp;
		    } 
		    // Internal Functions
		    var __getExt = function (path) {
		        var str = path + '';
		        var dotP = str.lastIndexOf('.') + 1;        return str.substr(dotP);
		    };
		 
		 
		    // Gather path infos   
		     if (options & OPTS.PATHINFO_DIRNAME) {
		        tmp_arr.dirname = this.dirname(path);
		    }
		 
		    if (options & OPTS.PATHINFO_BASENAME) {        if (false === have_basename) {
		            have_basename = this.basename(path);
		        }
		        tmp_arr.basename = have_basename;
		    } 
		    if (options & OPTS.PATHINFO_EXTENSION) {
		        if (false === have_basename) {
		            have_basename = this.basename(path);
		        }        if (false === have_extension) {
		            have_extension = __getExt(have_basename);
		        }
		        tmp_arr.extension = have_extension;
		    } 
		    if (options & OPTS.PATHINFO_FILENAME) {
		        if (false === have_basename) {
		            have_basename = this.basename(path);
		        }        if (false === have_extension) {
		            have_extension = __getExt(have_basename);
		        }
		        if (false === have_filename) {
		            have_filename = have_basename.substr(0, (have_basename.length - have_extension.length) - 1);        }
		 
		        tmp_arr.filename = have_filename;
		    }
		  
		    // If array contains only 1 element: return string
		    cnt = 0;
		    for (opt in tmp_arr) {
		        cnt++;    }
		    if (cnt == 1) {
		        return tmp_arr[opt];
		    }
		     // Return full-blown array
		    return tmp_arr;	
		},
		
		sprintf: sprintfWrapper.init
	});

	jQuery.validator.addMethod("UNIX", function(value, element){
		return this.optional(element) || value.match(/[a-zA-Z0-9_-]/); 
	});


	$.fn.resizeMe = function()
	{
		if( this.length > 1 )
			this.each(function(index,element){$(element).resizeMe(); } );
		else if( this.length == 1 )
		{			
			var item = this, width=0,tmp=null,tmp2=null,tmp3=null,border=0,margin=0,padding=0;
			tmp = item.getHiddenDimensions();
			tmp2 = item.getHiddenDimensions(true);
			padding = tmp.innerWidth-tmp.width;
			margin = tmp2.outerWidth - tmp.outerWidth;
			border = tmp.outerWidth-tmp.innerWidth;
			tmp3 = item.parent().getHiddenDimensions();
			width = tmp3.width - margin - padding - border;
			item.css("width",width+"px");
		}
		return this;
	}


	$.fn.getHiddenDimensions = function(includeMargin) {
	    var $item = this,
	        props = { position: 'absolute', visibility: 'hidden', display: 'block' },
	        dim = { width:0, height:0, innerWidth: 0, innerHeight: 0, outerWidth: 0, outerHeight: 0 },
	        $hiddenParents = $item.parents().andSelf().not(':visible'),
	        includeMargin = (includeMargin == null)? false : includeMargin;
	    
	    var oldProps = [];
	    $hiddenParents.each(function() {
	        var old = {};
	    
	        for ( var name in props ) {
	            old[ name ] = this.style[ name ];
	            this.style[ name ] = props[ name ];
	        }
	    
	        oldProps.push(old);
	    });
	    
	    dim.width = $item.width();
	    dim.outerWidth = $item.outerWidth(includeMargin);
	    dim.innerWidth = $item.innerWidth();
	    dim.height = $item.height();
	    dim.innerHeight = $item.innerHeight();
	    dim.outerHeight = $item.outerHeight(includeMargin);
	    
	    $hiddenParents.each(function(i) {
	        var old = oldProps[i];
	        for ( var name in props ) {
	            this.style[ name ] = old[ name ];
	        }
	    });
	    
	    return dim;
	},
	
	$.fn.getDimensions = $.fn.getHiddenDimensions
	
})(jQuery);



String.prototype.trim = function() {
	a = this.replace(/^\s+/, '');
	return a.replace(/\s+$/, '');
};
slice = Array.prototype.slice;
