// append the js-enabled stylesheet:
// this stylesheet contains styles which are only used in javascript enabled browsers.
function updateAdres(xml) {
	if($("success",xml).text() == "true") {
		$('#uid116').val($("straat",xml).text());
		$('#uid117').val($("plaats",xml).text());
	} else {
		$('#uid116').val("");
		$('#uid117').val("");
	}

	$('#uid116').validate();	
	$('#uid117').validate();	
}


function check_address() {
	var postcode = $('#uid114').val();
	var huisnummer = $('#uid118').val();
	
	if (postcode && huisnummer) {
		var url = "http://www.cnvo.nl/getAddress.php"; 
		$.get(url,{  
			username: "cnvowebsite" ,
			password: "3a9wgfmt54",
			postcode: postcode,
			nummer: huisnummer,
			level: "2",
			debug: "1"
    	 	}, function(xml) {  
   			updateAdres(xml);
 		});   
 	}
}

$(document).ready(function() {
  $('#zoekvraag').attr('autocomplete','off');
  
  /* override class names for rss mijn cnvo blocks */
  $('#mijncnvodel_1641').attr('class','delete pop-delete-alert-rss');
  $('#mijncnvodel_1642').attr('class','delete pop-delete-alert-rss');
  $('#mijncnvodel_1646').attr('class','delete pop-delete-alert-rss');
  
	/* adresverrijking */
	$('#uid114').blur(function() {
		check_address();
	});	
	$('#uid118').blur(function() {
		check_address();
	});	

  /* tabs */
	
if ($('#jqtabs-0').children().children().children().children().children().children('.tx_powermail_pi1_formconfirmation_back').length) {
	 var $location = $(location).attr('href');
	 var $url = $location.split("#c");
	 
	 $action = $('#jqtabs-0').children().children().children().children().children().children('.tx_powermail_pi1_formconfirmation_back').attr('action');
	 $newaction = $action + '?selectedTab=' + $url[1];
	 
	 $('#jqtabs-0').children().children().children().children().children().children('.tx_powermail_pi1_formconfirmation_back').attr('action', $newaction);
}
   /* pagination submit dsearch*/
 $("#show-results").change(function() 
    { 
     this.form.submit();    
    });

	/* search form */
	$('#zoekform').submit(function() {
		if ($('#zoekvraag').attr("title") == $('#zoekvraag').val() || !$('#zoekvraag').val()) {
			alert('U dient een zoekwoord op te geven');
			return false;
		}
	});
	
	/* search form */
	$('#tx-solr-search-form-pi-results').submit(function() {
		if ($('#zoekvraag-solr').attr("title") == $('#zoekvraag-solr').val() || !$('#zoekvraag-solr').val()) {
			alert('U dient een zoekwoord op te geven');
			return false;
		}
	});
	
	$('.tablink').click(function() {
		var $url = ($(this).attr('href')).split("#c");
		$url = 'jqtabs-' + $url[1] + '-0';
		$('#jqtabs-0').tabs('select', $url);
		return false; 
	});

	
	if ($('#jqtabs-0').children().children().children().children('.tx-powermail-pi1').length) {
		var $location = $(location).attr('href');
		var $url = $location.split("#c");
		$url = 'jqtabs-' + $url[1] + '-0';
		//alert($url);
		$('#jqtabs-0').tabs('select', $url);
	}
	
	
	$('.powermail_check').addClass('checkbox');
	$('.powermail_radio').addClass('radio'); 
  
  	$('.jscalendar').blur(function() { periodFilter(); $('#dates-dsearch').submit(); });
	$('.jscalendar').change(function() { periodFilter(); });

    if ($('li.send').length) {
			$('li.send').children('a').addClass('pop-iframe');
		}
	
	if ($('li.news-iframe').length) {
		
			$('li.news-iframe').children('a').addClass('pop-iframe');
			
			$('li.news-iframe').children('a').each(function(){
			
				url = $(this).attr('href');
				title = 'Laatste nieuws';
				
				$(this).attr('href', url +'?tipUrl=' + url + '&tipTitle=' + title + '&title=' + title + '&width=520&height=420');
		
			});
	}
	/* fce met lightbox  550*670 en 924*650 */
	
	if ($(".w550-h670").length) {
			$('.w550-h670').children('a').addClass('pop-iframe');

			$('.w550-h670').children('a').each(function(){
				if($(this).parents('.csc-default').find('.recht-tiplightbox').length==0){
        url = $(this).attr('href');
				title = $(this).attr('title');
				
				$(this).attr('href', url +'?tipUrl=' + url + '&tipTitle=' + title + '&title=' + title + '&width=550&height=670');
				}
			}); 
			
	}
	
	/*if ($(".w730-h590").length) {
			$('.w730-h590').children('a').addClass('pop-iframe');
			$('.w730-h590').children('a').each(function(){
				if($(this).parents('.csc-default').find('.recht-tiplightbox').length==0){
        url = $(this).attr('href');
				title = $(this).attr('title');
				
				$(this).attr('href', url +'?tipUrl=' + url + '&tipTitle=' + title + '&title=' + title + '&width=730&height=590');
				}
			});
			
	}*/
	
	if ($(".w924-h650").length) {
		$('.w924-h650').children('a').addClass('pop-iframe');
		
		$('.w924-h650').children('a').each(function(){
			url = $(this).attr('href');
			title = $(this).attr('title');
			
			$(this).attr('href', url +'?tipUrl=' + url + '&tipTitle=' + title + '&title=' + title + '&width=924&height=650');
		});
	}
		
	/* end fce met lightbox */
	
	
	/* f2a template aanpassing  */
	if ($("body#f2a").length) {
		$("#content").addClass('no-sidebar');
	}
	/* end f2a template aanpassing */
	
	/* f1d template aanpassing */
	if ($("body#f1d").length) {
		$("#content").addClass('no-right-col');
	}
	/* end f1d template aanpassing */
	
	/* powermail buttons */
	if ($(".tx-powermail-pi1").length) {
		powermailButtons.init();
	}
	/* end powermail buttons */	

	/*dropdown menu drede kolom */
	
	$(".main-nav-options .trigger").parent().parent().parent().parent(".main-nav-options").removeClass("small");
	$(".main-nav-options .news-list-dotted").parent().parent().parent().parent(".main-nav-options").removeClass("small");
	
	/*end dropdown menu drede kolom */
	
	/* campaign block empty handling needed for ie7 */
  if($('.campaign-content').length){
    $('.campaign-content').each(function(){
        var $campcontent = $(this).html();
        if($campcontent==0)
        $(this).html('&nbsp;');          

    });
  }
  
	/* email popup */
	if($('.emailpopup').length){
   $('.emailpopup').each(function(){
      var $eleId = $(this).parents('.csc-default').attr('id');

      $(this).find('.mail').each(function(){
        var $emailhref = $(this).attr('href');
        var $emailID = $emailhref.split('mailto:');
        var $emailEnc = encodeURIComponent($emailID[1]); 
        $(this).attr('href','nc/site-resources/pop-ups/perscontact.html?title=Perscontact&width=520&height=575&pm_receiver='+$emailEnc+'&receiverid='+$eleId);
        $(this).addClass('pop-iframe');
       
      });
    
   });

  }
	
/* 	$(".duur h2").colorizefirstword = function(){
		return this.each(function(){
			if(typeof $(this).text != "undefined"){
				 var text = $(this).html();
				 var wordarr = text.split(" ");
				 wordarr[0] = "<span style='color:red;'>" + wordarr[0] + "</span>";
				
				$(this).html(wordarr.join(" "));
			}
		});
	} */
	
$(".duur h2").html(function(i,text){
    return text.replace("Duur:", function(match){
        return '<span class="gray">' + match + '</span>';
    });
});
	

$('#register-accept .close-pop').click(function(){
				$parentPanel = $(this).parents('.popover-container');
				popOvers.hideIt($parentPanel);
				return false;
			});

$(".userlogin").hover(function(){
    $("#user").addClass('relinput');
},function(){
   $("#user").removeClass('relinput');
});	

$(".passlogin").hover(function(){
    $("#pass").addClass('relinput');
},function(){
   $("#pass").removeClass('relinput');
});

$("#forgot-submit").click(function(){
    if($("#forgot-email-pass").attr('value')==''){
       $('.forgoterror').addClass('forgoterrorshow');
       return false;
    }else{
       $('.forgoterror').removeClass('forgoterrorshow');
    }

});
	
if($('.scorecnvo').length){
   $('.scorelogin').hide();
}

// tipform fce
if($('.tipsubmit a').length){
  
  $('.tipsubmit a').each(function(){
     $(this).addClass('pop-iframe');
     tipurl = $(this).parents('.tipform-fce').attr('action');  
     url = $(this).attr('href');
		 title = $(this).attr('title');
		 
		 $(this).attr('href', url +'?tipUrl=' + tipurl + '&tipTitle=' + encodeURIComponent(title) + '&title=' + encodeURIComponent(title) + '&width=520&height=575');
     
  });
  
}
 
$('.recommended li a').click(function(){
             $parentPanel = $(this).parents('.popover-container');
				     popOvers.hideIt($parentPanel);
				     url = $(this).attr('href');
            window.parent.location.href=url;
           
        });
        
// correct mijn cnvo link before login
/* if($('.loginlink').length){
  var $loginlink = $('.loginlink .pop-iframe').attr('href');
  $('.right-link .pop-iframe').attr('href',$loginlink+'&notloggedin=1');
}  */

    draganddrop.init();
	
  replacetelefoon.init();          
	replaceFonts.init();
	mainNav.init();
	accountOptions.init();
	sidebarNav.init();
	deleteFilter.init();
	expanderTable.init();
	accordionExpander.init();
	tabs.init();
	pollBars.init();
	saveArticle.init();
	

	/* home */
	campaignCarousel.init();
	newsCarousel.init();
	textPosition.init();
	
	/* popovers */
	modal.init();

    appendShareBlock();
	
    thumbnailCarousel.init();
	appendMijnCNVOBlock();
    appendPrintBlock();
    printArticle.init();
	popOvers.init();
	
	
	/* forms */
	uniform.init();
	datePicker.init();
	errorMessage.init();
	toolTips.init();
	addFields.init();
	clearInput.init();
	submitHover.init();

	/* specific to starters en studenten T1-4.html */
	testimonials.init();
	testimonialLoadpop.init(); 
		
	/* specific to mijn cnvo T7-0.html */
	editBlocks.init();
	deleteTableRow.init();
	showBlocks.init();
	bannerCarousel.init();
	
	deleteInbox.init();
	
	/* specific to vraagtypen T100.html "*/
	slider.init();
	radioToSlider.init();	
	calculateFields.init();
	$('.form-info .tool-tip p').wrapInner('<span/>');
	
	/* browser specific */
	if ($.browser.safari) {
		textareaResize.init();
	}
	
	/* video sharing */
	videoShare.init();
	
	/* pagination */
	setPagination.init();
	
	printpopupcufon.init();
	
	internalRssMijncnvo.init();
	
  // check whether the rssfeed inputs are prefilled then unhide in popup loaded after addFields.init()
		$('.rss-wrapper').find('input').each(function(){
     if($(this).attr('value')){
        $(this).parent().show();
     }
    });
    
 // faq expand for bookmarks
   faqBookmark.init();
   
   $('ul.nested li').find('a').each(function(){
       $anchtext = $(this).html();
       if($anchtext==''){
         $(this).parent('li').hide();
       }
   });

       /* tabs */	
	
/*        var $tabs = $('.tab-block').tabs(); // first tab selected

       $('.tablink').click(function() { // bind click event to link
             $(this).attr("href");
             $tabs.tabs('select', 2); // switch to third tab
             return false;
       }); */
	  
   appendQuote.init();
   deleteBookmarkRow.init();
     
});

/* change fonts into CNVO font */
replaceFonts = {
	init:function() {
		Cufon.replace('.main-content h1', { 
			fontWeight: 'bold'
		});
		Cufon.replace('ul.expander-list li h2 a', { 
			fontWeight: 'bold', 
			hover: true
		});
		Cufon.replace('h2:not(.no-cufon)', { 
			fontWeight: 'bold'
		});
		Cufon.replace('.highlights h3', { 
			fontWeight: 'bold'
		});
		Cufon.replace('.overview-block h3 a', { 
			fontWeight: 'bold',
			hover: true
		});
		Cufon.replace('.overview-block h3', { 
			fontWeight: 'bold'
		});
		Cufon.replace('.link-cols h3', { 
			fontWeight: 'bold'
		});
		Cufon.replace('.button:not(.no-cufon)', { 
			fontWeight: 'bold'
		});
		Cufon.replace('.sidebar strong', { 
			fontWeight: 'bold'
		});
		Cufon.replace('.quote-block blockquote p', { 
			fontWeight: 'bold'
		}); 
		Cufon.replace('.banner-block ul li', { 
			fontWeight: 'bold'
		}); 
		Cufon.replace('.pop-content .article-info strong', { 
			fontWeight: 'bold'
		}); 
	
		
	}
}

appendQuote = {
    init:function() {
      if($('.quote-block blockquote').length){
        $('.quote-block blockquote').prepend('<span class="beforequote"></span>');
        $('.quote-block blockquote').append('<span class="afterquote"></span>');
      }

    }
}

/* shows and hides the account options triggered by the account link in header */
accountOptions = {
	init:function() {
		$(".account-link").hover(
			function(){ 
				if (document.all) {
					$('#main-nav .right-link').hide();
				}
				$('.account-link .account-options').fadeIn("fast"); 
			}, 
			function() {
				$('.account-link .account-options').fadeOut("fast"); 
				if (document.all) {
					$('#main-nav .right-link').show();
				}
			} 
		);
		$(".account-link > a").click(
			function() {
				return false;
			}
		);
	}
}

/* enables second level in main site navigation */

/* 
	### NOT ORIGINAL ###
	This function is changed because of the menu build by gifbuilder. Some lines are commented because the hovers are
	handled by typo3
*/

mainNav = {
	init:function() {
		$pageWidth = 960;
		$currentImg = $("#main-nav li.current img").attr('src');
		if ($currentImg) {
			/* $newCurrent = $currentImg.replace('.gif','-current.gif'); */
			//$newCurrent = $currentImg;
			//$("#main-nav li.current img").attr('src', $newCurrent);
			// aangepast door jorgen 17-09-2010 ivm image bug in menu
		}
		$("#main-nav li").not("#main-nav li li").hover(
			function(){ 
				/*
				$imgPath = $('img.main-nav-link', this).attr('src');
				$newImg = $imgPath.replace('.gif','-ro.gif');
				$('img.main-nav-link', this).attr('src', $newImg);
				*/
				
				$panelWidth = $('.main-nav-options', this).width();
				$position = $(this).position();
				if (($panelWidth + $position.left) > $pageWidth) {
					$newLeft = 0 - (($panelWidth + $position.left) - $pageWidth) +"px";
					$('.main-nav-options', this).css('left', $newLeft);
				}
				
				
				
				//$(".main-nav-options", this).fadeIn(); 
				$(".main-nav-options", this).show(); 
				$(".main-nav-options", this).hover (
					function() {
						over(document.getElementById(this.id+"-img").name);
					}
				)
				//$('a', this).addClass('hover');
			}, 
			function() {
				//$(".main-nav-options", this).fadeOut(); 
				
				tid = ($(".main-nav-options", this).attr('id'));
				out(document.getElementById(tid+"-img").name);
				$(".main-nav-options", this).hide(); 

				if ($('img.main-nav-link', this).attr('src').indexOf('-ro.gif') != -1) {
					$roImg = $('img.main-nav-link', this).attr('src');
					$newImg = $roImg.replace('-ro.gif','.gif');
					$('img.main-nav-link', this).attr('src', $newImg);
				}
				//$('a', this).removeClass('hover');
			} 
		);
	}
}

/* new printblock create and append to body */
function appendPrintBlock() {
   $('<div class="popover-container main-content"><div id="print-this-page" class="popover print-preview"><div class="title"><strong>Print preview</strong><span class="print-button close-pop">Print deze pagina</span></div><div class="pop-content"><div class="article-info"></div><div class="print-body">' + $("#contentBlock-1").html() +'</div>' + $("#footer-print").html() +'</div></div></div>').appendTo('body'); 
   if($('.print-body h1').length > 0) {
		
		$('.print-body h1').each(function() {
			$(this).replaceWith('<span class="h1">' + $(this).html() + '</span>');
		});
		
		Cufon.replace('.print-body .h1', { 
			fontWeight: 'bold', fontSize: '20px', color:'#424242', textTransform: 'uppercase' 
		});	
   }
}

/* new shareblock create and append to body */
function appendShareBlock() {
   $('<div class="popover-container" style="display:none;"><div id="share-this" class="popover"><div class="title"><h2>Deel op internet</h2></div>' + $("#hide-share-popcontent").html() +'</div></div>').appendTo('body');
   Cufon.replace('.tx-timtabsociable-pi1 .pop-content .article-info h1', { 
			fontWeight: 'bold', fontSize: '20px', color:'#424242', textTransform: 'uppercase' 
		});
    /* save bookmark pages Del meet enderen*/
  $('#savebookmark a').click(function(){
      $checkhtml1 = $('#savepageexist-this').html();
      $checkhtml2 = $('#savepage-this').html();
			// add to database
     $.get($(this).attr('href'), function(data){
         $responseText = $(data).filter('#responsetext').html();
         if($responseText=='existing'){
           popOvers.hideIt($('.popover-container'));
            //$('.popover-container').css('display','none');
            if($checkhtml1==null){
               $('<div class="popover-container" style="display:none;"><div id="savepageexist-this" class="popover"><div class="title"><h2>Opslaan in Mijn CNVO</h2></div><div class="pop-content"><div class="article-infox"><p>Deze pagina is reeds opgeslagen in jouw Mijn CNVO omgeving</p></div><fieldset class="buttons"><div class="submit-button"><input type="submit" value="Sluiten" class="close-pop submit" /></div></fieldset></div></div></div>').appendTo('body');
            }
            //popOvers.init();
            Cufon.replace('h2:not(.no-cufon)', { 
			fontWeight: 'bold'
		});
            popOvers.showIt('savepageexist-this');
            $('.close-pop').click(function(){
				$parentPanel = $(this).parents('.popover-container');
				popOvers.hideIt($parentPanel);
				return false;
			});
            
                   
           return false;
         }
         if($responseText=='saved'){
            popOvers.hideIt($('.popover-container'));
            //$('.popover-container').css('display','none');
            if($checkhtml2==null){
               $('<div class="popover-container" style="display:none;"><div id="savepage-this" class="popover"><div class="title"><h2>Opslaan in Mijn CNVO</h2></div><div class="pop-content"><div class="article-infox"><p>De pagina is opgeslagen in Mijn CVNO.</p></div><fieldset class="buttons"><div class="submit-button"><input type="submit" value="Sluiten" class="close-pop submit" /></div></fieldset></div></div></div>').appendTo('body');
            }
            //popOvers.init();
            modal.showIt();
           Cufon.replace('h2:not(.no-cufon)', { 
			fontWeight: 'bold'
		});
            popOvers.showIt('savepage-this');
            $('.close-pop').click(function(){
				$parentPanel = $(this).parents('.popover-container');
				popOvers.hideIt($parentPanel);
				return false;
			});
           
           return false;
         }
   
     });
      return false;
			});  
}


/* new mijnCNVO block create and append to body */
function appendMijnCNVOBlock() {
    
  // hidden content blocks aanpassen
	if ($('.hidefcewidget').length > 0) {
		
		$('.hidefcewidget').each(function() {
			$(this).parent().hide();
			$(this).replaceWith($(this).html());
		});
	}
	 // hide all rss content blocks
	if ($('.rssblok').length > 0) {
		
		$('.rssblok').each(function(){
			$(this).parent().hide();
		//$(this).replaceWith($(this).html());
		});
	}
	
	// show content blocks rss mijncnvo for user
	if ($('.rssfcewidget').length > 0) {
		
		$('.rssfcewidget').each(function(){
			$(this).parent().show();
			$(this).show();
		//	$(this).replaceWith($(this).html());
		});
	}
   
   if ($('.overview').length > 0) {
     //block-options
     $('.overview').find('.block-options ul').each(function(){
        if($(this).find('.edit').length < 1){
          if($(this).find('.delete').length > 0){
             $(this).css({'position':'absolute','right':'-30px'});
          }
        }
     
     });
     
   
	   $('<div class="popover-container" style="display:none;"><div class="popover" id="delete-alert"><div class="title"><h2>Zeker weten?</h2></div><div class="pop-content"><p>Klik op onderstaande knop om het blok definitief te verwijderen.</p><form action="[action]" method="post"><fieldset class="buttons"><div class="submit-button"><input type="submit" value="Verwijderen" class="close-pop delete-overview-block" /></div></fieldset></form></div></div></div>').appendTo('body');
	   
	   $('<div class="popover-container" style="display:none;"><div class="popover" id="delete-alert-rss"><div class="title"><h2>Zeker weten?</h2></div><div class="pop-content"><p>Weet u zeker dat u dit blok wilt verwijderen?</p><form action="[action]" method="post"><fieldset class="buttons"><div class="submit-button"><input type="submit" value="Verwijderen" class="close-pop delete-overview-block" /></div></fieldset></form></div></div></div>').appendTo('body');
      
	 /*  $('<div class="popover-container"><div class="popover" id="homepage-options"><div class="title"><h2>Pas homepage Mijn CNVO aan:</h2></div><div class="pop-content"><form action="[action]" method="post" id="show-overview-blocks"><fieldset><div class="field-group"><div id="column-1" class="column"></div><!-- /.column --><div id="column-2" class="column"></div><!-- /.column --></div></fieldset><fieldset class="buttons"><div class="submit-button"><input type="submit" value="Sla instellingen op" class="close-pop submit" /></div></fieldset></form></div><!-- /.pop-content --></div><!-- /.popover --></div><!-- /.popover-container -->').appendTo('body'); */
	 fields_rss = $('#add-rss-mijncnvo').html();
	 if(fields_rss == null)
	   fields_rss = '&nbsp;';
	   
	   $('<div class="popover-container"><div class="popover" id="homepage-options"><div class="title"><h2>Pas homepage Mijn CNVO aan:</h2></div><div class="pop-content"><form action="mijn-cnvo.html" method="post" id="show-overview-blocks" target="_top"><fieldset><div class="field-group"><div id="column-1" class="column"></div><!-- /.column --><div id="column-2" class="column"></div><!-- /.column --></div>'+fields_rss+'</fieldset><fieldset class="buttons"><div class="submit-button"><input type="submit" value="Sla instellingen op" class="rss-submit submit" /></div></fieldset></form></div><!-- /.pop-content --></div><!-- /.popover --></div><!-- /.popover-container -->').appendTo('body'); 

     // remove rss form fields from body after injecting to popup
$('#add-rss-mijncnvo').html('<span></span>');

//insert some rssfeed error messages and hide them
$('input#rss-feed').after('<span class="feederrorcount error error-rss">U kunt maximaal 3 RSS-feeds toevoegen</span>');
$('input#rss-feed').after('<span class="feederrorexist-1 error error-rss">Deze RSS-feed is reeds toegevoegd</span>');
$('input#rss-feed').after('<span class="feederrorinvalid-1 error error-rss">Dit is een niet geldige RSS-feed</span>');

$('input#rss-feed1').after('<span class="feederrorexist-2 error error-rss">Deze RSS-feed is reeds toegevoegd</span>');
$('input#rss-feed1').after('<span class="feederrorinvalid-2 error error-rss">Dit is een niet geldige RSS-feed</span>');

$('input#rss-feed2').after('<span class="feederrorexist-3 error error-rss">Deze RSS-feed is reeds toegevoegd</span>');
$('input#rss-feed2').after('<span class="feederrorinvalid-3 error error-rss">Dit is een niet geldige RSS-feed</span>');

$('<div class="popover-container" style="display:none;"><div id="rsssinsert-this" class="popover"><div class="title"><h2>Opslaan in Mijn CNVO</h2></div><div class="pop-content"><div class="article-infox"><p>De wijzigingen zijn opgeslagen in uw Mijn CNVO.</p></div><fieldset class="buttons"><div class="submit-button"><input type="submit" value="Sluiten" class="close-pop submit" /></div></fieldset></div></div></div>').appendTo('body');

       
	$('.error-rss').each(function(){
			$(this).hide();
		//$(this).replaceWith($(this).html());
		});
		
		// kolom 1 labels en checkboxen plaatsen.
		$('.overview').children('.col-1').children('.csc-default').each(function(){
			blockId = $(this).attr('id').replace('c', '');
			name = $(this).children('.overview-block').children('.block-options').children('h2').html();
			if( $(this).is(":visible") == "true" ){ checked = "checked"}
			else { checked = "" }
			
			
     	//console.log(blockId);
			//console.log(name);
			
			if(  $(this).is(":visible")){
				checked = "checked";
				checkedh = "true";
			}
			else {
				checked = "false";
			}
			
			rssblockshow = "false";
			if($(this).children('.rssblok').length>0)
					rssblockshow = "true";
			if($(this).children('.rssfcewidget').children('.rssblok').length>0)
        	rssblockshow = "true";
			
			if(rssblockshow=="false"){
			$('<input type="checkbox" id="check-'+ blockId +'" value="'+ checked +'" name="check-'+ blockId +'" class="checkbox '+ checked +'" checked="'+ checked +'" /><label for="check-'+ blockId +'">'+ name +'</label><br />').appendTo('#column-1');
			$('<input type="hidden" id="checkh-'+ blockId +'" value="'+ checked +'" name="check-'+ blockId +'" class="checkboxh '+ checked +'" checked="'+ checked +'" />').appendTo('#column-1');
			}
		});
		
		// kolom 2 labels en checkboxen plaatsen.
		$('.overview').children('.col-2').children('.csc-default').each(function(){
			blockId = $(this).attr('id').replace('c', '');
			name = $(this).children('.overview-block').children('.block-options').children('h2').html();
			//console.log(blockId);
			//console.log(name);
			
		
    	if(  $(this).is(":visible")){
				//console.log('true2');
				checked = "checked";
				checkedh = "true";
			}
			else {
				//console.log('false2');
				checked = "false";
			}
			
				rssblockshow = "false";
			if($(this).children('.rssblok').length>0)
					rssblockshow = "true";
			if($(this).children('.rssfcewidget').children('.rssblok').length>0)
        	rssblockshow = "true";
			
			if(rssblockshow=="false"){
			$('<input type="checkbox" id="check-'+ blockId +'" value="'+ checked +'" name="check-'+ blockId +'" class="checkbox '+ checked +'" checked="'+ checked +'" /><label for="check-'+ blockId +'">'+ name +'</label><br />').appendTo('#column-2');
			$('<input type="hidden" id="checkh-'+ blockId +'" value="'+ checked +'" name="check-'+ blockId +'" class="checkboxh '+ checked +'" checked="'+ checked +'" />').appendTo('#column-2');
			}
			
		});
		
		
		// items die uit staan ook echt uit zetten
		$('.checkbox.false').each(function() {
			$(this).attr('checked', false);
		});
		
		$('.checkboxh.false').each(function() {
			$(this).attr('checked', true);
		});
		
				
		$('.rss-submit').click(function(){
				rssfeed1 = $('#rss-feed').attr('value');
				rssfeed2 = $('#rss-feed1').attr('value');
				rssfeed3 = $('#rss-feed2').attr('value');
				
			nofeeds=0;
      if(rssfeed1==''&&rssfeed2==''&&rssfeed3==''){ nofeeds=1; }
      
      if(nofeeds==1){
          $parentPanel = $(this).parents('.popover-container');
      		popOvers.hideIt($parentPanel);
      }
      
			
			if(nofeeds==0){
			  // check for duplicate inputs first
			  var rssfeedInput = [];
			  $('.rss-wrapper').find('input').each(function(){
           rssfeedInput.push($(this).attr('value'));           
        });
			  
			  feed2cnt= feed3cnt=1;
			  var rssfeed2Cnt = [];
			  var rssfeed3Cnt = [];
        for(var i=0; i<rssfeedInput.length; i++) {
              if (rssfeedInput[i] != ''){
                  if(rssfeedInput[i]==rssfeed2){
                    rssfeed2Cnt.push(feed2cnt);
                    feed2cnt++; 
                  }
                  if(rssfeedInput[i]==rssfeed3){
                    rssfeed3Cnt.push(feed3cnt);
                    feed3cnt++; 
                  }
              }
        }

			    if(rssfeed2Cnt.length > 1){
            $('.feederrorexist-2').show();
            return false; 
          }else{
             $('.feederrorexist-2').hide();
          }
          
          if(rssfeed3Cnt.length > 1){
            $('.feederrorexist-3').show();
            return false; 
          }else{
             $('.feederrorexist-3').hide();
          }
           
         			
			  var url = "mijn-cnvo.html";
        $.get(url,{  
  			feeddata_1: rssfeed1 ,
  			feeddata_2: rssfeed2,
  			feeddata_3: rssfeed3,
  			actionfce: "addrss",
  			no_cache: "1",
  			type:"3331"
      	 	}, function(data) {  
     			   $responseText = $(data).filter('#responserss').html();
     			   
              if($responseText=='invalidrss-1'){
                 $('.feederrorinvalid-1').show();
              }else{
                 $('.feederrorinvalid-1').hide();
              }
              
              if($responseText=='invalidrss-2'){
                 $('.feederrorinvalid-2').show();
              }else{
                 $('.feederrorinvalid-2').hide();
              }
              
              if($responseText=='invalidrss-3'){
                 $('.feederrorinvalid-3').show();
              }else{
                 $('.feederrorinvalid-3').hide();
              }
              
              /* if($responseText=='countlimit'){
                 $('.feederrorcount').show();
              }else{
                 $('.feederrorcount').hide();
              } */
              
              if($responseText=='insertrss'){
                 
                 popOvers.hideIt($('.popover-container'));
                 Cufon.replace('h2:not(.no-cufon)', { 
      			       fontWeight: 'bold'
      		       });
                  popOvers.showIt('rsssinsert-this');
                  
                  //$('#rssinsert-this').parent().show();
                  $('.close-pop').click(function(){
          				    $parentPanel = $(this).parents('.popover-container');
          				    popOvers.hideIt($parentPanel);
          				    $('#show-overview-blocks').submit();
      			      });
                 
              }
             
     			
   		  });
   		}
     
				return false;
			});
		
	}
}




/* carousel animation on homepage */
campaignCarousel = {
	init:function() {
		if ($('#campaign-1').length > 0) {
			$blockArr = new Array;
			$blockArr[0] = $('#campaign-1');
			$blockArr[1] = $('#campaign-2');
			$blockArr[2] = $('#campaign-3');
			$blockArr[3] = $('#campaign-4');
			$blockArr[4] = $('#campaign-5');
			
			$buttonArr = new Array;
			$buttonArr[0] = $('#cbutton-1');
			$buttonArr[1] = $('#cbutton-2');
			$buttonArr[2] = $('#cbutton-3');
			$buttonArr[3] = $('#cbutton-4');
			$buttonArr[4] = $('#cbutton-5');

			$('.campaign-block').hide();
			$('#campaign-1').show();
			$('#cbutton-1 a').addClass('active');
			
			$looping = true;
			
			var refreshId = setInterval(function() {
				if ($looping == true) {
					// find out which button is active
					$activeButton = $('.campaign-buttons li a.active');
					$buttonID = $activeButton.parent().attr('id');
					$buttonInfo = $buttonID.split('button-');
					$buttonNum = $buttonInfo[1];
					$buttonNum ++;
					// reset when end is reached
					if ($buttonNum == 6) {
						$buttonNum = 1;
					}
					// activate the campaign
					campaignCarousel.fadeInNext($buttonNum);
				}
			}, 
			5000);			
			
			// stop animation when mouse is on campaign-block
			$('.campaign-block').hover(function(){ 
				$looping = false;
			}, 
			function(){
				$looping = true;
			});
			
			$('.campaign-buttons li a').hover(function(){ 
				$looping = false;
				// find out which button was pressed
				$buttonID = $(this).parent().attr('id');
				$buttonInfo = $buttonID.split('button-');
				$buttonNum = $buttonInfo[1];
				// activate the campaign
				campaignCarousel.fadeInNext($buttonNum);
			}, 
			function(){
				$looping = true;
			});
		}
	}, 
	fadeInNext:function($buttonNum) {
		$button = $('a', $buttonArr[$buttonNum-1]);
		if($button.attr('class').indexOf('active') == -1) {
			campaignCarousel.clearActive();
			campaignCarousel.fadeOutAll();
			$blockArr[$buttonNum-1].fadeIn();
			$button.addClass('active');
		}
	}, 
	fadeOutAll:function() {
		for(var p=0; p<$blockArr.length; p++) {
			$blockArr[p].fadeOut();
		}
	}, 
	clearActive:function() {
		for(var q=0; q<$buttonArr.length; q++) {
			$('a', $buttonArr[q]).removeClass('active');
		}
	}
}

/* news ticker animation on alternate homepage */
// http://www.gmarwaha.com/jquery/jcarousellite/
newsCarousel = {
	init:function() { 
		//.news-buttons
		$(".news-buttons").jCarouselLite({
			visible: 4,
			auto: 2800,
    		speed: 1800,
    		//speed:1000,
        	btnNext: ".next-news",
			btnPrev: ".prev-news" 
    	});
    	$('.campaign-content .news-buttons li').css('height', '45px');
// tweaked azeef|ALTERNET begin
$('.news-buttons').css('width', '924px');
//$('.campaign-content .news-buttons li').css('padding-right, '15px');
//$('.news-buttons').css('overflow', 'visible');
// tweaked azeef|ALTERNET end
	}
}

/* banner carousel animation on mijn cnvo page */
// http://www.gmarwaha.com/jquery/jcarousellite/
bannerCarousel = {
	init:function() { 
		$('.banner-carousel').append('<span class="prev-banner">vorige banner</span><span class="next-banner">volgende banner</span>');
		$(".banner-carousel").jCarouselLite({
			visible: 2.2,
			auto: 2000,
    		speed: 1000,
    		scroll: 2.2, 
        	btnNext: ".next-banner",
			btnPrev: ".prev-banner" 
    	});
		$('.banner-carousel .prev-banner, .banner-carousel .next-banner').hide();
		$('.banner-carousel').hover(function(){
			$('.banner-carousel .prev-banner, .banner-carousel .next-banner').fadeIn();
		}, function(){
			$('.banner-carousel .prev-banner, .banner-carousel .next-banner').fadeOut();		
		});
		
		$('.banner-carousel-breed').append('<span class="prev-banner">vorige banner</span><span class="next-banner">volgende banner</span>');
 		$(".banner-carousel-breed").jCarouselLite({
			visible: 1,
			auto: 2000,
    		speed: 1000,
    		scroll: 1, 
        	btnNext: ".next-banner",
			btnPrev: ".prev-banner" 
    	});
		
		$('.banner-carousel-breed .prev-banner, .banner-carousel-breed .next-banner').hide();
		$('.banner-carousel-breed').hover(function(){
			$('.banner-carousel-breed .prev-banner, .banner-carousel-breed .next-banner').fadeIn();
		}, function(){
			$('.banner-carousel-breed .prev-banner, .banner-carousel-breed .next-banner').fadeOut();		
		}); 
		
		
	}
}

/* thumbnail carousel animation on testimonials popover */
// http://www.gmarwaha.com/jquery/jcarousellite/
thumbnailCarousel = {
	init:function() { 
		thumbnailCarousel.subTitle();
		$(".thumbnail-carousel").jCarouselLite({
			visible: 8.6,
			auto: 0,
    		speed: 2000,
    		scroll: 5, 
        	btnNext: ".next-thumbnail",
			btnPrev: ".prev-thumbnail" 
    	});
		$('.thumbnail-carousel .prev-thumbnail, .thumbnail-carousel .next-thumbnail').hide();
		$('.thumbnail-carousel').hover(function(){
			$('.thumbnail-carousel .prev-thumbnail, .thumbnail-carousel .next-thumbnail').fadeIn();
		}, function(){
			$('.thumbnail-carousel .prev-thumbnail, .thumbnail-carousel .next-thumbnail').fadeOut();		
		});
	}, 
	subTitle:function() {
		$prevTitle = "";
		$thumbImg = $(".thumbnail-carousel ul li img");
		for(var t=0; t<$thumbImg.length; t++) {
			if ($($thumbImg[t]).attr('title') != $prevTitle) {
				$currentTitle = $($thumbImg[t]).attr('title');
				$withTitle = $(".thumbnail-carousel ul li img[title='"+$currentTitle+"']");
				//alert($withTitle.length);
				$titleWidth = $withTitle.length * 62; 
				$titleWidth = $titleWidth - 18;
				$('<span class="title" style="width:'+$titleWidth+'px;">'+$($thumbImg[t]).attr('title')+'</span>').appendTo($($thumbImg[t]).parents('li'));				
			}
			$prevTitle = $($thumbImg[t]).attr('title');
		}
	}
}

/* adjusts styles of nested sub navigation in the (left) sidebar */
/* enables expander functionality for filters */
sidebarNav = {
	init:function() {
		if ($('.sidebar ul ul').length > 0) {
			// add nested class to sub-nav uls with nesting
			if ($('.sidebar ul.sub-nav ul')) {	
				$('.sidebar ul.sub-nav ul').parent().parent().addClass('nested');
			}
			// add expander class to filter uls with nesting
			if ($('.sidebar ul.filters ul')) {	
				$('.sidebar ul.filters ul').parent().parent().addClass('expander');
			}

			/* richard */
			$('a.filtered').parent().parent().parent().addClass('open');

			if (($('input.hrgte').val() != 'dd-mm-jjjj' && $('input.hrgte').val() != '') || ($('input.hrlte').val() != 'dd-mm-jjjj' && $('input.hrlte').val() != '')) {
				$('input.hrgte').parent().parent().parent().addClass('open');			
			}			
			
			

			if ($('input.hrgte').val() != 'dd-mm-jjjj' && $('input.hrgte').val() != '') {
				if (!$('input.hrlte').val() || $('input.hrlte').val() == 'dd-mm-jjjj') {
					if ($('input.datetypefield').length == 0 || $('input.datetypefield').val() != 'event') {
						var time=new Date();
						var date=time.getDate();
						var month=time.getMonth() + 1;
						var year=time.getYear();
						var pref_month = "";
						if (month < 10)
							pref_month = "0";
						if (year < 2000)
							year = year + 1900;
						$('input.hrlte').val(date + "-" + pref_month + month + "-" + year);
					}
				}

			}

			if ($('input.hrgte').val() == 'dd-mm-jjjj' && !$('input.hrlte').val()) {
				$('input.hrlte').val("dd-mm-jjjj");
			}


			// enable show/hide animation on filter list
			$('.sidebar .filters ul, .sidebar .filters form').not('.sidebar .filters li.open ul, .sidebar .filters li.open form').hide();
			$('.sidebar .filters li a').not('.sidebar .filters li ul li a').click(function() {
				if (($.browser.msie) && (($.browser.version == '7.0') || ($.browser.version == '6.0'))) {
					$(this).next('ul, form').css('visibility','hidden');
					$(this).next('ul, form').css('overflow','hidden');
				}
				
				//$(this).next('ul, form').css('visibility','hidden');
				
				if ($(this).parent().attr('class').indexOf('open') != -1) {
					$(this).parent().removeClass('open');
					$(this).next('ul, form').slideUp({
						duration: 800,
						easing: 'easeOutExpo',
						complete: function(){
							$(this).css('visibility','visible');
						}
					});				
				} else {
					$(this).parent().addClass('open');
					$(this).next('ul, form').slideDown({
						duration: 800,
						easing: 'easeOutExpo',
						complete: function(){
							$(this).css('visibility','visible');
						}
					});

				}
				
				return false;
			});
			
		}
	}
}

/* delete filter option in sidebar filter navigation */
deleteFilter = {
	init:function() {
		$deleteLIs = $('.filters li li');
		$('<div class="tool-tip"><p></p></div>').appendTo($($deleteLIs));

		if (($.browser.msie) && (($.browser.version == '7.0') || ($.browser.version == '6.0'))) {
			$('div.tool-tip').addClass('ie-tip');
		}
		for(var m=0; m<$deleteLIs.length; m++) {
			$($deleteLIs[m]).find('span.delete').clone().removeClass('delete').appendTo($($deleteLIs[m]).find('p'));
		}
		$('<div class="strikethrough"></div>').appendTo($($deleteLIs));
		$('.filters li span.delete').css('visibility', 'hidden');
		$('.filters li .tool-tip').hide();
		$('.filters li .strikethrough').hide();
		$('.filters li li').hover(function() {
			$(this).find('span.delete').css('visibility', 'visible');
		},
		function() {
			$(this).find('span.delete').not('.tool-tip span.delete').css('visibility', 'hidden');
		});
		$('li li span.delete').not('li li .tool-tip span.delete').hover(function() {
/*			$(this).parent().find('.tool-tip').show(); */
			$(this).parent().find('.strikethrough').show();
		},
		function() {
			$(this).parent().find('.tool-tip').hide();
			$(this).parent().find('.strikethrough').hide();
		});
		$('li li span.delete').not('li li .tool-tip span.delete').click(function() {
			/* richard
			$(this).parent('li').fadeOut();
				*/
			//document.location =  $(this).parent().find('a').attr("href");
			document.location =  $('base').attr('href') + $(this).parent().find('a').attr("href");
		});
	}
}

/* clears input fields with classname "focus-clear" on first focus */
clearInput = {
	init:function() {
		$clearInput = '';
		$focusInputs = $('.focus-clear');
		for (var f=0; f<$focusInputs.length; f++) {
			$($focusInputs[f]).attr('title', $($focusInputs[f]).val());
		}
		$('.focus-clear').focus(function() {
			if ($(this).val() == $(this).attr('title')) {
				$clearInput = $(this).val();
				$(this).val('');
			}
		});
		$('.focus-clear').blur(function() {
			if($(this).val() == '') {
				$(this).val($clearInput);
			}
		});
	}
}
/* enables hover style on submit buttons */
submitHover = {
	init:function() {
		$('.submit-button').hover(
			function(){
				$(this).addClass('hover');	
			},
			function(){
				$(this).removeClass('hover');
			}
		);
	}
}
	
/* set the text position on campaign and news buttons (home and alternate home) 
	to vertically centre text over two lines */
textPosition = {
	init:function() {
		$campButtons = $('.campaign-buttons li a span');
		for (var v=0; v<$campButtons.length; v++) {
			if ($($campButtons[v]).height() < 26) {
				$($campButtons[v]).css('margin-top', '14px');
			}
		}		
		$newsButtons = $('.news-buttons li a span');
		for (var w=0; w<$newsButtons.length; w++) {
			if ($($newsButtons[w]).height() < 26) {
				$($newsButtons[w]).css('margin-top', '8px');
			}
		}
	}
}

/* allow search results table to expand */
expanderTable = {
	init:function() {
		if ($('.expander-table').length > 0) {
		$('.expander-table .expander-content').hide();
			// make sure the link to the article is clickable
			$('.expander-table tr.details td a').click(function() {
				 window.location.href = $(this).attr('href');
				if ($.browser.msie){
                                  window.location = 'http://www.cnvo.nl/'+$(this).attr('href');   
                                }
				  //alert($(this).attr('href'));
			});
			// enable show/hide on expander table list
			$('.expander-table tr.details td').click(function() {
				if (($.browser.msie) && (($.browser.version == '7.0') || ($.browser.version == '6.0'))) {
					$(this).parent().next().find('.article-options').css('visibility','hidden');
				}
				if ($(this).parent().attr('class').indexOf('open') != -1) {
					$(this).parent().removeClass('open');
					$(this).parent().next().find('.expander-content').slideUp({
						duration: 400,
						easing: 'easeOutExpo',
						complete: function(){
							$(this).find('.article-options').css('visibility','visible');
						}
					});					
				} else {
					expanderTable.closeAll();
					$(this).parent().addClass('open');
					$(this).parent().next().find('.expander-content').slideDown({
						duration: 400,
						easing: 'easeOutExpo',
						complete: function(){
							$(this).find('.article-options').css('visibility','visible');
						}
					});
				}
				return false;
			});
		}
	}, 
	closeAll:function() {
		$('.expander-table .expander-content').slideUp();
		$('.expander-table .open').removeClass('open');
	}
}

/* expander behaviour */
accordionExpander = {
	init:function() {
		// make sure the link to the article is clickable
		$('.accordion-expander li div.title a').click(function() {
                     window.location.href = $(this).attr('href');
                     if ($.browser.msie){
                                 window.location.href = 'http://www.cnvo.nl/'+$(this).attr('href');   
                     }
		});
		$(".accordion-expander").accordion({ header: '.title', active: '.open .title', collapsible: true, autoHeight: false });
		$(".expander-list").accordion({ header: 'h2', active: '.open h2', collapsible: true, autoHeight: false });
	}
}

// http://jqueryui.com/demos/datepicker/
datePicker = {
	init:function() {
		$("#datepicker-van, #datepicker-tot, #datepicker").datepicker({
			showOn: 'button',
			buttonImage: 'static/img/icon-calendar.gif',
			buttonImageOnly: true, 
			showOtherMonths: true, 
			selectOtherMonths: true, 
			dateFormat: 'dd-mm-yy'
		});
		$("#datepicker-van, #datepicker-tot, #datepicker").datepicker($.datepicker.regional['nl']);
	}
}

// http://docs.jquery.com/UI/Tabs
tabs = {
	init:function(){			
		//$('.tab-block').tabs();
		$('.block-content .csc-default .tab-block').tabs();
		$('.bookmark-tips .tab-block').tabs();
	}
}

/* creates an alpha layer to be triggered by various popover functions. */
modal = {
	init:function(){
		// prepend an overlay to the page
		$('body').append('<div id="overlay-container"><div id="overlay"></div></div>');
		
		// but hide it!
		modal.hideIt();
	}, 
	hideIt:function(){
		$('#overlay-container').fadeOut();
		// show any select elements for ie6
		if (($.browser.msie) && ($.browser.version == 6)) { 
			$('select').css('visibility', 'visible');
		}
	}, 
	showIt:function(){
		// hide any select elements for ie6
		if (($.browser.msie) && ($.browser.version == 6)) { 
			$('select').css('visibility', 'hidden');
			$('.popover select').css('visibility', 'visible');
		}
		modal.setOverlayHeight();
		$('#overlay-container').fadeIn();
	}, 
	setOverlayHeight:function(){
		$pageHeight = $('body').height();
		
		if ($pageHeight < $(window).height())
			$pageHeight = $(window).height();

		$pageHeight += 200;
		$('#overlay').css('height', $pageHeight+'px');
		$('#overlay').css('margin-top', 0-($('body').height() + 200) + 'px');
	}
}

/* popover panels */
popOvers = {
	init:function(){
		if ($('.popover').length > 0 || 0 == 0) {	
			// hide the popover panel
			popOvers.hideIt($('.popover-container'));
			
			// enable any element with the class 'close-pop' to close it's parent popover
			$('.close-pop').click(function(){
				$parentPanel = $(this).parents('.popover-container');
				popOvers.hideIt($parentPanel);
				return false;
			});
			
			$popClassArr = new Array;
			$popovers = $('.popover');
			for(var p=0; p<$popovers.length; p++) {
				$popClassArr[p] = '.pop-' + $popovers[p].id;
				$($popClassArr[p]).click(function(){
					$popIDArr = $(this).attr('class').split('pop-');
					$popID = $popIDArr[1].split(' ');
					popOvers.showIt($popID[0]);
					return false;
				});
			}
			
			
			// *** the second group of functions are for popovers using iframes	
			// enable any element with the class 'close-iframe' to close its parent iframe popover
			$('.close-iframe').click(function(){
				$parentFrame = $('iframe#popFrame', parent.document);
				$parentPanel = $parentFrame.parents('.popover-container');
								
				$parentOverlay = $('#overlay-container', parent.document);
				$parentOverlay.fadeOut(function(){
					$parentPanel.remove();
				});
				return false;
			});
			
			
			
			$('.pop-iframe').click(function(){
				
				// tip form fce processing inside if
       if($(this).parents('.tipform-fce').length){
         $inputname = $(this).parents('.tipform-fce').find('#inp03').attr('value');
         $inputemail = $(this).parents('.tipform-fce').find('#inp04').attr('value');
         $inputname2 = $(this).parents('.tipform-fce').find('#inp03a').attr('value');
         $inputemail2 = $(this).parents('.tipform-fce').find('#inp04a').attr('value');
         $inputname3 = $(this).parents('.tipform-fce').find('#inp03b').attr('value');
         $inputemail3 = $(this).parents('.tipform-fce').find('#inp04b').attr('value');
         
         $errorval = 0;
         if($inputname==''){
           $(this).parents('.tipform-fce').find('#inp03').after('<span class="error errorname">Dit is een verplicht veld</span>').appendTo();
           $errorval = 1;
         }
         if($inputemail==''){
           $(this).parents('.tipform-fce').find('#inp04').after('<span class="error emailerror">Dit is een verplicht veld</span>');
           $errorval = 1;
         }else{
             $('.errorname').remove();
         }
         if($inputemail){
           reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
           
            if(reg.test($inputemail) == false) {
                $('.emailerror').remove();

              $(this).parents('.tipform-fce').find('#inp04').after('<span class="error emailerror">Dit is invalid email</span>');
              $errorval = 1;
            }
                     
         }
         if($inputemail2){
           reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
           
            if(reg.test($inputemail2) == false) {
                $('.emailerror2').remove();

              $(this).parents('.tipform-fce').find('#inp04a').after('<span class="error emailerror2">Dit is invalid email</span>');
              $errorval = 1;
            }
                     
         }
         
         if($inputemail3){
           reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
           
            if(reg.test($inputemail3) == false) {
                $('.emailerror3').remove();

              $(this).parents('.tipform-fce').find('#inp04b').after('<span class="error emailerror3">Dit is invalid email</span>');
              $errorval = 1;
            }
                     
         }
         
         
         if($errorval==1){
           return false;
         }else{
           $('.errorname').remove();
           $('.emailerror').remove();
           $('.emailerror2').remove();
           $('.emailerror3').remove();
           $extravars = '';
           if($inputname2){
             $extravars = '&tipname1='+$inputname2;
           }
           if($inputname3){
             $extravars = $extravars+'&tipname2='+$inputname3;
           }
           if($inputemail2){
             $extravars = $extravars+'&tipemail1='+$inputemail2;
           }
           if($inputemail3){
             $extravars = $extravars+'&tipemail2='+$inputemail3;
           }
           
           
           urltip = $(this).attr('href');
				   $(this).attr('href', urltip +'&tipname='+$inputname+'&tipemail='+$inputemail+$extravars);
           
         }
      }
			
				$primaryContainer = $(this).parents('body');
				// get the url and extract variables from it
				$pageURL = decodeURI($(this).attr('href'));
				$urlArr = $pageURL.split('?');
				
				if($urlArr[2]) {
					$urlArr[0] = $urlArr[0]+'?'+$urlArr[1];
					$urlArr[1] = $urlArr[2]+'?'+$urlArr[3];
				}

				if($pageURL.indexOf('https') != -1) {
					$internalurlcheck = $(this).attr('href').indexOf('https://');
				} else {
					$httpcheck = $pageURL.indexOf('http');
					$internalurlcheck = $(this).attr('href').indexOf('http://');
				}
								  
				$externalPage = $urlArr[0];
				//$externalPage = encodeURIComponent($pageURL);
				if($internalurlcheck== -1) {
				   $externalPage = unescape($pageURL);
                }
				$titleArr = $urlArr[1].split('title=');
				/*alert($titleArr[1]);*/
				$titleArr2 = $titleArr[1].split('&');
				$title = $titleArr2[0];

				$widthArr = $urlArr[1].split('width=');
				$widthArr2 = $widthArr[1].split('&');
				$width = $widthArr2[0];

				$heightArr = $urlArr[1].split('height=');
				$heightArr2 = $heightArr[1].split('&');
				$height = $heightArr2[0];
		
				//create a popover with an iframe
				popOvers.popIFrame($primaryContainer, $externalPage, $title, $width, $height);

				return false;
			});
			
		}
	},
	popIFrame:function($container, $externalPage, $title, $width, $height){
	$externalPage = decodeURI($externalPage);
	  $tipUrl = getParameterByNameForQueryString('tipUrl',$externalPage);
	  if($tipUrl){
      $externalPage = $externalPage.replace($tipUrl,encodeURIComponent($tipUrl));
    }
    $redirectUrl = getParameterByNameForQueryString('return_url',$externalPage);
    if($redirectUrl){
      $externalPage = $externalPage.replace($redirectUrl,encodeURIComponent($redirectUrl));
    }
    $rssUrl = getParameterByNameForQueryString('rssUrl',$externalPage);
    if($rssUrl){
      $externalPage = $externalPage.replace($rssUrl,encodeURIComponent($rssUrl));
    }
    
		$iframe = '<iframe id="popFrame" src="'+$externalPage+'" width="'+$width+'" height="'+$height+'" frameBorder="0">';
		// there are two different widths of popover, 520px is default and 730px is defined by sub-class "wide"
		$className = '';
		if ($width > 520) {
			$className = 'wide';
		}
		if ($width == 550) {
			$className = 'wide550';
		}
		
		if ($width == 924) {
			$className = 'wide924';
		}
		
		$titlepopup = decodeURI($title);
		$titlepopup = $titlepopup.replace('%3A' ,function(match){
        	return ':';
    	});
    $titlepopup = $titlepopup.replace('%3B' ,function(match){
        return ';';
    });
    $titlepopup = $titlepopup.replace('%3F' ,function(match){
        return '?';
    });
		
		
		
		$('<div class="popover-container"><div id="iPop" class="popover '+$className+'"><div class="title"><h2>'+$titlepopup+'</h2></div>'+$iframe+'</div></div>').appendTo($container);
		
		popOvers.hideIt($('#iPop').parent());
		popOvers.showIt('iPop');
	},
	showIt:function($popPanel){
		popOvers.makeCloseButton($popPanel);
		modal.showIt();
		// position the popover
		$scrollTop = $(window).scrollTop();
		$viewportHeight = window.innerHeight ? window.innerHeight : $(window).height();
		$popHeight = $('#'+$popPanel).parent().height();
		$popTop = (($viewportHeight/2) + $scrollTop - ($popHeight/2));
		if ($popTop > 80) {
			$('#'+$popPanel).parent().css('top', $popTop);
		}
		else {
			$('#'+$popPanel).parent().css('top', 80);
		}
		
		// ie6 also requires the horizontal positioning to be set
		if (($.browser.msie) && ($.browser.version == '6.0')) {
			$viewportWidth = window.innerWidth ? window.innerWidth : $(window).width();
			$popWidth = $('#'+$popPanel).parent().width();
			$popLeft = ($viewportWidth/2) - ($popWidth/2);
			$('#'+$popPanel).parent().css('margin-left', $popLeft);
		}
		
		// show the popover panel's parent popover-container
		$('#'+$popPanel).parent().show();
		
		// if the popup is a print preview, attach the print-preview stylesheet
		$popClass = $('#'+$popPanel).attr('class');
		if ($popClass && $popClass.indexOf('print-preview') != -1) {
			popOvers.addPrintStyles();
		}
	}, 
	makeCloseButton:function($popPanel){
		// prepend a close button to the popover panel's title bar
		$(document.createElement("span")).attr("class","close").prependTo($('#'+$popPanel).find('div.title')); 
		
		$('.close').hover(function(){	
			$(this).addClass('hover');
		}, function(){
			$(this).removeClass('hover');		
		});
		$('.close').click(function(){			
			$parentPanel = $(this).parents('.popover-container');
			// hide the panel and the modal layer
			popOvers.hideIt($parentPanel);
			if($parentPanel.find('#rsssinsert-this').length){
			  rssfeed1 = $('#rss-feed').attr('value');
				rssfeed2 = $('#rss-feed1').attr('value');
				rssfeed3 = $('#rss-feed2').attr('value');
				
			  nofeeds=0;
        if(rssfeed1==''&&rssfeed2==''&&rssfeed3==''){ nofeeds=1; }
        if(nofeeds==0){ $('#show-overview-blocks').submit(); }
      }
      			
			// if it's an iframe popover, destroy the iframe and its containers!
			if ($popPanel == 'iPop') {
				$('#'+$popPanel).parent().remove();
			}
			

			return false;
		});
	}, 
	hideIt:function($popPanel){
		$popPanel.find('.close').remove();
		modal.hideIt();
		$popPanel.hide();
		
		// remove print-preview stylesheet
		popOvers.removePrintStyles();
	}, 
	addPrintStyles:function() {
		$('<link />', {
		href: 'static/css/print-preview.css',
		media: 'print',
		rel: 'stylesheet',
		type: 'text/css',
		'class': 'print_css'
		}).appendTo('head');
		// IE doesn't always notice the presence of new stylesheets
		if ($.browser.msie) {
			$('.print_css').clone().appendTo('head');
		}
	}, 
	removePrintStyles:function() {
		$("link[href='static/css/print-preview.css']").remove();
	}
}

/* makes poll results graphics expand to the percentage read from text */
pollBars = {
	init:function(){
		$result = $('.result');
		for(var i=0; i<$result.length; i++) {
			$this = $result[i];
			$color = $('.color', $this);
			$percentText = $('.percentage', $this).text();
			$percentArr = $percentText.split('%');
			$percent = $percentArr[0];
			$color.css('width', $percent + '%');
		}
	}
}

/* help texts in forms */
toolTips = {
	init:function(){
		$('form .tool-tip p').hide();
		if (($.browser.msie) && (($.browser.version == '7.0') || ($.browser.version == '6.0'))) {
			$('form .tool-tip').addClass('ie-tip');
		}
		$('form .tool-tip').hover(function(){
			$(this).find('p').stop(true, true);
			$(this).find('p').fadeIn();		
		}, 
		function(){
			$(this).find('p').fadeOut();		
		}
		);
	}
}

/* enables styled select as slider (questionnaire) */
slider = {
	init:function(){
		if ($('.slider-select').length > 0) {
			var select = $(".slider-select select");
			var slider = $('<div id="slider"></div>').insertAfter(select).slider({
				min: 1,
				max: 5,
				range: "min",
				value: select[0].selectedIndex + 1,
				slide: function(event, ui) {
					select[0].selectedIndex = ui.value - 1;
				}
			});
			$(".slider-select select").click(function() {
				slider.slider("value", this.selectedIndex + 1);
			});	
		}
	}
}


function periodFilter() {
	if($('.hrgte').val()){
      var hrgte = $('.hrgte').val();
      var e = hrgte.split('-');
      var f = new Date(e[2], e[1]-1, e[0]);
      var hrgte_unix = f.getTime() / 1000;
      $('.hidden-gte').val(hrgte_unix);
      $('.day').click(function() {
		if (($('.hrlte').val() == 'dd-mm-jjjj')) {
			$('.hrlte').attr("disabled", "disabled");
			$('.hidden-lte').attr("disabled", "disabled");
			$('.ltecb').attr("checked", false);
		}
		$('#dates-dsearch').submit();
      });
               
    }
    
    if($('.hrlte').val()){
      var lrgte = $('.hrlte').val();
      var el = lrgte.split('-');
      var fl = new Date(el[2], el[1]-1, el[0]);
      var lrgte_unix = (fl.getTime() / 1000) + 86399;
      $('.hidden-lte').val(lrgte_unix);
      $('.day').click(function() {
		if (($('.hrgte').val() == 'dd-mm-jjjj')) {
			$('.hrgte').attr("disabled", "disabled");
			var now = new Date();
			var nowtime = fl.getTime() / 1000;
			$('.hidden-gte').val(nowtime);
			//$('.hidden-gte').attr("disabled", "disabled");
			$('.gtecb').attr("checked", false);
		}
        $('#dates-dsearch').submit();
      });
    }
    
}

/* added azeef|ALTERNET enables multiple radio as slider (questionnaire) */
radioToSlider = {
	init:function(){
		if ($('.radio-to-slider').length > 0) {
		
			var sliderIndex = 0;
			$('.radio-to-slider').each(function() {
				var max_val = 0;
				var selected_index = 0;
				$(this).children().each(function() {
					if($(this).attr('type') == 'radio') {
						if( $(this).attr('checked') == true) { selected_index = max_val; }
						max_val++;
					}
				});
				
				if(selected_index == 0) {
					var flag=false;
					$(this).children().each(function() {
						if($(this).attr('type') == 'radio') {
							if(!flag) { $(this).attr('checked', 'true'); flag = true; }
						}
					});
				}
				
				var sliderDivId = 'uiSliderPlaceHolder' + sliderIndex;
				$(this).append('<div id="' + sliderDivId + '"></div>');
				
				var slider = $('#'+sliderDivId).slider({
					min: 0,
					max: max_val-1,
					range: "min",
					value:selected_index,
					slide: function(event, ui) {
						var i = 0;
						var selectVal = ui.value;
						$(this).parent().children().each(function() {
							if($(this).attr('type') == 'radio') {
								if(i == selectVal) {
									$(this).attr('checked', 'true');
								}
								i++;
							}
						});
					}
				});
				sliderIndex++;
			});
		}
		$('.radio-to-slider input').css('display', 'none');
	}
}

/* simple calculation of form fields (questionnaire) */
calculateFields = {
	init:function(){
		if ($('.calculate-fields').length > 0) {
			$('.calculate-fields input').val(''); 
			$('input.add').change(function(){ 
				// check that a number has been entered, no letters
				if (calculateFields.checkNumber($(this).val()) == false) {
					errorMessage.showError($(this).parent());
					// clear the field
					$(this).val("");
				}
				else { 
					$totalFields = 0;
					$addFields = $(this).parents('.calculate-fields').find('input.add');
					$totalField = $(this).parents('.calculate-fields').find('input.total');
					// add up the fields
					for(var j=0; j<$addFields.length; j++) {
						$thisFieldVal = $($addFields[j]).val();
						if($thisFieldVal != "") {
							$totalFields += eval($thisFieldVal);
						}
						$totalField.val($totalFields);
					}
				}
			});
		}
		
		if($('.calculate-fieldsnew').length > 0) {
		  	$('.calculate-fields input').val(''); 
			$('input.add').change(function(){ 
				// check that a number has been entered, no letters
				if (calculateFields.checkNumber($(this).val()) == false) {
					errorMessage.showError($(this).parent());
					// clear the field
					$(this).val("");
				}
      });
    }
	}, 
	checkNumber:function($value) {
		$numbersOnly = new RegExp("[0-9]+");;
		return $numbersOnly.test($value);
	}
}

/* shows the error message previous to $field */
errorMessage = {
	init:function() {
		$('form p.error').hide();
	},
	showError:function($field) {
		$field.prev('p.error').fadeIn();
	}
}

/* styles radio elements, checkboxes and select elements */
// http://pixelmatrixdesign.com/uniform/
uniform = {
	init:function() {
        //$("input, textarea, select, button").uniform();
        $("input.radio, input.checkbox, select").not('.slider-select select').uniform();
        // take the classname from the select element and apply it to the styled select
		$selectSelect = $('.selector select');
		for (var k=0; k<$selectSelect.length; k++) {
		$this = $selectSelect[k];
		$selectClass = $($selectSelect[k]).attr('class');
		$($selectSelect[k]).parent('.selector').addClass($selectClass);
		}
	}
}

/* enable editing on overview blocks (mijn cnvo) */
editBlocks = {
	init:function() {
		$('.overview-block .block-options ul').hide();
		$('.overview-block .results-nav').hide();
		// hover over block options
		$('.overview-block .block-options').hover(function(){
			
			$(this).find('ul').stop(true, true);
			$(this).find('ul').fadeIn();
			// hover over buttons
			$(this).find('li.delete, li.edit').hover(function(){
				$(this).addClass('hover');
			},
			function(){
				$(this).removeClass('hover');		
			});
			
		},
		function(){
			$(this).find('ul').stop(true, true);
			$(this).find('ul').fadeOut();		
		});	
		
		// click edit button
		$('.block-options li.edit').click(function(){
			$overviewBlock = $(this).parents('.overview-block');
			if ($overviewBlock.find('.results-nav').css('display') == 'none') {
				$overviewBlock.find('.results-nav').fadeIn();
			} else {
				$overviewBlock.find('.results-nav').fadeOut();
			}
			$overviewBlock.find('.results-nav select').change(function(){
				$(this).parents('.results-nav').fadeOut();
			});
				
			
		});	
		
		// click delete button
		$('.block-options li.delete').click(function(){	
			$overviewBlock = $(this).parents('.overview-block').parent();
			editBlocks.deleteBlock($overviewBlock);
		});
		
		// channel title for rss blocks
		if($(".rssblok").length){
      if($(".title_channel").length){
        $('.title_channel').each(function(){
  			$rssoverviewBlock = $(this).parent().parent().parent('.overview-block');
  			//alert($(this).parent().parent().parent('.overview-block').html());
        channeltitle = $(this).html();
  			$rssoverviewBlock.find('h2').html(channeltitle);
  			$(this).hide();						
  		  });
     } 
    }
    
    // listing of items inside the block[selectors are within the extension] based on limit
   if($(".overview-block").length){
    
      $('.limititem').each(function(){
        $(this).hide();
      });
      
      $('select.limitselect').each(function(){
          $cnvoBlok = $(this).parent().parent().parent().parent().parent('.csc-default');
          deflimit = $(this).val();
          limitcnt = 0;
          
          // for bookmark extension list
          $cnvoBlok.find('.tab-content').each(function(){
            limitcnt = 0;
            $(this).find('.limititem').each(function(){
              if(limitcnt < deflimit)
                $(this).show();
              else if(deflimit=='Alle')
                  $(this).show();
                limitcnt++;         
            });  
          });
          
          // for rss block extension list
          $cnvoBlok.find('.rssfeed-list').each(function(){
            limitcnt = 0;
            $(this).find('.limititem').each(function(){
              if(limitcnt < deflimit)
                $(this).show();
              else if(deflimit=='Alle')
                  $(this).show();
                limitcnt++;         
            });  
          });
          
          
          $(this).change(function(){
            $cnvoBlok = $(this).parent().parent().parent().parent().parent('.csc-default');
            deflimit = $(this).val();
            limitcnt = 0;
            
            // update to database for the user
      			var blockId = $(this).attr('id').replace('items-block-', '');
      			$.get("mijn-cnvo.html?type=3331", { actionfce:"limit-fce", limitfce: blockId, limit: deflimit }, function(data){
      				//$($overviewBlock).fadeOut();
      			});
            
            // for bookmark extension list
            $cnvoBlok.find('.tab-content').each(function(){
              limitcnt = 0;
              $(this).find('.limititem').each(function(){
                if(limitcnt < deflimit)
                  $(this).show();
                else if(deflimit=='Alle')
                  $(this).show();
                else
                  $(this).hide();
                limitcnt++;         
              });  
             });
             
             // for rss block extension list
             $cnvoBlok.find('.rssfeed-list').each(function(){
              limitcnt = 0;
              $(this).find('.limititem').each(function(){
                if(limitcnt < deflimit)
                  $(this).show();
                else if(deflimit=='Alle')
                  $(this).show();
                else
                  $(this).hide();
                limitcnt++;         
              });  
             });
             
             
          });
           
       });
      
     }   
		
		
	}, 
	deleteBlock:function() {
		$('input.delete-overview-block').one('click', function(){
			//update homepage options
			var blockId = $overviewBlock.attr('id').replace('c', '');
			
			//console.log(blockId); // hier gaat het dubbel
			// in case of mijn cnvo rss block
      if($overviewBlock.parent().find('.rssfcewidget').length){
         var blockId = $overviewBlock.parent().attr('id').replace('c', '');
      }
            
  			$.get("mijn-cnvo.html?type=3331", { actionfce:"remove-fce", removefce: blockId }, function(data){
				$($overviewBlock).fadeOut();
				editBlocks.updateOptionsForm($overviewBlock);
			});  
			
		});
	}, 
	updateOptionsForm:function($overviewBlock) {
		$checkboxID = 'check-' + $overviewBlock.attr('id').replace('c', '');
		$checkboxHiddenID = 'checkh-' + $overviewBlock.attr('id').replace('c', '');
		
		$('#'+$checkboxID).removeClass('checked').addClass('false');
		$('#'+$checkboxID).attr('checked', false);
		$('#'+$checkboxID).attr('value', 'false');
		
		$('#'+$checkboxHiddenID).removeClass('checked').addClass('false');
		$('#'+$checkboxHiddenID).attr('value', 'false');
		$('#'+$checkboxHiddenID).attr('checked', true);
		
		$.uniform.update("#"+$checkboxID);
		// clear rss input fields;
		if($overviewBlock.parent().find('.rssfcewidget').length){
			 $blockId = $overviewBlock.parent().attr('id').replace('c', '');
			 $('.rss-wrapper').find('input').each(function(){
				$inputBlockId = $(this).attr('name').replace('rss-feed-','');
				if($inputBlockId==$blockId){
					$(this).attr('value','');
					if($(this).parent().hasClass('extra')){
					  $(this).parent().hide();
					}            
				}
			 });
		}
    
		
	}


	
}

/* show overview blocks via form in homepage options popover (mijn cnvo) */
showBlocks = {
	init:function() {
		
		$("form#show-overview-blocks .checked:checkbox").live('click', function(){
			$(this).removeClass('checked').addClass('false');
			$(this).attr('value', 'false');
			var hiddenfield = $(this).attr('id').replace('check-', 'checkh-');
			
			// hidden fields aanpassen zodat een uitgevinkte checkbox ook verzonden kan worden
			$('#'+ hiddenfield).removeClass('checked').addClass('false');
			$('#'+ hiddenfield).attr('value', 'false');
			$('#'+ hiddenfield).attr('checked', true);
		});
		
		$("form#show-overview-blocks .false:checkbox").live('click', function(){
			$(this).removeClass('false').addClass('checked');
			$(this).attr('value', 'checked');
			var hiddenfield = $(this).attr('id').replace('check-', 'checkh-');
			
			// hidden fields aanpassen zodat een uitgevinkte checkbox ook verzonden kan worden
			$('#'+ hiddenfield).removeClass('false').addClass('checked');
			$('#'+ hiddenfield).attr('value', 'true');
			$('#'+ hiddenfield).attr('checked', true);
		});
		
		$('form#show-overview-blocks input.submit').bind('click', function(){
			$checkValues = {};
			
			var $revertFceArr = 0;
			var $removeFceArr = 0;
			
			$.each($('form#show-overview-blocks').serializeArray(), function(i, field) {
				$checkValues[i] = field.value;
				if (field.value == "true") {
					$blockID = field.name.replace('check-',''); 
					
					if($revertFceArr != 0){
						$revertFceArr = $revertFceArr +','+$blockID;
					}else{
						$revertFceArr = $blockID;
					}  
					
					$('#c'+$blockID).fadeIn(); 
				}
				if (field.value == "false") {
					$blockID = field.name.replace('check-','');
					
 					if($removeFceArr != 0){
						$removeFceArr = $removeFceArr +','+$blockID;
					}else{
						$removeFceArr = $blockID;
					}  

					$('#c'+$blockID).fadeOut();	
				}
			});
			
			if($revertFceArr != 0){
				$.get("mijn-cnvo.html?type=3331", { actionfce:"revert-fce", revertfce: $revertFceArr }, function(data){
					//revert block(s)
				}); 
			}
		
			if($removeFceArr != 0){
				$.get("mijn-cnvo.html?type=3331", { actionfce:"remove-fce", removefce: $removeFceArr }, function(data){
					//remove block(s)	
				}); 
			}	
			
			// rssblocks
			$('.rss-wrapper').find('input').each(function(){
         $inputBlockid = $(this).attr('name').replace('rss-feed-','');
         if($(this).attr('value')==''){
           $('#c'+$inputBlockid).fadeOut();
           $.get("mijn-cnvo.html?type=3331", { actionfce:"remove-fce", removefce: $inputBlockid }, function(data){ }); 
         }
        
      });
			
		});
	}
}

/* delete table row (in overview block, mijn cnvo) */
deleteTableRow = {
	init:function() {
		$deleteTDs = $('td.delete');
		$('<div class="tool-tip"><p></p></div>').appendTo($deleteTDs);
		$('<div class="strikethrough"></div>').appendTo($deleteTDs);
		$('td.delete span').css('visibility', 'hidden');
		$('td.delete .tool-tip').hide();
		$('td.delete .strikethrough').hide();
		$('.overview-block .tab-block table tr').hover(function() {
			$(this).find('td.delete span').css('visibility', 'visible');
		},
		function() {
			$(this).find('td.delete span').not('td.delete .tool-tip span').css('visibility', 'hidden');
		});
		for(var m=0; m<$deleteTDs.length; m++) {
			$($deleteTDs[m]).find('span').clone().appendTo($($deleteTDs[m]).find('p'));
		}
		$('td.delete span').hover(function() {
			$(this).parent().find('.tool-tip').show();
			$(this).parent().find('.strikethrough').show();
		},
		function() {
			$(this).parent().find('.tool-tip').hide();
			$(this).parent().find('.strikethrough').hide();
		});
		$('td.delete span').click(function() {
			$(this).parents('tr').fadeOut();
				// delete from database
			 $.get($(this).find('a').attr('href'), function(data){
   //alert("Data Loaded: " + data);
 });
		});
		
	}
}

deleteBookmarkRow = {
	init:function() {
     $deleteLis = $('.normal-bookmark li span.delete');
     $('<div class="tool-tip"><p></p></div>').appendTo($deleteLis);
		 $('<div class="strikethrough"></div>').appendTo($deleteLis);
		 $('.normal-bookmark li span.delete').css('visibility', 'hidden');
		 $('.normal-bookmark li .tool-tip').hide();
		 $('.normal-bookmark li .strikethrough').hide();
		 $('.normal-bookmark li').hover(function() {
			$(this).find('span.delete').css('visibility', 'visible');
		},
		function() {
			$(this).find('span.delete').not('li .tool-tip span').css('visibility', 'hidden');
		});
		
		for(var m=0; m<$deleteLis.length; m++) {
			$($deleteLis[m]).find('strong').clone().appendTo($($deleteLis[m]).find('p'));
		}
		$('.normal-bookmark li span.delete').hover(function() {
			$(this).parent().find('.tool-tip').show();
			$(this).parent().find('.strikethrough').show();
		},
		function() {
			$(this).parent().find('.tool-tip').hide();
			$(this).parent().find('.strikethrough').hide();
		});
		$('.normal-bookmark li span.delete').click(function() {
			$(this).parents('li').fadeOut();
				// delete from database
			 $.get($(this).find('a').attr('href'), function(data){
   //alert("Data Loaded: " + data);
 });
      return false;
		});
     	
	}
}

/* activates the animation that shows a user they've saved the article */
saveArticle = {
	init:function() {
		if ($('.article-options li.save, .page-options li.save, .article-option a.save').length > 0) {
			$('<div class="save-signal"></div>').appendTo('#content');

			$('.article-options li.save a, .page-options li.save a, .article-option a.save').click(function(){
				// calculate position and dimensions of mijn CNVO link
				$posMijnCNVO = $('#main-nav .right-link').offset();
				
				if ($.browser.msie  && parseInt($.browser.version) < 8) {
				$posMijnCNVO = $('#main-nav .right-link').position();
				}
				$mijnCNVOWidth = $('#main-nav .right-link').width();
				$halfMijnCNVOWidth = $mijnCNVOWidth/2;
				$mijnCNVOHeight = $('#main-nav .right-link').height();
				$halfMijnCNVOHeight = $mijnCNVOHeight/2;
				// calculate position and dimensions of article and apply to save signal
				$posArticle = $(this).parents('.article-options').offset();
				if($.browser.msie  && parseInt($.browser.version) < 8){
            $posArticle = $(this).parents('.article-options').position();
        }
        //secondary-content
				$parentWidth = $(this).parents('.article-options').width();
				$articleHeight = $(this).parents('.article-options').prev().height();
				if($(this).parents('.secondary-content').find('.page-options').length) {
					if($.browser.msie  && parseInt($.browser.version) < 8){
            $posArticle = $(this).parent().position();
          }else{
            $posArticle = $(this).parent().offset();
          }
          
					$parentWidth = $(this).parent().width();
					$articleHeight = $(this).parent().prev().height();
				}
				
				if($(this).parents('.article-option').length){
          $posArticle = $(this).parents('.article-option').offset();
				if($.browser.msie  && parseInt($.browser.version) < 8){
            $posArticle = $(this).parents('.article-option').position();
        }
        //secondary-content
				$parentWidth = $(this).parents('.article-option').width();
				$articleHeight = $(this).parents('.article-option').prev().height();
          
        }
								
				$('.save-signal').css('width', $parentWidth);
				$('.save-signal').css('height', $articleHeight);
				// show save signal, position it relative to the article before the "save" link and animate it
				$('.save-signal').css('display', 'block');
				$('.save-signal').css('left', $posArticle.left);
				$('.save-signal').css('top', $posArticle.top - $articleHeight);
				//$('.save-signal').position({ my: "left top", at: "left top", of: $(this).parent().parent().parent().prev() });
        $clickobj = $(this);				
				$('.save-signal').animate({
					width: 0,
					height: 0,
					top: $posMijnCNVO.top + $halfMijnCNVOHeight,
					left: $posMijnCNVO.left + $halfMijnCNVOWidth
				}, 600, function(){
					// completed animation					
					$('.save-signal').css('display', 'none');
					/* add to database part begin  */
     $checkhtml =  $('#saveswoosh-this').html();
	   $.get($clickobj.attr('href'), function(data){
         $responseText = $(data).filter('#responsetext').html();
         if($responseText=='existing'){
            if($checkhtml==null){
               $('<div class="popover-container" style="display:none;"><div id="saveswoosh-this" class="popover"><div class="title"><h2>Opslaan in Mijn CNVO</h2></div><div class="pop-content"><div class="article-infox"><p>Deze pagina is reeds opgeslagen in jouw Mijn CNVO omgeving</p></div><fieldset class="buttons"><div class="submit-button"><input type="submit" value="Sluiten" class="close-pop submit" /></div></fieldset></div></div></div>').appendTo('body');
                            
            }
    
           Cufon.replace('h2:not(.no-cufon)', { 
    	      fontWeight: 'bold'
           });
           $('.save-signal').css('display', 'none');
           popOvers.showIt('saveswoosh-this');
           $('.close-pop').click(function(){
    				$parentPanel = $(this).parents('.popover-container');
    				popOvers.hideIt($parentPanel);
    				return false;
    			 });
    
         }
   
     });
     /* add to database part end  */					
				});
				        				
				return false;
			});
		}
	}
}

/* activates the print buttons */
printArticle = {
	init:function() {
		$('.print-button').click(function(){
			window.print();
		});
		$('.print-button').hover(function(){
			$(this).addClass('hover');
		},function(){
			$(this).removeClass('hover');
		});
	}
}

/* add more fields to a form */
addFields = {
	init:function() {
		$('.extra-fields').find('div.extra').hide();
		$childCounter = 0;
		$('.extra-fields span.add').click(function(){
			$childCounter ++;
			if (($(this).parents('.extra-fields').children(":nth-child("+$childCounter+")").css('display') == 'none') && ($(this).parents('.extra-fields').children(":nth-child("+$childCounter+")").attr('class').indexOf('extra') != -1)) {
				$(this).parents('.extra-fields').children(":nth-child("+$childCounter+")").fadeIn();	
			}
		});
		$('.extra-fields span.add').hover(function(){
			$(this).addClass('hover');
		}, function(){
			$(this).removeClass('hover');		
		});
		if($('.pop-content .tip-a-friend').length){
      $('.large').each(function(){
         if($(this).attr('value')){
           if($(this).parents('.extra').length){
             $(this).parents('.extra').show();
           }
         
         }
      
      });
  
    }
	}
}

/* add hover states to testimonial images */
testimonials = {
	init:function() {
		if (($.browser.msie) && ($.browser.version == '6.0')) {
			return false;
		} else {
			$(".testimonials li a").hover(
				
				function(){ 
					$(this).find('img.testi-hidden').removeClass('testi-hidden');
					$(this).find('img:first').addClass('testi-hidden');
					$('.testimonials li a').css('z-index', '33');
					$(this).css('z-index', '44');
				}, 
				function() {
					$(this).find('img.testi-hidden').removeClass('testi-hidden');
					$(this).find('img:last').addClass('testi-hidden');
					$('.testimonials li a').css('z-index', '0');
					$(this).css('z-index', '0');
				} 			
	
/* 				function(){ 
					$imgPath = $(this).find('img').attr('src');
					$newImg = $imgPath.replace('.png','-ro.png');
					$(this).find('img').attr('src', $newImg);
					$('.testimonials li a').css('z-index', '33');
					$(this).css('z-index', '44');
				}, 
				function() {
					if ($(this).find('img').attr('src').indexOf('-ro.png') != -1) {
						$roImg = $(this).find('img').attr('src');
						$newImg = $roImg.replace('-ro.png','.png');
						$(this).find('img').attr('src', $newImg);
					}
				}  */
			);
		}
	}
}

/* disable textarea resize */
textareaResize = {
	init:function() {
		$('textarea').css('resize', 'none');
	}
}

videoShare = {
	init:function() {
		if ($('.video').length > 0) {
		
			
			
			var position = $('.video').position();
			var width = $('.video').width() - 2;	
			//var width = 423; 
			
			if (width<1) {
				setTimeout("videoShare.init()", 500);
			}
			
			widthSmall = 24;
			widthLarge = 190;
		
			leftPos1 = position.left + width - widthSmall;
			leftPos2 = position.left + width - widthLarge;
		
			topPos1 = position.top + 10;
			
			
 			$('.videosharing').css({"left": leftPos1 + "px", "top" : topPos1 + "px"});


			$('.videosharing').mouseenter (function() {
				$('.videosharing').stop(true, false);
				$('.videosharing').animate({
		 			"width" : widthLarge + "px",
			 		"left" : leftPos2 + "px"
			 	})
			 }).mouseleave (function() {
				$('.videosharing').stop(true, false);
				$('.videosharing').animate({
		 			"width" : widthSmall + "px",
			 		"left" : leftPos1 + "px"
			 	})
			 })
		}

	}
}

setPagination = {
	init:function() {
//		$("li").remove(":contains('First')");	
//		$("li").remove(":contains('Last')");	
		
		$("div.pagination ul li:contains('Volgende')").addClass("next");
		$("div.pagination ul li:contains('Vorige')").addClass("back");

		$("div.pagination ul li:last-child").addClass("last");
	}
}

deleteInbox = {
  init:function() {
    if($('.mijn-inbox').length > 0){
       $('li.delete span').click(function() {
  			 $(this).parents('li').fadeOut();
  			 // delete from database
  			 $.get($(this).find('a').attr('href'), function(data){
         //alert("Data Loaded: " + data);
         });
         return false;
		   });
		   
		   $('li.view').click(function() {
		       $.get($(this).find('a').attr('href'), function(data){
            //alert("Data Loaded: " + data);
           });
		   
		   });
		   
    }
  }

}


testimonialLoadpop = {
  init:function() {
  
    $('.popover .pop-content div .content-element').css('display','none');
    $('.popover .pop-content div .content-element:first').css('display','block');
    
    $('.thumbnail-block .thumbnail-carousel ul li').click(function() {
     var myid = $(this).attr('id');
     indexarr = myid.split('tbutton-');
     index = indexarr[1];
     var newid = 'testimonial-' + index;
     $('.popover .pop-content div .content-element').css('display','none');
     $('#' + newid).css('display','block');
    });
  
  }
}


replacetelefoon = {
  init:function(){
  preplace = '<span class="telefoon"></span>';
  $('p').each(function() {
    var htmlconp = $(this).html();
    newhtmlp = htmlconp.replace('Tel:', preplace);
    $(this).html(newhtmlp);
  })
  sreplace = '<strong class="telefoon"></strong>';
  $('span').each(function() {
    var htmlcons = $(this).html();
    newhtmls = htmlcons.replace('Tel:', sreplace);
    $(this).html(newhtmls);
  })
  
  }
}

powermailButtons = {
	init:function() {

		if ($('.powermail_multiplejs_tabs_item').length) {	
			
			$("fieldset.tx-powermail-pi1_fieldset").append('<div class="powermail-nav"> <div class="prev-button"> <a class="prev" href="#">vorige stap</a> </div> <div class="button"> <a class="next" href="#"><span>volgende stap</span></a> </div> </div>'); 
			
			if ($("fieldset.tx-powermail-pi1_fieldset:first")){
				$("fieldset.tx-powermail-pi1_fieldset:first .prev-button").remove();
			}
					
			if($("fieldset.tx-powermail-pi1_fieldset:last")){
				$("fieldset.tx-powermail-pi1_fieldset:last .powermail-nav").remove();
				
				$("fieldset.tx-powermail-pi1_fieldset:last .buttons").prepend('<div class="prev-button"> <a class="prev" href="#">vorige</a> </div>'); 
				
			}		
			
			$('.tx-powermail-pi1_fieldset .prev-button a.prev').click(function () {
				$('ul#tabs li.ui-tabs-selected').prev('li').children('a').click();
				
				return false;
			});
			
							
			$('.tx-powermail-pi1_fieldset .button a.next').click(function () {
				var ret = true;
				
				$('.required').each(function(i) {
					var r = $(this).validate();
					if (!r)
						ret = false;
				});
				
				if (ret){
          $('ul#tabs li.ui-tabs-selected').next('li').children('a').click();
        }	
					
				return false;
			});	
			
		}
	}
}

internalRssMijncnvo = {
	init:function() {
    if($('#rsspopup').length){    
     if($('.mijn-rss-cnvo').length){
        $('.mijn-rss-cnvo').each(function(){
           $(this).click(function(){
              $rssurl = $(this).attr('href');
             $.get("mijn-cnvo.html?type=3331", { actionfce:"add-internalrss", urldata: $rssurl }, function(data){
            	 $responseText = $(data).filter('#responserss').html();
               if($responseText=='insertrss'){
                 $('.pop-content').html('<div class="article-infox"><p>De wijzigingen zijn opgeslagen in jouw Mijn CNVO.</p></div><fieldset class="buttons"><div class="submit-button"><input type="submit" value="Sluiten" class="close-pop submit" /></div></fieldset>');
                 $('.close-pop').click(function(){
              			location.reload();
            		  });
                 
               }
               
               if($responseText=='countlimit'){
                   $('.pop-content').html('<div class="article-infox"><p>Deze RSS-feed kan niet toegevoegd worden omdat het maximale (3) aantal RSS-feeds is bereikt.</p></div><fieldset class="buttons"><div class="submit-button"><input type="submit" value="Sluiten" class="close-pop submit" /></div></fieldset>');
                 $('.close-pop').click(function(){
              			location.reload();
            		  });
               }
               
               if($responseText=='feedexist-1'){
                  $('.pop-content').html('<div class="article-infox"><p>De RSS-feed is aan jouw Mijn CNVO bestaat reeds.</p></div><fieldset class="buttons"><div class="submit-button"><input type="submit" value="Sluiten" class="close-pop submit" /></div></fieldset>');
                 $('.close-pop').click(function(){
              			location.reload();
            		  });
               }
               
      				
      			}); 
            return false;
              
              
           });
        });
        
        }
     }else{
     
        if($('.mijn-rss-cnvo').length){
     
             
       $('<div class="save-signal"></div>').appendTo('#content');
     
       $('<div class="popover-container" style="display:none;"><div id="rsssinsert-this" class="popover"><div class="title"><h2>Opslaan in Mijn CNVO</h2></div><div class="pop-content"><div class="article-infox"><p>De wijzigingen zijn opgeslagen in jouw Mijn CNVO.</p></div><fieldset class="buttons"><div class="submit-button"><input type="submit" value="Sluiten" class="close-pop submit" /></div></fieldset></div></div></div>').appendTo('body');
       
       $('<div class="popover-container" style="display:none;"><div id="rsscount-this" class="popover"><div class="title"><h2>Opslaan in Mijn CNVO</h2></div><div class="pop-content"><div class="article-infox"><p>Deze RSS-feed kan niet toegevoegd worden omdat het maximale (3) aantal RSS-feeds is bereikt.</p></div><fieldset class="buttons"><div class="submit-button"><input type="submit" value="Sluiten" class="close-pop submit" /></div></fieldset></div></div></div>').appendTo('body');
       
       $('<div class="popover-container" style="display:none;"><div id="rssexist-this" class="popover"><div class="title"><h2>Opslaan in Mijn CNVO</h2></div><div class="pop-content"><div class="article-infox"><p>De RSS-feed is aan jouw Mijn CNVO bestaat reeds.</p></div><fieldset class="buttons"><div class="submit-button"><input type="submit" value="Sluiten" class="close-pop submit" /></div></fieldset></div></div></div>').appendTo('body');
         
       $('.mijn-rss-cnvo').each(function(){
           $(this).click(function(){
                    
             	if ($.browser.msie  && parseInt($.browser.version) < 8) {
				$posMijnCNVO = $('#main-nav .right-link').position();
				}
				
				else {
				  $posMijnCNVO = $('#main-nav .right-link').offset();
				}
				
				$mijnCNVOWidth = $('#main-nav .right-link').width();
				$halfMijnCNVOWidth = $mijnCNVOWidth/2;
				$mijnCNVOHeight = $('#main-nav .right-link').height();
				$halfMijnCNVOHeight = $mijnCNVOHeight/2;
				// calculate position and dimensions of article and apply to save signal
				if ($(this).parents('.page-options')) {
					$posArticle = $(this).parent().offset();
					$parentWidth = $(this).parent().width();
					$articleHeight = $(this).parent().prev().height();
				} else {
					$posArticle = $(this).parents('.rsslinks_item').offset();
					$parentWidth = $(this).parents('.rsslinks_item').width();
					$articleHeight = $(this).parents('.rsslinks_item').prev().height();
				}
				$('.save-signal').css('width', $parentWidth);
				$('.save-signal').css('height', $articleHeight);
				// show save signal, position it relative to the article before the "save" link and animate it
				$('.save-signal').css('display', 'block');
				$('.save-signal').css('left', $posArticle.left);
				$('.save-signal').css('top', $posArticle.top - $articleHeight);
				//$('.save-signal').position({ my: "left top", at: "left top", of: $(this).parent().parent().parent().prev() });				
				$('.save-signal').animate({
					width: 0,
					height: 0,
					top: $posMijnCNVO.top + $halfMijnCNVOHeight,
					left: $posMijnCNVO.left + $halfMijnCNVOWidth
				}, 600, function(){
					// completed animation					
					$('.save-signal').css('display', 'none');
				});
           
           
             $rssurl = $(this).attr('href');
             $.get("mijn-cnvo.html?type=3331", { actionfce:"add-internalrss", urldata: $rssurl }, function(data){
               $('.save-signal').css('display', 'none');
            	 $responseText = $(data).filter('#responserss').html();
               if($responseText=='insertrss'){
                  popOvers.showIt('rsssinsert-this');
                  $('.close-pop').click(function(){
              			$parentPanel = $(this).parents('.popover-container');
              			popOvers.hideIt($parentPanel);
              			return false;
            		  });
                 
               }
               
               if($responseText=='countlimit'){
                  popOvers.showIt('rsscount-this');
                  $('.close-pop').click(function(){
              			$parentPanel = $(this).parents('.popover-container');
              			popOvers.hideIt($parentPanel);
              			return false;
            		  });
               }
               
               if($responseText=='feedexist-1'){
                  popOvers.showIt('rssexist-this');
                  $('.close-pop').click(function(){
              			$parentPanel = $(this).parents('.popover-container');
              			popOvers.hideIt($parentPanel);
              			return false;
            		  });
               }
               
      				
      			}); 
            return false;
          });
         
       });     
     
     }
     
     
     }
     
  }
}

//document.location.href
faqBookmark = {
  init:function() {
      var $location = $(location).attr('href');
	    var $url = $location.split("#e");
	    var $faqid = $url[1];
	    if($faqid){
        $('#e'+$faqid).find('h2.ui-accordion-header').removeClass('ui-state-default');
        $('#e'+$faqid).find('h2.ui-accordion-header').addClass('ui-state-active');
        $('#e'+$faqid).find('.expander-content').css('display','block');
        //$('#e'+$faqid).find('.accordion-expander ul.article-list li .title').addClass('ui-state-active');
      }
 }
}


printpopupcufon = {
  init:function() {
    //$('.print-body cufon').css('position','absolute');
    //$('.print-body cufoncanvas').css('position','relative');
    //$('.print-body cufoncanvas cvml').css('position','relative');
    //$('.print-body h2').css('position','relative');

  
  }
  }

   function getParameterByNameForQueryString( name, queryString ) {
  queryString = "http://cnvo2.dev.alternet.nl/?"+queryString;
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec(queryString);
  if( results == null )
   return "";
  else
   return decodeURIComponent(results[1].replace(/\+/g, " "));
 }
 
 
draganddrop = {
	init:function() {
	
	 //drag and drop elementen
		// Linker lijstje		
		if ($(".overview .col-1").length) {
			// retreive left blocks of the user if return 0 responsedata then its first time
			var r = new Date().getTime(); // unique random number to workaround IE cache issue
			$.get("mijn-cnvo.html?type=3331" + "&r=" + r, { actionfce:"retreiveorder", blkval:"left"}, function(data){
      				initleft = $(data).filter('#leftblock').html();
					
					if (initleft) {
						  $.each(initleft.split(","),function(i,id) {
								$("#"+id).appendTo(".overview .col-1");
						  });
					}
			});
		
			var links = $(".overview .col-1, .overview .col-2").sortable({
				connectWith: ".overview .col-1, .overview .col-2",
				placeholder: "overview-block-ghost",
				forcePlaceholderSize: true,
				opacity: 0.6,
				cursor: "move",
				handle: '.block-options h2',
			
				update:function(e,ui) {	
					var order = links.sortable("toArray").join();
					$.get("mijn-cnvo.html?type=3331", { actionfce:"orderblock", leftblk: order});
				}
			});
		} 
		
		// rechtse lijstje
		if ($(".overview .col-2").length) {
		  // retreive right blocks of the user if return 0 responsedata then its first time
			var r = new Date().getTime(); // unique random number to workaround IE cache issue
			$.get("mijn-cnvo.html?type=3331" + "&r=" + r, { actionfce:"retreiveorder", blkval:"right"}, function(data){
      				initright = $(data).filter('#rightblock').html();
					
					if (initright) {
						 $.each(initright.split(","),function(i,id) {
								$("#"+id).appendTo(".overview .col-2");
						  });
					}
      		});
		
			var rechts = $(".overview .col-2").sortable({
				connectWith: ".overview .col-1, .overview .col-2",
				placeholder: "overview-block-ghost",
				forcePlaceholderSize: true,
				opacity: 0.6,
				cursor: "move",
				handle: '.block-options h2',
				
				update:function(e,ui) {
					var order = rechts.sortable("toArray").join();
					$.get("mijn-cnvo.html?type=3331", { actionfce:"orderblock", rightblk: order});
				}
				
			});	
		} 		
	// eind drag and drop elementen
	}
}
