// Extending the STRING object


String.prototype.toDateFromDDMMYY = function()
{
	//REgular expression to test character '/'
	var oRe = /\//gi;
	
	//If date is not delemited by the character '/'
	//if(!oRe.test(this))
	if(this.indexOf('/') == -1)
	{
		throw new Error('String.toDateFromDDMMYY() expects date \'' + this + '\' delimited with character \'/\'');
	}
	
	//split date string
	var split = this.split(oRe);
	
	//Regular expression to check whether data starts with a '0' character
	var oRe = /^0/gi;
	
	//Get date parts
	//var day = (oRe.test(split[0]) == true) ? split[0].substring(1) : split[0];
	//var month = (oRe.test(split[1]) == true) ? split[1].substring(1) : split[1];
	var day = (split[0].substring(0,1) == '0') ? split[0].substring(1) : split[0];
	var month = (split[1].substring(0,1) == '0') ? split[1].substring(1) : split[1];
	var year = split[2];
	
	//if(Secondary._LOG_ENABLED)LOG.printH1(day + '/' + month + '/' + year);
	
	//Validate date
	if(isNaN(day) || isNaN(month) || isNaN(year))
	{
		throw new Error('String.toDateFromDDMMYY() expect date \'' + this + '\' with numerica values for day(' + day + '), month(' + month + ') and yesr (' + year + ')');
	}
	
	//Set date
	var oDate = new Date();
	oDate.setFullYear(parseInt(year),parseInt(month) - 1, parseInt(day), 0, 0, 0);
	
	return oDate;
};

//Returns date from date string e.g. 'August 28 2008'
String.prototype.toDateFromMonthDDYY = function()
{
	var dateSplit = this.split(/,?\s/gi);
	
	if(dateSplit.length != 3)
	{
		throw new Error('String.toDateFromMonthDDYY() the Date \'' + this + '\' does not match the expected format of \'August 22, 2008\'');
	}
	
	if(isNaN(dateSplit[1]))throw new Error('String.toDateFromMonthDDYY() expects a numeric value for the day');
	if(isNaN(dateSplit[2]))throw new Error('String.toDateFromMonthDDYY() expects a numeric value for the year');
	
	var index = -1;
	var months = ['jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec'];
	for(var i = 0; i < months.length; i++)
	{
		if(dateSplit[0].toLowerCase().indexOf(months[i]) != -1)
		{
			index = i;
		}
	}
	
	if(index == -1)
	{
		throw new Error('String.toDateFromMonthDDYY() Month in date does not match any of the months in the year');
	}
	
	var day = (dateSplit[1].substring(0,1) == '0') ? dateSplit[1].substring(1) : dateSplit[1];
	var month = index;
	var year = dateSplit[2];
	
	//Set date
	var oDate = new Date();
	oDate.setFullYear(parseInt(year),month, parseInt(day), 0, 0, 0);	
	return oDate;
	
};

String.prototype.trim = function () 
{
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}