 $(document).ready(function() { 
	$('#homeButton').hide();
	$.ajaxSetup({
	    'beforeSend' : function(xhr) {
	        xhr.overrideMimeType('text/html; charset=UTF-8');
	    },
	});
	//$("#loading").hide();
           // bind 'myForm' and provide a simple callback function 
	setupForm();
	testCookie();
});

function HideNavBar() {
setTimeout(scrollTo, 0, 0, 1);
}

function testCookie() {
	if (document.cookie.indexOf('language') != -1) { 
		   //A-OK
		 } 
		 else { 
			setCookie('language','nl');
		 }
}
function setCookie(name, value, expires, path, domain, secure) { 
	show_loading(true);
	var exp = new Date(); 
	 exp.setTime(exp.getTime() + 1800000);
	 var curCookie = name + "=" + escape(value) + 
		 "; expires=" + exp.toGMTString() + 
		((path) ? "; path=" + path : "") + 
		((domain) ? "; domain=" + domain : "") + 
		((secure) ? "; secure" : ""); 
	 document.cookie = curCookie; 
	location.reload(true);
	}
	
function show_loading(bool) {
	if (bool) {
		document.getElementById('loading_div').style.display='block';
		$("#loading").show();
	} else {
		document.getElementById('loading_div').style.display='none';
		$("#loading").hide();
	};
	
}
function getLater(station_id, station_text, hour, station_type)
{
		show_loading(true);
		$.get("data/small_data.php", {
				__EVENTARGUMENT : 'S'	, 
				__EVENTTARGET : 'S'		,
				stationIdHiddenField 	: station_id,
				stationTextBox			: station_text,
				timeRangeDropDownList	: hour,
				stationType				: station_type }
				, function(data) {
					$('#content').replaceWith(data);
					show_loading(false);
				}, 'html');
}

function setupForm()
{
	var options = {
		target:        '#content',   // target element(s) to be updated with server response 
		beforeSubmit:  showRequest,  // pre-submit callback 
		success:       showResponse  // post-submit callback
	}
	$.ajaxSetup({
	    'beforeSend' : function(xhr) {
	        xhr.overrideMimeType('text/html; charset=UTF-8');
	    },
	});
	$('#the_form').ajaxForm(function(html) { 
	   	$('#content').replaceWith(html);
		$("#loading").hide();
		$(".front_footer").hide();
		$('#homeButton').show();
	   });
}
function showRequest(formData, jqForm, options) { 
   	show_loading(true);
    return true; 
}
// post-submit callback 
function showResponse(responseText, statusText)  { 
	show_loading(false);
}
function goBack()
{
	$("#loading").show();
	$.get("../form.php", function(data) {
		$('#content').replaceWith(data);
		$("#loading").hide();
		$(".front_footer").show();
		$('#homeButton').hide();
		setupForm();
		
	})
}


