/**
 * $Id: producteigenschappen.js 17 2011-04-14 11:50:17Z projects $
 * 
 * js/producteigenschappen.js
 */

IE = (document.all ? true : false);

tempX = 0
tempY = 0

function getMouseXY(e) {
	
	if (IE) {
	  	tempX = event.clientX + document.documentElement.scrollLeft;
		tempY = event.clientY + document.documentElement.scrollTop;
	} else {
		tempX = e.pageX
		tempY = e.pageY
	}  
	
	if (tempX < 0) {
		tempX = 0;
	}
	  
	if (tempY < 0) {
		tempY = 0
	}
	
	var meer_info_div = document.getElementById('meer_info_div');
	
	if (meer_info_div && meer_info_div.style.display == 'block') {
		var divHeight = meer_info_div.clientHeight;
	
		meer_info_div.style.top = (tempY) + "px"; 
        meer_info_div.style.left = (tempX + 50) + "px";
	}
}	


function init_producteigenschappen() {
	var producteigenschappen = document.getElementById('producteigenschappen');
	
	if (producteigenschappen) {
		// Zoek alle radiobuttons en checkboxes op
		var inputs = producteigenschappen.getElementsByTagName('input');
		
		if (inputs && inputs.length > 0) {
			
			for (var i = 0; i < inputs.length; i++) {
				if (inputs[i].type == 'radio') {
					inputs[i].parentNode.onmouseover = producteigenschap_onmouseover;
					inputs[i].parentNode.onmouseout = producteigenschap_onmouseout;
					inputs[i].parentNode.onclick = producteigenschap_onclick;
				}
				
				if (inputs[i].type == 'checkbox') {
					inputs[i].parentNode.onmouseover = producteigenschap_onmouseover;
					inputs[i].parentNode.onmouseout = producteigenschap_onmouseout;
					inputs[i].parentNode.onclick = producteigenschap_onclick;
				}
			}
		}
	}
	
	if (document.addEventListener) {
		document.addEventListener("mousemove",getMouseXY,false);
	} else {
		document.onmousemove = getMouseXY;
	}
}

function producteigenschap_onmouseover() {
	if (!this.className.match(/selected/)) {
		add_class_name(this, 'hover')
	}
}

function producteigenschap_onmouseout() {
	remove_class_name(this, 'hover')	
}

function producteigenschap_onclick() {
	maak_keuze(this.id);
}

function maak_keuze(id) {

	var elt = document.getElementById(id);
	
	if (elt) {
	
		// Select the proper radio button or checkbox.
		var inputs = elt.getElementsByTagName('input');
		
		if (inputs && inputs.length > 0) {
			for (var i = 0; i < inputs.length; i++) {
				if (inputs[i].type == 'radio') {
					inputs[i].checked = true;
					var input_name = inputs[i].name;
					var input_id = inputs[i].id;
					var input_type = inputs[i].type;
					var input_state = 'on';
				} else if (inputs[i].type == 'checkbox') {
					if (inputs[i].checked) {
						inputs[i].checked = false;
						var input_type = inputs[i].type;
						remove_class_name(inputs[i].parentNode, 'selected');
						//add_class_name(inputs[i].parentNode, 'not_selected');
						var input_state = 'off';
					} else {
						inputs[i].checked = true;
						var input_name = inputs[i].name;
						var input_id = inputs[i].id;
						var input_type = inputs[i].type;
						var input_state = 'on';
					}
				}
			}
			
			if (input_type == 'radio')  {
				// Locate the other option
				var matches = input_id.match(/(.*)(_l|_r)/);
				
				if (matches && matches.length == 3) {
					
					if (matches[2] == '_l') {
						var other_id = matches[1] + '_r';
					} else {
						var other_id = matches[1] + '_l';
					}
					
					var other_radio = document.getElementById(other_id);
					if (other_radio) {
						other_radio.checked = false;
						remove_class_name(other_radio.parentNode, 'selected');
						add_class_name(other_radio.parentNode, 'not_selected');
					}
				}
			}
		}
		
		if (input_state == 'on') {
			remove_class_name(elt, 'not_selected');
			remove_class_name(elt, 'hover');
			add_class_name(elt, 'selected');
		}

		if (typeof(update_prijs) == 'function') {
			update_prijs();
		}
	}
}

