Website Contact Form

addEvent(window, 'load', initForm); var highlight_array = new Array(); function initForm(){ initializeFocus(); var activeForm = document.getElementsByTagName('form')[0]; addEvent(activeForm, 'submit', disableSubmitButton); ifInstructs(); showRangeCounters(); } function disableSubmitButton() { document.getElementById('saveForm').disabled = true; } // for radio and checkboxes, they have to be cleared manually, so they are added to the // global array highlight_array so we dont have to loop through the dom every time. function initializeFocus(){ var fields = getElementsByClassName(document, "*", "field"); for(i = 0; i < fields.length; i++) { if(fields[i].type == 'radio' || fields[i].type == 'checkbox') { fields[i].onclick = function() {highlight(this, 4);}; fields[i].onfocus = function() {highlight(this, 4);}; } else if ( fields[i].className.match('card-details-field') ) { fields[i].addEventListener("focusin", function(){highlight(this, 4);}); } else if(fields[i].className.match('addr') || fields[i].className.match('other')) { fields[i].onfocus = function(){highlight(this, 3);}; } else { fields[i].onfocus = function(){highlight(this, 2); }; } } } function highlight(el, depth){ if(depth == 2){var fieldContainer = el.parentNode.parentNode;} if(depth == 3){var fieldContainer = el.parentNode.parentNode.parentNode;} if(depth == 4){var fieldContainer = el.parentNode.parentNode.parentNode.parentNode;} addClassName(fieldContainer, 'focused', true); var focusedFields = getElementsByClassName(document, "*", "focused"); for(i = 0; i < focusedFields.length; i++) { if(focusedFields[i] != fieldContainer){ removeClassName(focusedFields[i], 'focused'); } } } function ifInstructs(){ var container = document.getElementById('public'); if(container){ removeClassName(container,'noI'); var instructs = getElementsByClassName(document,"*","instruct"); if(instructs == ''){ addClassName(container,'noI',true); } if(container.offsetWidth <= 450){ addClassName(container,'altInstruct',true); } } } function showRangeCounters(){ counters = getElementsByClassName(document, "em", "currently"); for(i = 0; i < counters.length; i++) { counters[i].style.display = 'inline'; } } function validateRange(ColumnId, RangeType) { if(document.getElementById('rangeUsedMsg'+ColumnId)) { var field; if (document.getElementById('Field'+ColumnId)) { field = document.getElementById('Field'+ColumnId); } else if (document.getElementById('Field'+ColumnId+'_other')) { field = document.getElementById('Field'+ColumnId+'_other'); } var msg = document.getElementById('rangeUsedMsg'+ColumnId); switch(RangeType) { case 'character': msg.innerHTML = field.value.length; break; case 'word': var val = field.value; val = val.replace(/\n/g, " "); var words = val.split(" "); var used = 0; for(i =0; i < words.length; i++) { if(words[i].replace(/\s+$/,"") != "") used++; } msg.innerHTML = used; break; case 'digit': msg.innerHTML = field.value.length; break; } } } function handleRadioOther(id, last) { var label = document.getElementById(id+'_otherlabel'); if (label) { if (last) { label.style.display = 'block'; } else { label.style.display = 'none'; } } } /*--------------------------------------------------------------------------*/ //http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/ function getElementsByClassName(oElm, strTagName, strClassName){ var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName); var arrReturnElements = new Array(); strClassName = strClassName.replace(/\-/g, "\\-"); var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)"); var oElement; for(var i=0; i addEvent(window, 'load', initForm); var highlight_array = new Array(); function initForm(){ initializeFocus(); var activeForm = document.getElementsByTagName('form')[0]; addEvent(activeForm, 'submit', disableSubmitButton); ifInstructs(); showRangeCounters(); } function disableSubmitButton() { document.getElementById('saveForm').disabled = true; } // for radio and checkboxes, they have to be cleared manually, so they are added to the // global array highlight_array so we dont have to loop through the dom every time. function initializeFocus(){ var fields = getElementsByClassName(document, "*", "field"); for(i = 0; i < fields.length; i++) { if(fields[i].type == 'radio' || fields[i].type == 'checkbox') { fields[i].onclick = function() {highlight(this, 4);}; fields[i].onfocus = function() {highlight(this, 4);}; } else if ( fields[i].className.match('card-details-field') ) { fields[i].addEventListener("focusin", function(){highlight(this, 4);}); } else if(fields[i].className.match('addr') || fields[i].className.match('other')) { fields[i].onfocus = function(){highlight(this, 3);}; } else { fields[i].onfocus = function(){highlight(this, 2); }; } } } function highlight(el, depth){ if(depth == 2){var fieldContainer = el.parentNode.parentNode;} if(depth == 3){var fieldContainer = el.parentNode.parentNode.parentNode;} if(depth == 4){var fieldContainer = el.parentNode.parentNode.parentNode.parentNode;} addClassName(fieldContainer, 'focused', true); var focusedFields = getElementsByClassName(document, "*", "focused"); for(i = 0; i < focusedFields.length; i++) { if(focusedFields[i] != fieldContainer){ removeClassName(focusedFields[i], 'focused'); } } } function ifInstructs(){ var container = document.getElementById('public'); if(container){ removeClassName(container,'noI'); var instructs = getElementsByClassName(document,"*","instruct"); if(instructs == ''){ addClassName(container,'noI',true); } if(container.offsetWidth <= 450){ addClassName(container,'altInstruct',true); } } } function showRangeCounters(){ counters = getElementsByClassName(document, "em", "currently"); for(i = 0; i < counters.length; i++) { counters[i].style.display = 'inline'; } } function validateRange(ColumnId, RangeType) { if(document.getElementById('rangeUsedMsg'+ColumnId)) { var field; if (document.getElementById('Field'+ColumnId)) { field = document.getElementById('Field'+ColumnId); } else if (document.getElementById('Field'+ColumnId+'_other')) { field = document.getElementById('Field'+ColumnId+'_other'); } var msg = document.getElementById('rangeUsedMsg'+ColumnId); switch(RangeType) { case 'character': msg.innerHTML = field.value.length; break; case 'word': var val = field.value; val = val.replace(/\n/g, " "); var words = val.split(" "); var used = 0; for(i =0; i < words.length; i++) { if(words[i].replace(/\s+$/,"") != "") used++; } msg.innerHTML = used; break; case 'digit': msg.innerHTML = field.value.length; break; } } } function handleRadioOther(id, last) { var label = document.getElementById(id+'_otherlabel'); if (label) { if (last) { label.style.display = 'block'; } else { label.style.display = 'none'; } } } /*--------------------------------------------------------------------------*/ //http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/ function getElementsByClassName(oElm, strTagName, strClassName){ var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName); var arrReturnElements = new Array(); strClassName = strClassName.replace(/\-/g, "\\-"); var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)"); var oElement; for(var i=0; i