// ==== navygation =============================================================
var iNavyGenCompleted=0;
//
var arrNavyWarnings=new Array();
var arrNavyErrors=new Array();
//
var theNavyTimer=null;
//
var theNavycntCurract=null; var theNavycntCurracttext=null;
var theNavycntMemory=null; var theNavycntTime=null; var theNavycntBar=null;
var theNavyCntProcessor=null;
var sNavycntLatestRec="";
//
var theNavyCurract=null; var theNavyCurracttext=null;
var theNavyMemory=null; var theNavyTime=null; var theNavyBar=null;
var theNavyProcessor=null;
var sNavyLatestRec="";
//
var fMaxProcNavycnt=0;
var fMaxMemNavycnt=0;
var fMaxProcNavy=0;
var fMaxMemNavy=0;
//
function wd_gen_ShowNavyStatus(sFlowText) {
	var iNavyCntRecStart=sFlowText.lastIndexOf('navycnt rec ');
	if (iNavyCntRecStart!==-1) {
		var sNavyCntRec=sFlowText.substr(iNavyCntRecStart+12); // 12 = 'navycnt rec '.length
		var iNavyCntRecFin=sNavyCntRec.indexOf(' recfin');
		if (iNavyCntRecFin!==-1) {
			sNavyCntRec=sNavyCntRec.substr(0, iNavyCntRecFin);
			if (sNavyCntRec!==sNavycntLatestRec) {
				var arrNavyCntRec=sNavyCntRec.split('::');
				if (arrNavyCntRec.length>5) {
					if (theNavycntCurracttext) theNavycntCurracttext.innerHTML=arrNavyCntRec[5]; // sMessage
					if (theNavycntCurract) theNavycntCurract.innerHTML=arrNavyCntRec[1]; // sGened
					if (theNavycntMemory) {
						var fMem=parseFloat(arrNavyCntRec[2].replace(",", "."));
						if (fMem>fMaxMemNavycnt) fMaxMemNavycnt=fMem;
						theNavycntMemory.innerHTML=fMem+" (max "+fMaxMemNavycnt+")"; // sMemory
					}
					if (theNavycntTime) theNavycntTime.innerHTML=arrNavyCntRec[3]; // sTime
					if (theNavyCntProcessor) {
						var fProcessor=parseFloat(arrNavyCntRec[4].replace(",", "."));
						if (fProcessor>fMaxProcNavycnt) fMaxProcNavycnt=fProcessor;
						theNavyCntProcessor.innerHTML=fProcessor+" (max "+fMaxProcNavycnt+") %"; // processor usage
					}
					if (theNavycntBar) {
						theNavycntBar.style.width=arrNavyCntRec[0]+"%"; // sPercent
						theNavycntBar.innerHTML=arrNavyCntRec[0]+"%"; // sPercent
						theNavycntBar.title=arrNavyCntRec[0]+"%"; // sPercent
					}
				}
				wd_gen_ShowSiteStatus();
				sNavycntLatestRec=sNavyCntRec;
			}
		}
	}
	//
	var iNavyRecStart=sFlowText.lastIndexOf('navyel rec ');
	if (iNavyRecStart!==-1) {
		var sNavyRec=sFlowText.substr(iNavyRecStart+11); // 11 = 'navyel rec '.length
		var iNavyRecFin=sNavyRec.indexOf(' recfin');
		if (iNavyRecFin!==-1) {
			sNavyRec=sNavyRec.substr(0, iNavyRecFin);
			if (sNavyRec!==sNavyLatestRec) {
				var arrNavyRec=sNavyRec.split('::');
				if (arrNavyRec.length>5) {
					if (theNavyCurracttext) theNavyCurracttext.innerHTML=arrNavyRec[5]; // sMessage
					if (theNavyCurract) theNavyCurract.innerHTML=arrNavyRec[1]; // sGened
					if (theNavyMemory) {
						var fMem=parseFloat(arrNavyRec[2].replace(",", "."));
						if (fMem>fMaxMemNavy) fMaxMemNavy=fMem;
						theNavyMemory.innerHTML=fMem+" (max "+fMaxMemNavy+")"; // sMemory
					}
					if (theNavyTime) theNavyTime.innerHTML=arrNavyRec[3]; // sTime
					//if (theNavyProcessor) theNavyProcessor.innerHTML=arrNavyRec[4];
					if (theNavyProcessor) {
						var fProcessor=parseFloat(arrNavyRec[4].replace(",", "."));
						if (fProcessor>fMaxProcNavy) fMaxProcNavy=fProcessor;
						theNavyProcessor.innerHTML=fProcessor+" (max "+fMaxProcNavy+") %"; // processor usage
					}
					if (theNavyBar) {
						theNavyBar.style.width=arrNavyRec[0]+"%"; // sPercent
						theNavyBar.innerHTML=arrNavyRec[0]+"%"; // sPercent
						theNavyBar.title=arrNavyRec[0]+"%"; // sPercent
					}
				}
				wd_gen_ShowSiteStatus();
				sNavyLatestRec=sNavyRec;
			}
		}
	}
}
var arrNavyStats=new Array();
function wd_gen_PickNavyStats(sFlowText) {
	// hash::gened::memory::time::cpu::message
	var arrMsgs=wd_PickupWDRecs(sFlowText, 'navyel rec ', ' recfin', '<tr><td>%1%</td><td>%3% sec</td><td>%f4% %</td><td>%f2% M</td><td>%5%</td></tr>');
	var sHash="";
	for (sHash in arrMsgs) {
		arrNavyStats[sHash]=arrMsgs[sHash];
		if (document.images['wd_navy_stats']) document.images['wd_navy_stats'].src="/webdirector/mdl_content/images/genstatsoops.gif";
	}
}
var arrNavycntStats=new Array();
function wd_gen_PickNavycntStats(sFlowText) {
	// hash::gened::memory::time::cpu::message
	var arrMsgs=wd_PickupWDRecs(sFlowText, 'navycnt rec ', ' recfin', '<tr><td>%1%</td><td>%3% sec</td><td>%f4% %</td><td>%f2% M</td><td>%5%</td></tr>');
	var sHash="";
	for (sHash in arrMsgs) {
		arrNavycntStats[sHash]=arrMsgs[sHash];
		if (document.images['wd_navycnt_stats']) document.images['wd_navycnt_stats'].src="/webdirector/mdl_content/images/genstatsoops.gif";
	}
}
function wd_gen_PickNavyWarns(sFlowText) {
	// hash::errno::errstr::errfile::errline
	var arrWarns=wd_PickupWDRecs(sFlowText, 'warning rec ', ' recfin', '%3% %4%<br/>%2%');
	var sHash="";
	for (sHash in arrWarns) {
		arrNavyWarnings[sHash]=arrWarns[sHash];
		if (document.images['wd_navycnt_warns']) document.images['wd_navycnt_warns'].src="/webdirector/mdl_content/images/genwarnsoops.gif";
		if (document.images['wd_navy_warns']) document.images['wd_navy_warns'].src="/webdirector/mdl_content/images/genwarnsoops.gif";
	}
}
function wd_gen_PickNavyErrs(sFlowText, sStatusCode, iErrCode, sReqUrl) {
	var arrErrors=new Array();
	//
	if (sStatusCode!=="200" && sStatusCode!==200) arrErrors[new Date().valueOf()+'']="invalid server response ["+sStatusCode+"]";// while trying to receive url ["+sReqUrl+"] (<a href=\""+sNavyServerLog+"\">server log</a>)";
	// hash::errno::errstr::errfile::errline
	arrErrors=wd_Concat(arrErrors, wd_PickupWDRecs(sFlowText, 'error rec ', ' recfin', '%3% %4%<br/>%2%'));
	//
	arrErrors=wd_Concat(arrErrors, wd_PickupRecs(sFlowText, '<b>Parse error</b>:', '<br />'));
	arrErrors=wd_Concat(arrErrors, wd_PickupRecs(sFlowText, 'Parse error:', '\n'));
	arrErrors=wd_Concat(arrErrors, wd_PickupRecs(sFlowText, 'Fatal error:', '\n'));
	var sHash="";
	for (sHash in arrErrors) {
		arrNavyErrors[sHash]=arrErrors[sHash];
		if (document.images['wd_navycnt_errs']) document.images['wd_navycnt_errs'].src="/webdirector/mdl_content/images/generrsoops.gif";
		if (document.images['wd_navy_errs']) document.images['wd_navy_errs'].src="/webdirector/mdl_content/images/generrsoops.gif";
	}
}
function wd_gen_NavyFlow () {
	/*
	ajax callback function for navygation generation backreference
	*/
	if (theNavyFlow.Req.readyState === 3) {
		var sFlowText=theNavyFlow.Req.responseXML.text;
		//
		wd_gen_ShowNavyStatus(sFlowText);
	}
	if (theNavyFlow.Req.readyState === 4) {
		if (theNavyTimer) {
			window.clearInterval(theNavyTimer);
			theNavyTimer=null;
		}
		//
		var sFlowText=theNavyFlow.Req.responseText;
		//
		wd_gen_ShowNavyStatus(sFlowText);
		//
		var sStatusCode=theNavyFlow.Req.status;
		var iErrCode=theNavyFlow.Req.responseXML.parseError.errorCode;
		//
		theNavyFlow.Req.abort();
		//
		wd_gen_PickNavyErrs(sFlowText, sStatusCode, iErrCode, theNavyFlow.latestUrl);
		wd_gen_PickNavyWarns(sFlowText);
		wd_gen_PickNavyStats(sFlowText);
		wd_gen_PickNavycntStats(sFlowText);
		//
//alert(sFlowText.substr(sFlowText.length-1024, 1024));
		if (sFlowText.indexOf('<NONCOMPLETED/>')!==-1) { //<NONCOMPLETED/>\n</LOGRECS>
			wd_gen_ShowSiteStatus();
			window.setTimeout('wd_gen_StartGenNavy(0);', 5000);
		} else {
			iNavyGenCompleted=1;
			wd_gen_ShowSiteStatus();
		}
	}
}
// ajax object for navygation generation backreference:
var theNavyFlow=new wd_HttpReq(wd_gen_NavyFlow, 1); // async
function wd_gen_StartGenNavy(bRealStart) {
	// prepare navygation generation backreference:
	theNavycntCurract=document.getElementById('wd_navycnt_curraction');
	theNavycntCurracttext=document.getElementById('wd_navycnt_curraction_text');
	theNavycntMemory=document.getElementById('wd_navycnt_memory');
	theNavyCntProcessor=document.getElementById('wd_navycnt_processor');
	theNavycntTime=document.getElementById('wd_navycnt_time');
	theNavycntBar=document.getElementById('wd_genbar_navycnt');
	//
	theNavyCurract=document.getElementById('wd_navy_curraction');
	theNavyCurracttext=document.getElementById('wd_navy_curraction_text');
	theNavyMemory=document.getElementById('wd_navy_memory');
	theNavyProcessor=document.getElementById('wd_navy_processor');
	theNavyTime=document.getElementById('wd_navy_time');
	theNavyBar=document.getElementById('wd_genbar_navy');
	//
	if (!theSiteTime) theSiteTime=document.getElementById('wd_site_time');
	if (!theSiteBar) theSiteBar=document.getElementById('wd_genbar_site');
	if (bRealStart!==-1) {
		// starting navygation generation
		var arrHeaders=new Array();
		arrHeaders['Accept-Encoding']=" ";
		arrHeaders['Content-Type']="application/x-www-form-urlencoded";
		var sBody="speed="+escape(fPubSpeed);
		if (bRealStart) sBody+="&start=1";
		theNavyFlow.request('POST', "http://"+WD_HOST+"/webdirector/mdl_content/shell/gennavy2.php", "", "", arrHeaders, sBody);
		/* POST - To guarantee that the results are not cached */
		// timer to control theNavyFlow (ajax calls callback foo one time for each state only)
		if (theNavyTimer) {
			window.clearInterval(theNavyTimer);
			theNavyTimer=null;
		}
		theNavyTimer=window.setInterval('wd_gen_NavyFlow();', 500);
	}
	//
	return 1;
}