
var url;var since=0;var changeID=0,focusID=0;var yellow="lemonchiffon";var red="tomato";var green="lightgreen";var intervalID;var selectfield;var isList;var active_image_index=1;var image_counter=0;function selectrecipe(id)
{var r=document.getElementById("StartRecipe");var rname=document.getElementById("recipe_name");var t=document.getElementById("RecipeText");var x=document.getElementById(id);var dt=document.getElementById("datatable");if(x===null||rname===null||t===null||r===null)
{return;}
r.style.width=(document.getElementById("datatable").offsetWidth-22)+"px";r.style.display="block";dt.style.display="none"
rname.value=x.innerHTML;if(t!=null)
t.innerHTML="To Start Recipe <span class='pname'>  "+rname.value+"</span>  Select a Controller, then click 'Start Recipe'";}
function logup()
{var tim=0;}
function selchange()
{}
function startRecipe(form)
{var c=document.getElementById("controller_list");if(c==null)
return;var index=c.selectedIndex;if(!index)
{alert("Please select a controller from the list");return null;}
var cname=c.options[index].text;var data="/NVhandler.ashx?controller="+cname+"&recipe_name="+form.recipe_name.value+"&start=1";setControllerData(data,handleRecipeStart);}
function handleRecipeStart()
{if(httpWrite.readyState==4)
{if(httpWrite.status==200)
{var result=httpWrite.responseText;var t=document.getElementById("RecipeText");if(result.indexOf("#")!=-1)
{t.innerHTML="Recipe has been started";window.location="index.htm";}
else
alert(result);}}}
function setupInput(id)
{isList=false;var s;var ps=document.getElementById("SEL_PS");var ls=document.getElementById("SEL_LS");var ib=document.getElementById("newdata");ps.style.display=ls.style.display=ib.style.display="none";if(id.indexOf("PS_")!=-1)
{s=ps;isList=true;}
else if(id.indexOf("LS_")!=-1)
{s=ls;isList=true;}
else
s=ib;selectfield=s;return s;}
function inputdata(id,name)
{changeID=id;var s=null,d=null;var word;window.status="Enter new data and click 'Send To Controller'";var x=document.getElementById(id);var r=document.getElementById("ChangeData");var t=document.getElementById("ChangeText");var d=document.getElementById("newdata");r.style.width=(document.getElementById("datatable").offsetWidth-22)+"px";r.style.display="block";var s=setupInput(id);if(s!=null)
s.style.display="inline";else
return;if(r!=null&&t!=null)
{if(d.id==s.id)
{d.value=x.innerHTML;word=" enter ";}
else
{word=" select ";}
t.innerHTML="To Change <span class='pname'> "+name+"</span>"+word+"a value and click 'Send To Controller'";}
s.focus();if(!isList)
s.select();}
function hide(id)
{var r=document.getElementById(id);r.style.display="none";}
function hide_show(id,sid)
{var r=document.getElementById(id);r.style.display="none";var s=document.getElementById(sid);s.style.display="block";}
function senddata(form)
{var d=document.getElementById("newdata");if(selectfield.id!=d.id)
d.value=selectfield.options[selectfield.selectedIndex].text;var data="/NVhandler.ashx?"+changeID+"="+d.value+"&change=1";setControllerData(data,handleChangeData);}
function handleChangeData()
{if(httpWrite.readyState==4)
{if(httpWrite.status==200)
{var result=httpWrite.responseText;var x=document.getElementById("ChangeText");if(result.indexOf("#")!=-1)
{x.innerHTML="The controller has received the changed parameter";}
else
{x.innerHTML="The controller has reported an error: "+result+" Please try again";}}}}
function getImage(i)
{var x=document.getElementById("GRP_01_01");var d=new Date();var unique=d.getMonth()+"_"+d.getDate()+"_"+d.getFullYear()+"_"+d.getHours()+"_"+d.getMinutes()+"_"+d.getSeconds();x.src="/NVhandler.ashx?"+"profile0"+i+"_"+unique+".jpg";}
function setImage(i)
{active_image_index=i;getImage(i);}
function stopupdate()
{clearInterval(intervalID);}
function getgraphtime(id)
{var x=document.getElementById(id);if(x==null)return;var d=new Date();x.value="Updated: "+d;}
function startAjax(x)
{since=0;url=x;getControllerData();intervalID=setInterval('getControllerData();',1000);}
function setControllerData(data,handler)
{httpWrite=getHTTPObject();httpWrite.onreadystatechange=handler;httpWrite.open("POST",data,true);httpWrite.send(data);}
function handleGraphs()
{if(image_counter++==10)
{getImage(active_image_index);image_counter=1;}}
function getControllerData()
{if(url.indexOf("Graphs")!=-1)
handleGraphs();else
{httpRead=getHTTPObject();httpRead.onreadystatechange=handleGetHttpResponse;httpRead.open("POST",url+"&since="+since,true);httpRead.send("");}}
var httpRead=getHTTPObject();var httpWrite=getHTTPObject();function handleGetHttpResponse()
{if(httpRead.readyState==4)
{if(httpRead.status==200)
{var result=httpRead.responseText;var length=result.length;var idArray=httpRead.responseText.split("\n");if(focusID)
return;for(var i=0;i<idArray.length-1;i++)
{var id=idArray[i].split(',');var x=document.getElementById(id[0]);if(x==null||id[0]==null||id[1]==null||id[0]==focusID)
continue;else
{if(id[0]!='DDD')
{var len=id[1].length;var val=id[1].substring(0,len-1);x.innerHTML=val;if(id[0].indexOf("PS_")!=-1)
{if(val.indexOf("Run")!=-1)
x.style.backgroundColor=green;else if(val.indexOf("END")!=-1)
x.style.backgroundColor=red;else
x.style.backgroundColor=yellow;}
else if(id[0].indexOf("PDT_")!=-1)
{var unknown=val.indexOf("-----");if(unknown==-1&&val.indexOf("Ended")==-1)
x.style.backgroundColor=green;else if(unknown==-1)
x.style.backgroundColor=red;}
else if(id[0].indexOf("LS_")!=-1)
{if(val.indexOf("Auto")!=-1)
x.style.backgroundColor=green;else
x.style.backgroundColor=yellow;}
else if(id[0].indexOf("CO_")!=-1&&id[0].indexOf("_src")==-1)
{if(val.indexOf("0")!=-1)
x.style.backgroundColor=red;else
x.style.backgroundColor=green;}}
else
{since=id[1];x.value=since;}}}}}}
function handleSetHttpResponse()
{if(httpWrite.readyState==4)
{if(httpWrite.status==200)
{var result=httpWrite.responseText;if(result.indexOf("#")==-1)
alert(result);}}}
function getHTTPObject()
{if(window.XMLHttpRequest)
{try
{xmlhttp=new XMLHttpRequest();}
catch(e)
{xmlhttp=false;}}
else if(window.ActiveXObject)
{try
{xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");}
catch(e)
{window.alert("ms.xmlhttp");try
{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
catch(E)
{xmlhttp=false;}}}
return xmlhttp;}



function popup(url)
{
	window.open(url,'','scrollbars=yes,resizable=yes,width=800,height=600,top=200,left=400,menubar=no');
} 
