var ajaxObjects = new Array();

function filterData(name,path){
	var serverSideFile = path + "/include/request.php";
	var ajaxIndex = ajaxObjects.length;
	var item = document.getElementById(name).options[document.getElementById(name).selectedIndex].value;

	ajaxObjects[ajaxIndex] = new sack();
	ajaxObjects[ajaxIndex].requestFile = serverSideFile;
	ajaxObjects[ajaxIndex].setVar('item',item);
	ajaxObjects[ajaxIndex].setVar('command',name);
	ajaxObjects[ajaxIndex].onCompletion = function(){ showFilterResults(name,ajaxIndex); };
	ajaxObjects[ajaxIndex].runAJAX();	
}

function showFilterResults(name,ajaxIndex){ 
	
	var requestSub = ajaxObjects[ajaxIndex].response.split("###");

	var objCategory = document.getElementById("category");		
	removeOption(objCategory);
	
	objCategory.options[0] = new Option("- Select One -","0");
	if(requestSub != 0){
		if(requestSub.length > 0){
			for(var i = 0; i < requestSub.length; i++){
				var optionsArr = requestSub[i].split("|||");
				objCategory.options[i + 1] = new Option(optionsArr[1],optionsArr[0]);
			}
		}
	}
	
	ajaxObjects[ajaxIndex] = false;
}

function removeOption(obj)
{
	for (var i = obj.length; i > 0; i--) {
		obj.remove(i);
	}
}

function xonload() {
    $("#loading").hide();
	document.getElementById('frame').style.visibility = 'visible';
}

function startIndicator() {
	setIntervalId = setInterval(closeIndicator, 3000);   
}

function closeIndicator() {      
    $("#loading").hide();
    clearInterval(setIntervalId);       
	document.getElementById('frame').style.visibility = 'visible';
} 								
