
function StartPrint()
{
  if(document.all)
  {
    print();
  }
  else
  {
    window.print();
  }
}

function validate_required(field, alerttxt)
{
 with (document.getElementById(field))
 {
   value = value.replace(/^\s*(.*?)\s*$/, "$1");  // trim
   if (value==null || value=="")
   {
     alert(alerttxt);
     focus();
     return false;
   }
 }
 return true;
}

function isValidChars(txt, validchars)
{
 for (i = 0; i < txt.length; i++)
  if (validchars.indexOf(txt.charAt(i)) == -1)
   return false
 return true
}

function validate_integer(field, alerttxt)
{
 with (document.getElementById(field))
 {
  value = value.replace(/^\s*(.*?)\s*$/, "$1");  // trim
  if (value==null || value=="")
  {
   value = "0"
   return true
  }
  if (!isValidChars(value, "0123456789"))
  {
   alert(alerttxt)
   focus()
   return false
  }
 }
 return true;
}

function validate_number(field, alerttxt)
{
 with (document.getElementById(field))
 {
  value = value.replace(/^\s*(.*?)\s*$/, "$1");  // trim
  if (value==null || value=="")
  {
   value = "0"
   return true
  }
  if (!isValidChars(value, "0123456789,"))
  {
   alert(alerttxt)
   focus()
   return false
  }
 }
 return true
}

function validate_phone(field, alerttxt)
{
 with (document.getElementById(field))
 {
  value = value.replace(/^\s*(.*?)\s*$/, "$1");  // trim
  if (value==null || value=="")
   return true
  if (!isValidChars(value, "0123456789"))
  {
   alert(alerttxt)
   focus()
   return false
  }
 }
 return true;
}

function validate_email(field, alerttxt)
{
 with (document.getElementById(field))
 {
  value = value.replace(/^\s*(.*?)\s*$/, "$1");  // trim
  if (value==null || value=="")
   return true
  if (!isValidChars(value.toLowerCase(), "._@0123456789abcdefghijklmnopqrstuvwxyz"))
  {
   alert(alerttxt)
   focus()
   return false
  }

  var apos   = value.indexOf("@");
  var dotpos = value.lastIndexOf(".");
  if (apos < 1 || dotpos - apos < 2)
  {
   alert(alerttxt);
   focus()
   return false;
  }
 }
 return true;
}

function validate_password(field, alerttxt)
{
 var iAsc = 0, iNum = 0;
 with (document.getElementById(field))
 {
   value = value.replace(/^\s*(.*?)\s*$/, "$1");  // trim
   for (i = 0; i < value.length; i++)
   {
     if ((value.charAt(i) >= "A" && value.charAt(i) <= "Z") || (value.charAt(i) >= "a" && value.charAt(i) <= "z"))
       iAsc++;
     if (value.charAt(i) >= "0" && value.charAt(i) <= "9")
       iNum++;
   }
   if (value.length < 8 || iAsc == 0 || iNum == 0)
   {
     alert(alerttxt)
     focus()
     return false
   }
 }
 return true
}

function validate_time(field, alerttxt)
{
 var re = /^(0[0-9]|1[0-9]|2[0-3])\:([0-5][0-9])/;

 with (document.getElementById(field))
 {
  value = value.replace(/^\s*(.*?)\s*$/, "$1");  // trim
  value = value.replace(/\./, ":");
  value = value.replace(/\,/, ":");
  if (value==null || value=="")
  {
   alert(alerttxt + '(1)');
   focus()
   return true;
  }
  if (!isValidChars(value, "0123456789:"))
  {
   alert(alerttxt + '(2)');
   focus()
   return false;
  }
  if (!re.test(value) == true)
  {
   alert(alerttxt + '(3)');
   focus()
   return false;
  }
 }
 return true;
}

function days_in_month(iMon, iYear)
{
 if (iMon < 1 || iYear < 1)
  return 0;
 if (iMon == 2)
  return (((iYear % 4 == 0) && ((!(iYear % 100 == 0)) || (iYear % 400 == 0))) ? 29 : 28);
 if (iMon == 4 || iMon == 6 || iMon == 9 || iMon == 11)
  return 30;
 return 31;
}

function validate_date(field, alerttxt, minDate, maxDate)
{
 var re = /^(3[01]|0[1-9]|[12]\d)\-(0[1-9]|1[012])\-\d{4}/;

 with (document.getElementById(field))
 {
  value = value.replace(/^\s*(.*?)\s*$/, "$1");  // trim
  value = value.replace(/\./g, "-");
  value = value.replace(/\//g, "-");
  if (value==null || value=="")
  {
   alert(alerttxt);
   return false;
  }
  if (value.length == 6 && isValidChars(value, "0123456789"))
  {
   value = value.substr(0,2) + "-" + value.substr(2,2) + "-20" + value.substr(4,2);
  }
  if (value.length == 8 && isValidChars(value, "0123456789"))
  {
   value = value.substr(0,2) + "-" + value.substr(2,2) + "-" + value.substr(4,4);
  }
  if (!re.test(value) == true)
  {
   alert(alerttxt);
   focus()
   return false;
  }
  if (Number(value.substr(0,2)) > days_in_month(Number(value.substr(3,2)), Number(value.substr(6,4))))
  {
   alert(alerttxt);
   focus()
   return false;
  }
  var curDate = new Date(Number(value.substr(6,4)), Number(value.substr(3,2))-1,Number(value.substr(0,2)));
  minDate.setHours(0);
  minDate.setMinutes(0);
  minDate.setSeconds(0);
  minDate.setMilliseconds(0);
  maxDate.setHours(23);
  maxDate.setMinutes(59);
  maxDate.setSeconds(59);
  maxDate.setMilliseconds(999);
  if (curDate < minDate || curDate > maxDate)
  {
   alert(alerttxt);
   focus()
   return false;
  }
 }
 return true;
}
function adjust_date(field)
{
 with (field)
 {
  value = value.replace(/^\s*(.*?)\s*$/, "$1");  // trim
  value = value.replace(/\./g, "-");
  value = value.replace(/\//g, "-");
  if (value.length == 6 && isValidChars(value, "0123456789"))
   value = value.substr(0,2) + "-" + value.substr(2,2) + "-20" + value.substr(4,2);
  if (value.length == 8 && isValidChars(value, "0123456789"))
   value = value.substr(0,2) + "-" + value.substr(2,2) + "-" + value.substr(4,4);
 }
}
function adjust_time(field)
{
 with (field)
 {
  value = value.replace(/^\s*(.*?)\s*$/, "$1");  // trim
  value = value.replace(/\./, ":");
  value = value.replace(/\,/, ":");
  if (value.length == 1 && isValidChars(value, "0123456789"))
   value = "0" + value + ":00";
  if (value.length == 2 && isValidChars(value, "0123456789"))
   value = value + ":00";
  if (value.length == 3 && isValidChars(value, "0123456789"))
   value = "0" + value.substr(0,1) + ":" + value.substr(1,2);
  if (value.length == 4 && isValidChars(value, "0123456789"))
   value = value.substr(0,2) + ":" + value.substr(2,2);
 }
}

function addbookmark(url)
{
  if (window.sidebar)
  {
    window.sidebar.addPanel("Doms Customer Web Service Log", url,"");
  }
  else
    if (document.all)
    {
      window.external.AddFavorite(url, "Doms Customer Web Service Log");
    }
  return true;
}

