String.prototype.trim= function()
{
return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.isInt= function()
{
if(!this) return false;
var strP=/^\d+(\.\d+)?$/;
if(!strP.test(this)) return false;
try{
if(parseInt(this)!=this) return false;
}
catch(ex)
{
return false;
}
return true;
}
function ExpandOrShrink(blockID, evt){
var block;
var event, image;
event = evt ? evt : (window.event ? window.event : null);
image = event.srcElement ? event.srcElement : event.target;
block = document.getElementById(blockID);
if (block.style.display == "none")
{
block.style.display = "";
image.src = "../../images/arrow-up.gif";
}
else
{
block.style.display = "none";
image.src = "../../images/arrow-down.gif";
}
}
//key down function
function is_number(){
var va=event.keyCode;
//a = window.frm.interest_rate.value
if(!((va > 47 && va <58) || (va > 95 && va < 106) || (va == 190) || (va == 110) || (va ==8) || (va == 46) || (va == 13) || (va == 9))){
event.returnValue=0
return false;
}
}
function is_int(){
var va=event.keyCode;
//a = window.frm.interest_rate.value
//event.srcElement.style.textAlign='right'
if(!((va > 47 && va <58) || (va > 95 && va < 106) || (va == 110) || (va ==8) || (va == 46) || (va == 13) ||(va == 9))){
event.returnValue=0
return false;
}
}
function isInteger(s)
{
var patrn=/^[0-9]{1,6}$/;
if (!patrn.exec(s)) return false
return true
}
function isFloat(s)
{
if(isNaN(s)){
//alert('not a number');
return false;
}else{
//alert('is a number');
var patrn=/^([0-9]{1,6})((\.{1}[0-9]{1,4}){0,1})$/;
if (!patrn.exec(s)) return false
return true
}
}
//yyyy-mm-dd
function isDate(str){
var pattern = /^((\d{4})|(\d{2}))-(\d{1,2})-(\d{1,2})$/g;
if(!pattern.test(str))
return false;
var arrDate = str.split("-");
if(parseInt(arrDate[0],10) < 100)
arrDate[0] = 2000 + parseInt(arrDate[0],10) + "";
var date = new Date(arrDate[0],(parseInt(arrDate[1],10) -1)+"",arrDate[2]);
if(date.getYear() == arrDate[0]
&& date.getMonth() == (parseInt(arrDate[1],10) -1)+""
&& date.getDate() == arrDate[2])
return true;
else
return false;
}
function isURL (url)
{
var pattern = /^(http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\?+!]*([^<>\"\"])*)|([A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\?+!]*([^<>\"\"])*)$/;
return pattern.exec(url.toLowerCase());
}
function isRegisterUserName(s)
{
var patrn=/^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){4,14}$/;
if (!patrn.exec(s)) return false
return true
}
function isTrueName(s)
{
var patrn=/^[a-zA-Z]{1,30}$/;
if (!patrn.exec(s)) return false
return true
}
function isPasswd(s)
{
var patrn=/^(\w){1,20}$/;
if (!patrn.exec(s)) return false
return true
}
function isTel(s)
{
//var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?(\d){1,12})+$/;
var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;
if (!patrn.exec(s)) return false
return true
}
function isMobil(s)
{
var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;
if (!patrn.exec(s)) return false
return true
}
function isEmail(strEmail) {
var myReg = /^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
if(myReg.test(strEmail)) return true;
return false;
}
function isPostalCode(s)
{
//var patrn=/^[a-zA-Z0-9]{3,12}$/;
var patrn=/^[a-zA-Z0-9]{3,12}$/;
if (!patrn.exec(s)) return false
return true
}
function isSearch(s)
{
var patrn=/^[^`~!@#$%^&*()+=|\\\][\]\{\}:;'\,.<>/?]{1}[^`~!@$%^&()+=|\\\][\]\{\}:;'\,.<>?]{0,19}$/;
if (!patrn.exec(s)) return false
return true
}
function isIP(s) //by zergling
{
var patrn=/^[0-9.]{1,20}$/;
if (!patrn.exec(s)) return false
return true
}
function DatetimeParser(datetimeStr, format)
{
var year, month, day, hour, minute;
var date = NaN;
try
{
switch (format)
{
case "yyyy-MM-dd hh:mm":
var arr = datetimeStr.split(" ")
var ymd = arr[0].split("-");
var hm = arr[1].split(":");
year = ymd[0];
month = ymd[1];
day = ymd[2];
hour = hm[0];
minute = hm[1];
date = new Date(year, month - 1, day, hour, minute, 0);
break;
default:
break;
}
} catch (e)
{
return NaN;
}
return date;
}
String.prototype.Trim = function()
{
return this.replace(/(^\s*)|(\s*$)/g,"");
}
function CheckDateTime(dateControlName)
{
var strDTCheck = eval(dateControlName).value.Trim() ;
var strDateString = eval(dateControlName).value.Trim();
var strDate;
var strTime;
var strSp = 0;
if (strDateString.length == 0)
{ return true; }
for (var i=0;i<strDateString.length;i++)
{
if (strDateString.substr(i,1) == " ")
{
strSp=i;
break;
}
}
if (strSp == 0)
{
if(strDTCheck.length <= 10 )
{
strDate = strDTCheck ;
return CheckDate(strDate) ;
}
return false;
}
strDate = strDateString.substr(0,strSp);
strTime = strDateString.substr(strSp+1,strDateString.length-strSp+1);
var separator = ':';
var arrayOfTimes = strTime.split(separator);
if(arrayOfTimes.length == 2 )
{
strTime = strTime +":00";
}
if (CheckDate(strDate) == true)
{
if (isTime(strTime) == true)
{ return true;}
else
{ return false;}
}
else
{
return false;
}
}
function isTime(str)
{
var a = str.match(/^(\d{1,2})(:)?(\d{1,2})\2(\d{1,2})$/);
if (a == null) {alert('Time format error.'); return false;}
if (a[1]>24 || a[3]>60 || a[4]>60)
{
alert("Time format error.");
return false
}
return true;
}
function CheckDate(SparaDate)
{
if (CheckyyyyMMdd(SparaDate) == true)
{ return true; }
var strYMDSP = 0;
var strYMD;
if (!(SparaDate.substr(4,1)=="-"))
{
return false;
}
var strYear = SparaDate.substr(0,4);
SparaDate = SparaDate.substr(5,SparaDate.length-5);
for (i=0;i<SparaDate.length;i++)
{
if (SparaDate.substr(i,1)=="-")
{
strYMDSP = i;
break;
}
}
if (strYMDSP<1)
{
return false;
}
var strMonth = SparaDate.substr(0,strYMDSP);
var strDay= SparaDate.substr(strYMDSP+1,SparaDate.length-strYMDSP+1);
if (strMonth.length == 1)
{ strMonth = "0"+strMonth; }
if (strDay.length == 1)
{ strDay = "0"+strDay; }
if (CheckyyyyMMdd(strYear+strMonth+strDay) == true)
{ return true; }
else
{ return false; }
} // end function CheckDate
function CheckyyyyMMdd(dayString)
{
var digit = "0123456789";
datelist = new Array(31,29,31,30,31,30,31,31,30,31,30,31);
if (dayString.length !=8) return(false);
for(i=0;i<8;i++)
{
if(digit.indexOf(dayString.charAt(i),0)==-1) return(false);
}
year = dayString.substr(0,4);
month = dayString.substr(4,2);
date = dayString.substr(6,2);
if (year>2200||year<1900||month>12||month<1||date>31||date<1) return(false);
if(date>datelist[month-1]) return(false);
yyyy = eval(year);
if ( month == "02" )
{
if ( (yyyy % 400) == 0 )
{
if ( date>29 ) return(false);
}
else if ( (yyyy % 4) == 0 && (yyyy % 100) != 0 )
{
if ( date>29 ) return(false);
}
else
{
if ( date>28 ) return(false);
}
}
return(true);
} // end function CheckyyyyMMdd
//parseDate
function GetDateObj(datestr)
{
//alert(datestr);
var strDTCheck = datestr ;
var strDateString = datestr;
var strDate;
var strTime;
var strSp = 0;
for (var i=0;i<strDateString.length;i++)
{
if (strDateString.substr(i,1) == " ")
{
strSp=i;
break;
}
}
//only date
if (strSp == 0)
{
if(strDTCheck.length <= 10 )
{
strDate = strDTCheck ;
}
strTime="0:0:0";
}
else
{
strDate = strDateString.substr(0,strSp);
strTime = strDateString.substr(strSp+1,strDateString.length-strSp+1);
}
var separator = ':';
var arrayOfTimes = strTime.split(separator); // HH:mm:ss
if(arrayOfTimes.length == 2 )
{
strTime = strTime +":00";
}
var arrayOfDate = strDate.split('-');
arrayOfTimes = strTime.split(':');
//alert(strDate);
//alert(strTime);
var newDateObj = new Date(parseInt(arrayOfDate[0],10),(parseInt(arrayOfDate[1],10)-1),parseInt(arrayOfDate[2],10), parseInt(arrayOfTimes[0],10),parseInt(arrayOfTimes[1],10),parseInt(arrayOfTimes[2],10) );
return newDateObj;
}
function hasSpecSymbol(str){
var i = 0;
var ch = '';
for (i = 0; i < str.length; i++) {
ch = str.charAt(i);
if ((ch == "`" )|| (ch == "~" )||(ch == "!" )||(ch == "@" )||
(ch == "#" )||(ch == "%" )||(ch == "^" )||(ch == "&" )||
(ch == "*" )||(ch == "(" )||(ch == ")" )||(ch == "+" )||
(ch == "=" )||(ch == "|" )||(ch == "{" )||(ch == "}" )||
(ch == "[" )||(ch == "]" )||(ch == ":" )||(ch == ";" )||
(ch == "<" )||(ch == ">" )||
(ch == "," )||(ch == "." )||(ch == "?" )) {
return false;
}
}
return true;
}
//is english letter
function ifLetter(str ){
for ( var i = 0 ; i < str.length; i ++ ){
if ( parseInt(str.charCodeAt(i)) < 27 || parseInt(str.charCodeAt(i)) > 128 )
return false;
}
return true;
}