
function trimString(sInString) {
	sInString = sInString.replace(/^\s+/g, "");
	return sInString.replace(/\s+$/g, "" );
}

function checkUrl(url) {
	url = url.replace(/https?:\/\//, "");
	var filter = /^([a-z0-9._-]+:[a-z0-9._-]+@)?[a-z0-9äöüÄÖÜ#._\/~% -]+(\?([a-z0-9_-]+(=[a-zA-Z0-99äöüÄÖÜß+%?_-]+&?)?)*)?$/i;
	return filter.test(url);
}

function checkMail(email) {
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return filter.test(email);
}

function checkFields(fields) {
	for (var fld in fields)	{
		if (trimString(fields[fld].value) == "") {
			fields[fld].focus();
			fields[fld].select();
			return false;
		}
	}

	return true;
}

function validateForm(frm) {
	with (frm) {
		if (!checkFields([txtName, txtUrl, txtDesc, txtEmail]))	{
			alert("Please fill all the required fields!");
			return false;
		}
		if (!checkUrl(txtUrl.value)) {
				("Please enter a valid URL!");
			txtUrl.focus();
			txtUrl.select();
			return false;
		}
		if (!checkMail(txtEmail.value)) {
			alert("Please enter a valid email address!");
			txtEmail.focus();
			txtEmail.select();
			return false;
		}
	}

	return true;
}
