﻿function displayPreferences()
{
	d = document.getElementById("ScratchPad");
	d.style.width='450px';
	setInner('Loading....');
	if(xmlhttp)
	{
		var url = "/php/AJAX/search.php?function=displayPrefForm";
		xmlhttp.open("GET", url,true);
		xmlhttp.onreadystatechange=function() 
		{
			if(xmlhttp.readyState==4)
			{
				setInner(xmlhttp.responseText);
				sortableCallback();
			}
		}
		xmlhttp.send(null);
	}
	showElementPositioned('ScratchPad', -450, 0);
}

function sortableCallback(){
   Sortable.create("firstlist",
     {dropOnEmpty:true,containment:["firstlist","secondlist"],constraint:false});
   Sortable.create("secondlist",
     {dropOnEmpty:true,containment:["firstlist","secondlist"],constraint:false,only:'moveable'});
}

// used for front page popin
function setProDisplayPref(prefForm)
{
	var selectedString =  Sortable.serialize('secondlist')
	
	var lines = prefForm.linesPerUpdate[0].checked ? 1 : 2 ;
	var updates = prefForm.updatesPerPage.value;
	
    d = document.getElementById('ScratchPad');
    setInner("Loading New Updates Table");
    
    	var url = '/php/AJAX/search.php?function=saveDisplayPref&lines=' + lines 
       				+ "&" + selectedString + "&updates=" + updates;
        
        xmlhttp.open("GET", url,true);
		xmlhttp.onreadystatechange=function() 
		{
		
			if (xmlhttp.readyState==4) 
			{
				window.location.reload();
			}
		}
		xmlhttp.send(null);
    
    hideElement('ScratchPad');
}
