<?php
include ('logue.php'); 
include ('entete2.php');
include ('entete.php');
include ('ressource.php');

echo"
<style>
input {
border:1px solid #7E7E7E;
background-color:#000000;
font-family:'trebuchet ms',sans-serif;
color:white;
}
textarea {
border:1px solid #7E7E7E;
background-color:#000000;
font-family:'trebuchet ms',sans-serif;
color:white;
}
select, option {
background-color:#000000;
color:white;
}
</style>
<STYLE TYPE=text/css>
.Style1 {color: #0000FF}
.Style2 {color: #FF0000}
</STYLE>";
echo"<div align=\"center\"><form name=\"colo\" method=\"post\" action=\"colonie.php\" target=\"_parent\">
<table align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
   <tr>
     <td width=\"100\" rowspan=\"2\" valign=\"middle\">
       <div align=\"center\">
         <input name=\"page\" value=\"" . $PHP_SELF . "\" type=\"hidden\" id=\"page\">
         <select name=\"idcolo\" onchange=submit()>";
include ('colo2.php'); 

$sql = "SELECT labo_lvl FROM matgraph_users WHERE id='$planete' ";
$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
$row = mysql_fetch_array($res); 
if ($row[labo_lvl] >= 5 ) {


$sql = "SELECT galaxi,system,position,eppz,place,placepris,planete FROM matgraph_users WHERE id='$planete' ";
$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
$row = mysql_fetch_array($res); 
$placelibre = $row[place]-$row[placepris];

$eppz = floor($row[eppz]) + 1 ;
$seppz = number_format(($row[eppz] * 60000), 0, ',', ' ');
echo"<script language=\"javascript\">
function couteppz() {

  var Besoin_energie = 0;

  if ( Math.round( document.getElementById('galaxi').value ) != $row[galaxi] ) {

    Dif_galaxi = Math.abs ( Math.round(document.getElementById('galaxi').value) - $row[galaxi] ) ;

    Besoin_energie = Dif_galaxi*30000;

  }
  else {

    if ( Math.round(document.getElementById('system').value) != $row[system] ) {

      Dif_system = Math.abs ( Math.round(document.getElementById('system').value) - $row[system] );

      if (Dif_system > 50)
        Besoin_energie = 30000;	

      else if (Dif_system > 20)
        Besoin_energie = 20000;	
	
      else if (Dif_system > 10)
        Besoin_energie = 10000;
	
      else if (Dif_system > 5)
        Besoin_energie = 5000;	
	
      else
        Besoin_energie = 2000;
    }
    else {

      if ( Math.round(document.getElementById('position').value) != $row[position] )
        Besoin_energie = 1000;

    }

  }

  startnb = Besoin_energie.toString();

  imax = Math.ceil( startnb.length / 3);
  endnb = '';
  nombre = new Array();

  for( i = 1; i <= imax; i++) {

    j = startnb.length - ( i * 3 );
    if ( j < 0 ) {
       h = 3 +  j;
       j = 0;
    }
    else {
       h =3;
    }

    nombre[i] = startnb.substr( j , h );

  }

  for( i-=1;  i > 0;  i--) {

    if ( i > 0 )
       endnb+=' ';

    endnb+= nombre[i];

  }

  document.getElementById('couteppz_ligne').innerHTML = endnb;
}

</script>";
echo"<div align=\"center\">
<table width=\"618\"  border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
    <tr>
      <td colspan=\"3\" align=\"center\"><b>Mission Espionnage type 2 :</b>
<br><br>
blablabla...</td>
    </tr>
  </table><br><br>
<div align=\"center\"><br><br>Vous possédez $eppz E.P.P.Z . Un E.P.P.Z contient 60 000 d'energies.<br><br>
<form name=\"form1\" method=\"post\" action=\"espio2_envoi.php\" target=\"_parent\">
  <table width=\"618\"  border=\"1\" cellspacing=\"0\" cellpadding=\"0\">
    <tr>
      <td colspan=\"3\"><div align=\"center\">Entrez les coordonn&eacute;es de la planète à espionner</div></td>
    </tr>
    <tr>
      <td width=\"203\"><div align=\"center\">Galaxie</div></td>
      <td width=\"203\"><div align=\"center\">Systeme Solaire </div></td>
      <td width=\"204\"><div align=\"center\">Position </div></td>
    </tr>
    <tr>
      <td><div align=\"center\">
        <input name=\"galaxi\" id=\"galaxi\" type=\"text\" value=\"$galaxi\" onChange=\"couteppz();\">
      </div></td>
      <td><div align=\"center\">
        <input name=\"system\" id=\"system\" type=\"text\" value=\"$system\" onChange=\"couteppz();\">
      </div></td>
      <td><div align=\"center\">
        <input name=\"position\" id=\"position\" type=\"text\" value=\"$position\" onChange=\"couteppz();\">
      </div></td>
    </tr>
    <tr>
      <td colspan=\"3\" height=\"40\"><div align=\"center\">
        <input type=\"submit\" name=\"Submit\" value=\"Activer la porte des étoiles\">
      </div></td>
    </tr>
  </table>
</form></div>
<table width=\"618\"  border=\"1\" cellspacing=\"0\" cellpadding=\"0\">
    <tr>
      <td align=\"center\">La somme de vos E.P.P.Z fait $seppz .
	  <br>Votre consomation d'energie est de : <b><font color=\"FF0000\"><div name=\"couteppz_ligne\" id=\"couteppz_ligne\">0</div></font></b></td>
    </tr>
  </table>
<table width=\"618\"  border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
    <tr>
      <td colspan=\"3\" align=\"center\"><br>En entrant les coordonnées d’une planète et en activant la porte des étoiles, un vortex se crée et votre M.A.L.P traverse la porte des étoiles. Une fois de l’autre côté, ils effectuera sa mission et transmettra les informations.</td>
    </tr>
  </table>";

}
else {
echo"<br><br>Vous n'avez pas de porte des étoiles sur cette planete."; } 
?>