window.onload = function() {
	hide_form();
	document.getElementById("select_input2").value = "0";
	document.getElementById("formcontact_utilisateur_nom").value = "";
	document.getElementById("formcontact_utilisateur_prenom").value = "";
	document.getElementById("formcontact_utilisateur_email").value = "";
	//document.getElementById("select_input3").value = "70";
	document.getElementById("formcontact_utilisateur_telephone").value = "";
	//document.getElementById("formcontact_utilisateur_adresse").value = "";
	document.getElementById("formcontact_utilisateur_codepostal").value = "";
	document.getElementById("formcontact_utilisateur_ville").value = "";
}

var validation = false;

function GetMiddleWindowHeight(h) {
	var windowHeight;
	if (self.innerHeight) {// all except Explorer
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowHeight = document.body.clientHeight;
	}
	windowHeight = (windowHeight/2) - (h/2);
return windowHeight;
}

function show_form(){
	hide_form();
	document.getElementById("form_layer").className = "";
	document.getElementById("content_layer").className = "";
	document.getElementById("form_layer").style.top = GetMiddleWindowHeight(410)+"px";
	document.getElementById("valider_rdv_ajax").innerHTML = "<input type='submit' class='bt_valider' name='valider_rdv' id='valider_rdv' value=''/>";
	
	document.getElementById('dimmer').style.visibility = "visible";
		
	//désactiver le filtre de #global
	document.getElementById('global').style.zIndex = "0";
	document.getElementById('global').style.position = "static";
	
	xt_med('F','11','FORMULAIRE::FINANCEMENT_CAPACITE_EMPRUNT');
	hideFlash();
}

function show_form_confirmation(){
	hide_form();
	document.getElementById("form_layer").className = "";
	document.getElementById("confirmation_layer").className = "";
	
	document.getElementById('dimmer').style.visibility = "visible";
		
	//désactiver le filtre de #global
	document.getElementById('global').style.zIndex = "0";
	document.getElementById('global').style.position = "static";
	hideFlash();
	document.getElementById('ajax_conv_adwords').innerHTML = '<img height="1" width="1" border="0" src="http://www.googleadservices.com/pagead/conversion/1038620162/?label=yE6xCIamYRCCrKDvAw"/><div style="display:inline;"><img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/1023162362/?label=qgiVCNrStwEQ-u_w5wM"/></div>';	
}

function hide_form(){
	document.getElementById("form_layer").className = "invisible";
	document.getElementById("content_layer").className = "invisible";
	
	document.getElementById('dimmer').style.visibility = "hidden";
		
	//réactiver le filtre de #global
	document.getElementById('global').style.zIndex = "10";
	document.getElementById('global').style.position = "relative";
	showFlash();
}

function go_simulation(xt_med) {
	if (validation == true) {
		show_form_confirmation();
	} else {
		show_form();
	}
}

function pop_up(url) {
	window.open(url,"_blank");
}

// Déclaration de la fonction de Callback
var callback = function(obj) {
	pop_up("http://www.solutionscles.com/credit/outils/emprunt.html?xtor=AL-2");
	show_form_confirmation();
}

function valid_form(url_loaded_file) {
	// Création de l'objet
	var XHR = new XHRConnection();
	
	var _form_err;
		
	_form_err = "";
	
	if(document.getElementById("img_utilisateur_nom").src.indexOf("form_valide") < 0 && document.getElementById("formcontact_utilisateur_nom").value.length > 1){
		check_form_alpha('utilisateur_nom');
		check_form_alpha('utilisateur_prenom');
		check_form_telephone('utilisateur_telephone');
		check_form_alpha_num('utilisateur_adresse');
		check_form_email('utilisateur_email');
		check_form_alpha_num('utilisateur_codepostal');
		check_form_alpha('utilisateur_ville');
	}

	if(document.getElementById("img_utilisateur_prenom").src.indexOf("form_valide") < 0){
		_form_err += "- Prénom invalide\n";
	}
	if(document.getElementById("img_utilisateur_email").src.indexOf("form_valide") < 0){
		_form_err += "- Email invalide\n";
	}
	if(document.getElementById("img_utilisateur_telephone").src.indexOf("form_valide") < 0){
		_form_err += "- Téléphone invalide\n";
	}
	/*
	if(document.getElementById("img_utilisateur_adresse").src.indexOf("form_valide") < 0){
		_form_err += "- Adresse invalide\n";
	}
	*/
	if(document.getElementById("img_utilisateur_codepostal").src.indexOf("form_valide") < 0){
		_form_err += "- Code postal invalide\n";
	}
	if(document.getElementById("img_utilisateur_ville").src.indexOf("form_valide") < 0){
		_form_err += "- Ville invalide\n";
	}
	
	if(_form_err != ""){
		alert("Un ou plusieurs champs génèrent une erreurs :\n\n" + _form_err);
		
		validation = false;
	} else {
		validation = true;
		
		document.getElementById("valider_rdv_ajax").innerHTML = "<img src='/skins/fr/img/commun/form-ajax-loader.gif' alt='Vérification des données' />";
		
		// Données à transmettre
		XHR.appendData('formcontact_utilisateur_civilite', document.getElementById("select_input2").value);
		XHR.appendData('formcontact_utilisateur_nom', document.getElementById("formcontact_utilisateur_nom").value);
		XHR.appendData('formcontact_utilisateur_prenom', document.getElementById("formcontact_utilisateur_prenom").value);
		XHR.appendData('formcontact_utilisateur_email', document.getElementById("formcontact_utilisateur_email").value);
		//XHR.appendData('formcontact_pay_id', document.getElementById("select_input3").value);
		XHR.appendData('formcontact_utilisateur_telephone', document.getElementById("formcontact_utilisateur_telephone").value);
		//XHR.appendData('formcontact_utilisateur_adresse', document.getElementById("formcontact_utilisateur_adresse").value);
		XHR.appendData('formcontact_utilisateur_codepostal', document.getElementById("formcontact_utilisateur_codepostal").value);
		XHR.appendData('formcontact_utilisateur_ville', document.getElementById("formcontact_utilisateur_ville").value);
		
		XHR.appendData('form_scrash_objet', 'speed_calc');
		
		if( (document.getElementById("formcontact_optin_partenaire1").checked == true)) {
			XHR.appendData('formcontact_optin_partenaire', 'oui');
		} else {
			XHR.appendData('formcontact_optin_partenaire', 'non');
		}
		XHR.appendData('formcontact_priorite', 1);
		
		// On soumet la requête
		// Signification des paramères:			
		// 	+ On indique à l'objet qu'il faut appeler le fichier fwrite.php
		// 	+ On utilise la méthode POST, adaptée l'envoi d'information
		// 	+ On indique quelle fonction appeler lorsque l'opération a été effectuée
		XHR.sendAndLoad(url_loaded_file, "POST", callback);
		
		var microtime = new Date();
		microtime = microtime.getTime();
		microtime = String(microtime).substr(2,9);
		prg_id_fil_id = url_loaded_file.substr(23,5);
		xt_med('F','11','CONFIRMATION::FINANCEMENT_CAPACITE_EMPRUNT&roimt=1&cmd='+microtime+'&x4='+document.getElementById("formcontact_utilisateur_telephone").value+'&x6='+document.getElementById("formcontact_utilisateur_codepostal").value+'&x7='+prg_id_fil_id+'&x11=FINANCEMENT_CAPACITE_EMPRUNT&x12='+document.getElementById("formcontact_utilisateur_email").value+'&x13='+microtime);
		
		return false;
	}
	
	return false;
}

