/**
  * author: mark fabrizio jr.
  * date: 8.16.2005
  *
  * req:
  *   x_core.js 
  *   x_event.js - library provided @ cross-browser.com [which could be deprecated by now]
  *               this is used just for cross browser event registration, just don't feel like
  *               writing my own
  *
  * desc: 
  *   coolForms() is a function that loops through all the form elements on a page and assigns
  *   styles to onFocus and onBlur events. coolForms requires a DOM compliant browser.
  *
  *   className changes will be in addition to any classes defined prior to coolForms execution.
  *
  *   all elements will be blurred at the execution of coolForms, so if you would like to 
  *   set the focus of an element, do so after calling coolForms.
  *
  *   css definitions for styling are required. the styled classes are:
  *
  *     textFocus, textBlur, buttonFocus, buttonBlur     
  * 
  * TODO - parameterize coolForms()
  *      - allow configuration for classNames
  *        more than just adjust properties in the .js file
*/
cf_config = Object();

//-------------- set config here
cf_config["text_blur"] =              "textBlur";
cf_config["text_focus"] =             "textFocus";
cf_config["text_mouseover"] =         "textMouseover";
cf_config["text_mouseout"] =          "textBlur";

cf_config["select-one_blur"] =        "textBlur";
cf_config["select-one_focus"] =       "textFocus";
cf_config["select-one_mouseover"] =   "textMouseover";
cf_config["select-one_mouseout"] =    "textBlur";

cf_config["textarea_blur"] =          "textBlur";
cf_config["textarea_focus"] =         "textFocus";
cf_config["textarea_mouseover"] =     "textMouseover";
cf_config["textarea_mouseout"] =      "textBlur";


cf_config["password_blur"] =          "textBlur";
cf_config["password_focus"] =         "textFocus";
cf_config["password_mouseover"] =     "textMouseover";
cf_config["password_mouseout"] =      "textBlur";

cf_config["submit_blur"] =            "buttonBlur";
cf_config["submit_focus"] =           "buttonFocus";
cf_config["submit_mouseover"] =       "buttonFocus";
cf_config["submit_mouseout"] =        "buttonBlur";

cf_config["button_blur"] =            "buttonBlur";
cf_config["button_focus"] =           "buttonFocus";
cf_config["button_mouseover"] =       "buttonFocus";
cf_config["button_mouseout"] =        "buttonBlur";

cf_config["checkbox_blur"] =            "";
cf_config["checkbox_focus"] =           "";


//---------------- end config


//---------------- don't edit from here on out unless you
//---------------- know what you are doing.

function coolForms(){
  for(i=0; i<document.forms.length;i++){
    for(j=0; j<document.forms[i].elements.length; j++){
      ele = document.forms[i].elements[j];
      ele.orig_class = ele.className;
      makeItCool(ele);
      try{
        ele.focus();
      }catch(e){}
    }
  }
  window.focus();
}
function makeItCool(ele){
  xAddEventListener(ele, 'focus', cf_changeClass);
  xAddEventListener(ele, 'blur', cf_changeClass);
  xAddEventListener(ele, 'mouseover', cf_changeClass);
  xAddEventListener(ele, 'mouseout', cf_changeClass);
}
function cf_changeClass(e){
  var ev = new xEvent(e);
  ele = ev.target;
  if(ev.type == 'focus'){ ele.hasFocus=true;  }
  if(ev.type == 'blur'){  ele.hasFocus=false; }
  if((ev.type == 'mouseover' || ev.type == 'mouseout') && ele.hasFocus) return;
  ele.className=ele.orig_class+" "+cf_config[ele.type+"_"+ev.type];
}