function trim(strTrim)
{
	var i = 0, j = strTrim.length - 1;
	while (strTrim.charAt(i) == " ") {i++;}
	while (strTrim.charAt(j) == " ") {j--;}
	return (j < 0) ? "" : strTrim.substring(i, j+1);
}
function cleanDate(_strDate, _delim)
{
	var myRegExp = /[^\d]*(\d{1,2})[^\d]*(\d{1,2})[^\d]*(\d+)[^\d]*/;
	return _strDate.replace(myRegExp, "$1" + _delim + "$2" + _delim + "$3");
}
function cleanEmail(mStr)
{
	var newStr = '';
	for (var i = 0; i<mStr.length; i++)
	{
		var ch = mStr.charAt(i).toLowerCase();
		if ((ch >= "a" && ch <= "z") || (ch == "@") || (ch == ".") || (ch == "_") || (ch == "-") || (ch >= "0" && ch <= "9")) {newStr += ch;}
	}
	return newStr;
}
function isValidEmail(mStr)
{
//	if ((mStr.indexOf('@@') == -1) && (mStr.indexOf('..') == -1) && (mStr.indexOf('.@') == -1) && (mStr.indexOf('@.') == -1))
//	{
//		var at = mStr.indexOf('@',1);
//		if (at != -1)
//		{
//			var dot = mStr.indexOf('.', at+3);
//			if (dot != -1)
//			{
//				dot = mStr.lastIndexOf('.');
//				if (dot+2 < mStr.length) {if (mStr == cleanEmail(mStr)) {return true;}}
//			}
//		}
//	}
//	return false;

	var x = mStr;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

	if (filter.test(x))
		return true;
	else
		return false;
}
function groupChecked(_checkGroup)
{
	var checkFound = false;
	for (var i=0; i < _checkGroup.length; i++)
	{
		if ( _checkGroup[i].checked )
		{
			checkFound = true;
			break;
		}
	}
	return checkFound;
}
function popWin(_w, _h, _text)
{
	myPop = window.open('', 'popPic', 'directories=0,location=0,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0,width=' + _w + ',height=' + _h);
	myPop.moveTo(320, 240);
//	myPop.resizeTo(myW, myH);
	myPop.document.open();
	myPop.document.write(
		 '<html>'
		+'<head>'
			+'<title>IPS / E-mail Dienst</title>'
			+'<style type="text/css">BODY{font-family:Arial,Sans-Serif;font-size:12px;}</style>'
			+'<script type="text/javascript">self.focus();</script>'
		+'</head>'
		+'<body><div style="cursor:pointer;font-size:10px;color:#cc0000;float:right;clear:all;text-decoration:underline;" onclick="self.close();">sluit venster</div><br>' + _text + '</body>'
		+'</html>'
	)
	myPop.document.close();
}

// # registration
function emailServiceChange(_FORM)
{
	if (_FORM['contents[IDContents][]'])
	{
		if (_FORM['contents[IDContents][]'].length)
		{
			for( i=0; i < _FORM['contents[IDContents][]'].length ;i++)
			{
				_FORM['contents[IDContents][]'][i].checked = false;
			}
		}
		else
			_FORM['contents[IDContents][]'].checked = false;
	}
}

function checkValidDate(_strDate, _strDelim)
{ // assumes input format: dd-mm-yyyy

	arrDateParts = _strDate.split(_strDelim);
	if (arrDateParts.length == 3)
	{
		return isValidDate(parseInt(arrDateParts[2], 10), (parseInt(arrDateParts[1], 10) - 1), parseInt(arrDateParts[0], 10));
	}
	else
		return false;
}
function isValidDate(_intY, _intM, _intD)
{
	return ( (_intM > -1 && _intM < 12) && (_intD > 0 && _intD  <= getDaysInMonth(_intY, _intM)) );
}
function getDaysInMonth(_intY, _intM)
{
	var myIntFeb = ( (_intY%4 == 0 && _intY%100 != 0) || _intY%400 == 0 ) ? 29 : 28;
	var myArrDaysInMonths = [31,myIntFeb,31,30,31,30,31,31,30,31,30,31];
	return myArrDaysInMonths[_intM];
}

