
/*
	Réalisation ADMIn Informatique : http://www.admin-info.com/
*/


/*
Fonctions type Java Script
Développement : ADMIn Informatique
Création : Janvier 2008
Modification :
Décembre 2008 : Correction de bugs
*/

// Fonction de validation des paramétres de l'utilisateur pour autoriser ou non la création du document PDF
function ValidParam(chiffre, texte)
{
	var var_project = document.getElementById('project_name').value;
	var var_project_country = document.getElementById('project_country').value;
	var var_project_description = document.getElementById('project_description').value;
	var var_compagny = document.getElementById('compagny').value;
	var var_first_name = document.getElementById('first_name').value;
	var var_last_name = document.getElementById('last_name').value;
	var var_email = document.getElementById('email').value;
	var var_TUV = document.getElementById('theo_unit_volume').value;
	if ((var_project == "") || (var_project_country == "") || (var_project_description == "") ||
        (var_compagny == "") || (var_first_name == "") || (var_last_name == "") ||
        (var_email == "") || (var_TUV == ""))
	{
		helpTopic(chiffre);
		document.getElementById('idLienPDF').href = "#";
	}
	else
	{
		var var_PHead = var_project+" - "+var_compagny;
		var cmd_PDF = "pdf_html/pdf_form_fill.php?ProjectName="+var_project+
			"&ProjectCountry="+var_project_country+
			"&ProjectDescription="+var_project_description+
			"&CompanyName="+var_compagny+
			"&FirstName="+var_first_name+
			"&LastName="+var_last_name+
			"&Email="+var_email+
			"&PHead="+var_PHead;
		//document.getElementById('idLienPDF').href = texte;
		document.getElementById('idLienPDF').href = cmd_PDF + texte;
	}

}

// Fonction appeler lors du clique de l'utilisateur sur le bouton "Compute". Permet de générer le calcul.
function ajaxCompute()
{
  var xhr = null;
  
  // Fonction de creation de l'objet XMLHttpRequest qui resservira pour chaques fonctions AJAX 
  if(window.XMLHttpRequest) xhr = new XMLHttpRequest();
  else
    if(window.ActiveXObject)
    {
      try {xhr = new ActiveXObject("Msxml2.XMLHTTP");}
      catch (e) {xhr = new ActiveXObject("Microsoft.XMLHTTP");}
    }
    else
    {
      alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest, veuillez le mettre à jour");
      xhr = false;
    }

  xhr.onreadystatechange = function()
  {
    if(xhr.readyState == 4 && xhr.status == 200)
    {document.getElementById('InTab').innerHTML = xhr.responseText;}
  }
  xhr.open("POST",'compute.php',true);
  xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  var var_st = document.getElementById('section_type').value;
  var var_ut = document.getElementById('unit_type').value;
  var var_as = document.getElementById('armour_slope').value;
  var var_cd = document.getElementById('concrete_density').value;
  var var_wd = document.getElementById('water_density').value;
  var var_wh = document.getElementById('wave_height').value;
  var var_bw = document.getElementById('breaking_wave').value;
  var var_ss = document.getElementById('seabed_slope').value;
  var var_se = document.getElementById('seabed_elevation').value;
  var var_ce = document.getElementById('crest_elevation').value;
  var var_project = document.getElementById('project_name').value;
  var var_project_country = document.getElementById('project_country').value;
  var var_project_description = document.getElementById('project_description').value;
  var var_compagny = document.getElementById('compagny').value;
  var var_first_name = document.getElementById('first_name').value;
  var var_last_name = document.getElementById('last_name').value;
  var var_email = document.getElementById('email').value;

  var msg = "section_type="+var_st+"&unit_type="+var_ut+"&armour_slope="+var_as+
    "&concrete_density="+var_cd+"&water_density="+var_wd+"&wave_height="+var_wh+
    "&breaking_wave="+var_bw+"&seabed_slope="+var_ss+"&seabed_elevation="+var_se+
    "&crest_elevation="+var_ce+"&project_name="+var_project+"&project_country="+
    var_project_country+"&project_description="+var_project_description+
    "&compagny="+var_compagny+"&first_name="+var_first_name+"&last_name="+
    var_last_name+"&email="+var_email;
 
  xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  xhr.send(msg);
}

// Fonction qui permet de changer l'image du bloc, suivant la séléction de l'utilisateur.
function changerImage()
{
  var iUT = document.getElementById('unit_type').value;
  switch (iUT)
  {
    case '1':
      UT = 'accropode';
      break;
    case '2':
      UT = 'accropode2';
      break;
    case '3':
      UT = 'coreloc';
      break;
    case '4':
      UT = 'ecopode';
      break;
    default:
      UT = 'accropode';
      break;
  }
  document.getElementById('imgBloc').src = 'images/sites/'+UT+'_ombre.gif';
  //http://www.concretelayer.com/images/files/A4_accropode_ang1108.pdf
  document.getElementById('PDF1').href = 'http://www.concretelayer.com/images/files/A4_'+UT+'_ang1108.pdf';
  document.getElementById('PDF2').href = 'pdf_html/pdf/'+UT+'_Design_Guidelines.pdf';
}
 
// Fonction pour changer le message des zones aides
function helpTopic(helpNumber)
{
  switch (helpNumber)
  {
    case 1:
      msg = 'The calculation can be applied on two types of structure stretches: a trunk section or a curved stretch.';
      hid = '1';
      break;
    case 2:
      msg = 'The Calculator gives the choice between the four CLI units (ACCROPODE&#8482;,ACCROPODE II&#8482;, ECOPODE&#8482;, CORE-LOC&#8482;).';
      hid = '1';
      break;
    case 3:
      msg = 'Two armour slopes can be use  for the CLI single layer units (4/3 and 3/2). However, for the calculation with the Hudson formula, the Calculator considers an armour slope of 4/3. The slope chosen by the designer will be integrated for geometrical considerations (number of rows).';
      hid = '1';
      break;
    case 4:
      msg = 'The concrete density should not be overestimated in order to be lower than the minimum measured density on site. Validity range [2250 - 2500 kg/m3].';
      hid = '1';
      break;
    case 5:
      msg = 'Sea water density. Validity range [1000 - 1040 kg/m3].';
      hid = '1';
      break;
    case 6:
      msg = 'The significant wave height (Hs) is H1/3 (average of the highest 1/3 of all wave heights). Attention should be paid to the difference between H1/3 and Hmo (spectral significant wave height) in shallow waters. Validity range [3 - 10 m].';
      hid = '1';
      break;
    case 7:
      msg = 'Wave breaking can influence the breakwater armour stability.';
      hid = '1';
      break;
    case 8:
      msg = 'The seabed slope is estimated taking into consideration the mean seabed slope in front of the structure. In case of non-breaking waves, the seabed slope does not influenced the calculation results. Validity range [0 - 10 %].';
      hid = '1';
      break;
    case 9:
      msg = 'The bottom level of the armour is the level where the first row of units is placed. Total height of the structure must be less than 35 m.';
      hid = '1';
      break;
    case 10:
      msg = 'Upper level of the armour. Total height of the structure must be less than 35 m.';
      hid = '1';
      break;
    case 11:
      msg = 'The theoretical volume is the unit volume resulting from the calculation.';
      hid = '2';
      break;
    case 12:
      msg = 'The standard volume is one of the family sizes appearing in CLI tables corresponding to the theoretical volume and respecting possibly the maximum number of rows along the armour slope.';
      hid = '2';
      break;
    case 13:
      msg = 'The unit mass is calculated using the standard volume and the concrete density value provided by the Designer.';
      hid = '2';
      break;
    case 14:
      msg = 'The unit height is calculated using the CLI unit standard shape.';
      hid = '2';
      break;
    case 15:
      msg = 'The underlayer thickness is specified in the CLI standards.';
      hid = '2';
      break;
    case 16:
      msg = 'The rocks underlayer is specified in the CLI standards.';
      hid = '2';
      break;
    case 17:
      msg = 'The underlayer thickness is specified in the CLI standards.';
      hid = '2';
      break;
    case 18:
      msg = 'The concrete consumption per m² is specified according to the CLI standards.';
      hid = '2';
      break;
    case 19:
      msg = 'The number of units per 100 m² is specified according to the CLI standards.';
      hid = '2';
      break;
    case 20:
      msg = 'The number of rows is specified according to the standard volume estimated by the Calculator, the bottom and upper armour slopes and the armour slope provided by the Designer.';
      hid = '2';
      break;
    case 21:
      msg = 'You must enter your identification information to access this function.';
      hid = '2';
      break;
    default:
      break;
  }
document.getElementById('htid'+hid).innerHTML = '<fieldset><legend><strong>Help topic</strong></legend><table class=Tht><tr><td valign=top>'+msg+'</td></tr></table></fieldset>';;
                                                 
}

// Fonction pour effacer le message des zones d'aide
function helpTopicOut(hid)
{
  document.getElementById('htid'+hid).innerHTML = '<fieldset><legend><strong>Help topic</strong></legend><table class=Tht><tr><td></td></tr></table></fieldset>';
}
