
// OPCJisDecimal(Pstr, Pp, Ps)
//   Parament
//     - Pstr    : 數值字串
//     - Pstr    : 整數位數
//     - Pstr    : 小數位數
//   Return
//     - '0' / 符合數值格式
//     - '1' / 數值字串為空字串
//     - '2' / 數值字串含有非數字
//     - '3' / 數值字串不得包含正負號
//     - '4' / 數值字串沒有小數位數
//     - '5' / 數值字串有小數點但沒有指定小數位數
//     - '6' / 數值字串的小數點在很奇怪的位置
//
function OPCJisDecimal(Pstr, Pp, Ps) {
  var num, dot, pp, ss;
  pp = arguments.length > 1 ? Pp : null;
  ss = arguments.length > 2 ? Ps : null;
  if (!Pstr) {
    return '1';
  }
  if (!isNaN(Pstr)) {
    if (Pstr.indexOf('+') > -1 || Pstr.indexOf('-') > -1) return '3';
    num = Pstr.indexOf('.') > -1 ? parseFloat(Pstr):parseInt(Pstr);
    num = num.toString();
    dot = num.indexOf('.');
    if (pp != null && dot > pp) return '4';
      if (dot != -1 && ss != null) {
        if (ss == 0) return '5';
        else if (dot < num.length - ss - 1) return '6';
      }
    return '0';
  }
  else {
    return '2';
  }
}


// OPCJisDate(data1,Fmt)
//   Parament
//     - data1   : 日期字串
//     - Fmt     : 日期格式
//   Return
//     - '0' / 符合日期格式
//     - '1' / 不符合日期格式
//     - '2' / 日期格式錯誤(有效日為01-31)
//     - '3' / 日期格式錯誤(有效日為01-30)
//     - '4' / 日期格式錯誤(有效日為01-29)
//     - '5' / 日期格式錯誤(有效日為01-28)
//     - '6' / 日期格式錯誤(有效月份為01-12)
//
function OPCJisDate(data1,Fmt) {
	var YY="";
	var MM="";
	var DD="";
  var DDyn="N";
	isok=1;

  if (data1.length != Fmt.length) return '1';

	for (var i=0;i < data1.length;i++){
		var ch=data1.charAt(i);
		var ch1=Fmt.charAt(i);
		if ((ch1 == "Y") || (ch1 == "M") || (ch1 == "D"))
			if ((ch != "0") && (ch != "1") && (ch != "2") && (ch != "3") && (ch != "4") && (ch != "5") && (ch != "6") && (ch != "7") && (ch != "8") && (ch != "9")) {
				isok=0;
				break;
			}
			else{
		    if (ch1=="Y")
			    YY=YY+ch;
				if (ch1=="M")
			    MM=MM+ch;
				if (ch1=="D") {
			    DD=DD+ch;
          DDyn="Y";
        }
			}
		else
		  if (ch != ch1){
	  	  isok=0;
		  	break;
  		}
	}

// *** 1999/10/06 Ryan : 以這個Project來講, 假設使用的是民國年 ***
  YY = parseInt(YY) + 1911;
// *** ======================================================= ***

	if (isok == 1)
		if ((MM > 0) && (MM < 13)) {
      if (DDyn=="Y") {
  			if ((MM == "01") || (MM == "03") || (MM == "05") ||(MM == "07")||(MM == "08")||(MM == "10")||(MM == "12"))
  				if ((DD < 32) && (DD > 0))
    				return '0';
  	  		else{
  		  		return '2';
  			  }
  			else 
  				if (MM != "02") 
  					if ((DD < 31) && (DD > 0))
  						return '0';
  					else{
  						return '3';
  					}
  				else 
  					if ((!(YY % 4) && (YY % 100)) || !(YY % 400))	
  						if ((DD < 30) && (DD > 0))
  							return '0';
  						else{
  							return '4';
  						}
  					else
  						if ((DD < 29) && (DD > 0))
  							return '0';
  						else{
  							return '5';
  						}
      } else return '0';
    }
		else {
			return '6';
		}
	else
		return '1';
}


/*
   Trims tailing spaces of a string.
   Input : The string will be trimmed.
   Return: The result string.
*/
function OPCJrTrim(str)
{
    var i;

    for (i = str.length - 1; i >= 0; i-- )
    {
        if (str.charAt(i) != ' ')
        {
            break;
        }
    }
    return str.substring(0, i+1);
}


/*
   Trims leading spaces of a string.
   Input : The string will be trimmed.
   Return: The result string.
*/
function OPCJlTrim(str)
{
    var i,len;

    len = str.length;
    for (i = 0; i < len; i++ )
    {
        if (str.charAt(i) != ' ')
        {
            break;
        }
    }
    return str.substring(i, len);
}


// OPCJchkEmail(str)
//   Parament
//     - str   : e-mail字串
//   Return
//     - '0' / 正確的e-mail格式
//     - '1' / e-mail字串為空字串
//     - '2' / e-mail字串沒有'@'字元
//
function OPCJchkEmail(str)
{
    var len, cnt, ch;

    if (!str) return '1';

    if (str.indexOf('@')<0) return '2';

    return '0';
}


// OPCJgetProdByClas(Pid, Pname)
//   Parament
//     - Pid     : 產品代號欄位字串
//     - Pname   : 產品名稱欄位字串
//   Return
//     none
//
function OPCJgetProdByClas(Pid, Pname) {
  window.open('sec002q1.asp?Iprdid=' + Pid + '&Iprdname=' + Pname,'QueryWin','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=no,copyhistory=yes,width=300,height=270');
}

// OPCJgetProdBySpec(Pid, Pname)
//   Parament
//     - Pid     : 產品代號欄位字串
//     - Pname   : 產品名稱欄位字串
//   Return
//     none
//
function OPCJgetProdBySpec(Pid, Pname) {
}

// OPCJgetSpec(Pitem)
//   Parament
//     - Pitem   : 產品代號欄位字串
//   Return
//     none
//
function OPCJgetSpec(Pitem) {
}
