﻿// JScript File

Type.registerNamespace("QPM");

// String functions
//
String.prototype.asAttribute= function()
{
	return this.replaceAll("\"", '&quot;').replaceAll('\'','&#39;');
}

String.prototype.asEscapedHtml = function()
{
	return this.replaceAll('&', '&amp;').replaceAll('>', '&gt;').replaceAll('<', '&lt;');
}

String.prototype.asText = function()
{
	return this.replaceAll('&amp;', '&').replaceAll('&gt;', '>').replaceAll('&lt;', '<').replaceAll('&quot;',"\"").replaceAll('&#39;','\'');
}

//
//
String.prototype.trim = function()
{
	// TODO: This code not compatible with IE lte 5.0
	//
	var sInString = this.replace(/ /g,' ');
	return sInString.replace(/(^\s+)|(\s+$)/g, "");
	//return this.replace(new RegExp("^\s*(.+?)\s*$","ig"),'$1')
}

String.prototype.replaceAll = function(pattern,replacement)
{
	// TODO: Escape pattern asRegExp
	//
	return this.replace(new RegExp(pattern,"g"),replacement)
}


QPM.isArray = function(object)
{
	if (object == null) return false;
	
	return (object.constructor.toString().indexOf("Array") != -1)
}