var popUp  = false;
var mmBox  = false;

function openUrl( whatToUpdate, url, loader, noLoading, map  )
{ 
         
       if( popUp && popUp.open  )
       {
            closePreview();
       }
       
       if( mmBox )
       {
           mmBox.style.display = 'none;';
       }
       
       var mainContent = $( whatToUpdate );
       var loaderContent = $( loader );
       
       var loadString = '<div align=\"center\"><img src="'+ urlConstant +'/images/loading.gif" style="margin-top: 100px; margin-bottom: 50px;"></div>';

       if( noLoading )
       {
            switch( noLoading )
	    {
	      case '2': 
	          loadString = '<div align=\"center\"><img src="'+ urlConstant +'/images/loading.gif" style="margin-top: 50px; margin-bottom: 50px;"></div>';
	      break;	 
	      
	      case '3': 
	          loadString = '<div align=\"center\"><img src="'+ urlConstant +'/images/loading_white.gif" style="margin-top: 100px; margin-bottom: 50px;"></div>';
	      break;	 
	      
	      default:
	         loadString = noLoading;
	      break;
	    }

       }
       if( mainContent )
       {
              if( !loaderContent )
	      {	        
                 mainContent.innerHTML = loadString;  
	      }
	      else if( noLoading != true )
	      {
	         loaderContent.innerHTML = loadString;
	      }	 
       }

       new Ajax.Updater( whatToUpdate, url, {
                                                 evalScripts: 1,
						 onSuccess: function()
						            {
							        if( map )
								{
								     var mapEl = $( map );
								     
								     if( mapEl )
								     {
								         mapEl.focus();
								     }
								}
							    }
					    });

       return false;

}
function submitForm( whatToUpdate, formName, noLoading, action, height )
{

       var params  = Form.serialize( formName );
      
       var mainContent = $( whatToUpdate );
       
       if( action )
       {
            var url = action;
       }
       else
       {
            var url = $( formName ).action;
       }

       if( mainContent )
       {
            if( noLoading == true)
            {
	    }
	    else if( $( noLoading ) )
	    {
		  
		  if( !height )
		  {
		       height = 200;
		  }

	          $( noLoading ).innerHTML = '<div align=\"center\"><img src="'+ urlConstant +'/images/loading.gif" style="margin-top: '+(height/2)+'px; margin-bottom: '+(height/2)+'px;"></div>';
	    }
	    else
	    {
              mainContent.innerHTML = '<div align=\"center\"><img src="'+ urlConstant +'/images/loading.gif" style="margin-top: '+(height/2)+'px; margin-bottom: '+(height/2)+'px;"></div>';
            }
       }
    
       var formNode = $( formName );
       if( formNode )
       {
	       var selects = formNode.getElementsByTagName( 'input' );
	       for( var cS = 0; cS < selects.length; cS++ ) 
	       {
	               var type =   selects[cS].getAttribute( 'type' );
	               if( type == "submit" || type == "button" || type == "image" )
		       {
		              selects[ cS ].disabled = true;
		       }
	       }
       }

       new Ajax.Updater(  whatToUpdate, url, 
                                          {
					     method: "post",
					     postBody: params,
					     evalScripts: 1,
					     onSuccess: function(){ 
					     		       
					     		       if( formNode )
							       {		
						                       var selects = formNode.getElementsByTagName( 'input' );
						   
								       for( var cS = 0; cS < selects.length; cS++ ) 
								       {
								              var type =  selects[cS].getAttribute( 'type' );
									      if( type == "submit" || type == "button" || type == "image" )
									      {
									          selects[ cS ].disabled = false;
									      }
									      
								       }
							       }	       					     
							       	return false;
					      }
					  }   
					
				);
    
       return false;
}


