/*

  forms.js
  Copyright (c) 2007 - Formauri, S.L. - Todos los derechos reservados/All rights reserved
  <http://www.formauri.es/>

*/
/* Functions that haven't been created by Formauri will be clearly detailed */





/* NEEDS: prototype.js (v 1.4.0) */




function initializeSpecialInput_Email(inputName, layerOk, layerNoOk)
{
  $(inputName).onfocus = function(){clearSafariRadios();addClassName(this.parentNode.parentNode, "focused", true)};
  $(inputName).onblur =  function()
                      {
                        removeClassName(this.parentNode.parentNode, "focused");
                        ValidateEmail($(inputName).value, layerOk, layerNoOk)
                      };
}

function initializeSpecialInput_URL(inputName, layerOk, layerNoOk)
{
  $(inputName).onfocus = function(){clearSafariRadios();addClassName(this.parentNode.parentNode, "focused", true)};
  $(inputName).onblur =  function()
                      {
                        removeClassName(this.parentNode.parentNode, "focused");
                        ValidateURL($(inputName).value, layerOk, layerNoOk)
                      };
}







/* From <http://www.wufoo.com/> */

var highlight_array = new Array();

// for radio and checkboxes, they have to be cleared manually, so they are added to the
// global array highlight_array so we dont have to loop through the dom every time.

function initializeFocus()
{
  fields = getElementsByClassName(document, "*", "field");
  for(i = 0; i < fields.length; i++)
  {
    if(fields[i].type == 'radio' || fields[i].type == 'checkbox' || fields[i].type == 'file')
    {
      fields[i].onclick = function(){clearSafariRadios(); addClassName(this.parentNode.parentNode, "focused", true)};
      fields[i].onfocus = function(){clearSafariRadios(); addClassName(this.parentNode.parentNode, "focused", true)};
      highlight_array.splice(highlight_array.length,0,fields[i]);
    }
    else
    {
      fields[i].onfocus = function(){clearSafariRadios();addClassName(this.parentNode.parentNode, "focused", true)};
      fields[i].onblur = function(){removeClassName(this.parentNode.parentNode, "focused")};
    }
  }
}


function clearSafariRadios()
{
  for(var i = 0; i < highlight_array.length; i++)
  {
    removeClassName(highlight_array[i].parentNode.parentNode, 'focused');
  }
}

function resizeSafariSelects()
{
  var detect = navigator.userAgent.toLowerCase();
  if(detect.indexOf('safari') + 1)
  {
    var container = document.getElementsByTagName('body');
    addClassName(container[0], 'safari', true)
  }
}





function ShowTooltip(id)
{
  $(id).style.display = "block";
}

function HideTooltip(id)
{
  $(id).style.display = "none";
}





