function f_ltrim(p_s) {
  var i=0;
  if (p_s==null) return "";

  while (p_s.charAt(i)==' ' && i<p_s.length) i++;
  return p_s.substr(i);
}

function f_rtrim(p_s) {
  var i=0;
  if (p_s==null) return "";

  i = p_s.length - 1;
  while (p_s.charAt(i)==' ' && i<p_s.length) i--;
  return p_s.substr(0,i + 1);
}

function f_trim(p_s) {
  var l_s='';
  if (p_s==null) return "";

  l_s = f_rtrim(p_s);
  return f_ltrim(l_s);
}
function f_validate_date(ps_date)
{
 //string:ps_date should be yyyy-mm-dd
  var today=new Date()
  var v_year = today.getYear()
  
  if (v_year>100) { v_year -= 1900 };
  t3 = new String (ps_date);
  var year = t3.slice(0,t3.search('-')) - 1900 ;
  //if (year>v_year)   return false;
  t3 = t3.substr(t3.search('-')+1);
  var month = t3.slice(0,t3.search('-'));
  if (month<1 || month>12)
      return false;
  t3 = t3.substr(t3.search('-')+1);
  var day = t3;
  if (day<1 || day>31)
      return false;
  var v_ndate = new Date(1900+year,month-1,day);
  v_year = v_ndate.getYear()
  if (v_year>100) { v_year -= 1900 };
  if (year!=v_year || month!=(v_ndate.getMonth()+1) || day!=v_ndate.getDate())
      return false;
  return true;
}

function popupWindow(url,wname) {
         window.open(url,wname).focus()
}
function f_chk_dbquotes(text){
	if (text.value.indexOf("\"")>=0){
		alert("Please remove the double quotation marks or replace them with single ones")
		text.focus()
		return false
	}
	return true;
}
function f_chk_empty(text){
	text.value = f_trim(text.value)
	if (text.value==""){
		alert("This area can't be empty")
		text.focus()
		return false
	}
	return true;
}
