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 personal_info(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("personal_info").innerHTML=xmlhttp.responseText; 
document.getElementById('automation_menu_1').className= 'page_menu_button_automation_active';
document.getElementById('automation_menu_2').className= 'page_menu_button_automation';
document.getElementById('automation_menu_3').className= 'page_menu_button_automation';
document.getElementById('automation_menu_4').className= 'page_menu_button_automation';
document.getElementById("machine_info").innerHTML="";
document.getElementById("admin_contact1").innerHTML="";
document.getElementById("troubleshoots1").innerHTML="";
if (str!=1)
	{
	document.getElementById("summary_profile").innerHTML=str;
	}
}
 }
xmlhttp.open("GET","embedded/pages/personal_info.php",true);
xmlhttp.send();
}

function machine_info(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("machine_info").innerHTML=xmlhttp.responseText; 
document.getElementById('automation_menu_2').className= 'page_menu_button_automation_active';
document.getElementById('automation_menu_1').className= 'page_menu_button_automation';
document.getElementById('automation_menu_3').className= 'page_menu_button_automation';
document.getElementById('automation_menu_4').className= 'page_menu_button_automation';
document.getElementById("personal_info").innerHTML="";
document.getElementById("admin_contact1").innerHTML="";
document.getElementById("troubleshoots1").innerHTML="";
if (str!=1)
	{
	document.getElementById("summary_profile").innerHTML=str;
	}
}
 }
xmlhttp.open("GET","embedded/pages/machine_info.php",true);
xmlhttp.send();
}

function admin_contact(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("admin_contact1").innerHTML=xmlhttp.responseText; 
document.getElementById('automation_menu_3').className= 'page_menu_button_automation_active';
document.getElementById('automation_menu_2').className= 'page_menu_button_automation';
document.getElementById('automation_menu_1').className= 'page_menu_button_automation';
document.getElementById('automation_menu_4').className= 'page_menu_button_automation';
document.getElementById("personal_info").innerHTML="";
document.getElementById("machine_info").innerHTML="";
document.getElementById("troubleshoots1").innerHTML="";
clear_admin_contact();
if (str!=1)
	{
	document.getElementById("summary_profile").innerHTML=str;
	}
}
 }
xmlhttp.open("GET","embedded/pages/admin_contact.php",true);
xmlhttp.send();
}

function troubleshoots(str,str1,str2)
{
if(str==1 && str1==0)
	{
	url="";
	}
else
	{
	url="?a="+str+"&b="+str1+"&c="+str2;
	}
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("troubleshoots1").innerHTML=xmlhttp.responseText; 
document.getElementById('automation_menu_4').className= 'page_menu_button_automation_active';
document.getElementById('automation_menu_2').className= 'page_menu_button_automation';
document.getElementById('automation_menu_1').className= 'page_menu_button_automation';
document.getElementById('automation_menu_3').className= 'page_menu_button_automation';
document.getElementById("personal_info").innerHTML="";
document.getElementById("machine_info").innerHTML="";
document.getElementById("admin_contact1").innerHTML="";
}
 }
xmlhttp.open("GET","embedded/pages/troubleshoots.php"+url,true);
xmlhttp.send();
}

function filter(str)
{
if (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;
	document.getElementById('filter_result').innerHTML=aa;
	} }
	xmlhttp.open("GET","embedded/functions/filter.php?a="+str,true);
	xmlhttp.send();
	}
else
	{
	document.getElementById('filter_result').innerHTML='';
	}
}

function clear_machine_info()
{
document.getElementById("1").checked=false;
document.getElementById("2").checked=false;
document.getElementById("3").checked=false;
document.getElementById("4").selectedIndex=0;
document.getElementById("5").selectedIndex=0;
document.getElementById("6").disabled=true;


}
//change info
function enable_change(str)
{
var xmlhttp;
if (str.length==0) 
{ 
	clear_change_info() 	
	return; 
}
if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }
else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{ 
var r =  xmlhttp.responseText;
document.getElementById("1_msg").innerHTML=r;
var found = r.search("invalid");
if(found == -1) 
		{
		document.getElementById("2").disabled=false;
		document.getElementById("4").disabled=false;
		document.getElementById("7").disabled=false;	
		}
else
		{
		document.getElementById("2").disabled=true;
		document.getElementById("3").disabled=true;
		document.getElementById("4").disabled=true;
		document.getElementById("6").disabled=true;
		document.getElementById("7").disabled=true;		
		}		
		
} }
xmlhttp.open("GET","embedded/functions/password_check.php?q="+str,true);
xmlhttp.send();
}

function strength(str){
var xmlhttp;
if (str.length==0) 
{ 
	document.getElementById("2_msg").innerHTML="";
	document.getElementById("3_msg").innerHTML="";
	document.getElementById("3").value="";
	document.getElementById("3").disabled=true;
	var x=document.getElementById("4_msg").innerHTML;
	var foundx= x.search("valid");
	if (foundx!=-1 && document.getElementById("4").value!="") 
		{
		document.getElementById("6").disabled=false;
		}
	else
		{
		document.getElementById("6").disabled=true;
		}
	return; 
}
if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }
else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{ 
var a=xmlhttp.responseText;
document.getElementById("2_msg").innerHTML=a;
document.getElementById("3").disabled=false;
document.getElementById("3_msg").innerHTML="";
document.getElementById("3").value="";
if (a!="")
	{
	document.getElementById("6").disabled=true;
	}

}
} 
xmlhttp.open("GET","embedded/functions/strengh.php?q="+str,true);
xmlhttp.send();
}

function confirme(str){
var xmlhttp;
var str1 = document.getElementById("2").value;
if (str.length==0) 
{ 
document.getElementById("3_msg").innerHTML=""; 
if (str1!="")
	{
	document.getElementById("6").disabled=true;
	document.getElementById("3_msg").innerHTML='<span class="invalid">Not Confirmed!</span>';
	}
else
	{
	document.getElementById("6").disabled=true;
	}
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("3_msg").innerHTML=xmlhttp.responseText;
var r =  xmlhttp.responseText;
var found = r.search("invalid");
if(found != -1)
	{
		document.getElementById("6").disabled=true;
	}
else 
	{
	var x=document.getElementById("4_msg").innerHTML;
	var foundx= x.search("invalid");
	if (foundx==-1 && document.getElementById("4").value!="") 
			{
			document.getElementById("6").disabled=false;
			}
		else if(document.getElementById("4").value=="")
			{
			document.getElementById("6").disabled=false;
			}
	}
} }
xmlhttp.open("GET","embedded/functions/confirm.php?q="+str+"&p="+str1,true);
xmlhttp.send();
}

function email_validator(str){
var xmlhttp;
if (str.length==0) 
{ 
document.getElementById("4_msg").innerHTML="Press enter";
var a=document.getElementById("3_msg").innerHTML;
var f=a.search("valid"); 
if(f==-1)
	{
	document.getElementById("6").disabled=true;
	}
else
	{
	document.getElementById("6").disabled=false;
	}
if(document.getElementById("1").value=="")
	{
	document.getElementById("6").disabled=false;
	}
if (document.getElementById("2").value=="")
		{
		document.getElementById("6").disabled=true;	
		}
	return; 
}
if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }
else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{ 
var a= document.getElementById("4").value;
var found = a.search("#");
var found_0 = a.search("&");
if(found != -1 || found_0 != -1)
{
document.getElementById("4_msg").innerHTML='<span class="invalid">Invalid address!</span>';
}
else
{
document.getElementById("4_msg").innerHTML=xmlhttp.responseText;
}
var r =  xmlhttp.responseText;
var found = r.search("invalid");
var a=document.getElementById("3_msg").innerHTML;
var f=a.search("valid");
if(found != -1)
	{
		document.getElementById("6").disabled=true;
	}
else 
	{
		if(document.getElementById('2').value!="")
			{
			if(f!=-1)
				{
				document.getElementById("6").disabled=false;
				}
			else
				{
				document.getElementById("6").disabled=true;
				}
			}
		else
			{
			document.getElementById("6").disabled=false;
			}
	}
} }
xmlhttp.open("GET","embedded/functions/email_validate.php?q="+str+"&qq="+2,true);
xmlhttp.send();
}
function clear_change_info()
{
document.getElementById("3_msg").innerHTML="";
document.getElementById("2_msg").innerHTML="";
document.getElementById("4_msg").innerHTML="Press enter";
document.getElementById("1_msg").innerHTML="Press enter";
document.getElementById("2").value="";
document.getElementById("3").value="";
document.getElementById("4").value="";
document.getElementById("3").disabled=true;
document.getElementById("2").disabled=true;
document.getElementById("4").disabled=true;
document.getElementById("6").disabled=true;
document.getElementById("7").disabled=true;
document.getElementById("summary_profile").innerHTML="";
}

//admin contact
function input_validator(str1,str){
var xmlhttp;
var msg=str1+"_msg";
var id=str1;
var other_msg;
var other_id;
if(str1==1)
	{
	other_msg="2_msg";
	other_id="2";
	}
else
	{
	other_msg="1_msg";
	other_id="1";
	}
if (str.length==0)
{ 
if(str1==2)
{
document.getElementById(msg).innerHTML="Press tab"; 
} 
else
{
document.getElementById(msg).innerHTML="Press enter"; 
}
document.getElementById("66").disabled=true;
return; 
}
if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }
else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{ 
var r =  document.getElementById(id).value;
var found = r.search("#");
var found_0 = r.search("&");
if(found != -1 || found_0 != -1)
	{
	document.getElementById(msg).innerHTML='<span class="invalid">Invalid Data!</span>';
	}
else
	{
	document.getElementById(msg).innerHTML=xmlhttp.responseText;
	}
if (document.getElementById(msg).innerHTML=='<span class="invalid">Invalid Data!</span>')
	{
	document.getElementById("66").disabled=true;
	}
else
	{
	var a = xmlhttp.responseText;
	var founda= a.search("invalid");
	if(founda==-1 && document.getElementById(other_id).value!="")
		{
		
		document.getElementById("66").disabled=false;
		}
	else
		{
		document.getElementById("66").disabled=true;
		}
		
	}
}}
xmlhttp.open("GET","embedded/functions/input_validate.php?q="+str,true);
xmlhttp.send();
}

function clear_admin_contact()
{
document.getElementById("66").disabled=true;
document.getElementById("1_msg").innerHTML="Press enter";
document.getElementById("2_msg").innerHTML="Press tab";
document.getElementById("1").value="";
document.getElementById("2").value="";
document.getElementById("summary_profile").innerHTML="";
}

//gia to sensor kai device info
function enable(str,str1)
{
var id;
var msg="";
if (str==1)
	{
	for(id=1;id<=2;id++)
		{
		if (document.getElementById(id).checked==true)
			{
			msg=msg+ "checked";
			}
		}
	for(id=3;id<=4;id++)
		{
		if (document.getElementById(id).value!="")
			{
			msg=msg+ "checked";
			}
		}
	if (document.getElementById("5").checked==true && msg!="")
		{
		document.getElementById("6").disabled=false;
		}
	else
		{
		document.getElementById("6").disabled=true;
		}
	}
else
	{
	var id;
	for (id=1;id<=5;id++)
		{
		if (id==1 || id==2 || id==3)
			{
			if (document.getElementById(id).checked==true)
				{
				msg=msg+"checked";
				}
			}
		else
			{
			if (document.getElementById(id).value!=0)
				{
				msg=msg+"checked";
				}
			}
		if(msg!="")
			{
			document.getElementById("6").disabled=false;
			}
		else
			{
			document.getElementById("6").disabled=true;
			}
		}
	}
}

function save(str1)
{
var url="";
var id;
var value;
if (str1==1)
	{
	for(id=1;id<=5;id++)
		{
		var str="str"+id;
		if(id!=4 && id!=5)
			{
			if (document.getElementById(id).checked==true)
				{
				value=document.getElementById(id).value+"1";
				}
			else
				{
				value=document.getElementById(id).value+"0";
				}
			}
		else
			{
				value=document.getElementById(id).value;
			}
		url=url+"&"+str+"="+value;		
		}
	}
if (str1==2)
	{
	for(id=1;id<=4;id++)
		{
		var str="str"+id;
		if(value=document.getElementById(id).value!="")
			{
			value=document.getElementById(id).value;
			url=url+"&"+str+"="+value;
			}
		}
	}
else if (str1==3)
	{
	for(id=1;id<=2;id++)
		{
		var str="str"+id;
		value=document.getElementById(id).value;
		url=url+"&"+str+"="+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)
{ 
var a=xmlhttp.responseText;
document.getElementById("summary_profile").innerHTML=a;
var found = a.search("added");
var found_0 = a.search("updated");
if(found != -1 || found_0 != -1)
	{
	if (str1==2)
		{
		personal_info(a);
		}
	else if (str1==1)
		{
		machine_info(a);
		}
	else
		{
		admin_contact(a);
		}
	
	}
}
 }
xmlhttp.open("GET","embedded/functions/save_profile.php?a="+str1+url,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,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='profile.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();
}
