
/* AJAX */

/*
*/
function deleteObject(id)
{
	if(confirm("Weet u zeker dat u dit item wilt verwijderen?"))
		goTo("?delete=" + id);
}

/*
*/
function searchFor(what, value)
{
	if(value.length >= 1)
	{
		jQuery.ajax({
					type:    "GET",
					url:     ROOT_PATH + "php/script/zoek_naar_" + what + ".ajax.php",
					data:    ({value : value}),
					success: function(msg)
					{						
						document.getElementById("zoekresultaten").innerHTML = msg;
						
						switchOverzicht("uit");
					}
				   });
	}
	else
		switchOverzicht("aan");
}

/*
*/
function searchIn(what, fieldname, value)
{
	if(value.length >= 1)
	{
		jQuery.ajax({
					type:    "GET",
					url:     ROOT_PATH + "php/script/zoek_in_" + what + ".ajax.php",
					data:    ({value : value}),
					success: function(msg)
					{						
						document.getElementById("zoek_" + fieldname).innerHTML = msg;
						
						var gevonden_select = document.getElementById("gezocht_" + fieldname);
						
						if(gevonden_select.selectedIndex >= 0)
							setValue(fieldname + "_id", gevonden_select.options[gevonden_select.selectedIndex].value);
						
						switchSelect("uit", fieldname);
					}
				   });
	}
	else
		switchSelect("aan", fieldname);
}

/*
*/
function geefZoektermen(website_id)
{
	jQuery.ajax({
				 type:    "GET",
				 url:     ROOT_PATH + "php/script/zoektermen.ajax.php",
				 data:    ({website_id : website_id}),
				 success: function(msg)
				 {						
					 document.getElementById("zoektermen").innerHTML = msg;
				 }
			   });
}

/*
*/
function zoektermStats(website_id, zoekmachine_id, zoekterm_id, van_datum, tot_datum)
{
	setValue("website_id", website_id);
	
	if(van_datum == null)
		van_datum = getValue("van_datum_jaar") + "-" + getValue("van_datum_maand") + "-" + getValue("van_datum_dag");
	else
	{		
		var datum = van_datum.split("-");
		
		setValue("van_datum_jaar",  datum[0]);
		setValue("van_datum_maand", datum[1]);
		setValue("van_datum_dag",   datum[2]);
	}
	
	if(tot_datum == null)
		tot_datum = getValue("tot_datum_jaar") + "-" + getValue("tot_datum_maand") + "-" + getValue("tot_datum_dag");
	else
	{
		var datum = tot_datum.split("-");
		
		setValue("tot_datum_jaar",  datum[0]);
		setValue("tot_datum_maand", datum[1]);
		setValue("tot_datum_dag",   datum[2]);
	}
	
	if(zoekmachine_id > 0)
		document.getElementById("zoekterm_statistieken").innerHTML = "<img src=\"" + ROOT_PATH + "php/script/zoekterm_stats.ajax.php?zoekmachine_id=" + zoekmachine_id + "&zoekterm_id=" + zoekterm_id + "&van_datum=" + van_datum + "&tot_datum=" + tot_datum + "\" style=\"margin-top: 20px;\" />";
	else
	{
		jQuery.ajax({
					 type:    "GET",
					 url:     ROOT_PATH + "php/script/zoekterm_stats.ajax.php",
					 data:    ({zoekmachine_id : zoekmachine_id,
								zoekterm_id    : zoekterm_id,
								van_datum      : van_datum,
								tot_datum      : tot_datum}),
					 success: function(msg)
					 {						
						 document.getElementById("zoekterm_statistieken").innerHTML = msg;
						 
						 setValue('zoekterm_id', zoekterm_id);
					 }
				   });
	}		
}

/*
*/
function switchOverzicht(status)
{
	if(status == "uit")
	{
		document.getElementById("overzicht").style.display      = "none";
		document.getElementById("zoekresultaten").style.display = "block";
	}
	else
	{
		document.getElementById("zoekresultaten").style.display = "none";
		document.getElementById("overzicht").style.display      = "block";		
	}
}

/*
*/
function switchSelect(status, fieldname)
{
	if(status == "uit")
	{
		document.getElementById("select_" + fieldname).style.display = "none";
		document.getElementById("zoek_" + fieldname).style.display   = "block";
	}
	else
	{
		document.getElementById("zoek_" + fieldname).style.display   = "none";
		document.getElementById("select_" + fieldname).style.display = "block";		
	}
}

/* FORM */

/*
*/
function getValue(id)
{
	var element = document.getElementById(id);
	
	if(element != null)
	{
		if(element.tagName == "select")
			return element.options[element.selectedIndex].value;
		else
			return element.value;
	}
	else
		return null;
}

/*
*/
function setValue(id, value)
{
	var element = document.getElementById(id);
	
	if(element != null)
	{
		if(element.tagName == "select")
		{
			for(var o = 0; o < element.options; o++)
			{
				if(element.options[o].value == value)
					element.selectedIndex = o;
			}
		}
		else
			element.value = value;
	}
}

/*
*/
function submitForm(id)
{
	var element = document.getElementById(id);
	
	if(element != null)
		element.submit();
}


/* LOG */

/*
*/
function log()
{	
	var scherm_resolutie = screen.width + "x" + screen.height;
	var flash_versie     = GetSwfVer(); //adobe function
	
	document.write("<iframe src=\"" + ROOT_PATH + "php/script/stats.php?scherm_resolutie=" + scherm_resolutie + "&flash_versie=" + flash_versie + "\" style=\"display: none;\" /></iframe>");
}


/* NAV */

/*
*/
function goTo(url)
{
	document.location.href = url;
}


/* CHART */
var chart;

function createChart(d, c, t, s)
{
	chart = new Highcharts.Chart({
			chart: {
				renderTo: c,
				defaultSeriesType: 'area',
				zoomType: 'x',
                borderWidth: 0,
                marginLeft: 70
			},
            
            legend: {enabled: false},
			
			title: {text: t},
			
			xAxis: {
				//categories: s,
				labels: {
					rotation: 90
				}
			},
			
			yAxis: {
				title: {text: 'Rank'}
			},
			
			tooltip: {
				formatter: function()
				{
					return "<b>"+this.point.name+'</b> '+'Rank: '+this.y;
				}
			},
			
			plotOptions: {
				area: {
					lineWidth: 1,
					marker: {
						enabled: false,
						states: {
							hover: {
								enabled: true,
								radius: 5
							}
						}
					},
					shadow: true,
					states: {
						hover: {
							lineWidth: 1
						}
					}
				}
			},
			
			series: [{
				data: d
			}],
            
            credits: { enabled: false }
		});
};


/**
*	Deselect functie voor BEHEER / RAPPORTAGE / OVERZICHT
*/
$(document).ready(function()
{

	$('.updateStatClass').click(function(e)
	{
		if($(this).hasClass("on"))
		{
			$(this).removeAttr('checked');
		}
		$(this).toggleClass("on");
		
		// check het aantal geselecteerde items
		if($('.topterm:checked').length == 5 && $('.bottomterm:checked').length == 3)
		{
			$('input[name="next"]').removeAttr("disabled");
			alert('Je kunt nu verder naar de volgende stap!');
		}
		else
			$('input[name="next"]').attr("disabled","disabled");
		
	}).filter(":checked").addClass("on");

});




