function mod_rewrite_safe(text) {

	text = trim(text.replace(/[^a-z0-9\-\_]/gi, '-').replace(/\-{2,}/g, "-").toLowerCase(),'-');
;
	return text;
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function ucwords (str) { 
// Uppercase the first character of every word in a string   
//  
// version: 909.322 
// discuss at: http://phpjs.org/functions/ucwords 
// +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com) 
// +   improved by: Waldo Malqui Silva 
// +   bugfixed by: Onno Marsman 
// *     example 1: ucwords('kevin van zonneveld'); 
// *     returns 1: 'Kevin Van Zonneveld' 
// *     example 2: ucwords('HELLO WORLD'); 
// *     returns 2: 'HELLO WORLD' 
return (str+'').replace(/^(.)|\s(.)/g, function ( $1 ) { return $1.toUpperCase( ); } ); 
}

function validate_price(str) {
	return Boolean(str.match(/^\d+(?:\.\d{2})?$/m));
}

function validate_postive_integer(str) {
	return Boolean(str.match(/^\d+$/m));
}

function convertToArray(obj, n) {   
   if (! obj.length) {return [];} // length must be set on the object, or it is not iterable   
   var a = [];   
  
   try {   
       a = Array.prototype.slice.call(obj, n);   
   }   
   // IE 6 and posssibly other browsers will throw an exception, so catch it and use brute force   
   catch(e) {   
		Core.batch(obj, function(o, i) {   
           if (n <= i) {   
               a[i - n] = o;   
           }   
       });   
   }   
  
   return a;   
};  

function confirm(msg,callback,title) {
	if( $('#jq_confirm').size() == 0 ) {
		create_jq_confirm();	
	}
	$('.jq_confirm_title').html(title);
	$('.jq_confirm_message').html(msg);
	$('#jq_confirm_trigger').click();
		
	$('div#fancy_div form.jq_confirm_form input:submit').click(function(){
		
	
		$.fn.fancybox.close();			
		if(this.value == 'Yes') {
		  if (typeof callback == 'string') {
			window.location.href = callback;
		  } else {
			callback();
		  }
		}
		
		return false;	
		
	});
	
	return false;
}

function create_jq_confirm() {
	var html = '';
	
	html = 	'<div style="display:none;" id="jq_confirm">' +
			'<form action="" class="jq_confirm_form" method="post" style="width: auto; height: 95%; margin: 0; padding: 10px 0 0 0; position: relative;">' +
        	'<p style="width: 95%; margin: 0; padding: 0 30px 10px 10px; color: #333;">' +
			'<strong class="jq_confirm_title"></strong></p>' +
			'<p style="width: 95%; margin: 0; padding: 0 30px 10px 20px; color: #fff;" class="jq_confirm_message"></p>' +
			'<div style="padding: 10px; position: absolute; bottom: 5px; left: 80px;">' +
			'<input class="submit" style="display: inline; margin: 0 5px; width: 100px;" type="submit" value="No" />' +
			'<input class="submit" style="display: inline; margin: 0 5px; width: 100px;" type="submit" value="Yes" />' +
			'</div>' +
			'</form>' +
			'</div>' +
			'<a href="#jq_confirm" id="jq_confirm_trigger" style="display: none;"></a>';
	
	$('body').append(html);
	
	$('#jq_confirm_trigger').fancybox({
		'zoomOpacity'			: true,
		'overlayShow'			: true,
		'zoomSpeedIn'			: 500,
		'zoomSpeedOut'			: 500,
		'frameWidth'			: 400,
		'frameHeight'			: 150,
		'easingIn'				: 'easeOutBack',
		'easingOut'				: 'easeInBack',
		'hideOnContentClick': false
		
	});
}

// A prototype safe version of the for ... in array.
// By prototype safe I mean it doesn't count functions added to the prototype
function foreach(obj, callback){
 var proto = obj.constructor.prototype,
  h = obj.hasOwnProperty, key;
 for(key in obj) {
  if((h && h.call(obj,key)) || proto[key] !== obj[key])
   callback(key, obj[key]);
 }
};


// Array.unique( ) - Remove duplicate values
Array.prototype.unique = function() {
    for (i=0; i<this.length; i++) {
        for (j=0; j<this.length-i; j++) {
            if (this[i] == this[i+j+1]) {
                this.splice(i+j+1, 1);
                j--;
            }
        }
    }
    return this;
};

// Array.size( ) - Get the length of an associative array...
Array.prototype.size = function() {
	size = 0;
    foreach( this, function( key, val ) {
		size++;							
	});
	return size;
};

function sizeof(object) {
	size = 0;
    foreach( object, function( key, val ) {
		size++;							
	});
	return size;
}


