var	pdf_action=0;
 
function myPdf(){
	pdf_action=1;
	checkFields();
}

function classASk(){
	pdf_action=0;
	checkFields();				
}

function checkFields(){
	var ChkBool = true;
	var vStr = "";
	
	var mv = parseInt(document.forms[0].elements["T1"].value)+parseInt(document.forms[0].elements["T2"].value)+parseInt(document.forms[0].elements["T31"].value)+parseInt(document.forms[0].elements["T32"].value);
	mv = mv+parseInt(document.forms[0].elements["T33"].value)+parseInt(document.forms[0].elements["T34"].value)+parseInt(document.forms[0].elements["T4"].value);
	mv = mv+parseInt(document.forms[0].elements["T5"].value)+parseInt(document.forms[0].elements["T6"].value)+parseInt(document.forms[0].elements["T7"].value);
	if ( mv==0 ){
		ChkBool = false;
		vStr = vStr + message_initiaite_nr_of_person_in_your_family;
	}
	
	mv=0;	
	if ( document.forms[0].product[0].checked==true ) { mv=1; }
	if ( document.forms[0].product[1].checked==true ) { mv=1; }
	if ( document.forms[0].product[2].checked==true ) { mv=1; }
	if ( document.forms[0].product[3].checked==true ) { mv=1; }
	if ( document.forms[0].product[4].checked==true ) { mv=1; }
	if ( document.forms[0].product[5].checked==true ) { mv=1; }
	
	if ( mv==0 ){
		ChkBool = false;
		vStr = vStr + message_make_a_product_choice;
	}						
	
	if ( pdf_action==1 ){
		if ( document.getElementById("myemail").value=="" ){
			ChkBool = false;
			vStr = vStr + message_email_may_not_be_empty;
		}else{
			z=document.getElementById("myemail").value;
			z=z.toLowerCase();
			document.getElementById("myemail").value=z;

			r=check_email(z);
			if ( r==false ){
				ChkBool = false
				vStr = vStr + message_invalid_email;
			}
		}					
	}
	
	
	if (ChkBool == false){
		alert(vStr);
		return ChkBool;
	}else{		
		_product_quotation_submit();
	}
}

function OuvrirPopup(page,nom,option){
	window.open(page,nom,option);
}

function checkSelect(){
	sw=0;

	if ( document.forms[0].elements["T1"].value!=0 ) sw=1;
	if ( document.forms[0].elements["T2"].value!=0 ) sw=1;
	if ( document.forms[0].elements["T31"].value!=0 ) sw=1;
	if ( document.forms[0].elements["T32"].value!=0 ) sw=1;
	if ( document.forms[0].elements["T33"].value!=0 ) sw=1;
	if ( document.forms[0].elements["T34"].value!=0 ) sw=1;
	if ( document.forms[0].elements["T4"].value!=0 ) sw=1;
	if ( document.forms[0].elements["T5"].value!=0 ) sw=1;
	if ( document.forms[0].elements["T6"].value!=0 ) sw=1;
	if ( document.forms[0].elements["T7"].value!=0 ) sw=1;

	if ( sw==0 ){
		alert(message_select_one_or_more_age_categories);
		document.forms[0].product[0].checked= false;
		document.forms[0].product[1].checked= false;
		document.forms[0].product[2].checked= false;
		document.forms[0].product[3].checked= false;
		document.forms[0].product[4].checked= false;
		document.forms[0].product[5].checked= false;
	}else{
		radio=document.forms[0].product;
		checkRadio(radio);
		CalcReal();
	}
}

function Calc(t){
	inside=0;

	if ( t.name=="T7" ){
		radio=document.forms[0].product;
		// if (radio[4].checked) { inside=1; e="Hospitalia Continu�teit tot 54 jaar toegankelijk.";} // HC
		if (radio[5].checked) { inside=1; e=message_error_HCHA_age_accessibility_59;} // HCHA
		if (radio[1].checked) { inside=1; e=message_error_HHA_age_accessibility_59;} // HHA
		if (radio[3].checked) { inside=1; e=message_error_HPHA_age_accessibility_59;} // HPHA

		if ( inside==1 ){
			alert(e);
			document.forms[0].elements["T7"].value=0;
		}
	}

	if ( t.name=="T6" ){
		radio=document.forms[0].product;
		// if (radio[4].checked) { inside=1; e="Hospitalia Continu�teit tot 54 jaar toegankelijk.";} // HC
		// if (radio[5].checked) { inside=1; e="Hospitalia Continu�teit & Hospitalia Ambulant tot 54 jaar toegankelijk.";} // HCHA

		if ( inside==1 ){
			alert(e);
			document.forms[0].elements["T6"].value=0;
		}
	}

	switch (t.name ){
		case "T6" :
			if ( t.value!=0 ){
				// document.getElementById("type_hc").style.display="none";
				// document.getElementById("type_hcha").style.display="none";
				document.getElementById("type_hc").style.display="";
				document.getElementById("type_hcha").style.display="";
				document.getElementById("type_hha").style.display="";
				document.getElementById("type_hpha").style.display="";
			}else{
				document.getElementById("type_hc").style.display="";
				document.getElementById("type_hcha").style.display="";
				document.getElementById("type_hha").style.display="";
				document.getElementById("type_hpha").style.display="";
			}
			break;
		case "T7" :
			if ( t.value!=0 ){
				document.getElementById("type_hha").style.display="none";
				document.getElementById("type_hpha").style.display="none";
				// document.getElementById("type_hc").style.display="none";
				document.getElementById("type_hc").style.display="";
				document.getElementById("type_hcha").style.display="none";
			}else{
				document.getElementById("type_hha").style.display="";
				document.getElementById("type_hpha").style.display="";
				document.getElementById("type_hc").style.display="";
				document.getElementById("type_hcha").style.display="";
			}
			break;
		default :
			document.getElementById("type_hha").style.display="";
			document.getElementById("type_hpha").style.display="";
			document.getElementById("type_hc").style.display="";
			document.getElementById("type_hcha").style.display="";
			break;
	}

	radio=document.forms[0].product;
	checkRadio(radio);
}

function checkRadio(radio){
	vend = 0;
	vprod = "";
	for (var i=0; i<radio.length;i++){
		if (vend==0){
			if (radio[i].checked){
				vmsg="";
				vend=1;
				vprod=radio[i].value;
			}else{
				vend=0;
				vmsg=message_make_a_product_choice_please;
			}
		}
	}

	inside=0;

	if ( document.forms[0].elements["T7"].value!=0 ){
		radio=document.forms[0].product;
		// if (radio[4].checked) { inside=1; e="Hospitalia Continu�teit tot 54 jaar toegankelijk.";} // HC
		if (radio[5].checked) { inside=1; e=message_error_HCHA_age_accessibility_54;} // HCHA
		if (radio[1].checked) { inside=1; e=message_error_HHA_age_accessibility_59;} // HHA
		if (radio[3].checked) { inside=1; e=message_error_HPHA_age_accessibility_59;} // HPHA

		if ( inside==1 ){
			alert(e);
			document.forms[0].elements["T7"].value=0;
		}
	} else if ( document.forms[0].elements["T6"].value!=0 ){
		radio=document.forms[0].product;
		// if (radio[4].checked) { inside=1; e="Hospitalia Continu�teit tot 54 jaar toegankelijk.";} // HC
		// if (radio[5].checked) { inside=1; e="Hospitalia Continu�teit & Hospitalia Ambulant tot 54 jaar toegankelijk.";} // HCHA

		if ( inside==1 ){
			alert(e);
			document.forms[0].elements["T6"].value=0;
		}
	}

	CalcReal();
}

function CalcReal(){
	fObj=document.subscribe;
	for(index=0; index<fObj.T1.options.length; index++){
	    if(fObj.T1.options[index].selected) { T1=fObj.T1.options[index].value; }
	    if(fObj.T2.options[index].selected) { T2=fObj.T2.options[index].value; }
	    if(fObj.T31.options[index].selected) { T31=fObj.T31.options[index].value; }
		if(fObj.T32.options[index].selected) { T32=fObj.T32.options[index].value; }
		if(fObj.T33.options[index].selected) { T33=fObj.T33.options[index].value; }
		if(fObj.T34.options[index].selected) { T34=fObj.T34.options[index].value; }
	    if(fObj.T4.options[index].selected) { T4=fObj.T4.options[index].value; }
    	if(fObj.T5.options[index].selected) { T5=fObj.T5.options[index].value; }
	    if(fObj.T6.options[index].selected) { T6=fObj.T6.options[index].value; }
	    if(fObj.T7.options[index].selected) { T7=fObj.T7.options[index].value; }
  	}

	// Hospitalia
	var tarif=tarif_HOSPITALIA;
	tot=T1*tarif[0]+T2*tarif[1]+T31*tarif[2]+T32*tarif[3]+T33*tarif[4]+T34*tarif[5]+T4*tarif[6]+T5*tarif[7]+T6*tarif[8]+T7*tarif[9];
	// Hospitalia plus
	tarif=tarif_PLUS;
	tot2=T1*tarif[0]+T2*tarif[1]+T31*tarif[2]+T32*tarif[3]+T33*tarif[4]+T34*tarif[5]+T4*tarif[6]+T5*tarif[7]+T6*tarif[8]+T7*tarif[9];
	if (vprod=="HCHA"){
		tarif=tarif_CONTINUITE_AMBULANT;
	}else if (vprod=="HHA"){
		tarif=tarif_AMBULANT;				
	}else if (vprod=="HPHA"){
		tarif=tarif_PLUS_AMBULANT;
	}
	totambu=T1*tarif[0]+T2*tarif[1]+T31*tarif[2]+T32*tarif[3]+T33*tarif[4]+T34*tarif[5]+T4*tarif[6]+T5*tarif[7]+T6*tarif[8];
		
	tarif=tarif_CONTINUITE;		
	totcont=T1*tarif[0]+T2*tarif[1]+T31*tarif[2]+T32*tarif[3]+T33*tarif[4]+T34*tarif[5]+T4*tarif[6]+T5*tarif[7]+T6*tarif[8]+T7*tarif[9];
	
	
	totplus=tot+totambu;
	tot2plus=tot2+totambu;

	if (totcont==0){
		tot3plus=0;
	}else{
		tot3plus=totcont+totambu;
	}

	tot=Math.round(tot*100)/100;
	tot2=Math.round(tot2*100)/100;
	totambu=Math.round(totambu*100)/100;
	totcont=Math.round(totcont*100)/100;
	totplus=Math.round(totplus*100)/100;
	tot2plus=Math.round(tot2plus*100)/100;
	tot3plus=Math.round(tot3plus*100)/100;
	bef=Math.round(tot*40.3399);
	bef2=Math.round(tot2*40.3399);
	befambu=Math.round(totambu*40.3399);
	befcont=Math.round(totcont*40.3399);
	befplus=Math.round(totplus*40.3399);
	bef2plus=Math.round(tot2plus*40.3399);
	bef3plus=Math.round(tot3plus*40.3399);

	if (vprod=="H") { fObj.cotisation.value=tot+" € ("+bef+" BEF)"; }
	if (vprod=="HP") { fObj.cotisation.value=tot2+" € ("+bef2+" BEF)"; }
	if (vprod=="HC") { fObj.cotisation.value=totcont+" € ("+befcont+" BEF)"; }
	if (vprod=="HHA") { fObj.cotisation.value=totplus+" € ("+befplus+" BEF)"; }
	if (vprod=="HPHA") { fObj.cotisation.value=tot2plus+" € ("+bef2plus+" BEF)"; }
	if (vprod=="HCHA") { fObj.cotisation.value=tot3plus+" € ("+bef3plus+" BEF)"; }
	
	document.getElementById("pdfZone").style.display="";
}

/*check checked option*/
function getCheckedOption(){
	sopt = "";

	for (var i=0; i<document.subscribe.product.length;i++){
         if (document.subscribe.product[i].checked) { sopt=document.subscribe.product[i].value; }
	}
	return sopt;
}
/*hide view options*/
function app_fn(){
	sopt = "";
	sopt = getCheckedOption();

	if (sopt=="HHA" || sopt=="HPHA"){
		showhide('tot59_fn', 'none');
		showhide('tot54_fn', 'block');
		showhide('tot59', 'none');
		showhide('tot54', 'block');
	}else if (sopt=="HC" || sopt=="HCHA"){
		showhide('tot59_fn', 'none');
		showhide('tot54_fn', 'none');
		showhide('tot59', 'none');
		showhide('tot54', 'none');
	}else{
		showhide('tot59_fn', 'block');
		showhide('tot54_fn', 'block');
		showhide('tot59', 'block');
		showhide('tot54', 'block');
	}
}
/*Show or Hide an element*/
function showhide(layer_ref, state){
	if (document.all) { //IS IE 4 or 5 (or 6 beta)
		eval( "document.all." + layer_ref + ".style.display = state");
	}
	if (document.layers) { //IS NETSCAPE 4 or below
		document.layers[layer_ref].display = state;
	}
	if (document.getElementById &&!document.all) {
		hza = document.getElementById(layer_ref);
		hza.style.display = state;
	}
}

function check_email(p){
		pattern = /^([A-Za-z0-9\.\-_]*)(@)([A-Za-z0-9\.\-]*)(\.)([a-z]{2,4})$/;
		var strEmail = p;

		bTest = pattern.test(strEmail);

		if (!bTest){
			return false;
		}
		return true;
}	
