var transport={};
function populateCell(_1,_2){
json=eval("("+_1+")");
Object.keys(json).each(function(_3){
dateOfCell=_3.split("/").join("");
cell_id=_2+dateOfCell;
if($(cell_id)){
if($(cell_id).getElementsByTagName("a").length>0){
$(cell_id).getElementsByTagName("a")[0].innerHTML=json[_3].GN.sc;
$(cell_id).getElementsByTagName("span")[0].innerHTML=json[_3].GN.ss;
}else{
$(cell_id).innerHTML="<a substitutions=\"date: '"+dateOfCell+"'\" bubbleblock=\"bubbleblock\" href=\"javascript:void(0);\">"+json[_3].GN.sc+"</a><span class=\"status\">"+json[_3].GN.ss+"</span>";
}
if(json[_3].GN.ss==="R.A.C."){
$(cell_id).className="rac";
}else{
$(cell_id).className=json[_3].GN.ss.toLowerCase();
}
new Effect.Highlight($(cell_id),{duration:1});
}
});
}
function callAvailability(_4,_5,_6,_7,_8){
return new Ajax.Request("/trains/availability/1?class="+_4+"&number="+_5+"&date="+_8+"&start="+_6+"&end="+_7,{asynchronous:true,evalScripts:true,onFailure:function(_9){
if(checkAllFinished(_5)===true){
$("spinner"+_5).style.display="none";
}
},onSuccess:function(_a){
populateCell(_a.responseText,_5);
if(checkAllFinished(_5)===true){
$("spinner"+_5).style.display="none";
}
}});
}
function fetchAvailability(_b,_c,_d,_e){
$("remote"+_b).remove();
transport[_b]=[];
$("spinner"+_b).style.display="block";
dates=eval($("dates"+_b).value);
dates.each(function(_f){
transport[_b].push(callAvailability(_c,_b,_d,_e,_f));
});
}
function checkAllFinished(_10){
transport[_10].each(function(t){
if((!t._complete)&&(t.transport.status!=200)){
return (false);
}
});
return (true);
}
Event.observe(window,"load",function(){
$("bubbleblock").remove();
});
