function statistics(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("1").innerHTML=xmlhttp.responseText; 
document.getElementById("2").innerHTML="";
document.getElementById("3").innerHTML="";
document.getElementById("4").innerHTML="";  
if (str!=1)
{
document.getElementById("data_message").innerHTML=str;  
}
else
{
document.getElementById("data_message").innerHTML="";
} 
}
 }
xmlhttp.open("GET","embedded/admin/pages/statistics.php",true);
xmlhttp.send();
}

function users(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("2").innerHTML=xmlhttp.responseText; 
 document.getElementById("1").innerHTML="";
document.getElementById("3").innerHTML="";
document.getElementById("4").innerHTML="";  
if (str!=1)
{
document.getElementById("display").innerHTML=str;  
}
else
{
document.getElementById("display").innerHTML="";
}
}
 }
xmlhttp.open("GET","embedded/admin/pages/users.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("1").innerHTML=xmlhttp.responseText; 
if (str>4 )
{
document.getElementById("data_message").innerHTML=str;  
}
else
{
document.getElementById("data_message").innerHTML="";
}
 
document.getElementById("2").innerHTML="";
document.getElementById("3").innerHTML="";
document.getElementById("4").innerHTML="";   
}
 }
xmlhttp.open("GET","embedded/admin/pages/troubleshoots.php"+url,true);
xmlhttp.send();
}

function messages(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("1").innerHTML=xmlhttp.responseText; 
document.getElementById("2").innerHTML="";
document.getElementById("3").innerHTML="";
document.getElementById("4").innerHTML=""; 
if (str<=5)
	{
	document.getElementById("data_message").innerHTML="";  
	}
else
	{
	document.getElementById("data_message").innerHTML=str;
	}
}
 }
xmlhttp.open("GET","embedded/admin/pages/messages.php"+url,true);
xmlhttp.send();
}

function show_user(str)
{
var xmlhttp;
if (str.length==0) { document.getElementById("display").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("display").innerHTML=xmlhttp.responseText; 
}}
xmlhttp.open("GET","embedded/admin/functions/show_user.php?q="+str,true);
xmlhttp.send();
}



function delete_user(str)
{
var xmlhttp;
if (str.length==0) { document.getElementById("e").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("e").innerHTML=xmlhttp.responseText; 
}}
xmlhttp.open("GET","embedded/admin/functions/confirm_delete.php?q="+str,true);
xmlhttp.send();
}

function delete_yn(str,str1)
{
var xmlhttp;
if (str.length==0) { document.getElementById("e").innerHTML=""; 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; 
if (str1!=str)
{
if (a=="")
	{
	show_user(str1);
	}
else
	{
	users(a);
	}
}
else
	{
	if (a=="")
		{
		view_message(str);
		}
	else
		{
		messages(a);
		}

	}
}}
xmlhttp.open("GET","embedded/admin/functions/delete.php?q="+str+"&p="+str1,true);
xmlhttp.send();
}

function insert_user()
{
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("display").innerHTML=xmlhttp.responseText; 
}}
xmlhttp.open("GET","embedded/admin/functions/device_insert.php",true);
xmlhttp.send();
}

function validator(str1,str){
var xmlhttp;
var msg=str+"_msg";
var id=str+"_id";
if (str1.length==0) { 
document.getElementById(msg).innerHTML="";
document.getElementById("b1").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 (str!=7)
	{	
	enable_save();
	}
}}
xmlhttp.open("GET","embedded/admin/functions/id_validation.php?q="+str+"&p="+str1,true);
xmlhttp.send();
}

function process_new_device()
{
var xmlhttp;
var d = document.getElementById("1_id").value;
var e = document.getElementById("2_id").value;
var u = document.getElementById("3_id").value;
if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }
else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
xmlhttp.onreadystatechange=function() 
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{ 
a=xmlhttp.responseText;
users(a);
}}
xmlhttp.open("GET","embedded/admin/functions/process_new_device.php?d="+d+"&e="+e+"&u="+u,true);
xmlhttp.send();
}

function view_message(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)
{ 
a=xmlhttp.responseText;
document.getElementById("1").innerHTML=a;
}}
xmlhttp.open("GET","embedded/admin/functions/view_message.php?m="+str,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;
setTimeout('clock()',1000);
} }
xmlhttp.open("GET","embedded/functions/clock.php",true);
xmlhttp.send();
}

function enable_save()
{
var msg=""
for (i=1;i<=3;i++)
	{
	var id1=i+"_id";
	var msg1=i+"_msg";
	var r=document.getElementById(msg1).innerHTML;
	var found_0 = r.search("Done!");
	if ( document.getElementById(id1).value!="" && found_0!=-1)
		{
		msg=msg +"";
		}
	else
		{
		msg=msg+"1";
		}
	}
	if (msg=="")
		{
		document.getElementById("b1").disabled=false;
		}
	else
		{
		document.getElementById("b1").disabled=true;
		}

}

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

function change_email(str)
{
if (str!="")
	{
	if (str==1)
		{
		url="q="+str;
		}
	else
		{
		var id=document.getElementById('d').innerHTML;
		var mail=document.getElementById('7_id').value;
		url="q="+str+"&d="+id+"&email="+mail;
		}
	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('email').innerHTML=aa;
	} }
	xmlhttp.open("GET","embedded/admin/functions/change_email.php?"+url,true);
	xmlhttp.send();
	}
}

