﻿var keyStr___0000 = "ABCDEFGHIJKLMNOP" +
                "QRSTUVWXYZabcdef" +
                "ghijklmnopqrstuv" +
                "wxyz0123456789+/" +
                "=";
//----------------------------------------------------------------------------------//
//Function: Trim(strVal)
//By: Hellin
//----------------------------------------------------------------------------------//
function stringTrim(strVal)
{
    var strTmp = strVal +"";
    if (strTmp.length == 0)
        return strTmp ;
    else
    	return strTmp.replace(/(^\s*)|(\s*$)/g, "");
}
//----------------------------------------------------------------------------------//
//Function: validate_email (inputstr)
//By: Hellin
//----------------------------------------------------------------------------------//
function validate_email (inputstr) {
	var pattern =/^[a-zA-Z0-9_\-.]+@([a-zA-Z0-9\-]+\.)+[a-zA-Z]{2,3}$/;
	if (inputstr.search(pattern) > -1) {
		return true;
	} else {
		return false;
	}
}
//----------------------------------------------------------------------------------//
//Function: encodeHTMLString(strVal)
//By: Hellin
//----------------------------------------------------------------------------------//
function encodeHTMLString(strVal)
{
    var reVal = /&/g;
    var strTmp = strVal.replace (reVal, "&amp;");
	reVal = /</g;
    strTmp = strVal.replace (reVal, "&lt;");
    reVal = />/g;
    strTmp = strTmp.replace (reVal, "&gt;");
    reVal = /"/g;
    strTmp = strTmp.replace (reVal, "&quot;");
    return (strTmp);
}
function encodeStringHTML(strVal)
{
    var reVal =/&amp;/g;
    var strTmp = strVal.replace (reVal, "&");
	reVal = /&lt;/g;
    strTmp = strVal.replace (reVal, "<");
    reVal = /&gt;/g;
    strTmp = strTmp.replace (reVal, ">");
    reVal = /&quot;/g;
    strTmp = strTmp.replace (reVal, "\"");
    return (strTmp);
}
//----------------------------------------------------------------------------------//
//Function: encodeURLString(strVal)
//By: Hellin
//----------------------------------------------------------------------------------//
function encodeURLString(strVal)
{
    var reVal = /%/g;
    var strTmp = strVal.replace (reVal, "%25");
    reVal = /&/g;
    strTmp = strTmp.replace (reVal, "%26");
    reVal = /#/g;
    strTmp = strTmp.replace (reVal, "%23");
    reVal = /\+/g;
    strTmp = strTmp.replace (reVal, "%2b");
    return (strTmp);
}
//----------------------------------------------------------------------------------//
//Function: isNumber (strVal)
//By: Hellin
//----------------------------------------------------------------------------------//
function isNumber (strVal)
{
    if (strVal==null || strVal==undefined || strVal.length == "")
        return false ;
    var reVal = /^[\-\+]?([0-9]\d*|0|[1-9]\d{0,2}(,\d{3})*)(\.\d+)?$/;
    if (reVal.test (strVal)) {
        var gar = strVal + '.';
        var tmp = gar.split ('.');
        if (tmp[0].length > 15)
            return false;
        else
            return true;
    }
    return false;
}
//----------------------------------------------------------------------------------//
//Function: isInteger (strVal)
//By: Hellin
//----------------------------------------------------------------------------------//
function isInteger (strVal)
{
    if (strVal==null||strVal==undefined||strVal.length == "")
        return false;
    reVal = /^[\-\+]?([1-9]\d*|0|[1-9]\d{0,2}(,\d{3})*)$/;
    return (reVal.test (strVal));
}

//----------------------------------------------------------------------------------//
//Function: isTime (strTime)
//By: Hellin
//----------------------------------------------------------------------------------//
function isTime (strTime)
{
    if (strTime==null ||strTime ==undefined || strTime.length == 0)
        return false;
    var reVal = /^(([0-9]|[01][0-9]|2[0-3])(:([0-9]|[0-5][0-9])){0,2}|(0?[0-9]|1[0-1])(:([0-9]|[0-5][0-9])){0,2}\s?[aApP][mM])?$/;
    return (reVal.test (strTime));
}
//----------------------------------------------------------------------------------//
//Function: isDate (strDate)
//By: Hellin
//----------------------------------------------------------------------------------//
function isDate (strDate)
{
    var nStart;
    var nEnd;
    var nYear;
    var nMonth;
    var nDay;
    var nFact;
    var arrDay = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
    if (strDate==null||strDate==undefined|| strDate.length == 0)
        return (false);
    reVal = /^([1-2]\d{3})[\/|\-](0?[1-9]|10|11|12)[\/|\-]([1-2]?[0-9]|0[1-9]|30|31)$/;
    if (!reVal.test (strDate))
        return (false);
    nStart = strDate.indexOf ("/", 0);
    nEnd = strDate.indexOf ("/", nStart + 1);
    nYear = eval (strDate.substring (0, nStart));
    nMonth = eval (strDate.substring (nStart + 1, nEnd));
    nDay = eval (strDate.substring (nEnd + 1, strDate.length));
    nFact = arrDay[nMonth - 1];
    if (nMonth == 2)
    {
        if ((nYear % 4 == 0 && nYear %100 != 0) || (nYear % 400 == 0))
            nFact ++;
    };
    if (nDay > nFact)
        return false;
    return true;
}
//----------------------------------------------------------------------------------//
//Function: isIPAddress (strVal)
//By: Hellin
//----------------------------------------------------------------------------------//
function isIPAddress (strVal)
{
    if (strVal==null|| strVal==undefined || strVal.length == 0)
        return false;
    var reVal = /^(\d{1}|\d{2}|[0-1]\d{2}|2[0-4]\d|25[0-5])\.(\d{1}|\d{2}|[0-1]\d{2}|2[0-4]\d|25[0-5])\.(\d{1}|\d{2}|[0-1]\d{2}|2[0-4]\d|25[0-5])\.(\d{1}|\d{2}|[0-1]\d{2}|2[0-4]\d|25[0-5])$/;
    return (reVal.test (strVal));
}
//----------------------------------------------------------------------------------//
//Function: IsDigit(ch) and so on
//By: SCY
//----------------------------------------------------------------------------------//
function IsDigit(ch)
{
    var digits;
    digits = "0123456789";
    return (digits.indexOf(ch.toLowerCase()) != -1);
}
function IsLower(ch)
{
    var lowers;
    lowers = "abcdefghijklmnopqrstuvwxyz";
    return (lowers.indexOf(ch) != -1);
}
function IsUpper(ch)
{
    var uppers;
    uppers = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    return (uppers.indexOf(ch) != -1);
}
function IsLetter(ch)
{
    return (IsUpper(ch) || IsLower(ch));
}
//----------------------------------------------------------------------------------//
//Function: FilterString(str)
//change special letter to Entity code
//By: MMZ
//----------------------------------------------------------------------------------//
function FilterString(str)
{
  return encodeXmlString(str);
}

//----------------------------------------------------------------------------------//
//Function: encodeXmlString(str)
//encode common string to XML format string
//By: LDH 2005.06.02
//----------------------------------------------------------------------------------//
String.prototype.encodeXml=function()
{
 var str=this;
 str=str.replace(/\x26/g,"&amp;");
 str=str.replace(/\x3c/g,"&lt;");
 str=str.replace(/\x3e/g,"&gt;");
 str=str.replace(/\x22/g,"&quot;");
 str=str.replace(/\x27/g,"&apos;");
 return str;
}

function encodeXmlString(str)
{
  if (!str)
    return "";
      
  str=str.replace(/\x26/g,"&amp;");
  str=str.replace(/\x3c/g,"&lt;");
  str=str.replace(/\x3e/g,"&gt;");
  str=str.replace(/\x22/g,"&quot;");
  str=str.replace(/\x27/g,"&apos;");
  
  return str;
}

//var tt='<&"\\>';
//alert(tt);
//alert(encodeXmlString(tt));
//var tt="1234567";
//alert(tt);
//alert(encodeXmlString(tt));

function formatSearch(s)
{
  if(s.length==0)
    return s;
  var ns="";

  var i=0;
  for(; i<s.length; i++)  //trim left
  {
    var c = s.charAt(i);
    if(c != ',' && c!= "'")
    {
      ns = ns+c;
    }
  }
  return ns;
}

function trimLeft(s)
{
  if(!s)
    return "";
  if(s.length==0)
    return s;

  var i=0;
  for(; i<s.length; i++)  //trim left
  {
    var c=s.charAt(i);
    if(c!=' ')
      break;
  }
  if(i==s.length)
   return "";
  s=s.substring(i,s.length);
  return s;
}
function trimRight(s)
{
  if(!s)
    return "";
  if(s.length==0)
    return s;

  var i=s.length-1;
  for(; i>=0; i--)  //trim right
  {
    var c=s.charAt(i);
    if(c!=' ')
      break;
  }
  if(i==-1)
    return "";
  s=s.substring(0,i+1);
  return s
}
function trim(s)
{
  if(!s)
    return "";
  s=trimLeft(s);
  s=trimRight(s);
  return s;
}

String.prototype.trim=function()
{
    return stringTrim(this);
}

//----------------------------------------------------------------------------------//
//Function: isIdInteger (strVal)
//By: LDH
//----------------------------------------------------------------------------------//
function isIdInteger (strVal)
{
    if (strVal==null||strVal==undefined||strVal.length == "")
        return false;
    reVal = /^[0-9]*([1-9]\d*|0|[1-9]\d{0,2}(,\d{3})*)$/;
    return (reVal.test (strVal));
}

//-------------------------------------------------------------------------------//
// date: Date object ,format: String such as(yyyy-MM-dd HH:mm:ss)
//----------------------------------------------------------------------------//
  function formatDateTime(date,format)
  {
            var strDate=format;
            
            var day=date.getDate() ;
            var month=date.getMonth()+1;
            var year=date.getYear();
            var hour=date.getHours();
            var minute =date.getMinutes();
            var second =date.getSeconds();

            if(parseInt(month)<10)month="0"+month;
            if(parseInt(day)<10)day="0"+day;
            if(parseInt(hour)<10)hour="0"+hour;
            if(parseInt(minute)<10)minute="0"+minute;  
            if(parseInt(second)<10)second="0"+second; 
            
            strDate=strDate.replace("yyyy",year);
            strDate=strDate.replace("MM",month);
            strDate=strDate.replace("dd",day);
            strDate=strDate.replace("HH",hour);
            strDate=strDate.replace("mm",minute);
            strDate=strDate.replace("ss",second);
            
            return strDate;
            
  }