function isValid(f){
	if(Trim(f.toemail.value)=="")
	{
		alert("Please enter email address.");
		f.toemail.value = '';
		f.toemail.focus();
		return false;
	}
	else if(Trim(f.toemail.value))
	{
		email = substr(f.toemail.value,0,-1);
		email_arr = email.split(",");
		for(i=0;i<email_arr.length;i++)
		{
			if(!isValidEmailRex(email_arr[i]))
			{
				alert("Please enter valid email address.");
				f.toemail.focus();
				return false;
			}
		}
    }
}

function Trim(s)
{
  // Remove leading spaces and carriage returns
  
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }

  // Remove trailing spaces and carriage returns

  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}

//Valid Email Using Regular Expression
function isValidEmailRex(emailAddress) {
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[(2([0-4]\d|5[0-5])|1?\d{1,2})(\.(2([0-4]\d|5[0-5])|1?\d{1,2})){3} \])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
    return re.test(emailAddress);
}

function substr (str, start, len) {
    str += '';
    var end = str.length;
    if (start < 0) {
        start += end;
    }
    end = typeof len === 'undefined' ? end : (len < 0 ? len + end : len + start);
    // PHP returns false if start does not fall within the string.
    // PHP returns false if the calculated end comes before the calculated start.
    // PHP returns an empty string if start and end are the same.
    // Otherwise, PHP returns the portion of the string from start to end.
    return start >= str.length || start < 0 || start > end ? !1 : str.slice(start, end);
}
