var isIE6 = $.browser.msie && $.browser.version == "6.0";

/* apply behavior stylesheet */
$("head").append($("<link rel='stylesheet' type='text/css' href='/assets/css/behavior.css' media='screen'/>"));

$(function() {

    var chAppAanroep = "/asp/appmain.asp?appactie=";

	/* replace page headers with custom font */
	$("h1").sifr({
		path: "/assets/swf/",
		font: "nobellight"
	});

	/*
	 * Sift wordt nogmaals uitgevoerd, vertraagd,
	 * Thickbox laad eerst gehele pagina en toont 
	 * hem dan pas. Sifr gaat alleen af als hij
	 * visible op het scherm is, daarom vertraagd
	 * inladen. Wenselijk is om dit alleen in het
	 * geval van Thickbox te doen, verfijnen.
	 */
	setTimeout(doeDeSifr, 500);

	/* toggle faq answers */
	$("div#vragen li > a").click(function() {
		if (!$(this).next("div.antwoord").hasClass("open")) {
			$("div#faq div.antwoord.open").removeClass("open").slideUp();
			$(this).next("div.antwoord").addClass("open").slideDown();
		} else {
			$("div#vragen div.antwoord.open").removeClass("open").slideUp();
		}
		return false;
	});

	/* greybox */
	$("*.greybox").click(function() {
		var t = "&#160;";//this.title || $(this).text() || this.href;
		GB_show(t,this.href,615,715);
		return false;
	});
    
    /* login */
    $("#login").click(function() {
		fuSubmitForm(this.form, this, chAppAanroep + 'lg_login');
		return false
    })
    
    /* back */
    $("#form_aanmelden #terug").click(function() {
        location.href = chAppAanroep + 'lg_start';
    })
    
    /* verder */
    $("#form_aanmelden #verder").click(function() {
        fuSubmitForm(this.form, this, chAppAanroep + "eerste_aanmelding_post");
    })

/*BROCHURE*/	
	/* documentatie aanvraag - scherm 1 - verder */
	$("#form_documentatieaanvraag_selecteermodel #naarstap2").click(function() {
		fuSubmitForm(this.form, this, chAppAanroep + "brochure2");
	})
	
	/* documentatie aanvraag - scherm 2 - verder */
	$("#form_documentatieaanvraag_persoonlijkegegevens #naarstap3").click(function() {
		fuSubmitForm(this.form, this, chAppAanroep + "brochure3");
	})

	/* terug van brochure 2 naar 1 */
	$("#brochure2_brochure1_terug").click(function() {	
	    document.getElementById("form_documentatieaanvraag_persoonlijkegegevens").method = "post";
	    document.getElementById("form_documentatieaanvraag_persoonlijkegegevens").action = chAppAanroep + "brochure1";
	    document.getElementById("form_documentatieaanvraag_persoonlijkegegevens").submit();
	})


	/* terug van brochure 3 naar 2 */
	$("#brochure3_brochure2_terug").click(function() {	
	    document.getElementById("form_documentatieaanvraag_huidigeauto").method = "post";
	    document.getElementById("form_documentatieaanvraag_huidigeauto").action = chAppAanroep + "brochure2";
	    document.getElementById("form_documentatieaanvraag_huidigeauto").submit();
	})
	
	/* terug van brochure 3 naar 1 */
	$("#brochure3_brochure1_terug").click(function() {	
	    document.getElementById("form_documentatieaanvraag_huidigeauto").method = "post";
	    document.getElementById("form_documentatieaanvraag_huidigeauto").action = chAppAanroep + "brochure1";
	    document.getElementById("form_documentatieaanvraag_huidigeauto").submit();
	})
	
	/* brochure posten */
	$("#form_documentatieaanvraag_huidigeauto #verstuur").click(function() {	
	    // geen validaties meer, opsturen data.
		document.getElementById("form_documentatieaanvraag_huidigeauto").method = "post";
	    document.getElementById("form_documentatieaanvraag_huidigeauto").action = chAppAanroep + "brochure_post";
	    document.getElementById("form_documentatieaanvraag_huidigeauto").submit();
	})
	
/*PROEFRIT*/

	/* proefrit aanvraag - scherm 1 - verder */
	$("#form_proefrit_selecteermodel #naarstap2").click(function() {
		fuSubmitForm(this.form, this, chAppAanroep + "proefrit2");
	})	

	/* proefrit aanvraag - scherm 2 - verder */
	$("#form_proefrit_persoonlijkegegevens #naarstap3").click(function() {
		fuSubmitForm(this.form, this, chAppAanroep + "proefrit3");
	})

	/* proefrit aanvraag - scherm 3 - verder */
	$("#form_proefrit_huidigeauto #verstuur").click(function() {
		document.getElementById("form_proefrit_huidigeauto").method = "post";
	    document.getElementById("form_proefrit_huidigeauto").action = chAppAanroep + "proefrit_post";
	    document.getElementById("form_proefrit_huidigeauto").submit();
	})
	
	$("#proefrit2_proefrit1_terug").click(function() {
		document.getElementById("form_proefrit_persoonlijkegegevens").method = "post";
	    document.getElementById("form_proefrit_persoonlijkegegevens").action = chAppAanroep + "proefrit1";
	    document.getElementById("form_proefrit_persoonlijkegegevens").submit();
	})
	$("#proefrit3_proefrit1_terug").click(function() {
		document.getElementById("form_proefrit_huidigeauto").method = "post";
	    document.getElementById("form_proefrit_huidigeauto").action = chAppAanroep + "proefrit1";
	    document.getElementById("form_proefrit_huidigeauto").submit();
	})
	$("#proefrit3_proefrit2_terug").click(function() {
		document.getElementById("form_proefrit_huidigeauto").method = "post";
	    document.getElementById("form_proefrit_huidigeauto").action = chAppAanroep + "proefrit2";
	    document.getElementById("form_proefrit_huidigeauto").submit();;
	})



	/* contact - scherm 1 - verder */
	$("#form_contact_persoonlijkegegevens #naarstap2").click(function() {
		fuSubmitForm(this.form, this, chAppAanroep + "contact2");
	})	

		/* contact - scherm 2 - verder */
	$("#form_contact_uwopmerking #verzenden").click(function() {
		document.getElementById("form_contact_uwopmerking").method = "post";
	    document.getElementById("form_contact_uwopmerking").action = chAppAanroep + "contact_post";
	    document.getElementById("form_contact_uwopmerking").submit();
	})

    /* wachtwoord vergeten */        
	$("#form_wachtwoordvergeten #verzenden").click(function() {
		fuSubmitForm(this.form, this, chAppAanroep + "wachtwoord_vergeten_post");
	})
	$("#form_wachtwoordvergeten #ww_terug").click(function() {
		location.href = chAppAanroep + 'lg_start';
	})

	/* mijn gegevens */
	$("#form_mijngegevens #change_password").click(function() {
		fuSubmitForm(this.form, this, chAppAanroep + "wachtwoord_wijzigen");
	})
	$("#form_mijngegevens #change_data").click(function() {
		fuSubmitForm(this.form, this, chAppAanroep + "klantinformatie_wijzig");
	})	
	$("#form_mijngegevens_wijzigen #wijzigingen_opslaan").click(function() {
		fuSubmitForm(this.form, this, chAppAanroep + "klantinformatie_post");
	})
	$("#form_mijngegevens_wijzigen #annuleren").click(function() {
		location.href = chAppAanroep + 'klantinformatie_bekijk';
	})	
	$("#form_wachtwoord_wijzigen #wachtwoord_opslaan").click(function() {
		fuSubmitForm(this.form, this, chAppAanroep + "wachtwoord_wijzigen_post");
	})
	$("#form_wachtwoord_wijzigen #annuleren").click(function() {
		location.href = chAppAanroep + 'klantinformatie_bekijk';
	})		
	$("#form_wachtwoord_wijzigen #verder").click(function() {
		location.href = chAppAanroep + 'klantinformatie_bekijk';
	})		
	
	$("#form_aanmelden_gegevens #verder").click(function() {
		fuSubmitForm(this.form, this, chAppAanroep + "eerste_aanmelding_scherm2_post");
	})		
	$("#form_aanmelden_gegevens #annuleren").click(function() {
		fuSubmitForm(this.form, this, chAppAanroep + "lg_start");
	})		
	
	
	/*
	 * Cendris koppeling voor formulieren
	 */
	$("input#postcode, input#huisnummer_nummer").change(function(){
		var chPostcode = $("input#postcode").val();
		var chHuisnummer = $("input#huisnummer_nummer").val();
		if(chPostcode != '' && chHuisnummer != '' ) {
			$.get("/asp/appmain.asp", { 
				appactie: "strwpl", 
				postcode: chPostcode, 
				huisnr: chHuisnummer
				}, 
				function(data){
					var chWoonplaats = $(data).find("PSTC").attr("woonplaats");
					var chStraat     = $(data).find("PSTC").attr("straat");

					if(chWoonplaats == null)
					  chWoonplaats = "";
					if(chStraat == null)  
					  chStraat = "";
					
					$("input#woonplaats").val(chWoonplaats);
					$("input#straatnaam").val(chStraat);				
				}
			);					
		}
	});		
});


function doeDeSifr() {	
	$("h1").sifr({
		path: "/assets/swf/",
		font: "nobellight"
	});		
}








