/*
 * EasyGUI XP 1.0.293
 * Copyright(c) 2006-2008 Gaetan Lauff <glauff@plansoft.de>.
 * 
 * This code is licensed under BSD license. Use it as you wish, 
 * but keep the copyright intact.
 * 
 * ========================================================
 * 
 * Prototype JavaScript framework, version 1.6.0.2
 * (c) 2005-2008 Sam Stephenson
 * 
 * ========================================================
 * 
 * script.aculo.us scriptaculous.js v1.8.1
 * Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
 * 
 * ========================================================
 */

/**
 * @fileoverview Library for Sorting Algorithms
 * 
 * @author	Gaetan Lauff	<glauff@plansoft.de>
 * @version $Id: lib.sort.js 286 2007-12-13 15:30:41Z glauff $
 */
var Sort = 
{
	/**
	 * Qsort Compare Function
	 * Compares Date-, String-, Numeric- and Currency Values
	 * Used in addition to array sort functions
	 *
	 * @param	{mixed}	a	value a that should be compared to or an object with a member called value
	 * @param	{mixed} b	value b
	 * @returns mixed
	 */
	compareValues: function(a, b)
	{
		if ( typeof a.value != "undefined" )
		{
			a = a.value;
		}
			
		if ( typeof b.value != "undefined" )
		{
			b = b.value;
		}
			
		if ( a == null || a == 'undefined' || a === false )
		{
			return -1;
		}
		
		if ( b == null || b == 'undefined' || b === false )
		{
			return 1;
		}
	
		var res;
		/**
		 * Date Compare
		 */
		if ( a.match(/^\d\d[\/-]\d\d[\/-]\d\d\d\d$/) || a.match(/^\d\d[\/-]\d\d[\/-]\d\d$/) ) 
		{
			if (a.length == 10) 
			{
		        var date1 = a.substr(6,4) + a.substr(3,2) + a.substr(0,2);
		    } 
		    else 
		    {
		        var year = a.substr(6,2);
		
		        if ( parseInt( year ) < 50 ) 
		        {
		        	year = '20' + year; 
		        } 
		        else 
		        {
		        	year = '19' + year;
		        }
		        
		        date1 = year + a.substr(3,2) + a.substr(0,2);
		    }
		    
		    if (b.length == 10) 
		    {
		        var date2 = b.substr(6,4) + b.substr(3,2) + b.substr(0,2);
		    } 
		    else 
		    {
		        var year = b.substr(6,2);
		        
		        if (parseInt(year) < 50) 
		        {
		        	year = '20' + year;
		        } 
		        else 
		        {
		       		year = '19' + year;
		        }
		       		
		        date2 = year + b.substr(3,2) + b.substr(0,2);
		    }
		    
		    if (date1 == date2)
		    {
		    	res = 0;
		    }
		    	
		    if ( date1 < date2 )
		    {
		    	res = -1;
		    }
	    	
	    	res = 1;
	    /**
	     * Currency Compare
	     */
		} 
		else if ( a.match(/^[��$]|EURO/) || a.match(/[\d\.]\s+(EURO|[��$])/) ) 
		{
			//alert(" a before replace: " + a + " b before replace: " + b + "!");
			
			var c = a.replace(/[^0-9.]/g,'');
	    	var d = b.replace(/[^0-9.]/g,'');
			//alert("a has type " + typeof(a) + " and value " + a + "|b has type " + typeof(b) + " and value: " + b);
			    
	    	res = parseFloat(c) - parseFloat(d); 
	    /**
	     * Numeric Compare
	     */
		} 
		else if (!isNaN( parseInt(a) ) && !isNaN( parseInt(b) ) ) 
		{
			if ( a.indexOf('.') != -1 || a.indexOf(',') != -1 ) 
			{
				/**
				 * Float Compare
				 */
				var c = parseFloat(a);
	    
	    		if (isNaN(c)) 
	    		{
	    			c = 0;
	    		}
	    
	    		var d = parseFloat(b);
	    
	    		if (isNaN(d)) 
	    		{
	    			d = 0;
	    		}
	    	
	    		res = c - d;
			} 
			else 
			{
				/**
				 * Integer Compare
				 */
				res = parseInt( a ) - parseInt( b);
			}
		} 
		else 
		{
			/**
	     	*String compare
	     	*/
			res = 1;
			
			if ( a == b ) 
			{
	    		res = 0;
			}
	    	
	   		if ( a < b ) 
	   		{
	    		res = -1;
	   		}
		}
		
		if (descend) 
		{
	    	res = res * -1;
		}
	
	    return res;
	}
};