var LoadHandler = {
  handlers:[],
  add:function(fn){
    if(window.onload!=LoadHandler.theHandler) LoadHandler._push(window.onload);
    LoadHandler._push(fn);
    window.onload=LoadHandler.theHandler;
  },
  _push:function(fn){
    if(typeof(fn)!='function') return;
    LoadHandler.handlers[LoadHandler.handlers.length]=fn;
  },
  theHandler:function(){
    var handlers=LoadHandler.handlers,i=-1,fn;
    while(fn=handlers[++i]) fn();
  }
}

function changeValueType(
  el, // a reference to the input element
  iValue, // the default value, set to 'password' in the demo
  blankValue, // true if the value should be empty, false otherwise
  noFocus) {  // set to true if the element should not be given focus

  el.onfocus=function(){return function(){
    if(this.hasFocus) return;
    if(el) el.hasFocus=true;
	el.value = ""
  }}();
  el.onblur=function(){return function(){
    if(this.hasFocus)
    if(this.value=='' || (this.value.toLowerCase()==iValue.toLowerCase())) {
      changeValueType(this,iValue,false,true);
    }
  }}();
 // hasFocus is to prevent a loop where onfocus is triggered over and over again
  el.hasFocus=false;
  // some browsers need the value set before the element is added to the page
  // while others need it set after
  if(!blankValue) el.value=iValue;

  if(!noFocus || typeof(noFocus)=='undefined') {
    window.tempElm=el;
    setTimeout("tempElm.hasFocus=true;tempElm.focus();",1);
  }
  return el;
}

LoadHandler.add(function(){
  // Normally I use object detection, however, in this case since I need to 
  // detect Konqueror and Safari which don't have unique objects,
  // I will use the user agent string to detect them. Only use this type of 
  // detection as a last resort.
  // I'm doing this because example 2 crashes Konqueror 3.4 and Safari 1.0

  var ua=navigator.userAgent.toLowerCase();
  if(!((ua.indexOf('konqueror')!=-1) && /khtml\/3\.[0-4]/.test(ua)) && 
    !(((ua.indexOf('safari')!=-1) && !window.print))) {

      // Set the third value to the text you want to appear in the field.
	  
	  changeValueType(document.contato.nome,'nome',false,true);
	  changeValueType(document.contato.empresa,'empresa',false,true);
	  changeValueType(document.contato.email,'e-mail',false,true);
	  changeValueType(document.contato.cidade,'cidade',false,true);
	  changeValueType(document.contato.estado,'uf',false,true);
	  changeValueType(document.contato.ddd,'ddd',false,true);
	  changeValueType(document.contato.telefone,'telefone',false,true);
	  changeValueType(document.contato.mensagem,'mensagem',false,true);
	  
	  changeValueType(document.indique_form.nome,'nome',false,true);
	  changeValueType(document.indique_form.email,'e-mail',false,true);
	  changeValueType(document.indique_form.nome_amigo,'nome',false,true);
	  changeValueType(document.indique_form.email_envia,'e-mail',false,true);
	  changeValueType(document.indique_form.mensagem,'mensagem',false,true);
  }
});





