/* onError */ function handle_error() { //window.alert('HELP!!!!!! THERE\'S AN ERROR!!!!!!!!!!!!!!!!!!!'); } window.onError = handle_error; /* validate sign up forms, check for bad characters only */ function validate(f) { /* iterate through the form elements to get the name & values, validate accordingly. Do not accept hidden form variables, or variables without names */ for(a = 0; a < f.length; a++) { if(f.elements[a].name != '' && f.elements[a].type != 'hidden'){ // validate this form element //window.alert("value = " + f.elements[a].name); if(checker(f.elements[a].value, f.elements[a].name)){f.elements[a].focus();return false;} } } return true; } /* validate any form, use required variable for list of field names to check for empty values, also can parse emails */ function required(f, required) { //window.alert('required = ' + required); var pattern = /email/i; // case insensitive pattern to be tested for email labeled field required_split = required.split(','); // split the comma separated string into pieces required_array = new Array; // the array which will store the final required list /* populate the required_array with the pieces trimming out all white space */ for (i = 0; i < required_split.length; i++) { required_array[i] = required_split[i]; field_name = trim(required_array[i]); //window.alert('value = ' + required_array[i]); //window.alert('value = ' + f.elements[field_name]); /* make sure the required field has a value */ if(f.elements[field_name].value == ""){ window.alert(field_name + " is a required field.\nPlease re-enter."); f.elements[field_name].focus(); return false; } /* check if it's an email field, if so validate the email address */ if(pattern.test(field_name)){ if(parse_email(f.elements[field_name].value)){ f.elements[field_name].focus(); return false; } } } return true; } /* parse an email address & validate */ function parse_email(email) { email = trim(email); if(email.search(/^[\w\-\.]+[@][\w\-]+(?:\.[\w\-]+)+$/) == -1) // || str.search(/.+?\@([\w.-]+?\s)/) == -1) { window.alert("Please enter a valid email address"); return true; } } /* trims leading and trailing spaces from the string */ function trim(str) { return( (""+str).replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') ); } /* check for evil characters function */ function checker(str, field) { if(field != 'company_description'){ // Energy News Data hack, don't parse quotes out of the company description if(str.search(/[\\\]\[\^\"{}<>|]/) != -1){ // no quotes allowed window.alert(field + " contains a forbidden character!\nPlease remove and resubmit form.\nCharacters forbidden are: \" | <> {} ^ ][ \\"); return true; } }else{ if(str.search(/[\\\]\[\^{}<>|]/) != -1){ // quotes allowed window.alert(field + " contains a forbidden character!\nPlease remove and resubmit form.\nCharacters forbidden are: | <> {} ^ ][ \\"); return true; } } } /* Check password if 2 passwords match */ function create_password(password1, password2) { if( (password1.value != password2.value) || (password1.value.length < 6) ) { window.alert("Passwords do not match.\nIt should be at least 6 characters long."); return false; } return true; } /* specific to Energy NewsData user accounts, at least 1 contact info must be displayed */ function check_END_display(f) { //window.alert("hello"); if(!f.company_email_display.checked && !f.company_fax_display.checked && !f.company_url_display.checked && !f.company_phone_display.checked) { window.alert('At least one form of contact info must be displayed.\n(phone, email, fax, or url)'); return false; } return true; } /* specific to Energy NewsData posting a job, at least 1 contact info must be displayed */ function check_END_display_job(f) { //window.alert("hello"); if(f.job_contact_email.value=='' && f.job_contact_fax.value=='' && f.job_contact_url.value=='' && f.job_contact_phone.value=='') { window.alert('At least one form of contact info must be displayed.\n(phone, email, fax, or url)'); return false; } if(f.job_contact_email.value != "") // validate the email { if(parse_email(f.job_contact_email.value)){ f.job_contact_email.focus(); return false; } } return true; } // function that sets the default values of the 'refine your search results' search form at bottom of search_results.php function setSearchParameters(state, company_type, job_category) { //window.alert(state + " " + company_type + " " + job_category); state_element = document.getElementById('state'); for(var i=0;i