
// Server Belastungs Test einschalten (inkl. Login)
var gLoadTestEnabled = false;
var gLoadTestUser = "";
var gLoadTestPass = "";

// Min. Wartezeit zwischen den "Klicks" [ms]
var gLoadTestTimer = 3000;


// Interne Daten/Funktionen
var gLoadTestDlgId = "";
var gLoadTestState = -1;

if (gLoadTestEnabled && gLoadTestState == -1)
{
	gLoadTestState++;
	
	setTimeout("LoadTestLoop()", gLoadTestTimer);
}


// Helper function: getEl (getElementById)
if (typeof getEl == 'undefined') {
	getEl = function(_ref)
	{
		var ref = _ref || window.event;
		var obj = null;
		
		if (typeof ref == 'object') {
			if (ref.tagName)
				obj = ref;
			else if (ref.target) {
				obj = ref.target.tagName ? ref.target : ref.target.parentNode;
			}
			else if (ref.srcElement) {
				obj = ref.srcElement.tagName ? ref.srcElement : ref.srcElement.parentNode;
			}
		}
		else if (typeof ref == 'string') {
			obj = document.getElementById(ref);
		}
		return obj;
	}
}

// Helper function: getRTStyle (get runtime style)
if (typeof getRTStyle == 'undefined') {
	getRTStyle = function(_ref)
	{
		var obj = (typeof _ref == 'string') ? getEl(_ref) : _ref;
		
		if (typeof obj != "object")
			return new Object; // Dummy um Javascript Error zu vermeiden
		
		if(typeof getComputedStyle == 'function')
		{	// Mozilla, Firefox, ...
			return document.defaultView.getComputedStyle(obj,null);
		}
		else
		{	// IE
			return obj.currentStyle;
		}
	}
}



// Main functions

function LoadTestLoop()
{
	if (gLoadTestEnabled)
		setTimeout("LoadTestLoop()", gLoadTestTimer);

	try 
	{
		/*var rand = Math.random() * 100;
		if (rand <= 3) {
			location.href = (location.href + "?rand=" + rand); // neue Session
		}*/
	
		var dlgId = document.body.id;
		
		if (dlgId && dlgId != gLoadTestDlgId) {
			gLoadTestDlgId = dlgId;
			gLoadTestState = 0;
		}
		
		switch (dlgId) 
		{
		case "IDD_ZA00":
			LoadTest_ZA00();
			break;
			
		case "IDD_ZA01":
			LoadTest_ZA01();
			break;
			
		default:
			if (!dlgId)
				alert("LoadTestLoop: Unknown DialogId '" + dlgId + "'");
		}
	}
	catch (e) {
		//alert(e.message);
	}
}



function LoadTest_ZA00()
{
	//alert(gLoadTestState);
	
	switch(gLoadTestState)
	{
	case 0:
		if (getRTStyle("IDC_GOTO_ZA02").visibility == "visible")
		{
			gLoadTestState = 2;
			getEl("IDC_GOTO_ZA02").click();
		}
	
		if (getRTStyle("IDC_EDIT_USERID").visibility == "visible")
		{
			if (getEl("IDC_EDIT_USERID").value != "" &&
				getEl("IDC_EDIT_PASSWD").value != "")
			{
				gLoadTestState++;
			}
			else if (gLoadTestUser != "" && gLoadTestPass != "")
			{
				getEl("IDC_EDIT_USERID").value = gLoadTestUser;
				getEl("IDC_EDIT_PASSWD").value = gLoadTestPass;
				gLoadTestState++;
			}
		}
		break;
	
	case 1:
		if (getRTStyle("IDC_EDIT_USERID").visibility == "visible")
		{
			gLoadTestState = 0;
			getEl("IDC_AGB_CHECK").checked = true;
			getEl("IDC_AGB_OK").click(); // page reload
		}
		break;
	
	case 2:
		break;
	}
}



function LoadTest_ZA01()
{
	//alert(gLoadTestState);

	switch(gLoadTestState)
	{
	default:
	case 0:
		getEl("VOLUMENSTROM_EDIT").value = 2000 + Math.round(Math.random() * 3000);
		getEl("STATIDRUCK_EDIT").value = 100 + Math.round(Math.random() * 1400);
		
		if (getEl("IDC_SEARCH"))
		{
			gLoadTestState++;
			getEl("IDC_SEARCH").click();
		}
		break;
		
	case 1:
		if (simtGetDisabled("IDC_ZA02_TABLE") == false)
		{
			simtSelectRow("IDC_ZA02_TABLE_1");
			gLoadTestState++;
		}
		break;
		
	case 2:
		if (simtGetSelectedRow("IDC_ZA02_TABLE") != "IDC_ZA02_TABLE_1")
		{
			simtSelectRow("IDC_ZA02_TABLE_1");
		}
		else
		{
			gLoadTestState++;
			getEl("IDC_KL").click();
		}
		break;
		
	case 3:
		if (getEl("IDC_DET_STEMPELDATEN"))
		{
			gLoadTestState++;
			getEl("IDC_DET_STEMPELDATEN").click();
		}
		break;
		
	case 4:
		if (getEl("IDC_TAB_VENTILATORAUSWAHL"))
		{
			gLoadTestState = 0;
			getEl("IDC_TAB_VENTILATORAUSWAHL").click();
		}
		break;
	}
}
