var cPREFIX_CLASS= 'bsubs_', cPREFIX_APP= 'rrb_';

function dt_buttons() { var a= new Array(), i;
  a= new Array('nw', 'ne', 'sw', 's', 'se');
  $('.'+cPREFIX_CLASS+'button_1').each(
      function(idx, item) {
        for ( i= 0; i< a.length; i++ )
          $(this).append( ( a[i]== 's'?'<div class="'
            +cPREFIX_CLASS+a[i] +'" />'
            :'<img alt="" class="'+cPREFIX_CLASS+a[i]
            +'" src="'+cPREFIX_APP+'media/trim/trim_button_'
            +a[i]+'.gif" />' ));
      }
    );
}

/******************************************************************************
* 20100622 psbrogna create DOM TARGET attributes from document REL attributes *
* ref: http://articles.sitepoint.com/article/standards-compliant-world        *
******************************************************************************/
function dt_externalLinks() { var a, h, i, j, L, p, s0, s1;
  if ( document.getElementsByTagName ) { a= document.getElementsByTagName('a');
    p= document.forms[0].elements['basePath'].value;
    L= window.location.pathname.split('?')[0].toLowerCase();
    for ( i= 0; i< a.length; i++ )
      with ( a[i] ) 
        if ( getAttribute('href') ) { h= getAttribute('href'); 
          switch ( getAttribute('rel') ) {
            case 'external': setAttribute('target', '_blank'); break;
            case 'internal':
              if ( p+h.toLowerCase()== L ) 
                setAttribute('class', (( getAttribute('class')
                ?getAttribute('class'):'' )+' bsubs_selected')
                .replace(/^ +/,''));
              s0= getAttribute('href');
              s1= '?C='+document.forms[0].elements['CID'].value;
              j= s0.indexOf('#');
              if ( j== -1 ) s0= s0+s1;
              else s0= s0.substr(0, j)+s1+s0.substr(j);
              setAttribute('href', s0); break;
            }
          }
  }
}

function dt_loaders() { $('div.'+cPREFIX_CLASS+'loader').each( function(idx, item) { $('#'+$(this).id.replace('_loaderSource_', '_')).html($(this).html()); }); }

function dt_expanders() {
  $('.'+cPREFIX_CLASS+'expander').each( function(idx, item) { $(this).click( function() { $('#'+this.id+'_target').fadeIn(500); } ); } );
  $('.'+cPREFIX_CLASS+'expander_closer').each( function(idx, item) { 
    $(this).click( function() { $(this).parentsUntil('.'+cPREFIX_CLASS+'expander_target').parent().fadeOut(250); } )
  } );
}

function dt_balancedColumns() { var i, n, x, t;
  $('.'+cPREFIX_CLASS+'balancedColumns').each( function( pIndex ) { with ( $(this) ) {
    t= get(0).nodeName; n= attr('id').substr(1+attr('id').lastIndexOf('_')); x= Math.round(0.5+children().length/n);
    for ( i= 0; i<  n; i++ ) children(t+':lt('+x+')').wrapAll('<td class="'+cPREFIX_CLASS+'balancedColumn '+cPREFIX_CLASS+(i+1)+'">');
    children().wrapAll('<table>').wrapAll('<tr>'); } } );
}

function dom_transformations() { dt_balancedColumns(); dt_buttons(); dt_loaders(); dt_expanders(); dt_externalLinks(); }

function form_validation() { $("#myform").validator(); }

function myOnload() { dom_transformations(); form_validation(); }

$(document).ready( function() { myOnload(); } );


