//######################################################################################################
// Removes both Leading and Trailing blanks.
//

function removeAllSpaces(str)
{
   str = removeLeadingSpaces(str); //Remove Leading Spaces
   str = removeTrailingSpaces(str); //Remove Trailing Spaces
   return str;
}
//######################################################################################################

//######################################################################################################
// This method is used to remove both Leading spaces.
// It takes argument of the string which Leding Spaces has to removed.

function removeLeadingSpaces(str)
{
   var whitespace = new String(" \t\n\r");
   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1)
    {
      var j=0, i = s.length;
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)  j++;
      s = s.substring(j, i);
    }
   return s;
}
//######################################################################################################

//######################################################################################################
// This method is used to remove Trailing spaces.
// It takes argument of the string which Trailing Spaces has to removed.

function removeTrailingSpaces(str)
{
   var whitespace = new String(" \t\n\r");
   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1)
   {
      var i = s.length - 1;       // Get length of string
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1) i--;

      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}
//######################################################################################################

//######################################################################################################
// This methods takes email address as an argument and validate the email.
// It returns TRUE if email is valid, FALSE otherwise.

function validateEmail(emailStr)
{
	/* The following pattern is used to check if the entered e-mail address
	   fits the user@domain format.  It also is used to separate the username
	   from the domain. */

	var emailPat=/^(.+)@(.+)$/

	/* The following string represents the pattern for matching all special
	   characters.  We don't want to allow special characters in the address. 
	   These characters include ( ) < > @ , ; : \ " . [ ]    
	*/

	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"

	/* The following string represents the range of characters allowed in a 
	   username or domainname.  It really states which chars aren't allowed.
	*/

	var validChars="\[^\\s" + specialChars + "\]"

	/* The following pattern applies if the "user" is a quoted string (in
	   which case, there are no rules about which characters are allowed
	   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	   is a legal e-mail address. 
	*/

	var quotedUser="(\"[^\"]*\")"

	/* The following pattern applies for domains that are IP addresses,
	   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	   e-mail address. NOTE: The square brackets are required.
	*/

	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/

	/* The following string represents an atom (basically a series of
	   non-special characters.) 
	*/

	var atom=validChars + '+'

	/* The following string represents one word in the typical username.
	   For example, in john.doe@somewhere.com, john and doe are words.
	   Basically, a word is either an atom or quoted string.
	*/

	var word="(" + atom + "|" + quotedUser + ")"

	// The following pattern describes the structure of the user

	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")

	/* The following pattern describes the structure of a normal symbolic
	   domain, as opposed to ipDomainPat, shown above. 
	*/

	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

	/* Finally, let's start trying to figure out if the supplied address is
	   valid. 
	*/

	/* Begin with the coarse pattern to simply break up user@domain into
	   different pieces that are easy to analyze.
	*/

	var matchArray=emailStr.match(emailPat)

	if (matchArray==null)
	{
	  /* 
		 Too many/few @'s or something; basically, this address doesn't
		 even fit the general mould of a valid e-mail address. 
	  */
		return false
	}

	var user=matchArray[1]
	var domain=matchArray[2]

	// See if "user" is valid 
	if (user.match(userPat)==null)
	{
		// user is not valid
		return false
	}

	/* 
	   if the e-mail address is at an IP address (as opposed to a symbolic
	   host name) make sure the IP address is valid.
	*/

	var IPArray=domain.match(ipDomainPat)

	if (IPArray!=null)
	{
		// this is an IP address
		  for (var i=1;i<=4;i++)
		  {
			if (IPArray[i]>255)
			{
			  return false
			}
		}
		return true
	}

	// Domain is symbolic name
	var domainArray=domain.match(domainPat)

	if (domainArray==null)
	{
		return false
	}

	/* domain name seems valid, but now make sure that it ends in a
	   three-letter word (like com, edu, gov) or a two-letter word,
	   representing country (uk, nl), and that there's a hostname preceding 
	   the domain or country.
	*/

	/* Now we need to break up the domain to get a count of how many atoms
	   it consists of.
	*/

	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length

	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3)
	{
	   // the address must end in a two letter or three letter word.
	   return false
	}

	// Make sure there's a host name preceding the domain.
	if (len<2)
	{
	   return false
	}

	 return true;
}
//######################################################################################################


//######################################################################################################
// This function will check admin login 
//

function isCheckboxSelected(frm)
{
  var sel_status=false;

  for (var ctr=0; ctr < frm.length; ctr++)
  {
    var field_name = frm.elements(ctr).name;
	if ((field_name.indexOf("|") > 0) && (frm.elements(ctr).checked))
	{
	   sel_status= true;
	   break;       
	 }
  }
  
  return sel_status;

}

//######################################################################################################
// This function will check admin login 
//

function isRadioSelected(frm)
{
  var sel_status=false;

  for (var ctr=0; ctr < frm.length; ctr++)
  {
    var field_name = frm.elements(ctr).name;
	
	if ((field_name.indexOf("|") > 0) && (frm.elements(ctr).checked))
	{
	   sel_status= true;
	   break;       
	}

  }

  return sel_status;

}
//######################################################################################################

//######################################################################################################
// This function will check admin login 
//

function checkAdminLogin(frm)
{
  var login = frm.login.value;
  var password = frm.password.value;
  
  //Remove leading and trailing spaces.
  if (login.length > 0)
  {
    login = removeAllSpaces(login);
	frm.login.value = login;
  }
  
  //Display alert if login is blank
  if (!login)
  {
    alert("Login should not be blank.");
	frm.login.focus();
	return false;
  }
  
  //Remove Leading and Trailing spaces from password.
  if (password.length > 0)
  {
    password = removeAllSpaces(password);
	frm.password.value = password;
  }
  
  //Display error if password is blank.
  if (!password)
  {
    alert("Password should not be blank.");
	frm.password.focus();
	return false;
  }
   
   return true;
}
//######################################################################################################

//######################################################################################################
//
// This function will check Admin Registration Form.

function checkAdminRegForm(frm)
{
  
  var first_name = frm.first_name.value;
  var last_name = frm.last_name.value;
  var login = frm.login.value;
  var password = frm.password.value;
  var re_password = frm.re_password.value;
  var email = frm.email.value;
  
  //Remove Leading and Trailing Spaces  
  if (first_name.length > 0)
  {
    first_name = removeAllSpaces(first_name);
	frm.first_name.value = first_name;
  }
  
  //Display alert message if first_name is blank.
  if (!first_name)
  {
    alert("First name should not blank.");
	frm.first_name.focus();
	return false;
  }
  
  //Remove Leading and Trailing Spaces  
  if (last_name.length > 0)
  {
    last_name = removeAllSpaces(last_name);
	frm.last_name.value = last_name;
  }
  
  //Display alert message if last_name is blank.
  if (!last_name)
  {
    alert("Last name should not blank.");
	frm.last_name.focus();
	return false;
  }
  
  //Remove Leading and Trailing Spaces  
  if (login.length > 0)
  {
    login = removeAllSpaces(login);
	frm.login.value = login;
  }
  
  //Display alert message if login is blank.
  if (!login)
  {
    alert("Login name should not blank.");
	frm.login.focus();
	return false;
  }
  
  //Remove Leading and Trailing Spaces  
  if (password.length > 0)
  {
    password = removeAllSpaces(password);
	frm.password.value = password;
  }
  
  //Display alert message if password is blank.
  if (!password)
  {
    alert("Password should not blank.");
	frm.password.focus();
	frm.password.value="";
	return false;
  }
  
  //Remove Leading and Trailing Spaces  
  if (re_password.length > 0)
  {
    re_password = removeAllSpaces(re_password);
	frm.password.value = password;
  }
  
  //Display alert message if re_password is blank.
  if (!re_password)
  {
    alert("Confirm password should not blank.");
	frm.re_password.focus();
	frm.re_password.value="";
	return false;
  }
  
  //Match Password and Confirm passord. Display error if they does not match.
  for (var ctr=0;ctr < password.length ; ctr++)
  {
     if (password.charAt(ctr) != re_password.charAt(ctr))
	 {
		 alert("Password does not match. Please re-enter.");
		 frm.re_password.value = "";
		 frm.re_password.focus();
		 return false;
	 }
  }
  
  //Remove Leading and Trailing Spaces  
  if (email.length > 0)
  {
    email = removeAllSpaces(email);
	frm.email.value = email;
  }
  
  //Display alert message if email is blank.
  if (!email)
  {
    alert("Email should not blank.");
	frm.email.focus();
	return false;
  }  
  else
  {
    if (validateEmail(email)== false)
	{
	  alert("Please enter valid email.");
	  frm.email.focus();
	  return false;
	}
  } 
      
  return true;    
}
//######################################################################################################

//######################################################################################################
// This function will check PasswordForm.
//
  
 function checkPasswordForm(frm)
 {
    var email = frm.email.value;
	 
     //Remove Leading and Trailing Spaces  
	  if (email.length > 0)
	  {
		email = removeAllSpaces(email);
		frm.email.value = email;
	  }
	  
	  //Display alert message if email is blank.
	  if (!email)
	  {
		alert("Email should not blank.");
		frm.email.focus();
		return false;
	  }  
	  else
	  {
		if (validateEmail(email)== false)
		{
		  alert("Please enter valid email.");
		  frm.email.focus();
		  return false;
		}
	  }
	  	  
    return true;   
 } 
//######################################################################################################

//######################################################################################################
//This function will check faculty registrtion form.

function checkFacultyForm(frm)
{
  
  var user_id = frm.user_id.value; 
  var password = frm.password.value;
  var re_password = frm.re_password.value;  
  var first_name = frm.first_name.value; 
  var last_name = frm.last_name.value;
  var email = frm.email.value;
  var house_name = frm.house_name.value;
  var phone_office = frm.phone_office.value; 
  var phone_residence = frm.phone_residence.value;

  //Remove Leading and Trailing Spaces.
  if (user_id.length > 0)
  {
     user_id = removeAllSpaces(user_id);
	 frm.user_id.value = user_id;
  }
  
  //Display alert if fields is blank.
  if (!user_id)
  {
     alert("Login ID should not be left balnk.");
	 frm.user_id.focus();
	 return false;
  }
  
  //Remove Leading and Trailing Spaces  
  if (password.length > 0)
  {
    password = removeAllSpaces(password);
	frm.password.value = password;
  }
  
  //Display alert message if password is blank.
  if (!password)
  {
    alert("Password should not be left blank.");
	frm.password.focus();
	return false;
  }
  
  //Remove Leading and Trailing Spaces  
  if (re_password.length > 0)
  {
    re_password = removeAllSpaces(re_password);
	frm.re_password.value = re_password;
  }
  
  //Display alert message if re_password is blank.
  if (!re_password)
  {
    alert("Confirm password should not be left blank.");
	frm.re_password.focus();
	return false;
  }
  
  //Match Password and Confirm passord. Display error if they does not match.
  for (var ctr=0;ctr < password.length; ctr++)
  {
     if (password.charAt(ctr) != re_password.charAt(ctr))
	 {
		 alert("Password does not match. Please re-enter.");
		 frm.re_password.value = "";
		 frm.re_password.focus();
		 return false;
	 }
  }
  
  //Remove Leading and Trailing Spaces.
  if (first_name.length > 0)
  {
     first_name = removeAllSpaces(first_name);
	 frm.first_name.value = first_name;
  }
  
  //Display alert if fields is blank.
  if (!first_name)
  {
     alert("First name should not be left balnk.");
	 frm.first_name.focus();
	 return false;
  }
  
  //Remove Leading and Trailing Spaces.
  if (last_name.length > 0)
  {
     last_name = removeAllSpaces(last_name);
	 frm.last_name.value = last_name;
  }
  
  //Display alert if fields is blank.
  if (!last_name)
  {
     alert("Last name should not be left balnk.");
	 frm.last_name.focus();
	 return false;
  }

  //Remove Leading and Trailing Spaces  
  if (email.length > 0)
  {
	email = removeAllSpaces(email);
	frm.email.value = email;
  }
  
  //Display alert message if email is blank.
  if (!email)
  {
	alert("Email should not left blank.");
	frm.email.focus();
	return false;
  }  
  else
  {
	if (validateEmail(email)== false)
	{
	  alert("Please enter valid email.");
	  frm.email.focus();
	  return false;
	}
  }

  //Remove Leading and Trailing Spaces.
  if (house_name.length > 0)
  {
     house_name = removeAllSpaces(house_name);
	 frm.house_name.value = house_name;
  }
  
  //Display alert if fields is blank.
  if (!house_name)
  {
     alert("House name should not be left balnk.");
	 frm.house_name.focus();
	 return false;
  }
  
  //Remove Leading and Trailing Spaces.
  if (phone_office.length > 0)
  {
     phone_office = removeAllSpaces(phone_office);
	 frm.phone_office.value = phone_office;
  }
  
  //Display alert if fields is blank.
  if (phone_office.length > 0)
  {
    //Display alert for invalid character in phone number.
	var phone_reg1 = new RegExp("[a-z]");
	var phone_reg2 = new RegExp("[A-Z]");	   
	var phone_reg3 = new RegExp("[!@#$^&*_|~`]");
	   
	if (phone_reg1.test(phone_office) == true || phone_reg2.test(phone_office) == true || phone_reg3.test(phone_office) == true)
	{
	  alert("Please enter correct phone number.");
	  frm.phone_office.focus();
	  return false;
	}
  }
  
  //Remove Leading and Trailing Spaces.
  if (phone_residence.length > 0)
  {
     phone_residence = removeAllSpaces(phone_residence);
	 frm.phone_residence.value = phone_residence;
  }
  
  //Display alert if fields is blank.
  if (phone_residence.length > 0)
  {
    //Display alert for invalid character in phone number.
	var phone_reg1 = new RegExp("[a-z]");
	var phone_reg2 = new RegExp("[A-Z]");	   
	var phone_reg3 = new RegExp("[!@#$^&*_|~`]");
	   
	if (phone_reg1.test(phone_residence) == true || phone_reg2.test(phone_residence) == true || phone_reg3.test(phone_residence) == true)
	{
	  alert("Please enter correct phone number.");
	  frm.phone_residence.focus();
	  return false;
	}
  }

  return true;
}
//######################################################################################################

//######################################################################################################
//
function checkEditFacultyForm(frm)
{
  var password = frm.password.value;
  var re_password = frm.re_password.value;  
  var first_name = frm.first_name.value; 
  var last_name = frm.last_name.value;
  var email = frm.email.value;
  var house_name = frm.house_name.value;
  var phone_office = frm.phone_office.value; 
  var phone_residence = frm.phone_residence.value;

  
  //Remove Leading and Trailing Spaces  
  if (password.length > 0)
  {
    password = removeAllSpaces(password);
	frm.password.value = password;
  }
  
  //Display alert message if password is blank.
  if (!password)
  {
    alert("Password should not be left blank.");
	frm.password.focus();
	return false;
  }
  
  //Remove Leading and Trailing Spaces  
  if (re_password.length > 0)
  {
    re_password = removeAllSpaces(re_password);
	frm.re_password.value = re_password;
  }
  
  //Display alert message if re_password is blank.
  if (!re_password)
  {
    alert("Confirm password should not be left blank.");
	frm.re_password.focus();
	return false;
  }
  
  //Match Password and Confirm passord. Display error if they does not match.
  for (var ctr=0;ctr < password.length; ctr++)
  {
     if (password.charAt(ctr) != re_password.charAt(ctr))
	 {
		 alert("Password does not match. Please re-enter.");
		 frm.re_password.value = "";
		 frm.re_password.focus();
		 return false;
	 }
  }
  
  //Remove Leading and Trailing Spaces.
  if (first_name.length > 0)
  {
     first_name = removeAllSpaces(first_name);
	 frm.first_name.value = first_name;
  }
  
  //Display alert if fields is blank.
  if (!first_name)
  {
     alert("First name should not be left balnk.");
	 frm.first_name.focus();
	 return false;
  }
  
  //Remove Leading and Trailing Spaces.
  if (last_name.length > 0)
  {
     last_name = removeAllSpaces(last_name);
	 frm.last_name.value = last_name;
  }
  
  //Display alert if fields is blank.
  if (!last_name)
  {
     alert("Last name should not be left balnk.");
	 frm.last_name.focus();
	 return false;
  }

  //Remove Leading and Trailing Spaces  
  if (email.length > 0)
  {
	email = removeAllSpaces(email);
	frm.email.value = email;
  }
  
  //Display alert message if email is blank.
  if (!email)
  {
	alert("Email should not left blank.");
	frm.email.focus();
	return false;
  }  
  else
  {
	if (validateEmail(email)== false)
	{
	  alert("Please enter valid email.");
	  frm.email.focus();
	  return false;
	}
  }

  //Remove Leading and Trailing Spaces.
  if (house_name.length > 0)
  {
     house_name = removeAllSpaces(house_name);
	 frm.house_name.value = house_name;
  }
  
  //Display alert if fields is blank.
  if (!house_name)
  {
     alert("House name should not be left balnk.");
	 frm.house_name.focus();
	 return false;
  }
  
  //Remove Leading and Trailing Spaces.
  if (phone_office.length > 0)
  {
     phone_office = removeAllSpaces(phone_office);
	 frm.phone_office.value = phone_office;
  }
  
  //Display alert if fields is blank.
  if (phone_office.length > 0)
  {
    //Display alert for invalid character in phone number.
	var phone_reg1 = new RegExp("[a-z]");
	var phone_reg2 = new RegExp("[A-Z]");	   
	var phone_reg3 = new RegExp("[!@#$^&*_|~`]");
	   
	if (phone_reg1.test(phone_office) == true || phone_reg2.test(phone_office) == true || phone_reg3.test(phone_office) == true)
	{
	  alert("Please enter correct phone number.");
	  frm.phone_office.focus();
	  return false;
	}
  }
  
  //Remove Leading and Trailing Spaces.
  if (phone_residence.length > 0)
  {
     phone_residence = removeAllSpaces(phone_residence);
	 frm.phone_residence.value = phone_residence;
  }
  
  //Display alert if fields is blank.
  if (phone_residence.length > 0)
  {
    //Display alert for invalid character in phone number.
	var phone_reg1 = new RegExp("[a-z]");
	var phone_reg2 = new RegExp("[A-Z]");	   
	var phone_reg3 = new RegExp("[!@#$^&*_|~`]");
	   
	if (phone_reg1.test(phone_residence) == true || phone_reg2.test(phone_residence) == true || phone_reg3.test(phone_residence) == true)
	{
	  alert("Please enter correct phone number.");
	  frm.phone_residence.focus();
	  return false;
	}
  }

  return true;

}
//######################################################################################################

//######################################################################################################
//This function will allow to select all checkboxes.

function checkFacultyCheckbox(frm)
{
  //If section checkbox is not created then display alerts
  if (isCheckboxSelected(frm) == false)
  {
    alert("Please select checkbox for deletion.");
	return false;
  }
  
  return true;
}
//######################################################################################################


function checkResumeCheckbox(frm)
{
  //If section checkbox is not created then display alerts
  if (isCheckboxSelected(frm) == false)
  {
    alert("Please select checkbox for deletion.");
	return false;
  }
  
  return true;
}
//######################################################################################################
// This function will check ScrollingTextForm.
  
 function checkScrollTextForm(frm)
 {
    var scroll_text = frm.scrolling_text.value;
	 
     //Remove Leading and Trailing Spaces  
	  if (scroll_text.length > 0)
	  {
		scroll_text = removeAllSpaces(scroll_text);
		frm.scrolling_text.value = scroll_text;		
	  }
	  
	  //Display alert message if scroll_text is blank.
	  if (!scroll_text)
	  {
		alert("Scrolling text should not blank.");
		frm.scrolling_text.focus();
		return false;
	  } 
	  
	  //Display alert message if scroll_text is > 60 chracter.
	  if (scroll_text.length > 80)
	  {
		alert("Scrolling text should not be greater than 80 character.");
		frm.scrolling_text.focus();
		return false;
	  }  
    
	return true;
 }
//######################################################################################################

//######################################################################################################
// This function is used to display confirmation before deleteing the records.
//
/*
function confirmDeletion(script_name,action, id)
{
  var status = confirm("Are you sure you want to delete?");
  
  if (status == true)
  {
	 //Call URL to delete the user.
	 window.location = script_name+"?action="+action+"&id="+id;
  }
}
*/
//######################################################################################################

//######################################################################################################
// This function will check announcement text and uploading image.
//

function checkAnnouncementsForm(frm)
{
  var title = frm.title.value;
  var announcement = frm.announcement.value;
  
  //Remove Leading and Trailing spaces.
  if (title.length > 0)
  {
	 title = removeAllSpaces(title);
	 frm.title.value = title;
  } 

  //If field is blank then display alert 
  if (!title)
  {
	 alert("Please enter title.");
	 frm.title.focus();
	 return false;
  }
  
  //Remove Leading and Trailing spaces.
  if (announcement.length > 0)
  {
	 ann_msg = removeAllSpaces(announcement);
	 frm.announcement.value = announcement;
  } 

  //If field is blank then display alert 
  if (!announcement)
  {
	 alert("Please enter announcement.");
	 frm.announcement.focus();
	 return false;
  }
 
  return true;

}
//######################################################################################################

//######################################################################################################
// This function will check aedit parents info.
//

function checkEditParents(frm)
{
  var fname = frm.parents_fname.value;
  var lname = frm.parents_lname.value;
  var emailid = frm.parents_emailid.value;
  var school_no = frm.school_no.value;


  //Remove Leading and Trailing spaces.
  if (school_no.length > 0)
  {
	 school_no = removeAllSpaces(school_no);
	 frm.school_no.value = school_no;
  } 

  //If field is blank then display alert 
  if (!school_no)
  {
	 alert("Please enter school no.");
	 frm.school_no.focus();
	 return false;
  }
  
  //Remove Leading and Trailing spaces.
  if (fname.length > 0)
  {
	 fname = removeAllSpaces(fname);
	 frm.parents_fname.value = fname;
  } 

  //If field is blank then display alert 
  if (!fname)
  {
	 alert("Please enter first name.");
	 frm.parents_fname.focus();
	 return false;
  }
  
  //Remove Leading and Trailing spaces.
  if (lname.length > 0)
  {
	 lname = removeAllSpaces(lname);
	 frm.parents_lname.value = lname;
  } 

  //If field is blank then display alert 
  if (!lname)
  {
	 alert("Please enter last name.");
	 frm.parents_lname.focus();
	 return false;
  }

  //Remove Leading and Trailing spaces.
  if (emailid.length > 0)
  {
	 emailid = removeAllSpaces(emailid);
	 frm.parents_emailid.value = emailid;
  } 

  //If field is blank then display alert 
  if (!emailid)
  {
	 alert("Please enter email id.");
	 frm.parents_emailid.focus();
	 return false;
  } else
  {
    if (validateEmail(emailid)== false)
	{
	  alert("Please enter valid email.");
	  frm.parents_emailid.focus();
	  return false;
	}
  } 
 
  return true;

}
//######################################################################################################

//######################################################################################################
// This function will check main category of the event.
// Returns true if main category is selected or false otherwise.

function isSelected(frm)
{
   if (frm.mcat_id.value=="--")
   {
	  alert("Please select main category.");
	  frm.mcat_id.focus();
	 return false;
   }
  
  return true;
}

//######################################################################################################
// This function will check current event form
//

function checkCurrentEventForm(frm)
{
  var event_name = frm.event_name.value;
  var happening_date = frm.happening_date.value;
  var event_desc = frm.event_desc.value;

  //Check Main Category.
  if (isSelected(frm) == false)
  {     
	  return false;
  }
  
  //Remove Leading and Trailing Spaces.
  if (event_name.length > 0)
  {
    event_name = removeAllSpaces(event_name);
	frm.event_name.value = event_name;
  }
  
  //Display alert if field is blank
  if (!event_name)
  {
	  alert("Event name should not be left blank.");
	  frm.event_name.focus();
	  return false;
  }
  
  //Remove Leading and Trailing Spaces.
  if (happening_date.length > 0)
  {
    happening_date = removeAllSpaces(happening_date);
	frm.happening_date.value = happening_date;
  }
  
  //Display alert if field is blank
  if (!happening_date)
  {
	  alert("Happening date should not be left blank.");
	  frm.happening_date.focus();
	  return false;
  }
  /*else
  {
     //If happening date is there then validate that date.
	 //Date should not be less than current date.

	 var slash_ctr=0;
	 for (var ctr=0; ctr < happening_date.length; ctr++)
	 {
		 if (happening_date.charAt(ctr) == '/')
		 {
           slash_ctr++;
		 }
	 }

	 if (slash_ctr != 2)
	 {
       alert("Please enter valid date");
	   frm.happening_date.focus();
	   return false;
	 }
	 
	 //if happening date is valid then get dd.mm.yyyy
	 var happening_arr =happening_date.split("/");
	 var happening_dd = happening_arr[0];
	 var happening_mm = happening_arr[1];
	 var happening_yyyy = happening_arr[2];

	 if (happening_dd.length == 0 || happening_mm.length == 0 || happening_yyyy.length != 4)
	 {
		 alert("Please enter valid date");
		 frm.happening_date.focus();
		 return false;
	 }
	
	//If day and month begin with 0 then get last digit of day and month
	happening_dd = (happening_dd.charAt(0) == '0')? happening_dd.charAt(1) : happening_dd;
    happening_mm = (happening_mm.charAt(0) == '0')? happening_mm.charAt(1) : happening_mm;
	
	//Display alert if day > 31 and month > 12
	if (happening_dd > 31 || happening_mm > 12)
	{
      alert("Please enter valid date.");
	  frm.happening_date.focus();
	  return false;
	}

	//Call checkDate(YYYY,MM,DD) to validate the date.
	if (checkDate(happening_yyyy, happening_mm, happening_dd) == false)
	{
      alert("Happening date should not be less than current date.");
	  frm.happening_date.focus();
	  return false;
	}

  }*///end of else

  //Remove Leading and Trailing Spaces.
  if (event_desc.length > 0)
  {
    event_desc = removeAllSpaces(event_desc);
    frm.event_desc.value = event_desc;
  } 

  //If field is blank then display alert.
  if (!event_desc)
  {
     alert("Event description should not be left blank.");
	 frm.event_desc.focus();
	 return false;
  }

  return true;

 }
//######################################################################################################
// This function will check forthcoming event form
//

function checkForthComingEvent(frm)
{
  var event_name = frm.event_name.value;
  var happening_date = frm.happening_date.value;
  var event_desc = frm.event_desc.value;

  //Remove Leading and Trailing Spaces.
  if (event_name.length > 0)
  {
    event_name = removeAllSpaces(event_name);
	frm.event_name.value = event_name;
  }
  
  //Display alert if field is blank
  if (!event_name)
  {
	  alert("Event name should not be left blank.");
	  frm.event_name.focus();
	  return false;
  }
  
  //Remove Leading and Trailing Spaces.
  if (happening_date.length > 0)
  {
    happening_date = removeAllSpaces(happening_date);
	frm.happening_date.value = happening_date;
  }
  
  //Display alert if field is blank
  if (!happening_date)
  {
	  alert("Happening date should not be left blank.");
	  frm.happening_date.focus();
	  return false;
  }
  //Remove Leading and Trailing Spaces.
  if (event_desc.length > 0)
  {
    event_desc = removeAllSpaces(event_desc);
    frm.event_desc.value = event_desc;
  } 

  //If field is blank then display alert.
  if (!event_desc)
  {
     alert("Event description should not be left blank.");
	 frm.event_desc.focus();
	 return false;
  }

  return true;

 }
//######################################################################################################

//######################################################################################################
// This function will check General event form
//

function checkGeneralEventForm(frm)
{
  var event_name = frm.event_name.value;
  var happening_date = frm.happening_date.value;
  var event_desc = frm.event_desc.value;

  //Check Main Category.
  if (isSelected(frm) == false)
  {     
	  return false;
  }
  
  //Remove Leading and Trailing Spaces.
  if (event_name.length > 0)
  {
    event_name = removeAllSpaces(event_name);
	frm.event_name.value = event_name;
  }
  
  //Display alert if field is blank
  if (!event_name)
  {
	  alert("Event name should not be left blank.");
	  frm.event_name.focus();
	  return false;
  }
  
  //Remove Leading and Trailing Spaces.
  if (happening_date.length > 0)
  {
    happening_date = removeAllSpaces(happening_date);
	frm.happening_date.value = happening_date;
  }
  
  //Display alert if field is blank
  if (!happening_date)
  {
	  alert("Happening date should not be left blank.");
	  frm.happening_date.focus();
	  return false;
  }
  /*else
  {
     //If happening date is there then validate that date.
	 //Date should not be less than current date.

	 var slash_ctr=0;
	 for (var ctr=0; ctr < happening_date.length; ctr++)
	 {
		 if (happening_date.charAt(ctr) == '/')
		 {
           slash_ctr++;
		 }
	 }

	 if (slash_ctr != 2)
	 {
       alert("Please enter valid date");
	   frm.happening_date.focus();
	   return false;
	 }
	 
	 //if happening date is valid then get dd.mm.yyyy
	 var happening_arr =happening_date.split("/");
	 var happening_dd = happening_arr[0];
	 var happening_mm = happening_arr[1];
	 var happening_yyyy = happening_arr[2];

	 if (happening_dd.length == 0 || happening_mm.length == 0 || happening_yyyy.length != 4)
	 {
		 alert("Please enter valid date");
		 frm.happening_date.focus();
		 return false;
	 }
	
	//If day and month begin with 0 then get last digit of day and month
	happening_dd = (happening_dd.charAt(0) == '0')? happening_dd.charAt(1) : happening_dd;
    happening_mm = (happening_mm.charAt(0) == '0')? happening_mm.charAt(1) : happening_mm;
	
	//Display alert if day > 31 and month > 12
	if (happening_dd > 31 || happening_mm > 12)
	{
      alert("Please enter valid date.");
	  frm.happening_date.focus();
	  return false;
	}	

  }//end of else*/

  //Remove Leading and Trailing Spaces.
  if (event_desc.length > 0)
  {
    event_desc = removeAllSpaces(event_desc);
    frm.event_desc.value = event_desc;
  } 

  //If field is blank then display alert.
  if (!event_desc)
  {
     alert("Event description should not be left blank.");
	 frm.event_desc.focus();
	 return false;
  }

  return true;

 }
//######################################################################################################

//######################################################################################################
// This function will check date.
// It returns true if date >= current date.

  function checkDate(year,month,day)
  {
    var status=true;
   
	//Get the curret date
	var cur_date = new Date();
	var cur_dd = cur_date.getDate();
	var cur_mm = cur_date.getMonth()+1;
	var cur_yyyy = cur_date.getFullYear();
		
	//If happening date < than current date then display alert.
	if (year < cur_yyyy)
	{
	   status = false;			   
	}
	else if (year == cur_yyyy)
	{
		if (month < cur_mm)
		{
		   status = false;
		}
		else if (month == cur_mm)
		{
			if (day < cur_dd)
			{
			  status = false;
			}
		}
	}
	
   return status;

}//End of function.
//######################################################################################################

//######################################################################################################
//This function will check Forth comn Event form.
//

function checkForthComingEventForm(frm)
{
  if (checkForthComingEvent(frm) == false)
  {
    return false;
  }  
  
  return true;
}
//######################################################################################################

//######################################################################################################
//This function will check School Today Event form.
//

function checkSchoolTodayForm(frm)
{
  
  var event_name = frm.event_name.value;
  var event_desc = frm.event_desc.value;

  //Remove Leading and Trailing Spaces.
  if (event_name.length > 0)
  {
    event_name = removeAllSpaces(event_name);
	frm.event_name.value = event_name;
  }
  
  //Display alert if field is blank
  if (!event_name)
  {
	  alert("Event name should not be left blank.");
	  frm.event_name.focus();
	  return false;
  }
  
  //Remove Leading and Trailing Spaces.
  if (event_desc.length > 0)
  {
    event_desc = removeAllSpaces(event_desc);
    frm.event_desc.value = event_desc;
  } 

  //If field is blank then display alert.
  if (!event_desc)
  {
     alert("Event description should not be left blank.");
	 frm.event_desc.focus();
	 return false;
  }
  
  return true;
}
//######################################################################################################

//######################################################################################################
function checkSchoolTodayImages(frm)
{
  if (checkCurrentEventImages(frm) == false)
  {
    return false;
  }
  
   return true;
}
//######################################################################################################

//######################################################################################################
function checkCurrentEventImages(frm)
{
  var img_caption = frm.img_caption.value;
  var img_file = frm.img_file.value;

  //Remove Leading and Trailing Spaces.
  if (img_caption.length > 0)
  {
	img_caption = removeAllSpaces(img_caption);
    frm.img_caption.value = img_caption; 
  }

  //Display Error if field is blank.
  if (!img_caption)
  {
    alert("Image caption should not be left blank.");
	frm.img_caption.focus();
	return false;
  }
  
  //Remove Leading and Trailing Spaces.
  if(img_file.length > 0)
  {
    img_file = removeAllSpaces(img_file);
	frm.img_file.value = img_file;
  }
  
  //Display alert if field is blank.
  if(!img_file)
  {
    alert("Please select image file.");
	frm.img_file.focus();
	return false;
  }

  //If img_file has some value then check validity of the file name.
  if (img_file.length > 0)
  {
     if (img_file.indexOf(".") == -1)
     {
		alert("Please select correct image file.");
        frm.img_file.focus();		
		return false;
     }
	 else
	 {
	    //If file has dot (.) then split it and identify image type .gif, .jpg		
        var file_ext = img_file.substr(img_file.indexOf(".")+1);

		if (!(file_ext == "gif" || file_ext == "GIF" || file_ext == "jpg" || file_ext == "JPG"))
	    {
			alert("Please select only gif or jpg image file.");
			frm.img_file.focus();			
			return false;
	    }	 
	  } 

   }//end of outer if
  
   return true;
}
//######################################################################################################

//######################################################################################################
// This function will check ClassSectionForm.
// 

function checkClassSectionForm(frm)
{

  if ((frm.section_type[0].checked))
  { 
	  var sel_status=false;

	  for (var ctr=0; ctr < frm.length; ctr++)
	  {
		var field_name = frm.elements(ctr).name;
		if (field_name.indexOf("|") > 0)
		{
		   if (frm.elements(ctr).checked)
		   {
			  sel_status= true;
			  break;
		   }
		 }
	  }
	  
	  //If section checkbox is not created then display alerts
	  if (sel_status == false)
	  {
		alert("Please select checkbox section.");
		return false;
	  }
  }
 
 //If Create Section Manually Redio button is selected then check section name.
  if (frm.section_type[1].checked)
  {
	var class_section = frm.class_section.value;
	if (class_section.length > 0)
	{
      class_section = removeAllSpaces(class_section); 
	  frm.class_name.value = class_section;
	}
    //If field is blank then display alert.
	if (!class_section)
	{
      alert('Please enter section name.');
	  frm.class_section.focus();
	  return false;
	}
  }

  return true;

}//End of function.
//######################################################################################################

//######################################################################################################
// This function will check ImgCategoryForm.
// 

function checkImgCategoryForm(frm)
{
  var category_name = frm.category_name.value;
  
  //Remove Leading and Trailing Spaces.
  if (category_name.length > 0)
  {
    category_name = removeAllSpaces(category_name);
	frm.category_name.value = category_name;
  }

  //If field is blank then display display alert.
  if (!category_name)
  {
    alert("Category name should not be left blank.");
	frm.category_name.focus();
	return false;
  }

  return true;

}//End of function.
//######################################################################################################

//######################################################################################################
// This function will check Subject Form.
// 

function checkSubjectForm(frm)
{
  var subject  = frm.subject_name.value; 
  
  //Remove leading and trailing Spaces.
  if (subject.length > 0)
  {
	 subject = removeAllSpaces(subject);  
	 frm.subject_name.value = subject;
  }
  
  //If field is blank then display eror message.
  if (!subject)
  {
    alert("Subject should not be left blank.");
	frm.subject_name.focus();
	return false;
  }

 return true;
}
//######################################################################################################

//######################################################################################################
// This function will check Adventure Form.
// 

function checkAdventureForm(frm)
{
  var category_name  = frm.category_name.value; 
  
  //Remove leading and trailing Spaces.
  if (category_name.length > 0)
  {
	 category_name = removeAllSpaces(category_name);  
	 frm.category_name.value = category_name;
  }
  
  //If field is blank then display eror message.
  if (!category_name)
  {
    alert("Category name should not be left blank.");
	frm.category_name.focus();
	return false;
  }

 return true;
}
//######################################################################################################

//######################################################################################################
// This function will check Adventure Event Form.
// 

function checkAdventureEvent(frm)
{
  var happening_date = frm.happening_date.value;
  var event_title = frm.event_title.value; 
  var event_desc = frm.event_desc.value;

  //Remove Leading and Trailing Spaces.
  if (happening_date.length > 0)
  {
    happening_date = removeAllSpaces(happening_date);
	frm.happening_date.value = happening_date;
  }
  
  //Display alert if field is blank
  if (!happening_date)
  {
	  alert("Happening date should not be left blank.");
	  frm.happening_date.focus();
	  return false;
  }
  else
  {
     //If happening date is there then validate that date.
	 //Date should not be less than current date.

	 var slash_ctr=0;
	 for (var ctr=0; ctr < happening_date.length; ctr++)
	 {
		 if (happening_date.charAt(ctr) == '/')
		 {
           slash_ctr++;
		 }
	 }

	 if (slash_ctr != 2)
	 {
       alert("Please enter valid date");
	   frm.happening_date.focus();
	   return false;
	 }
	 
	 //if happening date is valid then get dd.mm.yyyy
	 var happening_arr =happening_date.split("/");
	 var happening_dd = happening_arr[0];
	 var happening_mm = happening_arr[1];
	 var happening_yyyy = happening_arr[2];

	 if (happening_dd.length == 0 || happening_mm.length == 0 || happening_yyyy.length != 4)
	 {
		 alert("Please enter valid date");
		 frm.happening_date.focus();
		 return false;
	 }
	
	//If day and month begin with 0 then get last digit of day and month
	happening_dd = (happening_dd.charAt(0) == '0')? happening_dd.charAt(1) : happening_dd;
    happening_mm = (happening_mm.charAt(0) == '0')? happening_mm.charAt(1) : happening_mm;
	
	if (happening_dd > 31 || happening_mm > 12)
	{
      alert("Please enter valid date.");
	  frm.happening_date.focus();
	  return false;
	}
	
	//Call checkDate(YYYY,MM,DD) to validate the date.
	/*
	if (checkDate(happening_yyyy, happening_mm, happening_dd) == false)
	{
      alert("Happening date should not be less than current date.");
	  frm.happening_date.focus();
	  return false;
	}
     */
  }//end of else
  
  
  //Remove leading and trailing Spaces.
  if (event_title.length > 0)
  {
	 event_title = removeAllSpaces(event_title);  
	 frm.event_title.value = event_title;
  }
  
  //If field is blank then display eror message.
  if (!event_title)
  {
    alert("Event title should not be left blank.");
	frm.event_title.focus();
	return false;
  }
  
  //Remove leading and trailing Spaces.
  if (event_desc.length > 0)
  {
	 event_desc = removeAllSpaces(event_desc);  
	 frm.event_desc.value = event_desc;
  }
  
  //If field is blank then display eror message.
  if (!event_desc)
  {
    alert("Event description should not be left blank.");
	frm.event_desc.focus();
	return false;
  }

 return true;
}
//######################################################################################################

//######################################################################################################
//This function will check games form.

function checkGamesForm(frm)
{
  var sport_name = frm.sport_name.value;
  var sport_desc = frm.sport_desc.value;
  
  //Remove Leading and Trailing Spaces.
  if (sport_name.length > 0)
  {
	 sport_name = removeAllSpaces(sport_name);
     frm.sport_name.value = sport_name;
  }
  //Display error if field is blank.
  if (!sport_name)
  {
	  alert("Sport name should not be left.");
	  frm.sport_name.focus();
	  return false;
  }

  //Remove Leading and Trailing spaces.
  if(sport_desc.length > 0)
  {
     sport_desc = removeAllSpaces(sport_desc);
	 frm.sport_desc.value = sport_desc;
  }

  //If field is blank then display alert.
  if (!sport_desc)
  {
	  alert("Please enter sport description.");
	  frm.sport_desc.focus();
	  return false;
  }

  return true;
}

//######################################################################################################

//######################################################################################################
//This function will check society form.

function checkSocietyForm(frm)
{
  var society_name = frm.society_name.value;
  var society_desc = frm.society_desc.value;

  //Remove Leading and Trailing Spaces.
  if (society_name.length > 0)
  {
	 society_name = removeAllSpaces(society_name);
     frm.society_name.value = society_name;
  }
  //Display error if field is blank.
  if (!society_name)
  {
	  alert("Plese enter society name.");
	  frm.society_name.focus();
	  return false;
  }

  //Remove Leading and Trailing spaces.
  if(society_desc.length > 0)
  {
     society_desc = removeAllSpaces(society_desc);
	 frm.society_desc.value = society_desc;
  }

  //If field is blank then display alert.
  if (!society_desc)
  {
	  alert("Please enter society description.");
	  frm.society_desc.focus();
	  return false;
  }

  return true;
}

//######################################################################################################

//######################################################################################################
// This function will check announcement text and uploading image.
//

function checkSound(frm)
{
  var sound_caption = frm.sound_caption.value;
  var mp3_file = frm.mp3_file.value;
  var rm_file = frm.rm_file.value;

  //Remove Leading and Trailing Spaces.
  if(sound_caption.length > 0)
  {
    sound_caption = removeAllSpaces(sound_caption);
	frm.sound_caption.value = sound_caption;
  }
  
  //Display alert if field is blank.
  if(!sound_caption)
  {
    alert("Please enter sound caption.");
	frm.sound_caption.focus();
	return false;
  }
  
  
  //Remove Leading and Trailing Spaces.
  if(mp3_file.length > 0)
  {
    mp3_file = removeAllSpaces(mp3_file);
	frm.mp3_file.value = mp3_file;
  }
  
  //Remove Leading and Trailing Spaces.
  if(rm_file.length > 0)
  {
    rm_file = removeAllSpaces(rm_file);
	frm.rm_file.value = rm_file;
  }

  //Display alert if field is blank.
  if ((!mp3_file) && (!rm_file))
  {
    alert("Please select either .mp3 file or .rm file or both.");
	frm.mp3_file.focus();
	return false;
  }

  //If User is uploading mp3 file then check extensions.
  if (mp3_file != '')
  {

	
	 if (mp3_file.indexOf(".") == -1)
     {
		alert("Please select correct .mp3 file.");
        frm.mp3_file.focus();
		return false;
     }	 
	 else
	 {
	    //If file has dot (.) then split it and identify sound type .mp3		
        var file_ext = mp3_file.substr(mp3_file.lastIndexOf(".")+1);

		if (!(file_ext == "mp3" || file_ext == "MP3"))
	    {
			alert("Please select .mp3 file only.");
			frm.mp3_file.focus();			
			return false;
	    }
	 } 	 
  }

  //If User is uploading rm file then check extensions.
  if (rm_file != '')
  {
     if (rm_file.indexOf(".") == -1)
     {
		alert("Please select correct .rm file.");
        frm.rm_file.focus();
		return false;
     }
	 else
	 {
	    //If file has dot (.) then split it and identify sound type .mp3		
        var file_ext = rm_file.substr(rm_file.lastIndexOf(".")+1);

		if (!(file_ext == "rm" || file_ext == "RM"))
	    {
			alert("Please select .rm file only.");
			frm.rm_file.focus();			
			return false;
	    }
	 }    
  }

  return true;

}
//######################################################################################################

//######################################################################################################
// This function will check job form.
//

function checkJobs(frm)
{
  var post_name = frm.post_name.value;
  var last_posting_date = frm.last_posting_date.value;
  var post_desc = frm.post_desc.value;

  //Remove Leading and Trailing Spaces.
  if(post_name.length > 0)
  {
    post_name = removeAllSpaces(post_name);
	frm.post_name.value = post_name;
  }
  
  //Display alert if field is blank.
  if(!post_name)
  {
    alert("Please enter post name.");
	frm.post_name.focus();
	return false;
  }
  
  if (last_posting_date.length > 0)
  {
    last_posting_date = removeAllSpaces(last_posting_date);
	frm.last_posting_date.value = last_posting_date;
  }
  
  if (!last_posting_date)
  {
    alert("Please enter last date of resume posting.");
	frm.last_posting_date.focus();
  }
  else
  {
	  //If last_posting_date is there then validate that date.
	  //Date should not be less than current date.     

		 var slash_ctr=0;
		 for (var ctr=0; ctr < last_posting_date.length; ctr++)
		 {
			 if (last_posting_date.charAt(ctr) == '/')
			 {
			   slash_ctr++;
			 }
		 }

		 if (slash_ctr != 2)
		 {
		   alert("Please enter valid last posting date");
		   frm.last_posting_date.focus();
		   return false;
		 }
		 
		 //if last_posting_date date is valid then get dd.mm.yyyy
		 var date_arr = last_posting_date.split("/");
		 var date_dd = date_arr[0];
		 var date_mm = date_arr[1];
		 var date_yyyy = date_arr[2];

		 if (date_dd.length == 0 || date_mm.length == 0 || date_yyyy.length != 4)
		 {
			 alert("Please enter valid last posting date");
			 frm.last_posting_date.focus();
			 return false;
		 }
		
		//If day and month begin with 0 then get last digit of day and month
		date_dd = (date_dd.charAt(0) == '0')? date_dd.charAt(1) : date_dd;
		date_mm = (date_mm.charAt(0) == '0')? date_mm.charAt(1) : date_mm;
		
		//Display alert if day > 31 and month > 12
		if (date_dd > 31 || date_mm > 12)
		{
		  alert("Please enter valid last posting date .");
		  frm.last_posting_date.focus();
		  return false;
		}

		//Call checkDate(YYYY,MM,DD) to validate the date.
		if (checkDate(date_yyyy, date_mm, date_dd) == false)
		{
		  alert("Last posting should not be less than current date.");
		  frm.last_posting_date.focus();
		  return false;
		}

   }//End of Else.

  ///Remove Leading and Trailing Spaces.
  if(post_desc.length > 0)
  {
    post_desc = removeAllSpaces(post_desc);
	frm.post_desc.value = post_desc;
  }
  
  //Display alert if field is blank.
  if(!post_desc)
  {
    alert("Please enter post description.");
	frm.post_desc.focus();
	return false;
  }

  return true;

}
//######################################################################################################

//######################################################################################################
// This function will Post Message Form.
//

function checkPostMessage(frm)
{
  var posted_by = frm.posted_by.value; 
  var message = frm.message.value;
  
  //Remove Leading and Trailing Spaces.
  if(posted_by.length > 0)
  {
    posted_by = removeAllSpaces(posted_by);
	frm.posted_by.value = posted_by;
  }
  
  //Display alert if field is blank.
  if(!posted_by)
  {
    alert("Please enter your name.");
	frm.posted_by.focus();
	return false;
  }
  
  ///Remove Leading and Trailing Spaces.
  if(message.length > 0)
  {
    message = removeAllSpaces(message);
	frm.message.value = message;
  }
  
  //Display alert if field is blank.
  if(!message)
  {
    alert("Message should not be left blank.");
	frm.message.focus();
	return false;
  }

  return true; 
}

//######################################################################################################

//######################################################################################################
// This function will check house names.

function checkHouse(frm)
{
  var house_name = frm.house_name.value;

  //Remove Leading and Trailing blanks.
  if (house_name.length > 0)
  {
    house_name = removeAllSpaces(house_name);
	frm.house_name.value = house_name;
  }

  //if field is blank then display alert.
  if (!house_name)
  {
	 alert("Please enter house name.");
     frm.house_name.focus();
	 return false;
  }

  return true;
}
//######################################################################################################

//######################################################################################################
// This function will check party names.

function checkParty(frm)
{
  var party_name = frm.party_name.value;

  //Remove Leading and Trailing blanks.
  if (party_name.length > 0)
  {
    party_name = removeAllSpaces(party_name);
	frm.paty_name.value = party_name;
  }

  //if field is blank then display alert.
  if (!party_name)
  {
	 alert("Please enter party name.");
     frm.party_name.focus();
	 return false;
  }

  return true;
}
//######################################################################################################

//######################################################################################################
// This function will check school type form.

function checkSchoolType(frm)
{
  var school_type = frm.school_type.value;

  //Remove Leading and Trailing blanks.
  if (school_type.length > 0)
  {
    school_type = removeAllSpaces(school_type);
	frm.school_type.value = school_type;
  }

  //if field is blank then display alert.
  if (!school_type)
  {
	 alert("Please enter school type.");
     frm.school_type.focus();
	 return false;
  }

  return true;
}
//######################################################################################################

//######################################################################################################
// This function will check house names checkbox selection.

function checkHouseName(frm)
{
  //If section checkbox is not created then display alerts
  if (isCheckboxSelected(frm) == false)
  {
    alert("Please select checkbox for deletion.");
	return false;
  }
  
  return true;
}
//######################################################################################################

//######################################################################################################
// This function will check Current Event checkbox selection.

function checkCurrentEvent(frm)
{
  //If section checkbox is not created then display alerts
  if (isCheckboxSelected(frm) == false)
  {
    alert("Please select checkbox for deletion.");
	return false;
  }
  
  return true;
}
//######################################################################################################

//######################################################################################################
// This function will check Scrolling Text checkbox selection.

function checkScrollText(frm)
{
  //If section checkbox is not created then display alerts
  if (isCheckboxSelected(frm) == false)
  {
    alert("Please select checkbox for deletion.");
	return false;
  }
  
  return true;
}
//######################################################################################################

//######################################################################################################
// This function will check ScrollEvent checkbox selection.

function checkScrollEvent(frm)
{
  //If section checkbox is not created then display alerts
  if (isCheckboxSelected(frm) == false)
  {
    alert("Please select checkbox for deletion.");
	return false;
  }
  
  return true;
}
//######################################################################################################

//######################################################################################################
// This function will check Announce checkbox selection.

function checkAnnounceForm(frm)
{
  //If section checkbox is not created then display alerts
  if (isCheckboxSelected(frm) == false)
  {
    alert("Please select checkbox for deletion.");
	return false;
  }
  
  return true;
}
//######################################################################################################

//######################################################################################################
// This function will check Subject checkbox selection.

function checkSubjectDelForm(frm)
{
  //If section checkbox is not created then display alerts
  if (isCheckboxSelected(frm) == false)
  {
    alert("Please select checkbox for deletion.");
	return false;
  }
  
  return true;
}
//######################################################################################################

//######################################################################################################
// This function will check scholar form.

function checkScholarForm(frm)
{
  var scholar_name = frm.scholar_name.value;
  
  //Remove Leading and Trailing Blanks.
  if (scholar_name.length > 0)
  {
    scholar_name = removeAllSpaces(scholar_name);
	frm.scholar_name.value = scholar_name;
  }

  //Display alert if field is blank.
  if (!scholar_name)
  {
	alert("Scholar name should not be left blank.");
    frm.scholar_name.focus();
	return false;
  }

  var school_no = frm.school_no.value;

  //Remove Leading and Trailing Blanks.
  if (school_no.length > 0)
  {
    school_no = removeAllSpaces(school_no);
	frm.school_no.value = school_no;
  }

  //Display alert if field is blank.
  if (!school_no)
  {
	alert("School no. should not be left blank.");
    frm.school_no.focus();
	return false;
  }
  
  //validate class and corresponding class section.
  var class_name = frm.class_id.options[frm.class_id.selectedIndex].text;
  var class_section = frm.class_section_id.options[frm.class_section_id.selectedIndex].text;
  var class_sec = class_section.substr(0,class_name.length);

  //Display alert if class does not match with class section.
  if (class_name != class_sec)
  {
	alert("Please select section corresponding to the class. If section for the\n  current class does not exist then you can create it from the left menu.");
    frm.class_section_id.focus();
	return false;
  }
  
  //Check DOB year.
  var dtObject = new Date();
  var cur_year = dtObject.getFullYear();
  var dob_yyyy = frm.dob_yyyy.options[frm.dob_yyyy.selectedIndex].text;
  
  //If DOB year is current years.
  if (dob_yyyy == cur_year)
  {
    alert("Please select correct Date of Birth.");
	frm.dob_yyyy.focus();
	return false;
  }
  
  //Validate Language.
  var language = frm.language.value;

  //Remove Leading and Trailing Blanks.
  if (language.length > 0)
  {
    language = removeAllSpaces(language);
	frm.language.value = language;
  }

  //Display alert if field is blank.
  if (!language)
  {
	alert("Please enter language.");
    frm.language.focus();
	return false;
  }
  
  //Validate joining years less than current year.
  var join_yyyy = frm.join_yyyy.options[frm.join_yyyy.selectedIndex].text;  
  if (cur_year > (parseInt(join_yyyy)))
  {
	alert("Please select correct joining date.");
	frm.join_yyyy.focus();
	return false;
  }

  //If Mother name is blank then display.
  var mother_name = frm.mother_name.value;

  //Remove Leading and Trailing Spaces
  if (mother_name.length > 0)
  { 
    mother_name = removeAllSpaces(mother_name);
	frm.mother_name.value=mother_name;
  }

  //Display error if field is blank.
  if (!mother_name)
  {
    alert("Please enter mother name.");
	frm.mother_name.focus();
	return false;
  }
  
  //Display Error if Father First Name and Last Name is blank.
  var father_fname = frm.father_fname.value;
  
  //Remove Leading and Trailing Spaces.
  if (father_fname.length > 0)
  {
	 father_fname = removeAllSpaces(father_fname);
	 frm.father_fname.value = father_fname;
  }
  
  //If field is blank then display alert.
  if (!father_fname)
  {
     alert("First name should not be left balnk.");
	 frm.father_fname.focus();
	 return false;
  } 
  
  //Display Error if Father First Name and Last Name is blank.
  var father_lname = frm.father_lname.value;
  
  //Remove Leading and Trailing Spaces.
  if (father_lname.length > 0)
  {
	 father_lname = removeAllSpaces(father_lname);
	 frm.father_lname.value = father_lname;
  }
  
  //If field is blank then display alert.
  if (!father_lname)
  {
     alert("Last name should not be left balnk.");
	 frm.father_lname.focus();
	 return false;
  }   
  
  //Validate parent email.
  var parent_email = frm.parent_email.value;

  //Remove Leading Trailing Spaces
  if (parent_email.length > 0)
  {
    parent_email = removeAllSpaces(parent_email);
	frm.parent_email.value = parent_email;
  }
  
  //Validate parent email.
  if (parent_email.length > 0)
  {
	 if (validateEmail(parent_email)== false)
	 {
	   alert("Please enter valid email.");
	   frm.parent_email.focus();
	   return false;
	 }
  }
  
  //Validate parent address.
  var address_one = frm.address_one.value;

  //Remove Leading and Trailing Spaces.
  if (address_one.length > 0)
  {
	address_one = removeAllSpaces(address_one);   
	frm.address_one.value = address_one;
  }

  //If Field is blank then display error
  if (!address_one)
  {
    alert("Parent address should not be left blank.");
	frm.address_one.focus();
	return false;
  }

  //Validate parent house no.
  var parent_house_no = frm.parent_house_no.value;

  //Remove Leading and Trailing blanks
  if (parent_house_no.length > 0)
  {
    parent_house_no = removeAllSpaces(parent_house_no);
	frm.parent_house_no.value = parent_house_no;
  }

  //Display alert if field is blank.
  if (!parent_house_no)
  {
    alert("Please enter parent house number.");
	frm.parent_house_no.focus();
	return false;
  }
  
  //Validate parent city
  var parent_city = frm.parent_city.value;

  //Remove Leading and Trailing blanks
  if (parent_city.length > 0)
  {
    parent_city = removeAllSpaces(parent_city);
	frm.parent_city.value = parent_city;
  }

  //Display alert if field is blank.
  if (!parent_city)
  {
    alert("Please enter parent city name.");
	frm.parent_city.focus();
	return false;
  }
  
  //Validate parent city
  var parent_state = frm.parent_state.value;

  //Remove Leading and Trailing blanks
  if (parent_state.length > 0)
  {
    parent_state = removeAllSpaces(parent_state);
	frm.parent_state.value = parent_state;
  }

  //Display alert if field is blank.
  if (!parent_state)
  {
    alert("Please enter parent state.");
	frm.parent_state.focus();
	return false;
  }
  
  //Validate parent State
  var parent_state = frm.parent_state.value;

  //Remove Leading and Trailing blanks
  if (parent_state.length > 0)
  {
    parent_state = removeAllSpaces(parent_state);
	frm.parent_state.value = parent_state;
  }

  //Display alert if field is blank.
  if (!parent_state)
  {
    alert("Please enter parent state.");
	frm.parent_state.focus();
	return false;
  }
  
  //Validate parent post_office
  var post_office = frm.post_office.value;

  //Remove Leading and Trailing blanks
  if (post_office.length > 0)
  {
    post_office = removeAllSpaces(post_office);
	frm.post_office.value = post_office;
  }

  //Display alert if field is blank.
  if (!post_office)
  {
    alert("Post office should not be left blank.");
	frm.post_office.focus();
	return false;
  }

  //Validate parent district
  var district = frm.district.value;

  //Remove Leading and Trailing blanks
  if (district.length > 0)
  {
    district = removeAllSpaces(district);
	frm.district.value = district;
  }

  //Display alert if field is blank.
  if (!district)
  {
    alert("District should not be left blank.");
	frm.district.focus();
	return false;
  }
  
  //Validate destination
  var destination = frm.destination.value;

  //Remove Leading and Trailing blanks
  if (destination.length > 0)
  {
    destination = removeAllSpaces(destination);
	frm.destination.value = destination;
  }

  //Display alert if field is blank.
  if (!destination)
  {
    alert("Destination should not be left blank.");
	frm.destination.focus();
	return false;
  }
  

  return true;
}
//######################################################################################################

//######################################################################################################
// This function will check house names checkbox selection.

function checkClassForm(frm)
{
  var class_name = frm.class_name.value;

  //Remove Leading and Trailing spaces.
  if (class_name.length > 0)
  {
	 class_name = removeAllSpaces(class_name);
	 frm.class_name.value = class_name;
  }

  //Display alert if fields is balnk.
  if (!class_name)
  {
	  alert('Please enter class name.');
	  frm.class_name.focus();
	  return false;

  }
  
  return true;
}

//######################################################################################################
// This function will check house names checkbox selection.

function checkExamForm(frm)
{
  var exam_name = frm.exam_name.value;

  //Remove Leading and Trailing spaces.
  if (exam_name.length > 0)
  {
	 exam_name = removeAllSpaces(exam_name);
	 frm.exam_name.value = exam_name;
  }

  //Display alert if fields is balnk.
  if (!exam_name)
  {
	  alert('Please enter examination name.');
	  frm.exam_name.focus();
	  return false;
  }
  
  return true;
}

//######################################################################################################
// This function will check class and related sections.

function checkClassSection(frm)
{
  var class_name = frm.class_id.options[frm.class_id.selectedIndex].text;
  var section_name = frm.section_id.options[frm.section_id.selectedIndex].text;
  
  //Get class name from section name.
  //If class name does not exits in the section then display alert.
  var class_section = section_name.substr(0,class_name.length);
  
  if (class_name != class_section)
  {
    alert("Please select setion of current class."); 
	return false;
  }
 
  return true;
}
//######################################################################################################

//######################################################################################################
// This function will check house names checkbox selection.

function checkSubjectClass(frm)
{
  //If section checkbox is not created then display alerts
  if (isCheckboxSelected(frm) == false)
  {
    alert("Please select subjects.");
	return false;
  }
  
  return true;
}
//######################################################################################################

//######################################################################################################
// This function will check subject marks.

function checkSubjectMarks(frm)
{
   var sel_status = 0;	
   for (var ctr=0; ctr < frm.length; ctr++)
   {	
	  var field_name = frm.elements(ctr).name;
	  if (field_name.indexOf("|") > 0)
	  {	    
		subject = frm.elements(ctr).value;
		if (subject.length > 0)
		{
          subject = removeAllSpaces(subject);
		  frm.elements(ctr).value = subject; 
		}
		if (!subject)
		{
          sel_status=ctr;
		  break;
		}
		else
		{
		   var marks_reg = new RegExp("[0-9.]");
		   if (marks_reg.test(subject) == false)
		   {
             sel_status=ctr;
		     break;
           }
		}
	  }
    }

   if (sel_status > 0)
   {
     
	 alert("Please enter marks of "+field_name.substr(0,field_name.indexOf("|")));
     frm.elements(sel_status).focus();
	 return false;
   }

  return true;
}
//######################################################################################################

//######################################################################################################
//This function will check edit marks form.

function checkEditMarks(frm)
{
  //Call method to check marks.
  return checkSubjectMarks(frm);
}

//######################################################################################################

//######################################################################################################
// This function will display a window

function openWindow(theURL,winName,w,h)
{
  var str = 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width='+w+',height='+h;
  window.open(theURL,winName,str);
}
//######################################################################################################

//######################################################################################################
//This function will check Parent Form.

function checkParentForm(frm)
{
  var school_no = frm.school_no.value;
  var scholar_name = frm.scholar_name.value;
  var parent_email = frm.parent_email.value;
  
  //Remove Leading and Trailing Spaces.
  if (school_no.length > 0)
  {
    school_no = removeAllSpaces(school_no);
	frm.school_no.value = school_no;
  }

  //If field is blank then display error.
  if (!school_no)
  {
    alert("Please enter school number.");
	frm.school_no.focus();
	return false;
  }
  
  //Remove Leading and Trailing Spaces.
  if (scholar_name.length > 0)
  {
    scholar_name = removeAllSpaces(scholar_name);
	frm.scholar_name.value = scholar_name;
  }

  //If field is blank then display error.
  if (!scholar_name)
  {
    alert("Please enter scholar name.");
	frm.scholar_name.focus();
	return false;
  }
  
  //Remove Leading and Trailing Spaces.
  if (parent_email.length > 0)
  {
    parent_email = removeAllSpaces(parent_email);
	frm.parent_email.value = parent_email;
  }

  //If field is blank then display error.
  if (!parent_email)
  {
    alert("Please enter parent email.");
	frm.parent_email.focus();
	return false;
  }
  else
  {
     if (validateEmail(parent_email)== false)
     {
        alert("Please enter correct parent email.");
		frm.parent_email.focus();
		return false;
     }
  }

  return true;
}
//######################################################################################################

//######################################################################################################
//This function will check Parent Registration Form.

function checkParentRegForm(frm)
{
  var login_name = frm.login_name.value;
  var password = frm.password.value;
  var conf_password = frm.conf_password.value;
  var email = frm.email.value;

  //Remove Leading and Trailing spaces.
  if (login_name.length > 0)
  {
    login_name = removeAllSpaces(login_name);
	frm.login_name.value = login_name;
  }

  //Display alert if field is blank.
  if (!login_name)
  { 
    alert("Please enter login name.");
	frm.login_name.focus();
	return false;
  }
  
  //Remove Leading and Trailing spaces.
  if (password.length > 0)
  {
    password = removeAllSpaces(password);
	frm.password.value = password;
  }

  //Display alert if field is blank.
  if (!password)
  { 
    alert("Please enter password.");
	frm.password.focus();
	return false;
  }
  
  //Remove Leading and Trailing spaces.
  if (conf_password.length > 0)
  {
    conf_password = removeAllSpaces(conf_password);
	frm.conf_password.value = conf_password;
  }

  //Display alert if field is blank.
  if (!conf_password)
  { 
    alert("Please enter confirm password.");
	frm.conf_password.focus();
	return false;
  }

  //Match Password and Confirm passord. Display error if they does not match.
  for (var ctr=0;ctr < password.length ; ctr++)
  {
	 if (password.charAt(ctr) != conf_password.charAt(ctr))
	 {
		 alert("Confirm password does not match. Please re-enter.");
		 frm.conf_password.value = "";
		 frm.conf_password.focus();
		 return false;
	 }
  }  
  
  //Remove Leading and Trailing Spaces.
  if (email.length > 0)
  {
    email = removeAllSpaces(email);
	frm.email.value = email;
  }

  //If field is blank then display error.
  if (!email)
  {
    alert("Please enter email.");
	frm.email.focus();
	return false;
  }
  else
  {
     if (validateEmail(email)== false)
     {
        alert("Please enter correct email.");
		frm.email.focus();
		return false;
     }
  }

  return true;
}
//######################################################################################################

//######################################################################################################
//This function will check Parent Registration Form.

function checkLoginForm(frm)
{
  var login_name = frm.login_name.value;
  var password = frm.password.value;

  //Remove Leading and Trailing spaces.
  if (login_name.length > 0)
  {
    login_name = removeAllSpaces(login_name);
	frm.login_name.value = login_name;
  }

  //Display alert if field is blank.
  if (!login_name)
  { 
    alert("Please enter login name.");
	frm.login_name.focus();
	return false;
  }
  
  //Remove Leading and Trailing spaces.
  if (password.length > 0)
  {
    password = removeAllSpaces(password);
	frm.password.value = password;
  }

  //Display alert if field is blank.
  if (!password)
  { 
    alert("Please enter password.");
	frm.password.focus();
	return false;
  }

  return true;
}
//######################################################################################################

//######################################################################################################
// This fucntion will check Notice Form.

function checkNoticeForm(frm)
{
   var notice = frm.notice.value;

   //Remove Leading and Trailing Spaces
   if (notice.length > 0)
   { 
	 notice = removeAllSpaces(notice);   
	 frm.notice.value = notice;
   }

   //Display Error if field is blank.
   if (!notice)
   {
     alert("Please enter notice.");
	 frm.notice.focus();
     return false;
   } 

   return true;

 }

//######################################################################################################

//######################################################################################################
//This function will check Chat Form.

function checkChatForm(frm)
{
  var chat_subject = frm.chat_subject.value;
  var chat_date = frm.chat_date.value;

  //Remove Leading and Trailing spaces.
  if (chat_subject.length > 0)
  {
    chat_subject = removeAllSpaces(chat_subject);
	frm.chat_subject.value = chat_subject;
  }

  //Display alert if field is blank.
  if (!chat_subject)
  { 
    alert("Please enter chat subject.");
	frm.chat_subject.focus();
	return false;
  }
  
  if (chat_date.length > 0)
  {
     chat_date = removeAllSpaces(chat_date);
	 frm.chat_date.value = chat_date;
  }
  
  if (!chat_date)
  {
    alert("Please enter valid chat date.");
	frm.chat_date.focus();
	return false;
  }
  else
  {
	  //If chat_date is there then validate that date.
	  //Date should not be less than current date.     

		 var slash_ctr=0;
		 for (var ctr=0; ctr < chat_date.length; ctr++)
		 {
			 if (chat_date.charAt(ctr) == '/')
			 {
			   slash_ctr++;
			 }
		 }

		 if (slash_ctr != 2)
		 {
		   alert("Please enter valid date");
		   frm.chat_date.focus();
		   return false;
		 }
		 
		 //if happening date is valid then get dd.mm.yyyy
		 var chat_date_arr = chat_date.split("/");
		 var chat_date_dd = chat_date_arr[0];
		 var chat_date_mm = chat_date_arr[1];
		 var chat_date_yyyy = chat_date_arr[2];

		 if (chat_date_dd.length == 0 || chat_date_mm.length == 0 || chat_date_yyyy.length != 4)
		 {
			 alert("Please enter valid date");
			 frm.chat_date.focus();
			 return false;
		 }
		
		//If day and month begin with 0 then get last digit of day and month
		chat_date_dd = (chat_date_dd.charAt(0) == '0')? chat_date_dd.charAt(1) : chat_date_dd;
		chat_date_mm = (chat_date_mm.charAt(0) == '0')? chat_date_mm.charAt(1) : chat_date_mm;
		
		//Display alert if day > 31 and month > 12
		if (chat_date_dd > 31 || chat_date_mm > 12)
		{
		  alert("Please enter valid date.");
		  frm.chat_date.focus();
		  return false;
		}

		//Call checkDate(YYYY,MM,DD) to validate the date.
		if (checkDate(chat_date_yyyy, chat_date_mm, chat_date_dd) == false)
		{
		  alert("Chat date should not be less than current date.");
		  frm.chat_date.focus();
		  return false;
		}

   }//End of Else.
   
  //Get from time.
  var from_time_hh = parseInt(frm.from_time_hh.options[frm.from_time_hh.selectedIndex].value);
  var from_time_min = parseInt(frm.from_time_min.options[frm.from_time_min.selectedIndex].value);
  
  //Get to time.
  var to_time_hh = parseInt(frm.to_time_hh.options[frm.to_time_hh.selectedIndex].value);
  var to_time_min = parseInt(frm.to_time_min.options[frm.to_time_min.selectedIndex].value);
  
  //If To time <= From time then display alert message.
  if ((to_time_hh <= from_time_hh) && (to_time_min <= from_time_min))
  {
	alert("To time should be greater than from time.");
    frm.to_time_hh.focus();
	return false;
  }

  return true;
}

//######################################################################################################
//This function will check ChatForm checkboxes.

function checkChatCheckbox(frm)
{
  //If section checkbox is not created then display alerts
  if (isCheckboxSelected(frm) == false)
  {
    alert("Please select checkbox for deletion.");
	return false;
  }
  
  return true;
}
//######################################################################################################

//######################################################################################################
//This function will check Notice checkboxes.

function checkNoticeCheckbox(frm)
{
  //If section checkbox is not created then display alerts
  if (isCheckboxSelected(frm) == false)
  {
    alert("Please select checkbox for deletion.");
	return false;
  }
  
  return true;
}
//######################################################################################################

//######################################################################################################
//This function will check ClassAllotment Form.

function checkClassAllotment(frm)
{
   var sel_status = false;

   for (var ctr=0; ctr < frm.length; ctr++)
   {
	   var field_name = frm.elements(ctr).name;
	   if (field_name.indexOf("\|") > 0)
	   {
		  if (frm.elements(ctr).selectedIndex != 0)
		  {
			  sel_status= true;
			  break;
	      }
		  
	  }
   }
	  
  //If section checkbox is not created then display alerts
  if (sel_status == false)
  {
	alert("Please select class that is taught by this faculty.");
	return false;
  }
  
  return true;
}
//######################################################################################################

//######################################################################################################
//This function will check ProductForm.

function checkProductForm(frm)
{
  var prod_name = frm.prod_name.value;
  var prod_desc = frm.prod_desc.value;
  var prod_price = frm.prod_price.value;
  var prod_file = frm.prod_file.value;

  var reg = new RegExp("[a-zA-Z!@#$^&*_|~`]");

  //Remove Leading and Trailing spaces.
  if (prod_name.length > 0)
  {
    prod_name = removeAllSpaces(prod_name);
	frm.prod_name.value = prod_name;
  }
  
  //Display error if fields is blank
  if (!prod_name)
  {
     alert("Please enter product title.");
	 frm.prod_name.focus();
	 return false;
  }

  //Remove Leading and Trailing spaces.
  if (prod_desc.length > 0)
  {
    prod_desc = removeAllSpaces(prod_desc);
	frm.prod_desc.value = prod_desc;
  }
  
  //Display error if fields is blank
  if (!prod_desc)
  {
     alert("Please enter product description.");
	 frm.prod_desc.focus();
	 return false;
  }

  //Remove Leading and Trailing Blank Spaces.
  if (prod_price.length > 0)
  {
    prod_price = removeAllSpaces(prod_price);
	frm.prod_price.value = prod_price;
  }

  //Display Error if field is blank.
  if (!prod_price)
  {
     alert("Please enter product price.");
	 frm.prod_price.focus();
	 return false;
  }
  else
  {
     //Check product price.
	 if (reg.test(prod_price) == true)
	 {
       alert("Please enter valid product price.");
	   frm.prod_price.focus();
	   return false;
	 }
  }
  
  //Remove Leading and Trailing Spaces.
  if(prod_file.length > 0)
  {
    prod_file = removeAllSpaces(prod_file);
	frm.prod_file.value = prod_file;
  }
  
  //If img_file has some value then check validity of the file name.
  if (!prod_file)
  {
    alert("Please select product image file.");
	frm.prod_file.focus();
	return false;
  }
  else
  {
     if (prod_file.indexOf(".") == -1)
     {
		alert("Please select correct image file.");
        frm.prod_file.focus();
		return false;
     }
	 else
	 {
	    //If file has dot (.) then split it and identify image type .gif, .jpg		
        var file_ext = prod_file.substr(prod_file.lastIndexOf(".")+1);

		if (!(file_ext == "gif" || file_ext == "GIF" || file_ext == "jpg" || file_ext == "JPG"))
	    {
			alert("Please select only gif or jpg image file.");
			frm.prod_file.focus();
			return false;
	    }
	 }    
  }

  return true;
}

//######################################################################################################

//######################################################################################################
//This function will allow to select all checkboxes.

function checkProductCheckbox(frm)
{
  //If section checkbox is not created then display alerts
  if (isCheckboxSelected(frm) == false)
  {
    alert("Please select checkbox for deletion.");
	return false;
  }
  
  return true;
}
//######################################################################################################

//######################################################################################################
//This function will check ProductForm.

function checkEditProductForm(frm)
{
  var prod_name = frm.prod_name.value;
  var prod_desc = frm.prod_desc.value;
  var prod_qty = frm.prod_qty.value;
  var prod_price = frm.prod_price.value;

  var reg = new RegExp("[a-zA-Z!@#$^&*_|~`]");

  //Remove Leading and Trailing spaces.
  if (prod_name.length > 0)
  {
    prod_name = removeAllSpaces(prod_name);
	frm.prod_name.value = prod_name;
  }
  
  //Display error if fields is blank
  if (!prod_name)
  {
     alert("Please enter product title.");
	 frm.prod_name.focus();
	 return false;
  }

  //Remove Leading and Trailing spaces.
  if (prod_desc.length > 0)
  {
    prod_desc = removeAllSpaces(prod_desc);
	frm.prod_desc.value = prod_desc;
  }
  
  //Display error if fields is blank
  if (!prod_desc)
  {
     alert("Please enter product description.");
	 frm.prod_desc.focus();
	 return false;
  }
  
  //Remove Leading and Trailing spaces.
  if (prod_qty.length > 0)
  {
    prod_qty = removeAllSpaces(prod_qty);
	frm.prod_qty.value = prod_qty;
  }
  
  //Display error if fields is blank
  if (!prod_qty)
  {
     alert("Please enter product quantity.");
	 frm.prod_qty.focus();
	 return false;
  }
  else
  {
     //Check product quantity.
	 if (reg.test(prod_qty) == true)
	 {
       alert("Please enter valid number.");
	   frm.prod_qty.focus();
	   return false;
	 }
  }
  
  //Remove Leading and Trailing Blank Spaces.
  if (prod_price.length > 0)
  {
    prod_price = removeAllSpaces(prod_price);
	frm.prod_price.value = prod_price;
  }

  //Display Error if field is blank.
  if (!prod_price)
  {
     alert("Please enter product price.");
	 frm.prod_price.focus();
	 return false;
  }
  else
  {
     //Check product price.
	 if (reg.test(prod_price) == true)
	 {
       alert("Please enter valid product price.");
	   frm.prod_price.focus();
	   return false;
	 }
  }  

  return true;
}

//######################################################################################################

//######################################################################################################
// This function will check fort news form. 

function checkFortNews(frm)
{
  var news_title = frm.news_title.value;
  var news_desc = frm.news_desc.value;

  //Remove Leading and trailing spaces.
  if (news_title.length > 0)
  {
    news_title = removeAllSpaces(news_title);
	frm.news_title.value = news_title;
  }

  //Display alert if field is blank
  if (!news_title)
  {
    alert("Please enter news title.");
	frm.news_title.focus();
	return false;
  }

  //Remove Leading and trailing spaces.
  if (news_desc.length > 0)
  {
    news_desc = removeAllSpaces(news_desc);
	frm.news_desc.value = news_desc;
  }

  //Display alert if field is blank
  if (!news_desc)
  {
    alert("Please enter news description.");
	frm.news_desc.focus();
	return false;
  }

  return true;
}
//######################################################################################################

//######################################################################################################
//

function checkContents(frm)
{
  
  var contents = frm.contents.value;
  var year = frm.year.value;

   //Remove Leading and Trailing Blanks
  if(contents.length > 0)
  {
    contents = removeAllSpaces(contents);
    frm.contents.value = contents;
  }

  //Display Alert if fields is blank.
  if (!contents)
  {
    alert("Please paste html contents.");
	frm.contents.focus();
	return false;
  }
  
  //Remove Leading and Trailing Blanks
  if(year.length > 0)
  {
    year = removeAllSpaces(year);
    frm.year.value = year;
  }

  //Display Alert if fields is blank.
  if (!year)
  {
    alert("Year should not be left blank.");
	frm.year.focus();
	return false;
  }
  else
  {
    if (isNaN(year) == true)
    {
      alert("Please enter year in four digits e.g. 1975");
	  frm.year.focus();
	  return false;
    }

	var dt = new Date();
	cur_year = dt.getFullYear();

	if (year > cur_year)
	{
      alert("Year should not be greater than current year.");
	  frm.year.focus();
	  return false;
	}
  
  }

  return true;
}

//######################################################################################################

//######################################################################################################
//

function checkPDFFile(frm)
{
 
  var year = frm.year.value;
  var file_path = frm.pub_file.value;
  var file_name = file_path.substr((file_path.lastIndexOf(".")+1));
 
  //Check Year.
  if (checkYear(frm) == false)
  {
    return false;
  }
  
  //Remove leading and trailing spaces.
  if (file_name.length > 0)
  { 
    file_name = removeAllSpaces(file_name);
	frm.pub_file.value = file_name;
  } 

  //If file name is blank then display alert message.
  if (!file_name)
  {
	alert("Please select PDF file.");
	frm.pub_file.focus();
	return false;
  }
  else
  {
    //Display alert if file extension is not html or htm
	if ((file_name == "pdf") || (file_name == "PDF"))
    {
      return true;
    }
	else
	{
	  alert("Please select pdf file only.");
	  frm.pub_file.focus();
	  return false;
	}
  } 
  
  return true;
}


//######################################################################################################



function checkCSVFile(frm)
{
 
  var file_path = frm.parents_file.value;
  var file_name = file_path.substr((file_path.lastIndexOf(".")+1));
 
  //Remove leading and trailing spaces.
  if (file_name.length > 0)
  { 
    file_name = removeAllSpaces(file_name);
	frm.parents_file.value = file_name;
  } 

  //If file name is blank then display alert message.
  if (!file_name)
  {
	alert("Please select CSV file.");
	frm.parents_file.focus();
	return false;
  }
  else
  {
    //Display alert if file extension is not html or htm
	if ((file_name == "csv") || (file_name == "CSV"))
    {
      return true;
    }
	else
	{
	  alert("Please select CSV file only.");
	  frm.parents_file.focus();
	  return false;
	}
  } 
  
  return true;
}


//######################################################################################################

//######################################################################################################
//

function checkArchiveReview(frm)
{  
	
  if (frm.edition.selectedIndex == "0")
  {
    alert("Please Select Edition.");
	return false;
  }

  return true;
}
//######################################################################################################

//######################################################################################################
// This function will check image caption and image file name.

function checkGeneralImgCategory(frm)
{
   if (checkCurrentEventImages(frm) == false)
   {
      return false;
   }  

  return true;

}
//######################################################################################################



//######################################################################################################
// This function will display alert if admin submit without selecting the checkbox.
//
function checkAdminTask(frm)
{
  //If section checkbox is not created then display alerts
  if (isCheckboxSelected(frm) == false)
  {
    return confirm("You have not selected any task. Do you still want to submit?");
	
  }
  
  return true;
}

//######################################################################################################

//######################################################################################################
//

function checkPageNo(frm)
{
  var page = frm.page.value;
  var reg = new RegExp("[0-9]");
  
  if (reg.test(page) == false)
  {
    alert("Please enter valid page number.");
	frm.page.focus();
	return false;
  }

  return true;	
}

//######################################################################################################

//######################################################################################################
//

function checkResume(frm)
{
  
  var first_name = frm.first_name.value;
  var last_name = frm.last_name.value;
  var address = frm.address.value;
  var city = frm.city.value;
  var state = frm.state.value;
  var pin = frm.pin.value;
  var experience = frm.experience.value;
  var cover_letter = frm.cover_letter.value;
  var cv_file = frm.cv_file.value;

  //Remove Leading and Training blanks
  if (first_name.length > 0)
  {
	first_name = removeAllSpaces(first_name);
	frm.first_name.value = first_name;
  }

  //Display alert if field is blank.
  if (!first_name)
  {
    alert("Please enter your first name.");
	frm.first_name.focus();
	return false;
  }
  
  //Remove Leading and Training blanks
  if (last_name.length > 0)
  {
	last_name = removeAllSpaces(last_name);
	frm.last_name.value = last_name;
  }

  //Display alert if field is blank.
  if (!last_name)
  {
    alert("Please enter your last name.");
	frm.last_name.focus();
	return false;
  }

  //Remove Leading and Training blanks
  if (address.length > 0)
  {
	address = removeAllSpaces(address);
	frm.address.value = address;
  }

  //Display alert if field is blank.
  if (!address)
  {
    alert("Please enter your address.");
	frm.address.focus();
	return false;
  }
  
  //Remove Leading and Training blanks
  if (city.length > 0)
  {
	city = removeAllSpaces(city);
	frm.city.value = city;
  }

  //Display alert if field is blank.
  if (!city)
  {
    alert("Please enter your city.");
	frm.city.focus();
	return false;
  }

  //Remove Leading and Training blanks
  if (state.length > 0)
  {
	state = removeAllSpaces(state);
	frm.state.value = state;
  }

  //Display alert if field is blank.
  if (!state)
  {
    alert("Please enter your state.");
	frm.state.focus();
	return false;
  }

  //Remove Leading and Training blanks
  if (pin.length > 0)
  {
	pin = removeAllSpaces(pin);
	frm.pin.value = pin;
  }

  //Display alert if field is blank.
  if (!pin)
  {
    alert("Please enter your pin code.");
	frm.pin.focus();
	return false;
  }
  else
  {
     if (isNaN(pin))
     {
       alert("Please enter valid pin code.");
	   frm.pin.focus();
	   return false;
     }	
  }
   
  //Remove Leading and Training blanks
  if (experience.length > 0)
  {
	experience = removeAllSpaces(experience);
	frm.experience.value = experience;
  }

  //Display alert if field is blank.
  if (!experience)
  {
    alert("Please enter your experience.");
	frm.experience.focus();
	return false;
  }
  else
  {
	 if (isNaN(experience))
     {
       alert("Please enter valid experience.");
	   frm.experience.focus();
	   return false;
     }	  
  }

  //Remove Leading and Training blanks
  if (cover_letter.length > 0)
  {
	cover_letter = removeAllSpaces(cover_letter);
	frm.cover_letter.value = cover_letter;
  }

  //Display alert if field is blank.
  if (!cover_letter)
  {
    alert("Please enter cover letter.");
	frm.cover_letter.focus();
	return false;
  }

  //Remove Leading and Training blanks
  if (cv_file.length > 0)
  {
	cv_file = removeAllSpaces(cv_file);
	frm.cv_file.value = cv_file;
  }

  //Display alert if field is blank.
  if (!cv_file)
  {
    alert("Please select your resume file.");
	frm.cv_file.focus();
	return false;
  }
  
  //If cv_file has some value then check validity of the file name.
  if (cv_file.length > 0)
  {
     if (cv_file.indexOf(".") == -1)
     {
		alert("Please select correct resume file.");
        frm.cv_file.focus();		
		return false;
     }
	 else
	 {
	    //If file has dot (.) then split it and identify image type .doc, .rtf		
        var file_ext = cv_file.substr(cv_file.indexOf(".")+1);

		if (!(file_ext == "doc" || file_ext == "DOC" || file_ext == "rtf" || file_ext == "RTF"))
	    {
			alert("Please attach a .doc or .rtf file only for your resume.");
			frm.cv_file.focus();			
			return false;
	    }

	  }//End of else    

   }//End of outer If

  return true;	
}

//######################################################################################################

//######################################################################################################
//

function checkResumeCheckbox(frm)
{
  //If section checkbox is not selecteds then display alert
  if (isCheckboxSelected(frm) == false)
  {
    alert("Please select checkbox for deletion.");
	return false;
  }
  
  return true;
}
//######################################################################################################

//######################################################################################################
//

function checkCurrentNews(frm)
{
  var news_no = frm.news_no.value;
  

  //Remove Leading and Trailing blank spaces.
  if (news_no.length > 0)
  {
    news_no = removeAllSpaces(news_no);
  }

  if (!news_no)
  {
    alert("Please enter number of current news to display.");
	frm.news_no.focus();
	return false;
  }
  else
  {
    if (isNaN(news_no) == true)
    {
      alert("Please enter only number.");
	  frm.news_no.focus();
	  return false;
    }

	if (news_no <= 1)
	{
      alert("Number of current news item should be greater than one.");
	  frm.news_no.focus();
	  return false;
	}
  }
  
  return true;
}

//######################################################################################################

//######################################################################################################
//

function checkSOBAPosting(frm)
{
  var first_name = frm.first_name.value;
  var last_name = frm.last_name.value;
  var house_name = frm.house_name.value;
  var from_year = frm.from_year.value;
  var to_year = frm.to_year.value;

  //Remove Leading and Trailing Spaces.
  if (first_name.length > 0)
  {
    first_name = removeAllSpaces(first_name);
	frm.first_name.value = first_name;
  }

  //If field is blank then display alert.
  if (!first_name)
  {
    alert("Please enter first name.");
	frm.first_name.focus();
	return false;
  }
  
  //Remove Leading and Trailing Spaces.
  if (last_name.length > 0)
  {
    last_name = removeAllSpaces(last_name);
	frm.last_name.value = last_name;
  }

  //If field is blank then display alert.
  if (!last_name)
  {
    alert("Please enter last name.");
	frm.last_name.focus();
	return false;
  }

  //Remove Leading and Trailing Spaces.
  if (house_name.length > 0)
  {
    house_name = removeAllSpaces(house_name);
	frm.house_name.value = house_name;
  }

  //If field is blank then display alert.
  if (!house_name)
  {
    alert("Please enter house name.");
	frm.house_name.focus();
	return false;
  }
  
  //Remove Leading and Trailing Spaces.
  if (from_year.length > 0)
  {
    from_year = removeAllSpaces(from_year);
	frm.from_year.value = from_year;
  }

  //If field is blank then display alert.
  if (!from_year)
  {
    alert("Please enter from year.");
	frm.from_year.focus();
	return false;
  }
  else
  {
     if (isNaN(from_year)== true)
     {
       alert("Please enter from year in four digits like 1995.");
	   frm.from_year.focus();
	   return false;
     }
  } 
  
  //Remove Leading and Trailing Spaces.
  if (to_year.length > 0)
  {
    to_year = removeAllSpaces(to_year);
	frm.to_year.value = to_year;
  }

  //If field is blank then display alert.
  if (!to_year)
  {
    alert("Please enter to year.");
	frm.to_year.focus();
	return false;
  }
  else
  {
     if (isNaN(to_year)== true)
     {
       alert("Please enter to year in four digits like 1999.");
	   frm.to_year.focus();
	   return false;
     }
  } 

  return true;
}

//######################################################################################################

//######################################################################################################
//

function checkGalleryRadio(frm)
{
  //If section checkbox is not selecteds then display alert
  if (isRadioSelected(frm) == false)
  {
    alert("Please select radio button for deletion.");
	return false;
  }
  
  return true;
}
//######################################################################################################

//######################################################################################################
//

function checkGalleryCheckbox(frm)
{
  //If section checkbox is not selecteds then display alert
  if (isCheckboxSelected(frm) == false)
  {
    alert("Please select checkbox for deletion.");
	return false;
  }
  
  return true;
}
//######################################################################################################

//######################################################################################################
//

function checkSpecifiedDate(frm)
{
  var specified_date = frm.specified_date.value;
  
   //Remove Leading and Trailing Spaces.
  if (specified_date.length > 0)
  {
    specified_date = removeAllSpaces(specified_date);
	frm.specified_date.value = specified_date;
  }
  
  //Display alert if field is blank
  if (!specified_date)
  {
	  alert("Specified date should not be left blank.");
	  frm.specified_date.focus();
	  return false;
  }
  else
  {
     //If specified date is there then validate that date.
	 //Date should not be less than current date.

	 var slash_ctr=0;
	 for (var ctr=0; ctr < specified_date.length; ctr++)
	 {
		 if (specified_date.charAt(ctr) == '/')
		 {
           slash_ctr++;
		 }
	 }

	 if (slash_ctr != 2)
	 {
       alert("Please enter valid date");
	   frm.specified_date.focus();
	   return false;
	 }
	 
	 //if specified date is valid then get dd.mm.yyyy
	 var specified_arr = specified_date.split("/");
	 var specified_dd = specified_arr[0];
	 var specified_mm = specified_arr[1];
	 var specified_yyyy = specified_arr[2];

	 if (specified_dd.length == 0 || specified_mm.length == 0 || specified_yyyy.length != 4)
	 {
		 alert("Please enter valid date");
		 frm.specified_date.focus();
		 return false;
	 }
	
	//If day and month begin with 0 then get last digit of day and month
	specified_dd = (specified_dd.charAt(0) == '0')? specified_dd.charAt(1) : specified_dd;
    specified_mm = (specified_mm.charAt(0) == '0')? specified_mm.charAt(1) : specified_mm;
	
	//Display alert if day > 31 and month > 12
	if (specified_dd > 31 || specified_mm > 12)
	{
      alert("Please enter valid date.");
	  frm.specified_date.focus();
	  return false;
	}

	return true;
 }

}//End of function. 

//######################################################################################################

//######################################################################################################
// This function display alert if year is not numeric and greater than current year.

function checkYear(frm)
{
  var year = frm.year.value;
  
  //Remove Leading and Trailing Blanks
  if(year.length > 0)
  {
    year = removeAllSpaces(year);
    frm.year.value = year;
  }

  //Display Alert if fields is blank.
  if (!year)
  {
    alert("Year should not be left blank.");
	frm.year.focus();
	return false;
  }
  else
  {
    if (isNaN(year) == true)
    {
      alert("Please enter year in four digits e.g. 1975");
	  frm.year.focus();
	  return false;
    }
    
	if (year.length < 4)
    {
      alert("Please enter year in four digits e.g. 1975");
	  frm.year.focus();
	  return false;
    }


	var dt = new Date();
	cur_year = dt.getFullYear();

	if (year > cur_year)
	{
      alert("Year should not be greater than current year.");
	  frm.year.focus();
	  return false;
	}
  
  }

  return true;

}//End of function. 

//######################################################################################################

//######################################################################################################
// This function display alert if user is searching blanks.

function checkSearchForm(frm)
{
  var search_text = frm.search_text.value;

  //Remove Leading and Trailing Spaces.
  if (search_text.length > 0)
  {
    search_text = removeAllSpaces(search_text);
	frm.search_text.value = search_text;
  }
  
  //Display Alert if field is blank.
  if (!search_text)
  {
	  alert("Please enter search string.");
	  frm.search_text.focus();
	  return false;
  }

  return true;
} 

//######################################################################################################

//######################################################################################################
// This function display alert if meal fields are blank.

function checkMeals(frm)
{
  var breakfast = frm.breakfast.value;
  var school_refreshment = frm.school_refreshment.value;
  var lunch = frm.lunch.value;
  var evening_refreshment = frm.evening_refreshment.value;
  var dinner = frm.dinner.value;


  //Remove Leading and Trailing Spaces.
  if (breakfast.length > 0)
  {
    breakfast = removeAllSpaces(breakfast);
	frm.breakfast.value = breakfast;
  }
  
  //Display Alert if field is blank.
  if (!breakfast)
  {
	  alert("Breakfast should not be left blank.");
	  frm.breakfast.focus();
	  return false;
  }
  
  //Remove Leading and Trailing Spaces.
  if (school_refreshment.length > 0)
  {
    school_refreshment = removeAllSpaces(school_refreshment);
	frm.school_refreshment.value = school_refreshment;
  }
  
  //Display Alert if field is blank.
  if (!school_refreshment)
  {
	  alert("School refreshment should not be left blank.");
	  frm.school_refreshment.focus();
	  return false;
  }
  
  //Remove Leading and Trailing Spaces.
  if (lunch.length > 0)
  {
    lunch = removeAllSpaces(lunch);
	frm.lunch.value = lunch;
  }
  
  //Display Alert if field is blank.
  if (!lunch)
  {
	  alert("Lunch should not be left blank.");
	  frm.lunch.focus();
	  return false;
  }
  
  //Remove Leading and Trailing Spaces.
  if (evening_refreshment.length > 0)
  {
    evening_refreshment = removeAllSpaces(evening_refreshment);
	frm.evening_refreshment.value = evening_refreshment;
  }
  
  //Display Alert if field is blank.
  if (!evening_refreshment)
  {
	  alert("Evening refreshment should not be left blank.");
	  frm.evening_refreshment.focus();
	  return false;
  }
  
  //Remove Leading and Trailing Spaces.
  if (dinner.length > 0)
  {
    dinner = removeAllSpaces(dinner);
	frm.dinner.value = dinner;
  }
  
  //Display Alert if field is blank.
  if (!dinner)
  {
	  alert("Dinner should not be left blank.");
	  frm.dinner.focus();
	  return false;
  }

  return true;
} 

//######################################################################################################

//######################################################################################################
// This function will display alerts if meal notes or spcial meal notes are blank. 

function checkNotes(frm)
{
  var notes = frm.notes.value;

  //Remove Leading and Trailing Spaces.
  if (notes.length > 0)
  {
    notes = removeAllSpaces(notes);
	frm.notes.value = notes;
  }
  
  //Display Alert if field is blank.
  if (!notes)
  {
	  alert("Note should not be left blank.");
	  frm.notes.focus();
	  return false;
  }

  return true;
} 
//######################################################################################################

//######################################################################################################
//

function checkCheckbox(frm)
{
  //If section checkbox is not selecteds then display alert
  if (isCheckboxSelected(frm) == false)
  {
    alert("Please select product that you want to purchase.");
	return false;
  } 
  
  return true;
}

function checkArticle(frm)
{
  var news_title = frm.title.value;
  var news_desc = frm.article_desc.value;

  //Remove Leading and trailing spaces.
  if (news_title.length > 0)
  {
    news_title = removeAllSpaces(news_title);
	frm.title.value = news_title;
  }

  //Display alert if field is blank
  if (!news_title)
  {
    alert("Please enter title.");
	frm.title.focus();
	return false;
  }

  //Remove Leading and trailing spaces.
  if (news_desc.length > 0)
  {
    news_desc = removeAllSpaces(news_desc);
	frm.article_desc.value = news_desc;
  }

  //Display alert if field is blank
  if (!news_desc)
  {
    alert("Please enter description.");
	frm.article_desc.focus();
	return false;
  }

  return true;
}
//######################################################################################################


