window.onload=function(){
	program(1,1,1);
	clock();
	var a=setTimeout('timer()',991);
	}



function reload(){
var xmlhttp;
if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }
else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{ document.getElementById('footer').innerHTML=xmlhttp.responseText;
} }
xmlhttp.open("GET","embedded/pages/footer.php",true);
xmlhttp.send();
}


function date_select(str){
var xmlhttp;
if (str.length==0) { document.getElementById("date_out").innerHTML=""; return; }
if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }
else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{ 
document.getElementById("date_out").innerHTML=xmlhttp.responseText; 
} 
}
xmlhttp.open("GET","./embedded/functions/date_select.php?q="+str,true);
xmlhttp.send();
}

function day_select(str,str1){
var xmlhttp;
if (str.length==0) { document.getElementById("cday").innerHTML=""; return; }
if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }
else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{ document.getElementById("cday").innerHTML=xmlhttp.responseText; } }
xmlhttp.open("GET","./embedded/functions/day.php?m="+str+"&d="+str1,true);
xmlhttp.send();
}

function day_select_d(str,str1){
var xmlhttp;
if (str.length==0) { document.getElementById("cdayd").innerHTML=""; return; }
if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }
else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{ 
document.getElementById("cdayd").innerHTML=xmlhttp.responseText; } }
xmlhttp.open("GET","./embedded/functions/day.php?m="+str+"&d="+str1,true);
xmlhttp.send();
}

function date_select_d(str){
var xmlhttp;
if (str.length==0) { document.getElementById("date_out_d").innerHTML=""; return; }
if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }
else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{ document.getElementById("date_out_d").innerHTML=xmlhttp.responseText; } }
xmlhttp.open("GET","./embedded/functions/date_select_d.php?q="+str,true);
xmlhttp.send();
}

function sensors_chart(){
var xmlhttp;
var str = document.getElementById("sensors_list").value;
var str1 = document.getElementById("period_list").value;
var day; var month; var week;
if(str1!="")
{
if (str1 =="day" )
	{
	str2 = document.getElementById("month").value;
	if (str2 =="month")
		{
		str4="no";
		}
	else
		{
		if(document.getElementById("day")!=null)
			{
			str4 = document.getElementById("day").value;
			}
		else
			{
			str4='';
			}
		}
	str3 = 'no';
	}
else if (str1 =="week")
	{
	str2 = document.getElementById("month").value;
	str3 = document.getElementById("week").value;
	str4 = 'no';
	}
else if (str1=="month")
	{
	str2 = document.getElementById("month").value;
	str3 = 'no';
	str4 = 'no';
	}
else if (str1=="year")
	{
	str2 = document.getElementById("year").value;
	str3 = str4 = str2;
	}
}
else
{
str4=str3=str2=str1=str='' ;
}


if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }
else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{ document.getElementById("chart_s").innerHTML=xmlhttp.responseText; 
} }
xmlhttp.open("GET","./embedded/functions/chart_sensor.php?s="+str+"&p="+str1+"&m="+str2+"&w="+str3+"&d="+str4,true);
xmlhttp.send();
}		

function device_chart(){
var xmlhttp;
var str = document.getElementById("device_list").value;
var str1 = document.getElementById("period_list_d").value;
var day; var month; var week;
if(str1!="")
{
if (str1 =="day" )
	{
	str2 = document.getElementById("month_d").value;
	if (str2 =="month")
		{
		str4="no";
		}
	else
		{
		if(document.getElementById("day_d")!=null)
			{
			str4 = document.getElementById("day_d").value;
			}
		else
			{
			str4='';
			}
		}
	str3 = 'no';
	}
else if (str1 =="week")
	{
	str2 = document.getElementById("month_d").value;
	str3 = document.getElementById("week_d").value;
	str4 = 'no';
	}
else if (str1=="month")
	{
	str2 = document.getElementById("month_d").value;
	str3 = 'no';
	str4 = 'no';
	}
else if (str1=="year")
	{
	str2 = document.getElementById("year_d").value;
	str3 = str4 = str2;
	alert(str2);
	}
}
else
{
str4=str3=str2=str1=str='' ;
}
if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }
else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{ document.getElementById("chart_d").innerHTML=xmlhttp.responseText;} }
xmlhttp.open("GET","./embedded/functions/chart_device.php?s="+str+"&p="+str1+"&dm="+str2+"&dw="+str3+"&dd="+str4,true);
xmlhttp.send();
}	


function submit_check_index()
{
if (document.getElementById("submit_check").innerHTML!="")
	{
	document.getElementById("submit_check").innerHTML="";
	}
}
function bigger(str)
{
var id;
var graph;
if (str==1)
	{
	id="sensor_image";
	graph="chart_graph";
	}
else
	{
	id="device_image";
	graph="device_graph";
	}
var graph1=graph+"1";
if (document.getElementById(id).className==graph)
	{
	document.getElementById(id).className=graph1;
	}
else
	{
	document.getElementById(id).className=graph;
	}

}

function notice(str)
{
if (str==1)
	{
	document.getElementById("overview_notice").style.visibility="visible";
	}
else
	{
	document.getElementById("overview_notice").style.visibility="hidden";
	}
}

function clock(){
var xmlhttp;
if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }
else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{ 
document.getElementById("clock").innerHTML=xmlhttp.responseText;
} }
xmlhttp.open("GET","embedded/functions/clock.php",true);
xmlhttp.send();
}

function timer()
{

h=document.getElementById("h").innerHTML;
m=document.getElementById("m").innerHTML;
s=document.getElementById("s").innerHTML;
s++;
if(s<10)
	{
	s="0"+s;
	}
if (s==60)
	{
	s="00";
	m++;
	if(m<10)
		{
		m="0"+m;
		}
	document.getElementById("m").innerHTML=m;
	reload();
	program(1,1,1);
	}
if (m==60)
	{
	m="00";
	h++;
		if(h<10)
		{
		h="0"+h;
		}
	document.getElementById("h").innerHTML=h;
	clock();
	
	}
document.getElementById("s").innerHTML=s;	
	

setTimeout("timer()",991);
}

function logout(str)
{
var xmlhttp;
if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }
else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var aa=xmlhttp.responseText;
if (str==1)
	{
	var c=confirm(aa);
	if (c==true)
		{
		logout(2);
		}
	}
else if(str==2)
	{
	window.location.href='index.php';
	}
else
	{
	window.location.href='overview.php';
	}
} }
xmlhttp.open("GET","embedded/functions/log_out.php?a="+str,true);
xmlhttp.send();
}

function program(str,str2,str3)
{
var xmlhttp;
if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }
else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{ 
document.getElementById("programm").innerHTML=xmlhttp.responseText;
} }
xmlhttp.open("GET","embedded/functions/programm.php?a="+str+"&s="+str2+"&x="+str3,true);
xmlhttp.send();
}
