Cufon.replace('#topmenu a',{hover:'true'})('h1')('h2')('h3')('.button');

$(document).ready(function() {
	
	$('.dossierbox .item:last-child').addClass('last');
	
	var origVal = $('#searchinput input').val();
	$('#searchinput input').focus(function(){
			if($(this).val() == origVal) {
			$(this).val('');
			}
			}).blur(function(){
			if($(this).val() == '') {
			$(this).val(origVal)
			}
	});
	
	
	$('#slidecontainer').cycle({
				fx:'fade',
				speed:1000, 
				timeout:5000,
				pause:1
	});
	
	$('#slidecontainer_right').cycle({
				fx:'fade',
				speed:1000, 
				timeout:5000,
				pause:1
	});
	
	$('#newsbox .itemlist').cycle({
				fx:'scrollHorz',
				speed:1000, 
				timeout:5000,
				pause:1,
				pager: '#newspager'
	});
	
	$('#cycle_bigads').cycle({
				fx:'fade',
				speed:1000, 
				timeout:5000,
				pause:1
	});
	
	$('#newspager a').bind("click", function() {
		return false;
	});
	
	
});

////////////////////////////////////////////////////////////////////////////////////////////////////
////////// SEMINAR SUBSCRIPTION FORM
////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////
////////// Link "Als uw gegevens niet meer correct zijn, klik hier om deze te wijzigen."
$(document).ready(function() {	
	$("#HidePrefilledUserFormLink").click(
		function(){
			$('#ShowPrefilledUserFormIfLoggedIn').attr('value','0');	
			$('#registrationform').submit();
		}
	);
});

////////////////////////////////////////////////////////////////////////////////////////////////////
////////// Automatically copy contents from company info to facturation info

// registrationcompany_name > invoicecompany_name
$(document).ready(function() {	
	$("#registrationcompany_details input:text").blur(function(){
		inputvalue = $(this).val();	
		inputid = $(this).attr('id');
		inputid = '#' + inputid.replace('registrationcompany_', 'invoicecompany_');
		if (inputid != '#invoicecompany_email') { 
			$(inputid).val(inputvalue)
		};
	});
	
	// TODO: change value of radio buttons too
	// registrationcompany_vatpercentage
	// invoicecompany_vatpercentage
	// perhaps this can help: 
	// http://my.galagzee.com/2007/09/21/selecting-radio-button-in-javascript-with-jquery/	
});

////////////////////////////////////////////////////////////////////////////////////////////////////
////////// Hide/show "Aard (andere)" field. Show if selection in "Aard" field is "-1" ("Andere...")

function hideOrShowOtherCompanyTypeField() {
	if ($("#registrationcompany_type").val() == '-1') {
		$("#aard_other").show();
		$("#registrationcompany_type_other").focus();
	} else {
		$("#aard_other").hide();
	}
}

function hideOrShowOtherInvoiceCompanyTypeField() {
	if ($("#invoicecompany_type").val() == '-1') {
		$("#invoiceaard_other").show();
		$("#invoicecompany_type_other").focus();
	} else {
		$("#invoiceaard_other").hide();
	}
}

$(document).ready(function() {	
	hideOrShowOtherCompanyTypeField();
	$("#registrationcompany_type").change(function(){
		hideOrShowOtherCompanyTypeField();
	});
	
	hideOrShowOtherInvoiceCompanyTypeField();
	$("#invoicecompany_type").change(function(){
		hideOrShowOtherInvoiceCompanyTypeField();
	});
});


////////////////////////////////////////////////////////////////////////////////////////////////////
////////// Company & location select boxes population

if (!WAX) { var WAX = new Object() }

WAX = {
		
	company_selected					:	'',
	location_selected					:	'',
	invoicecompany_location_selected	:	'',

	companySelected	:	function() {
		$('#location').empty();
		$.each(eval(WAX.company_selected), function(key,value) {
			$('#location').append('<option value="'+key.replace(/p/,'')+'">'+value+'</option>');
		});
		
		$('#invoicecompany_location').empty();
		$.each(eval(WAX.company_selected), function(key,value) {
			$('#invoicecompany_location').append('<option value="'+key.replace(/p/,'')+'">'+value+'</option>');
		});
		
		WAX.locationSelected();
		WAX.invoiceLocationSelected();
	},
	
	locationSelected : function() {
		WAX.location_selected = $("#location").val();
		$('#companyAddress').html(eval(WAX.location_selected));
	},
	
	invoiceLocationSelected : function () {
		WAX.invoicecompany_location_selected = $("#invoicecompany_location").val();
		$('#invoicecompanyAddress').html(eval(WAX.invoicecompany_location_selected));
	},
		
	initSelectBoxes : function(objData) {
	
		if(objData.company_selected!=null)	{
			
			WAX.company_selected = objData.company_selected;
			WAX.location_selected = objData.location_selected;
			WAX.invoicecompany_location_selected = objData.invoicecompany_location_selected;
			
			$("#company").val(WAX.company_selected);
			WAX.companySelected();
			$("#location").val(objData.location_selected);
			WAX.locationSelected();
			$("#invoicecompany_location").val(objData.invoicecompany_location_selected);
			WAX.invoiceLocationSelected();
		}

		$("#company").bind('change',function (){
			WAX.company_selected = $("#company").val();
			WAX.companySelected();
			WAX.invoiceLocationSelected();
		});
		
		$("#location").bind('change',function (){
			WAX.locationSelected();
		});

		$("#invoicecompany_location").bind('change',function (){
			WAX.invoiceLocationSelected();
		});
	}
}

