//********************************************************************//
//*** Created by: ATI-SG (08/31/2000) ***//.
//*** 1. isBlank: Check if string is blank.
//*** 2. isDate: Check if string is formated date or not.
//*** 3. isInt: Check if string is number or not.
//*** 4. isEmail: Check if string a formated e-mail address or not.
//*** 5. isLength: Check if length string is less than or equal certain number of character.
//*** 6. confirmDelete: Check if user really want to delete a certain record.
//********************************************************************//
//**************************** CONSTANTS ***********************
var c_Null = " can not be null!"
var c_Delete = "Do you really want to delete this record?"
var c_InvalidEmail = "Invalid email, please try again!"
//**************************************************************
// Name: isBlank.
// Input: p_Str.
// Output: True/False.
// Usage: Use when you want to specify a string is blank string or not.
//**************************************************************
function isBlank(p_Str)
{
  var v_Len;
  if (p_Str == null)
    v_Len = 0;
  else
    v_Len = p_Str.length;
  if(!v_Len)
    return true;
  for (i=0; i<v_Len; i++)
  {
    if(p_Str.charAt(i)!= " ")
      return false;
  }
  return true;
}
//**************************************************************
// Name: isEmail.
// Input: p_Str.
// Output: True/False.
// Usage: Use when you want to specify a string is email address or not.
//**************************************************************
function isEmail(p_Str)
{
  var v_Len;
  if (p_Str == null)
    v_Len = 0;
  else
    v_Len = p_Str.length;
  //Check if blank
  if(!v_Len)
    return false;
  //Check if email
  if (p_Str.indexOf(' ') >= 0)
       return false;
  if (p_Str.indexOf('@') == -1)
    return false;
  //if it is email
  return true;
}

//**************************************************************
// Name: isDayOMOY.
// Input: vDay,vMonth,vYear.
// Output: True/False.
// Usage: Use to specify valid day, month, year.
//**************************************************************

function isDayOMOY(vDay,vMonth,vYear)
{
  if(parseInt(vYear) < 1900)
    return false;
  if ((vDay<1)||(vMonth<1)||(vMonth>12)||(vYear<0))
    return false;
  if ((vMonth==1)||(vMonth==3)||(vMonth==5)||(vMonth==7)||(vMonth==8)||(vMonth==10)||(vMonth==12))
    if (vDay>31)
      return false;
  if ((vMonth==4)||(vMonth==6)||(vMonth==9)||(vMonth==11))
    if (vDay>30)
      return false;
  if (vMonth==2)
    if (vYear%4==0)
      return (vDay<=29);
    else
      return (vDay<=28);
  return true;
}

//**************************************************************
// Name: isDate.
// Input: str,mode.
//   + mode=1: date formated dd/mm/yyyy or dd/mm/yy.
//   + mode=2: date formated mm/dd/yyyy or mm/dd/yy.
// Output: True/False.
// Usage: Use to specify a valid date.
//**************************************************************

function isDate(str,mode)
{
  var vlen, i,vType, aDate;
  vType="/";
  aDate = str.split(vType);
  var alen ;
  alen= aDate.length;
  if (alen!=3)
    return false;
  if ((aDate[0].length!=1) && (aDate[0].length!=2))
    return false;
  if ((aDate[1].length!=1) && (aDate[1].length!=2))
    return false;
  if ((aDate[2].length!=2) && (aDate[2].length!=4))
    return false;
  for(i=0; i<alen; i++){
    if(isNaN(aDate[i]))
      return false;
  }
  if(mode==1)
    return(isDayOMOY(aDate[0],aDate[1],aDate[2]));
  else
    return(isDayOMOY(aDate[1],aDate[0],aDate[2]));
  return true;
}
//***************************************************************
//function check year must more than 1900						*	
//input value type date"mm/dd/yyyy"								*
//return value = "yyyy"											*
//if yyyy < 1900 then return false								*
//***************************************************************
function checkyear(vld){
	var str = vld
	var str1 = "/"
	var s = str.lastIndexOf(str1)
		aa =str.substring(s+1,str.length)
		if(aa < 1900)
		{
		return false;
		}else
		return true;
}	

//**************************************************************
// Name: DelOnClick.
// Input: N/A.
// Output: True/False.
// Usage: Use when you want to delete a certain record.
//**************************************************************

function delOnClick() 
{
  var choose;
  choose = confirm("Do you really want to delete this record?");
  if (!choose)
  {
    return false;
  }
  return true;
}

//**************************************************************
// Name: IsInt.
// Input: num - num is a number or not.
// Output: True/False.
// Usage: Use when you want to specify an input whether a number or not.
//**************************************************************

function isInt(num) 
{
  var tempNum = new String(num);
  tempNum = allTrim(tempNum);
  var numLen = tempNum.length;
  if (numLen == 0) 
  {
    return true;
  }
  else 
  {
    var i = 0;
    for(i =0; i < numLen; i++)
    {
      if ((tempNum.substr(i,1) < "0")||(tempNum.substr(i,1) > "9"))
      {
        return false;
      }
    }
    return true;
  }
}

//**************************************************************
// Name: isLength.
// Input: str, length - is max length.
// Output: True/False.
// Usage: Use when you want to specify string length less than or equal length.
//**************************************************************

function isLength(str, l)
{
  if(str.length > l)
  {
    return false;
  }
  return true;
}

//**************************************************************
// Name: lTrim.
// Input: str.
// Output: String str without space in left hand.
// Usage: Use when you want to delete all space in left hand of string.
//**************************************************************

function lTrim(str)
{
  var strg,vlen;
  strg=str;
  vlen=strg.length;
  while((vlen>0)&&(strg.charAt(0)==" "))
  { 
    strg=strg.substr(1);
    vlen=strg.length;
  }
  return(strg);
}

//**************************************************************
// Name: rTrim.
// Input: str.
// Output: String str without space in right hand.
// Usage: Use when you want to delete all space in right hand of string.
//**************************************************************

function rTrim(str)
{
  var strg,vlen;
  strg=str;
  vlen=strg.length;
  while((vlen>0)&&(strg.charAt(vlen-1)==" "))
  { 
    strg=strg.substr(0,vlen-1);
    vlen=strg.length;
  }
  return(strg);
}

//**************************************************************
// Name: allTrim.
// Input: str.
// Output: String str without space in left & right hand.
// Usage: Use when you want to delete all space in left & right hand of string.
//**************************************************************

function allTrim(str)
{
  var strg;
  strg=lTrim(str);
  strg=rTrim(strg);
  return(strg);
}
//**************************************************************
function confirmDelete()
{
  var ok = window.confirm(c_Delete);
  if(ok)
  {
    return true;
  }
  else
  {
    return false;
  }
}
//**************************************************************
//function line scroll
function scrollit_r2l(seed){ 	
	var msg="American Technologis-inc very happy service customer!";
	var out =" ";	
	 if (seed <=100 && seed > 0) {
                      for (c=0 ; c < seed ; c++) out+=" ";
                      out+=msg;
	    seed--;
	    var cmd="scrollit_r2l(" + seed + ")";
                      window.status=out;
	    timerTwo=window.setTimeout(cmd,100);
                  } else 
	      if (seed <= 0) { 
	         if (-seed < msg.length) {
	           out+=msg.substring(-seed,msg.length);
	           seed--;
	           var cmd="scrollit_r2l(" + seed + ")";
	           window.status=out;
	           timerTwo=window.setTimeout(cmd,100);
	        }
	        else { 
	           window.status=" ";
    	            timerTwo=window.setTimeout("scrollit_r2l(100)",75)

	       }
	     }
}

//end function line scroll

//
//Check valid image file
function CheckImage(strPath)
{
  //Check image file path
  //Path to image file have to include "\" character after that is image filename
  //Find position of "\"
  intLast = strPath.lastIndexOf(String.fromCharCode(92));

  //intLast have to less than v_file1.length-4
  if (intLast >= strPath.length-5)
    return false

  chrPoint = strPath.charCodeAt(strPath.length-4)
  
  // chrPoint : must be dot character "."
  if ( chrPoint != 46)
    return false

  //get file extention
  ext   = strPath.substr(strPath.length-3);
  
  //Check image file extention: must be "gif" or "jpg" or "jpe"
  if ((ext.toUpperCase()!="GIF") && (ext.toUpperCase()!="JPG") && (ext.toUpperCase()!="jPE"))
    return false
    
  return true
}
