function loadXMLDoc(url, type) {
	if(type == "search") {
		getObject("searchResult").style.display = "block";
		getObject("searchResult").innerHTML = "Searching...";
	}
   // Internet Explorer
   try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
   catch(e) {
      try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
      catch(oc) { req = null; }
   }

   // Mozailla/Safari
   if (!req && typeof XMLHttpRequest != "undefined") { req = new XMLHttpRequest(); }

   // Call the processChange() function when the page has loaded
   if (req != null) {
		if(type == "search") {
			req.onreadystatechange = processChange;
		} else if (type == "broken") {
			req.onreadystatechange = processBroken;
		} else if (type == "radio") {
			req.onreadystatechange = processRadio;
		} else if (type == "bookmark") {
			req.onreadystatechange = processBookmark;
		}
		req.open("GET", url, true);
		req.send(null);
   }
}

function processChange() {
	// The page has loaded and the HTTP status code is 200 OK
	if (req.readyState == 4 && req.status == 200) {
		// Write the contents of this URL to the searchResult layer
		document.getElementById("searchResult").style.display = "block";
		document.getElementById("searchResult").style.visibility = "visible";
		getObject("searchResult").innerHTML = req.responseText;
		totaltext = req.responseText.length;
		if (totaltext == 1 || totaltext == 3 || totaltext == 2) {
			document.getElementById("searchResult").style.display = "none";
		}
	}
}

function processBroken() {
	// The page has loaded and the HTTP status code is 200 OK
	if (req.readyState == 4 && req.status == 200) {
		// Write the contents of this URL to the searchResult layer
		getObject("functiontext").innerHTML = req.responseText;
	}
}
function processRadio() {
	// The page has loaded and the HTTP status code is 200 OK
	if (req.readyState == 4 && req.status == 200) {
		// Write the contents of this URL to the searchResult layer
		getObject("functiontext").innerHTML = req.responseText;
	}
}
function processBookmark() {
	// The page has loaded and the HTTP status code is 200 OK
	if (req.readyState == 4 && req.status == 200) {
		// Write the contents of this URL to the searchResult layer
		getObject("functiontext").innerHTML = req.responseText;
	}
}

function getObject(name) {
   var ns4 = (document.layers) ? true : false;
   var w3c = (document.getElementById) ? true : false;
   var ie4 = (document.all) ? true : false;

   if (ns4) return eval('document.' + name);
   if (w3c) return document.getElementById(name);
   if (ie4) return eval('document.all.' + name);
   return false;
}

function DoSmilie(smilecode) {
	var CurrentMessage = document.getElementById('MPIII_CommentBox').value;
	var NewMessage = CurrentMessage+" "+smilecode+" ";
	document.getElementById('MPIII_CommentBox').value = NewMessage;
}
function VerifyForm() {
	var ThisDownloadID = Form.Element.getValue('ThisDownloadID');
	var ratingcomments = Form.Element.getValue('MPIII_CommentBox');
	document.getElementById('MPIII_CommentSubmit').disabled = true;
	if (ratingcomments.length <= 200) {
		alert('Your comments are not thorough enough.\n\nThey need to be at least 200 characters!\n\nPut some effort into it!');
		document.getElementById('MPIII_CommentBox').focus();
		document.getElementById('MPIII_CommentSubmit').disabled = false;
		return false;	
	}
	document.getElementById('MPIII_DownloadID').value=ThisDownloadID;
	return true;
}
function JumpToGenre(subid) {
	window.location='dl_sub.php?sid='+subid;
}
function JumpToCat(catid) {
	if(catid == "1" || catid == "3" || catid == "5") {
		window.location='dl_cat.php?cid='+catid;
	} else if (catid == "2" || catid == "6" || catid == "7") {
		window.location='dl_sub.php?cid='+catid;
	}
}

var thumb = 0;
var quality_rating = 0;
var overall_rating = 0;

function feedback(type, value) {
	if(type == "thumbs") {
		thumb = value;	
		loadRating("ajax_rating1.php");
	} else if(type == "quality") {
		quality_rating = value;	
		loadRating("ajax_rating2.php");
	} else if(type == "overall") {
		overall_rating = value;	
	}
	if(thumb != 0 && quality_rating != 0 && overall_rating != 0) {
		feedbackSubmit('ajax_feedback.php');
	}
	return;
}

function loadRating(url) {
	new Ajax.Updater({ success: 'FeedbackDiv', failure: 'FeedbackDiv' }, url, {
		method:'get'
	});
}

function feedbackSubmit(url) {
	var ThisDownloadID = Form.Element.getValue('ThisDownloadID');
	new Ajax.Updater({ success: 'FeedbackDiv', failure: 'FeedbackDiv' }, url, {
		method:'post',
		parameters: '?thumb='+thumb+'&quality='+quality_rating+'&overall='+overall_rating+'&DownloadID='+ThisDownloadID
	});
}


