jQuery.noConflict();

var zoeken_not_clicked = true;
var zoeken_not_clicked2 = true;

function setZoeken(el) {
	if (zoeken_not_clicked) {
		el.value = ""
		zoeken_not_clicked = false;
	}
}

function setZoeken2(el) {
	if (zoeken_not_clicked2) {
		el.value = ""
		zoeken_not_clicked2 = false;
	}
}

function validateFilled(o) {
	switch(o.value.length > 0) {
		case true:
			o.className="valid";
			break;
		case false:
			o.className="error";
			break;
	}
}

function validateFloat(o) {
	o.value = parseFloat(o.value.replace(",", ".")).toString().replace(".",",");
	if (o.value == "NaN") {
		o.value = 0;
	}
	switch (isFloat(o.value)) {
		case true:
			o.className="valid";
			break;
		case false:
			o.className="error";
			break;
	}
}

function validateInt(o) {
	switch (isInteger(o.value)) {
		case true:
			o.className="valid";
			break;
		case false:
			o.className="error";
			break;
	}
}

function getElementsByClassName(classname,tag) {
   if(!tag) tag = "*";
   var anchs =  document.getElementsByTagName(tag);
   var total_anchs = anchs.length;
   var regexp = new RegExp('\\b' + classname + '\\b');
   var class_items = new Array()
 
    for(var i=0;i<total_anchs;i++) { //Go thru all the links seaching for the class name
        var this_item = anchs[i];
        if(regexp.test(this_item.className)) {
            class_items.push(this_item);
        }
    }
    return class_items;
}

function isFloat (s) {
	var i;
	if (s.length == 0)
		return false;
		
	for (i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if (!isDigit(c) && (c != ",")) 
			return false;
	}
	return true;
}

function isInteger (s) {
	var i;
	if (s.length == 0)
		return false;
		
	for (i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if (!isDigit(c)) 
			return false;
	}
	return true;
}

function print_pdf(doc) {
	pw = window.open(doc);
}

function isDigit (c) {
	return ((c >= "0") && (c <= "9"))
}


// zonneboilertool
jQuery(function() {
	
	
	jQuery('.zentasol a.extra_info').each(function() {
		var icon, content;
		icon = jQuery('.info', this);
		content = jQuery(this).parents('.answer').eq(0).find('.extra_info_content');

		icon
			.mouseover(function() {
				content.show();
			})
			.mouseout(function(){
				content.hide();
			});

		jQuery(this).click(function() { return false; });
	});

	jQuery('.zentasol div.next_step').click(function() {
		jQuery('a.next_step').click();
	});

	jQuery('.zentasol div.prev_step').click(function() {
		window.location = jQuery('a.prev_step').attr("href");
		return false; 
	});

	jQuery('.zentasol div.print').click(function() {
		window.print();
		return false;
	});
	
	jQuery('.zentasol div.pdf').click(function() {
		window.location = jQuery('a.make_pdf').attr("href");
		return false;
	});

	jQuery('.zentasol a.next_step').click(function() {
		jQuery('#submitform').submit();
		return false;
	});

	jQuery('.zentasol a.print').click(function() {
		window.print();
		return false;
	});

	//disable select
	jQuery(".zentasol input:radio").click(function() {
		if (this.value == 'no_remeha_boiler'){
			jQuery("form select").attr("disabled", "true"); 
			//all following form elements
			jQuery(".answer input").each(function(i) {
					jQuery(this).attr('disabled', 'disabled');
			});
			
			jQuery('.chooseboiler').removeAttr('disabled');
			
			//display next
			jQuery('.nextstep').show();
			

		}
		else if ( jQuery('input:radio[id=no_remeha_boiler_option]:checked').val() == "no_remeha_boiler" ) {
			jQuery("form select").attr("disabled", "true");
			jQuery('.nextstep').show();
		}
		else {
			jQuery("form select").removeAttr("disabled");
			jQuery(".answer input").each(function(i) {
					jQuery(this).removeAttr('disabled');

			});
			//display next
			jQuery('.nextstep').hide();
		}
		
		if (jQuery("#chooseboiler option:selected:first").text().match(/calenta/i)){
			var next_answer = jQuery("#chooseboiler").parents('.answers').eq(0).nextAll('.answers').eq(0);
			var radios = next_answer.find('input');
			radios.eq(1).attr('checked', 'checked');
			radios.eq(0).attr('disabled', 'disabled');
		}
		
		
	});
	
	if ( jQuery('.zentasol input:radio[id=no_remeha_boiler_option]:checked').val() == "no_remeha_boiler" ) {
		 jQuery(".answer input").each(function(i) {
						jQuery(this).attr('disabled', 'disabled');
				});
				
		 jQuery('.chooseboiler').removeAttr('disabled');
		 jQuery('.nextstep').show();
	}
	
	
	
	
	//Calenta no 'ombouw'

	jQuery(".zentasol #chooseboiler").each(function() {
		var boiler = jQuery(this);
		
		var first_time = true;
		
		var changeCalenta = function() {
			var next_answer = jQuery(boiler).parents('.answers').eq(0).nextAll('.answers').eq(0);
			var radios = next_answer.find('input');
			
			var check_calenta = jQuery(':selected', boiler).text().match(/calenta/i);
			
			if (check_calenta) {
				radios.eq(1).attr('checked', 'checked');
				radios.eq(0).attr('disabled', 'disabled');
			} else  {
				
				if (!first_time) {
					radios.eq(0).removeAttr('disabled');
					radios.eq(0).attr('checked', 'checked');
				}
			}
			
			
			if (first_time) first_time = false;
		}
		
		boiler.change(changeCalenta);
		changeCalenta();
	});
	
	
	
	var allOptions = jQuery('select#recipient_be').clone().html();
	//contactform
	var changePartner_Mampaey = function() {
		 jQuery('select#recipient_be').html(allOptions);
		 jQuery('#recipient_be').removeAttr('disabled');
		  jQuery("select#recipient_be option[value='6']").remove();
	}
	var changePartner_Thema = function() {
		 jQuery('select#recipient_be').html(allOptions);
		 jQuery("select#recipient_be option[value='2']").remove();
		 jQuery("select#recipient_be option[value='3']").remove();
		 jQuery("select#recipient_be option[value='4']").remove();
		 jQuery("select#recipient_be option[value='5']").remove();
		 jQuery('#recipient_be').removeAttr('disabled');
	}
	
	
	if (jQuery('select#partner_be').val() == 'Mampaey'){
		changePartner_Mampaey();
	}
	if (jQuery('select#partner_be').val() == 'Thema'){
		changePartner_Thema();
	}

	jQuery("select#partner_be").change(function() {
		jQuery("select#partner_be option:selected").each(function () {
                if (jQuery(this).val() == 'Mampaey'){
					changePartner_Mampaey();
				}
				else if (jQuery(this).val() == 'Thema'){
					 changePartner_Thema();
				}else {
					 jQuery('#recipient_be').attr('disabled', 'disabled');
				}
            });
	});


});

