// Array Remove - By John Resig (MIT Licensed)
Array.prototype.del = function(from, to) { /* renamed because ext.js defines a different remove() */
  var rest = this.slice((to || from) + 1 || this.length);
  this.length = from < 0 ? this.length + from : from;
  return this.push.apply(this, rest);
};

Array.prototype.join_quoted = function(glue_ch, seperator_ch, quote_ch) {
	if(!quote_ch) quote_ch = '"';
	var i;
	var result = '';
	for(i = 0; i < this.length; i++) {
		if(this[i].indexOf(seperator_ch) > 0) {
			result += quote_ch + this[i] + quote_ch;
		} else {
			result += this[i];
		}
		if(i < this.length-1) {
			result += glue_ch;
		}
	}

	return result;
}

String.prototype.split_quoted = function(seperator_ch, quote_ch) {
	if(!quote_ch) quote_ch = '"';

	var in_quote = false;
	var i;
	var token = '';
	var result = new Array();

	for(i = 0; i < this.length; i++) {
		if(!in_quote) {
			switch(this[i]) {
				case quote_ch:
					add_token();
					in_quote = true;
					break;
				case seperator_ch:
					add_token();
					break;
				default:
					token += this[i];
			}
		} else {
			switch(this[i]) {
				case quote_ch:
					add_token();
					in_quote = false;
					break;
				default:
					token += this[i];
			}
		}
	}

	add_token();

	function add_token() {
		if(token.trim() != '') {
			result.push(token);
		}
		token = '';
	}

	return result;
}

String.prototype.is_valid_url = function()
{
	length = self.length;
	if(length > 0) {
		var j = new RegExp();
		j.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");
		if (j.test(self)) {
			return true;
		}
	}

	return false;
}

function setSelectionRange(input, selectionStart, selectionEnd)
{
  if (input.setSelectionRange) {
	input.focus();
	input.setSelectionRange(selectionStart, selectionEnd);
  } else if (input.createTextRange) {
	var range = input.createTextRange();
	range.collapse(true);
	range.moveEnd('character', selectionEnd);
	range.moveStart('character', selectionStart);
	range.select();
  }
}

jQuery.fn.ajaxSubmit = function(parent, handler) {
	var params = {};
	
	jQuery(this).find("input[@checked], input[@type='text'], input[@type='hidden'], input[@type='password'], input[@type='submit'], option[@selected], textarea")
	  .filter(":enabled")
	  .each(function() {
	    params[ this.name || this.id || this.parentNode.name || this.parentNode.id ] = this.value;
	});
	
	//$("body").addClass("curWait");
	jQuery(parent).load(this.attr("action"), params, handler);
	
	return this;
}
