// ---------------------------------------------------------------------
// Just Computers Contact Form/Make an Order Form
// ---------------------------------------------------------------------

function prettyForms(formid, reqFields) {
  if ( document.getElementById ) {
    document.forms[formId].onsubmit = function() { return validateForm(reqFields); }
    var labels = document.forms[formid].getElementsByTagName("label");
    for ( i = 0; i < labels.length; i++ ) {
      if ( labels[i].htmlFor != '' ) {
        formInput = document.getElementById(labels[i].htmlFor);
        formInput.label = labels[i];
        formInput.onfocus = function() { textFocus(this); }
        formInput.onblur = function() { textBlur(this); }
      } else return false;
      if ( formInput.type != 'checkbox' && formInput.type != 'radio' ) {
        try {
          labels[i].currentStyle.display = "none";
        } catch(e) {
          labels[i].style.display = "none";
        }
        if(formInput.value == '') {
          formInput.value = labels[i].innerHTML;
        }
      } else return false;
    }
  } else {
    return false;
  }
}

function textFocus(input) {
  if ( input.value == input.label.innerHTML ) {
    input.value = '';
  } else {
    return false;
  }
}

function textBlur(input) {
  if ( input.value == '' ) {
    input.value = input.label.innerHTML;
  } else {
    return false;
  }
}

function validateForm(inputArray) {
  var x;
  for ( x in inputArray ) {
    var inputElm = document.getElementById(inputArray[x]);
    if ( (inputElm.value == inputElm.label.innerHTML) || (inputElm.value == '') ) {
      alert('Please fill out all required fields before submitting this form.');
      inputElm.focus();
      return false;
    }
  }
  return true;
}