function checkCurrentDates(dd1,mm1,yy1,cd1,cm1,cy1) { var flag=true; yy1=parseInt(yy1); mm1=parseInt(mm1); dd1=parseInt(dd1); cd1=parseInt(cd1); cm1=parseInt(cm1); cy1=parseInt(cy1); if (yy1 < cy1) { alert("The required date should be greater than today's date."); flag=false; } else if (yy1 == cy1) { if(mm1 < cm1) { alert("The required date should be greater than today's date."); flag=false; } else if(mm1 == cm1) { if(dd1 < cd1) { alert("The required date should be greater than today's date."); flag=false; } } } return flag; } function checkCorrectDates(dd1,mm1,yy1,dd2,mm2,yy2) { var flag=true; yy1=parseInt(yy1); mm1=parseInt(mm1); dd1=parseInt(dd1); yy2=parseInt(yy2); mm2=parseInt(mm2); dd2=parseInt(dd2); if (yy1 > yy2) { alert("From date should be less than to date."); flag=false; } else if (yy1 == yy2) { if(mm1 > mm2) { alert("From date should be less than to date."); flag=false; } else if(mm1 == mm2) { if(dd1 > dd2) { alert("From date should be less than to date."); flag=false; } } } return flag; } function monthToNum(monthStr) { if (monthStr=="") return false; var m = monthStr; if (monthStr.length>3) var m = monthStr.substring(0,2); if (m=="jan" || m=="Jan" || m=="JAN") return 1; else if (m=="feb" || m=="Feb" || m=="FEB") return 2; else if (m=="mar" || m=="Mar" || m=="MAR") return 3; else if (m=="apr" || m=="Apr" || m=="APR") return 4; else if (m=="may" || m=="May" || m=="MAY") return 5; else if (m=="jun" || m=="Jun" || m=="JUN") return 6; else if (m=="jul" || m=="Jul" || m=="JUL") return 7; else if (m=="aug" || m=="Aug" || m=="AUG") return 8; else if (m=="sep" || m=="Sep" || m=="SEP") return 9; else if (m=="oct" || m=="Oct" || m=="OCT") return 10; else if (m=="nov" || m=="Nov" || m=="NOV") return 11; else if (m=="dec" || m=="Dec" || m=="DEC") return 12; else return 0; } function checkBlank(fieldname) { var field1 = fieldname.value; field1=trimme(field1); if(field1.length==0 || field1=="") { alert("Please enter required date."); fieldname.value = field1; fieldname.focus(); return false; } else { fieldname.value = field1; return true; } } function isWhitespace(s) { var ss = s.value; var len = ss.length; var i; var j=0; var flag = true; if (chkEmpty(s) == false) { for (i = 0; i < len; i++) { var c = ss.charAt(i); if(c == " "){j=j+1;} } if(j == len) { alert("Please enter required date.") s.select(); s.focus(); flag=false; } else flag = true; } return flag; } function chkEmpty(theField) { if(theField.value == "") return true; else return false; } function trimme(num1) { var num=num1; len=num.length; for (var j=0;j0) for (var j=len-1;j>0;j--) { char1=num.charAt(j); if(char1==" ") num1=num.substring(0,j); else break; } return num1; } function validDate(dateField, errMsg, fmt) { var ds = dateField.value; // bail if the date parameter is empty if (ds == "") return true; // declare local variables var n = 10; // the Y2K offset in years var today = new Date(); var err = 0; // error flag var month = ""; var d; var m; var y; var p1 = 0; var p2 = 0; var dd = 0; var mm = 0; var yy = (today.getYear() < 1900) ? today.getYear() + 1900 : today.getYear(); var e = errMsg; if (errMsg == "") { // default error message if second parameter is empty e = "Invalid date! Please re-enter using a standard format..."; } // strip leading and trailing spaces while (ds.charAt(0) == " ") { ds = ds.substring(1,ds.length); dateField.value = ds; } while (ds.charAt(ds.length-1) == " ") { ds = ds.substring(0,ds.length-1); dateField.value = ds; } // handle common data-entry shortcuts if (ds == "t" || ds == "today" || ds == "0") { dd = today.getDate(); mm = today.getMonth() + 1; ds = mm + "/" + dd + "/" + yy; } else if (ds.length < 3 && isNum(ds)) { // try as a date in the current month and year if (parseInt(ds) < 32) { dd = ds; mm = today.getMonth() + 1; ds = mm + "/" + dd + "/" + yy; } } else if (ds.length == 3 && monthToNum(ds) > 0) { // assume it's a month string, set date as 1st dd = 1; mm = monthToNum(ds); ds = mm + "/" + dd + "/" + yy; } else if (ds.length == 4 && isNum(ds)) { if (parseInt(ds) > 1231) { // assume it's a year [yyyy], set date to 1st January dd = 1; mm = 1; yy = ds; ds = mm + "/" + dd + "/" + yy; } else { // assume it's a month and day [mmdd], set year as current dd = ds.substring(2); mm = ds.substring(0,2); ds = mm + "/" + dd + "/" + yy; } } else if (ds.length>4 && ds.length<7 && monthToNum(ds.substring(0,3))>0 && ds.indexOf(" ",0)>0) { // assume it's a month and day (mmm d[d]), set year as current p1 = ds.indexOf(" "); // position of space dd = ds.substring(p1+1,ds.length); mm = monthToNum(ds.substring(0,3)); ds = mm + "/" + dd + "/" + yy; } else if (ds.length>2 && ds.length<6 && ds.indexOf("/",0)>0 && ds.indexOf("/",0)==ds.lastIndexOf("/")) { // assume it's a month and day (mm/dd), set year as current p1 = ds.indexOf("/"); // position of slash mm = ds.substring(0,p1); dd = ds.substring(p1+1,p1+3); if (dd.charAt(0) == "0") dd = dd.substring(1,2); if (mm.charAt(0) == "0") mm = mm.substring(1,2); ds = mm + "/" + dd + "/" + yy; } else if (ds.length>2 && ds.length<6 && ds.indexOf(" ",0)>0 && ds.indexOf(" ",0)==ds.lastIndexOf(" ")) { // assume it's a month and day (mm dd), set year as current p1 = ds.indexOf(" "); // position of space mm = ds.substring(0,p1); dd = ds.substring(p1+1,p1+3); if (dd.charAt(0) == "0") dd = dd.substring(1,2); if (mm.charAt(0) == "0") mm = mm.substring(1,2); ds = mm + "/" + dd + "/" + yy; } else if (ds.length>2 && ds.length<6 && ds.indexOf("-",0)>0 && ds.indexOf("-",0)==ds.lastIndexOf("-")) { // assume it's a day and month (dd-mm), set year as current p1 = ds.indexOf("-"); // position of dash dd = ds.substring(0,p1); mm = ds.substring(p1+1,ds.length); if (dd.charAt(0) == "0") dd = dd.substring(1,2); if (mm.charAt(0) == "0") mm = mm.substring(1,2); ds = mm + "/" + dd + "/" + yy; } if (ds.indexOf("-",0)>0 && ds.indexOf("-",0)<3) { // test for DD-MMM-YYYY standard format if (ds.length == 11 && ds.indexOf("-",0) == 2 && ds.lastIndexOf("-") == 6) { dd = ds.substring(0,2); mm = monthToNum(ds.substring(3,6)); yy = ds.substring(7,11); if (dd.charAt(0) == "0") dd = dd.substring(1,2); if (isNum(mm+dd+yy)) { ds = mm + "/" + dd + "/" + yy; } else { mm = 0; dd = 0; yy = 0; } } } // validate the standard space-delimited formats else if (ds.indexOf(" ",0)>0 && (ds.length-ds.lastIndexOf(" "))<6) { if (ds.indexOf(",",0) > 0) { // validate 'mmm[...] dd, yy[yy]' type formats p1 = ds.indexOf(" "); // position of first space mm = monthToNum(ds.substring(0,3)); dd = ds.substring(p1+1,ds.indexOf(",",0)); p2 = ds.lastIndexOf(" "); // position of last space yy = ds.substring(p2+1,ds.length); if (dd.charAt(0) == "0") dd = dd.substring(1,2); if (yy.length > 4) yy = yy.substring(0,4); if (yy == "0" || yy == "00" || yy == "000") yy = "2000"; while (yy.substring(0,1)=="0") { yy = yy.substring(1,yy.length); // remove leading zeroes } if (yy == "") yy = (today.getYear() < 1900) ? today.getYear() + 1900 : today.getYear(); if (isNum(mm+dd+yy)) { if (yy > 0 && yy < 100) { yy = (yy < n) ? (2000 + parseInt(yy)) : (1900 + parseInt(yy)); } ds = mm + "/" + dd + "/" + yy; } else { mm = 0; dd = 0; yy = 0; } } else if (monthToNum(ds.substring(ds.indexOf(" ")+1,ds.indexOf(" ")+4))>0) { // validate 'dd mmm[...] yy[yy]' type formats p1 = ds.indexOf(" "); // position of first space dd = ds.substring(0,p1); if (dd.charAt(0) == "0") dd = dd.substring(1,2); p2 = ds.lastIndexOf(" "); // position of last space mm = monthToNum(ds.substring(p1+1,p1+4)); // extract 3 bytes for month yy = ds.substring(p2+1,ds.length); if (yy.length > 4) yy = yy.substring(0,4); if (yy == "0" || yy == "00" || yy == "000") yy = "2000"; while (yy.substring(0,1) == "0") { yy = yy.substring(1,yy.length); // remove leading zeroes } if (yy == "") yy = (today.getYear() < 1900) ? today.getYear() + 1900 : today.getYear(); if (isNum(mm+dd+yy)) { if (yy > 0 && yy < 100) { yy = (yy < n) ? (2000 + parseInt(yy)) : (1900 + parseInt(yy)); } ds = mm + "/" + dd + "/" + yy; } else { mm = 0; dd = 0; yy = 0; } } } // attempt to parse any other dates with valid IETF formats if (dd==0 && mm==0 && yy==0) { d = new Date(Date.parse(ds)); dd = d.getDate(); mm = (d.getMonth() + 1); // Netscape returns last 2 digits of years 1900-1999, // and the full year (4 char) string for dates > 2000 or < 1900; // IE returns 1900 minus the current year in all cases, // except IE3, when the year is earlier than 1970 if (d.getYear() > 2000) { yy = d.getYear(); // Netscape } else if (d.getYear() < 1900 && d.getYear() > 200) { yy = d.getYear(); // Netscape, date prior to 1900 } else { yy = d.getYear() + 1900; } if (dd == 31 && mm == 12 && yy == 1969) { // IE's start-epoch date mm = 0; dd = 0; yy = 0; } ds = mm + "/" + dd + "/" + yy; } // verify the date components if (parseInt(dd)>0 && parseInt(mm)>0 && parseInt(yy)+1>0) { if (mm < 1 || mm > 12) err = 1; if (dd < 1 || dd > 31) err = 1; if (yy < 1000 || yy > 9999) err = 1; // check the months with 30 days if (mm == 4 || mm == 6 || mm == 9 || mm == 11) { if (dd == 31) { dd = 1; // flick it forward a day mm = mm + 1; } } // check February and leap years if (mm == 2) { if (dd > 29) err = 1; if (dd == 29 && ((yy/4) != parseInt(yy/4))) { dd = 1; // flick it forward a day mm = 3; } } } // finally, test whether the input string can be Date.parsed d = new Date(Date.parse(ds)); if (!d.getDate()) err = 1; if (err==1 || dd==0 || mm==0) { alert(e); dateField.select(); dateField.focus(); return false; } // we have a valid IETF date, so convert it to // the specified standard format for database entry if (parseInt(dd)<10 && (fmt < 4 || fmt > 6)) dd = "0" + dd; // add leading zero to days 1-9 // convert month numeric to string if (mm == 1) month = "Jan"; else if (mm == 2) month = "Feb"; else if (mm == 3) month = "Mar"; else if (mm == 4) month = "Apr"; else if (mm == 5) month = "May"; else if (mm == 6) month = "Jun"; else if (mm == 7) month = "Jul"; else if (mm == 8) month = "Aug"; else if (mm == 9) month = "Sep"; else if (mm == 10) month = "Oct"; else if (mm == 11) month = "Nov"; else if (mm == 12) month = "Dec"; else month == ""; // add leading zero to months 1-9 for mm formats if (fmt > 6 && mm < 10) mm = "0" + mm; // trim for yy formats if ((yy>99) && (fmt==0 || fmt==2 || fmt==5 || fmt==7 || fmt==9)) { yy = yy - (parseInt(yy/100)*100); if (yy < 10) yy = "0" + yy; } // re-test the date components if (dd==0 || dd=="" || month=="" || mm==0 || mm=="" || yy=="") { alert(e); dateField.select(); dateField.focus(); return false; } if (fmt == 1) dateField.value = dd + " " + month + " " + yy; else if (fmt == 2) dateField.value = dd + "-" + month + "-" + yy; else if (fmt == 3) dateField.value = dd + "-" + month + "-" + yy; else if (fmt == 4) dateField.value = month + " " + dd + ", " + yy; else if (fmt == 5) dateField.value = mm + "/" + dd + "/" + yy; else if (fmt == 6) dateField.value = mm + "/" + dd + "/" + yy; else if (fmt == 7) dateField.value = mm + "/" + dd + "/" + yy; else if (fmt == 8) dateField.value = mm + "/" + dd + "/" + yy; else if (fmt == 9) dateField.value = mm + " " + dd + " " + yy; else if (fmt == 10) dateField.value = mm + " " + dd + " " + yy; else dateField.value = dd + " " + month + " " + yy; return true; } // Internal function to test whether argument is a number function isNum(arg) { if (arg == "") return false; for (i=0; i "9") { return false; } } return true; } // Internal function to convert a month string to numeric 1-12 function monthToNum(monthStr) { if (monthStr=="") return false; var m = monthStr; if (monthStr.length>3) var m = monthStr.substring(0,2); if (m=="jan" || m=="Jan" || m=="JAN") return 1; else if (m=="feb" || m=="Feb" || m=="FEB") return 2; else if (m=="mar" || m=="Mar" || m=="MAR") return 3; else if (m=="apr" || m=="Apr" || m=="APR") return 4; else if (m=="may" || m=="May" || m=="MAY") return 5; else if (m=="jun" || m=="Jun" || m=="JUN") return 6; else if (m=="jul" || m=="Jul" || m=="JUL") return 7; else if (m=="aug" || m=="Aug" || m=="AUG") return 8; else if (m=="sep" || m=="Sep" || m=="SEP") return 9; else if (m=="oct" || m=="Oct" || m=="OCT") return 10; else if (m=="nov" || m=="Nov" || m=="NOV") return 11; else if (m=="dec" || m=="Dec" || m=="DEC") return 12; else return 0; } // My functions start here // checks for empty/null/length of strings function checkStrRange(str,min,max) { if (isEmpty(str)==true) { msgBox(str,"Please enter a value.") return false } else { if(isWhiteSpace(str)==true) { msgBox(str,"Invalid input. Empty string not allowed.") return false } else { if (checkLen(str,min,max)==false) { msgBox(str,"Invalid number of characters.") return false } } } return true } // checks for empty/null function checkStrEmpty(str) { if (isEmpty(str)==true) { msgBox(str,"Please enter a value.") return false } else { if(isWhiteSpace(str)==true) { msgBox(str,"Invalid input. Empty string not allowed.") return false } } return true } // checks for length of strings function checkStrRan(str,min,max) { if (checkLen(str,min,max)==false) { msgBox(str,"Invalid number of characters.") return false } return true } // checks whether the field is numeric/length/negative values for optional fields of nummeric data type. function checkStrRan1(str,min,max) { if (isEmpty(str)==false) { if(isWhiteSpace(str)==true) { msgBox(str,"Invalid input. Empty string not allowed.") return false } else { if (isNaN(str.value)==true) { msgBox(str,"Characters are not allowed.") return false } else { if (checkLen(str,min,max)==false) { msgBox(str,"Invalid number of characters.") return false } else { if(checkNegValue(str)==true) { msgBox(str,"Please enter a positive number.") return false } } } } } else { str.value ="0" } return true } // checks whether the field is numeric/length/negative values for mandatory fields of numeric data type function checkStrRan2(str,min,max) { if (isEmpty(str)==true) { msgBox(str,"Please enter a value.") return false } else { if(isWhiteSpace(str)==true) { msgBox(str,"Invalid input. Empty string not allowed.") return false } else { if (isNaN(str.value)==true) { msgBox(str,"Characters are not allowed.") return false } else { if (checkLen(str,min,max)==false) { msgBox(str,"Invalid number of characters.") return false } else { if(checkNegValue(str)==true) { msgBox(str,"Please enter a positive value.") return false } } } } } return true } // checks the card number // checks whether the field is numeric/length/negative values for mandatory fields of numeric data type function checkStrRan3(str,min,max) { if (isEmpty(str)==true) { msgBox(str,"Please enter a value.") return false } else { if(isWhiteSpace(str)==true) { msgBox(str,"Invalid input. Empty string not allowed.") return false } else { if (isNaN(str.value)==true) { msgBox(str,"Characters are not allowed.") return false } else { if (checkLen(str,min,max)==false) { msgBox(str,"Invalid number of characters.") return false } else { if(checkNegVal(str)==true) { msgBox(str,"Please enter a positive value greater than zero.") return false } } } } } return true } // checks for empty/null for list boxes function checkStrEmpty1(str) { if (isEmpty1(str)==true) { msgBox1(str,"Please select a value.") return false } } function isEmpty(str) { if ((str.value == null) || (str.value.length == "")) return true return false } function isWhiteSpace(str) { var ss = str.value; var len = ss.length; var i; var j=0; for (i = 0; i < len; i++) { var c = ss.charAt(i); if(c == " "){j=j+1;} } if(j == len) return true return false } function checkNegValue(str) { if(str.value < 0 ) return true return false } function checkNegVal(str) { if(str.value < 1 ) return true return false } function checkLen(str,min,max) { if(str.value.length < min || str.value.length > max) return false return true } function checkValidEmail(str,min,max) { if (isEmpty(str)==true) { msgBox(str,"Please enter a value."); return false } else { if(isWhiteSpace(str)==true) { msgBox(str,"Invalid input. Empty string not allowed.") return false } else { if (checkLen(str,min,max)==false) { msgBox(str,"Invalid number of characters.") return false } else { if(checkEmail(str)==false) { msgBox(str,"Please enter a valid email address.") return false } } } } return true } // To check valid email ID function checkEmail(str) { var flag = false; if(!isEmpty(str)) { if(!isWhiteSpace(str)) { var ob = str.value; var len = ob.length; for(i=0;i<=ob.length;i++) { if(ob.charAt(i) == '@') { if(i == 0 || i == len-1)break; for(j=0;j<=ob.length;j++) { if(ob.charAt(j) == '.') { if(j == 0 || j == len-1)break; flag = true; break; } } } }} //if(!flag) //{ //alert("Please enter a valid email address."); //str.value=""; //str.focus(); //} } return flag; } function isEmpty1(str) { if((str.options[str.selectedIndex].value == "") || (str.options[str.selectedIndex].value == 0)) return true; else return false; } function msgBox(str,msg) { alert(msg) str.focus() str.select() } function msgBox1(str,msg) { alert(msg) str.focus() } // this function transfers data from one list box to another function transferData(list1,list2) { var k=0,j=0,index2=0; var len=list1.options.length; var len1=list2.options.length; var ary2=new Array(); for (var i=0; i < len; i++) { if(list1.options[i].selected==true) { while(index2 < len1 && list1.options[i].text > list2.options[index2].text) { ary2[j++]=list2.options[index2].text; ary2[j++]=list2.options[index2].value; index2++; } if(index2 < len1 && list1.options[i].value == list2.options[index2].value) { index2++; } ary2[j++]=list1.options[i].text; ary2[j++]=list1.options[i].value; list1.options[i].selected=false; } else { list1.options[k].text = list1.options[i].text; list1.options[k].value = list1.options[i].value; k++; } } while(index2 < len1) { ary2[j++]=list2.options[index2].text; ary2[j++]=list2.options[index2].value; index2++; } list1.options.length = k; list2.options.length=0; j=0; for(var m=0;m