// *******************************************
//	LaunchWindow(
//		Url of new window,
//		Name of new window,
//		(Optional) Close existing window
//		)
// *******************************************
//  This function is responsibile for
//  opening new windows and cleaning up after
//  previously opened windows with the same
//  name
// *******************************************
function LaunchWindow(Url, Name, Cleanup)
{
	if(Cleanup != void(0) && Cleanup == true)
	{
		//
		// Check for existing window
		if(window[Name] != void(0) && window[Name] != null)
			//
			// Close existing window
			window[Name].close();
	}
	
	//
	// Open the new window
	window.open(Url, Name, null);
}

function IsDateValid(dtInput)
{
    if(Trim(dtInput).length > 0)
    {
		var match = dtInput.match(/^[ ]*[0]?(\d{1,2})\/(\d{1,2})\/(\d{4,})[ ]*$/);
		
		if (match)
		{
			var tmpdate = new Date(match[3], parseInt(match[1], 10) - 1, match[2]);
			if (tmpdate.getDate() == parseInt(match[2], 10) && tmpdate.getFullYear() == parseInt(match[3], 10) && (tmpdate.getMonth() + 1) == parseInt(match[1], 10))
				return true;
		}
		
		return false;
    }
    else
		return true;
}

function Trim(str){return str.replace(/^\W*|\W*$/gi,"");}
function RTrim(str){return str.replace(/\W*$/,"");}
function LTrim(str){return str.replace(/^\W*/,"");}