NAME = System Info
NEED_IFUN_SUPPORT = 1

CAN_EDIT_STYLE = 1
CAN_EDIT_STRINGS = 1

CAN_EDIT_BACKGROUND_IMAGE = [$DEFINITION]/background.png

BEGIN_BODY_ONLOAD

	<div id="[$DEF_name]Div" style="
	[$STYLE_background]
	[$STYLE_background-color]
	[$STYLE_color]
	[$STYLE_text-shadow]
	[$STYLE_font-family]
	[$STYLE_font-weight]
	[$STYLE_font-size]
	[$STYLE_height]
	[$STYLE_width]
	[$STYLE_margin]
	[$STYLE_padding]
	[$STYLE_font-style]
	[$STYLE_word-spacing]
	[$STYLE_text-align]
	[$STYLE_text-indent]
	[$STYLE_text-transform]
	[$STYLE_text-decoration]
	[$STYLE_line-height]
	[$STYLE_border]
	[$STYLE_border-top]
	[$STYLE_border-bottom]
	[$STYLE_border-left]
	[$STYLE_border-right]
	[$STYLE_position_element]
	[$STYLE_transform]
	min-height: 10px;
	overflow: hidden;
	">

		<span id="[$DEF_name]Text" style="display: block;
		[$STYLE_position_content]
		[$STYLE_reflection]
		">
		</span>

	</div>

END_BODY_ONLOAD

BEGIN_ONLOAD

  [$DEF_name]Load();

END_ONLOAD

BEGIN_DEFINITION

	var [$DEF_name]Interval 	= 1000 * [$DEF_interval];
	var [$DEF_name]IntervalID 	= 0;
	var [$DEF_name]LastShown 	= 0;

	//-------------------------------------------------------------

	function [$DEF_name]Update(obj)
	{
		var FormatStr = "[$DEF_format]";
		var theText;
		var theStr;
		
		theText = FormatStr;
		//---
	  	{
			theText = theText.replace(/\$SPACE_USED/g, obj.SpaceUsed);
		}
		//---
	  	{
			theText = theText.replace(/\$PHONE_NUMBER/g, obj.Phone);
		}
		//---
	  	{
			theText = theText.replace(/\$LANGUAGE/g, obj.Language);
		}
		//---
		
		document.getElementById("[$DEF_name]Text").style.display = 'block';
		document.getElementById("[$DEF_name]Text").innerHTML = theText;
	}
	
	//-------------------------------------------------------------

	function [$DEF_name]Load()
	{
		var CurrentTimestamp = new Date();
		var CurrentTime = CurrentTimestamp.getTime();
		
		delete CurrentTimestamp;
		
		if ([$DEF_name]LastShown + [$DEF_name]Interval - 1000 <= CurrentTime)
		{
			var obj = {error:false, errorString:null};
				
			if (ON_DEVICE)
			{
				url = "/tmp/WidgetInfo.xml";

				var xmlReq = new XMLHttpRequest();
				xmlReq.onreadystatechange = function(e){[$DEF_name]Callback(e, xmlReq);}
				xmlReq.overrideMimeType("text/xml");
				xmlReq.open("GET", url, false); // synchronous!
				xmlReq.setRequestHeader("Cache-Control", "no-cache");
				xmlReq.setRequestHeader("wx", "385");
				xmlReq.send(null); 
			}
			else
			{
				obj.SpaceUsed	= 17;
				obj.Phone	= "1 (222) 555-1212";
				obj.Language	= "en";

				[$DEF_name]Update(obj);
			}
			
			delete obj;

			var CurrentTimestamp = new Date();
			[$DEF_name]LastShown = CurrentTimestamp.getTime();
			delete CurrentTimestamp;
		}

		if ([$DEF_name]IntervalID)
		{
			clearInterval( [$DEF_name]IntervalID );
			[$DEF_name]IntervalID = 0;
		}
		
		if ([$DEF_name]Interval)
			[$DEF_name]IntervalID = setInterval([$DEF_name]Load, [$DEF_name]Interval);
	}
	
	//-------------------------------------------------------------

	function [$DEF_name]Callback(event, xmlReq)
	{
		if (xmlReq.readyState != 4)						return;
		if (xmlReq.status != 200 && xmlReq.status != 0)	return;
		if (!xmlReq.responseXML)						return;

		var obj = {error:false, errorString:null};

		var Database = findChild(xmlReq.responseXML, "bSE_Database");
		
		/*
		tag = findChild(Database, "Mail");
		obj.Mail = parseInt(trimWhiteSpace(tag.firstChild.data), 10);

		tag = findChild(Database, "SMS");
		obj.SMS = parseInt(trimWhiteSpace(tag.firstChild.data), 10);

		tag = findChild(Database, "Call");
		obj.Call = parseInt(trimWhiteSpace(tag.firstChild.data), 10);
		*/
		
		//---
		
		tag = findChild(Database, "SpaceUsed");
		obj.SpaceUsed = parseInt(trimWhiteSpace(tag.firstChild.data), 10);
		
		tag = findChild(Database, "Phone");
		obj.Phone = trimWhiteSpace(tag.firstChild.data);

		tag = findChild(Database, "Language");
		obj.Language = trimWhiteSpace(tag.firstChild.data);

		[$DEF_name]Update(obj);
		delete obj;
	}
	
END_DEFINITION

BEGIN_DEF

	DEF_name = 
	DEF_interval = 15
	DEF_iconSize = 12
	DEF_format = [$SPACE_USED% Used<br>$PHONE_NUMBER]

END_DEF

BEGIN_FORMAT_MENU
	
	BEGIN_FORMAT_ENTRY
		CODE = 1
		DESC = Default (All)
		FORMAT = $SPACE_USED% Used<br>$PHONE_NUMBER<br>$LANGUAGE
	END_FORMAT_ENTRY

	//---
	
	BEGIN_FORMAT_ENTRY
		CODE = 0
		DESC = Disk Space Used (Percent)
		FORMAT = $SPACE_USED
	END_FORMAT_ENTRY

	BEGIN_FORMAT_ENTRY
		CODE = 0
		DESC = My Phone Number
		FORMAT = $PHONE_NUMBER
	END_FORMAT_ENTRY
	
	BEGIN_FORMAT_ENTRY
		CODE = 0
		DESC = Current Language (Code)
		FORMAT = $LANGUAGE
	END_FORMAT_ENTRY
		
END_FORMAT_MENU

BEGIN_STYLE

	STYLE_position_element = 0px 0px;
	STYLE_position_content = 0px 0px;
	STYLE_transform = none;
	STYLE_padding = 4px 4px 4px 4px;
	STYLE_reflection = none;
	STYLE_font-size = 12px;
	STYLE_text-align = left;
	STYLE_height = auto;
	STYLE_width = auto;
	STYLE_background-color = none;
	STYLE_margin = 0px 0px 0px 0px;
	STYLE_border = none;
	STYLE_text-shadow = 4px 4px 4px rgba(0, 0, 0, 0.75);
	STYLE_font-family = Helvetica;
	STYLE_font-weight = bold;
	STYLE_color = rgba(255, 128, 128, 1);

	STYLE_background = 
	STYLE_font-style = 
	STYLE_word-spacing = 
	STYLE_text-align = 
	STYLE_text-indent = 
	STYLE_text-transform = 
	STYLE_text-decoration = 
	STYLE_line-height = 
	STYLE_border-top = 
	STYLE_border-bottom = 
	STYLE_border-left = 
	STYLE_border-right = 

END_STYLE
