//-changeClass
//-setImgSize
//-getElementsByClassName
//-bookmarksite



if (!window.console || !console.firebug)
{
    var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
    "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];

    window.console = {};
    for (var i = 0; i < names.length; ++i)
        window.console[names[i]] = function() {}
}

function toggleStep3Button() {
	if($('.--stap1 select').val() != 'Kies uit:' && $('#jobid').val() != '')
	{
		$('.naar_stap_3').removeClass("hidden")
		$('.naar_stap_3').fadeIn()
		
		$('#arrow_stap3').css('cursor', 'pointer')
		$('#arrow_stap3').unbind('click').bind('click', function(){
			$('form').submit();
			return false;
		})
	}
	else
	{
		$('.naar_stap_3').addClass("hidden")
		$('.naar_stap_3').fadeOut()
		
		$('#arrow_stap3').css('cursor', 'default')
		$('#arrow_stap3').unbind('click').bind('click', function(){
			return false;
		});
	
		
	}
}


function resetFrontForm() {
	// reset het hele formulier
	//$('#error_zip').css('display','block');
	$('#error_zip_mail').css('display','block');
	$('.stap_2.--stap2.right').addClass('inactive')
	
	// vinkjes aan de bovenkant
	$('.stap_check').find('.--big_tick').css('display', 'none');
	$('.stap_check .bg_dark_grey').css('background-color', '');
	
	// rechtervlak v formulier
	//$('.stap_2').css('display','none');
	// reset waarden + 'Naar stap 3' button
	$('#jobid').val('');
	$('.checklist ul li').removeClass("active");
	// toggleStep3Button();
	// reset jobtype
	$('#selectcategorie ul li').removeClass("active");
	$('#selectcategorie .jobtype_1').addClass("active");
	$('.focus').removeClass("focus");
	$('.stap_1').addClass("focus");
}

function toggleJob(job_id)
{
	if($("#jobid").val().search(job_id+";") < 0)
	{
		$("#jobid").val($("#jobid").val() + job_id + ";");
	}
	else
	{
		$("#jobid").val($("#jobid").val().replace(job_id + ";", ""));
	}
	
	if($("#jobid").val().length > 0)
	{
		tick = $('.--stappen_check .--stap2 .--animation').parents('.stap_check').find('.--big_tick')
		if(tick.css('display') == 'none'){
			tick.css('display','block');
			toggleStep3Button()
		}
	}
	else
	{
		var animation_overlay = $('.--stappen_check .--stap2 .--animation');
		var newbg = animation_overlay.css('backgroundColor')
		animation_overlay.animate({
			backgroundColor: newbg
		},'fast',function(){
			tick = $(this).parents('.stap_check').find('.--big_tick')
			if(tick.css('display') == 'block'){
				tick.css('display','none');
				toggleStep3Button();
			}
		});
	}
}

/* ONLOAD */
$(document).ready(function(){ 
	
	$(".testimonials").innerfade({ animationtype: 'fade', speed: 1000, timeout: 10000, type: 'sequence', containerheight: '1em' });
	
	$(document).pngFix();
	
	$('.confirm').click(function(event) {
    location.href = $(this).attr('href');
	}).confirm({
		msg:'Weet u zeker dat u wilt verwijderen?',
		timeout:5000,
		cls:'confirmbutton',
		wrapper: '<div class="confirmlink">',
		buttons: {
			ok:'Ja',
		    cancel:'Nee',
		    separator:'  '
		}
	});	
	
	$(document).ready(function(){ $('input[@type=text]').focus(function(){ if($(this).val() == $(this).attr('defaultValue')) { $(this).val(''); } }); $('input[@type=text]').blur(function(){ if($(this).val() == '') { $(this).val($(this).attr('defaultValue')); } }); });
	
	$(".flashmessages .btn_exit a").click(function() {
		$(".flashmessages").slideUp(250);
		$(".flashmessages").addClass("hiddenbox");
		return false;
	});
	
	$.timer(10000, function(timer) {
		if($(".flashmessages").hasClass("hiddenbox"))
			return false;			
		$(".flashmessages").slideUp(250);
		timer.stop();
	});
	
	$('#tabs_content > ul').tabs();
	
	$('.checkbox ul li a').click(function () {
		
		var parts = $(this).attr("id").split("_");
		
		console.log(parts);
		
		var job_id = parts[1];
		
		if($(this).parent().hasClass('active'))
		{
			$(this).parent().removeClass('active');
		}
		else
		{
			$(this).parent().addClass('active');
		}
		
		toggleJob(job_id)
		
		return false;
	});
	
	$('#arrow_stap5').click(function(){
		$('form').submit();
		return false;			
	});
	
	$('#miniloginForm input').keyup(function(event) {
		if (event.keyCode == 13) {
			$('#miniloginForm').submit();
		}
	});
	
	$('#minilogin #password').click(function(e){
		$('#minilogin #password').addClass('selected');
	});
	
	$('#minilogin #password').focus(function(e){
		$('#minilogin #password').addClass('selected');
	});
	
	$('#selectcategorie ul li a').click(function () {
		if ($('#selectcategorie ul li').hasClass('active')) {
			$('#selectcategorie ul li').removeClass('active');
		}
		
		if ($('#checkbox .checklist').hasClass('hidden')) {
			$('#checkbox .checklist').addClass('hidden');
		}
		
		$(this).parent().addClass('active');
			
		$('#checkbox_' + $(this).parent().attr('id')).removeClass('hidden');
		
		return false;
	});
	
	// Datepicker koppelen
	$('input.Mct_Form_Element_Date').each(function(){
		$(this).datePicker({startDate:'01/01/1900',createButton:true,clickInput:false});
	});
	
	// Terug naar stap 1 -->was nog niet nodig ...
	/*
	$('#back_to_1').click(function(){
		
		toggleStep3Button();
		
		$('.stap_2').fadeOut(
			function(){
				$('.stap_1').fadeIn();
			}
		);
		$('.stap3').addClass("hidden")
		$('.stap3').fadeOut()
		$('.big_tick').css('display','none');
		
	});
	*/
	
	// View specifiek             !!! currentView moet nog geset worden!!!
	if(currentView = 'index' || true){
		$('#region_id').change(function(){

			if($("#region_id").val().length > 0)
			{
				// Postcode is correct
				
				
				$('.stap_2.--stap2.right').removeClass('inactive');
				
				$('.stap_1').fadeOut(
					function(){
						$('.stap_2').fadeIn();
					}
				);
			
				$('#error_zip').css('display','none');
				$('#error_zip_mail').css('display','none');
				$('#areabox #zip').css( {'border':'1px solid #D6D6D6', 'color':'#474747'} );
				
 				tick = $('.--stappen_check .--stap1 .--grey').parents('.stap_check').find('.--big_tick')
				if(tick.css('display') == 'none') {
					tick.css('display','block');;
				}

				// reset jobtype
				/*
				$('#selectcategorie ul li').removeClass("active");
				$('#selectcategorie .jobtype_1').addClass("active");
				*/
				
				/* Stap 2 blauw maken */
				var animation_overlay = $('.--stappen_check .--stap2 .--animation');
				var newbg = animation_overlay.parents('.--blue').css('backgroundColor');
				animation_overlay.animate({ backgroundColor: newbg}, 'slow');
				
				
				/*
				$('.focus').removeClass("focus");
				$('.stap_2').addClass("focus");
				*/
			}
			else
			{
				// Postcode is incorrect
				resetFrontForm();
			}
		});
	}
	
});
