  
  var progress_bars = new Array();

  function include_js( aURL )
  {
	var script  = document.createElement('script');
	script.type = 'text/javascript';
	script.src  = encodeURI(aURL);
	document.getElementsByTagName('head')[0].appendChild(script); 
  }
  
  function include_js2( aURL )
  {
 	document.write('<script type="text/javascript" src="' + encodeURI(aURL) + '"></script>');
  }  

  function progress_init( aProgressBarDIV )
  {
   progress_bars[ aProgressBarDIV ] = 0;
   progress_end( aProgressBarDIV );
  }
  
  function progress_begin( aProgressBarDIV )
  {
  	progress_bars[ aProgressBarDIV ]++;
  	if ( progress_bars[ aProgressBarDIV ] > 0 )
  	  if ( xajax.$(aProgressBarDIV) != null )
  	    xajax.$(aProgressBarDIV).style.display = 'block'; 	  
  }

  function progress_end( aProgressBarDIV )
  {  	
    if ( progress_bars[ aProgressBarDIV ] > 0 )
      progress_bars[ aProgressBarDIV ] = progress_bars[ aProgressBarDIV ] - 1;
            
  	if ( progress_bars[ aProgressBarDIV ] < 1 )   
  	  if ( xajax.$(aProgressBarDIV) != null )
  	    xajax.$(aProgressBarDIV).style.display = 'none';
  }
  
  
  function toggle_details( divid , aAjaxCall, aProgressDiv, PlayEffect , action )
  {
    // we know the state of the detail div, based on opacity... 0=closed  <>0=open
    if ( dojo.byId( divid ).style.opacity == 0 ) 
    {		
		// if we are told to play the effect, then do so.. this should be called by the xajax callback... 
		if ( PlayEffect == false )
		{
			// if the DIV is closed, then setup the progress spinner
			progress_begin( aProgressDiv );
			aAjaxCall( divid, action );
		}else{
			var wipe = dojo.fx.wipeIn({node: divid,duration: 1000});
			var fade = dojo.fadeIn({node: divid ,duration: 1000})
			dojo.fx.combine([fade, wipe]).play();
			progress_end( aProgressDiv );
	  	}
	  	 	
	} else {	  	
	    // in the case where the DIV is already open, then we dont need to do an Ajax callback
	    // so just go and do the effect right away..
	  	var wipe = dojo.fx.wipeOut({node: divid,duration: 1000});
	  	var fade = dojo.fadeOut({node: divid ,duration: 1000})  
	  	dojo.fx.combine([fade, wipe]).play();	
	};
  }  
  
  
  
  
    
  function validate_form_field( aFormField, aValidation )
  {
    //alert( aFormField.name +' - '+ aValidation[ aFormField.name ] +' - '+ aFormField.value );
    lResult = aValidation[ aFormField.name ].test( aFormField.value );
    
    if ( lResult )
    {
      aFormField.className = "validate_ok";
    } else {
      aFormField.className = "validate_fail";
    };
    
    return lResult;
  } 
  
  function isdefined( variable)
  {
    return typeof variable!="undefined";
  }

  function onPWChange(btn, text)
  { 
	if ( btn == 'ok' )
	{
		if ( text.match( /(?=^.{6,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$/ ) )
		{ 
		  xajax_portal_changepassword( text ); 
		} else {	
  		  Ext.MessageBox.alert('Password not changed', 'Password must be 6 characters or more, contain upper & lower case letters and at least 1 number or special character.' );
		};
	} else {
		Ext.MessageBox.alert('Password not changed', 'The password has not been changed.' );
	};
  }

  function changepw()
  {
//    Ext.MessageBox.getDialog().body.child('input').dom.type='password';  // removed to make work in IE
    Ext.MessageBox.prompt('Password Change', 'Please enter your new password:', onPWChange);
  }
	

  
  function validate_form( aForm , aValidation )
  {
    lResult = true;
    
	for(i=0; i < aForm.elements.length; i++)
	{
	  if ( isdefined( aValidation[ aForm.elements[i].name ] ) )
	  {
	    // done seperate, so that the function is called every time... even if lResult is already false..
	    lValRes = validate_form_field( aForm.elements[i] , aValidation );
	    
	    lResult = lResult && lValRes;
	  };
	};
	
	return lResult;
  }       

