NAME = Mail, Calls, SMS Dependent Image
NEED_IFUN_SUPPORT = 1

CAN_EDIT_STYLE = 1

CAN_EDIT_BACKGROUND_IMAGE = [$DEFINITION]/background.png

CAN_ADD_IMAGES = 1

BEGIN_BODY_ONLOAD

	<div id="[$DEF_name]Div" style="display: block;
	[$STYLE_background]
	[$STYLE_background-color]
	[$STYLE_height]
	[$STYLE_width]
	[$STYLE_margin]
	[$STYLE_padding]
	[$STYLE_border]
	[$STYLE_border-top]
	[$STYLE_border-bottom]
	[$STYLE_border-left]
	[$STYLE_border-right]
	[$STYLE_position_element]
	[$STYLE_transform]
	min-height: 1px;
	overflow: hidden;
	">

		<img id="[$DEF_name]Image" src="" alt="" style="display: none;
		width: 100%;
		height: 100%;
		[$STYLE_reflection]
		">

	</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 MailNum = obj.Mail;
		var SMSNum = obj.SMS;
		var CallNum = obj.Call;
		
		//---
		
		[$CONDITIONS]
		
		//---
		
		if (imgPath.length)
		{
			document.getElementById("[$DEF_name]Image").style.display = 'block';
			document.getElementById("[$DEF_name]Image").src = imgPath;
		}
		else
		{
			document.getElementById("[$DEF_name]Image").style.display = 'none';
		}
	}

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

	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.Call 		= DEFAULT_COUNT;
				obj.SMS 		= DEFAULT_COUNT;
				obj.Mail 		= DEFAULT_COUNT;

				[$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);
		
		[$DEF_name]Update(obj);
		delete obj;
	}

END_DEFINITION

BEGIN_DEF

	DEF_name = 
	DEF_interval = 15

END_DEF

BEGIN_COND

END_COND

BEGIN_CONDITION_MENU
	
	BEGIN_CONDITION_ENTRY
		DESC = Ignore
		VAR = 
	END_CONDITION_ENTRY
	
	BEGIN_CONDITION_ENTRY
		DESC = Number of E-Mails
		VAR = MailNum
	END_CONDITION_ENTRY
	
	BEGIN_CONDITION_ENTRY
		DESC = Number of SMS
		VAR = SMSNum
	END_CONDITION_ENTRY
	
	BEGIN_CONDITION_ENTRY
		DESC = Number of Missed Calls
		VAR = CallNum
	END_CONDITION_ENTRY
	
END_CONDITION_MENU

BEGIN_STYLE

	STYLE_background = none;
	STYLE_width = 320px;
	STYLE_height = 480px;
	STYLE_padding = 0px 0px 0px 0px;
	STYLE_position_element = absolute; top: 0px; left: 0px;
	STYLE_background-color = none;
	STYLE_transform = none;
	STYLE_reflection = none;
	STYLE_margin = 0px 0px 0px 0px;
	STYLE_border = none;
	STYLE_border-top = none;
	STYLE_border-bottom = none;
	STYLE_border-left = none;
	STYLE_border-right = none;

END_STYLE
