code: save file jUtil.js
function chkCharacter(obj,maxlimit,objMessage) {
var objMessage,field,num;
objMessage=document.getElementById(objMessage);
field=obj;
num=(maxlimit-field.value.length);
if(num<=0) {
num=0;
objMessage.style.color='red';
} else {
objMessage.style.color='green';
}
objMessage.innerHTML=num+" Character Remaining.";
if (field.value.length > maxlimit)
field.value = field.value.substring(0, maxlimit);
}
function isnotemail(email) {
var regEx = /^[\w\.\+-]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,6}$/;
if(!regEx.test(email))
{
return true;
}
return false;
}
////////////////////////////////////////////////////////////////////
var charSetName="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
function isName(myst) {
var i;
for (i = 0; i < myst.length; i++) {
var c = myst.charAt(i);
if (charSetName.indexOf(c) < 0) {
return false;
}
}
return true;
}
var charSetNameOther=" abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
function isNameOther(myst) {
var i;
for (i = 0; i < myst.length; i++) {
var c = myst.charAt(i);
if (charSetNameOther.indexOf(c) < 0) {
return false;
}
}
return true;
}
var numSet="1234567890";
function isNumber(myst) {
var i;
for (i = 0; i < myst.length; i++) {
var c = myst.charAt(i);
if (numSet.indexOf(c) < 0) {
return false;
}
}
return true;
}
var numSetDec="1234567890.";
function isNumberDec(myst) {
var i,noOfDec=0,decPos=0;
var splitArr;
for (i = 0; i < myst.length; i++) {
var c = myst.charAt(i);
if(c=='.') {
noOfDec++;
decPos=i;
}
if (numSetDec.indexOf(c) < 0) {
return false;
}
}
if(noOfDec>=1) {
splitArr=myst.split(".");
//alert("splitArr.length="+splitArr.length);
if(splitArr.length>2) {
//alert("Invalid Number");
return false;
} else {
var firstVal=splitArr[0];
var secondValue=splitArr[1];
//alert(secondValue.length);
if(secondValue.length==0 || secondValue.length>2) {
//alert("Invalid format");
return false ;
}
}
}
return true;
}
/////////////////get Date auto fill Date /////////////////////////////
/*function fillDate(curCtrl,nextCtrl) {
var dateVal,fullDate;
var toDay,dd,mm,yyyy;
var splitDate,searchSep;
dateVal=jQuery.trim($("#"+curCtrl).val());
toDay=new Date();
dd=toDay.getDate();
mm=toDay.getMonth()+1;
yyyy=toDay.getFullYear();
if(dateVal=="") {
fullDate=dd+"-"+mm+"-"+yyyy;
$("#"+curCtrl).val(fullDate);
} else {
searchSep=dateVal.indexOf("-");
if(searchSep==-1) {
if(parseInt(dateVal)>31) {
alert("Wrong date range");
return;
}
fullDate=dateVal+"-"+mm+"-"+yyyy;
} else {
splitDate=dateVal.split("-");
fullDate=splitDate[0];
if(splitDate[1]==undefined || splitDate[1]=="") {
fullDate=fullDate+"-"+mm;
} else {
fullDate=fullDate+"-"+splitDate[1];
}
if(splitDate[2]==undefined || splitDate[2]=="") {
fullDate=fullDate+"-"+yyyy;
} else {
fullDate=fullDate+"-"+splitDate[2];
}
}
$("#"+curCtrl).val(fullDate);
}
if(jQuery.trim(nextCtrl)!="") {
$("#"+nextCtrl).focus();
}
}*/
function fillDate(curCtrl,nextCtrl) {
var dateVal,fullDate;
var toDay,dd,mm,yyyy;
var splitDate,searchSep;
dateVal=jQuery.trim($("#"+curCtrl).val());
toDay=new Date();
dd=toDay.getDate();
mm=toDay.getMonth()+1;
yyyy=toDay.getFullYear();
var currentDate=dd+"-"+mm+"-"+yyyy;
if(dateVal=="") {
fullDate=dd+"-"+mm+"-"+yyyy;
$("#"+curCtrl).val(fullDate);
} else {
searchSep=dateVal.indexOf("-");
if(searchSep==-1) {
if(parseInt(dateVal)>31 || parseInt(dateVal)<1) {
//alert("Wrong date range.");
$("#"+curCtrl).val(currentDate);
return;
}
fullDate=dateVal+"-"+mm+"-"+yyyy;
} else {
splitDate=dateVal.split("-");
fullDate=splitDate[0];
//alert(fullDate);
if(splitDate[1]==undefined || splitDate[1]=="" || parseInt(splitDate[1])<1) {
fullDate=fullDate+"-"+mm;
} else {
fullDate=fullDate+"-"+splitDate[1];
}
if(splitDate[2]==undefined || splitDate[2]=="" || parseInt(splitDate[2])<1) {
fullDate=fullDate+"-"+yyyy;
} else {
var yRem=parseInt(splitDate[2]);
if(yRem>=1 && yRem<=25) {
splitDate[2]=parseInt(splitDate[2])+2000;
}
fullDate=fullDate+"-"+splitDate[2];
}
}
$("#"+curCtrl).val(fullDate);
if(!chkForLeap(fullDate)) {
$("#"+curCtrl).val(currentDate);
$("#"+curCtrl).focus();
}
}
if(jQuery.trim(nextCtrl)!="") {
$("#"+nextCtrl).focus();
}
}
function chkForLeap(dt) {
var ans=true;
var oldDt,dd,mm,yyyy,lp,lpFeb,i;
var monthArray=new Array(12);
for (i=0;i<12; i++) {
monthArray[i]=new Array(2);
}
monthArray[0][0]=1;
monthArray[0][1]=31;
monthArray[1][0]=2;
monthArray[1][1]=29;
monthArray[2][0]=3;
monthArray[2][1]=31;
monthArray[3][0]=4;
monthArray[3][1]=30;
monthArray[4][0]=5;
monthArray[4][1]=31;
monthArray[5][0]=6
monthArray[5][1]=30;
monthArray[6][0]=7;
monthArray[6][1]=31;
monthArray[7][0]=8;
monthArray[7][1]=31;
monthArray[8][0]=9;
monthArray[8][1]=30;
monthArray[9][0]=10;
monthArray[9][1]=31;
monthArray[10][0]=11;
monthArray[10][1]=30;
monthArray[11][0]=12;
monthArray[11][1]=31;
oldDt=dt;
spDate=oldDt.split("-");
dd=parseInt(spDate[0]);
mm=parseInt(spDate[1]);
yyyy=parseInt(spDate[2]);
var currentYear,toDay;
toDay=new Date();
currentYear=toDay.getFullYear();
var reg = /^\d{1,2}\-\d{1,2}\-\d{4}$/;
if(!oldDt.match(reg)) {
//alert("Invalid date format: ");
ans=false;
return ans;
}
if(mm>12 || mm<1) {
//alert("Invalid date format: ");
$("#"+curCtrl).val(currentDate);
ans=false;
return ans;
}
if(yyyy>currentYear || yyyy<(currentYear-25)){
//alert("Invalid year");
$("#"+curCtrl).val(currentDate);
ans=false;
return ans;
}
lp=yyyy%4;
lpFeb=lp==0?29:28;
monthArray[1][1]=lpFeb;
if(dd>monthArray[mm-1][1] || dd<1) {
//alert("Invalid day of date, you could not enter "+dd +" as it is greater than "+monthArray[mm-1][1]);
$("#"+curCtrl).val(currentDate);
ans=false;
return ans;
}
return ans;
}
///////////////////////////////////////////////////////////////////////////
function checkRoomSearchDate(input) {
var validformat=/^\d{2}\/\d{2}\/\d{4}$/;
var returnval=false;
if (!validformat.test(input))
returnval=false;
else {
var monthfield=input.split("/")[0];
var dayfield=input.split("/")[1];
var yearfield=input.split("/")[2];
var returnval = new Date(yearfield, monthfield-1, dayfield);
/*if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
returnval=false; else returnval=t*/
}
return returnval;
}
function jShow(obj) {
$("#"+obj).show();
}
function jHide(obj) {
$("#"+obj).hide();
}
function objShow(obj) {
var ct=document.getElementById(obj);
ct.style.display='';
}
function objHide(obj) {
var ct=document.getElementById(obj);
ct.style.display='none';
}
function showErr(msg) {
var matter="<div class='notification error'>";
matter=matter+"<div class='text'>";
matter=matter+" <p><strong></strong>"+msg +"</p></div></div>";
return matter;
}
/*function showErr(msg) {
var matter="<div class='notification error'>";
matter=matter+"<div class='text'>";
matter=matter+" <p><strong>Error!</strong>"+msg +"</p></div></div>";
return matter;
}*/
function showSucc(msg) {
var matter="<div class='notification success'>";
matter=matter+"<div class='text'>";
matter=matter+" <p><strong>Success!</strong>"+msg +"</p></div></div>";
return matter;
}
function nextFocus(nextID) {
$("#"+nextID).focus();
}
function setFocusSubmit(e){
var cd=0;
if(window.event) {
cd = e.keyCode;
} else if(e.which) {
cd = e.which;
}
if(cd==13) {
return true;
} else {
return false;
}
}
function setFocusDate(e){
var cd=0;
if(window.event) {
cd = e.keyCode;
} else if(e.which) {
cd = e.which;
}
if(cd==9) {
return true;
} else {
return false;
}
}
function getIndexs(listBoxCtrl) {
var listBox=document.getElementById(''+listBoxCtrl+'');
var totalIndexes=listBox.length-1;
return totalIndexes;
}
function doAjax(urlStr,POSTorGET,variableAndValue) {
var ans="";
$.ajax( {
type: POSTorGET,
async: false,
url: urlStr,
data: variableAndValue,
timeout: 10000,
cache:false,
success: function(msg){ans=msg;},
error: function(xhr) {
if (xhr.responseText)
ans=xhr.responseText;
else
ans="I don't know! My Processor Has Been HACKED!";
}
}
);
return ans;
}
// HOW TO USE doAjax???
/*function doAddAction() {
var a1,a2,a3,dataVal;
var a1Val,a2Val,a3Val;
var urlStr="xmlPost.php";
var postOrGet="POST";
var ans;
var forHideDiv,forShowDiv;
forHideDiv="";
forShowDiv="";
a1Val="This is a1 val";
a2Val="This is a2 val";
a3Val="This is a3 val";
var variableAndValue={a1:a1Val,a2:a2Val,a3:a3Val};
ans=doAjax(urlStr,postOrGet,variableAndValue);
alert(ans);
}*/
function chkCharacter(obj,maxlimit,objMessage) {
var objMessage,field,num;
objMessage=document.getElementById(objMessage);
field=obj;
num=(maxlimit-field.value.length);
if(num<=0) {
num=0;
objMessage.style.color='red';
} else {
objMessage.style.color='green';
}
objMessage.innerHTML=num+" Character Remaining.";
if (field.value.length > maxlimit)
field.value = field.value.substring(0, maxlimit);
}
function isnotemail(email) {
var regEx = /^[\w\.\+-]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,6}$/;
if(!regEx.test(email))
{
return true;
}
return false;
}
////////////////////////////////////////////////////////////////////
var charSetName="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
function isName(myst) {
var i;
for (i = 0; i < myst.length; i++) {
var c = myst.charAt(i);
if (charSetName.indexOf(c) < 0) {
return false;
}
}
return true;
}
var charSetNameOther=" abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
function isNameOther(myst) {
var i;
for (i = 0; i < myst.length; i++) {
var c = myst.charAt(i);
if (charSetNameOther.indexOf(c) < 0) {
return false;
}
}
return true;
}
var numSet="1234567890";
function isNumber(myst) {
var i;
for (i = 0; i < myst.length; i++) {
var c = myst.charAt(i);
if (numSet.indexOf(c) < 0) {
return false;
}
}
return true;
}
var numSetDec="1234567890.";
function isNumberDec(myst) {
var i,noOfDec=0,decPos=0;
var splitArr;
for (i = 0; i < myst.length; i++) {
var c = myst.charAt(i);
if(c=='.') {
noOfDec++;
decPos=i;
}
if (numSetDec.indexOf(c) < 0) {
return false;
}
}
if(noOfDec>=1) {
splitArr=myst.split(".");
//alert("splitArr.length="+splitArr.length);
if(splitArr.length>2) {
//alert("Invalid Number");
return false;
} else {
var firstVal=splitArr[0];
var secondValue=splitArr[1];
//alert(secondValue.length);
if(secondValue.length==0 || secondValue.length>2) {
//alert("Invalid format");
return false ;
}
}
}
return true;
}
/////////////////get Date auto fill Date /////////////////////////////
/*function fillDate(curCtrl,nextCtrl) {
var dateVal,fullDate;
var toDay,dd,mm,yyyy;
var splitDate,searchSep;
dateVal=jQuery.trim($("#"+curCtrl).val());
toDay=new Date();
dd=toDay.getDate();
mm=toDay.getMonth()+1;
yyyy=toDay.getFullYear();
if(dateVal=="") {
fullDate=dd+"-"+mm+"-"+yyyy;
$("#"+curCtrl).val(fullDate);
} else {
searchSep=dateVal.indexOf("-");
if(searchSep==-1) {
if(parseInt(dateVal)>31) {
alert("Wrong date range");
return;
}
fullDate=dateVal+"-"+mm+"-"+yyyy;
} else {
splitDate=dateVal.split("-");
fullDate=splitDate[0];
if(splitDate[1]==undefined || splitDate[1]=="") {
fullDate=fullDate+"-"+mm;
} else {
fullDate=fullDate+"-"+splitDate[1];
}
if(splitDate[2]==undefined || splitDate[2]=="") {
fullDate=fullDate+"-"+yyyy;
} else {
fullDate=fullDate+"-"+splitDate[2];
}
}
$("#"+curCtrl).val(fullDate);
}
if(jQuery.trim(nextCtrl)!="") {
$("#"+nextCtrl).focus();
}
}*/
function fillDate(curCtrl,nextCtrl) {
var dateVal,fullDate;
var toDay,dd,mm,yyyy;
var splitDate,searchSep;
dateVal=jQuery.trim($("#"+curCtrl).val());
toDay=new Date();
dd=toDay.getDate();
mm=toDay.getMonth()+1;
yyyy=toDay.getFullYear();
var currentDate=dd+"-"+mm+"-"+yyyy;
if(dateVal=="") {
fullDate=dd+"-"+mm+"-"+yyyy;
$("#"+curCtrl).val(fullDate);
} else {
searchSep=dateVal.indexOf("-");
if(searchSep==-1) {
if(parseInt(dateVal)>31 || parseInt(dateVal)<1) {
//alert("Wrong date range.");
$("#"+curCtrl).val(currentDate);
return;
}
fullDate=dateVal+"-"+mm+"-"+yyyy;
} else {
splitDate=dateVal.split("-");
fullDate=splitDate[0];
//alert(fullDate);
if(splitDate[1]==undefined || splitDate[1]=="" || parseInt(splitDate[1])<1) {
fullDate=fullDate+"-"+mm;
} else {
fullDate=fullDate+"-"+splitDate[1];
}
if(splitDate[2]==undefined || splitDate[2]=="" || parseInt(splitDate[2])<1) {
fullDate=fullDate+"-"+yyyy;
} else {
var yRem=parseInt(splitDate[2]);
if(yRem>=1 && yRem<=25) {
splitDate[2]=parseInt(splitDate[2])+2000;
}
fullDate=fullDate+"-"+splitDate[2];
}
}
$("#"+curCtrl).val(fullDate);
if(!chkForLeap(fullDate)) {
$("#"+curCtrl).val(currentDate);
$("#"+curCtrl).focus();
}
}
if(jQuery.trim(nextCtrl)!="") {
$("#"+nextCtrl).focus();
}
}
function chkForLeap(dt) {
var ans=true;
var oldDt,dd,mm,yyyy,lp,lpFeb,i;
var monthArray=new Array(12);
for (i=0;i<12; i++) {
monthArray[i]=new Array(2);
}
monthArray[0][0]=1;
monthArray[0][1]=31;
monthArray[1][0]=2;
monthArray[1][1]=29;
monthArray[2][0]=3;
monthArray[2][1]=31;
monthArray[3][0]=4;
monthArray[3][1]=30;
monthArray[4][0]=5;
monthArray[4][1]=31;
monthArray[5][0]=6
monthArray[5][1]=30;
monthArray[6][0]=7;
monthArray[6][1]=31;
monthArray[7][0]=8;
monthArray[7][1]=31;
monthArray[8][0]=9;
monthArray[8][1]=30;
monthArray[9][0]=10;
monthArray[9][1]=31;
monthArray[10][0]=11;
monthArray[10][1]=30;
monthArray[11][0]=12;
monthArray[11][1]=31;
oldDt=dt;
spDate=oldDt.split("-");
dd=parseInt(spDate[0]);
mm=parseInt(spDate[1]);
yyyy=parseInt(spDate[2]);
var currentYear,toDay;
toDay=new Date();
currentYear=toDay.getFullYear();
var reg = /^\d{1,2}\-\d{1,2}\-\d{4}$/;
if(!oldDt.match(reg)) {
//alert("Invalid date format: ");
ans=false;
return ans;
}
if(mm>12 || mm<1) {
//alert("Invalid date format: ");
$("#"+curCtrl).val(currentDate);
ans=false;
return ans;
}
if(yyyy>currentYear || yyyy<(currentYear-25)){
//alert("Invalid year");
$("#"+curCtrl).val(currentDate);
ans=false;
return ans;
}
lp=yyyy%4;
lpFeb=lp==0?29:28;
monthArray[1][1]=lpFeb;
if(dd>monthArray[mm-1][1] || dd<1) {
//alert("Invalid day of date, you could not enter "+dd +" as it is greater than "+monthArray[mm-1][1]);
$("#"+curCtrl).val(currentDate);
ans=false;
return ans;
}
return ans;
}
///////////////////////////////////////////////////////////////////////////
function checkRoomSearchDate(input) {
var validformat=/^\d{2}\/\d{2}\/\d{4}$/;
var returnval=false;
if (!validformat.test(input))
returnval=false;
else {
var monthfield=input.split("/")[0];
var dayfield=input.split("/")[1];
var yearfield=input.split("/")[2];
var returnval = new Date(yearfield, monthfield-1, dayfield);
/*if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
returnval=false; else returnval=t*/
}
return returnval;
}
function jShow(obj) {
$("#"+obj).show();
}
function jHide(obj) {
$("#"+obj).hide();
}
function objShow(obj) {
var ct=document.getElementById(obj);
ct.style.display='';
}
function objHide(obj) {
var ct=document.getElementById(obj);
ct.style.display='none';
}
function showErr(msg) {
var matter="<div class='notification error'>";
matter=matter+"<div class='text'>";
matter=matter+" <p><strong></strong>"+msg +"</p></div></div>";
return matter;
}
/*function showErr(msg) {
var matter="<div class='notification error'>";
matter=matter+"<div class='text'>";
matter=matter+" <p><strong>Error!</strong>"+msg +"</p></div></div>";
return matter;
}*/
function showSucc(msg) {
var matter="<div class='notification success'>";
matter=matter+"<div class='text'>";
matter=matter+" <p><strong>Success!</strong>"+msg +"</p></div></div>";
return matter;
}
function nextFocus(nextID) {
$("#"+nextID).focus();
}
function setFocusSubmit(e){
var cd=0;
if(window.event) {
cd = e.keyCode;
} else if(e.which) {
cd = e.which;
}
if(cd==13) {
return true;
} else {
return false;
}
}
function setFocusDate(e){
var cd=0;
if(window.event) {
cd = e.keyCode;
} else if(e.which) {
cd = e.which;
}
if(cd==9) {
return true;
} else {
return false;
}
}
function getIndexs(listBoxCtrl) {
var listBox=document.getElementById(''+listBoxCtrl+'');
var totalIndexes=listBox.length-1;
return totalIndexes;
}
function doAjax(urlStr,POSTorGET,variableAndValue) {
var ans="";
$.ajax( {
type: POSTorGET,
async: false,
url: urlStr,
data: variableAndValue,
timeout: 10000,
cache:false,
success: function(msg){ans=msg;},
error: function(xhr) {
if (xhr.responseText)
ans=xhr.responseText;
else
ans="I don't know! My Processor Has Been HACKED!";
}
}
);
return ans;
}
// HOW TO USE doAjax???
/*function doAddAction() {
var a1,a2,a3,dataVal;
var a1Val,a2Val,a3Val;
var urlStr="xmlPost.php";
var postOrGet="POST";
var ans;
var forHideDiv,forShowDiv;
forHideDiv="";
forShowDiv="";
a1Val="This is a1 val";
a2Val="This is a2 val";
a3Val="This is a3 val";
var variableAndValue={a1:a1Val,a2:a2Val,a3:a3Val};
ans=doAjax(urlStr,postOrGet,variableAndValue);
alert(ans);
}*/