//----------------------------------------------------------------------------------------- // The following functions are used to control navigation around the system and can be used // to ensure the user has saved data to the database before they navigate away from a page // this will ensure the system is user friendly. All links within the system should be // wrapped with these function calls //----------------------------------------------------------------------------------------- // Initialise the site wide data changed flag, this will be used by screen to warn the user // where they attempt to navigate to a URL when changes to a page have been made var data_changed = false; // This function will be used site wide linked to the change event on all edit controls this // will set the data changed flag which will then be used in navigation checks function changes() { data_changed = true; } // This common function is used site wide to goto to a URL with or without params this will check // the data changed flag and get the user to confirm the navigation before moving off the page. function goto_url(url) { if (check_navigate()) { //We need to check to see if we are in an IFRAME if this is the case we need to set the //document location property for the parent document and not the IFRAME document window.parent.document.location.href = url; data_changed = false; } } // This function is used to allow the user to navigate through pages of a datagrid within the system // this will ensure the status of the page is captured which will allow us to update the status // of the check boxes as the user navigated through the pages. Javascript cookies are used to pass // this information to PHP, PHP is then responsible for setting the initial status of the controls function datagrid_goto_url(url) { window.parent.document.location.href = url; data_changed = false; } // This function is used site wide to check the state of the data changed flag where the user has // changed anything they will need to confirm the changes. function check_navigate() { //Check the data flag if (data_changed == true) { // Something has changed get the user to confirm the changes if (confirm('Are you sure you want to navigate away from the current page? if you click OK you will loose the changes you have made')) return true; else return false; } else return true; } //----------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------- // The following core functions are are low level checks used within the form validation // code within the system, this is part of the system level HTML helper classes //----------------------------------------------------------------------------------------- // This function will create a trim function on the string class which we can // use to ensure the customer has provided data in a relevant field String.prototype.trim = function() { return this.replace(/^\s*|\s*$/g, "") } // This function will do a numeric check on each char that is input, as its inputted // If it finds a none numeric char it strips it straight away, ((e) is event) // this will also validate to ensure the value is a valid integer function keyPress_float(e, control, decimals) { // Get hold of the key press event var key = (window.event) ? event.keyCode : e.which; if (window.event) key = event.keyCode else key = e.which // backspace (8) if (key == 8 || key == 0) return; // returns for form submission if (key == 10 || key == 13) return; // if dot (46) we need to check there is only one var decimal_pos = control.value.indexOf("."); if (key == 46 && decimal_pos == -1) return; // We need to enforce the decimals if (decimal_pos > -1) { var decimal_counter = control.value.length - decimal_pos - 1; if (decimal_counter < decimals) { if (key > 47 && key < 58) return; } } else { // Was key that was pressed a numeric character (0-9) or backspace (8) if (key > 47 && key < 58) return; // if so, do nothing else // otherwise, discard character } // Squash the keypress under IE and firefox if (window.event) window.event.returnValue = null; else e.preventDefault(); } // This function will do a numeric check on each char that is input, as its inputted // If it finds a none numeric char it strips it straight away, ((e) is event) // this will also validate to ensure the value is a valid integer function keyPress_integer(e, control) { // Get hold of the key press event var key = (window.event) ? event.keyCode : e.which; if (window.event) key = event.keyCode else key = e.which // returns for form submission if (key == 10 || key == 13) return; // Was key that was pressed a numeric character (0-9) or backspace (8) if ( key > 47 && key < 58 || key == 8 || key == 0) return; // if so, do nothing else // otherwise, discard character // Squash the keypress under IE and firefox if (window.event) window.event.returnValue = null; else e.preventDefault(); } function keyPress_sem_path(e, control) { // Get hold of the key press event var key = (window.event) ? event.keyCode : e.which; if (window.event) key = event.keyCode else key = e.which // returns for form submission if (key == 10 || key == 13) return; // Was key that was pressed a numeric character (0-9) or backspace (8) if (key > 47 && key < 58 || key == 8 || key == 0) return; // if so, do nothing // Lowercase a-z and uppercase A-Z if (key >= 65 && key <= 90 || key >= 97 && key <= 122) return; // if so, do nothing // Sepcial keyword characters underscore (95) or forward slash (47) if (key == 95 || key == 47) return; // if so, do nothing // Squash the keypress under IE and firefox if (window.event) window.event.returnValue = null; else e.preventDefault(); } function keyPress_sem_keyword(e, control) { // Get hold of the key press event var key = (window.event) ? event.keyCode : e.which; if (window.event) key = event.keyCode else key = e.which // returns for form submission if (key == 10 || key == 13) return; // Was key that was pressed a numeric character (0-9) or backspace (8) underscore (95) if (key > 47 && key < 58 || key == 8 || key == 0 || key == 95) return; // if so, do nothing // Lowercase a-z and uppercase A-Z if (key >= 65 && key <= 90 || key >= 97 && key <= 122) return; // if so, do nothing // Squash the keypress under IE and firefox if (window.event) window.event.returnValue = null; else e.preventDefault(); } // This function will check the string provided is in the correct format // This will be used by all of the validation classes used within the system function isEmail(argvalue) { if (argvalue.indexOf(" ") != -1) return false; else if (argvalue.indexOf("@") == -1) return false; else if (argvalue.indexOf("@") == 0) return false; else if (argvalue.indexOf("@") == (argvalue.length-1)) return false; arrayString = argvalue.split("@"); // var retSize = customSplit(argvalue, "@", "arrayString"); if (arrayString[1].indexOf(".") == -1) return false; else if (arrayString[1].indexOf(".") == 0) return false; else if (arrayString[1].charAt(arrayString[1].length-1) == ".") { return false; } return true; } // check for valid numeric strings function isNumeric(string_value) { var ValidChars = "0123456789"; var Char; var Result = true; if (string_value.length == 0) return false; // test strString consists of valid characters listed above for (i = 0; i < string_value.length && Result == true; i++) { Char = string_value.charAt(i); if (ValidChars.indexOf(Char) == -1) { Result = false; break; } } return Result; }