//To check whether the Textbox control is blank or not function IsInputFilled(strControl) { if(strControl.value=="") { return false; } else { return true; } } //To check whether the Dropdown control is selected or not function IsSelectFilled(strControl) { if(strControl.selectedIndex < 0) { return false; } if(strControl[strControl.selectedIndex].value=="") { return false; } else { return true; } } //To check whether the Radio control is selected or not function IsRadioFilled(strControl) { for(i=0; i 1)) { return false; } else { return true; }*/ var str = strControl.value var remove_comma=/\,/g; str=str.replace(remove_comma, ''); var filter=/[0-9]*[.][0-9]*[.][0-9]*/ //[^0-9.] will match for strings other than 0 to 9 and dot. var filter1=/[^0-9.]/ if ((filter.test(str)==true)||(filter1.test(str)==true)) { return false; } else { return true; } } function IsCurrency(strControl) { if(!IsFloat(strControl)) { return false; } var t = parseFloat(strControl.value) * 100; t = "" + t; if(t.indexOf('.') >=0 ) { return false; } return true; } //To check whether the Email Id entered in Textbox control is valid Email Id or not function IsEmail(strControl) { var str=strControl.value if(str=="") { return true; } //var filter=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/ //var filter = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ var filter = /^(([^<>()[\]\\.,;:\s@\!$#&%*?~`^{}'|+="]+(\.[^<>()[\]\\.,;:\s@\!$#&%*?~`^{}'|+="]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ if ((filter.test(str)==false)||(str.indexOf("/")!==-1)) { return false; } else { return true; } } //This function autofills the date.ie if you have not entered month, year //It will take the current month ,year function AutoCompleteDate(strControl) { if(!IsInputFilled(strControl)) { return false; } var val = strControl.value.split('/'); var val1 = ""; var val2 = ""; var val3 = ""; if(val.length == 1) { val1 = val[0]; }else if(val.length == 2) { val1 = val[0]; val2 = val[1]; }else if(val.length == 3) { val1 = val[0]; val2 = val[1]; val3 = val[2]; } var now = new Date(); var date = now.getDate(); var month = now.getMonth() + 1; var year = now.getFullYear(); date = PrefixZero(date); month = PrefixZero(month); if(val1.length == 0) { val1 = date; } if(val2.length == 0) { val2 = month; } if(val3.length == 0) { val3 = year; } if(val1.length != 2) { val1 = PrefixZero(val1); } if(val2.length != 2) { val2 = PrefixZero(val2); } if(val3.length == 1) { val3 = "200" + val3; } if(val3.length == 2) { if(val3 > 70) { val3 = "19" + val3; } else { val3 = "20" + val3; } } val[0] = val1; val[1] = val2; val[2] = val3; strControl.value = val[0] + "/" + val[1] + "/" + val[2]; } function AutoCompleteDatetime(strControl) { var space=strControl.value.split(" "); var date = space[0]; var time; strControl.value = space[0]; LibAutoCompleteDate(strControl); if(strControl.value == "" || strControl.value == null) return; strControl.value = strControl.value + " "; if(space[1] == null || space[1] == "") { time = "00:00:00"; } else { time = space[1]; } var colon = time.split(":"); var hours = ""; var minutes = ""; var seconds = ""; hours = colon[0]; minutes = colon[1]; seconds = colon[2]; if(hours == null || hours == "") hours = "00"; if(minutes == null || minutes == "") minutes = "00"; if(seconds == null || seconds == "") seconds = "00"; if(hours.length ==0) hours = "00"; if(hours.length ==1) hours = "0" + hours; if(minutes.length ==0) minutes = "00"; if(minutes.length ==1) minutes = "0" + minutes; if(seconds.length ==0) seconds = "00"; if(seconds.length ==1) seconds = "0" + seconds; strControl.value += hours + ":" + minutes + ":" + seconds; } //This function is used inside the LibAutoCompleteDate function. //It will add 0 to the existing value if it is less than 10 function PrefixZero(i) { if(i < 10) { i = "0" + i; } return i; } //It checks whether the date is in valid dd/mm/yy format or not function IsDate(strControl) { if(strControl.value == "") { return true; // Note, mandatory validations are anyways separately done. } var dateSplit=strControl.value.split("/") var day = dateSplit[0]; var month = dateSplit[1]; var year = dateSplit[2]; if((dateSplit.length < 3)||(dateSplit.length > 3)) { return false; } /*else if(LibIsValidInteger(day)==false||LibIsValidInteger(month)==false||LibIsValidInteger(year)==false) { return false; }*/ var filter=/[^0-9]/ if (filter.test(day)==true) { return false; } if (filter.test(month)==true) { return false; } if (filter.test(year)==true) { return false; } if((day <= 0)||(day > 31)) { return false; } if((month <= 0)||(month > 12)) { return false; } if(((month == 4)||(month == 6)||(month == 9)||(month == 11))&&(day == 31)) { return false; } if(month==2) { var isLeapYear =(year % 4==0 &&(year % 100 !=0||year % 400 ==0)); //alert(isLeapYear); if(day > 29 || (day == 29 && !isLeapYear)) { return false; } } if((year.length==3)||(year.length > 4)||(year.length==0)) { return false } else { return true; } } function IsDatetime(strControl) { if(strControl.value.indexOf(" ")==-1) { return false; } var space=strControl.value.split(" "); var date = space[0]; /*if(LibIsValidDate(date)==false) { return false; }*/ var dateSplit= date.split("/"); var time = space[1] var timeSplit = time.split(":") if((dateSplit.length < 3)||(dateSplit.length > 3)) { return false; } if((timeSplit.length < 3)||(timeSplit.length > 3)) { return false; } var month = dateSplit[0]; var day = dateSplit[1]; var year = dateSplit[2]; /*var now = new Date() var hour = now.getHours(); var min = now.getMinutes(); var sec = now.getSeconds();*/ var hour = timeSplit[0]; var min = timeSplit[1]; var sec = timeSplit[2]; if((day <= 0)||(day > 31)) { return false; } if((month <= 0)||(month > 12)) { return false; } if(((month == 4)||(month == 6)||(month == 9)||(month == 11))&&(day == 31)) { return false; } if(month==2) { var isLeapYear =(year % 4==0 &&(year % 100 !=0||year % 400 ==0)); //alert(isLeapYear); if(day > 29 || (day == 29 && !isLeapYear)) { return false; } } if((year.length==3)||(year.length > 4)||(year.length==0)) { return false } if((hour < 0)||(hour >=24)) { return false; } if((min < 0)||(min >=60)||(min=="")) { return false; } if((sec < 0)||(sec >=60)||(sec=="")) { return false; } /*else { strControl.value = day + "/" + month + "/" + year + " " + hour + ":" + min + ":" + sec }*/ return true; } function InputError(strControl,strMessage) { alert(strMessage); strControl.focus(); strControl.select(); } function SelectError(strControl,strMessage) { alert(strMessage); strControl.focus(); } //it checks whether the From date is less than or equal to To Date function LibDateComparison(strControl,strControl1) { var fromDate=strControl.value; var toDate=strControl1.value; var testdate = new Date(fromDate.substring(6,10),fromDate.substring(3,5)-1,fromDate.substring(0,2)); var testdate1 = new Date(toDate.substring(6,10),toDate.substring(3,5)-1,toDate.substring(0,2)); if(testdate >=testdate1) { return false; } else { return true; } } //it checks whether the from Value is less than to Value function LibValueComparison(strControl,strControl1) { if(strControl.value >= strControl1.value) { return false; } else { return true; } } function FieldHelp(strTable,strField,strHeight,strWidth) { var helpWindow=window.open('Help/Field/'+strTable +'_' +strField +'.aspx','FieldHelp','height='+strHeight+',width='+strWidth+',left=660,top=205') helpWindow.focus(); } var ValidationError = false; function AllAddModifyValid() { ValidationError = false; var Mandatory = AllMandatory.split(","); var fieldname; var tMandatory = ","+AllMandatory+","; var tIntegers = ","+AllIntegers+","; var tFloats = ","+AllFloats+","; var tStrings = ","+AllStrings+","; var tCurrencies = ","+AllCurrencies+","; var tEmails = ","+AllEmails+","; var tDates = ","+AllDates+","; var tDateTimes = ","+AllDateTimes+","; for(i = objForm.elements.length-1; i>=0; i--) { // why this logic? ...because error sequence should be same as physical sequence on screen. var Field = objForm.elements[i]; if(!Field.name || !Field.type) { // Some elements may not be "Fields" at all. continue; } if(!eval("document.getElementById('vld"+Field.name+"')")) { // Hidden fields have no vld** div continue; } if(tMandatory.indexOf(","+Field.name+",") != -1) { if(!MandatoryValid(Field)) { ValidationError = true; continue; // If primary validation fails, why go to next one! } } if(tStrings.indexOf(","+Field.name+",") != -1) { if(!IsString(Field)) { eval("document.getElementById('vld"+Field.name+"').innerHTML = 'Contains Invalid Characters';"); Field.focus(); ValidationError = true; } else { eval("document.getElementById('vld"+Field.name+"').innerHTML = '';"); } } if(tIntegers.indexOf(","+Field.name+",") != -1) { if(!IsInteger(Field)) { eval("document.getElementById('vld"+Field.name+"').innerHTML = 'Should be Whole Number';"); Field.focus(); ValidationError = true; } else { eval("document.getElementById('vld"+Field.name+"').innerHTML = '';"); } } if(tFloats.indexOf(","+Field.name+",") != -1) { if(!IsFloat(Field)) { eval("document.getElementById('vld"+Field.name+"').innerHTML = 'Should be Decimal Number';"); Field.focus(); ValidationError = true; } else { eval("document.getElementById('vld"+Field.name+"').innerHTML = '';"); } } if(tCurrencies.indexOf(","+Field.name+",") != -1) { if(!IsCurrency(Field)) { eval("document.getElementById('vld"+Field.name+"').innerHTML = 'Should be Dedimal with max 2 decimal places';"); Field.focus(); ValidationError = true; } else { eval("document.getElementById('vld"+Field.name+"').innerHTML = '';"); } } if(tEmails.indexOf(","+Field.name+",") != -1) { if(!IsEmail(Field)) { eval("document.getElementById('vld"+Field.name+"').innerHTML = 'Should be of the form x@y.z';"); Field.focus(); ValidationError = true; } else { eval("document.getElementById('vld"+Field.name+"').innerHTML = '';"); } } if(tDates.indexOf(","+Field.name+",") != -1) { if(!IsDate(Field)) { eval("document.getElementById('vld"+Field.name+"').innerHTML = 'Should be a valid Date';"); Field.focus(); ValidationError = true; } else { eval("document.getElementById('vld"+Field.name+"').innerHTML = '';"); } } if(tDateTimes.indexOf(","+Field.name+",") != -1) { if(!IsDateTime(Field)) { eval("document.getElementById('vld"+Field.name+"').innerHTML = 'Should be a valid DateTime';"); Field.focus(); ValidationError = true; } else { eval("document.getElementById('vld"+Field.name+"').innerHTML = '';"); } } } return !ValidationError; } function AllSearchValid() { ValidationError = false; var fieldname; var tAllLists = ","+AllLists+","; var tAllRanges = ","+AllRanges+","; for(i = objForm.elements.length-1; i>=0; i--) { // why this logic? ...because error sequence should be same as physical sequence on screen. var Field = objForm.elements[i]; if(!Field.name || !Field.type) { // Some elements may not be "Fields" at all. continue; } if(!eval("document.getElementById('vld"+Field.name+"')")) { // Hidden fields have no vld** div continue; } if(tAllLists.indexOf(","+Field.name+",") != -1) { if(Field.value.indexOf("'") != -1 || Field.value.indexOf('"') != -1) { eval("document.getElementById('vld"+Field.name+"').innerHTML = 'Contains Invalid Characters';"); Field.focus(); ValidationError = true; } else { eval("document.getElementById('vld"+Field.name+"').innerHTML = '';"); } } if(tAllRanges.indexOf(","+Field.name+",") != -1) { eval("var t1 = document." + Field.form + "." + Field.name + "From;"); eval("var t2 = document." + Field.form + "." + Field.name + "To;"); if( ( IsInputFilled(t1) & !IsInputFilled(t2)) || ( IsInputFilled(t2) & !IsInputFilled(t1)) ) { eval("document.getElementById('vld"+Field.name+"').innerHTML = 'Specify Start as well as End values';"); t1.focus(); ValidationError = true; } else { eval("document.getElementById('vld"+Field.name+"').innerHTML = '';"); } } } return !ValidationError; } function MandatoryValid(Field){ var MValidationError = false; fieldtype = Field.type.toLowerCase(); fieldname = Field.name; if(fieldtype == "text" || fieldtype == "password" || fieldtype == "hidden" || fieldtype == "textarea") { if(!IsInputFilled(Field)) { eval("document.getElementById('vld"+fieldname+"').innerHTML = 'Mandatory field';"); Field.focus(); MValidationError = true; } else { eval("document.getElementById('vld"+fieldname+"').innerHTML = '';"); } } else if(fieldtype == "checkbox") { if(!IsCheckBoxFilled(Field)) { eval("document.getElementById('vld"+fieldname+"').innerHTML = 'Mandatory field';"); Field.focus(); MValidationError = true; } else { eval("document.getElementById('vld"+fieldname+"').innerHTML = '';"); } } else if(fieldtype == "radio") { if(!IsRadioFilled(Field)) { eval("document.getElementById('vld"+fieldname+"').innerHTML = 'Mandatory field';"); Field.focus(); MValidationError = true; } else { eval("document.getElementById('vld"+fieldname+"').innerHTML = '';"); } } else if(fieldtype.indexOf("select")!=-1) { if(!IsSelectFilled(Field)) { eval("document.getElementById('vld"+fieldname+"').innerHTML = 'Mandatory field';"); Field.focus(); MValidationError = true; } else { eval("document.getElementById('vld"+fieldname+"').innerHTML = '';"); } } else { alert(fieldname + " is a Mandatory field."); Field.focus(); MValidationError = true; } if(MValidationError) { return false; } return true; } function FlashStatus(StatusElementId, StatusMessage) { if(StatusMessage.substring(0, 10) != '@@@TRUE@@@') { alert('Error Occurred.'); } var RegExp=/\@\@\@\TRUE\@\@\@/; var StatusMessage = StatusMessage.replace(RegExp, ""); if(document.getElementById(StatusElementId)) { document.getElementById(StatusElementId).innerHTML = unescape(StatusMessage); setTimeout("document.getElementById('"+StatusElementId+"').innerHTML=' ';", 3000); } } function OpenAddMoreMasters(ThePage) { var AddPageWin; AddPageWin=open(ThePage, "AddPageWin"); // setTimeout("AddPageWin.focus();", 500); } function OpenRefreshMasters(EntireURL) { var RefreshPageWin; RefreshPageWin=open(EntireURL, "RefreshPageWin", "width=100,height=100,toolbars=no,scrollbars=no"); // setTimeout("RefreshPageWin.focus();", 500); } function ShowViewOne(URL) { var ViewOneWin; ViewOneWin=open(URL, "ViewOneWin", "width=350,height=300,toolbars=no,scrollbars=yes,resizable=yes"); // setTimeout("ViewOneWin.focus();", 500); } function RefineSearch(SearchPage) { if(objForm) { objForm.action=SearchPage; objForm.submit(); } } function AddMore(AddPage) { if(objForm) { objForm.action=AddPage; objForm.submit(); } }