// This is a library for verifying that certain edit boxes
// have values or not

function byID( id )
{
   return document.getElementById( id );
}

function checkRequiredFields_restoreOriginalBorderColor(ids )
{
   for ( var i = 0; i < ids.length; i++ )
   {
      var id = ids[i];
      
      var input = $('#'+id);
   
      input.css( { "border-color" : input.attr('orig-css') } );
   }
}

function checkRequiredFields_init( ids )
{
   for ( var i = 0; i < ids.length; i++ )
   {
      var id = ids[i];
      
      var input = $('#'+id);
   
      input.attr('orig-css', input.css("border-left-color") );
   }
}

function checkRequiredFields_checkInputHasVal( ids )
{
   var retval = true;
   
   for ( var i = 0; i < ids.length; i++ )
   {
      var id = ids[i];
      
      var input = $('#'+id);

      if ( !inputHasVal( id ) )
      {
         hilightInput( id );

         retval = false;
      }
   }
   
   return retval;
}

//



function trim( str )
{
   return str.replace(/^\s+|\s+$/g,"");
}

// used in verification of forms
// checks that an input element with id of 'id' has a value in it
function inputHasVal( id )
{
   var input = $('#'+id);
   var val = input.val();
   
   if ( val == null || trim(val).length == 0 )
      return false;
      
   return true;
}

function isEmpty( val )
{
   if ( val == null || trim(val).length == 0 )
      return true;
      
   return false;
}


function hilightInput(id)
{
   var input = $('#'+id);
   
   // input.attr('orig-css', input.css("border-left-color") );
   
   input.css( {border: "1px solid #b81d24"} );
      
   input.focus();
   
   $('#required-error-' + id ).fadeIn(750);
}

function asJTarget( event ) 
{
   var target;
   
   if ( !event )  
      var event = window.event;
   
   if ( event.target ) 
      target = event.target;
      
   else if ( event.srcElement ) 
      target = event.srcElement;
      
   if ( target.nodeType == 3) // defeat Safari bug
      target = target.parentNode;
      
   return $(target);      
}

function toggleAttr( qthis, toggleAttrname )
{
  if ( qthis.attr( toggleAttrname ) == 'true' )
  {
    qthis.attr( toggleAttrname, 'false' );
  }
  else
  {
    qthis.attr( toggleAttrname, 'true' );
  }
}


function bool( qthis, attrname )
{
  return qthis.attr( attrname) == 'true';
}

function setbool( qthis, attrname, val )
{
   if ( val )
      qthis.attr( attrname, 'true' );
   else
      qthis.attr( attrname, 'false' );
}

function isOldIE()
{
   var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
   var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);

   return ( jQuery.browser.msie && (ie55 || ie6) );
}


function closeIncompatibleWarning()
{
   $.post( "/a/home/disableIncompatibleWarning" );
   
   $('#incompatible').fadeOut(300);
}