
var login_placeholder = function (uname, pname, pname_holder, holder_class) {
 var username = document.getElementById(uname);
 var password = document.getElementById(pname);
 var password_holder = document.getElementById(pname_holder);
 
 var p_attr = "_placeholder";
 
 // set default value
 username.value = username.getAttribute(p_attr);
 password_holder.value = password_holder.getAttribute(p_attr);
 
 // set default class
 $(username).addClass(holder_class);
 $(password_holder).addClass(holder_class);

 // check the username
 if (!username.value) {
  // set the place holder text and class
  username.value = username.getAttribute(p_attr);
 }
 
 // check the password
 if (!password.value) {
  // hide the password field
  password.style.display = 'none';
  
  // show the place holder password field
  // and the place holder text and class
  password_holder.style.display = '';
  password_holder.value = password_holder.getAttribute(p_attr);
  $(password_holder).addClass(holder_class);
 }
 
 // add the click and blur events
 $(username)
  .click(function () {
   // reset the class
   $(this).removeClass(holder_class);
   
   // if we're displaying the place holder
   // text, clear the field
   if (this.value === this.getAttribute(p_attr))
    this.value = '';
  })
  .focus(function () {
   // reset the class
   $(this).removeClass(holder_class);
   
   // if we're displaying the place holder
   // text, clear the field
   if (this.value === this.getAttribute(p_attr))
    this.value = '';
  })
  .blur(function () {
   if (!this.value) {
    // if no username, show the placeholder text
    $(this).addClass(holder_class);
    this.value = this.getAttribute(p_attr);
   }
  });
 
 $(password).blur(function () {
  // if no pass, show the place holder field
  if (!this.value) {
   password.style.display = 'none';
   password_holder.style.display = '';
   password_holder.value = password_holder.getAttribute(p_attr);
  }
 });
 
 $(password_holder)
  .click(function () {
   // when a user click on the password
   // holder field, hide it, and displace and 
   // focus on the actual password field
   password_holder.style.display = 'none';
   password.style.display = '';
   password.focus();
  })
  .focus(function () {
   // when a user click on the password
   // holder field, hide it, and displace and 
   // focus on the actual password field
   password_holder.style.display = 'none';
   password.style.display = '';
   password.focus();
  });
};





var field_placeholder = function (field, holder_class) {
 var field_node = document.getElementById(field);
 var p_attr = "_placeholder";
 
 if (!field_node)
  return false;
 
 if (field_node.nodeName.toLowerCase() === "select") {
  // set default class
  $(field_node).addClass(holder_class);
  
  // add the click and blur events
  $(field_node)
   .click(function () {
    // reset the class
    $(this).removeClass(holder_class);
   })
   .focus(function () {
    // reset the class
    $(this).removeClass(holder_class);
   });
 }
 
 else {
  // set default value
  field_node.value = field_node.getAttribute(p_attr);
  
  // set default class
  $(field_node).addClass(holder_class);
  
  // add the click and blur events
  $(field_node)
   .click(function () {
    // reset the class
    $(this).removeClass(holder_class);
    
    // if we're displaying the place holder
    // text, clear the field
    if (this.value === this.getAttribute(p_attr))
     this.value = '';
   })
   .focus(function () {
    // reset the class
    $(this).removeClass(holder_class);
    
    // if we're displaying the place holder
    // text, clear the field
    if (this.value === this.getAttribute(p_attr))
     this.value = '';
   })
   .blur(function () {
    if (!this.value) {
     // if no username, show the placeholder text
     $(this).addClass(holder_class);
     this.value = this.getAttribute(p_attr);
    }
   });
 }
};





$(function () {
 login_placeholder("username_field", "password_field", "password_holder", "placeholder_text");
 
 field_placeholder("name_field", "placeholder_text");
 field_placeholder("email_field", "placeholder_text");
 field_placeholder("website_field", "placeholder_text");
 
 field_placeholder("form_location", "placeholder_text");
 field_placeholder("phone", "placeholder_text");
 field_placeholder("promo_code", "placeholder_text");
 field_placeholder("comments", "placeholder_text");
 field_placeholder("industry", "placeholder_text");
});

