// Currently NOT used to submit contactsFormSel (on the contacts.php pg) function confirmDelete(elem){ //elem is the element to get by id var resp = confirm("Are you sure you want to delete this record? It cannot be reversed."); if (resp === true) { //Change innerhtml of form so validations won't be performed document.getElementById(elem).onsubmit = ''; //contactsFormSel return true; } else { return false; } }//end confirmDelete /*This function will take parameters pageName - a url with a GET name portion of the name/value pair - example: machines_current.php?srch_org_id= elemName - the name of the select element that is sending its index thisVal - the value of the selected option The function will then use the elemName and thisVal to get the value of the selected index. It will then redirect the page to the pageName url with the value of the selected option as the value in the name/value pair.*/ function loadPage(pageName, elemName, thisVal){ var elem=document.getElementById(elemName); var selVal = elem.options[elem.selectedIndex].value; //document.getElementById("selClient").selectedIndex.value; var urlString = pageName.concat(selVal); location.replace(urlString); }//end loadPage /*function loadPageTest(thisVal){ I CHANGED THIS FUNCTION TO THE ONE ABOVE SO IT CAN BE CALLED BY MULTIPLE EVENTS var pg='machines_current.php?srch_org_id='; var elem=document.getElementById("selClient"); var selVal = elem.options[elem.selectedIndex].value; //document.getElementById("selClient").selectedIndex.value; var urlString = pg.concat(selVal); //alert(urlString); location.replace(urlString); }*/ /*This function will set the hidden input cur_mac to the value of the page that the user is being directed to, then it will call the ajax function pgThrough to re-populate the inputs on the equipNotesComplaints tab.*/ function chgPg(newPg, ser num){ document.getElementById("cur_mac").value = newPg; alert("hi Sallie"); //pageThrough(newPg); } /*These functions will be called by the validate function (such as validateContacts) determined by the calling page, to validate the corresponding field that is passed as a parameter. The fields will be validated by a function specific to the requirements for that field. If anything other than the acceptable options for that function are present, then the user will see an alert asking them to enter valid data. If there are no invalid entries, then the functions will return empty strings. If all of the validation functions called by the function validate[name of page]() return empty strings, then the form will be submitted and handled by the php script. The validateEmail and validatePhone fields will be checked to validate that input was made and the, format is an acceptable format. */ /*Suitable for first, last, and middle names */ function validateAlphaHyphenQuote(field, lblName){//accepts only alphas, ', and - if(field === ""){ return ('No ' + lblName + ' was entered. \n'); }//end if else if((/[^a-z A-Z'-]/.test(field))){ return "Please enter a valid " + lblName + ". \n"; } else{//no error so return an empty string return ""; } }//end validateAlphaHyphenQuote /*Suitable for alphas with some symbols, like notes or messages */ function validateAlphaSymbols(field, lblName){//accepts only alphas, ', !, ?, and - if(field === ""){ return ('No ' + lblName + ' was entered. \n'); }//end if else if((/[^a-z A-Z'!?.-]/.test(field))){ return "Please enter a valid " + lblName + ". \n"; } else{//no error so return an empty string return ""; } }//end validateAlphaSymbols /* This validation function will validate the street field */ function validateAddress(field, lblName){//accepts only alphanumeric, ', and - if(field === ""){ return "Please enter " + lblName + ". \n"; }//end if else if((/[^0-9 a-z A-Z'-]/.test(field))){ return "Please enter a valid " + lblName + ". \n"; } else{//no error so return an empty string return ""; } }//end validateAddress /* This validation function will validate Street field only if there is something entered if this field is optional*/ function validateOptStreet(field, lblName){//accepts only alphanumeric and - if(field === ""){ return ""; }//end if else if((/[^0-9 a-z A-Z-]/.test(field))){ return "Please enter a valid " + lblName + ". \n"; } else{//no error so return an empty string return ""; } }//end validateOptStreet /* This validation function will validate field: zip */ function validateZip(field){ if(field === ""){ return "No zip code was entered. \n"; }//end if else if((/[^0-9-]{5}/.test(field))){ return "Please enter a valid zip code. \n"; } else{//no error so return an empty string return ""; }//end else }//end validateZip /* This validation function will validate field: zip4. It is ok to be empty. */ function validateZip4(field){ if(field === ""){ return ""; }//end if else if((/[^0-9-]/.test(field))){ return "Please enter a valid zip code. \n"; } else{//no error so return an empty string return ""; }//end else }//end validateZip4 /* This validation function will validate number fields. Only allowing numbers */ function validateNum(field, lblName){ if(field === ""){ return "No " + lblName + " was entered. \n"; }//end if else if((/[^0-9-]/.test(field))){ return "Please enter a valid " + lblName + ". \n"; } else{//no error so return an empty string return ""; }//end else }//end validateNum /* This validation function will validate phone numbers that have 3 components; area code, exchange, and phone. It will make sure that if any parts were entered, all parts were entered and it will verify that all inputs are numbers. */ function validatePhone(area, exch, ph, lblName){ /*If any of the components have data, then validate that ALL have data */ var msg; /*If all components have data, validate that all 3 are acceptable. */ if((area !== "") && (exch !=="") && (ph !== "")){ //if((strlen(area) == 3) && (strlen(exch) == 3) && (strlen(ph == 4))){ var valMsg = ""; valMsg = validateNum(area, lblName); valMsg += validateNum(exch, lblName); valMsg += validateNum(ph, lblName); return valMsg; } /*If all components have NO data, return an empty string */ else if((area === "") && (exch === "") && (ph === "")){ return ""; } /*If some components have data but others do not, advise user */ else{ return "All 3 parts of the " + lblName + " must be entered."; } } function validateEmail(field){ var regExPattern = /^[\w.-]+@[\w.-]+\.[a-z A-Z]{2,6}$/; if(field === ""){ return "No email address was entered. \n"; }//end if else{//field !empty so validate it if(regExPattern.test(field)!== true){ return "Please enter a valid email address. \n"; } else{//no error so return an empty string return ""; }//end else }//end else }//end validateEmail function validateCoField(field, coField){ var x = document.getElementById(field).selectedIndex; var sel = document.getElementById(field).options; var cx = document.getElementById(coField).selectedIndex; var cSel = document.getElementById(coField).options; if(((cSel[cx].text).trim() === "Client") || ((cSel[cx].text).trim() === "C")){ if(sel[x].index === 0){ return "If you are creating a client you must select an organization."; } else{//no error so return an empty string return ""; }//end else }//end if else{//no error so return an empty string return ""; }//end else }//end validateCoField /* This validation function will validate number fields. Only allowing numbers and hyphens */ function validateNumHyphen(field, lblName){ if(field === ""){ return "No " + lblName + " was entered. \n"; }//end if else if((/[^0-9-]/.test(field))){ return "Please enter a valid " + lblName + ". \n"; } else{//no error so return an empty string return ""; }//end else }//end validateNumHyphen /* This function will call all the validations required for the ContactForm on contacts.php. If all validations pass, return true so form will submit.*/ function validateContacts(formName){ //Add Validation type to arg list var fail = ""; /* Fields to Validate */ fail += (validateAlphaHyphenQuote(document.forms[formName].fName.value, 'first name')); fail += (validateAddress(document.forms[formName].lName.value, 'last name')); fail += (validateOptStreet(document.forms[formName].jobTitle.value, 'job title')); fail += (validateAddress(document.forms[formName].street.value, 'street address')); fail += (validateAddress(document.forms[formName].city.value, 'city')); fail += (validateNumHyphen(document.forms[formName].zip.value, 'zip code')); fail += (validateCoField('orgs', 'cType')); fail += (validatePhone(document.forms[formName].busPh1.value, document.forms[formName].busPh2.value, document.forms[formName].busPh3.value, 'business phone')); fail += (validatePhone(document.forms[formName].mblPh1.value, document.forms[formName].mblPh2.value, document.forms[formName].mblPh3.value, 'mobile phone')); fail += (validatePhone(document.forms[formName].fax1.value, document.forms[formName].fax2.value, document.forms[formName].fax3.value, 'fax')); /*po boxes are optional so ONLY perform validations if there is a value entered */ if((document.forms[formName].pob.value) !== ""){ fail += (validateAddress(document.forms[formName].pob.value, 'PO box')); } /*email addresses are optional so ONLY perform validations if there is a value entered */ if((document.forms[formName].eAddr.value) !== ""){ fail += (validateEmail(document.forms[formName].eAddr.value)); } /*sdUsers are optional so ONLY perform validations if there is a value entered */ if((document.forms[formName].sdUser.value) !== ""){ fail += (validateNum(document.forms[formName].sdUser.value, 'stardoc user')); } /*Notes are optional so ONLY perform validations if there is a value entered */ if((document.forms[formName].notes.value) !== ""){ fail += (validateAlphaSymbols(document.forms[formName].notes.value, 'notes')); } if(fail === ""){//if there are no errors return true so the form will submit return true; }//end if else{ alert(fail); return false; }//end else }//end validateEdits