function isValidName(sn)
{
	s = trim(sn.value)+'';
	if (s&&(/^[a-zA-Z\.\- ]+$/.test(s)))
  {
  	RestoreFieldStyle(sn);
  	return true;
  }
  else
  {
  	HighlightErrorField(sn);
  	return false;
  }
}

function isValidPassword(sn)
{
	s = trim(sn.value)+'';
	if (s&&(/([0-9a-zA-z\.\,\-\=\_\+]+){5}/.test(s)))
  {
  	RestoreFieldStyle(sn);
  	return true;
  }
  else
  {
  	HighlightErrorField(sn);
  	return false;
  }
}

function isValid(sn)
{
  s = trim(sn.value)+'';
  if (s)
  {
  	RestoreFieldStyle(sn);
  	return true;
  }
  else
  {
  	HighlightErrorField(sn);
  	return false;
  }
}

function isValidEmail(sn)
{
	s = trim(sn.value)+'';
	if(s && (/^\w+([\.\-]?\w+)*@\w+([\.\-]?\w+)*(\.\w{2,3})+$/.test(s)))

	{
  	RestoreFieldStyle(sn);
  	return true;
  }
  else
  {
  	HighlightErrorField(sn);
  	return false;
  }
}

function isValidUserName(sn)
{
	s = trim(sn.value)+'';

	if(s && (/^[\w]{1,}[\w\d_]{1,}$/.test(s)))
	{
  	RestoreFieldStyle(sn);
  	return true;
  }
  else
  {
  	HighlightErrorField(sn);
  	return false;
  }
}

function isValidUserGroup(sn)
{
	s = trim(sn.value)+'';
	if(s && (/^[\d]+$/.test(s)))

	{
  	RestoreFieldStyle(sn);
  	return true;
  }
  else
  {
  	HighlightErrorField(sn);
  	return false;
  }
}

function isValidNumber(sn)
{
	s = trim(sn.value)+'';
	if(s && (/^[\d]+$/.test(s)))
	{
		RestoreFieldStyle(sn);
		return true;
	}
	else
	{
		HighlightErrorField(sn);
		return false;
	}

}

function isValidDate(sn)
{
	s = trim(sn.value)+'';
	if( s && (/^[\d]+$/.test(s)) && (Number(s) > 0) )
	{
		RestoreFieldStyle(sn);
		return true;
	}
	else
	{
		HighlightErrorField(sn);
		return false;
	}

}

function isValidYear(sn)
{
	s = trim(sn.value)+'';
	if( s && (/^[\d]+$/.test(s)) && (Number(s) >= 2000)  && (Number(s) <= 2010) )
	{
		RestoreFieldStyle(sn);
		return true;
	}
	else
	{
		HighlightErrorField(sn);
		return false;
	}

}

function isValidMYear(sn)
{
	s = trim(sn.value)+'';
	if( s && (/^[\d]+$/.test(s)) && (Number(s) >= 1800)  && (Number(s) <= 2010) )
	{
		RestoreFieldStyle(sn);
		return true;
	}
	else
	{
		HighlightErrorField(sn);
		return false;
	}

}

function isValidPhone(sn)
{

	s = trim(sn.value)+'';
	if(s && (/^[\d]{1,}([ ]{0,1}[\.,\(\)\-\/]{0,1}[ ]{0,1}[\d]{1,}[ ]{0,1}){0,}$/.test(s)))

	{
  	RestoreFieldStyle(sn);
  	return true;
  }
  else
  {
  	HighlightErrorField(sn);
  	return false;
  }
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
//   var inputString = inputField.value+'';
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

function HighlightErrorField(field)
{
  field.style.borderColor="#ff0000";
  field.style.background="#fff0f0";
}

function RestoreFieldStyle(field)
{
  field.style.borderColor="#025829";
  field.style.background="#ffffff";

}

/*
var correct = true;
function CheckForm()
{
	correct = true ;
  var err_msg = " ";

  if (!isValidName(trim(document.contactform.name)))
  {
  	err_msg = err_msg + "Please enter the client name correctly.\n";
    correct = false;
  }

  if (!isValid(trim(document.contactform.address)))
  {
  	err_msg = err_msg + "Please enter the address.\n";
    correct = false;
  }

  if (!correct)
  {
    alert("Error:\n"+err_msg);
  }
  return correct;
}
*/
