//Script by Kyle Baker (Last Modified: 2007/09/21)
//http://www.kyleabaker.com/
//Feel free to use this script, and modify it anyway you wish. All I ask is that you please leave the first three lines in at all times.

//README: There are only 5 small things that need to be edited in this file for your update to work. They are numbered below.
//			You will also need to add 'onload="UpdateCheck();"' to the body tag in the html file so the update is performed
//			when the widget is launched. You also need an empty div with the id 'divUpdate' to display the result of the update
//			check. Make sure the 'divUpdate' div has 'style="display:none;"' in the tag. Example:
//			<div id="divUpdate" style="display:none;"></div>
//			Also, make sure to add the script between the head tag in the html file:
//			<script type="text/javascript" src="update.js"></script>

	// 1. Widget name
var name="My Widget's Name Here";
	// 2. Current widget version as an number/double
var version=1.01;
	// 3. URL to your widget page at widgets.opera.com
var url="http://widgets.opera.com/widget/6580";
	// 4. Do you want divUpdate to be visible after update check if no update was found? true/false
var bNoUpdate=false;
	// 5. Do you want divUpdate to be visible after update check if an update is found? true/false
var bUpdate=true;

//***************************************************************************************
//No need to edit beyond this point, unless you want to edit the update message displayed.
function UpdateCheck(){
	var requestUpdate = new XMLHttpRequest();
	requestUpdate.onreadystatechange = function() {
		var temp, tempindex;
		if(requestUpdate.readyState === 4) {
			if(requestUpdate.responseText === "") {
				return;
			}
			temp = requestUpdate.responseText;
			tempindex = temp.indexOf('Version:</strong> ')+18;
			temp = temp.substr(tempindex);
			tempindex = temp.indexOf('</span> ');
			temp = temp.substr(0,tempindex);
			if (temp > version) {
				document.getElementById('divUpdate').innerHTML = "<font size='1' color='#FFFFFF'><b>"+name+" "+version+" - <a href='"+url+"' style='color:#FFFFFF'>Update!: v"+temp+"</a></font>";
				if (bUpdate) { document.getElementById('divUpdate').style.display="inline"; }
			} else {
				document.getElementById('divUpdate').innerHTML = "<font size='1' color='#FFFFFF'><b>"+name+" "+version+" - <a href='"+url+"' style='color:#FFFFFF'>Up-to-date!</a></font>";
				if (bNoUpdate) { document.getElementById('divUpdate').style.display="inline"; }
			}
			//requestUpdate.close();
		}
	};
	requestUpdate.open("GET", url);
	requestUpdate.send();
}