function trimAll(sString)
{
while (sString.substring(0,1) == ' ')
{
sString = sString.substring(1, sString.length);
}
while (sString.substring(sString.length-1, sString.length) == ' ')
{
sString = sString.substring(0,sString.length-1);
}
return sString;
}


function groupstudyForm_Validator(groupstudyForm)
{
	//File
 if (trimAll(groupstudyForm.groupstudyname.value) == "" ||trimAll(groupstudyForm.groupstudyname.value) == "Name*")
 {
 alert("Please enter a value for the \"Name\" field.");
 groupstudyForm.groupstudyname.focus();
 return (false);
 }
	
//File
 if (trimAll(groupstudyForm.groupstudysubject.value) == ""||trimAll(groupstudyForm.groupstudysubject.value) == "Groupstudy Subject *" )
 {
 alert("Please enter a value for the \"Subject\" field.");
 groupstudyForm.groupstudytelephone.focus();
 return (false);
 }
	
 //Mobile
 if (trimAll(groupstudyForm.groupstudytelephone.value) == ""||trimAll(groupstudyForm.groupstudytelephone.value) == "Telephone*" )
 {
 alert("Please select \"Telephone\" to upload.");
 groupstudyForm.groupstudytelephone.focus();
 return (false);
 }
 var checkOK = "0123456789";
 var checkStr = groupstudyForm.groupstudytelephone.value;
 var allValid = true;
 var validGroups = true;
 for (i = 0; i < checkStr.length; i++)
 {
 ch = checkStr.charAt(i);
 for (j = 0; j < checkOK.length; j++)
 if (ch == checkOK.charAt(j))
 break;
 if (j == checkOK.length)
 {
 allValid = false;
 break;
 }
 }
 if (!allValid)
 {
 alert("Please enter only digit in the \"Telephone\" field.");
 groupstudyForm.groupstudytelephone.focus();
 return (false);
 }



//E-Mail
if (trimAll(groupstudyForm.groupstudyemail1.value) == "" || groupstudyForm.groupstudyemail1.value == "E-mail ID*" )
{
alert("Please enter a value for the \"E-Mail\" field.");
groupstudyForm.groupstudyemail1.focus();
return (false);
}
var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890_.@ \t\r\n\f";
var checkStr = groupstudyForm.groupstudyemail1.value;
var allValid = true;
var validGroups = true;
for (i = 0; i < checkStr.length; i++)
{
ch = checkStr.charAt(i);
for (j = 0; j < checkOK.length; j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
if (checkStr.indexOf('@') == -1 || checkStr.indexOf('.') == -1 )
{
allValid = false;
break;
}
}
if (!allValid)
{
alert("Please enter a valid id in the \"E-Mail \" field.");
groupstudyForm.groupstudyemail1.focus();
return (false);
}
return (true);
}
