//Creating the submenu
$.metadata.setType("attr", "validate");

$(document).ready(function(){ 
	$("ul.sf-menu").supersubs({ 
    	minWidth:    12,   // minimum width of sub-menus in em units 
        maxWidth:    27,   // maximum width of sub-menus in em units 
        extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
                           // due to slight rounding differences and font-family 
	}).superfish({autoArrows: false});  // call supersubs first, then superfish, so that subs are 
                         				// not display:none when measuring. Call before initialising 
                         				// containing tabs for same reason. 
	
	$('input[type="text"]').focus(function (){
		clearText(this);
	});
	$('input[type="text"]').blur(function (){
		addText(this);
	});
	
	$('#submit-newsletter').click(function() {
		post_reg_newsletter_form();
	});
	
	$('#reg_newsletter_sended_div').hide();
	
	
	///Login Form intranet
	//Toggle mededelingen formulier
	$('#form_slide').click(function() {
		$('#med_form').toggle();
		
		if($('textarea.tinymce').is(":visible")){
			get_tinymce_editor();
		}
	});
	
	$('#form_mededelingen').submit(function() {
		post_message();
		return false;
	});
	$('#submit_employee_login').click(function() {
		post_login_employee_form('login');
	});
	
	// this one requires the value to be the same as the first parameter
	$.validator.methods.equal = function(value, element, param) {
		return value == param;
	};
	
	$('#llicc2011_form').validate({
		rules: {
			math: {
				equal: 11
			}
		}
	});
	$('#iesc2011_form').validate({
		rules: {
			math: {
				equal: 11
			}
		}
	});
	$('#dowmc60_form').validate({
		rules: {
			math: {
				equal: 11
			}
		}
	});
	$('#afp2011_form').validate({
		rules: {
			math: {
				equal: 11
			}
		}
	});
	$('#ensemble_form').html('');
	$('#solist_form').html('');
	$('label[for="form_choice"]').hide();
	
}); 



//Links with the class external will open in a new window, to get the code valid in xhtml-strict
$(function() {
	$(".external").attr("target","_blank");
});

function clearText(theField)
{
if (theField.defaultValue == theField.value)
theField.value = '';
}

function addText(theField)
{
if (theField.value == '')
theField.value = theField .defaultValue;
}

//Mailme - Email Spam Protector
$(function() {
    var at = / at /;
    var dot = / dot /g;
    $('span.mailme').each( function() {
        var addr = jQuery(this).text().replace(at,"@").replace(dot,".");
        $(this)
            .after('<a href="mailto:'+addr+'" class="mailme">'+ addr +'</a>')
            .remove();
    });
});

function post_reg_newsletter_form()
{
	
	var formdata = $("#reg_newsletter_form").serialize();
	$.ajax({
		type: "POST",
		url: "../reg_nieuwsbrief.php",
		data: formdata,
		timeout: 2000,
		error: function (XMLHttpRequest, textStatus, errorThrown) {
			alert('Er ging iets mis, probeer opnieuw.');
		},
		success: function (data) {
			var response=$(data);
            var oneval = response.filter('#message').html();
			var subval = response.filter('#hide').html();
			
			
			if(subval == 'yes'){
				$('#reg_newsletter_form_div').hide();
				$('#reg_newsletter_sended_div').html(oneval);
				$('#reg_newsletter_sended_div').show();
			}
			else
			{
				alert(oneval);
			}
		}
	});
};

document.write('<style>.noscript { display: none; }</style>');
jQuery(document).ready(function($) {
				// We only want these styles applied when javascript is enabled
				$('div.navigation').css({'width' : '220px', 'float' : 'left'});
				$('div.content').css('display', 'block');

				// Initially set opacity on thumbs and add
				// additional styling for hover effect on thumbs
				var onMouseOutOpacity = 0.67;
				$('#thumbs ul.thumbs li').opacityrollover({
					mouseOutOpacity:   onMouseOutOpacity,
					mouseOverOpacity:  1.0,
					fadeSpeed:         'fast',
					exemptionSelector: '.selected'
				});
				
				// Initialize Advanced Galleriffic Gallery
				var gallery = $('#thumbs').galleriffic({
					delay:                     2500,
					numThumbs:                 18,
					preloadAhead:              10,
					enableTopPager:            true,
					enableBottomPager:         true,
					maxPagesToShow:            7,
					imageContainerSel:         '#slideshow',
					controlsContainerSel:      '#controls',
					captionContainerSel:       '#caption',
					loadingContainerSel:       '#loading',
					renderSSControls:          true,
					renderNavControls:         false,
					playLinkText:              wmc_play_slideshow,
					pauseLinkText:             wmc_pause_slideshow,
					prevLinkText:              wmc_prev_pic,
					nextLinkText:              wmc_next_pic,
					nextPageLinkText:          wmc_next,
					prevPageLinkText:          wmc_prev,
					enableHistory:             false,
					autoStart:                 false,
					syncTransitions:           true,
					defaultTransitionDuration: 900,
					onSlideChange:             function(prevIndex, nextIndex) {
						// 'this' refers to the gallery, which is an extension of $('#thumbs')
						this.find('ul.thumbs').children()
							.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
							.eq(nextIndex).fadeTo('fast', 1.0);
					},
					onPageTransitionOut:       function(callback) {
						this.fadeTo('fast', 0.0, callback);
					},
					onPageTransitionIn:        function() {
						this.fadeTo('fast', 1.0);
					}
				});
			});

function post_message()
{
	var formdata = $("#form_mededelingen").serialize();
	$.ajax({
		type: "POST",
		url: "../../../../exe/post_message.php",
		data: formdata,
		timeout: 2000,
		error: function (XMLHttpRequest, textStatus, errorThrown) {
			alert('Er ging iets mis, probeer opnieuw.');
		},
		success: function (data) {
			var response=$(data);
            var oneval = response.filter('#messagekind').html();
			var subval = response.filter('#messagetext').html();
			
			alert(subval);
			
			if(oneval == 'positive')
			{
				location.reload();
			}
		}
	});
};

function post_login_employee_form(action)
{
	var formdata = $("#login_employee_form").serialize();
	$.ajax({
		type: "POST",
		url: "../../../../exe/login.php?t="+action,
		data: formdata,
		timeout: 2000,
		error: function (XMLHttpRequest, textStatus, errorThrown) {
			alert('Er ging iets mis, probeer opnieuw.');
		},
		success: function (data) {
			var response=$(data);
            var oneval = response.filter('#kind').html();
			var subval = response.filter('#message').html();
			
			if(oneval == 'positive')
			{
				location.reload();
			}
			
			if(oneval == 'negative')
				var mess_div = 'login_newsletter_mess_div';
			
			$("#"+mess_div).removeClass();
			$("#"+mess_div).addClass(oneval);
			$("#"+mess_div).show();
			$("#"+mess_div).html("<span>"+subval+"</span>");
			$("#"+mess_div).animate({ "opacity" : 1 });
			
		}
	});
};

jQuery(function( $ ){
	// Scroll initially if there's a hash (#something) in the url 
	$.localScroll.hash({
		queue:true,
		duration:1500
	});
	
	/**
	 * NOTE: I use $.localScroll instead of $('#navigation').localScroll() so I
	 * also affect the >> and << links. I want every link in the page to scroll.
	 */
	$('.news_archive_sub').localScroll({
		queue:true,
		duration:1500,
		hash:true
	});
});

function get_form_select(form)
{
	var lang = $('#lang').val();
	
	if(form == 'solist_form')
    {
        $.ajax({
            type: "GET",
            url: "../../../../exe/"+form+".php?lang="+lang,
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert('Er ging iets mis, probeer opnieuw.');
            },
            success: function (data) {
                $('#solist_form').html(data);
                $('#form_choice').val('solist_form');
                $('#ensemble_form').html('');
                $('label[for="form_choice"]').hide();
            }
        });    
    }
    else if(form == 'duo_form')
    {
        $.ajax({
            type: "GET",
            url: "../../../../exe/"+form+".php?lang="+lang,
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert('Er ging iets mis, probeer opnieuw.');
            },
            success: function (data) {
                $('#solist_form').html(data);
                $('#form_choice').val('duo_form');
                $('#ensemble_form').html('');
                $('label[for="form_choice"]').hide();
            }
        });    
    }
    else if(form == 'ensemble_form')
	{
		$.ajax({
			type: "GET",
			url: "../../../../exe/"+form+".php?lang="+lang,
			error: function (XMLHttpRequest, textStatus, errorThrown) {
				alert('Er ging iets mis, probeer opnieuw.');
			},
			success: function (data) {
				$('#ensemble_form').html(data);
				$('#form_choice').val('ensemble_form');
				$('#solist_form').html('');
				$('label[for="form_choice"]').hide();
			}
		});	
	}
	else
	{
		$('#ensemble_form').html('');
		$('#form_choice').val('');
		$('#solist_form').html('');
		$('label[for="form_choice"]').show();
	}
}


function get_tinymce_editor()
{
		$('textarea.tinymce').tinymce({
			// Location of TinyMCE script
			script_url : '../../../../cms/tinymce/tiny_mce.js',

			// General options
			theme : "advanced",
			language : "nl",
			skin : "thebigreason",
			width: "395",

			plugins : "paste,emotions",

			// Theme options
			theme_advanced_buttons1 : "emotions,separator,bold,italic,underline,strikethrough,separator,link,unlink",
			theme_advanced_buttons2 : "",
			theme_advanced_buttons3 : "",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			
			paste_auto_cleanup_on_paste : true,
			paste_preprocess : function(pl, o) {
				// Content string containing the HTML from the clipboard
				alert(o.content);
			},
			paste_postprocess : function(pl, o) {
				// Content DOM node containing the DOM structure of the clipboard
				alert(o.node.innerHTML);
			},
			relative_urls : false,
			convert_urls : false
		});
}

function get_employee(member_id,path)
{
	$.ajax({
		type: "GET",
		url: "../../../../exe/get_employee.php?member_id="+member_id+"&path="+path,
		error: function (XMLHttpRequest, textStatus, errorThrown) {
			alert('Er ging iets mis, probeer opnieuw.');
		},
		success: function (data) {
			$('#member_div').html(data);
		}
	});	
}

function save_new_password()
{
	var formdata = $('#newpassword').serialize();
	$.ajax({
		type: "GET",
		url: "../../../../exe/get_passwordform.php",
		data:formdata,
		error: function (XMLHttpRequest, textStatus, errorThrown) {
			alert('Er ging iets mis, probeer opnieuw.');
		},
		success: function (data) {
			$('#password').val('');
			$('#passwordform').hide();
			$('#passwordform_mess').show();
			$('#passwordform_mess').html(data);
		}
	});	
}

function check_instrument_iesc()
{
	var hout_checked = $('input[name=hout]').is(':checked');
	var koper_checked = $('input[name=koper]').is(':checked');
	if(hout_checked || koper_checked)
	{
		$('input[name=instrument]').addClass('required');
	}
	else
	{
		$('input[name=instrument]').removeClass('required');
	}
}

function check_dutchopen()
{
	var country = $('input[name=cp_land]').val().toLowerCase();
	var arr = ["nederland", "netherlands", "the netherlands", "holland"];
	if(jQuery.inArray(country,arr) > -1) {
		$('input[name=ork_iban]').removeClass('required');
		$('input[name=ork_swift]').removeClass('required');
	}
	else
	{
		$('input[name=ork_iban]').addClass('required');
		$('input[name=ork_swift]').addClass('required');
	}
}


function check_iesc_radios(id)
{
	var checked = $('input[name='+id+']').is(':checked');
	if(checked)
	{
		$('#'+id+'_concert').attr('checked','checked');
	}
	else
	{
		$('input[name='+id+'_divisie]').removeAttr('checked');
	}
}

function clearForm(id)
{
	$(':input',id)
 	.not(':button, :submit, :reset, :hidden')
 	.val('')
 	.removeAttr('checked')
 	.removeAttr('selected');

}
