


// Default functions
 function gebi(id) {return document.getElementById(id)}



function demo_login()
{

	gebi('login_form').login.value = 'demo';
	gebi('login_form').password.value = 'demo';
	document.login_form.submit();


}


function HideOptions()
{

	gebi('options_div').style.display='none';
	gebi('hide_div').style.display='none';
	gebi('show_div').style.display='block';
	map_div.style.left = '0px';
	map_div = document.getElementById('map_canvas');
//	map_div.style.height = getClientHeight() - 100 + 'px';
	map_div.style.width = getClientWidth() + 'px';


}



function ShowOptions()
{

	gebi('options_div').style.display='inline';
	gebi('show_div').style.display='none';
	gebi('hide_div').style.display='block';
	map_div = document.getElementById('map_canvas');
	map_div.style.left = '300px';
//	map_div.style.height = getClientHeight() - 100 + 'px';
	map_div.style.width = getClientWidth() - 300 + 'px';


}


function OnLoadSub()
{

	track_imei = document.getElementById('track_imei').value;

	doResize();


	SetCurentDate();


	initialize();


	InitializeTimer(); 


}

function doResize()
{

	client_width = getClientWidth();
	client_height = getClientHeight();


	if ((document.getElementById('track_imei')))
	{

		map_div = gebi('map_canvas');


		if(gebi('options_div').style.display == 'none')
		{

			map_div.style.width	= client_width + 'px';

			map_div.style.height	= client_height - 75 + 'px';

			gebi('options_div').style.height = client_height - 90 + 'px';


		}
		else
		{

			map_div.style.height	= client_height - 75 + 'px';

			map_div.style.width	= client_width  - 300 + 'px';

			gebi('options_div').style.height = client_height - 90 + 'px';

		}
                              
	}
	else
	{

		var main_page_div		= gebi('main_page_div');

		main_page_div.style.height	= client_height - 95 + 'px';

		main_page_div.style.width	= client_width - 20 + 'px';

	}


}


function ShowAd()
{

//	alert('Нужен сайт?! Звони! +38 050 1 911 300 / Need for site?! Just call! +38 050 1 911 300');

}




function SetCurentDate()
{

//1 минута в миллисекундах
	var minute = 60000; 




	var today = new Date();
  tt = new Date (today - today.getTimezoneOffset()*minute);  //приводим к местному часовому поясу
	var yesterday = new Date(today - 86400000); // 86400000 = 1 сутки
  tt = new Date (yesterday - yesterday.getTimezoneOffset()*minute);  //приводим к местному часовому поясу
//debug(yesterday);

//	document.calendar_form.startLogDate.value = yesterday.getFullYear() + "-" + add0(yesterday.getMonth()+1) + "-" + add0(yesterday.getDate());

	document.calendar_form.startLogDate.value = yesterday.getFullYear() + "-" + add0(today.getMonth()+1) + "-" + add0(today.getDate());
	document.calendar_form.endLogDate.value = today.getFullYear() + "-" + add0(today.getMonth()+1) + "-" + add0(today.getDate());

/*

	var i; 
	var ss;
	for (i=0; i<24; i++)
	{
		ss = add0(i);
		document.calendar_form.startHoursList [i] = new Option (ss, i);
		document.calendar_form.endHoursList [i] = new Option (ss, i);
	}
	for (var i=0; i<60; i++)
	{
		ss = add0(i);
		document.calendar_form.startMinutesList [i] = new Option (ss, i);
		document.calendar_form.endMinutesList [i] = new Option (ss, i);
	}



	document.calendar_form.startHoursList.selectedIndex = yesterday.getHours();
	document.calendar_form.startMinutesList.selectedIndex = yesterday.getMinutes();
	document.calendar_form.endHoursList.selectedIndex = today.getHours();
	document.calendar_form.endMinutesList.selectedIndex = today.getMinutes();	

*/

}


function add0(str)
{
	str = str.toString();
	if (str.length == 1)
	str ="0" + str;
	return str;

}



function SetDateToView()
{

	var start;
	var end;

	var my_calendar = gebi('calendar_form');


	start	= document.calendar_form.startLogDate.value;
	end	= document.calendar_form.endLogDate.value;


//	[document.calendar_form.stat_year_from.value, document.calendar_form.stat_month_from.value, document.calendar_form.stat_day_from.value] = start.split('-');

	document.calendar_form.stat_year_from.value	= (start.split('-'))[0];
	document.calendar_form.stat_month_from.value	= (start.split('-'))[1];
	document.calendar_form.stat_day_from.value	= (start.split('-'))[2];

//	[document.calendar_form.stat_year_to.value, document.calendar_form.stat_month_to.value, document.calendar_form.stat_day_to.value] = end.split('-');

	document.calendar_form.stat_year_to.value	= (end.split('-'))[0];
	document.calendar_form.stat_month_to.value	= (end.split('-'))[1];
	document.calendar_form.stat_day_to.value	= (end.split('-'))[2];

//	document.calendar_form.submit();

//	show_track();

//	alert(


	show_track(


'stat_year_from=' + my_calendar.stat_year_from.value + '&' +
'stat_month_from=' + my_calendar.stat_month_from.value + '&' +
'stat_day_from=' + my_calendar.stat_day_from.value + '&' +
'stat_hour_from=' + my_calendar.stat_hour_from.value + '&' +
'stat_minute_from=' + my_calendar.stat_minute_from.value + '&' +

'stat_year_to=' + my_calendar.stat_year_to.value + '&' +
'stat_month_to=' + my_calendar.stat_month_to.value + '&' +
'stat_day_to=' + my_calendar.stat_day_to.value + '&' +
'stat_hour_to=' + my_calendar.stat_hour_to.value + '&' +
'stat_minute_to=' + my_calendar.stat_minute_to.value + '&' +

'show_chart=' + gebi('show_chart').checked



	);


}

function Getkml()
{

	var start;
	var end;

	var my_calendar = gebi('calendar_form');


	start	= document.calendar_form.startLogDate.value;
	end	= document.calendar_form.endLogDate.value;


//	[document.calendar_form.stat_year_from.value, document.calendar_form.stat_month_from.value, document.calendar_form.stat_day_from.value] = start.split('-');

	document.calendar_form.stat_year_from.value	= (start.split('-'))[0];
	document.calendar_form.stat_month_from.value	= (start.split('-'))[1];
	document.calendar_form.stat_day_from.value	= (start.split('-'))[2];

//	[document.calendar_form.stat_year_to.value, document.calendar_form.stat_month_to.value, document.calendar_form.stat_day_to.value] = end.split('-');

	document.calendar_form.stat_year_to.value	= (end.split('-'))[0];
	document.calendar_form.stat_month_to.value	= (end.split('-'))[1];
	document.calendar_form.stat_day_to.value	= (end.split('-'))[2];

	document.calendar_form.submit();

//	show_track();

//	alert('Hello!');


}


function Show_Names_Popups()
{


	if(gebi('show_names').checked)
	{

		for(var i = 0; i < my_markers.length; i++)
		{

			my_markers[i].showPopup();

		}

	}
	else
	{

		for(var i = 0; i < my_markers.length; i++)
		{

			my_markers[i].hidePopup();

		}

	}

}



function getClientWidth()
{

	return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;

}

function getClientHeight()
{

	return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;

}


function FollowObject()
{

	ReadVar( '/last_coord.htm', '');

/*

	for (var i = 0; i <= imei_counter-1; i++)
	{

		ReadVar( '/cgi-bin/read_last.cgi?track_imei=' + i , '', i);

	}

*/

}

