/*!
 * initialization
 * Version 1.0
 * Author MFE
 * Copyright (c) 2008 Denbel - www.denbel.nl
 */

var profileDialog = null;
var profileDialogEx = null;

var mailReg = new RegExp( /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i );

/**
 * DOMReady event
 * @param object
 * @return void
 */
YAHOO.util.Event.onDOMReady( function( e )
{
    /**
     * submits edit form
     * @param Form form
     * @return void
     */
    var submitEditForm = function( form )
    {
        var requiredFields = YAHOO.util.Dom.getElementsByClassName( 'required' );
        var warned = false;
        
        for( var i = 0; i < requiredFields.length; i++ )
        {
            switch( requiredFields[i].tagName )
            {
                case 'INPUT':
                    if( requiredFields[i].value == '' )
                    {
                        if( !warned )
                        {
                            requiredFields[i].focus();
                            YAHOO.util.Dom.get( 'error' ).innerHTML = '<span>Please fill out the required fields.</span>';
                            YAHOO.util.Dom.setStyle( 'error', 'display', '' );
                            warned = true;
                        }
                        YAHOO.util.Dom.setStyle( requiredFields[i], 'border', '1px solid #ff0000' );
                    }
                    break;
                
                case 'SELECT':
                    if( requiredFields[i].value == '' )
                    {
                        if( !warned )
                        {
                            requiredFields[i].focus();
                            YAHOO.util.Dom.get( 'error' ).innerHTML = '<span>Please fill out the required fields.</span>';
                            YAHOO.util.Dom.setStyle( 'error', 'display', '' );
                            warned = true;
                        }
                        YAHOO.util.Dom.setStyle( requiredFields[i], 'border', '1px solid #ff0000' );
                    }
                    break;
                
                default:
                    break;
            }
        }
        
        if( warned )
        {
            return;
        }
        
        YAHOO.util.Dom.setStyle( 'fEdit', 'display', 'none' );
        YAHOO.util.Dom.setStyle( 'sending', 'display', '' );
        
        YAHOO.util.Connect.setForm( YAHOO.util.Dom.get( 'fUpload' ), true );
        YAHOO.util.Connect.asyncRequest( 'post', '/proxy.php',
        {
            failure: function( o )
            {
                YAHOO.util.Dom.setStyle( 'sending', 'display', 'none' );
                YAHOO.util.Dom.setStyle( 'fEdit', 'display', '' );
                YAHOO.util.Dom.get( 'error' ).innerHTML = '<span>There was an error.</span>';
                YAHOO.util.Dom.setStyle( 'error', 'display', '' );
            },
            upload: function( o )
            {
                YAHOO.util.Dom.get( '__IMAGE__' ).value = Denbel.util.stripTags( o.responseText );
                
                var rpc = new Denbel.rpc.XmlRpcClient( '/proxy.php' );
                var msg = rpc.createMessage( 'editNomination' );
                
                try
                {
                    msg.addForm( o.argument );
                }
                catch( ex )
                {
                }
                
                rpc.callService( msg,
                {
                    success: function( res )
                    {
                        if( res.data == '' )
                        {
                            YAHOO.util.Dom.setStyle( 'sending', 'display', 'none' );
                            YAHOO.util.Dom.setStyle( 'fEdit', 'display', '' );
                            YAHOO.util.Dom.get( 'error' ).innerHTML = '<span>There was an error.</span>';
                            YAHOO.util.Dom.setStyle( 'error', 'display', '' );
                        }
                        else
                        {
                            YAHOO.util.Dom.get( 'main' ).innerHTML = res.data;
                            initAll();
                            //YAHOO.util.Dom.setStyle( 'btn_eligible', 'display', 'none' );
                        }
                    },
                    failure: function( res )
                    {
                        YAHOO.util.Dom.setStyle( 'sending', 'display', 'none' );
                        YAHOO.util.Dom.setStyle( 'fEdit', 'display', '' );
                        YAHOO.util.Dom.get( 'error' ).innerHTML = '<span>There was an error.</span>';
                        YAHOO.util.Dom.setStyle( 'error', 'display', '' );
                    },
                    argument: null
                } );
            },
            argument: form
        }, 'upload=1&key=' + Denbel.core.MD5.calc( 'fgteditform' ) );
    };
    
    /**
     * submits nominiation form
     * @param Form form
     * @return void
     */
    var submitNominationForm = function( form )
    {
        var requiredFields = YAHOO.util.Dom.getElementsByClassName( 'required' );
        var warned = false;
        
        for( var i = 0; i < requiredFields.length; i++ )
        {
            switch( requiredFields[i].tagName )
            {
                case 'INPUT':
                    if( requiredFields[i].value == '' )
                    {
                        if( !warned )
                        {
                            requiredFields[i].focus();
                            YAHOO.util.Dom.get( 'error' ).innerHTML = '<span>Please fill out the required fields.</span>';
                            YAHOO.util.Dom.setStyle( 'error', 'display', '' );
                            warned = true;
                        }
                        YAHOO.util.Dom.setStyle( requiredFields[i], 'border', '1px solid #ff0000' );
                    }
                    break;
                
                case 'SELECT':
                    if( requiredFields[i].value == '' )
                    {
                        if( !warned )
                        {
                            requiredFields[i].focus();
                            YAHOO.util.Dom.get( 'error' ).innerHTML = '<span>Please select a value.</span>';
                            YAHOO.util.Dom.setStyle( 'error', 'display', '' );
                            warned = true;
                        }
                        YAHOO.util.Dom.setStyle( requiredFields[i], 'border', '1px solid #ff0000' );
                    }
                    break;
                
                default:
                    break;
            }
        }
        
        if( warned )
        {
            return;
        }
        
        YAHOO.util.Dom.setStyle( 'fNominate', 'display', 'none' );
        YAHOO.util.Dom.setStyle( 'sending', 'display', '' );
        
        var rpc = new Denbel.rpc.XmlRpcClient( '/proxy.php' );
        var msg = rpc.createMessage( 'nominate' );
        msg.addForm( form );
        
        rpc.callService( msg,
        {
            success: function( res )
            {
                if( res.data == '' )
                {
                    YAHOO.util.Dom.setStyle( 'sending', 'display', 'none' );
                    YAHOO.util.Dom.setStyle( 'fNominate', 'display', '' );
                    YAHOO.util.Dom.get( 'error' ).innerHTML = '<span>There was an error.</span>';
                    YAHOO.util.Dom.setStyle( 'error', 'display', '' );
                }
                else
                {
                    YAHOO.util.Dom.get( 'contentbox' ).innerHTML = res.data;
                    
                    if( res.argument == '0' )
                    {
                        YAHOO.util.Dom.setStyle( 'btn_eligible', 'display', 'none' );
                    }
                    else
                    {
                        initNominationForm();
                        YAHOO.util.Dom.setStyle( 'edit-sent', 'display', '' );
                    }
                }
            },
            failure: function( res )
            {
                YAHOO.util.Dom.setStyle( 'sending', 'display', 'none' );
                YAHOO.util.Dom.setStyle( 'fNominate', 'display', '' );
                YAHOO.util.Dom.get( 'error' ).innerHTML = '<span>There was an error.</span>';
                YAHOO.util.Dom.setStyle( 'error', 'display', '' );
            },
            argument: YAHOO.util.Dom.get( 'iAnother' ).value
        } );
    };
    
    /**
     * initializes the edit form
     * @return void
     */
    var initEditForm = function()
    {
        var form = YAHOO.util.Dom.get( 'fEdit' );
        
        YAHOO.util.Event.addListener( 'editSubmit', 'click', function( e, o )
        {
            YAHOO.util.Event.stopEvent( e );
            submitEditForm( o );
        }, form );
        
        YAHOO.util.Event.addListener( form, 'submit', function( e )
        {
            YAHOO.util.Event.stopEvent( e );
            submitEditForm( this );
        } );
        
        YAHOO.util.Dom.setStyle( 'i_btn_submitChin', 'cursor', 'pointer' );
        
        YAHOO.util.Event.addListener( 'btn_submitChin', 'mouseover', function( e )
        {
            YAHOO.util.Event.stopEvent( e );
            YAHOO.util.Dom.setStyle( 'i_btn_submitChin', 'background-image', 'url( "/media/img/btn_submit_rollover.gif" )' );
        } );
        
        YAHOO.util.Event.addListener( 'btn_submitChin', 'mouseout', function( e )
        {
            YAHOO.util.Event.stopEvent( e );
            YAHOO.util.Dom.setStyle( 'i_btn_submitChin', 'background-image', 'url( "/media/img/btn_submit_normal.gif" )' );
        } );
    };
    
    /**
     * initializes the nomination form
     * @return void
     */
    var initNominationForm = function()
    {
        var form = YAHOO.util.Dom.get( 'fNominate' );
        
        YAHOO.util.Event.addListener( 'submitNominate1', 'click', function( e, o )
        {
            YAHOO.util.Event.stopEvent( e );
            YAHOO.util.Dom.get( 'iAnother' ).value = '0';
            submitNominationForm( o );
        }, form );
        
        YAHOO.util.Event.addListener( 'submitNominate2', 'click', function( e, o )
        {
            YAHOO.util.Event.stopEvent( e );
            YAHOO.util.Dom.get( 'iAnother' ).value = '1';
            submitNominationForm( o );
        }, form );

        YAHOO.util.Event.addListener( form, 'submit', function( e )
        {
            YAHOO.util.Event.stopEvent( e );
            submitNominationForm( this );
        } );
        
        YAHOO.util.Dom.setStyle( 'i_btn_submitChin1', 'cursor', 'pointer' );
        YAHOO.util.Dom.setStyle( 'i_btn_submitChin2', 'cursor', 'pointer' );
        
        YAHOO.util.Event.addListener( 'btn_submitChin1', 'mouseover', function( e )
        {
            YAHOO.util.Event.stopEvent( e );
            YAHOO.util.Dom.setStyle( 'i_btn_submitChin1', 'background-image', 'url( "/media/img/btn_submit_rollover.gif" )' );
        } );
        
        YAHOO.util.Event.addListener( 'btn_submitChin1', 'mouseout', function( e )
        {
            YAHOO.util.Event.stopEvent( e );
            YAHOO.util.Dom.setStyle( 'i_btn_submitChin1', 'background-image', 'url( "/media/img/btn_submit_normal.gif" )' );
        } );
        
        YAHOO.util.Event.addListener( 'btn_submitChin2', 'mouseover', function( e )
        {
            YAHOO.util.Event.stopEvent( e );
            YAHOO.util.Dom.setStyle( 'i_btn_submitChin2', 'background-image', 'url( "/media/img/btn_submit2_rollover.gif" )' );
        } );
        
        YAHOO.util.Event.addListener( 'btn_submitChin2', 'mouseout', function( e )
        {
            YAHOO.util.Event.stopEvent( e );
            YAHOO.util.Dom.setStyle( 'i_btn_submitChin2', 'background-image', 'url( "/media/img/btn_submit2_normal.gif" )' );
        } );
    };
    
    /**
     * initializes the search form
     * @return void
     */
    var initSearchForm = function()
    {
        var form = YAHOO.util.Dom.get( 'fSearch' );
        
        YAHOO.util.Event.addListener( 'iSearch', 'click', function( e )
        {
            if( this.value.toLowerCase() == 'search...' )
            {
                this.value = '';
            }
        } );
        
        YAHOO.util.Event.addListener( 'searchSubmit', 'click', function( e, o )
        {
            YAHOO.util.Event.stopEvent( e );
            submitSearchForm( o );
        }, form );
        
        YAHOO.util.Event.addListener( form, 'submit', function( e )
        {
            YAHOO.util.Event.stopEvent( e );
            submitSearchForm( this );
        } );
    };
    
    /**
     * initializes active content
     * @return void
     */
    var initActiveContent = function()
    {
        if( !YAHOO.util.Dom.inDocument( 'frames' ) )
        {
            //throw Error( '**REMOVE** frames not in doc' );
            return;
        }
        
        if( !swfobject )
        {
            throw Error( 'Missing required component' );
            return;
        }
        
        if( swfobject.getFlashPlayerVersion().major > 0 && !YAHOO.util.Dom.hasClass( document.body, 'linux' ) )
        {
	        try
	        {
		        swfobject.embedSWF(
		            '/media/swf/frames_animation.swf',
		            'frames',
		            '900',
		            '360',
		            '7.0.0.0',
		            'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0',
		            null,
		            {
			            'quality': 'high',
			            'align': 'middle',
			            'play': 'true',
			            'loop': 'true',
			            'scale': 'showall',
			            'wmode': 'transparent',
			            'devicefont': 'false',
			            'id': 'frames_animation',
			            'bgcolor': '#ffffff',
			            'name': 'frames_animation',
			            'menu': 'false',
			            'allowFullScreen': 'false',
			            'allowScriptAccess': 'sameDomain',
			            'salign': ''
		            }
		        );
	        }
	        catch( e )
	        {
	            YAHOO.util.Dom.setStyle( 'frames', 'display', 'none' );
	        }
        }
        else
        {
            YAHOO.util.Dom.setStyle( 'frames', 'display', 'none' );
        }
    };
    
    /**
     * initializes fold boxes
     * @return void
     */
    var initFoldBoxes = function()
    {
        var foldBoxes = YAHOO.util.Dom.getElementsByClassName( 'foldlink' );
        if( foldBoxes.length == 0 )
        {
            return;
        }
        
        for( var i = 0; i < foldBoxes.length; i++ )
        {
            YAHOO.util.Event.addListener( foldBoxes[i], 'click', function( e )
            {
                YAHOO.util.Event.stopEvent( e );
                
                closeAllBoxes();
                
                YAHOO.util.Dom.setStyle( this.getAttribute( 'id' ) + '_contents', 'display', '' );
            } );
        }
    };
    
    /**
     * Unfolds all fold boxes
     * @return void
     */
    var closeAllBoxes = function()
    {
        var foldBoxes = YAHOO.util.Dom.getElementsByClassName( 'foldlink' );
        if( foldBoxes.length == 0 )
        {
            return;
        }
        
        for( var i = 0; i < foldBoxes.length; i++ )
        {
            YAHOO.util.Dom.setStyle( foldBoxes[i].getAttribute( 'id' ) + '_contents', 'display', 'none' );
        }
    };
    
    /**
     * does all initialization
     * @return void
     */
    var initAll = function()
    {
      if( YAHOO.util.Dom.inDocument( 'emailus' ) && YAHOO.util.Dom.get( 'emailus' ).getAttribute( 'href' ) == '#' )
      {
        YAHOO.util.Dom.get( 'emailus' ).setAttribute( 'href', 'mailto:sdconnect@elsevier.com' );
      }
      
      if( YAHOO.util.Dom.inDocument( 'profile_overlay' ) )
      {
        YAHOO.util.Dom.setStyle( 'profile_overlay', 'display', 'none' );
      }
      
	    if( YAHOO.util.Dom.inDocument( 'eligible_overlay' ) )
	    {
	      YAHOO.util.Dom.setStyle( 'eligible_overlay', 'visibility', 'hidden' );
	    }
	    
	    if( YAHOO.util.Dom.inDocument( 'category_overlay' ) )
	    {
        YAHOO.util.Dom.setStyle( 'category_overlay', 'visibility', 'hidden' );
	    }
      
      initVoteTabs();
	    initProfileOverlay();
	    initNominationForm();
	    initSearchForm();
	    initEditForm();
	    initAnchors();
	    initActiveContent();
	    initFoldBoxes();
	    initStages();
      initPromoteForm();
      initContactForm();
      
      addToVoteList( null );
	    
	    getNomineeList();
	    getPendingList();
      //getNomineeTable( '1' );
    };
    
    // ********************************
    Denbel.Website.init( false );
    
    initAll();
} );

function initVoteTabs()
{
  if( !YAHOO.util.Dom.inDocument( 'vote_3_overlay' ) )
  {
    return;
  }
  
  if( window.location.toString().indexOf( '?search' ) > -1 )
  {
    showLayer( 'vote_5_overlay' );
    return;
  }
  
  var tabs = [
    'vote_1_overlay',
    'vote_2_overlay',
    'vote_3_overlay',
    'vote_4_overlay'
  ];
  
  var rnd = parseInt( Math.random() * 100 );
  
  if( rnd < 25 )
  {
    showLayer( 'vote_1_overlay' );
    getNomineeTable('1');
  }
  else if( rnd > 25 && rnd < 50 )
  {
    showLayer( 'vote_2_overlay' );
    getNomineeTable('5');
  }
  else if( rnd > 50 && rnd < 74 )
  {
    showLayer( 'vote_3_overlay' );
    getNomineeTable('2');
  }
  else if( rnd > 75 )
  {
    showLayer( 'vote_4_overlay' );
    getNomineeTable('3');
  }
  else
  {
    showLayer( 'vote_1_overlay' );
    getNomineeTable('1');
  }
}

function initContactForm()
{
  if( !YAHOO.util.Dom.inDocument( 'fContact' ) )
  {
    return;
  }
  
  YAHOO.util.Event.addListener( 'sendsmall', 'click', function( e )
  { 
    YAHOO.util.Event.stopEvent( e );
    submitContact( 'fContact' );
  } );
  
  YAHOO.util.Event.addListener( 'fContact', 'submit', function( e )
  {
    YAHOO.util.Event.stopEvent( e );
    submitContact( this );
  } );
}

function submitContact( f )
{
  if( YAHOO.lang.isString( f ) )
  {
    f = YAHOO.util.Dom.get( f );
  }
  
  var i = 0;
  var ok = true;
  var required = YAHOO.util.Dom.getElementsByClassName( 'required' );
  
  for( i = 0; i < required.length; i++ )
  {
    if( required[i].value == '' )
    {
      YAHOO.util.Dom.setStyle( required[i], 'border', '1px solid #ff0000' );
      YAHOO.util.Dom.get( 'contact_error' ).innerHTML = 'Please fill out the required fields';
      ok = false;
    }
    else
    {
      YAHOO.util.Dom.setStyle( required[i], 'border', '' );
    }
  }
  
  if( !ok )
  {
    return;
  }
  
  var email = YAHOO.util.Dom.getElementsByClassName( 'email' );
  
  for( i = 0; i < email.length; i++ )
  {
    if( !mailReg.test( email[i].value ) )
    {
      YAHOO.util.Dom.setStyle( email[i], 'border', '1px solid #ff0000' );
      YAHOO.util.Dom.get( 'contact_error' ).innerHTML = 'Please enter a valid e-mail address';
      ok = false;
    }
    else
    {
      YAHOO.util.Dom.setStyle( email[i], 'border', '' );
    }
  }
  
  if( ok )
  {
    f.submit();
  }
}

function initPromoteForm()
{
  if( !YAHOO.util.Dom.inDocument( 'fPromote' ) || !YAHOO.util.Dom.getRegion( 'fPromote' ) )
  {
    return;
  }
  
  if( YAHOO.util.Dom.getStyle( 'iNominee', 'visibility' ) != 'hidden' )
  {
    YAHOO.util.Dom.get( 'iNominee' ).disabled = true;
    
    YAHOO.util.Event.addListener( 'iNominee', 'click', function( e )
    {
      YAHOO.util.Event.stopEvent( e );
      var name = this.options[this.selectedIndex].innerHTML;
      
      YAHOO.util.Dom.get( 'iText' ).value = 'I voted for ' + name + ' on the For Great Thinking website and I think you should do the same!';
    } );
    
    YAHOO.util.Event.addListener( 'iNominee', 'change', function( e )
    {
      YAHOO.util.Event.stopEvent( e );
      var name = this.options[this.selectedIndex].innerHTML;
      
      YAHOO.util.Dom.get( 'iText' ).value = 'I voted for ' + name + ' on the For Great Thinking website and I think you should do the same!';
    } );
  }
  
  YAHOO.util.Event.addListener( 'sendsmall', 'click', function( e )
  {
    YAHOO.util.Event.stopEvent( e );
    submitPromote( 'fPromote' );
  } );
  
  YAHOO.util.Event.addListener( 'sendmore', 'click', function( e )
  {
    YAHOO.util.Event.stopEvent( e );
    submitPromote( 'fPromote' );
  } );
  
  YAHOO.util.Event.addListener( 'fPromote', 'submit', function( e )
  {
    YAHOO.util.Event.stopEvent( e );
    submitPromote( this );
  } );
  
  if( YAHOO.util.Dom.getStyle( 'iNominee', 'visibility' ) != 'hidden' )
  {
    YAHOO.util.Event.addListener( 'iEmail', 'blur', function( e )
    {
      YAHOO.util.Event.stopEvent( e );
      
      if( this.value == '' )
      {
        return;
      }
      else if( !mailReg.test( this.value ) )
      {
        YAHOO.util.Dom.setStyle( this, 'border', '1px solid #ff0000' );
        return;
      }
      
      YAHOO.util.Dom.setStyle( this, 'border', '1px solid #000' );
      
      var rpc = new Denbel.rpc.XmlRpcClient( '/proxy.php' );
      var msg = rpc.createMessage( 'getVotesByEmail' );
      msg.createAndAddParameter( null, this.value );
      
      rpc.callService( msg,
      {
        success: function( res )
        {
          var el = YAHOO.util.Dom.get( res.argument );
          var i = 0;
          
          for( i = 0; i < el.options.length; i++ )
          {
            el.options[i] = null;
          }
          
          var s = res.data[0];
          
          if( s == '' )
          {
            return;
          }
          
          var items = s.split( '|@@|@@|' );
          var parts = null;
          
          for( i = 0; i < items.length; i++ )
          {
            parts = items[i].split( '|@@|' );
            el.options[i] = new Option( parts[1], parts[0] );
          }
          
          if( el.options.length > 0 )
          {
            el.disabled = false;
            
            var name = YAHOO.util.Dom.get( 'iNominee' ).options[0].innerHTML;
            YAHOO.util.Dom.get( 'iText' ).value = 'I voted for ' + name + ' on the For Great Thinking website and I think you should do the same!';
          }
        },
        failure: function( res )
        {
        },
        argument: 'iNominee'
      } );
    } );
  }
}

function submitPromote( f )
{
  if( YAHOO.lang.isString( f ) )
  {
    f = YAHOO.util.Dom.get( f );
  }
  
  var i = 0;
  var requiredFields = YAHOO.util.Dom.getElementsByClassName( 'required' );
  var ok = true;
  
  for( i = 0; i < requiredFields.length; i++ )
  {
    if( requiredFields[i].value == '' )
    {
      YAHOO.util.Dom.setStyle( requiredFields[i], 'border', '1px solid #ff0000' );
      ok = false;
    }
  }
  
  if( ok )
  {
    var emailFields = YAHOO.util.Dom.getElementsByClassName( 'email' );
    
    for( i = 0; i < emailFields.length; i++ )
    {
      if( emailFields[i].value == '' )
      {
        continue;
      }
      
      if( !mailReg.test( emailFields[i].value ) )
      {
        YAHOO.util.Dom.setStyle( emailFields[i], 'border', '1px solid #ff0000' );
        ok = false;
      }
    }
  }
  else
  {
    YAHOO.util.Dom.get( 'invite_error' ).innerHTML = 'Please enter at least one recipient.';
    return;
  }
  
  if( ok )
  {
    f.submit();
  }
  else
  {
    YAHOO.util.Dom.get( 'invite_error' ).innerHTML = 'Please enter correct e-mail addresses';
  }
}

/**
 * initializes anchors
 * @return void
 */
function initAnchors()
{
    var anchors = YAHOO.util.Dom.getElementsByClassName( 'targetBlank' );
    
    for( var i = 0; i < anchors.length; i++ )
    {
        if( anchors[i].tagName != 'A' )
        {
            continue;
        }

        anchors[i].setAttribute( 'target', '_blank' );
    }
}

function initNomineeTable()
{
  var items = YAHOO.util.Dom.getElementsByClassName( 'nominee-item' );
  
  for( var i = 0; i < items.length; i++ )
  {
    YAHOO.util.Event.addListener( items[i], 'mouseover', function( e )
    {
      YAHOO.util.Event.stopEvent( e );
      YAHOO.util.Dom.setStyle( this, 'background-image', "url('/media/img/nominee_table_select.png')" );
      YAHOO.util.Dom.setStyle( this, 'color', '#fff' );
    } );
    
    YAHOO.util.Event.addListener( items[i], 'mouseout', function( e )
    {
      YAHOO.util.Event.stopEvent( e );
      YAHOO.util.Dom.setStyle( this, 'background-image', 'none' );
      YAHOO.util.Dom.setStyle( this, 'color', '#000' );
    } );
    
    YAHOO.util.Event.addListener( items[i], 'click', function( e )
    {
      YAHOO.util.Event.stopEvent( e );
      showProfileEx( this.getAttribute( 'id' ).split( '_' )[1] );
    } );
  }
  
  if( YAHOO.env.ua.ie > 0 && YAHOO.env.ua.ie < 7 )
  {
    correctPNG();
  }
}

function initStages()
{
  var stages = YAHOO.util.Dom.getElementsByClassName( 'stage' );
  var s = [];
  
  for( var i = 0; i < stages.length; i++ )
  {
    s.push( new Denbel.ui.Stage( stages[i].getAttribute( 'id' ),
    {
      sequence: ( i + 1 )
    } ) );
  }
}

function getLoadingHtml( text, img, nomargin )
{
    if( !img )
    {
        img = 'loading2';
    }
    
    var m = '';
    
    if( !nomargin )
    {
      m = 'margin-top:20px;';
    }
    
    return '<div style="text-align:center;' + m + '"><img src="/media/img/' + img +  '.gif" alt="" /><br /><span>' + text + '</span></div>'
}

function getNomineeTable( categoryId, page )
{
  var id = null;
  
  switch( categoryId )
  {
    case '1':
    case '4':
      id = 'contentbox';
      break;
    
    case '2':
      id = 'nominee-tab3';
      break;
    
    case '3':
      id = 'nominee-tab4';
      break;
    
    case '5':
      id = 'nominee-tab2';
      break;
  }
  
  if( !YAHOO.util.Dom.inDocument( id ) || !YAHOO.util.Dom.getRegion( id ) || !YAHOO.util.Dom.hasClass( id, 'vote' ) )
  {
    return;
  }
  
  YAHOO.util.Dom.get( id ).innerHTML = getLoadingHtml( 'Loading...', 'loading4' );
  
  if( !page )
  {
    page = 1;
  }
  
  var rpc = new Denbel.rpc.XmlRpcClient( '/proxy.php' );
  var msg = rpc.createMessage( 'getNominees2' );
  msg.createAndAddParameter( 'categoryId', categoryId );
  msg.createAndAddParameter( 'page', page.toString() );
  
  rpc.callService( msg,
  {
    success: function( res )
    {
      YAHOO.util.Dom.get( res.argument.id ).innerHTML = res.data[0];
      initNomineeTable();
    },
    failure: function( res )
    {
    },
    argument:
    {
      id: id
    }
  } );
}

/**
 * initializes nominee list
 * @return void
 */
function getNomineeList( page )
{
    if( !YAHOO.util.Dom.inDocument( 'nomineelist' ) )
    {
        return;
    }
    
    YAHOO.util.Dom.get( 'nomineelist' ).innerHTML = getLoadingHtml( 'Loading...' );
    
    if( !page )
    {
        page = 1;
    }
    
    var rpc = new Denbel.rpc.XmlRpcClient( '/proxy.php' );
    var msg = rpc.createMessage( 'getNominees' );
    msg.createAndAddParameter( 'page', page.toString() );
    
    rpc.callService( msg,
    {
        success: function( res )
        {
            YAHOO.util.Dom.get( 'nomineelist' ).innerHTML = res.data;
            
            try
            {
                if( YAHOO.env.ua.ie > 0 && YAHOO.env.ua.ie < 7 )
                {
                  correctPNG();
                }
            }
            catch( ex )
            {
            }
        },
        failure: function( res )
        {
        },
        argument: null
    } );
}

/**
 * initializes pending list
 * @return void
 */
function getPendingList( page )
{
    if( !YAHOO.util.Dom.inDocument( 'pendinglist' ) )
    {
        return;
    }
    
    YAHOO.util.Dom.get( 'pendinglist' ).innerHTML = getLoadingHtml( 'Loading...' );
    
    if( !page )
    {
        page = 1;
    }
    
    var rpc = new Denbel.rpc.XmlRpcClient( '/proxy.php' );
    var msg = rpc.createMessage( 'getPendingNominees' );
    msg.createAndAddParameter( 'page', page.toString() );
    
    rpc.callService( msg,
    {
        success: function( res )
        {
            YAHOO.util.Dom.get( 'pendinglist' ).innerHTML = res.data;
            
            try
            {
              if( YAHOO.env.ua.ie > 0 && YAHOO.env.ua.ie < 7 )
              {
                correctPNG();
              }
            }
            catch( ex )
            {
            }
        },
        failure: function( res )
        {
        },
        argument: null
    } );
}

/**
 * Shows profile overlay with nominee info
 * @param int nomineeId
 * @return void
 */
function showProfile( nomineeId )
{
    if( !initProfileOverlay() )
    {
        //throw Error( 'dialog not initialized' );
        return;
    }
    
    var rpc = new Denbel.rpc.XmlRpcClient( '/proxy.php' );
    var msg = rpc.createMessage( 'getNomineeProfile' );
    msg.createAndAddParameter( 'nomineeId', nomineeId );
    
    rpc.callService( msg,
    {
        success: function( res )
        {
            YAHOO.util.Dom.get( 'profile_overlay_contents' ).innerHTML = res.data;
            YAHOO.util.Event.addListener( 'profile_overlay_close', 'click', function( e, o )
            {
                YAHOO.util.Event.stopEvent( e );
                YAHOO.util.Dom.setStyle( 'profile_overlay', 'display', 'none' );
                o.hide();
            }, profileDialog );
        },
        failure: function( res )
        {
            YAHOO.util.Dom.get( 'profile_overlay_contents' ).innerHTML = '<table style="width:400px;"><tr><td valign="top"><span><strong>Nominee info</strong></span></td><td valign="top"></td><td valign="top" style="text-align:right;"><a id="profile_overlay_close" rel="internal" href="#"><img alt="CLOSE" src="/media/img/btn_close_normal.png" /></a></td></tr><tr><td colspan="3">There was an error. Please try again.</td></tr></table>';
		    YAHOO.util.Event.addListener( 'profile_overlay_close', 'click', function( e, o )
		    {
		        YAHOO.util.Event.stopEvent( e );
		        YAHOO.util.Dom.setStyle( 'profile_overlay', 'display', 'none' );
		        o.hide();
		    }, profileDialog );
        },
        argument: null
    } );
    
    YAHOO.util.Dom.get( 'profile_overlay_contents' ).innerHTML = getLoadingHtml( 'Loading...', 'loading3' );
    YAHOO.util.Dom.setStyle( 'profile_overlay', 'display', '' );
    
    profileDialog.show();
}

function showProfileEx( nomineeId, leaderboard )
{
  if( !initProfileOverlayEx() )
  {
    return;
  }
  
  var rpc = new Denbel.rpc.XmlRpcClient( '/proxy.php' );
  var msg = rpc.createMessage( 'getNomineeProfile' );
  msg.createAndAddParameter( null, nomineeId );
  msg.createAndAddParameter( null, true );
  
  rpc.callService( msg,
  {
    success: function( res )
    {
      YAHOO.util.Dom.get( 'profile_overlay_contents2' ).innerHTML = res.data[0];
      
      YAHOO.util.Event.addListener( 'profile_overlay_close2', 'click', function( e, o )
      {
        YAHOO.util.Event.stopEvent( e );
        YAHOO.util.Dom.setStyle( 'profile_overlay2', 'display', 'none' );
        o.hide();
      }, profileDialogEx );
      
      YAHOO.util.Event.addListener( 'profile_overlay_add', 'click', function( e, o )
      {
        YAHOO.util.Event.stopEvent( e );
        addToVoteList( YAHOO.util.Dom.get( 'profile_table' ).className.split( '_' )[1] );
      }, profileDialogEx );
      
      initAnchors();
      
      if( YAHOO.env.ua.ie > 0 && YAHOO.env.ua.ie < 7 )
      {
        correctPNG();
      }
    },
    failure: function( res )
    {
      YAHOO.util.Dom.get( 'profile_overlay_contents2' ).innerHTML = '<table style="width:400px;"><tr><td valign="top"><span><strong>Nominee info</strong></span></td><td valign="top"></td><td valign="top" style="text-align:right;"><a id="profile_overlay_close2" rel="internal" href="#"><img alt="CLOSE" src="/media/img/btn_close_normal.png" /></a></td></tr><tr><td colspan="3">There was an error. Please try again.</td></tr></table>';
      YAHOO.util.Event.addListener( 'profile_overlay_close2', 'click', function( e, o )
      {
        YAHOO.util.Event.stopEvent( e );
        YAHOO.util.Dom.setStyle( 'profile_overlay2', 'display', 'none' );
        o.hide();
      }, profileDialogEx );
    },
    argument: null 
  } );
  
  if( leaderboard )
  {
    YAHOO.util.Dom.addClass( 'profile_overlay2', 'leaderboardoverlay' );
  }
  else
  {
    YAHOO.util.Dom.removeClass( 'profile_overlay2', 'leaderboardoverlay' );
  }
  
  YAHOO.util.Dom.get( 'profile_overlay_contents2' ).innerHTML = getLoadingHtml( 'Loading...', 'loading4' );
  YAHOO.util.Dom.setStyle( 'profile_overlay2', 'display', '' );
  
  YAHOO.util.Dom.setStyle( 'title_vote', 'display', 'none' );
  YAHOO.util.Dom.setStyle( 'content_vote', 'display', 'none' );
  YAHOO.util.Dom.setStyle( 'title_search', 'display', 'none' );
  YAHOO.util.Dom.setStyle( 'content_search', 'display', 'none' );
  YAHOO.util.Dom.setStyle( 'title_submit', 'display', 'none' );
  YAHOO.util.Dom.setStyle( 'content_submit', 'display', 'none' );      
  YAHOO.util.Dom.setStyle( 'title_nominees', 'display', '' );
  YAHOO.util.Dom.setStyle( 'content_nominees', 'display', '' );
  
  profileDialogEx.show();
}

function showVoteListQuestion( nomineeId, name )
{
  var id = 'vote-list-contents';
  YAHOO.util.Dom.setStyle( id, 'display', 'none' );
  YAHOO.util.Dom.setStyle( 'vote-list-question', 'display', '' );
  
  var html = YAHOO.util.Dom.get( 'vote-list-question' ).innerHTML;
  YAHOO.util.Dom.get( 'vote-list-question' ).innerHTML = html.replace( '%%name%%', name );
  
  YAHOO.util.Event.addListener( 'lNo', 'click', function( e )
  {
    YAHOO.util.Event.stopEvent( e );
    YAHOO.util.Dom.setStyle( 'vote-list-contents', 'display', '' );
    YAHOO.util.Dom.setStyle( 'vote-list-question', 'display', 'none' );
  } );
  
  YAHOO.util.Event.addListener( 'lYes', 'click', function( e, o )
  {
    YAHOO.util.Event.stopEvent( e );
    YAHOO.util.Dom.setStyle( 'vote-list-contents', 'display', '' );
    YAHOO.util.Dom.setStyle( 'vote-list-question', 'display', 'none' );    
    removeFromVoteList( o );
  }, nomineeId );
}

function removeFromVoteList( nomineeId )
{
  var id = 'vote-list-contents';
  var old = YAHOO.util.Dom.get( id ).innerHTML;
  
  YAHOO.util.Dom.get( id ).innerHTML = '<span>' + getLoadingHtml( 'Please wait...', 'loading4', true ) + '</span>';
  
  var rpc = new Denbel.rpc.XmlRpcClient( '/proxy.php' );
  var msg = rpc.createMessage( 'removeFromMyVoteList' );
  msg.createAndAddParameter( null, nomineeId );
  
  rpc.callService( msg,
  {
    success: function( res )
    {
      YAHOO.util.Dom.setStyle( 'vote-list-contents', 'display', '' );
      YAHOO.util.Dom.setStyle( 'vote-list-question', 'display', 'none' );
      
      YAHOO.util.Dom.get( res.argument.id ).innerHTML = res.data[0];
      initVoteListRemoveButtons();
    },
    failure: function( res )
    {
      YAHOO.util.Dom.get( res.argument.id ).innerHTML = res.argument.oldContent;
      YAHOO.util.Dom.get( 'profile_overlay_error2' ).innerHTML = 'ERROR: ' + res.fault.get( 'faultString' );
      YAHOO.util.Dom.setStyle( 'profile_overlay_error2', 'display', '' );
    },
    argument:
    {
      id: id,
      oldContent: old
    }
  } );
}

function initVoteListRemoveButtons()
{
  var removeButtons = YAHOO.util.Dom.getElementsByClassName( 'removebutton' );
  
  for( var i = 0; i < removeButtons.length; i++ )
  {
    YAHOO.util.Event.addListener( removeButtons[i], 'click', function( e )
    {
      YAHOO.util.Event.stopEvent( e );
      var nomId = this.getAttribute( 'id' ).split( '_' )[1];
      showVoteListQuestion( nomId, YAHOO.util.Dom.get( 'fullname_' + nomId ).innerHTML );
    } );
  }
}

function addToVoteList( nomineeId )
{
  var id = 'vote-list-contents';
  
  if( YAHOO.util.Dom.inDocument( id ) && YAHOO.util.Dom.hasClass( id, 'vote' ) )
  {
    var old = YAHOO.util.Dom.get( id ).innerHTML;
    
    YAHOO.util.Dom.setStyle( 'vote-list-form', 'display', 'none' );
    YAHOO.util.Dom.setStyle( id, 'display', '' );
    
    YAHOO.util.Dom.get( id ).innerHTML = '<span>' + getLoadingHtml( 'Please wait...', 'loading4', true ) + '</span>';
    
    YAHOO.util.Dom.setStyle( 'middlebottom', 'display', '' );
    YAHOO.util.Dom.setStyle( 'middlebottom2', 'display', 'none' );
    
    if( YAHOO.util.Dom.getStyle( 'vote_5_overlay', 'visibility' ) != 'hidden' )
    {
      YAHOO.util.Dom.setStyle( 'title_vote', 'display', 'none' );
      YAHOO.util.Dom.setStyle( 'content_vote', 'display', 'none' );
      YAHOO.util.Dom.setStyle( 'title_submit', 'display', 'none' );
      YAHOO.util.Dom.setStyle( 'content_submit', 'display', 'none' );
      YAHOO.util.Dom.setStyle( 'title_nominees', 'display', 'none' );
      YAHOO.util.Dom.setStyle( 'content_nominees', 'display', 'none' );
      YAHOO.util.Dom.setStyle( 'title_search', 'display', '' );
      YAHOO.util.Dom.setStyle( 'content_search', 'display', '' );
    }
    else
    {
      YAHOO.util.Dom.setStyle( 'title_vote', 'display', '' );
      YAHOO.util.Dom.setStyle( 'content_vote', 'display', '' );
      YAHOO.util.Dom.setStyle( 'title_nominees', 'display', 'none' );
      YAHOO.util.Dom.setStyle( 'content_nominees', 'display', 'none' );
      YAHOO.util.Dom.setStyle( 'title_submit', 'display', 'none' );
      YAHOO.util.Dom.setStyle( 'content_submit', 'display', 'none' );
      YAHOO.util.Dom.setStyle( 'title_search', 'display', 'none' );
      YAHOO.util.Dom.setStyle( 'content_search', 'display', 'none' );
    }
  }
  
  var rpc = new Denbel.rpc.XmlRpcClient( '/proxy.php' );
  var msg = rpc.createMessage( 'getMyVoteList' );
  msg.createAndAddParameter( null, nomineeId );
  
  rpc.callService( msg,
  {
    success: function( res )
    {
      if( res.data[0] == false )
      {
        YAHOO.util.Dom.get( 'profile_overlay_error2' ).innerHTML = 'You already have this person on your list.';
        YAHOO.util.Dom.setStyle( 'profile_overlay_error2', 'display', '' );
        
        if( YAHOO.util.Dom.inDocument( res.argument.id ) && YAHOO.util.Dom.hasClass( id, 'vote' ) )
        {
          YAHOO.util.Dom.get( res.argument.id ).innerHTML = res.argument.oldContent;
        }
      }
      else
      {
        if( YAHOO.util.Dom.inDocument( res.argument.id ) && YAHOO.util.Dom.hasClass( id, 'vote' ) )
        {
          YAHOO.util.Dom.get( res.argument.id ).innerHTML = res.data[0];
        }
        
        if( profileDialogEx )
        {
          profileDialogEx.hide();
        }
        
        initVoteListRemoveButtons();
      }
    },
    failure: function( res )
    {
      if( YAHOO.util.Dom.inDocument( res.argument.id ) && YAHOO.util.Dom.hasClass( id, 'vote' ) )
      {
        YAHOO.util.Dom.get( res.argument.id ).innerHTML = res.argument.oldContent;
      }
      
      YAHOO.util.Dom.get( 'profile_overlay_error2' ).innerHTML = 'ERROR: ' + res.fault.get( 'faultString' );
      YAHOO.util.Dom.setStyle( 'profile_overlay_error2', 'display', '' );
    },
    argument:
    {
      id: id,
      oldContent: old
    }
  } );
}

function showVoteForm()
{
  var id = 'vote-list-contents';
  
  YAHOO.util.Dom.setStyle( id, 'display', 'none' );
  YAHOO.util.Dom.setStyle( 'vote-list-form', 'display', '' );
  
  YAHOO.util.Dom.setStyle( 'middlebottom', 'display', 'none' );
  YAHOO.util.Dom.setStyle( 'middlebottom2', 'display', '' );
  YAHOO.util.Dom.setStyle( 'title_submit', 'display', '' );
  YAHOO.util.Dom.setStyle( 'content_submit', 'display', '' );
  YAHOO.util.Dom.setStyle( 'title_search', 'display', 'none' );
  YAHOO.util.Dom.setStyle( 'content_search', 'display', 'none' );
  YAHOO.util.Dom.setStyle( 'title_vote', 'display', 'none' );
  YAHOO.util.Dom.setStyle( 'content_vote', 'display', 'none' );

  YAHOO.util.Dom.get( 'boardofnominees' ).innerHTML = 'Please wait a moment...';

  var rpc = new Denbel.rpc.XmlRpcClient( '/proxy.php' );
  var msg = rpc.createMessage( 'getMyVoteBoard' );
  
  rpc.callService( msg,
  {
    success: function( res )
    {
      YAHOO.util.Dom.get( res.argument.target ).innerHTML = res.data[0];
    },
    failure: function( res )
    {
      YAHOO.util.Dom.get( res.argument.target ).innerHTML = 'There was an error.';
    },
    argument:
    {
      target: 'boardofnominees'
    }
  } );

  YAHOO.util.Event.addListener( 'vote-list-form', 'submit', function( e )
  {
    YAHOO.util.Event.stopEvent( e );
    submitVotes();
  } );
}

function submitVotes()
{
  var frm = YAHOO.util.Dom.get( 'fVote' );
  
  if( !frm )
  {
    return;
  }
  
  var requiredFields = YAHOO.util.Dom.getElementsByClassName( 'required' );
  var warned = false;
  
  for( var i = 0; i < requiredFields.length; i++ )
  {
    switch( requiredFields[i].tagName )
    {
      case 'INPUT':
        if( requiredFields[i].value == '' )
        {
          if( !warned )
          {
            requiredFields[i].focus();
            //YAHOO.util.Dom.get( 'error' ).innerHTML = '<span>Please fill out the required fields.</span>';
            alert( 'Please fill out the requred fields.' );
            //YAHOO.util.Dom.setStyle( 'error', 'display', '' );
            warned = true;
          } 
          YAHOO.util.Dom.setStyle( requiredFields[i], 'border', '1px solid #ff0000' );
        }
        else
        {
          if( YAHOO.util.Dom.hasClass( requiredFields[i], 'email' ) )
          {
            if( !mailReg.test( requiredFields[i].value ) )
            {
              if( !warned )
              {
                requiredFields[i].focus();
                alert( 'Please enter a valid e-mail address.' );
                warned = true;
              }
              YAHOO.util.Dom.setStyle( requiredFields[i], 'border', '1px solid #ff0000' );
            }
          }
        }
        break;
    
      case 'SELECT':
        if( requiredFields[i].value == '' )
        {
          if( !warned )
          {
            requiredFields[i].focus();
            //YAHOO.util.Dom.get( 'error' ).innerHTML = '<span>Please fill out the required fields.</span>';
            //YAHOO.util.Dom.setStyle( 'error', 'display', '' );
            alert( 'Please fill out the requred fields.' );
            warned = true;
          }
          YAHOO.util.Dom.setStyle( requiredFields[i], 'border', '1px solid #ff0000' );
        }
        break;
      
        default:
          break;
    }
  }
  
  if( warned )
  {
      return;
  }
  
  var rpc = new Denbel.rpc.XmlRpcClient( '/proxy.php' );
  var msg = rpc.createMessage( 'sendVotes' );
  msg.addForm( frm );
  
  YAHOO.util.Dom.get( 'vote-list-contents' ).innerHTML = getLoadingHtml( 'Sending...', 'loading4' );
  YAHOO.util.Dom.setStyle( 'vote-list-form', 'display', 'none' );
  YAHOO.util.Dom.setStyle( 'vote-list-contents', 'display', '' );
  
  rpc.callService( msg,
  {
    success: function( res )
    {
      YAHOO.util.Dom.setStyle( 'vote-list-form', 'display', 'none' );
      YAHOO.util.Dom.setStyle( res.argument, 'display', '' );
      YAHOO.util.Dom.get( res.argument ).innerHTML = '<div style="position:absolute;top:-20px;left:673px;"><a rel="internal" href="#" onclick="addToVoteList(null);return false;"><img id="btnclose" alt="" src="/media/img/btn_close_normal.png" onmouseover="imgSwap(this);" onmouseout="imgSwap(this);" /></a></div><span>Thank you for participating. An e-mail with confirmation link has been sent to your e-mail address.</span>';
    },
    failure: function( res )
    {
      YAHOO.util.Dom.setStyle( 'vote-list-form', 'display', 'none' );
      YAHOO.util.Dom.setStyle( res.argument, 'display', '' );
      YAHOO.util.Dom.get( res.argument ).innerHTML = '<div style="position:absolute;top:-20px;left:673px;"><a rel="internal" href="#" onclick="addToVoteList(null);return false;"><img id="btnclose" alt="" src="/media/img/btn_close_normal.png" onmouseover="imgSwap(this);" onmouseout="imgSwap(this);" /></a></div><span class="error">' + res.fault.get( 'faultString' ) + '</span>';
    },
    argument: 'vote-list-contents'
  } );
}

/**
 * Hides the profile dialog
 * @return void
 */
function hideProfile()
{
    if( !profileDialog )
    {
        return;
    }
    
    try
    {
        profileDialog.hide();
    }
    catch( ex )
    {
    }
}

/**
 * Hides the profile dialog
 * @return void
 */
function hideProfileEx()
{
    if( !profileDialogEx )
    {
        return;
    }
    
    try
    {
        profileDialogEx.hide();
    }
    catch( ex )
    {
    }
}

/**
 * initializes profile overlay
 * @return bool
 */
function initProfileOverlay()
{
    if( !YAHOO.util.Dom.inDocument( 'profile_overlay' ) )
    {
        return false;
    }
    
    if( profileDialog )
    {
        return true;
    }
    
    profileDialog = new YAHOO.widget.Overlay( 'profile_overlay' );
    profileDialog.render();
    profileDialog.hide();
    
    YAHOO.util.Event.addListener( 'profile_overlay_close', 'click', function( e, o )
    {
        YAHOO.util.Event.stopEvent( e );
        YAHOO.util.Dom.setStyle( 'profile_overlay', 'display', 'none' );
        o.hide();
    }, profileDialog );
    
    return true;
}

/**
 * initializes profile overlay ex
 * @return bool
 */
function initProfileOverlayEx()
{
    if( !YAHOO.util.Dom.inDocument( 'profile_overlay2' ) )
    {
        return false;
    }
    
    if( profileDialogEx )
    {
        return true;
    }
    
    profileDialogEx = new YAHOO.widget.Overlay( 'profile_overlay2' );
    profileDialogEx.render();
    profileDialogEx.hide();
    
    profileDialogEx.hideEvent.subscribe( function( e )
    {
      if( YAHOO.util.Dom.getStyle( 'vote_5_overlay', 'visibility' ) != 'hidden' )
      {
        return;
      }
      
      YAHOO.util.Dom.setStyle( 'title_vote', 'display', '' );
      YAHOO.util.Dom.setStyle( 'content_vote', 'display', '' );
      YAHOO.util.Dom.setStyle( 'title_search', 'display', 'none' );
      YAHOO.util.Dom.setStyle( 'content_search', 'display', 'none' );      
      YAHOO.util.Dom.setStyle( 'title_nominees', 'display', 'none' );
      YAHOO.util.Dom.setStyle( 'content_nominees', 'display', 'none' );
      YAHOO.util.Dom.setStyle( 'title_submit', 'display', 'none' );
      YAHOO.util.Dom.setStyle( 'content_submit', 'display', 'none' );
    } );
    
    YAHOO.util.Event.addListener( 'profile_overlay_close2', 'click', function( e, o )
    {
        YAHOO.util.Event.stopEvent( e );
        YAHOO.util.Dom.setStyle( 'profile_overlay2', 'display', 'none' );
        o.hide();
    }, profileDialogEx );
    
    return true;
}

/**
 * Submits search form
 * @param Form form
 * @param int page
 * @return void
 */
function submitSearchForm( form, page )
{
    if( YAHOO.lang.isString( form ) )
    {
        form = YAHOO.util.Dom.get( form );
    }
    
    var target = YAHOO.util.Dom.get( 'target' ).value;
    var img = ( YAHOO.util.Dom.inDocument( 'phase2' ) ) ? 'loading4' : null;
    YAHOO.util.Dom.get( target ).innerHTML = getLoadingHtml( 'Searching...', img );
    
    if( page )
    {
        YAHOO.util.Dom.get( 'iPage' ).value = page;
    }
    else
    {
      YAHOO.util.Dom.get( 'iPage' ).value = '1';
    }
    
    var rpc = new Denbel.rpc.XmlRpcClient( '/proxy.php' );
    var msg = rpc.createMessage( 'search' );
    msg.addForm( form );
    
    rpc.callService( msg,
    {
        success: function( res )
        {
            YAHOO.util.Dom.get( res.argument ).innerHTML = res.data;
            
            if( YAHOO.util.Dom.inDocument( 'phase2' ) )
            {
              initNomineeTable();
            }
        },
        failure: function( res )
        {
          YAHOO.util.Dom.get( res.argument ).innerHTML = 'Sorry, there seems to be an error. Please try your search again. If the problem persists, please return at a later time and try again.';
          //throw Error( res.statusText );
        },
        argument: target
    } );
};
