// JavaScript Document

/* By Mohammad Sajjad Hossain*/
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

function URLDecode(psEncodeString)
{
  // Create a regular expression to search all +s in the string
  var lsRegExp = /\+/g;
  // Return the decoded string
  return unescape(String(psEncodeString).replace(lsRegExp, " "));
}

function confirmDelete(entity) {
	return confirm("Are you sure you want to delete " + entity + "?");
}

function isNumeric(value, errorMessage)
{
	var regex = /^\d+$/;

	if (!regex.test(value))
	{
		alert(errorMessage);
		return false;
	}
	else
	{
		return true;
	}
}

function openWindow(url, width, height)
{
	window.open(url, "", "height=" + height + ",width=" + width + "location = 0, status = 1, resizable = 0, scrollbars=1, toolbar = 0");
}

function openResizableWindow(url, width, height)
{
	window.open(url, "", "height=" + height + ",width=" + width + "location = 0, status = 1, resizable = 1, scrollbars=1, toolbar = 0");
}

function refreshParent(url, closeMe)
{
	parent.location = url;

	if(closeMe != undefined && closeMe)
	{
		self.close();
	}
}

function pad(number,length) {
    var str = '' + number;
    while (str.length < length)
        str = '0' + str;
    return str;
}

function hasNoInvalidCharacter(value)
{
	invalidChars = ["|", "~"];

	for(i = 0; i < invalidChars.length; i++)
	{
		if(value.indexOf(invalidChars[i]) != -1)
		{
			return false;
		}
	}
	return true;
}
