/*========================================
 * OBJECT: Utils
 *=======================================*/
Utils = (IsUndef("Utils")) ? new Object() : Utils;

Utils.GetSlug = function(str) {
	/*str = str.toLowerCase().trim();
	slug = "";
	for(var i = 0 ; i < str.length ; ++i) {
		if(97 <= str.charCodeAt(i) && str.charCodeAt(i) <= 122) {
			slug += str.charAt(i);
		} else if(str.charAt(i) == " " && i + 1 < str.length - 1) {
			slug += "_";
		} else if(0 <= str.charAt(i) && str.charAt(i) < 9) {
			slug += str.charAt(i);
		} else if(str.charAt(i) == "." && i < str.length - 1) {
			slug += "_dot_";
		} else {
			slug += "_";
		}
	}
	return slug;*/
	
	num_chars = 50; // default SlugField length
	str = str.toLowerCase().trim();
	// changes, e.g., "Petty theft" to "petty_theft"
    // remove all these words from the string before urlifying
    removelist = ["a", "an", "as", "at", "before", "but", "by", "for", "from",
                  "is", "in", "into", "like", "of", "off", "on", "onto", "per",
                  "since", "than", "the", "this", "that", "to", "up", "via",
                  "with"];
    r = new RegExp('\\b(' + removelist.join('|') + ')\\b', 'gi');
    str = str.replace(r, '');
    str = str.replace(/[^-\w\s]/g, '');  // remove unneeded chars
    str = str.replace(/^\s+|\s+$/g, ''); // trim leading/trailing spaces
    str = str.replace(/[-\s]+/g, '-');   // convert spaces to hyphens
    str = str.toLowerCase();             // convert to lowercase
    return str.substring(0, num_chars);// trim to first num_chars chars
    //return str;
}

//alert(Utils.GetSlug("a 2 3"));

Utils.GetParent = function(obj) {
	var result;
	try {
		result = obj.parentNode;
	}
	catch(err) {
		result = obj.parentElement;
	}

	return result;
}
