// FUNCTION TO UPDATE PRODUCT TYPES ON SCREEN
function fnSelectFolder(){
	var mid = document.getElementById('mid').value;
	// NOW REFRESH THE SELECT
	var URL = "scripts/updateFolderList.asp?mid=" + mid
	fn_xmlReq (URL , fnSelectFolderUpdate);
}
function fnSelectFolderUpdate(){
	if (xmlReqReturnValue == 'none'){
		document.getElementById('selectFolder').innerHTML = '';
		document.getElementById('selectFolderTD').style.display = "none";
	} else {
		document.getElementById('selectFolder').innerHTML = xmlReqReturnValue;
		document.getElementById('selectFolderTD').style.display = "";
	}
}

// FUNCTION TO ADD DOWNLOAD
var act_id
function fnAddDownload(posting_id,action_id){
	var URL = "scripts/updateDownloadList.asp?id=" + posting_id + "&act=" + action_id
	act_id = action_id;
	fn_xmlReq (URL , fnAddDownloadUpdate);
}
function fnAddDownloadUpdate(){
	alert(xmlReqReturnValue);
	if (act_id != 0){
		fnRefreshDownloadList()
	}
}

function fnRefreshDownloadList(){
	var URL = "scripts/updateDownloadList.asp?act=99"
	fn_xmlReq (URL , fnRefreshDownloadListUpdate);
}
function fnRefreshDownloadListUpdate(){
	document.getElementById('downloadlist').innerHTML = xmlReqReturnValue;
}

function fnClearDownload(){
	if (confirm('Are you sure you want to clear your Download List?')){
		var URL = "scripts/updateDownloadList.asp?act=88"
		fn_xmlReq (URL , fnClearDownloadUpdate);
	}
}
function fnClearDownloadUpdate(){
	alert( xmlReqReturnValue) ;
	document.getElementById('downloadlist').innerHTML = "";
}

var xmlReqReturnValue 
// FUNCTION TO SEND XML REQUESTS
function fn_xmlReq(passedURL,theFunction){

	passedURL = passedURL + "&rnd=" + Math.random();

	xmlReq = null;
	if(window.XMLHttpRequest) xmlReq = new XMLHttpRequest();
	else if(window.ActiveXObject) xmlReq = new ActiveXObject("Microsoft.XMLHTTP");
	if(xmlReq==null) return; // Failed to create the request

	xmlReq.onreadystatechange = function()
	{
		switch(xmlReq.readyState)
		{
		case 0: // Uninitialized
			break;
		case 1: // Loading
			break;
		case 2: // Loaded
			break;
		case 3: // Interactive
			break;
		case 4: // Done!
			xmlReqReturnValue = xmlReq.responseText;
			theFunction()
			break;
		default:
			break;
      }
    }
	xmlReq.open ('GET', passedURL, true);
	xmlReq.send (null);
}