function getResults(SORT){
	document.getElementById("searchMessage").innerHTML = "";
	document.getElementById("searchResults").innerHTML="<I>Searching DVDs...</I>";
	var SEARCH_PARAMS = getFormValues("searchForm","GET");
	xmlHttp = createAjaxObject();
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4){
			document.getElementById("searchResults").innerHTML=xmlHttp.responseText;
		}
	}
	SEARCH_PARAMS += "&SORT=" + SORT;
	xmlHttp.open("GET","list.php?" + SEARCH_PARAMS,true);
	xmlHttp.send(null);
	//return true;
}

function getDVDDetail(DVD_ID,MODIFY,TITLE,DEFAULT_ASIN){
	if (typeof MODIFY == "undefined") {
		MODIFY = false;
	}
	if (typeof TITLE == "undefined") {
		TITLE = "";
	}
	if (typeof DEFAULT_ASIN == "undefined") {
		DEFAULT_ASIN = "";
	}
	
	if(MODIFY==true){
		LOAD_MESSAGE = "Loading DVD Information for Modification";
		if(DEFAULT_ASIN != ""){
			LOAD_MESSAGE += " with defaults from Amazon";
		}
	} else {
		LOAD_MESSAGE = "Loading DVD Information";
	}
	document.getElementById("searchResults").innerHTML="<I>" + LOAD_MESSAGE + "...</I>";
	xmlHttp = createAjaxObject();
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4){
			document.getElementById("searchResults").innerHTML=xmlHttp.responseText;
		}
	}
	if(MODIFY==true){
		PAGE = "modify.php";
	} else {
		PAGE = "info.php";
	}
	
	PARAMS = "";
	if(TITLE != ""){
		PARAMS += "&DVD_TITLE=" + TITLE;
	}
	if (DEFAULT_ASIN != "") {
		PARAMS += "&ASIN=" + DEFAULT_ASIN;
	}
	xmlHttp.open("GET",PAGE + "?DVD_ID=" + DVD_ID + PARAMS,true);
	xmlHttp.send(null);
	//return true;
}


function addDVD(ADD_FORM){
	ADD_FORM.submitButton.disabled = true;
	getDVDDetail(0,true,ADD_FORM.DVD_TITLE.value);
}


function updateDVD(UPDATE_FORM){
	document.getElementById("searchMessage").innerHTML = "";
	UPDATE_FORM.submitButton.disabled = true;
	UPDATE_VALUES = getFormValues(UPDATE_FORM); 
	UPDATE_VALUES += "&modify=true";
	document.getElementById("searchResults").innerHTML="<I>Adding DVD Info...</I>";
	xmlHttp = createAjaxObject();
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4){
			document.getElementById("searchResults").innerHTML=xmlHttp.responseText;
		}
	}
	xmlHttp.open("POST","info.php",true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
     xmlHttp.setRequestHeader("Content-length", UPDATE_VALUES.length);
     xmlHttp.send(UPDATE_VALUES);
	//document.getElementById("searchMessage").innerHTML="";
	return;
}

function deleteDVD(DVD_ID,CONFIRM){
	if(CONFIRM!=true){
		PAGE = "delete.php?DVD_ID=" + DVD_ID;
	} else {
		PAGE = "delete.php?DELETE_CONFRIM=true&DVD_ID=" + DVD_ID;
	}
	//var SEARCH_PARAMS = getFormValues(searchForm,"GET");
	xmlHttp = createAjaxObject();
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4){
			document.getElementById("searchResults").innerHTML=xmlHttp.responseText;
		}
	}
	// + "&" + SEARCH_PARAMS
	xmlHttp.open("GET",PAGE,true);
	xmlHttp.send(null);
	//return true;
}


function updatePreview(){
	document.getElementById("descriptionPreview").innerHTML = modifyDVD.DESCRIPTION.value;
	return true;
}

function updateLocation(DVD_ID,LIBRARY_ID,LIBRARY_LOCATION){
	document.getElementById("searchMessage").innerHTML = "Update " + DVD_ID + " to " + LIBRARY_ID + " - " + LIBRARY_LOCATION;
	xmlHttp = createAjaxObject();
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4){
			document.getElementById("searchMessage").innerHTML = xmlHttp.responseText;
		}
	}
	PAGE = "update.php?TYPE=LIBRARY&DVD_ID=" + DVD_ID + "&LIBRARY_ID=" + LIBRARY_ID + "&LIBRARY_LOCATION=" + LIBRARY_LOCATION;
	xmlHttp.open("GET",PAGE,true);
	xmlHttp.send(null);
	return;
}

function rateDVD(DVD_ID,RATING,PERSON_NAME){
	document.getElementById("currentRating_" + DVD_ID).style.width = (RATING * 20) + "%";
	PAGE = "update.php?TYPE=RATING&DVD_ID=" + DVD_ID + "&RATING=" + RATING;
	xmlHttp = createAjaxObject();
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4){
			document.getElementById("searchMessage").innerHTML = xmlHttp.responseText;
		}
	}	
	xmlHttp.open("GET",PAGE,true);
	xmlHttp.send(null);
}
