
function showMessageDiv(a_node, an_id, message) {
  var the_div = document.getElementById(an_id);
  if (!the_div) {
    the_div = document.createElement("div");
    the_div.setAttribute("id", an_id);
    a_node.insertBefore(the_div, a_node.firstChild);
  }
  the_div.innerHTML = message;
}

function clearMessageDiv(a_node, an_id) {
  var the_div = document.getElementById(an_id);
  if (the_div) {
    a_node.removeChild(the_div);
  }
}


function validateForm(form) {
	var error_msg = '';
  
  function check_for(the_field, a_class, a_regex, an_error_msg) {
    if (the_field.value >= '') { /* Check that the "field" really is a field (has a value) */
      if (the_field.className.match(RegExp('\\b'+a_class+'\\b'))) { /* has the specified class */
        if (the_field.value.match(a_regex)) { /* checked fine (matches the specified regex) */
          if (the_field.className.match(/ problem$/)) { /* marked as problem on previous validation */
            the_field.className = the_field.className.replace(/ problem$/,'');
          }
        } else { /* Not fine -- register problem */
          the_field.className += ' problem';
          error_msg += '<li>&#8220;'+
            the_field.name.replace(/^[0-9a-z]_/,'').replace(/_/g,' ') + /* Strip prefixes and underscores */
            '&#8221;: '+an_error_msg+'</li>';
        }
      }
    }
  }

  var fields = form.getElementsByTagName('*');
  for (var i = 0; i < fields.length; i++) {
    /*
      Add any new checks here, including the following values:
      css class to check, regex to match against, and error message for failed matches.
    */
    check_for(fields[i], 'email', /^$|[0-9a-zA-Z\.]+@[0-9a-zA-Z\.]+\.[a-zA-Z]+/,
      'This field needs to contain a valid e-mail address.');
    check_for(fields[i], 'required', /.+/,
      'This field needs to be filled.');
  }

	if (error_msg > '') {
    showMessageDiv(form, 'error-msg',
      'Before submitting the form, please attend to the fields highlighted in red below:<ul>'+error_msg+'</ul>'
    );
    return false;
  } else {
    clearMessageDiv(form, 'error-msg');
		return true;
  }
}



function change(id) {
  inputItem=document.getElementById(id);
  identity=document.getElementById(id+'Detail');
  if(inputItem.checked){
    identity.className='style2';
  }else{
    identity.className='style1';
  }
}

function clearMailAddress(form) {
	form.Address.value = '';
	form.City.value = '';
	form.State.value = '';
	form.International_StateProvince.value = '';
	form.Country.value = '';
	form.Zipcode.value = '';
}