// JavaScript Document
/* copyright lwwebprograms.nl */
$windowInnerWidth = 0;
$windowInnerHeight = 0;

function getInnerWindowHeight()
{
    /* from a script by Jan Peter Koch - quirksmode.org */
    if (window.innerHeight) {
        /* all except Explorer */
    	$windowInnerWidth = window.innerWidth;
    	$windowInnerHeight = window.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        /* Explorer 6 Strict Mode */
    	$windowInnerWidth = document.documentElement.clientWidth;
    	$windowInnerHeight = document.documentElement.clientHeight;
    } else if (document.body) {
        /* other Explorers */
    	$windowInnerWidth = document.body.clientWidth;
    	$windowInnerHeight = document.body.clientHeight;
    }
    return new Array($windowInnerWidth, $windowInnerHeight);
}

function setHeight()
{
	var maxHeight = jQuery('div#lft').height();
	if (jQuery('div#rgt').height() > maxHeight)
		maxHeight = jQuery('div#rgt').height();
	var windowHeight = jQuery(window).height();
	if (windowHeight-362 > maxHeight)
		maxHeight = windowHeight-362;
	maxHeight = maxHeight +30;	 
	jQuery('div#content_div_id div#rgt').css({'height': maxHeight + 'px'});
	jQuery('div#content_div_id div#lft').css({'height': maxHeight + 'px'}); 
}

function compareColumnsHeight()
{
	jQuery('div#lft').css({height: jQuery('div#rgt').height() + 'px'});
}

function fixIntroPageLayout()
{
	var windowHeight = jQuery(window).height();
	var usedHeight = 44+39+300;
	if (windowHeight-usedHeight > 310) 
		jQuery('div#content_wrapper_bottom').css({'height':windowHeight-usedHeight + 'px'});
}

jQuery(window).load(function() {
	try {
		jQuery(document).pngFix();
	
		jQuery("ul.sf-menu").superfish({
		  	animation: {height:'show'},   // slide-down effect without fade-in 
	    	delay:     1200,
	    	autoArrows: false
		}); 
		// init top tab menu
		jQuery('.menu li ').each(function(it, el) {
			jQuery(this).bind('mouseover', function() {
				if (this.className != 'hover active')
					this.className = this.className.replace(/\s*/,'') + 'hover';
			});
			jQuery(this).bind('mouseout', function() {
				if (this.className != 'hover active') { 
					this.className = this.className.replace(/\s*hover\s*/,'');
				}
			});
			jQuery(this).bind('click', function() {
				
			});
		});
	 } catch (error) {}
	try {
		jQuery('ul.news_list li').bind('mouseover', function() {
		   	jQuery(this).addClass(' hover'); 
		});
		jQuery('ul.news_list li').bind('mouseout', function() {
		   	jQuery(this).removeClass(' hover');
		});
		jQuery('ul.news_list li').bind('click', function() {
		   	
		});
	} catch (error) {
	
	}
	try {
		jQuery('table.full_education_list tr').hover(function() {
		    jQuery(this).addClass('hover');
		}, function() {
			jQuery(this).removeClass('hover');
		});
		jQuery('table.full_education_list tr').click(function() {
		   location.href = jQuery('a', jQuery(this)).attr('href');
		});
	} catch (error) {
	
	}
});

jQuery(document).ready(function() {
   	try {
		jQuery('form#newsletter_signup').submit(function() {
		   	var emailVal = jQuery('input[name=emailaddress]', jQuery(this)).val();
		   	var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		   	
			if (emailVal == "") {
				jQuery('form#newsletter_signup div.error').html('Verplicht veld').show();	
			} else if (!filter.test(emailVal)) {
				jQuery('form#newsletter_signup div.error').html('Onjuist e-mailadres').show();
			} else {
				// everything ok!
				jQuery('div#newsletter_cont').html('<img src="/img/loadingAnimation.gif" />');	
				jQuery.post('/ajax_server.php?app=newsletter&action=signup',
			  	{ 
			  		email : emailVal
				},
			  	function(data){
			  		if (data) {
			  			jQuery('div#newsletter_cont').text(data);
						return false;	
			  		}
			  	}
			);
			}
			return false;
		});
   	} catch (error) {
   
   	}
   	jQuery('div.top_menu_beside_logo li a').each(function() {
   		var link = jQuery(this).attr('href');
	   	jQuery(this).parent().click(function() {
		   	location.href = link;
		});
	});
    jQuery("#comment_form").validate({
	 	submitHandler: function(form) {
	 		jQuery('div.comments').fadeTo("slow",'0.33');
	 		jQuery.post('/ajax_server.php?app=frontPage&action=comment',
		  	{ 
		  		data : jQuery(form).serialize()
			},
		  	function(data){
		  		if (data) {
			   		jQuery('div.comments').html(data);
			   		jQuery('div.comments').fadeTo("slow",'1');
                    jQuery('div.product_reviews_wrapper').html('<p>Bedankt voor uw reactie.</p>');
			   		return false;
			   	};
			});
	   }
	}); 
	jQuery('input#js_controle').val('validated'); 
});

var Insurer = {

	productWrapperClass	: 'div.insurer_wrapper_product',
	warningDivId		: 'div.warning_insurer',
	maxChoosenProdOneTime: 4,
	
	getProduct			: function(formObj)
	{
		var selectedIds = [];
		jQuery('input[@type=checkbox][@checked]', formObj).each(function() {
		   	selectedIds.push(this.value);	
		});
		if (selectedIds.length  < 1) {
			jQuery(this.productWrapperClass).hide();
		 	jQuery(this.warningDivId).show();
		 	return false;
		}
		jQuery(this.warningDivId).hide();
		jQuery(this.productWrapperClass).show();
		
		jQuery(this.productWrapperClass+ ' div.body').html('<img src="/img/loadingAnimation.gif" />');
		jQuery.post('/ajax_server.php?app=insurer&action=getProduct',
		  	{ 
		  		insurerIds: selectedIds.join(",")
			},
		  	function(data){
		  		if (data) {
		  			jQuery(Insurer.productWrapperClass+ ' div.body').html(data);
					return false;	
		  		}
		  	}
		);
	  	return false;	
	},
	
	
	checkCheckedProducts	: function(formObj)
	{
		var checkedItems = jQuery('input[@type=checkbox][@checked]', formObj);
		if (checkedItems.size() < 1) {
			jQuery('div.warning_product').show();
			return false;
		}
		if (checkedItems.size() > this.maxChoosenProdOneTime) {
			jQuery('div.warning_product_to_much_choosen').show();
			return false;
		}
		return true;
	},
	
	print		: function()
	{
		return !window.open('?print=true', 'Printen','width=900,height=700,scrollbars=yes,toolbar=no,location=no'); 	
	}
	
}
