﻿// Internet Explorer 6 or 7 ?
var ie  = ($.browser.msie); 
var ie6 = ($.browser.msie && $.browser.version < 7 ) ? true : false;
var ie7 = ($.browser.msie && $.browser.version == 7 ) ? true : false;


/* FORM VALIDATION */
function validateRegisterForm(source, arguments) {	
	// reset previous validation
	var error = false;
	hideErrors("ctl00_placeholderContent_lblErrorRegisterForm");
	hideErrors("ctl00_placeholderContent_lblErrorConditionsRegisterForm");
	
	// validate fields
	if((trim($('#ctl00_placeholderContent_txtFirstname').val()) == "") || ($('#ctl00_placeholderContent_txtFirstname').val() == $('#ctl00_placeholderContent_txtFirstname').attr('title'))) 
	  error = showError("ctl00_placeholderContent_lblErrorRegisterForm","ctl00_placeholderContent_txtFirstname");
	  
	if((trim($('#ctl00_placeholderContent_txtName').val()) == "") || ($('#ctl00_placeholderContent_txtName').val() == $('#ctl00_placeholderContent_txtName').attr('title'))) 
	  error = showError("ctl00_placeholderContent_lblErrorRegisterForm","ctl00_placeholderContent_txtName");
	  
	if(!$('#ctl00_placeholderContent_listGender_0').attr('checked') && !$('#ctl00_placeholderContent_listGender_1').attr('checked')) {
    error = showError("ctl00_placeholderContent_lblErrorRegisterForm","ctl00_placeholderContent_listGender_0");
    error = showError("ctl00_placeholderContent_lblErrorRegisterForm","ctl00_placeholderContent_listGender_1");
	}
	  
	if(!isEmail($('#ctl00_placeholderContent_txtEmail').val())) 
	  error = showError("ctl00_placeholderContent_lblErrorRegisterForm","ctl00_placeholderContent_txtEmail");
	  
	if($('#ctl00_placeholderContent_txtEmailConfirm').val() != $('#ctl00_placeholderContent_txtEmail').val()) 
	  error = showError("ctl00_placeholderContent_lblErrorRegisterForm","ctl00_placeholderContent_txtEmailConfirm");
	  
	if((trim($('#ctl00_placeholderContent_txtCardnumber').val()) == "") || ($('#ctl00_placeholderContent_txtCardnumber').val() == $('#ctl00_placeholderContent_txtCardnumber').attr('title')))  
	  error = showError("ctl00_placeholderContent_lblErrorRegisterForm","ctl00_placeholderContent_txtCardnumber");
	  
	if(!$('#ctl00_placeholderContent_checkTerms').attr('checked')) {
	  if(error) {
	    error = showError("ctl00_placeholderContent_lblErrorRegisterForm","ctl00_placeholderContent_checkTerms");
	  } else {
	    error = showError("ctl00_placeholderContent_lblErrorConditionsRegisterForm","ctl00_placeholderContent_checkTerms");
	  }
	}
	
  if(error) {
      arguments.IsValid = false;
  }
}



function validateRegisterFormQuestions(source, arguments) {	
	// reset previous validation
	var error = false;
	hideErrors("ctl00_placeholderContent_lblErrorRegisterFormQuest");
	
	// validate fields
	/*if((trim($('#ctl00_placeholderContent_txtKeerTanken').val()) == "") || ($('#ctl00_placeholderContent_txtKeerTanken').val() == $('#ctl00_placeholderContent_txtKeerTanken').attr('title'))) 
	  error = showError("ctl00_placeholderContent_lblErrorRegisterFormQuest","ctl00_placeholderContent_txtKeerTanken");
	  
	if((trim($('#ctl00_placeholderContent_txtKmRijd').val()) == "") || ($('#ctl00_placeholderContent_txtKmRijd').val() == $('#ctl00_placeholderContent_txtKmRijd').attr('title'))) 
	  error = showError("ctl00_placeholderContent_lblErrorRegisterFormQuest","ctl00_placeholderContent_txtKmRijd");
	  
	  
	if(!isGetal($('#ctl00_placeholderContent_txtKeerTanken').val())) 
	  error = showError("ctl00_placeholderContent_lblErrorRegisterFormQuest","ctl00_placeholderContent_txtKeerTanken");
	  
	  
	  if(!isGetal($('#ctl00_placeholderContent_txtKmRijd').val())) 
	  error = showError("ctl00_placeholderContent_lblErrorRegisterFormQuest","ctl00_placeholderContent_txtKmRijd");
	*/
	  
	if(trim($('#ctl00_placeholderContent_ddlFuel').val()) == "1") 
	  error = showError("ctl00_placeholderContent_lblErrorRegisterFormQuest","ctl00_placeholderContent_ddlFuel");
	if(trim($('#ctl00_placeholderContent_ddlKm').val()) == "1") 
	  error = showError("ctl00_placeholderContent_lblErrorRegisterFormQuest","ctl00_placeholderContent_ddlKm");
	
  if(error) {
      arguments.IsValid = false;
  }
}



function validateGlobalRegisterForm(source, arguments) {	
	// reset previous validation
	var error = false;
	hideErrors("ctl00_lblErrorRegisterForm");
	hideErrors("ctl00_lblErrorConditionsRegisterForm");
	
	// validate fields
	if((trim($('#ctl00_txtFirstname').val()) == "") || ($('#ctl00_txtFirstname').val() == $('#ctl00_txtFirstname').attr('title'))) 
	  error = showError("ctl00_lblErrorRegisterForm","ctl00_txtFirstname");
	  
	if((trim($('#ctl00_txtName').val()) == "") || ($('#ctl00_txtName').val() == $('#ctl00_txtName').attr('title'))) 
	  error = showError("ctl00_lblErrorRegisterForm","ctl00_txtName");
	  
	if(!$('#ctl00_listGender_0').attr('checked') && !$('#ctl00_listGender_1').attr('checked')) {
    error = showError("ctl00_lblErrorRegisterForm","ctl00_listGender_0");
    error = showError("ctl00_lblErrorRegisterForm","ctl00_listGender_1");
	}
	  
	if(!isEmail($('#ctl00_txtEmail').val())) 
	  error = showError("ctl00_lblErrorRegisterForm","ctl00_txtEmail");
	  
	if($('#ctl00_txtEmailConfirm').val() != $('#ctl00_txtEmail').val()) 
	  error = showError("ctl00_lblErrorRegisterForm","ctl00_txtEmailConfirm");
	  
	if((trim($('#ctl00_txtCardnumber').val()) == "") || ($('#ctl00_txtCardnumber').val() == $('#ctl00_txtCardnumber').attr('title')))  
	  error = showError("ctl00_lblErrorRegisterForm","ctl00_txtCardnumber");
	    
  if(!$('#ctl00_checkTerms').attr('checked')) {
	  if(error) {
	    error = showError("ctl00_lblErrorRegisterForm","ctl00_checkTerms");
	  } else {
	    error = showError("ctl00_lblErrorConditionsRegisterForm","ctl00_checkTerms");
	  }
	}
	
  if(error) {
      arguments.IsValid = false;
  }
}

function validateContactForm(source, arguments) {	
	// reset previous validation
	var error = false;
	hideErrors("ctl00_placeholderContent_lblErrorContactForm");
	
	// validate fields
	if((trim($('#ctl00_placeholderContent_txtFirstname').val()) == "") || ($('#ctl00_placeholderContent_txtFirstname').val() == $('#ctl00_placeholderContent_txtFirstname').attr('title'))) 
	  error = showError("ctl00_placeholderContent_lblErrorContactForm","ctl00_placeholderContent_txtFirstname");
	  
	  if((trim($('#ctl00_placeholderContent_txtName').val()) == "") || ($('#ctl00_placeholderContent_txtName').val() == $('#ctl00_placeholderContent_txtName').attr('title'))) 
	  error = showError("ctl00_placeholderContent_lblErrorContactForm","ctl00_placeholderContent_txtName");
	  
	  if((trim($('#ctl00_placeholderContent_txtCardnumber').val()) == "") || ($('#ctl00_placeholderContent_txtCardnumber').val() == $('#ctl00_placeholderContent_txtCardnumber').attr('title'))) 
	  error = showError("ctl00_placeholderContent_lblErrorContactForm","ctl00_placeholderContent_txtCardnumber");
	  
	 if(!isEmail($('#ctl00_placeholderContent_txtEmail').val())) 
	  error = showError("ctl00_lblErrorRegisterForm","ctl00_placeholderContent_txtEmail");

	  if((trim($('#ctl00_placeholderContent_txtPhone').val()) == "") || ($('#ctl00_placeholderContent_txtPhone').val() == $('#ctl00_placeholderContent_txtPhone').attr('title'))) 
	  error = showError("ctl00_placeholderContent_lblErrorContactForm","ctl00_placeholderContent_txtPhone");
	    
	  if(trim($('#ctl00_placeholderContent_ddlTopics').val()) == "1") 
	  error = showError("ctl00_placeholderContent_lblErrorContactForm","ctl00_placeholderContent_ddlTopics");
	  
	  if((trim($('#ctl00_placeholderContent_txtMessage').val()) == "") || ($('#ctl00_placeholderContent_txtMessage').val() == $('#ctl00_placeholderContent_txtMessage').attr('title'))) 
	  error = showError("ctl00_placeholderContent_lblErrorContactForm","ctl00_placeholderContent_txtMessage");
	  
	  if(($('#ctl00_placeholderContent_txtPostcode').val() != $('#ctl00_placeholderContent_txtPostcode').attr('title'))) {
	    if(!isPostcode($('#ctl00_placeholderContent_txtPostcode').val()) || (trim($('#ctl00_placeholderContent_txtPostcode').val()) == "")) {
	    	  error = showError("ctl00_placeholderContent_lblErrorContactForm","ctl00_placeholderContent_txtPostcode");
	    }
	  } 
	
  if(error) {
      arguments.IsValid = false;
  }
}

function validateLoginForm(source, arguments) {	
	// reset previous validation
	var error = false;
	hideErrors("ctl00_lblErrorLoginForm");
	
	// validate fields  
	if(!isEmail($('#ctl00_txtEmailLogin').val())) 
	  error = showError("ctl00_lblErrorLoginForm","ctl00_txtEmailLogin");
	   
	if((trim($('#ctl00_txtCardnumberLogin').val()) == "")) 
	  error = showError("ctl00_lblErrorLoginForm","ctl00_txtCardnumberLogin");
	  	
  if(error) {
      arguments.IsValid = false;
  }
}

function validateGlobalStafForm(source, arguments) {	
	// reset previous validation
	var error = false;
	hideErrors("ctl00_lblErrorStafForm");
	
	// validate fields  
	if(isEmail($('#ctl00_txtEmailStaf1').val()))  {
	  //check first friend name
	  if((trim($('#ctl00_txtFirstnameStaf1').val()) == "") || ($('#ctl00_txtFirstnameStaf1').val() == $('#ctl00_txtFirstnameStaf1').attr('title')))
	  error = showError("ctl00_lblErrorStafForm","ctl00_txtFirstnameStaf1");
	}
	
	if((trim($('#ctl00_txtFirstnameStaf1').val()) != "") && ($('#ctl00_txtFirstnameStaf1').val() != $('#ctl00_txtFirstnameStaf1').attr('title'))) {
	  //check first friend mail
	  if(!isEmail($('#ctl00_txtEmailStaf1').val())) 
	  error = showError("ctl00_lblErrorStafForm","ctl00_txtEmailStaf1");
	}
	
	if(isEmail($('#ctl00_txtEmailStaf2').val()))  {
	  //check second friend name
	  if((trim($('#ctl00_txtFirstnameStaf2').val()) == "") || ($('#ctl00_txtFirstnameStaf2').val() == $('#ctl00_txtFirstnameStaf2').attr('title')))
	  error = showError("ctl00_lblErrorStafForm","ctl00_txtFirstnameStaf2");
	}
	
	if((trim($('#ctl00_txtFirstnameStaf2').val()) != "") && ($('#ctl00_txtFirstnameStaf2').val() != $('#ctl00_txtFirstnameStaf2').attr('title'))) {
	  //check second friend mail
	  if(!isEmail($('#ctl00_txtEmailStaf2').val())) 
	  error = showError("ctl00_lblErrorStafForm","ctl00_txtEmailStaf2");
	}
	
	if(!error) {
	  if(((trim($('#ctl00_txtFirstnameStaf1').val()) == "") || ($('#ctl00_txtFirstnameStaf1').val() == $('#ctl00_txtFirstnameStaf1').attr('title'))) && ((trim($('#ctl00_txtFirstnameStaf2').val()) == "") || ($('#ctl00_txtFirstnameStaf2').val() == $('#ctl00_txtFirstnameStaf2').attr('title')))) {
	    error = true; 
	  } 
	}
	  	
  if(error) {
      arguments.IsValid = false;
  }
}

/* GENERAL FUNCTIONS */
function showError(label, field) {
	$('#' + label).show();
	$('#' + field + ', label[for="' + field + '"]').addClass('error');
	return true;
}

function hideErrors(label) {
	$('#' + label).hide();
	$('input, select, textarea, label').removeClass('error');
}

function isEmail(v) {
	return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(v);
}

function isPostcode(v) {
	return /^[0-9]{4}$/.test(v);
}

function isGetal(v) {
      return !(/\D/.test(v));
}

function hideValue(id,text) {
  if($('#'+id).val() == text) $('#'+id).val("");
}

function trim(v) {
      return v.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}

/* SHOW/HIDE LOGIN & REGISTRATION FORM, STAF & INFO */
function showRegistration() {
  $('.loginForm').hide();
  $('.loginForm2').hide();
  $('.registrationForm').show();
	hideErrors("ctl00_lblErrorRegisterForm");
}

function showLogin() {
  $('.loginForm').show();
  $('.registrationForm').hide();
  hideErrors("ctl00_lblErrorLoginForm");
}

function showLogin2() {
  $('.loginForm2').show();
  $('.registrationForm').hide();
  hideErrors("ctl00_lblErrorLoginForm");
}

function showInfoCardnumber() {
  $('#infoCardnumber').show();
  $('#errorInfo').hide();
}

function showStaf() {
  $('.stafForm').show();
  $('.stafFormTnx').hide();
  hideErrors("ctl00_lblErrorStafForm");
  $('#ctl00_txtFirstnameStaf1').val( $('#ctl00_txtFirstnameStaf1').attr('title'));
  $('#ctl00_txtEmailStaf1').val( $('#ctl00_txtEmailStaf1').attr('title'));
  $('#ctl00_txtFirstnameStaf2').val( $('#ctl00_txtFirstnameStaf2').attr('title'));
  $('#ctl00_txtEmailStaf2').val( $('#ctl00_txtEmailStaf2').attr('title'));
}

/* 
    CLEAR FIELD ON FOCUS 
    Used in integrated site, to clear search field on focus
		For input text where the field label is displayed as initial value of the field 
		when the field is cleared, the initial value - stored in title attribute - is displayed 
*/

$(document).ready(function () {

    //png fix
    //$(document).pngFix();
    
		// Focus fields
		$('.focusField').clearFieldOnFocus();
		
		//faq settings
		$("#accordionFaq").accordion({ autoHeight: false, collapsible: true , active: false }); 
		
	  $('.subtitleFaq').click(function () {
	        
	        hideErrors("ctl00_placeholderContent_lblErrorRegisterFormQuest");
	        
	        
	    var tempbool = $(this).find('a').hasClass("btn_open");
	    $('.subtitleFaq a').addClass("btn_open");
		     
	        if (tempbool)
	        {
	            $(this).find('a').addClass("btn_close").removeClass("btn_open");
	        }
	        else
	        {
	            $(this).find('a').addClass("btn_open").removeClass("btn_close");
	        }
	        $('#containerFaq').jScrollPane();
		 // $(this).find('a').removeClass("btn_open").addClass("btn_close");
	  });

	  //$(function(){
			
		  $('#containerFaq').jScrollPane();
		
			$('#accordionFaq div').click(function() {
				 setTimeout(function() { $('#containerFaq').jScrollPane(); }, 500);
			});
			
		
	  //});
	  
	  //slider gallery
	  $("#slider").easySlider();
	  $(".popup_top").hide();
	  
	  //$(".open").click(function () {
  	//	 $(this).find(".popup_top").toggle("slow");
      // });
       
       $(".ope").click(function () {
          $(".popup_top").hide();
  		    // katrien $(this).parent().find(".popup_top").show("slow");
					var fx = (ie)?'':'slow';
					$(this).parent().find(".popup_top").show(fx);
       });
       
      /* 
	    $(".close").click(function () {
	     $(".popup_top").hide("slow");
  		 //$(this).find(".popup_top").toggle("slow");
      });
			*/
	    $(".popup_top").click(function () {
	     // katrien $(".popup_top").hide("slow");
			 var fx = (ie)?'':'slow';
			 $(".popup_top").hide(fx);
  		 //$(this).find(".popup_top").toggle("slow");
      });
      
       $("#volgendeBtn").click(function () {
            $(".popup_top").hide();
       });
       
       $("#vorigeBtn").click(function () {
            $(".popup_top").hide();
       });
      
      
    //login popup
    $(".closeLogin").click(function () {
		  $(".loginForm").hide(10);
    });
    
    //login popup 2
    $(".closeLogin2").click(function () {
		  $(".loginForm2").hide(10);
    });
    
    //registration popup
    $(".closeRegistration").click(function () {
		  $(".registrationForm").hide(10);
    });		

    //staf popup
    $(".closeStaf").click(function () {
		  $(".stafForm").hide(10);
    });	
    
    //extra info popup
    $("#closeInfo").click(function () {
		  $("#errorInfo").hide(10);
    });
    
    $("#closeInfoCardnumber").click(function () {
		  $("#infoCardnumber").hide(10);
    });		
});

(function($){
	jQuery.fn.clearFieldOnFocus = function() {
		return this.each(function() {
			$(this).focus(function() { if($(this).attr('value') == $(this).attr('title')) $(this).attr('value', ''); });
			$(this).blur(function() { if($(this).attr('value') == '') $(this).attr('value', $(this).attr('title')); });
		});
	};
})(jQuery);