var Skyeye = new Class(
{
	initialize : function()
	{
	},

	GetLatLongFormat:function(value)
	{
		var arr = value.split(".");
		var number = parseInt(arr[0].substr(1));
		var test = 0 + "."+  arr[2];
		number = Math.round(test*60);
		return arr[0]+"&deg;"+arr[1]+"'"+number+"\"";
	},

	ConvertLatLong:function(value)
	{
		var arr = value.split(".");
		var number = parseInt(arr[0].substr(1));
		var test = arr[1] + "."+  arr[2];
		number = number + test/60;

		if (arr[0].substr(0, 1) == "N" || arr[0].substr(0, 1) == "E")
			return number;
		return -number;
	},
	
	DateTimeFormat:function(date, time, at)
	{
		var arr = date.split("-");
		var result = arr[2]+"/"+arr[1] + " " + arr[0];
		arr = time.split(":");
		result += " " + at +" <strong>" + arr[0]+"."+arr[1]+"</strong>" ;
		return result;
	},
	
	GetDirectionFormat:function(direction, excludegree)
	{
		var format = "";
		if (0 <= direction && direction < 22.5)
			format = "N";
		if (22.5 <= direction && direction < 45)
			format = "N-NE";
		if (45 <= direction && direction < 67.5)
			format = "NE";
		if (67.5 <= direction && direction < 90)
			format = "E-NE";
		if (90 <= direction && direction < 112.5)
			format = "E";
		if (112.5 <= direction && direction < 135)
			format = "E-SE";
		if (135 <= direction && direction < 157.5)
			format = "SE";
		if (157.5 <= direction && direction < 180)
			format = "S-SE";
		if (180 <= direction && direction < 202.5)
			format = "S";
		if (202.5 <= direction && direction < 225)
			format = "S-SW";
		if (225 <= direction && direction < 247.5)
			format = "SW";
		if (247.5 <= direction && direction < 270)
			format = "W-SW";
		if (270 <= direction && direction < 292.5)
			format = "W";
		if (292.5 <= direction && direction < 315)
			format = "W-NW";
		if (315 <= direction && direction < 337.5)
			format = "NW";
		if (337.5 <= direction && direction < 360)
			format = "N-NW";
			
		if (excludegree == true)
			format += " / " + direction + "&deg;";
			
		return format;
	},
	
	GetBatteryFormat : function(battery, complexview)
	{	
		if(complexview == true)
		{
			if (battery <3500)
				return "0%";
			if (battery > 4200)
				return "100%";
			return (Math.round((battery - 3500) * 100 / (4200 - 3500)) + "%");
		}
	},
	
	GetGSMSignalFormat : function(signal, complexview)
	{
		
		if(complexview == true)
		{
			if (signal <= -110)
				return 'No signal';
			if (-109 <= signal && signal <= -100)
				return 'Low';
			if (-99 <= signal && signal <= -90)
				return 'Low/medium';
			if (-89 <= signal && signal <= -80)
				return 'Medium';
			if (-79 <= signal && signal <= -72)
				return 'Medium/high';
			if (-71 <= signal)
				return 'High';			
		}
	},
	
	GetPowerSourceFormat : function(unitstate)
	{
		var status = parseInt(unitstate, 16);
		var bit1 = status >> 1 & 0x1;
		var bit0 = status >> 0 & 0x1;
		if (bit1 == 1 && bit0 == 1)
		// Lader tilsluttet og fuldt opladet
		return 0;    
		else if (bit1 == 1 && bit0 == 0)
		// oplader i øjeblikket
		return 0;
		else if (bit1 == 0 && bit0 == 0)
		// Lader ikke tilsluttet
		return 1;    
		else if (bit1 == 0 && bit0 == 1)
		// Oplader tilsluttet
		return 0;
		// Ukendt status!!
		else return 0;
		
	},
	
	GetUnitState : function(unitstate)
	{
		var status = parseInt(unitstate, 16);
		var bit8 = status >> 8 & 0x1;
		
		if (bit8 == 1)
			return true;
		else
			return false;
	},

	GetEvent:function (yearfrom, monthfrom, dayfrom, yearto, monthto, dayto, callBackFunc)
	{
		var opt = {
			method:"post",
			url:"index.php?tmpl=component",
			data:"option=com_skyeye&task=JSCallSkyEye&func=GetEvent&yearfrom="+yearfrom+"&monthfrom="+monthfrom+"&dayfrom="+dayfrom+
				"&yearto="+yearto+"&monthto="+monthto+"&dayto="+dayto,
			onComplete: function (result) {
					var data = eval(result);
					callBackFunc(data);
				}
		};
		
		new Request(opt).send();
	},
	
	ProcessPayment : function(amount, cardnumber, expiredate, csv, callBackFunc)
	{
		var opt = {
			method:"post",
			url:"index.php?tmpl=component",
			data:"option=com_skyeye&task=ProcessPayment&amount="+amount+"&cardnumber="+cardnumber+"&expiredate="+expiredate+"&csv="+csv,
			onComplete: function (result) {
					var data = eval(result);
					callBackFunc(data);
			}
		};
		new Request(opt).send();
	},
	
	
	getPositionHistory : function(sid, year, month, day, callBackFunc)
	{
		var opt = {
			method:"post",
			url:"index.php?tmpl=component",
			data:"option=com_skyeye&task=JSCallSkyEye&func=GetPositionHistory&year="+year+"&month="+month+"&day="+day,
			onComplete: function (result) {
					var data = eval("(" + result + ")");
					callBackFunc(data);
				}
		};
	
		new Request(opt).send();

		//var obj = new Ajax(links, opt).request();		
	},
	
	getNearestAddr:function(sid, lat, long, callBackFunc)
	{
		var opt = {
			method:"post",
			url:"index.php?tmpl=component",
			data:"option=com_skyeye&task=JSCallSkyEye&func=NearestAddress&lat="+lat+"&long="+long,
			onComplete: function (result) {
					var data = eval("(" + result + ")");
					callBackFunc(data);
				}
		};
		new Request(opt).send();
	},
	
	getLatestPos : function(sid, posformat, localtion, callBackFunc)
	{
		var opt= {
			method:"post",
			url:"index.php?tmpl=component",
			data: "option=com_skyeye&task=JSCallSkyEye&func=GetLatestPosition",
			onComplete: function (result) {
					var data = eval(result);
					callBackFunc(data);
				}
		};
		
		new Request(opt).send();
	},
	
	SaveMode:function(mode)
	{
		var opt= {
			method:"post",
			url:"index.php?tmpl=component",
			data: "option=com_skyeye&task=savemode&mode="+mode,
			onComplete: function (result) {
				}
		};
		
		new Request(opt).send();
		
	},
	
	getMode:function()
	{
		return Cookie.read("map_mode");
	},
	
	showPopupByDate:function(curdate, posindex)
	{
		window.open('index.php?option=com_skyeye&tmpl=component&view=skyeye&layout=print&date='+curdate+'&posindex='+posindex, 'PrintPage', 'width=600, height=850, top=0, left=0, scrollbars=yes');
		//window.open("index2.php?option=com_skyeye&view=skyeye&layout=print&date="+curdate+"&posindex="+posindex, "Print Page", "menubar=no, width=600, height=850, toolbar=no, scrollbars=yes");
		
	}
	
});