var def_width = 0;
var def_height = 0;

var tesztIDk = null;

function ol() {
	var so = new SWFObject( "flash/menu.swf", "menu_swf", "207", "560", "7", "#FFFFFF" );
	so.addParam( "scale", "noscale" ); 
	so.write( "middle_left" );

	setSize();
	
	keepAlive();
}

function keepAlive() {
	getReq( 'alive', '' );	
	setTimeout( "keepAlive()", 60000 );
}

function setSize() {
	try {

		var myWidth = 0, myHeight = 0;
		if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		}
	
		var top_center = document.getElementById( "top_center" );
		top_center.style.width = myWidth - 207 - 176;
	
		if ( def_width != myWidth || def_height != myHeight ) {
	
			var top_center_top  = document.getElementById( "top_center_top" );
			var top_flash_width = myWidth - 207 - 176;
			var s = '';
			s += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + top_flash_width + '" height="90" id="top_linea" align="left">';
			s += '	<param name="allowScriptAccess" value="sameDomain" />';
			s += '	<param name="movie" value="flash/top.swf" />';
			s += '	<param name="quality" value="high" />';
			s += '	<param name="bgcolor" value="#ffffff" />';
			s += '	<embed src="flash/top.swf" quality="high" bgcolor="#ffffff" width="' + top_flash_width + '" height="90" name="top_linea" align="left" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
			s += '</object>';
			top_center_top.innerHTML = s;
	
			var container_middle = document.getElementById( "container_middle" );
			container_middle.style.height = myHeight - 131 - 36;
			container_middle.style.width  = myWidth;
	
			var middle_center = document.getElementById( "middle_center" );
			middle_center.style.width  = myWidth - 207 - 176;
			middle_center.style.height = myHeight - 131 - 36;
	
			def_width  = myWidth;
			def_height = myHeight;
		}
	
		var szam = 0;
		do {
			szam++;
			var obj = document.getElementById( "cimke_center_" + szam );
			if ( obj != null ) {
				obj.style.width = myWidth - 207 - 176 - 21 - 506 - 30;
			}
		} while ( obj != null );
	
		var container_bottom = document.getElementById( "container_bottom" );
		container_bottom.style.top = myHeight - 36;
	
		var bottom_left = document.getElementById( "bottom_left" );
		bottom_left.style.width = myWidth - 176;

	} catch ( e ) {}

	setTimeout( "setSize()", 1000 );
}

function newXMLHttpRequest() {
	if ( window.XMLHttpRequest ) {
		httpRequest = new XMLHttpRequest();
		if ( httpRequest.overrideMimeType ) {
			httpRequest.overrideMimeType( 'text/xml' );
		}
	} else if ( window.ActiveXObject ) {
		try {
			httpRequest = new ActiveXObject( "Msxml2.XMLHTTP" );
		} catch ( e ) {
		try {
			httpRequest = new ActiveXObject( "Microsoft.XMLHTTP" );
			} catch ( e ) {}
		}
	}

	if ( !httpRequest ) {
		alert( 'Giving up :( Cannot create an XMLHTTP instance' );
		return false;
	}
	
	return httpRequest;
}

function getPage( page ) {
	var httpRequest = newXMLHttpRequest();
	httpRequest.from = "getPage";
	httpRequest.onreadystatechange = function() { alertContents( httpRequest, page ) };
	httpRequest.open( 'POST', 'getpage.php?page=' + page, true );
	httpRequest.setRequestHeader( "Connection", "close" );
	httpRequest.send( "" );
	var obj = document.getElementById( "loading" );
	obj.style.display = 'block';

	if ( page == "test" ) {
		getReq( 'test', 'action=getIDs&nyelv=angol' );
	}
}

function getReq( page, parameter ) {
	var httpRequest = newXMLHttpRequest();
	httpRequest.from = "getReq";
	if ( page == "applyform" ) {
		httpRequest.open( 'POST', 'apply.php', true );
	} else if ( page == "test" || page == "test.check" ) {
		httpRequest.open( 'POST', 'test.php', true );
	} else if ( page == "alive" ) {
		httpRequest.open( 'POST', 'alive.php', true );
	}
	httpRequest.onreadystatechange = function() { alertContents( httpRequest, page ) };
	httpRequest.setRequestHeader( "Content-type", "application/x-www-form-urlencoded" );
	httpRequest.setRequestHeader( "Connection", "close" );
	httpRequest.send( parameter );
	if ( page != 'alive' ) {
		var obj = document.getElementById( "loading" );
		obj.style.display = 'block';
	}
}

function alertContents( httpRequest, page ) {

	var obj = document.getElementById( "loading" );

	if ( httpRequest.readyState == 4 ) {
		if ( httpRequest.status == 200 ) {

			if ( page == "applyform" ) {
				if ( httpRequest.responseText == "OK" ) {
					getPage( "applyok" );
				} else {
					applyError( httpRequest.responseText );
				}
			} else if ( page == "test" ) {
				
				if ( httpRequest.from == "getPage" ) {
					cont = document.getElementById( "middle_center" );
					cont.innerHTML = httpRequest.responseText;
				} else {
					tesztIDk = eval( '(' + httpRequest.responseText + ')' );		
				}

			} else if ( page == "test.check" ) {
			
				if ( httpRequest.from == "getPage" ) {
					cont = document.getElementById( "middle_center" );
					cont.innerHTML = httpRequest.responseText;
				} else {
					getPage( 'test.check' );				
				}
				
			} else if ( page == "alive" ) {
			
				//Do nothing
				
			} else {

				cont = document.getElementById( "middle_center" );
				cont.innerHTML = httpRequest.responseText;

				if ( page == "terkep" ) {
					var soTerkep = new SWFObject( "flash/terkep.swf", "mymovie", "500", "299", "9", "#FFFFFF" );
					soTerkep.write( "terkemSFW" );
				} 

			}

			obj.style.display = 'none';

		} else {
			alert( 'There was a problem with the request.' );
			obj.style.display = 'none';
		}
	}

}

function openWindow( _url, _name, _param ) {
	var i_name = window.open( _url, _name, _param );
}

function applyError( errmsg ) {
	var o_name = document.getElementById( "errormsg" );
	o_name.innerHTML = '<font size="3" color="red"><b>' + errmsg + '</b></font>';
}

function sendapplyFunc() {
	var param    = "";
	var obj      = null;
	var obj_form = null;

	obj_form = document.getElementById( "applyform" );

	obj = document.getElementById( "name" );
	param += 'name=' + obj.value;
	obj = document.getElementById( "telnr" );
	param += '&telnr=' + obj.value;
	obj = document.getElementById( "email" );
	param += '&email=' + obj.value;
	obj = obj_form.nyelv;
	var selectedItem = null;
	for( var i = 0; i < obj.length; i++ ) {
		if ( obj[ i ].checked )
			selectedItem = obj[ i ];
	}
	if ( selectedItem != null )
		param += '&nyelv=' + selectedItem.value;

	obj = obj_form.chk_hesze;
	if ( obj.checked )
		param += '&chk_hesze=' + obj.value;
	obj = obj_form.chk_kecse;
	if ( obj.checked )
		param += '&chk_kecse=' + obj.value;
	obj = obj_form.chk_szo;
	if ( obj.checked )
		param += '&chk_szo=' + obj.value;
	obj = obj_form.chk_mas;
	if ( obj.checked )
		param += '&chk_mas=' + obj.value;

	obj = document.getElementById( "othertime" );
	param += '&othertime=' + obj.value;

	getReq( "applyform", param );
}

function doTestCheck() {
	var param = "action=analyzeTest&";
	var obj   = null;
	for( var key in tesztIDk ) {
		obj = document.getElementById( "r_" + tesztIDk[ key ] + "_a" );
		if ( obj.checked )
			param += "r_" + tesztIDk[ key ] + "=1&";
		obj = document.getElementById( "r_" + tesztIDk[ key ] + "_b" );
		if ( obj.checked )
			param += "r_" + tesztIDk[ key ] + "=2&";
		obj = document.getElementById( "r_" + tesztIDk[ key ] + "_c" );
		if ( obj.checked )
			param += "r_" + tesztIDk[ key ] + "=3&";
	}
	getReq( 'test.check', param );
}

