     function addMega(){
     //this function
     
		$(this).children("div").each(function(idx,el){
		    el.style.display='block';
		});
        $(this).addClass("hovering");
        
        }

      function removeMega(){
      //this function
      
		var par = $(this).children("div").get(0);
		var $div = $(par);
        $div.fadeOut("normal");
		$(this).removeClass("hovering");
        }
        
        
function populatedropdowns(li)
{

//this function



	var svr = li.extra[0];

	       
      $.getJSON("select.php", {id: svr}, function(j){
      		
      		var rel = '';
      		var port = '';
      		var wcm = '';
      		
      		
			rel = j[0].release;
			port = j[0].portalbuild;
			wcm = j[0].wcmbuild;
			dbtype = j[0].dbtype;
			dbhost = j[0].dbhost;
			ldaptype = j[0].ldaptype;
			
			dbport = j[0].dbport;
			iscluster = j[0].iscluster;
			nodetype = j[0].nodetype;
			webroot = j[0].webroot;
			profilepath = j[0].profilepath;
			admininst = j[0].admininst;
			expinst = j[0].expinst;
			db2mem = j[0].db2mem;
			was7 = j[0].was7;
			
			clustertype = j[0].clustertype;
			primarynode = j[0].primarynode;
			secondarynode = j[0].secondarynode;
			dmgr = j[0].dmgr;
			rebuilddmgr = j[0].rebuilddmgr;
			
			realm = j[0].realm;
			realm1 = j[0].realm1;
			realm2 = j[0].realm2;
			
			$("select#release").selectOptions(rel);
			
			getSetProps(rel,port,wcm,dbtype,dbhost,ldaptype,dbport,iscluster,nodetype,webroot,profilepath,admininst,expinst,db2mem,was7, clustertype, primarynode, secondarynode, dmgr, rebuilddmgr);	
		
	
		  
      });

}

function dbdetails(){
//this function


$("select#dbhost").removeAttr("disabled");
	dbtype = $("select#dbtype option:selected").val();
	
	
	
	if((dbtype == "sqlserver2005") || (dbtype == "sqlserver2008"))
	{
		alert('Please note that this DB type isn\'t fully automated! \nYou will need to create tables/users manually on \nthe server before database-transfer can run.');
	}
	$.getJSON("getdbs.php",{dbtype: dbtype, type: 'host'}, function(j){
			var options = '';
	
			for (var i = 0; i < j.length; i++) {
				options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
			}
			
			$("select#dbhost").html(options);		
	
	});
	
		$.getJSON("getdbs.php",{dbtype: dbtype, type: 'port'}, function(j){
			var selport = '';
	
			for (var i = 0; i < j.length; i++) {
				selport = j[i].dbport;
			}
			
			$("input#dbport").val(selport);		
	
	});
	

}

function popEmptyDrops(){ 
// this function populates the dropdowns for a new server that doesn't have anything in the DB, OR
// populates portal builds and wcm builds when the release is changed.


rel = $("select#release option:selected").val(); //get the selected release 

$("select#portalbuild").removeAttr("disabled"); //stop the portalbuild select being disabled.
$("select#wcmbuild").removeAttr("disabled"); //stop the wcmbuild select being disabled.

      //this line gets the available portal builds for the selected release via dir.php (as JSON) and updates the dropdown

 $.getJSON("dir.php", {release: rel}, function(j){

		  var options = '';
	
		  for (var i = 0; i < j.length; i++) {
			  options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
		  }
	
		  $("select#portalbuild").html(options);
			
      });
      
      //this line gets the wcmbuild via dir3.php (as JSON) and updates the wcmbuild dropdown
      
 $.getJSON("dir3.php", {release: rel}, function(j){

		  var options = '';
	
		  for (var i = 0; i < j.length; i++) {
			  options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
		  }
	
		  $("select#wcmbuild").html(options);
      });
	dbdetails(); //populate the dbhost and dbport with whatever is selected in the dbtype dropdown
	
}

function getSetProps(rel, port, wcm, dbtype, dbhost, ldaptype, dbport, iscluster, nodetype, webroot, profilepath, admininst, expinst, db2mem, was7, clustertype, primarynode, secondarynode, dmgr, rebuilddmgr, realm, realm1, realm2) {
//This function populates the form on the screen with the last saved properties in the DB.


$("select#portalbuild").removeAttr("disabled"); //stop the portalbuild select being disabled.
$("select#wcmbuild").removeAttr("disabled"); //stop the wcmbuild select being disabled.


//this line gets the available portal builds for the selected release via dir.php (as JSON) and updates the dropdown
 $.getJSON("dir.php", {release: rel}, function(j){

		  var options = '';
	
		  for (var i = 0; i < j.length; i++) {
			  options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
		  }
	
		  $("select#portalbuild").html(options);
		  $("select#portalbuild").selectOptions(port); //set the selected option
			
      });
      
      
 //this line gets the wcmbuild via dir3.php (as JSON) and updates the wcmbuild dropdown
 $.getJSON("dir3.php", {release: rel}, function(j){

		  var options = '';
	
		  for (var i = 0; i < j.length; i++) {
			  options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
		  }
	
		  $("select#wcmbuild").html(options);
		  $("select#wcmbuild").selectOptions(wcm); //set the selected option
      });
      
      //populate the form with the values from the DB passed to this function.
      
      $("select#dbtype").selectOptions(dbtype);
      
      dbdetails(); // populate the host and port with available options
      
      $("select#dbhost").selectOptions(dbhost); // next 2 lines overwrite the above results if the last save was different.
      $("input#dbport").val(dbport);
      
      $("select#ldaptype").selectOptions(ldaptype);
      $("select#realm").selectOptions(realm);
      
      if(realm == "TRUE")
      {
		$("#addrealm").slideToggle(300);	
		
		var testlink = document.getElementById('addrealmclick');
		
		//make sure the link reflects the current state and the action that is coming if clicked.
		
		if(testlink.innerHTML == 'Click here to hide realm ldap properties') {
			testlink.innerHTML = 'Click here to show realm ldap properties';
		}
		else
		{
			testlink.innerHTML = 'Click here to hide realm ldap properties';
		}	      
      }
      //if realm == true, make the additional realm properties show!

      
      $("input#realm1").val(realm1);
      $("input#realm2").val(realm2);
      
      $("select#was7").selectOptions(was7);
      $("select#cluster").selectOptions(iscluster);
      
      if(iscluster == "TRUE")
      {
		$("#addcluster").slideToggle(300);	
		
		var testlink = document.getElementById('addclustclick');
		
		//make sure the link reflects the current state and the action that is coming if clicked.
		
		if(testlink.innerHTML == 'Click here to hide additional clustering properties') {
			testlink.innerHTML = 'Click here to show additional clustering properties';
		}
		else
		{
			testlink.innerHTML = 'Click here to hide additional clustering properties';
		}	      
      }
      //if cluster == true, make the additional properties show!
      
      $("select#nodetype").selectOptions(nodetype);      
      $("select#clustertype").selectOptions(clustertype);
      
      $("input#primarynode").val(primarynode);
      $("input#secondarynode").val(secondarynode);
      $("input#dmgr").val(dmgr);
      
      $("select#rebuilddmgr").selectOptions(rebuilddmgr);
      
      
      //needs a for loop inside the php db results that echos
      // echo "\$(\"input#$varname\").val($jsvarname); ";
      
      $("input#WebSphere_Root").val(webroot);
      $("input#profile_path").val(profilepath);
      $("select#admininstall").selectOptions(admininst);
      $("select#expinstall").selectOptions(expinst);
      $("select#db2mem").selectOptions(db2mem);

}

function findValue(li) {
//this function decides whether the server typed exists or not, then calls the appropriate function.


	$("select#release").removeAttr("disabled");
	$("select#release").removeOption("0"); //remove the option that says "please select server..."
	
	//if there is nothing found by the autocompleter
	if( li == null ) {
	
		
		var svr = $("#hostname")[0].value;
		
		//$.getJSON("addhost.php", {host: svr});
		
		alert("This is your first time, adding your server ("+svr+") now.");
		
		popEmptyDrops();
		
	}
	else //if the server is found (/does exist)
	{
		if( !!li.extra ) var sValue = li.extra[0];
	
		else var sValue = li.selectValue;
			
		populatedropdowns(li); //get the details from the DB and populate the form on page.
	}
	
}

function selectItem(li) {
	findValue(li);
}

function formatItem(row) {
	return row[0];
}


function lookupLocal(){
//this function looks up the server as it is being typed into the hostname field

	var oSuggest = $("#hostname")[0].autocompleter;

	oSuggest.findValue();

	return false;
}

function showclust() {
	var clus = $("select#cluster option:selected").val();
	
		$("#addcluster").slideToggle(300);	
		
		var testlink = document.getElementById('addclustclick');
		
		//make sure the link reflects the current state and the action that is coming if clicked.
		
		if(testlink.innerHTML == 'Click here to hide additional clustering properties') {
			testlink.innerHTML = 'Click here to show additional clustering properties';
		}
		else
		{
			testlink.innerHTML = 'Click here to hide additional clustering properties';
		}	
	
}

//everything in this function needs to load once the page has finished loading. Most of these things initialize the javascript functions.

$(document).ready(function() {
	$("#hostname").autocomplete(
				"autocomp.php",
		{
			delay:10,
			minChars:1,
			matchSubset:1,
			matchContains:1,
			cacheLength:10,
			onItemSelect:selectItem,
			onFindValue:findValue,
			formatItem:formatItem,
			autoFill:true
		}
	);
	
	

	  //hide the all of the element with id #additional
  $("#additional").hide();
  $("#addcluster").hide();
  $("#addrealm").hide();
  //toggle the componenet with id #additional
  $("#addclick").click(function()
  {
    
    $(this).next("#additional").slideToggle(300);
    
    
    var testlink = document.getElementById('addclick');
    
    //make sure the link reflects the current state and the action that is coming if clicked.
    
    if(testlink.innerHTML == 'Click here to hide additional properties') {
    	testlink.innerHTML = 'Click here to show additional properties';
    }
    else
    {
    	testlink.innerHTML = 'Click here to hide additional properties';
    } 
    }); 
    
    $("#addclustclick").click(function()
  	{
    
    $(this).next("#addcluster").slideToggle(300);
    
    
    var testlink = document.getElementById('addclustclick');
    
    //make sure the link reflects the current state and the action that is coming if clicked.
    
    if(testlink.innerHTML == 'Click here to hide additional clustering properties') {
    	testlink.innerHTML = 'Click here to show additional clustering properties';
    }
    else
    {
    	testlink.innerHTML = 'Click here to hide additional clustering properties';
    } 
    });  

	$("#addrealmclick").click(function()
  	{
    
    $(this).next("#addrealm").slideToggle(300);
    
    
    var testlink = document.getElementById('addrealmclick');
    
    //make sure the link reflects the current state and the action that is coming if clicked.
    
    if(testlink.innerHTML == 'Click here to hide realm properties') {
    	testlink.innerHTML = 'Click here to show realm properties';
    }
    else
    {
    	testlink.innerHTML = 'Click here to hide realm properties';
    } 
    });  
    



//this is the funcion that configures the menu (using hoverIntent).
      
      var megaConfig = {
         interval: 250,
         sensitivity: 4,
         over: addMega,
         timeout: 250,
         out: removeMega
    };

    $("li.mega").hoverIntent(megaConfig);


			//config sifr
			$.sifr({
				path: 'fonts/',
				save: true
			});
			
			$('h2').sifr({ font: 'steward' });
			$('#logo h1').sifr({ font: 'steward' });

						
			//sidebar and main with equal height
			var mainHeight = $('#main').height();
			var sidebarHeight = $('#sidebar').height();
			
			if(mainHeight > sidebarHeight) {
				$('#sidebar').height(mainHeight);
			} else {
				$('#main').height(sidebarHeight);
			}

		});
		


