var infoOptions = new Array('ctl00_Content_emailresponse','ctl00_Content_psysical','ctl00_Content_personal', 'ctl00_Content_other'); var formFields = new Array('ctl00_Content_name','ctl00_Content_email','ctl00_Content_company','ctl00_Content_country', 'ctl00_Content_phonenumber', 'ctl00_Content_address', 'ctl00_Content_comment'); var contactRequirements = new Array('1111000','1011010','1011100','1111000'); var requiredInfo = new Array(formFields.length); //For collecting sum of requirements function setRequired() { var i, j, required, reqarr, f, html; //Reset requirements for (i = 0; i <= requiredInfo.length - 1; i++) { requiredInfo[i] = '0'; } //Collect requirements for (i = 0; i <= infoOptions.length - 1; i++) { if (document.getElementById(infoOptions[i]).checked) { //We only go through the checked items required = contactRequirements[i]; reqarr = required.split(""); for (j = 0; j <= reqarr.length - 1; j++) { //Here we add requirements (logic is 0&1=1, 1&1=1) if (reqarr[j] == '1') { requiredInfo[j] = '1'; } } } } //Mark requirements for (i = 0; i <= formFields.length - 1; i++) { //For each of the field texts... f = document.getElementById(formFields[i] + 'text'); html = f.innerHTML; if (requiredInfo[i] == '1') { f.innerHTML = html.split('*')[0] + '*'; //Quick and dirty way of removing any tailing '*' before adding. } else { f.innerHTML = html.split('*')[0]; } } } function doSubmit() { var i, val, any, err; //First we validate any = ""; for (i = 0; i <= requiredInfo.length - 1; i++) { //Run through current info requirements if (requiredInfo[i] == '1') { any = '1'; //Mark that we indeed have some requirements if (document.getElementById(formFields[i]).value == "" || (i==3 && document.getElementById(formFields[i]).value == 'none') ) { document.getElementById(formFields[i]).focus(); alert('You are missing a required value.\nPlease enter the needed information.'); return false; } } } if (document.getElementById(formFields[1]).value != "") { err = checkEmailAddress(document.getElementById(formFields[1]).value); if (err != 0) { alert('Your email address has an incorrect format.\nPlease check for illeagal characters or incorrect format.') return false; } } if (any == "") { //No requirements were found so nothing was asked for. That is no good. alert('You have not entered any requests. Please do so.' ); return false; } return true; } function checkEmailAddress(adr) { var arr, dom, i; var illegalChars = /[\(\)\<\>\,\;\:\\\/\"\[\]]/; //That is ()<>,;:\/"[] notably not ' (single quotation mark) if (adr.match(illegalChars)) {return 1} arr = adr.split('@'); if (arr.length != 2) {return 2} //We want exactly one "@" if (1 < adr.split(' ').length) {return 3} //We want no spaces dom = arr[1].split('.'); if (dom.length < 2) {return 4} //We want at least one "." in the domain for (i = 0; i < dom.length; i++) { if (dom[i] == "") {return 5} //We want no "xx..yy", "xx." or ".xx" in the domain } if (dom[dom.length - 1].split("").length < 2) {return 6} //We want at least two chars in domain main id return 0; } setRequired();