var whitespace = " \t\n\r";
var doublequote = '\"';
var defaultEmptyOK = false;

function isEmpty(s){
	return ((s == null) || (s.length == 0))
}

function jtrim(strvalue){
	while (strvalue.charAt(0) == " "){
		strvalue = strvalue.substring(1);
  	}
  	while (strvalue.charAt(strvalue.length-1) == " "){
  		strvalue = strvalue.substring(0,strvalue.length-1)
  	} 	
	return strvalue;
}

function isWhitespace (s){
	var i;
	// Is s empty?
	if (isEmpty(s)) return true;

	// Search through string's characters one by one
	// until we find a non-whitespace character.
	// When we do, return false; if we don't, return true.
	for (i = 0; i < s.length; i++) {   
	// Check that current character isn't whitespace.
		var c = s.charAt(i);
				
		if (whitespace.indexOf(c) == -1) return false;
	}
			
	// All characters are whitespace.
	return true;
}

function isEmail (s){
	if (isEmpty(s))
	// is s whitespace?
	if (isWhitespace(s)) return false;
	 
	// there must be >= 1 character before @, so we
	// start looking at character position 1
	// (i.e. second character)
	var i = 1;
	var sLength = s.length;
	 
	// look for @
	while ((i < sLength) && (s.charAt(i) != "@")) i++;
	if ((i >= sLength) || (s.charAt(i) != "@")) return false;
	else i += 2;
	 
	// look for .
	while ((i < sLength) && (s.charAt(i) != ".")) i++;
	 
	// there must be at least one character after the .
	if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
	else return true;
}

function isCharsInBag (s, bag){  
	var i;
	// Search through string's characters one by one.
	// If character is in bag, append to returnString.

	for (i = 0; i < s.length; i++){   
		// Check that current character isn't whitespace.
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1) return false;
	}
	return true;
}

function ReplaceDoubleQuote (s){
	for (i = 0; i < s.length; i++){   
		// Check that current character isn't whitespace.
		var c = s.charAt(i);
		if (doublequote.indexOf(c) >= 0) s.replace('"','\"')
	}
	return s;
}

function populate(objForm,objYear,objMonth,objDay) {
	timeA = new Date(objYear.options[objYear.selectedIndex].text, objMonth.options[objMonth.selectedIndex].value, 1);
	timeDifference = timeA - 86400000;
	timeB = new Date(timeDifference);
	var daysInMonth = timeB.getDate();
	for (var i = 0; i < objDay.length; i++) {
		objDay.options[0] = null;
	}
	for (var i = 0; i < daysInMonth; i++) {
		objDay.options[i] = new Option(i+1,i+1);
	}
}

function LaunchWin(url, name, winwidth, winheight){
	window.open(url,name,'scrollbars=yes,resizable=no,menubar=no,statusbar=no,width='+winwidth+',height='+winheight);
}