//user Tools JS functions

function toggleChecks(selectAll)
{
	var field = document.DLProducts.list;
	var undef;
	
	if(field.length)
	{
		for (i = 0; i <= field.length; i++)
			field[i].checked = selectAll.checked ;
	} else {
		field.checked = selectAll.checked ;
	}
}


function getChecked(field)
{
	var actList = '0';
	if(field.length)
	{
		for (var i = 0; i < field.length; i++)
		{
			if(field[i].checked)
			{
				actList = actList + ',' + field[i].value;
			}
		}
	} else {
		if(field.checked)
		{
			actList = actList + ',' + field.value;
		}
	}
	return actList;
}

function remove()
{
	var field = document.DLProducts.list;
	var actList = getChecked(field);
	if( actList != '0' )
	{
		d = document.getElementById("AJAXData");        
		if(xmlhttp)
		{
			xmlhttpdo("/php/AJAX/downloadCart.php?function=removeItems&ids=" + actList);
		}
		else
		{
			jsrsdo2("/php/AJAX/downloadCart.php", "removeItems", Array("'" + actList + "'"))
		}
	}
}

function removeReports()
{
	var field = document.DLProducts.list;
	var actList = getChecked(field);
	if( actList != '0' )
	{
		d = document.getElementById("AJAXData");        
		if(xmlhttp)
		{
			xmlhttpdo("/php/AJAX/report.php?function=removeReport&ids=" + actList);
		}
		else
		{
			jsrsdo2("/php/AJAX/report.php", "removeReport", Array("'" + actList + "'"))
		}
	}
}

function emailReports()
{
	var field = document.DLProducts.list;
	var actList = getChecked(field);
	
	if( actList != '0' )
	{
		d = document.getElementById("ScratchPad");        
		if(xmlhttp)
		{
			xmlhttpdo("/php/AJAX/report.php?function=emailReport&ids=" + actList);
		}
		else
		{
			jsrsdo2("/php/AJAX/report.php", "emailReport", Array("'" + actList + "'"))
		}
	}
}

function downloadReports()
{
	var field = document.DLProducts.list;
	var actList = getChecked(field);
	if( actList != '0' )
	{
		d = document.getElementById("ScratchPad");        
		if(xmlhttp)
		{
			xmlhttpdo("/php/AJAX/report.php?function=downloadReport&ids=" + actList);
		}
		else
		{
			jsrsdo2("/php/AJAX/report.php", "downloadReport", Array("'" + actList + "'"))
		}
	}
}

function updateReports()
{
	var field = document.DLProducts.list;
	var actList = getChecked(field);
	if( actList != '0' )
	{
		d = document.getElementById("AJAXData");        
		if(xmlhttp)
		{
			xmlhttpdo("/php/AJAX/report.php?function=updateReport&ids=" + actList);
		}
		else
		{
			jsrsdo2("/php/AJAX/report.php", "updateReport", Array("'" + actList + "'"))
		}
	}
}

function generateReport( formFields )
{
	var xmlFields = '';
	var formElements = formFields.elements; 
	for (var i=0;i<formFields.length;i++) 
	{
		if( formElements[i].type == 'checkbox' || formElements[i].type == 'radio')
		{
			if( formElements[i].checked )
			{
				xmlFields = xmlFields + '&' + formElements[i].name + '=' + formElements[i].value;
			}
		}
		else
		{
			if( formElements[i].value != '' )
			{
				xmlFields = xmlFields + '&' + formElements[i].name + '=' + formElements[i].value;
			}
		}
	}
        
	d = document.getElementById('ScratchPad');
	setInner('<img src="http://image.versiontracker.com/images/indicator.gif">Generating Report');
	showElementPositioned('ScratchPad', 0, -120);
		
	if(xmlhttp)
	{
	    var url = '/php/AJAX/report.php?function=generateReport' + xmlFields;
        xmlhttp.open("GET", url,true);
		xmlhttp.onreadystatechange=function() 
		{
			if (xmlhttp.readyState==4) 
			{
				setInner(xmlhttp.responseText);
				loadReports();
				//showElement('ScratchPad');
			}
		}
		xmlhttp.send(null);
	}
		
}

function loadReports()
{
	d = document.getElementById("AJAXData");        
	if(xmlhttp)
	{
		xmlhttpdo("/php/AJAX/report.php?function=loadReports");
	}
	else
	{
		jsrsdo2("/php/AJAX/report.php", "loadReports", Array())
	}

}

function editReport(id)
{
	if(xmlhttp)
	{
	    var url = "/php/AJAX/report.php?function=editReport&id=" + id;
        xmlhttp.open("GET", url,true);
		xmlhttp.onreadystatechange=function() 
		{
			if (xmlhttp.readyState==4) 
			{
				eval(xmlhttp.responseText);
				//d = document.getElementById("ScratchPad");  
				//setInner(xmlhttp.responseText)
				//showElement('ScratchPad');
			}
		}
		xmlhttp.send(null);
	}

}



function removeFromDownloadCart(actList)
{
	if(actList != '')
	{
		d = document.getElementById("AJAXData");        
		if(xmlhttp)
		{
			xmlhttpdo("/php/AJAX/downloadCart.php?function=removeItems&ids=" + actList);
		}
		else
		{
			jsrsdo2("/php/AJAX/downloadCart.php", "removeItems", Array("'" + actList + "'"))
		}
	}
	hideElement('ScratchPad');
}

function removeSystem(systemID)
{
	if(systemID != '')
	{
		d = document.getElementById("AJAXData");        
		if(xmlhttp)
		{
			xmlhttpdo("/php/AJAX/systems.php?function=removeSystem&ids=" + systemID);
		}
		else
		{
			jsrsdo2("/php/AJAX/systems.php", "removeSystem", Array("'" + systemID + "'"))
		}
	}
}

function sortInstalledProducts(field, direction) {
	d = document.getElementById('AJAXData');
	if(xmlhttp) {
		xmlhttpdo('/php/AJAX/installedProduct.php?function=getInstalledProducts&by=' + field
			+ '&dir=' + direction );
	}
}

function pageInstalledProducts(page) {
	d = document.getElementById('AJAXData');
	if(xmlhttp) {
		xmlhttpdo('/php/AJAX/installedProduct.php?function=getInstalledProducts&pg=' + page
			);
	}
}

function setOutOfDateOnly(chkbox) {

	var OOD = 'no';

	if(chkbox.checked)
	{
		OOD = 'yes';
	}

	d = document.getElementById('AJAXData');
	if(xmlhttp) {
		xmlhttpdo('/php/AJAX/installedProduct.php?function=getInstalledProducts&outOdDateOnly=' + OOD
			);
	}
}
function setWinDrivers(chkbox) {

	var winDrivers = 'no';

	if(chkbox.checked)
	{
		winDrivers = 'yes';
	}

	d = document.getElementById('AJAXData');
	if(xmlhttp) {
		xmlhttpdo('/php/AJAX/installedProduct.php?function=getInstalledProducts&winDrivers=' + winDrivers
			);
	}
}
function setInstalledAlert(Sched)
{
	d = document.getElementById('ScratchPad');
	if(xmlhttp) {
		xmlhttpdo('/php/AJAX/alerts.php?function=setInstalledAlert&sched=' + Sched
			);
	}
}

function sortDownloadCart(field, direction) {
	d = document.getElementById('AJAXData');
	if(xmlhttp) {
		xmlhttpdo('/php/AJAX/downloadCart.php?function=getDownloadCart&by=' + field
			+ '&dir=' + direction );
	}
}

function pageDownloadCart(page) {
	d = document.getElementById('AJAXData');
	if(xmlhttp) {
		xmlhttpdo('/php/AJAX/downloadCart.php?function=getDownloadCart&pg=' + page );
	}
}

function sortAlertList(field, direction) {
	d = document.getElementById('AJAXData');
	if(xmlhttp) {
		xmlhttpdo('/php/AJAX/alerts.php?function=getAlertList&by=' + field
			+ '&dir=' + direction );
	}
}

function pageAlertList(page) {
	d = document.getElementById('AJAXData');
	if(xmlhttp) {
		xmlhttpdo('/php/AJAX/alerts.php?function=getAlertList&pg=' + page );
	}
}

function sortAddToAlertList(field, direction) {
	d = document.getElementById('AJAXData');
	
	
	if(xmlhttp) {
		xmlhttpdo('/php/AJAX/addAlert.php?function=getProductList&by=' + field
			+ '&dir=' + direction + '&platform=' + document.getElementById('alertSearchForm').qPlatform.value 
			+ '&s=' + document.getElementById('livesearch').value);
	}
}

function pageAddToAlertList(page) {
	d = document.getElementById('AJAXData');
	if(xmlhttp) {
		xmlhttpdo('/php/AJAX/addAlert.php?function=getProductList&pg=' + page
			+ '&platform=' + document.getElementById('alertSearchForm').qPlatform.value 
			+ '&s=' + document.getElementById('livesearch').value);
	}
}

function downloadFromDownloadCart() {
	var field = document.DLProducts.list;
	var actList = getChecked(field);
	d = document.getElementById('ScratchPad');
	d.style.width='250px';
	if(xmlhttp) {
		xmlhttpdo('/php/AJAX/downloadCart.php?function=download&ids=' + actList
			);
	}
	showElementPositioned('ScratchPad', -400, 120);
}

function downloadFromInstalledProducts() {
	var field = document.DLProducts.list;
	var actList = getChecked(field);
	d = document.getElementById('ScratchPad');
	d.style.width='200px';
	if(xmlhttp) {
		xmlhttpdo('/php/AJAX/installedProduct.php?function=download&ids=' + actList
			);
	}
	showElementPositioned('ScratchPad', -100, -20);
}

function addInstalledProductsToDLCart() {

	var field = document.DLProducts.list;
	var actList = getChecked(field);
	d = document.getElementById('ScratchPad');
	d.style.width='300px';
	setInner('Loading....');
	if(xmlhttp) {
		xmlhttpdo('/php/AJAX/installedProduct.php?function=addToDownloadCart&products=' + actList
			);
	}
	showElementPositioned('ScratchPad', -120, 0);
}


function removeAlerts()
{
	var field = document.DLProducts.list;
	var actList = getChecked(field);
	if(actList != '0')
	{
		d = document.getElementById("AJAXData");        
		if(xmlhttp)
		{
			xmlhttpdo("/php/AJAX/alerts.php?function=removeItems&ids=" + actList);
		}
		else
		{
			jsrsdo2("/php/AJAX/alerts.php", "removeItems", Array("'" + actList + "'"))
		}
	}

}


function showSystem(form)
{
	d = document.getElementById("AJAXData");
	
	if(xmlhttp)
	{
		xmlhttpdo('/php/AJAX/installedProduct.php?function=getInstalledProducts&systemID=' + form.systems.value);
	}
	document.focus();
}


function editAlert( alertID )
{ 
	d = document.getElementById("ScratchPad");
	
	d.style.width='200px';
	setInner('Loading....');
	
	if(xmlhttp)
	{
		xmlhttpdo("/php/AJAX/alerts.php?function=alertSettingsForm&alertID=" + alertID);
	}
	else
	{
		jsrsdo2("modPrefForm", Array("'" + alertID + "'"))
	}
	
	showElementPositioned('ScratchPad', -100, -120);
}

function addAlert( )
{ 
	var field = document.DLProducts.list;
	var actList = getChecked(field);
	
	if(actList != '0')
	{
		d = document.getElementById("ScratchPad");       
		d.style.width='200px'; 
		setInner('Loading....');
		
		if(xmlhttp)
		{
			xmlhttpdo("/php/AJAX/addAlert.php?function=alertSettingsForm&alertID=" + actList);
		}
		else
		{
			jsrsdo2("/php/AJAX/addAlert.php", "alertSettingsForm", Array("'" + actList + "'"))
		}
		
		showElementPositioned('ScratchPad', -300, -120);
	}
}


function saveAccountSettings( formFields ) 
{     
	var xmlFields = '';
	var formElements = formFields.elements; 
	for (var i=0;i<formFields.length;i++) 
	{
		if( formElements[i].type == 'checkbox' || formElements[i].type == 'radio')
		{
			if( formElements[i].checked )
			{
				xmlFields = xmlFields + '&' + formElements[i].name + '=' + encodeURIComponent(formElements[i].value);
			}
		}
		else
		{
			if( formElements[i].value != '' )
			{
				xmlFields = xmlFields + '&' + formElements[i].name + '=' + encodeURIComponent(formElements[i].value);
			}
		}
	}
   
		d = document.getElementById("ScratchPad");       
		d.style.width='400px'; 
		setInner('Loading....');
		
		if(xmlhttp)
		{
			xmlhttpdo('/php/AJAX/account.php?function=saveAccountSettings' + xmlFields);
		}
		else
		{
			jsrsdo2("/php/AJAX/addAlert.php", "alertSettingsForm", Array("'" + actList + "'"))
		}

            if (typeof(formFields.screenName) != 'undefined') {
                displayName = formFields.screenName.value;
            }

			email = formFields.femail.value;
			firstName = formFields.firstName.value;
			middleName = formFields.middleName.value;
			lastName = formFields.lastName.value;
			city = formFields.realCity.value;
			state = formFields.realState.value;
			zip = formFields.realZip.value;
			country = formFields.realCountry.value;
			address1 = formFields.realAddress1.value;
			address2 = formFields.realAddress2.value;
			phone = formFields.realPhone.value;

		showElementPositioned('ScratchPad', 0, -200);
		
}

function doNothing(){
	return true;
}



function saveNewAlerts( formFields ) 
{     
	var xmlFields = '';
	var formElements = formFields.elements; 
	for (var i=0;i<formFields.length;i++) 
	{
		if( formElements[i].type == 'checkbox' || formElements[i].type == 'radio')
		{
			if( formElements[i].checked )
			{
				xmlFields = xmlFields + '&' + formElements[i].name + '=' + formElements[i].value;
			}
		}
		else
		{
			if( formElements[i].value != '' )
			{
				xmlFields = xmlFields + '&' + formElements[i].name + '=' + formElements[i].value;
			}
		}
	}
   
   
	d = document.getElementById('ScratchPad');
	
	if(xmlhttp)
	{
	    var url = '/php/AJAX/addAlert.php?function=saveAlertSettings' + xmlFields;
        xmlhttp.open("GET", url,true);
		xmlhttp.onreadystatechange=function() 
		{
			if (xmlhttp.readyState==4) 
			{
				setInner(xmlhttp.responseText);
				d = document.getElementById('ScratchPad');
				setInner('Your alerts have been saved.<div style ="text-align:center"><a href="javascript:hideElement(\'ScratchPad\');">Close Window</a></div>');
				showElement('ScratchPad');

				var field = document.DLProducts.list;
				for (i = 0; i < field.length; i++)
				{
					field[i].checked = false;
				}
				
			}
		}
		xmlhttp.send(null);
	   
	}
	else
	{
		jsrsdo("saveAlertSettings", Array(xmlFields))
	}
}

function editMultipleAlerts( position )
{ 
	var field = document.DLProducts.list;
	var actList = getChecked(field);
	
	if(actList != '0')
	{
		d = document.getElementById("ScratchPad");       
		d.style.width='300px'; 
		setInner('Loading....');
		var xAdjust = -120;
		if( position == 'bottom' )
		{
			xAdjust = -420;
		} 
		
		if(xmlhttp)
		{
			xmlhttpdo("/php/AJAX/alerts.php?function=alertSettingsForm&alertID=" + actList);
		}
		else
		{
			jsrsdo2("/php/AJAX/alerts.php", "removeItems", Array("'" + actList + "'"))
		}
		
		showElementPositioned('ScratchPad', -300, xAdjust);
	}
}

function saveAlertSettings( formFields ) 
{     
	var xmlFields = '';
	var formElements = formFields.elements; 
	for (var i=0;i<formFields.length;i++) 
	{
		if( formElements[i].type == 'checkbox' || formElements[i].type == 'radio')
		{
			if( formElements[i].checked )
			{
				xmlFields = xmlFields + '&' + formElements[i].name + '=' + formElements[i].value;
			}
		}
		else
		{
			if( formElements[i].value != '' )
			{
				xmlFields = xmlFields + '&' + formElements[i].name + '=' + formElements[i].value;
			}
		}
	}
   
	d = document.getElementById('AJAXData');
	
	if(xmlhttp)
	{
	    var url = '/php/AJAX/alerts.php?function=saveAlertSettings' + xmlFields;
        
        xmlhttp.open("GET", url,true);
		xmlhttp.onreadystatechange=function() 
		{
			if (xmlhttp.readyState==4) 
			{
				setInner(xmlhttp.responseText);
				d = document.getElementById('ScratchPad');
				setInner('Your Alert Settings have been saved.<div style ="text-align:center"><a href="javascript:hideElement(\'ScratchPad\');">Close Window</a></div>');
				showElement('ScratchPad');
			}
		}
		xmlhttp.send(null);
	}
	else
	{
		jsrsdo("saveAlertSettings", Array(xmlFields))
	}
}

function saveModPref(modForm)
{
	var moduleID = modForm.mid.value;
	var selectedModule = getSelectedRadio(modForm.moduleName);
	var modulename = modForm.moduleName[selectedModule].value;
	
	d = document.getElementById("module" + moduleID);
	
	if(xmlhttp)
	{
		xmlhttpdo("/php/jsrpc.php?function=saveModPref&modIdx=" + moduleID + "&mod=" + modulename);
	}
	else
	{
		jsrsdo("saveModPref", Array(modulename,moduleID))
	}
	
	hideElement('ScratchPad');
}
    
function sortableCallback(){
   Sortable.create("firstlist",
     {dropOnEmpty:true,containment:["firstlist","secondlist"],constraint:false});
   Sortable.create("secondlist",
     {dropOnEmpty:true,containment:["firstlist","secondlist"],constraint:false,only:'moveable'});
}    
function displayPrefs()
{
    basicRPCForm('displayPrefForm', 200, -200, 0);
}    

function getDisplayPrefForm(page)
{
    d = document.getElementById('AJAXData');
	
	if(xmlhttp)
    {
        var url = '/php/AJAX/account.php?function=getDisplayPrefForm&page=' + page;
        
        xmlhttp.open("GET", url,true);
		xmlhttp.onreadystatechange=function() 
		{
			if (xmlhttp.readyState==4) 
			{
				setInner(xmlhttp.responseText);
				sortableCallback();
			}
		}
		xmlhttp.send(null);
        
    }
	
}

function platformNewsForm(plat)
{
    d = document.getElementById("ScratchPad");
    
    d.style.width='400px';
    setInner('Loading....');
    
    if(xmlhttp)
    {
        xmlhttpdo("/php/jsrpc.php?function=platformNewsForm&platform=" + plat);
    }
    else
    {
        jsrsdo("platformNewsForm", Array("'" + plat + "'"))
    }
    
    showElementPositioned('ScratchPad', -420, -200);
}


function savePlatformNews(newsForm)
{
    d = document.getElementById('ScratchPad');
   // hideElement('ScratchPad');
    
    var platform = newsForm.platform.value;
    var title1 = newsForm.title1.value;
    var url1 = newsForm.url1.value;
    var title2 = newsForm.title2.value;
    var url2 = newsForm.url2.value;
    var title3 = newsForm.title3.value;
    var url3 = newsForm.url3.value;
    var title4 = newsForm.title4.value;
    var url4 = newsForm.url4.value;
    var title5 = newsForm.title5.value;
    var url5 = newsForm.url5.value;
    
	if(xmlhttp)
    {
       xmlhttpdo("/php/jsrpc.php?function=savePlatformNews&platform=" + platform
            + "&title1=" + title1
            + "&title2=" + title2
            + "&title3=" + title3
            + "&title4=" + title4
            + "&title5=" + title5
            + "&url1=" + URLencode(url1)
            + "&url2=" + URLencode(url2)
            + "&url3=" + URLencode(url3)
            + "&url4=" + URLencode(url4)
            + "&url5=" + URLencode(url5));
    }
    else
    {
        jsrsdo("savePlatformNews", Array(platform, title1, url1, title2, url2, title3, url3, title4, url4, title5, url5));
    }
    
  
}

function saveProDisplayPref(prefForm)
{
	if (document.getElementById('secondlist'))
	{
		var selectedString =  Sortable.serialize('secondlist')
		var lines = prefForm.linesPerUpdate[0].checked ? 1 : 2 ;
		var page = prefForm.pageToEdit.value;
		var mode = 'updates';
		var days = 2;
		
		if (page == 'frontPage' && !prefForm.editType[1].checked)
		{
			mode = prefForm.updateQuantity[0].checked ? 'updates' : 'days' ;
			days = prefForm.daysPerPage.value;
		}
		
		if (prefForm.editType[1].checked)
		{
			page = 'global';
			mode = prefForm.updateQuantity.checked ? 'days' : 'updates';
			days = prefForm.daysPerPage.value;
		}
		
		var updates = prefForm.updatesPerPage.value;
		var advertising ='yes';
		
		if(prefForm.advertising)
		{
			advertising = prefForm.advertising.checked ? 'yes' : 'no';
		}
		
		var yAdjust = -20;
	}
	else
	{
		var selectedString = '';
		var lines = '';
		var mode = '';
		var updates = '';
		var days = '';
		var advertising ='yes';
		var yAdjust = -20;
	}
	
	if(prefForm.UpdateTable)
	{
		var updateTable = prefForm.UpdateTable[0].checked ? 'updateTable' : 'updateTable2';
	}
	
	d = document.getElementById('ScratchPad');
	setInner('<img src="http://image.versiontracker.com/images/indicator.gif"> Saving settings ....');
	
	var url = '/php/AJAX/account.php?function=saveDisplayPref&lines=' + lines + "&days=" + days + "&" + selectedString + "&updates=" + updates + "&mode=" + mode + "&page=" + page + "&advertising=" + advertising + "&updateTable=" + updateTable;
	if(xmlhttp)
	{
		xmlhttpdo(url);
	}
	else
	{
		jsrsdo("account", Array(Theme, UpdateTable, CurrentPlatform));
	}
	// setActiveStyleSheet(theme);
	showElementPositioned('ScratchPad', yAdjust, -100);
}

function resetProDisplayPref()
{
    d = document.getElementById('AJAXData');
    
	if(xmlhttp)
    {
    	var url = '/php/AJAX/account.php?function=displayPrefForm';
    	xmlhttp.open("GET", url,true);
		xmlhttp.onreadystatechange=function() 
		{
			if (xmlhttp.readyState==4) 
			{
				setInner(xmlhttp.responseText);
				Sortable.create("firstlist",
				 {dropOnEmpty:true,containment:["firstlist","secondlist"],constraint:false});
				Sortable.create("secondlist",
				 {dropOnEmpty:true,containment:["firstlist","secondlist"],constraint:false,only:'moveable'});
			}
		}
		xmlhttp.send(null);
    }
    else
    {
        jsrsdo("account", Array(Theme, UpdateTable, CurrentPlatform))
    }
}

function resetSelectionFilter()
{
	active = new Array();
	for (selected in saved)
    {
    	active[selected] = saved[selected];
    }
    
    pd = document.getElementById('preferenceForm');
    for (selected in savedPD)
    {
    	//pd[selected][savedPD[selected]].selected = true;
    	//alert(selected + ' -> ' + savedPD[selected]);
    }
    
    updateFromPlatform(selectedPlatform);
    updateFromCategory(selectedCategory);
	updateFilterDisplay();
}

function saveSelectionFilterAccount(formFields)
{
	var filterString = '';
    var xmlFields = '';
	var formElements = formFields.elements; 
	saved = new Array();
	for (selected in active)
    {
    	if(active[selected])
    	{
    		filterString = filterString + ',' + encodeURIComponent(selected);
    	}
    	saved[selected] = active[selected];
    }
	for (var i=0;i<formFields.length;i++) 
	{
		if( formElements[i].type == 'checkbox' || formElements[i].type == 'radio')
		{
			if( formElements[i].checked )
			{
				xmlFields = xmlFields + '&' + formElements[i].name + '=' + encodeURIComponent(formElements[i].value);
			}
		}
		else
		{
			if( formElements[i].value != '' )
			{
				xmlFields = xmlFields + '&' + formElements[i].name + '=' + encodeURIComponent(formElements[i].value);
			}
		}
	}
    
    d = document.getElementById('ScratchPad');

    if (is_ie) {
    	document.getElementById('osxRatingLimitMacOSX').style.visibility = 'hidden';
    	document.getElementById('osxReviewLimitMacOSX').style.visibility = 'hidden';
    	document.getElementById('macRatingLimitMacOS').style.visibility = 'hidden';
    	document.getElementById('macReviewLimitMacOS').style.visibility = 'hidden';
    	document.getElementById('winRatingLimitWindows').style.visibility = 'hidden';
    	document.getElementById('winReviewLimitWindows').style.visibility = 'hidden';
    	document.getElementById('palmRatingLimitPalm').style.visibility = 'hidden';
    	document.getElementById('palmReviewLimitPalm').style.visibility = 'hidden';
    }

	if(xmlhttp) {
		xmlhttpdo('/php/AJAX/account.php?function=saveSelectionFilter&filter=' + filterString.substring(1) + xmlFields );
	}
    showElementPositioned('ScratchPad', -200, -200);
}

function showElementsAgain() {
	if (is_ie) {
    	document.getElementById('osxRatingLimitMacOSX').style.visibility = 'visible';
    	document.getElementById('osxReviewLimitMacOSX').style.visibility = 'visible';
    	document.getElementById('macRatingLimitMacOS').style.visibility = 'visible';
    	document.getElementById('macReviewLimitMacOS').style.visibility = 'visible';
    	document.getElementById('winRatingLimitWindows').style.visibility = 'visible';
    	document.getElementById('winReviewLimitWindows').style.visibility = 'visible';
    	document.getElementById('palmRatingLimitPalm').style.visibility = 'visible';
    	document.getElementById('palmReviewLimitPalm').style.visibility = 'visible';
    }
}

function editModuleSettings( moduleID )
{ 
	var list = document.getElementById("pageList").value;
	d = document.getElementById("ScratchPad");
	d.style.width='400px';
	setInner('Loading....');
	
	if(xmlhttp)
	{
		xmlhttpdo("/php/AJAX/account.php?function=modPrefForm&mid=" + moduleID + '&page=' + list);
	}
	else
	{
		jsrsdo("modPrefForm", Array("'" + moduleID + "'"))
	}
	
	showElementPositioned('ScratchPad', -420, 0);
}

function loadModuleList(page)
{
	d = document.getElementById('AJAXData');
	if(xmlhttp) {
		xmlhttpdo('/php/AJAX/account.php?function=loadModules&page=' + page.value );
	}

}
function setAllModules()
{
	var page = document.getElementById("pageList").value;
	d = document.getElementById('ScratchPad');
	if(xmlhttp) {
		xmlhttpdo('/php/AJAX/account.php?function=setAllModules&page=' + page );
	}
    showElementPositioned('ScratchPad', 0, -200);
}
function setToDefault()
{
	var page = document.getElementById("pageList").value;
	if(xmlhttp) {
		var url = '/php/AJAX/account.php?function=setToDefault&page=' + page;
		xmlhttp.open("GET", url,true);
		xmlhttp.onreadystatechange=function() 
		{
			if (xmlhttp.readyState==4) 
			{
				d = document.getElementById("AJAXData");  
				setInner(xmlhttp.responseText);
				d = document.getElementById('ScratchPad');
				setInner('Modules have been restored to their default value.<div style="text-align:center;"><a href="javascript:hideElement(\'ScratchPad\');">Close Window</a></div>');
				showElementPositioned('ScratchPad', -200, -20);
			}
		}
		xmlhttp.send(null);
	}
}

function saveMailingPrefs(formFields)
{
	var formElements = formFields.elements; 
	var xmlFields = '';
	for (var i=0;i<formFields.length;i++) 
	{
		if( formElements[i].type == 'checkbox' || formElements[i].type == 'radio')
		{
			if( formElements[i].checked )
			{
				xmlFields = xmlFields + '&' + formElements[i].name + '=' + formElements[i].value;
			}
		}
		else
		{
			if( formElements[i].value != '' )
			{
				xmlFields = xmlFields + '&' + formElements[i].name + '=' + formElements[i].value;
			}
		}
	}
    
    d = document.getElementById('ScratchPad');

	if(xmlhttp) {
		xmlhttpdo('/php/AJAX/account.php?function=saveMailingPrefs' + xmlFields );
	}
    showElementPositioned('ScratchPad', 0, -200);
}

function saveDisplayPref(prefForm)
{
	var Theme = prefForm.Theme[getSelectedRadio(prefForm.Theme)].value;
	var UpdateTable = 'updateTable';
	if(canChangeUpdatesTable == 1 )
	{
		UpdateTable = prefForm.UpdateTable[getSelectedRadio(prefForm.UpdateTable)].value;
	}
	
	//d = document.getElementById('updatesTable');
	d = document.getElementById('ScratchPad');
	hideElement('ScratchPad');
	if(xmlhttp)
	{
		xmlhttpdo("/php/jsrpc.php?function=saveDisplayPref&theme=" + Theme + "&updateTable=" + UpdateTable + "&platform=" + CurrentPlatform);
	}
	else
	{
		jsrsdo("saveDisplayPref", Array(Theme, UpdateTable, CurrentPlatform))
	}
	
	window.location.reload();
}

function saveThemePref(Theme)
{
    d = document.getElementById('ScratchPad');
    hideElement('ScratchPad');
	if(xmlhttp)
    {
       xmlhttpdo("/php/jsrpc.php?function=saveThemePref&theme=" + Theme);
    }
    else
    {
        jsrsdo("saveThemePref", Array(Theme))
    }
    
    setActiveStyleSheet(Theme)
}
