// JavaScript Document
var f;
var c;
var h;

function goProfil() {
	f = document.getElementById("personnes");
	f.value = 0;
	f.onchange = createBenef;
	f.current = 0;
	c = document.getElementById('beneficiaires');
}

/*
function ecrireInfo(o){
	h = document.getElementById("contNaissance");
	if ((o == "conjoint") || (o == "autre")) {
		h.innerHTML = "L'offre monchoix.sant&eacute; est propos&eacute;e aux personnes &acirc;g&eacute;es de 16 ans &agrave; 70 ans."
		}
	if (o == "enfant") {
		h.innerHTML = "Votre enfant est consid&eacute;r&eacute; comme b&eacute;n&eacute;ficiaire jusqu'&agrave; ses 25 ans. Au-del&agrave;, de ses 25 ans, il peut adh&eacute;rer &agrave; titre individuel."
		}
}
*/

function createBenef(){
	
	if (f.value == 0) {
		document.getElementById('boxy3').style.display = "none";
	}
	else {
		document.getElementById('boxy3').style.display = "block";
		var v = parseInt(this.value);
		// Create
		for(var i=1; i<=v; i++){
			// If exist
			var n = document.getElementById("benef"+i);
			if(!n){
				c.appendChild(buildBenef(i));
			}
			//if (i == 1){
				//document.getElementById("type11"+i).onchange = ecrireInfo("conjoint");
				//document.getElementById("type12"+i).onchange = ecrireInfo("enfant");
				//document.getElementById("type13"+i).onchange = ecrireInfo("autre");
				
				for (var w=1; w<=3; w++){
					document.getElementById("type"+w+""+i).i = i;
					document.getElementById("type"+w+""+i).w = w;
					document.getElementById("type"+w+""+i).onclick = function() {
						h = document.getElementById("contNaissance"+this.i);
						if ((document.getElementById("type"+this.w+""+this.i).value == "conjoint") || (document.getElementById("type"+this.w+""+this.i).value == "autre")) {
							h.innerHTML = "L'offre monchoix.sant&eacute; est propos&eacute;e aux personnes &acirc;g&eacute;es de 16 ans &agrave; 70 ans."
							}
						if (document.getElementById("type"+this.w+""+this.i).value == "enfant") {
							h.innerHTML = "Votre enfant est consid&eacute;r&eacute; comme b&eacute;n&eacute;ficiaire jusqu'&agrave; ses 25 ans. Au-del&agrave; de ses 25 ans, il peut adh&eacute;rer &agrave; titre individuel."
							}
					}
				}
			//}
		}
		// Destroy
		if(f.current > v){
			for(var i=(v+1); i<=f.current; i++){
				var n = document.getElementById("benef"+i);
				n.parentNode.removeChild(n);
			}
		}
		f.current = v;
	}
}

function buildBenef(i){
	var d = document.createElement("div");
	d.id = "benef"+i;
	var b = "<div class=\"box3\"><div class=\"titre\">B&eacute;n&eacute;ficiaire "+i+"</div>\n";
	b += "\t<div class=\"inputy\"><input class=\"first\" type=\"radio\" name=\"type"+i+"\" id=\"type1"+i+"\" value=\"conjoint\" ";
	//if (i == 1){b += "onclick=\"javascript:ecrireInfo(\'conjoint\');\"";}
	b += " />Conjoint<input type=\"radio\" name=\"type"+i+"\" id=\"type2"+i+"\" value=\"enfant\" ";
	//if (i == 1){b += "onclick=\"javascript:ecrireInfo(\'enfant\');\"";}
	b += " />Enfant<input type=\"radio\" name=\"type"+i+"\" id=\"type3"+i+"\" value=\"autre\" ";
	//if (i == 1){b += "onclick=\"javascript:ecrireInfo(\'autre\');\"";}
	b += " />Autre</div>\n";
	b += "\t<div class=\"field\">\n";
	b += "\t\t<div class=\"label\"><label for=\"tel\">Ann&eacute;e de naissance<span>*</span></label></div>\n";
	b += "\t\t<div class=\"input\"><input type=\"text\" value=\"\" name=\"naissance"+i+"\" id=\"naissance"+i+"\" size=\"6\" /></div>\n";
	//if (i == 1){
		b += "\t<div class=\"infoCont\">\n";
		b += "\t\t<div id=\"infoNaissance2Off"+i+"\" class=\"infoOff infoNaissance2Off\"><a href=\"#0\" onmouseover=\"goAffiche('infoNaissance2On','infoNaissance2Off',"+i+");\" title=\"\"><img src=\"includes/img/info_off.gif\" width=\"14\" height=\"14\" border=\"0\" alt=\"\" /></a></div>\n";
		b += "\t\t<div id=\"infoNaissance2On"+i+"\" class=\"infoOn infoNaissance2On\" onmouseout=\"goAffiche('infoNaissance2Off','infoNaissance2On',"+i+");\">\n";
		b += "\t\t\t<div class=\"infoOnLeft\"><img src=\"includes/img/info_left_2.gif\" width=\"9\" height=\"33\" border=\"0\" alt=\"\" /></div>\n";
		b += "\t\t\t<div id=\"contNaissance"+i+"\" class=\"infoOnCent\">L'offre monchoix.sant&eacute; est propos&eacute;e aux personnes &acirc;g&eacute;es de 16 ans &agrave; 70 ans.</div>\n";
		b += "\t\t\t<div class=\"infoOnRight\"><img src=\"includes/img/info_right_2.gif\" width=\"3\" height=\"33\" border=\"0\" alt=\"\" /></div>\n";
		b += "\t\t\t<div class=\"clear\"></div>\n";
		b += "\t\t</div>\n";
		b += "\t</div>\n";
	//}
	b += "\t<div class=\"clear\"></div>\n";
	b += "\t</div>\n";
	b += "\t<div class=\"field\">\n";
	b += "\t\t<div class=\"label\"><label for=\"tel\">R&eacute;gime de S&eacute;curit&eacute; sociale<span>*</span></label></div>\n";
	b += "\t\t<div class=\"input\"><select name=\"secu"+i+"\" id=\"secu"+i+"\">\n";
    b += "\t\t\t\t<option value=\"#0\"></option>\n";
    b += "\t\t\t\t<option value=\"1\">R&eacute;gime G&eacute;n&eacute;ral</option>\n";
    b += "\t\t\t<option value=\"2\">R&eacute;gime Alsace-Moselle</option>\n";
    b += "\t\t</select></div>\n";
	//if (i == 1){
		b += "\t<div class=\"infoCont\">\n";
		b += "\t\t<div id=\"infoRegime2Off"+i+"\" class=\"infoOff infoRegime2Off\"><a href=\"#0\" onmouseover=\"goAffiche('infoRegime2On','infoRegime2Off',"+i+");\" title=\"\"><img src=\"includes/img/info_off.gif\" width=\"14\" height=\"14\" border=\"0\" alt=\"\" /></a></div>\n";
		b += "\t\t<div id=\"infoRegime2On"+i+"\" class=\"infoOn infoRegime2On\" onmouseout=\"goAffiche('infoRegime2Off','infoRegime2On',"+i+");\">\n";
		b += "\t\t\t<div class=\"infoOnLeft\"><img src=\"includes/img/info_left_3.gif\" width=\"10\" height=\"44\" border=\"0\" alt=\"\" /></div>\n";
		b += "\t\t\t<div class=\"infoOnCent\">Le r&eacute;gime est n&eacute;cessaire &agrave; la tarification de votre devis. Si vous ne connaissez pas le r&eacute;gime de votre b&eacute;n&eacute;ficiaire, vous pouvez le retrouver inscrit sur son attestation de S&eacute;curit&eacute; sociale.</div>\n";
		b += "\t\t\t<div class=\"infoOnRight\"><img src=\"includes/img/info_right_3.gif\" width=\"3\" height=\"44\" border=\"0\" alt=\"\" /></div>\n";
		b += "\t\t\t<div class=\"clear\"></div>\n";
		b += "\t\t</div>\n";
		b += "\t</div>\n";
	//}
	b += "\t<div class=\"clear\"></div>\n";
	b += "</div>\n";
	d.innerHTML = b;
	return d;
}
function goAffiche(type1,type2,id){
	//alert(type1+" : "+type2+" : "+id);
	document.getElementById(type1+id).style.display = "block";
	document.getElementById(type2+id).style.display = "none";
}
function affiche(o){
	if (o =='infoNumero'){
		document.getElementById('infoNumeroOff').style.display = "none";
		document.getElementById('infoNumeroOn').style.display = "block";
	}
	if (o =='infoNaissance'){
		document.getElementById('infoNaissanceOff').style.display = "none";
		document.getElementById('infoNaissanceOn').style.display = "block";
	}
	if (o =='infoPostal'){
		document.getElementById('infoPostalOff').style.display = "none";
		document.getElementById('infoPostalOn').style.display = "block";
	}
	if (o =='infoRegime'){
		document.getElementById('infoRegimeOff').style.display = "none";
		document.getElementById('infoRegimeOn').style.display = "block";
	}
}

function desaffiche(o){
	if (o =='infoNumero'){
		document.getElementById('infoNumeroOff').style.display = "block";
		document.getElementById('infoNumeroOn').style.display = "none";
	}
	if (o =='infoNaissance'){
		document.getElementById('infoNaissanceOff').style.display = "block";
		document.getElementById('infoNaissanceOn').style.display = "none";
	}
	if (o =='infoPostal'){
		document.getElementById('infoPostalOff').style.display = "block";
		document.getElementById('infoPostalOn').style.display = "none";
	}
	if (o =='infoRegime'){
		document.getElementById('infoRegimeOff').style.display = "block";
		document.getElementById('infoRegimeOn').style.display = "none";
	}
}

function goPlayer(type){
	if ( type == "block") { ecrirePlayer(); }
	document.getElementById('layer').style.display = type;
	document.getElementById('layerCont').style.display = type;
}

function ecrirePlayer(flv) {
	var flashvars = {
		monFLV: flv
	};
	var params = {
		wmode: "transparent"
	};
	var attributes = {};
	
	var so = new swfobject.embedSWF("includes/swf/player.swf", "layerCont", "727", "444", "8.0.0", "includes/swf/expressInstall.swf", flashvars, params, attributes);
}

function activeLayer(cont,type){
	//alert("activeLayer "+ cont+ " " +type);
	if ( cont == "layerMailCont") { document.getElementById('layerMailCont').style.display = type; }
	if ( cont == "layerMailConfirmCont") { document.getElementById('layerMailConfirmCont').style.display = type; }
	if ( cont == "layerTableau") {
		// HACK : dans IE il y a un bug avec les z-index.
		// On ne peux pas mettre z-index à -1 en permanence
		// car on ne peut plus cliquer sur les liens du footer après.
		if(type == "none") {
			document.getElementById('footer').style.zIndex = 1;
		}
		else {
			document.getElementById('footer').style.zIndex = -1;
		}

		document.getElementById('layerTableau').style.display = type;
		document.getElementById('layerTableau').style.position = "absolute";
		document.getElementById('layerTableau').style.top = "0px";
		document.getElementById('layerTableau').style.left = "210px";
	}

	document.getElementById('layer').style.display = type;
	document.getElementById('layer').style.height = "1605px";
	document.getElementById('layer').style.width = "1250px";
	document.getElementById('layer').style.position = "absolute";
	document.getElementById('layer').style.top = "-180px";
	document.getElementById('layer').style.left = "-355px";
	
	if ( cont == "layerMailCont") { document.getElementById('mailValidBtn').focus();}
	if ( cont == "layerMailConfirmCont" ) {	elem = document.getElementById('mailFermerBtn');
											if (elem && type != "none") {
												elem.focus();										
											}
										}

	if(type == "none"){
		//msc_rEnd(document.getElementById('layerMailConfirmCont'));
		msc_rEnd(document.getElementById(cont));
	} else {
		//msc_rStart(document.getElementById('layerMailConfirmCont'));
		msc_rStart(document.getElementById(cont));
	}
}

var msc_nOpera = (navigator.userAgent.indexOf('Opera') != -1)? true : false;
var msc_nIe = (document.all && !msc_nOpera && navigator.platform == "Win32")? true : false;
var msc_nIe7 = (navigator.userAgent.indexOf('MSIE 7') != -1)? true : false ;

/***** 00 - MSC - Rescue *****/
function msc_rStart(){
	if(msc_nIe && !msc_nIe7){
		var parent = arguments[0].parentNode;
		var frame = document.createElement('iframe');
		var elem = parent.insertBefore(frame,arguments[0]);
		if(elem){
			elem.id = 'IFrameLayer';
			elem.className = 'rescue';
			elem.style.position = 'absolute';
			elem.style.left = arguments[0].offsetLeft+'px';
			elem.style.top = arguments[0].offsetTop+'px';
			elem.style.width = arguments[0].offsetWidth+'px';
			elem.style.height = arguments[0].offsetHeight+'px';
			elem.style.filter = 'alpha(opacity=0);';
		}
	}
}

function msc_rEnd(){
	if(msc_nIe && !msc_nIe7){
		//var parent = arguments[0].parentNode;
		//alert("2 ");
		//var frame = parent.getElementsByTagName("iframe")[0];
		//alert("3 "+frame);
		//var elem = parent.removeChild(frame);
		var Node = document.getElementById("IFrameLayer");
		Node.parentNode.removeChild(Node);
	}
}

function fieldCleaner(o){
	if(o.value == o.title){
		o.value = "";
	}
}
function fieldFiller(o){
	if(o.value == ""){
		o.value = o.title;
	}
}

function afficheInfo(o){
	o.className = "tabInfoOn";
}

function desafficheInfo(o){
	o.className = "tabInfoOff";
}

function Autotab(next, longueur, texte) {
    if (texte.length > longueur-1) {
	      document.getElementById(next).focus();
	  }
}
