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



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


function scenario_check(str,str1,str2,str3)
{
if (str1==0)
	{
	str1=document.getElementById("duration_value").value;
	}
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('s_n').innerHTML=xmlhttp.responseText;
var r =  xmlhttp.responseText;
var foundb=r.search("Καμία αλλαγή!");
var found = r.search("okkk");
var foundb=r.search("decision");
if (found !=-1)
	{
	changes(str);
	}
if (document.getElementById("scenario_notification").className=="okkk" || (document.getElementById("scenario_notification").className=="decision" && foundb!=-1))
			{
			document.getElementById("duration").style.visibility="hidden";
			document.getElementById("duration_value").value="";
			document.getElementById('duration').className="decision";
			document.getElementById('check').innerHTML='<br /><a class="invalid">Ορίστε Διάρκεια!</a>';
			changes(2);
			document.getElementById('l_f').style.visibility="visible";
			document.getElementById('db1').style.visibility="hidden";
			document.getElementById('db2').style.visibility="hidden";
			reload();
			}
} }
xmlhttp.open("GET","embedded/functions/scenario_check.php?c="+str+"&q="+str1+"&d="+str2+"&e="+str3,true);
xmlhttp.send();
}

function changes(str)
{
if (str==1)
	{
	document.getElementById("duration").style.visibility="visible";
	changes1();
	}
else
	{
	document.getElementById('duration').className="decision";
	document.getElementById('check').innerHTML="<a class='invalid'><br />Ορίστε Διάρκεια!</a>";
	document.getElementById("duration_value").value="";
	document.getElementById("duration").style.visibility="hidden";
	program(1,1,0);
	}
}
function changes1()
{
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('last_data').innerHTML=xmlhttp.responseText;
} }
xmlhttp.open("GET","embedded/functions/device_table_no_stable.php",true);
xmlhttp.send();
}

function enablef(str,str1)
{
var xmlhttp;
if (str ==1)
	{
	str="f";
	}
else if (str==2)
	{
	str="l";
	}
else
	{
	str="w";
	}
if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }
else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{ 
document.getElementById('last_data').innerHTML=xmlhttp.responseText;
} }
xmlhttp.open("GET","embedded/functions/device_table_no_stable.php?"+str+"="+str1,true);
xmlhttp.send();
}


function choose_function(str)
{
if (str==1)
	{
	changes(1);
	document.getElementById("s_n").innerHTML="";
	document.getElementById('l_f').style.visibility="hidden";
	document.getElementById('db1').style.visibility="visible";
	document.getElementById('db2').style.visibility="visible";
	}
else if (str==2)
	{
	var str1=document.getElementById("duration_value").value;
	if (str1=="")
		{
		document.getElementById('check').innerHTML='<br /><a class="invalid">Ορίστε Διάρκεια!</a>';
		document.getElementById('duration').className="decision";
		}
	else
		{
		scenario_check(1,0,0,0);
		}
	}
else
	{
	changes(2);
	document.getElementById('l_f').style.visibility="visible";
	document.getElementById('db1').style.visibility="hidden";
	document.getElementById('db2').style.visibility="hidden";
	if (document.getElementById('scenario_notification')!=null)
		{
		document.getElementById('scenario_notification').innerHTML="";
		document.getElementById('scenario_notification').style.visibility="hidden";
		}
	reload();
	}

}

function duration_validate(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)
{
document.getElementById('check').innerHTML=xmlhttp.responseText;
if (str.length==0)
	{
	document.getElementById('duration').className="decision";
	document.getElementById('check').innerHTML="<a class='invalid'><br />Ορίστε Διάρκεια!</a>";
	}
else
	{	
	var found = str.search("#");
	var found_0 = str.search("&");
	if(found != -1 || found_0 != -1)
		{
		document.getElementById('check').innerHTML="Μόνο αριθμοί!";
		document.getElementById('duration').className="decision";
		document.getElementById("db1").disabled=true;
		}
	}
var r =xmlhttp.responseText;
var found = r.search("Επιτυχής!");
if (found==-1)
	{
	document.getElementById('duration').className="decision";
	document.getElementById("db1").disabled=true;
	}
else
	{
	document.getElementById('duration').className="okkk";
	document.getElementById("db1").disabled=false;
	}
 } }
xmlhttp.open("GET","embedded/functions/duration_check.php?q="+str,true);
xmlhttp.send();
}

function login(str,str1)
{
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('password_check').innerHTML=xmlhttp.responseText;
} }
xmlhttp.open("GET","embedded/functions/password_check.php",true);
xmlhttp.send();
}

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,0);
	}
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
	{
	window.location.href='index.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();
}

function popup(str)
{
	if (str==1)
		{
		document.getElementById("s_msg").style.visibility="visible";
		}
	else if(str==2)
		{
		document.getElementById("s_msg").style.visibility="hidden";
		}
	else
		{
		if (str==111)
			{
			document.getElementById("program_title1").style.visibility="visible";
			}
		else if (str==112)
			{
			document.getElementById("program_title2").style.visibility="visible";
			}
		else if (str==113)
			{
			document.getElementById("program_title3").style.visibility="visible";
			}	
		else
			{
			if (document.getElementById("program_title1")!=null)
				{
				document.getElementById("program_title1").style.visibility="hidden";
				}
			if (document.getElementById("program_title2")!=null)
				{
				document.getElementById("program_title2").style.visibility="hidden";
				}
			if (document.getElementById("program_title3")!=null)
				{
				document.getElementById("program_title3").style.visibility="hidden";
				}		
				
			}
		}
}