//////////////////
// clientutil.js
//////////////////

function TrimWord(str) {
	var re;
	
	re = /\s*/;
	str = str.replace(re, "");
	return str
}
	
	
function IsEmpty(str) {
	var tempstr, re;
	
	re = /\s*/g;
	tempstr = str.replace(re, "");
	if (tempstr.length == 0)
		return true;
	else
		return false;
}

function IsValidDate(sDate){
	var DateArray, vmonth, vday, vyear;
	
	DateArray = sDate.split("/");
	if (DateArray.length != 3)
		return false;
	else {
		vmonth = parseInt(DateArray[0], 10);
		vday = parseInt(DateArray[1], 10);
		vyear = parseInt(DateArray[2], 10);
		if (vyear < 10) 
			vyear += 2000;
		else if ((vyear > 10) && (vyear < 100))
			vyear += 1900;
		else
			vyear = vyear;

		if ((vmonth > 12) || (vmonth < 1))
			return false;
		if ((vday > 31) || (vday < 1))
			return false;
		if ((vyear < 1970) || (vyear > 3000))
			return false;
		if (((vmonth == 4) || (vmonth == 6) || (vmonth == 9) || (vmonth == 11)) && (vday > 30))			    
			return false;
		if (vmonth == 2)
			if (((vyear % 4) != 0) && (vday > 28))
				return false;
			else 
				if (vday > 29)
					return false;

	}
	return true;
}

function IsValidTime(sTime) {
	var TArray1, TArray2;
	
	TArray1 = sTime.split(" ");
	if (TArray1.length != 2)
		return false;
	TArray1[1] = TArray1[1].toUpperCase();
	if ((TArray1[1] == "AM") || (TArray1[1] == "PM"))
		; // Do nothing
	else
		return false;
	
	TArray2 = TArray1[0].split(":");
	if (TArray2.length != 2)
		return false;
	
	if ((parseInt(TArray2[0], 10) < 0) || (parseInt(TArray2[0], 10) > 12) ||
		(parseInt(TArray2[1], 10) < 0) || (parseInt(TArray2[1], 10) > 59))
		return false;
	return true;
}

function prepStr(str) {
	str = str.toLowerCase();
	str = str.replace(/['"-]/g, "");
	str = str.replace(/\W/g, " ");
	str = str.replace(/\s+/g, " ");
	return str;
	}

function camelCaps(str, theCase) {
	var tempArray = str.split(' ');

	// Make the first character of each word upper- or lowercase
	// depending on the value of theCase
	for (var i = 0; i < tempArray.length; i++) {
		if (theCase) {
			tempArray[i] = tempArray[i].charAt(0).toUpperCase() + tempArray[i].substring(1);
			}
		else {
			tempArray[i] = tempArray[i].charAt(0).toLowerCase() + tempArray[i].substring(1);
			}
		}
	return tempArray.join(' ');
}


function openWindowLink(pageURL, winName) {
	window.open(pageURL, winName,
				'directories=no, location=no, menubar=no, scrollbars=yes, status=yes, toolbar=no, resizable=yes')
}

