function trim(str)
{
	var newString = str + ''
	newString = newString.replace(/\s+/g,"");
	return newString
}			

function ValidateRequiredField(ctrlID)
{
	if (trim(document.getElementById(ctrlID).value).length < 1)
		return false
	else
		return true
}

function ValidateRequiredDecimal(ctrlID)
{
	var valid = true
	var dec = trim(document.getElementById(ctrlID).value)
	if (dec.length < 1)
		valid = false
	else
	{
		if (!isDecimal(dec))
			valid = false
		else
			document.getElementById(ctrlID).value = parseFloat(dec)
	}
	
	return valid
}

function isNumeric(string)
{
	var strToTest = trim(string)
	var valid = true

	if (strToTest.length==0)
		valid = false
	else
	{
		for (var i=0;i<strToTest.length; i++)
		{
			var x = parseInt(strToTest.charAt(i))
			if (isNaN(x))
			{
				valid = false;
				break;
			}	
		}
	}
	
	return valid	
}

function isDecimal(string)
{
	var strToTest = trim(string)
	var valid = true
	
	if (strToTest.length==0)
		valid = false
	else
	{
		for (var i=0;i<strToTest.length; i++)
		{
			var x = parseInt(strToTest.charAt(i))
			var dot = strToTest.charAt(i)
			if ((isNaN(x)) && (dot!='.'))
			{
				valid = false;
				break;
			}	
		}
		
		var x = parseFloat(strToTest)
		if (isNaN(x))
		{
			valid = false;
		}	
	}
			
	return valid	
}

function isDate(dateStr) 
{
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{2,4})$/;
	var matchArray = dateStr.match(datePat); // is the format ok?
	var valid = true
	
	
	if (matchArray == null) 
		valid = false
	else
	{
		month = matchArray[1]; // p@rse date into variables
		day = matchArray[3];
		year = matchArray[5];

		if (month < 1 || month > 12) 
			valid = false;

		if (day < 1 || day > 31)	
			valid = false;

		if ((month==4 || month==6 || month==9 || month==11) && day==31) 
			valid = false;

		if (month == 2) 
		{ 
			// check for february 29th
			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			if (day > 29 || (day==29 && !isleap)) 
				valid = false
		}
	}

	return valid
}

function IsWithinNumericRange(number, min, max)
{
	var valid = isDecimal(number)
	if (number<min || number>max)	
	{
		valid = false
	}
	
	return valid
}

//this function clicks the desired button on an enter keypress
function enterClick(btnID)
{	
	if (event.keyCode == 13)
	{ 
		document.getElementById(btnID).click();	
		event.returnValue=false;
		event.cancel = true;
			
	} 
}

function ReadMore(parm, size)
{
	var setSize = "width=300, height=300"
	switch(size)
	{
		case "M" : setSize = "width=400, height=400"; break;
		case "L" : setSize = "width=500, height=500"; break;
	}
		
	window.open("/readMore.aspx?" + parm, "more", setSize + ", toolbars=no, scrollbars=3")
}
