function sanitizeInput(input){var div=document.createElement('div');div.appendChild(document.createTextNode(input));return div.innerHTML;} function validate_association(association){return(association.length>0);} function validate_association_number(association,association_number){if(association!='htsa'){return(association_number.length>0);}else{return true;}} function validate_city(city){return(city.length>0);} function validate_company_name(name){return(name.length>0);} function validate_contact_topic(topic){return(topic!=0);} function validate_contact_message(message){return(message.length>0&&message.length<=32000);} function validate_email_address(email){return(email.length>0);} function validate_first_name(name){filter=/^[-a-zA-Z'`., ]{1,45}$/;return filter.test(name);} function validate_last_name(name){filter=/^[a-zA-Z-'`., ]{1,45}$/;return filter.test(name);} function validate_occupation(occupation){return(occupation.length>0);} function validate_phone_number(phone){filter=/^[-0-9. +()]+$/;return(filter.test(phone));} function validate_product_inquiry(inquiry){return(inquiry.length>0);} function validate_state(state){return(state.length>0);} function validate_street_address(street_address){return(street_address.length>0);} function validate_user_comment(name){filter=/^[-a-zA-Z0-9?!'`., ]{1,2000}$/;return filter.test(name);} function validate_number(name){filter=/^[0-9]{1,20}$/;return filter.test(name);} function validate_zip_code(zip_code,country){if(country==239){filter=/^[-0-9]{5,10}$/;return(filter.test(zip_code));}else{return(zip_code.length>0);}};$(document).ready(function(){var form_data_has_errors;var error_line_height=16;var systems_help_data=[];var fields={first_name:{data:'',text:'First Name',validate:validate_first_name},last_name:{data:'',text:'Last Name',validate:validate_last_name},email_address:{data:'',text:'Email Address',validate:validate_email_address},company_name:{data:'',text:'Company Name'},phone_number:{data:'',text:'Phone Number'},user_comment:{data:'',text:'Comment'}};var background_height,overlay_height;if(window.matchMedia("(max-width: 479px)").matches){background_height=880;overlay_height=880;} else if(window.matchMedia("(max-width: 768px)").matches){background_height=980;overlay_height=980;} else{background_height=820;overlay_height=880;} if($('#recaptcha-placeholder').length){background_height+=120;$('#form-single').css({'height':background_height+'px'});overlay_height+=120;$('#static-display-form').css({'height':overlay_height+'px'});} $('#submit-systems-help').on('click',function(){form_data_has_errors=false;for(var field in fields){if(fields.hasOwnProperty(field)){$('#'+field+'_error').html('');}} $('#recaptcha_error').html('');var recaptcha_response=null;systems_help_data=$('#form-lighting-systems').serializeArray();var field_count=systems_help_data.length;var index=0;var height_adjustment=0;for(var field in fields){fields[field].data=systems_help_data[index++].value;fields[field].data=sanitizeInput(fields[field].data);if(fields[field].hasOwnProperty('validate')){var isValid;if(field==='zip_code'){isValid=fields[field].validate(fields[field].data,239);}else{isValid=fields[field].validate(fields[field].data);console.log(field+"is"+isValid);} if(!isValid){$('#'+field+'_error').html('Please enter a valid '+fields[field].text+'');height_adjustment+=error_line_height;form_data_has_errors=true;}}} $('#form-single').css({'height':(background_height+height_adjustment)+'px'});$('#static-display-form').css({'height':(overlay_height+height_adjustment)+'px'});if(form_data_has_errors){return;} if(indexcaptcha');}else{$('#'+error+'_error').html('Please enter a valid '+fields[error].text+'');} height_adjustment+=error_line_height;} $('#form-single').css({'height':(background_height+height_adjustment)+'px'});$('#static-display-form').css({'height':(overlay_height+height_adjustment)+'px'});return;}},error:function(){return;}});});$('#first_name').on('blur',function(){var first_name=$(this).val();if($('#first_name_error').html().length>0&&validate_first_name(first_name)){$('#static-display-form').height($('#static-display-form').height()-error_line_height);$('#form-single').height($('#form-single').height()-error_line_height);$('#first_name_error').html('');}});$('#last_name').on('blur',function(){var last_name=$(this).val();if($('#last_name_error').html().length>0&&validate_last_name(last_name)){$('#static-display-form').height($('#static-display-form').height()-error_line_height);$('#form-single').height($('#form-single').height()-error_line_height);$('#last_name_error').html('');}});$('#email_address').on('blur',function(){var email_address=$(this).val();if($('#email_address_error').html().length>0&&validate_email_address(email_address)){$('#static-display-form').height($('#static-display-form').height()-error_line_height);$('#form-single').height($('#form-single').height()-error_line_height);$('#email_address_error').html('');}});$('#phone_number').on('blur',function(){var phone_number=$(this).val();if($('#phone_number_error').html().length>0&&validate_phone_number(phone_number)){$('#static-display-form').height($('#static-display-form').height()-error_line_height);$('#form-single').height($('#form-single').height()-error_line_height);$('#phone_number_error').html('');}});$('body').on('keydown','#breadcrumb-home-link',function(event){var key=event.which;if(key==9){$('#first_name').focus();return false;}}).on('keydown','#first_name',function(event){var key=event.which;if(key==9&&event.shiftKey){$('#submit-systems-help').focus();return false;}}).on('keydown','#submit-systems-help',function(event){var key=event.which;if(key==9&&!event.shiftKey){$('#first_name').focus();return false;}});});