var BASE64ARRAY; function noback() { var i = 0; var previous_hash = window.location.hash; var x = setInterval(function () { i++; window.location.hash = "/noop/" + i; if (i === 100) { clearInterval(x); window.location.hash = previous_hash; } }, 10); } function clearFrame(iframe) { document.getElementById(iframe).src = 'about:blank'; } function isEmpty(v) { v = v.trim(); if (!v || v === "") { return true; } return false; } function clearCheckBoxes(chkBoxName, start_id) { //alert(start_id); if (chkBoxName) { var l = document.getElementsByName(chkBoxName).length; for (var i = start_id; i < (l + start_id); i++) { document.getElementById(i).checked = false; // document.getElementById(i).setAttribute("checked", false); } } } function clearCheckBoxesTillGivenID(chkBoxName, start_id, end_id) { if (chkBoxName) { for (var i = start_id; i <= end_id; i++) { document.getElementById(i).checked = false; // document.getElementById(i).setAttribute("checked", false); } } } function selectCheckBoxes(chkBoxName, start_id) { //alert(start_id); if (chkBoxName) { var l = document.getElementsByName(chkBoxName).length; for (var i = start_id; i < (l + start_id); i++) { document.getElementById(i).checked = true; //document.getElementById(i).setAttribute("checked", true); } } } /* Check if none is checked from the array of checkbox */ function is_none_checked(cb_name, start_id) { //alert("cb_name is " + cb_name + " start_id =" + start_id); var len = document.getElementsByName(cb_name).length; var last_id = start_id + len - 1; var none_checked = true; for (var i = parseInt(start_id); i <= last_id; i++) { if (document.getElementById(i).checked) { none_checked = false; break; } } if (none_checked === true) { return true; } else { return false; } } function isAllChecked(chkboxName, starting_id) { var l = document.getElementsByName(chkboxName).length; for (var i = starting_id; i < (l + starting_id); i++) { if (!document.getElementById(i).checked === true) { return false; } } return true; } // Reset and flushes the file object path function resetImage(IMG1_ID, IMG2_ID, IMG3_ID, DETAILDIV) { // alert("in reset"); if (IMG1_ID) { document.getElementById(IMG1_ID).src = ""; } if (IMG2_ID) { document.getElementById(IMG2_ID).src = ""; } if (IMG3_ID) { document.getElementById(IMG3_ID).src = ""; // Important } if (DETAILDIV) { document.getElementById(DETAILDIV).src = ""; } } /* Gets age in years months and days */ function get_age(DateID, ageTextBoxID) { /* THIS CODE GIVES THE YEAR IN ABSOLUTE FORM var dob = new Date(document.getElementById(DateID).value); var monthDiff = Date.now() - dob.getTime(); // Convert calculated difference in date format var ageDt = new Date(monthDiff); // Extract year from date var year = ageDt.getUTCFullYear()-1970; // Now calculate the age in year var age = Math.abs(year); */ var now = new Date(); // var today = new Date(now.getYear(), now.getMonth(), now.getDate()); var yearNow = now.getYear(); var monthNow = now.getMonth(); var dateNow = now.getDate(); var dob = new Date(document.getElementById(DateID).value); // In the case of yyyy-mm-dd format to extract // dob = new Date(dob.substring(6, 10), // dob.substring(0, 2) - 1, // dob.substring(3, 5) // ); var yearDob = dob.getYear(); var monthDob = dob.getMonth(); var dateDob = dob.getDate(); var age = {}; var yearAge = yearNow - yearDob; if (monthNow >= monthDob) var monthAge = monthNow - monthDob; else { yearAge--; var monthAge = 12 + monthNow - monthDob; } if (dateNow >= dateDob) var dateAge = dateNow - dateDob; else { monthAge--; var dateAge = 31 + dateNow - dateDob; if (monthAge < 0) { monthAge = 11; yearAge--; } } age = { years: yearAge, months: monthAge, days: dateAge }; document.getElementById(ageTextBoxID).value = age.years + '.' + age.months + ' yrs'; } /* Used for the purpose of getting month number as well as Quarter numerical value * for displaying purpose on fees_domain. It also returns number of Quarters as * per the value used in the jsp page */ function getMonthNumber(s) { if (!s) { return -1; } else if (s === "Jan.") { return 1; } else if (s === "Feb.") { return 2; } else if (s === "Mar.") { return 3; } else if (s === "Apr.") { return 4; } else if (s === "May") { return 5; } else if (s === "June") { return 6; } else if (s === "July") { return 7; } else if (s === "Aug.") { return 8; } else if (s === "Sept.") { return 9; } else if (s === "Oct.") { return 10; } else if (s === "Nov.") { return 11; } else if (s === "Dec.") { return 12; } else if (s === "I-Quarter") { return 13; } else if (s === "II-Quarter") { return 14; } else if (s === "III-Quarter") { return 15; } else if (s === "IV-Quarter") { return 16; } else if (s === "Yearly") { return 100; } else if (s === "NA") { return 1000; } } /* Used for the purpose of getting month names for displaying fees paid * by the student on student fees page. It also returns name of Quarters as * per the value used in the jsp page */ function getMonthName(i) { if (parseInt(i) === 0) { return ""; } else if (parseInt(i) === 1) { return "Jan."; } else if (parseInt(i) === 2) { return "Feb."; } else if (parseInt(i) === 3) { return "Mar."; } else if (parseInt(i) === 4) { return "Apr."; } else if (parseInt(i) === 5) { return "May"; } else if (parseInt(i) === 6) { return "June"; } else if (parseInt(i) === 7) { return "July"; } else if (parseInt(i) === 8) { return "Aug."; } else if (parseInt(i) === 9) { return "Sept."; } else if (parseInt(i) === 10) { return "Oct."; } else if (parseInt(i) === 11) { return "Nov."; } else if (parseInt(i) === 12) { return "Dec."; } else if (parseInt(i) === 13) { return "I-Quarter"; } else if (parseInt(i) === 14) { return "II-Quarter"; } else if (parseInt(i) === 15) { return "III-Quarter"; } else if (parseInt(i) === 16) { return "IV-Quarter"; } else if (parseInt(i) === 100) { return "Yearly"; } else if (parseInt(i) === 1000) { return "NA"; } } /* Used internally for displaying months of fees paid by the student. * Accepts array and return the string value by concatenating */ function getMonths(s) { // alert("Value of s is " + s); var months = s.split(","); // Split the array // alert(months.length); if (months.length === 1) { return getMonthName(s); } else if (months.length > 1) { var tempString = ""; for (var j = 0; j < months.length; j++) { tempString += getMonthName(months[j]) + ", "; } return tempString.substr(0, tempString.length - 2); } } /* Fill all static sections - UNUSED- CHECK */ function fillAllSections(dd_id1, dd_id2) { var dd_id_array = null; if (dd_id2 === null) { dd_id_array = [dd_id1]; // create s single element array and pass } else { dd_id_array = [dd_id1, dd_id2]; // create s single element array and pass } var SECTIONS = ["A", "B", "C", "D", "E", "F", "G", "H"]; for (var i = 0; i < dd_id_array.length; i++) { if (dd_id_array[i]) { var dd_id = dd_id_array[i]; /* Clear section select */ clearSelect(dd_id); // clear select var select = document.getElementById(dd_id); for (var j = 0; j < SECTIONS.length; j++) { var opt = SECTIONS[j]; var el = document.createElement("option"); el.textContent = opt; el.value = opt; select.appendChild(el); } } } } /* Check ITS USE */ function fillAlphabets(dd_id) { var ALPHA = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]; var select = document.getElementById(dd_id); for (var j = 0; j < ALPHA.length; j++) { var opt = ALPHA[j]; var el = document.createElement("option"); el.textContent = opt; el.value = opt; select.appendChild(el); } } function fillNumbers(dd_id) { var NUMBERS = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]; var select = document.getElementById(dd_id); for (var j = 0; j < NUMBERS.length; j++) { var opt = NUMBERS[j]; var el = document.createElement("option"); el.textContent = opt; el.value = opt; select.appendChild(el); } } // Removes items from the given select function remove_item(dd_id) { var length = document.getElementById(dd_id).length; if (length > 0) { var select = document.getElementById(dd_id); select.remove(select.selectedIndex); } } // Transfer selected item from the source select to target select drop down function transfer_item(sourcedd, targetdd) { var sub_name = document.getElementById(sourcedd).value; var select = document.getElementById(targetdd); var found = false; // FILL THE DROP DOWN LIST COMBO if (sub_name !== "") { // Check for duplicate values var len = document.getElementById(targetdd).length; var check_value = null; for (var i = 0; i < len; i++) { check_value = document.getElementById(targetdd).options[i].value; if (check_value === sub_name) { alert("Duplicate item! Please check!"); document.getElementById(sourcedd).focus(); found = true; break; } } if (found === false) { { var el = document.createElement("option"); el.textContent = sub_name; el.value = sub_name; select.appendChild(el); } } } else { alert("Please select item to assign"); document.getElementById(sourcedd).focus(); return true; } } /* Select all items in drop down list to pass onto the servlet */ function select_all(dd_id) { var options = document.getElementById(dd_id).options; var len = options.length; while (len--) { options[len].selected = true; } } // CHECKS IF DROP DOWN LIST IS EMPTY function is_empty(dd_id) { var options = document.getElementById(dd_id).options; if (options.length < 1) { return true; } else { return false; } } // CHECKS IF GIVEN ELEMENT IS EMPTY function is_blank(id) { //alert(id); var x = document.getElementById(id).value; // alert(x); if (x.trim() === "" || x === null) { alert("Blank Inputs! Please check"); document.getElementById(id).focus(); return true; } else { return false; } } /* Converts the entire value to uppercase when the key is released */ function formatUpperCase(id, v) { document.getElementById(id).value = v.toUpperCase(); } function formatLowerCase(id, v) { document.getElementById(id).value = v.toLowerCase(); } function allowEmailOnly(e) { var k; // alert(e.keyCode); document.all ? k = e.keyCode : k = e.which; return((k > 44 && k < 47) || (k >= 48 && k <= 57) || (k > 63 && k < 91) || (k > 94 && k < 123)); } /* Blocks special characters , but allows space comma ,- and _ */ function blockSpecialCharacter(e) { var k; //alert(e.keyCode); document.all ? k = e.keyCode : k = e.which; return((k > 64 && k < 91) || (k > 94 && k < 123) || k === 32 || (k > 43 && k <= 45) || (k >= 48 && k <= 57)); } /* Blocks special characters , but allows space comma ,- and _ */ function allowMessageOnly(e, textAreaID) { var k; // alert(document.getElementById(textAreaID).value); // alert(String.fromCharCode(e.keycode)); document.all ? k = e.keyCode : k = e.which; /* Do not accept enter key but append new line to the value */ if (k === 13) { // alert(String.fromCharCode(e.keyCode)); document.getElementById(textAreaID).value += String.fromCharCode(e.keyCode); } return ((k > 64 && k < 91) || (k > 94 && k < 123) || k === 32 || (k > 43 && k <= 46) || (k >= 48 && k <= 57)); } /* Allows 0 to 9, - and , */ function allowMobileNo(e) { // alert(e.keyCode); var k; document.all ? k = e.keyCode : k = e.which; return((k > 47 && k < 58)); } /* Check file size and type of each file */ function validateFile(FILE_ID, SIZE_IN_KB, FILE_EXTNS) { var fileID = document.getElementById(FILE_ID); var userExtensions = FILE_EXTNS.split(","); var extOk = false; if (fileID.files.length > 0) { for (var i = 0; i < fileID.files.length; i++) { var file = fileID.files[i]; var ext = file.name.split("."); ext = ext[ext.length - 1]; //alert("File size = "+ file.size); if ((file.size / 1024) > SIZE_IN_KB) { alert("File size should be upto " + SIZE_IN_KB + " KB"); fileID.value = null; return false; } for (var j = 0; j < userExtensions.length; j++) { // alert("File Extension is " + ext + " User Extension is " + userExtensions[j]); extOk = false; if (ext.toUpperCase() === userExtensions[j].toUpperCase()) { // alert("in if condition"); extOk = true; break; } } } if (!extOk) { alert("Invalid file type. Only " + FILE_EXTNS + " files are allowed"); fileID.value = null; return false; } } return true; } function validate_input(id1, id2, id3, id4) { var all_check = true; if (id1) { if ((document.getElementById(id1).value).trim() === "" || document.getElementById(id1).value === null) { document.getElementById(id1).focus(); all_check = false; } } if (id2) { if ((document.getElementById(id2).value).trim() === "" || document.getElementById(id2).value === null) { document.getElementById(id2).focus(); all_check = false; } } if (id3) { if ((document.getElementById(id3).value).trim() === "" || document.getElementById(id3).value === null) { document.getElementById(id3).focus(); all_check = false; } } if (id4) { if ((document.getElementById(id4).value).trim() === "" || document.getElementById(id4).value === null) { document.getElementById(id4).focus(); all_check = false; } } if (all_check === true) { return true; } else { alert("Invalid Inputs!"); return false; } } /**************************************************************************** * Function that accepts file class as well as image class, read the file and * displayt the selected iomage file in the given image control * @param FILE_CLASS - class of the file input * @param IMG_CLASS - class of the img * **************************************************************************/ function previewFile(FILE_CLASS, IMG_CLASS) { var preview = document.querySelector(IMG_CLASS); var file = document.querySelector(FILE_CLASS).files[0]; // when user select an image, `reader.readAsDataURL(file)` will be triggered // reader instance will hold the result (base64) data // next, event listener will be triggered and we call `reader.result` to get // the base64 data and replace it with the image tag src attribute if (file) { var reader = new FileReader(); reader.addEventListener("load", function () { preview.src = reader.result; }, false); reader.readAsDataURL(file); } } /* This function is called from uploadDocuments.jsp onchange() event of * file input button. Single or multiple files can be selected and * passed in the file input along with the flag 'A'. * * Files are extracted from the file control and each file is passed to * readAndPreview() method to check for the given file extensions and append * to the given preview division. * * @flag - 'A' when existing image files are not discarded from the preview and * the additional selected files are also appended to this division as well as * BASE64ARRAY array. If 'A' is not passed then the existing image files are * removed from the preview division as well as BASE64ARRAY array also. * ******************************************************************************/ function previewFiles(FILE_ID, SIZEINKB, PREVIEW_ID, FILE_EXTNS, FLAG) { //alert("in new preview"); var fileID = document.getElementById(FILE_ID); // alert(BASE64ARRAY.length); // If not to append then clear the previous selected files if (FLAG !== 'A') { // alert(BASE64ARRAY.length); // Flush the previous data of the array as well as division document.getElementById(PREVIEW_ID).innerHTML = ""; if (BASE64ARRAY) { for (var i = 0; i <= BASE64ARRAY.length; i++) { BASE64ARRAY.pop(); } } } if (fileID.files.length > 0) { /********************************************************************* * If file meets file size and extensions specified by the user then * append each file to the preview division * ******************************************************************/ if (validateFile(FILE_ID, SIZEINKB, FILE_EXTNS)) { for (var i = 0; i < fileID.files.length; i++) { var file = fileID.files[i]; readAndPreview(file, PREVIEW_ID); } // document.getElementById(PREVIEW_ID).hidden = false; } } else { alert("No file selected."); } } function readAndPreview(file, PREVIEW_ID) { var preview = document.getElementById(PREVIEW_ID); // Preview division id var reader = new FileReader(); reader.addEventListener("load", function () { var base64String = reader.result; var image = new Image(); // image.height = 100; image.title = file.name; image.src = this.result; preview.appendChild(image); if (BASE64ARRAY) { // alert(base64String); BASE64ARRAY.push(base64String); } document.getElementById(PREVIEW_ID).style.display = 'block'; // IN A GLOBAL STRING ARRAY, base64 String for each image an be stored }, false); reader.readAsDataURL(file); } function getFormattedCell(tr, width, bgcolor, border) { var td = document.createElement('td'); td = tr.insertCell(-1); td.style.width = width; td.style.backgroundColor = bgcolor; td.style.border = border; // td.style.backgroundColor = "white"; // td.style.border = "1px solid"; return td; } /* NOT USED FLAG = "VS" for verifying student * FLAG = 'VU' for verifying username / password * callback - CALLBACK FUNCTION that fetches the response value and returns it function verify(id_value, pwd, c_id, FLAG, callback) { // alert(id_value); // alert(pwd); id_value = id_value.trim(); pwd = pwd.trim(); var form = document.createElement("form"); form.setAttribute("action", "validateUser"); form.setAttribute("method", "POST"); form.setAttribute("enctype", "multipart/form-data"); var formData = new FormData(form); formData.append("flag", FLAG); formData.append("q1", id_value); formData.append("q2", pwd); formData.append("q3", c_id); var percent = document.getElementById("percentage"); var msg = document.getElementById("message"); var msgvalue = "Verifying. Please wait.."; sendAndReceiveData('POST', form, 'uploadingDiv', 'messageDiv', percent, msg, msgvalue, formData, false, false, null, function (responseRecord) { var success = false; if (responseRecord.toString() !== "") { if (responseRecord.KEY === id_value) { success = true; } else { alert("Invalid Reg. No / password. Retry!"); success = false; } } else { success = false; } document.getElementById('uploadingDiv').style.display = "none"; // SPECIAL CALL BACK CODE if (callback) callback(success); }); } */ /* Compare tow dates and return true if d1 is less than or equal to d2 date value */ function isD1LessThanD2(D1, D2) { var startDate = new Date(document.getElementById(D1).value); var endDate = new Date(document.getElementById(D2).value); // alert(startDate); // alert(endDate); if (startDate && endDate) { if (startDate.getTime() < endDate.getTime()) { return true; } else { return false; } } return true; } /* Build comma seperated ids - for id's that starts from anywhere */ function getSelectedIds(target_checkbox_name, start_id) { var L = document.getElementsByName(target_checkbox_name).length; var ids = ""; var selected_ids = 0; for (var i = start_id; i < (parseInt(L) + parseInt(start_id)); i++) { // alert(document.getElementById(parseInt(i)).checked); if (document.getElementById(parseInt(i)).checked) { //arr.push(document.getElementById(i).value); ids += document.getElementById(i).value + ","; selected_ids++; } } if (selected_ids > 0) { if (!confirm(selected_ids + " candidates selected. Kindly Confirm.")) { return ""; } ids = ids.substring(0, ids.length - 1); return ids; } else { alert("Selection empty. Kindly check"); return ""; } } // only for those id that starts from any id function getUnSelectedIds(target_checkbox_name, start_id) { var L = document.getElementsByName(target_checkbox_name).length; //alert("length is " + L); var ids = ""; var unselected_ids = 0; for (var i = start_id; i < (parseInt(L) + parseInt(start_id)); i++) { if (!document.getElementById(i).checked === true) { //arr.push(document.getElementById(i).value); ids += document.getElementById(i).value + ","; unselected_ids++; } } if (unselected_ids > 0) { if (!confirm(unselected_ids + " receipient(s) will be sent message. Kindly Confirm.")) { return ""; } ids = ids.substring(0, ids.length - 1); return ids; } else { alert("All receipient selected."); return ids; } }