//FONCTION PERMETTANT DE REDIMENSIONNER DEUX BLOCS
function ResizeColonne(idGauche, idDroite, plus_gauche, plus_droite){
	// HEIGHT
	var height_gauche 			= $("#" + idGauche).height();
	var height_droite 			= $("#" + idDroite).height();
	
	// Taille complète gauche
	if (plus_gauche != ""){
		height_gauche= height_gauche + parseInt(plus_gauche);
	}else{
		plus_gauche = 0
	}

	// Taille complète droite
	if (plus_droite != ""){
		height_droite= height_droite + parseInt(plus_droite);
	}else{
		plus_droite =0;
	}
				
	// comparaison des tailles
	if(height_gauche > height_droite){ // Le bloc de gauche est plus grand
		$("#" + idDroite).height(height_gauche - parseInt(plus_droite));
	}else{
		$("#" + idGauche).height(height_droite - parseInt(plus_gauche));
	}
}


function tb_show_mask(){
	if(document.getElementById("TB_window"))
	{
		document.getElementById("TB_window").style.display = "none";
	}
	if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
		$("body","html").css({height: "100%", width: "100%"});
		$("html").css("overflow","hidden");
		if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
			$("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
		}
	}else{//all others
		if(document.getElementById("TB_overlay") === null){
			$("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
		}
	}
	
	if(tb_detectMacXFF()){
		$("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
	}else{
		$("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
	}


	$("body").append("<div id='TB_load'><img src='"+ pathRacine +"_images/loading_sofath.gif' /></div>");//add loader to the page
	$('#TB_load').show();//show loader
	
}

function getExpression(lg, marqueur)
{
	$.ajax({
		type: "POST",   
		url: pathRacine + "_ajax/get_expression.asp",        
		data: "lang="+ lg +"&marqueur="+ marqueur,
		success: function(msg){   
			alert(msg);
		},
		error:function(msg){       
			alert(msg.ResponseText);
		}
	}); 	
}


function trim(string){
	return string.replace(/(^\s*)|(\s*$)/g,'');
} 

function isMailValid(email){
	 var verif = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9_.-]{2,}[.][a-zA-Z]{2,3}$/;
	 if (verif.exec(email) == null)
		return false; //mail incorrect
	 else
		return true; //mail correct
} 

function SubmitFormContact(){
	document.getElementById("form-contact").submit();
}

function ValidationContact(form){
	
	if(form.nom.value == ""){
		getExpression(codeLangue, "alert-nom");
		form.nom.focus();
		return false;
	}
	if(form.prenom.value == ""){
		getExpression(codeLangue, "alert-prenom");
		form.prenom.focus();
		return false;
	}
	if(!isMailValid(form.email.value)){
		getExpression(codeLangue, "alert-email");
		form.email.focus();
		return false;
	}
	if(form.adresse_projet.value == ""){
		getExpression(codeLangue, "alert-adresse_projet");
		form.adresse_projet.focus();
		return false;
	}
	if(form.projet.value == ""){
		getExpression(codeLangue, "alert-projet");
		form.projet.focus();
		return false;
	}
	if(form.adresse.value == ""){
		getExpression(codeLangue, "alert-adresse");
		form.adresse.focus();
		return false;
	}
	if(form.codepostal.value == ""){
		getExpression(codeLangue, "alert-codepostal");
		form.codepostal.focus();
		return false;
	}
	if(form.ville.value == ""){
		getExpression(codeLangue, "alert-ville");
		form.ville.focus();
		return false;
	}
	if(form.pays.value == ""){
		getExpression(codeLangue, "alert-pays");
		form.pays.focus();
		return false;
	}
	
	return true;
} 



function getQueryVariable(variable) {
	var find = false;
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
  
  if (find==false){
	return "";
  }
}
function popupPartage(sType){
	urlPage = "";
	switch (sType) {
		case 'Twitter':
			urlPage = "http://www.twitter.com/home?status=" + document.location.href;
			break;
		case 'Google':
			urlPage = "http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=" + document.location.href + "&amp;title=";
			break;
		case 'Facebook':
			urlPage = "http://www.facebook.com/sharer.php?u=" + document.location.href;
			break;
		case 'Yahoo':
			urlPage = "https://login.yahoo.com/config/login?.src=bmk2&amp;.intl=us&amp;.done=http://us.bookmarks.yahoo.com/admin/savebm%3FadminAction%3DAdd%26amp;selectall%3Don%26amp;url%3D" + document.location.href;
			break;
		case 'Myspace':
			urlPage = "http://www.myspace.com/index.cfm?fuseaction=postto&amp;u=" + document.location.href + "&amp;t=";
			break;
		case 'Delicious':
			urlPage = "http://del.icio.us/post?url=" + document.location.href;
			break;
		case 'Friendfeed':
			urlPage = "https://friendfeed.com/account/login?next=/%3Furl%3D" + document.location.href;
			break;
		case 'Digg':
			urlPage = "http://digg.com/submit?url=" + document.location.href;
			break;
	}

	if (urlPage != ""){
		window.open(urlPage);
	}
}

function Envoyer(){
	tb_show("", pathRacine + "_ajax/send_friend.asp?height=140&width=350&modal=true&action=demand&lng=" + codeLangue, false);
}

function EnvoyerPage(){
		$("#message_send_mail").hide()
		$("#send_email").css("border-color", "#CECECE");
		$("#message_send_mail_nom").hide()
		$("#send_email_nom").css("border-color", "#CECECE");

	if ($("#send_email_nom").val() !=""){
		if (($("#send_email").val() !="") && (isMailValid($("#send_email").val()))){
		
			$("#formulaire_envoie").hide()
			$.ajax({
				type: "POST",   
				url: pathRacine + "_ajax/send_friend.asp?action=send&lng=" + codeLangue,        
				data: "email="+ $("#send_email").val() + "&nom=" + $("#send_email_nom").val(),
				success: function(msg){
					if(msg=="ok"){
						$("#confirmation_formulaire_envoie").show()
					}
				},
				error:function(msg){       
					alert(msg.ResponseText);
				}
			});
		}else{
			$("#message_send_mail").show()
			$("#send_email").css("border-color", "red");
			$("#send_email").focus();		
		}
	}else{
		$("#message_send_mail_nom").show()
		$("#send_email_nom").css("border-color", "red");
		$("#send_email_nom").focus();		
	}

}

function Partager(){
	$(".bloc_partage").slideDown();
}

function FermerPartage(){
	$(".bloc_partage").slideUp();
}

function Imprimer(){
	window.open(pathRacine + "datasheets/" + dossierParent + "/" + codePage + ".pdf");
}

function Telecharger(){
	window.open(pathRacine + "_ajax/send_pdf.asp?action=send&codepage=" + codePage + "&dossierParent=" + dossierParent);
}

function Imprimer_Concessionnaire(){
	window.open( "../datasheets/" + codePage + ".pdf");
}

function Telecharger_Concessionnaire(sdossier){
	window.open(pathRacine + "_ajax/send_pdf.asp?action=send&codepage=" + codePage + "&sdossier=" +sdossier);
}

function ValidForm(){
	isValid = true;
	// nom
	if(isValid){
		if($("input[name='nom']").val() ==""){
			isValid = false;
			$("input[name='nom']").focus();
			alert($("input[name='form_nom']").val());
		}
	}
	// adresse
	if(isValid){
		if($("input[name='adresse']").val() ==""){
			isValid = false;
			$("input[name='adresse']").focus();
			alert($("input[name='form_adresse']").val());
		}
	}
	// ville
	if(isValid){
		if($("input[name='ville']").val() ==""){
			isValid = false;
			$("input[name='ville']").focus();
			alert($("input[name='form_ville']").val());
		}
	}
	// cp
	if(isValid){
		if($("input[name='cp']").val() ==""){
			isValid = false;
			$("input[name='cp']").focus();
			alert($("input[name='form_cp']").val());
		}
	}
	// pays
	if(isValid){
		if($("input[name='pays']").val() ==""){
			isValid = false;
			$("input[name='pays']").focus();
			alert($("input[name='form_pays']").val());
		}
	}
	// e-mail
	if(isValid){
		if($("input[name='email']").val() ==""){
			isValid = false;
			$("input[name='email']").focus();
			alert($("input[name='form_email']").val());
		}
	}
	if(isValid){
		$("#formulaire_contact").submit();
	}
}

function ValidFormPro(){
	isValid = true;
	// nom
	if(isValid){
		if($("input[name='nom']").val() ==""){
			isValid = false;
			$("input[name='nom']").focus();
			alert($("input[name='form_nom']").val());
		}
	}
	// prenom
	if(isValid){
		if($("input[name='prenom']").val() ==""){
			isValid = false;
			$("input[name='prenom']").focus();
			alert($("input[name='form_prenom']").val());
		}
	}
	// societe
	if(isValid){
		if($("input[name='societe']").val() ==""){
			isValid = false;
			$("input[name='societe']").focus();
			alert($("input[name='form_societe']").val());
		}
	}
	// adresse
	if(isValid){
		if($("input[name='adresse']").val() ==""){
			isValid = false;
			$("input[name='adresse']").focus();
			alert($("input[name='form_adresse']").val());
		}
	}
	// ville
	if(isValid){
		if($("input[name='ville']").val() ==""){
			isValid = false;
			$("input[name='ville']").focus();
			alert($("input[name='form_ville']").val());
		}
	}
	// cp
	if(isValid){
		if($("input[name='cp']").val() ==""){
			isValid = false;
			$("input[name='cp']").focus();
			alert($("input[name='form_cp']").val());
		}
	}
	// pays
	if(isValid){
		if($("input[name='pays']").val() ==""){
			isValid = false;
			$("input[name='pays']").focus();
			alert($("input[name='form_pays']").val());
		}
	}
	// tel
	if(isValid){
		if($("input[name='tel']").val() ==""){
			isValid = false;
			$("input[name='tel']").focus();
			alert($("input[name='form_tel']").val());
		}
	}
	// e-mail
	if(isValid){
		if($("input[name='email']").val() ==""){
			isValid = false;
			$("input[name='email']").focus();
			alert($("input[name='form_email']").val());
		}
	}
	// activite
	if(isValid){
		if($("select[name='activite']").val() ==""){
			isValid = false;
			$("select[name='activite']").focus();
			alert($("input[name='form_activite']").val());
		}
	}
	if(isValid){
		$("#formulaire_contact").submit();
	}
}

function ValidFormPostule(){
	isValid = true;
	// nom
	if(isValid){
		if($("input[name='nom']").val() ==""){
			isValid = false;
			$("input[name='nom']").focus();
			alert($("input[name='form_nom']").val());
		}
	}
	if(isValid){
		if($("input[name='prenom']").val() ==""){
			isValid = false;
			$("input[name='prenom']").focus();
			alert($("input[name='form_prenom']").val());
		}
	}
	if(isValid){
		if($("input[name='naissance']").val() ==""){
			isValid = false;
			$("input[name='naissance']").focus();
			alert($("input[name='form_naissance']").val());
		}
	}
	// adresse
	if(isValid){
		if($("input[name='adresse']").val() ==""){
			isValid = false;
			$("input[name='adresse']").focus();
			alert($("input[name='form_adresse']").val());
		}
	}
	// ville
	if(isValid){
		if($("input[name='ville']").val() ==""){
			isValid = false;
			$("input[name='ville']").focus();
			alert($("input[name='form_ville']").val());
		}
	}
	// cp
	if(isValid){
		if($("input[name='cp']").val() ==""){
			isValid = false;
			$("input[name='cp']").focus();
			alert($("input[name='form_cp']").val());
		}
	}
	// tel_perso
	if(isValid){
		if($("input[name='tel_perso']").val() ==""){
			isValid = false;
			$("input[name='tel_perso']").focus();
			alert($("input[name='form_tel_perso']").val());
		}
	}
	// secteur_souhaite
	if(isValid){
		if($("input[name='secteur_souhaite']").val() ==""){
			isValid = false;
			$("input[name='secteur_souhaite']").focus();
			alert($("input[name='form_activite']").val());
		}
	}
	// parcours_pro
	if(isValid){
		if($("textarea[name='parcours_pro']").val() ==""){
			isValid = false;
			$("textarea[name='parcours_pro']").focus();
			alert($("input[name='form_parcours_pro']").val());
		}
	}
	// formation
	if(isValid){
		if($("textarea[name='formation']").val() ==""){
			isValid = false;
			$("textarea[name='formation']").focus();
			alert($("input[name='form_formation']").val());
		}
	}
	// ambition
	if(isValid){
		if($("textarea[name='ambition']").val() ==""){
			isValid = false;
			$("textarea[name='ambition']").focus();
			alert($("input[name='form_ambition']").val());
		}
	}
	// ambition
	if(isValid){
		if($("select[name='connu_sofath']").val() ==""){
			isValid = false;
			$("select[name='connu_sofath']").focus();
			alert($("input[name='form_connu_sofath']").val());
		}
	}
	if(isValid){
		$("#formulaire_contact").submit();
	}
}
function ValidFormDevis(){
	isValid = true;
	// nom
	if(isValid){
		if($("input[name='nom']").val() ==""){
			isValid = false;
			$("input[name='nom']").focus();
			alert($("input[name='form_champs_obligatoire']").val());
		}
	}
	// e-mail
	if(isValid){
		if($("input[name='email']").val() ==""){
			isValid = false;
			$("input[name='email']").focus();
			alert($("input[name='form_champs_obligatoire']").val());
		}
	}
	// tel
	if(isValid){
		if($("input[name='tel']").val() ==""){
			isValid = false;
			$("input[name='tel']").focus();
			alert($("input[name='form_champs_obligatoire']").val());
		}
	}
	// cp
	if(isValid){
		if($("input[name='cp']").val() ==""){
			isValid = false;
			$("input[name='cp']").focus();
			alert($("input[name='form_champs_obligatoire']").val());
		}
	}	
	// pays
	if(isValid){
		if($("input[name='pays']").val() ==""){
			isValid = false;
			$("input[name='pays']").focus();
			alert($("input[name='form_champs_obligatoire']").val());
		}
	}
	// monprojet
	if(isValid){
		if($("select[name='monprojet']").val() ==""){
			isValid = false;
			$("select[name='monprojet']").focus();
			alert($("input[name='form_champs_obligatoire']").val());
		}
	}
	if(isValid){
		$("#formulaire_contact").submit();
	}
}


function OpenFaq(id,action){
	if (action == "open"){
		$("#theme" + id+"label").attr("href", "javascript:OpenFaq(" + id + ",'close' )");
		$("#theme" + id).html("<a href=\"javascript:OpenFaq(" + id + ",'close' )\"><img src='" + pathRacine + "_images/Picto-moins.png' height='20' width='20' alt='-' title='-' border='0' align='absmiddle' /></a>");
		$("#faqs" + id).show();
	}else{
		$("#theme" + id+"label").attr("href", "javascript:OpenFaq(" + id + ",'open' )");
		$("#theme" + id).html("<a href=\"javascript:OpenFaq(" + id + ",'open' )\"><img src='" + pathRacine + "_images/Picto-plus.png' height='20' width='20' alt='+' title='+' border='0' align='absmiddle' /></a>");
		$("#faqs" + id).hide();
	}
}


