function clearBox(input) { if(input.value==input.defaultValue) { input.value = ''; } } function resetBox(input) { if(!input.value) { input.value = input.defaultValue; } } /* function validateField(myField, type) { var contents = get(myField).value; var errorNotification = 'e'+ myField; if(type == 'email') { // email field // validate against invalid email addresses if ((/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(contents))){ get(errorNotification).style.visibility='hidden'; } else { get(errorNotification).style.visibility='visible'; } } else if(type == 'basic') { // compulsory - at least 1 character // basic validation against empty fields which are deemed compulsory if(contents != '') { get(errorNotification).style.visibility='hidden'; } else { get(errorNotification).style.visibility='visible'; } } }*/ function empty(value) { if(value == '' || value == false || value == null || value == 0) { return true; } else { return false; } } function get(eid) { return document.getElementById(eid); } function generateInvoice(myForm) { var error = 0; var errorMessage = ''; var name = get('name').value; var email = get('email').value; var terms = get('terms').checked; var focusField = ''; if(empty(name)) { error = 1; focusField = 'name'; errorMessage += 'Please enter your name.'; } else if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))){ error = 1; focusField = 'email'; errorMessage += 'Please enter a valid email address.'; } else if(empty(terms)) { error = 1; focusField = 'terms'; errorMessage += 'You must accept the terms and conditions.'; } if(error == 1) { alert(errorMessage); //var errorIcon = 'e'+focusField; //get(errorIcon).style.visibility='visible'; // focus on error field if focus field provided get(focusField).style.backgroundColor='#FEFFE5'; get(focusField).focus(); return false; } else { //alert("here"); get(myForm).submit(); return true; } }