
// ==== Asynchronous JavaScript and XML :) ===============================

function ajaxFunction(){
  var xmlHttp;
  try {
	// Firefox, Opera 8.0+, Safari
	xmlHttp=new XMLHttpRequest();
  } catch(e){
	// Internet Explorer
	try {
	  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  } catch(e){
	try {
	  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  } catch(e){
	  alert("Uw browser ondersteund geen AJAX!");
	  return false;
	  }
	}
  }
  return xmlHttp;
}

// ==== AJAX-FUNCTIES VOOR WEBDESIGN AANBIEDERS ==========================

function favoriet_opslaan(id){
	
	var xmlHttp = ajaxFunction();

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			
			var data = xmlHttp.responseText;
			
			document.getElementById('favoriet_text').innerHTML = "<a href='javascript:void(0);' onClick=\"favoriet_verwijderen('"+id+"');\">Verwijder uit favorieten</a> &raquo;";
			
			var mijn_favorieten_span = document.getElementById('mijn_favorieten_span');
			if(mijn_favorieten_span.style.display == 'block'){
				mijn_favorieten_span.style.display = 'none';
			}
			
			if(document.getElementById('favoriet'+id)){
				document.getElementById('favoriet'+id).style.display = 'block';
			} else {
				document.getElementById('mijn_favorieten').innerHTML += data;
			}
			
			
		}
	}
	
	xmlHttp.open("GET", "/ajax.inc.php?action=favoriet_opslaan&id="+id, true);
	xmlHttp.send(null);
	
	return true;
	
}
function favoriet_verwijderen(id){
	
	var xmlHttp = ajaxFunction();

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {

			var data = xmlHttp.responseText.split("|");

			document.getElementById('favoriet_text').innerHTML = "<a href='javascript:void(0);' onClick=\"favoriet_opslaan('"+data[0]+"');\">Opslaan in favorieten</a> &raquo;";

			document.getElementById('favoriet'+data[0]).style.display = 'none';
			if(data[1] == 0){
				document.getElementById('mijn_favorieten_span').style.display = 'block';
			}
			
		}
	}
	
	xmlHttp.open("GET", "/ajax.inc.php?action=favoriet_verwijderen&id="+id, true);
	xmlHttp.send(null);
	
	return true;
	
}
function beoordelen(id, categorie, cijfer){
	
	var xmlHttp = ajaxFunction();

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {

			var data = xmlHttp.responseText.split("|");
			
			document.getElementById('aantal_stemmen').innerHTML = data[0];
			document.getElementById('total_rating').innerHTML = data[1];
			document.getElementById('rating_'+categorie).innerHTML = data[2];
			alert(data[3]);
			
		}
	}
	
	xmlHttp.open("GET", "/ajax.inc.php?action=stem_uitbrengen&id="+id+"&categorie="+categorie+"&cijfer="+cijfer, true);
	xmlHttp.send(null);
	
	return true;
	
}

// ==== OVERIG ===========================================================

function star_hover(star, cat, a, b){
	for(var i = 1; i <= 5; i++){

		document.getElementById('star'+cat+i).style.width = '16px';
		if(star >= i){
			document.getElementById('star'+cat+i).style.background = 'url(http://www.webdesignaanbieders.nl/files/star_hover_small.jpg)';
		} else {

			document.getElementById('star'+cat+i).style.background = 'url(http://www.webdesignaanbieders.nl/files/star_small.jpg)';

			if(a >= i){
				document.getElementById('star'+cat+i).style.width = '16px';
			} else if(a == i-1){
				document.getElementById('star'+cat+i).style.width = b+'px';
			} else {
				document.getElementById('star'+cat+i).style.width = '0px';
			}
			document.getElementById('star'+cat+i).style.background = 'url(http://www.webdesignaanbieders.nl/files/star_over_small.jpg)';

		}

	}
}
function star_out(cat, a, b){
	for(var i = 1; i <= 5; i++){

		if(a >= i){
			document.getElementById('star'+cat+i).style.width = '16px';
		} else if(a == i-1){
			document.getElementById('star'+cat+i).style.width = b+'px';
		} else {
			document.getElementById('star'+cat+i).style.width = '0px';
		}
		document.getElementById('star'+cat+i).style.background = 'url(http://www.webdesignaanbieders.nl/files/star_over_small.jpg)';

	}
}
function smallstar_hover(cat, star){
	for(var i = 1; i <= 5; i++){

		if(star >= i){
			document.getElementById('smallstar'+cat+i).style.background = 'url(http://www.webdesignaanbieders.nl/files/star_over_small2.jpg)';
		} else {
			document.getElementById('smallstar'+cat+i).style.background = 'url(http://www.webdesignaanbieders.nl/files/star_small2.jpg)';
		}

	}	
}
function smallstar_out(cat, star){
	for(var i = 1; i <= 5; i++){

		if(star >= i){
			document.getElementById('smallstar'+cat+i).style.background = 'url(http://www.webdesignaanbieders.nl/files/star_over_small2.jpg)';
		} else {
			document.getElementById('smallstar'+cat+i).style.background = 'url(http://www.webdesignaanbieders.nl/files/star_small2.jpg)';
		}

	}	
}
function smallstar_click(cat, star){


	document.getElementById('beoordeling_'+cat).value = star;
}

// =======================================================================
