

	var loading = false;

	function endAjaxCIRC() { 
		loading = false;
		Effect.Fade('indicatorTR', {duration: 0});	
		correctHeight();
		if (document.getElementById('file')) document.getElementById('file').value = '';
		if (document.getElementById('embed')) document.getElementById('embed').value = '';
		if (document.getElementById('email')) document.getElementById('email').value = '';		
	}
	
	function startAjaxCIRC() {
		loading = true;
		Effect.Appear('indicatorTR', {duration: 0});	
	}
	
	function circuitFunc(sector_id, whatTo) {
		getAjaxForC(sector_id, whatTo);
		
	}
	
	function newxPage(sector_id, onxpage, isvideo) {
		
		var vrz = new Array();
		vrz.push(new Array('circuit_id',document.getElementById('circuit_id').value));
		if (sector_id) vrz.push(new Array('sector_id',sector_id.toString()));
		vrz.push(new Array('ctype', (isvideo ? 'videosinner' : 'picturesinner')));
		vrz.push(new Array('onpage',onxpage.toString()));
				
		var jvz = getXMLPostbody(vrz);
		
		startAjaxCIRC();
		new Ajax.Request('/dloc/ajax/Circuit__doMe/moto/ger/',
			{
				method:'post',
				postBody: jvz,
				onSuccess: function(transport) {
					var response = transport.responseText || '';
					if (document.getElementById('selxx')) document.getElementById('selxx').innerHTML=response;
					endAjaxCIRC();
				},
				onFailure: function() { 
					alert('Ajax error...');
					pageTracker._trackPageview('ajax/error'); 
					endAjaxCIRC();
				}
			}
		);
		
	}

	function getAjaxForC(sector_id, what, isrates) {
		if (loading) return;
		
		if (what == 'tickets') {
			document.location = 'https://www.mygpticket.com/moto/ger/race/germany_motogp#'+sector_id;
			return;
		}
		
		var vrz = new Array();
		vrz.push(new Array('circuit_id',document.getElementById('circuit_id').value.toString()));
		if (sector_id) vrz.push(new Array('sector_id',sector_id.toString()));
		vrz.push(new Array('ctype',what.toString()));
		if (isrates) {
			var myrates = document.getElementById('A_v').value.toString() + document.getElementById('B_v').value.toString() + document.getElementById('C_v').value.toString() + document.getElementById('D_v').value.toString();
			vrz.push(new Array('myrate', myrates));		
		}

		var jvz = getXMLPostbody(vrz);
		
		startAjaxCIRC();
		
		new Ajax.Request('/dloc/ajax/Circuit__doMe/moto/ger/',
			{
				method:'post',
				postBody: jvz,
				onSuccess: function(transport) {
					var response = transport.responseText || '';
					document.getElementById('circuit_ajax_div').innerHTML=response;
					endAjaxCIRC();
					Element.scrollTo('circuit_ajax_div');
					pageTracker._trackPageview('ajax/'+what); 
					
				},
				onFailure: function() { 
					alert('Ajax error...');
					pageTracker._trackPageview('ajax/error'); 
					endAjaxCIRC();
				}
			}
		);
			
	}

	function showBigPic(urlpic, isvideo, ishelp, sector_id, addit) {
		document.getElementById('clearMe').style.visibility = 'hidden';		
		if (!ishelp) {
			document.getElementById('containedbyme').style.padding = '10px 0 10px 0';
			if (!isvideo) {
				document.getElementById('containedbyme').innerHTML = '<img src="'+urlpic+'">';
			} else {
				var soxbig = new SWFObject(urlpic, "mai", "425", "355", "8", "#000");
				soxbig.addParam("allowScriptAccess", "allDomain");
				soxbig.addParam("quality", "best"); 
				soxbig.addParam("scale", "noscale"); 
				soxbig.addParam("wmode", "transparent"); 
				soxbig.addParam("salign", "lt"); 
				soxbig.write("containedbyme");		
			}
			pageTracker._trackPageview('ajax/showbig'); 
		} else {
			document.getElementById('containedbyme').style.verticalAlign = 'top';
			document.getElementById('containedbyme').style.textAlign = 'left';			
			document.getElementById('containedbyme').style.padding = '25px';
			var vrz = new Array();
			vrz.push(new Array('circuit_id',document.getElementById('circuit_id').value.toString()));
			if (sector_id) vrz.push(new Array('sector_id',sector_id.toString()));
			vrz.push(new Array('ctype', 'help'));
			if (addit) {
				vrz.push(new Array('additional', addit));		
			}					
			var jvz = getXMLPostbody(vrz);			
			new Ajax.Request('/dloc/ajax/Circuit__doMe/moto/ger/',
			{
					method:'post',
					postBody: jvz,
					onSuccess: function(transport) {
						var response = transport.responseText || '';
						document.getElementById('containedbyme').innerHTML=response;
					},
					onFailure: function() { 
						alert('Ajax error...');
						pageTracker._trackPageview('ajax/error'); 
					}
				}
			);
		}
		document.getElementById('bigPictureIshere').style.display = 'block';
		correctHeight();
	}

	function hideBigPic() {
		document.getElementById('bigPictureIshere').style.display = 'none';
		document.getElementById('containedbyme').style.verticalAlign = 'middle';
		document.getElementById('containedbyme').style.textAlign = 'center';
		document.getElementById('containedbyme').style.padding = '0';
		document.getElementById('containedbyme').innerHTML = '&nbsp;';
		document.getElementById('clearMe').style.visibility = 'visible';
	}
	
	function uploadBegin() {
		startAjaxCIRC();
		document.getElementById('picupl').submit();
	}
	
	function showMessage(msg) {
		if (msg == '0') {
			window.alert("Fehler! ( akzeptieren wir : gif / jpeg )");
		}
		if (msg == '1') {
			window.alert("Upload erfolgreich!");
		}
		if (msg == '0v') {
			window.alert("Zuerst kopieren Sie &quot;Einbetten code&quot; ein, dann klicken Sie &quot;schicken&quot;!");
		}
		if (msg == '1v') {
			window.alert("Ihre Upload war erfolgreich, wir werden Ihres Video ansehen und in 24 Stunden genehmigen. Bitte kommen Sie zurück und schauen Sie es an unseres Website auch an.");
		}
	}
	
	function canIdo() {
		if (document.getElementById('A_v').value == '') return false;
		if (document.getElementById('B_v').value == '') return false;
		if (document.getElementById('C_v').value == '') return false;
		if (document.getElementById('D_v').value == '') return false;
		return true;
	}
	
	function rateBegin(seid) {
		if (canIdo()) {
			if ($("circuit-iframe") != null) {
				document.getElementById('circuit-iframe').contentWindow.location = $("circuit-iframe").readAttribute("data-src").replace("[sectorID]", "sector_id=" + seid + "&");
			} else {
				load_flash_into(globalsr+'&sector_id='+seid, 'circuitflashh', 'circFlash', 550, 400, true);
			}
			getAjaxForC(seid, 'rates', true);
		}
	}
		
	function STclicked(typ, val) {
		document.getElementById(typ+'_v').value = val;
		for (var x = 1; x <= 5; x++) {
			document.getElementById(typ+x.toString()).className = ( val == x ? 'active' : '' );	
		}
		if (canIdo()) {
			new Effect.Opacity('sbutton', {from: 0.3, to: 1.0, duration: 2.0});	
		}
	}

