

function get_random(limit)
{
    var ranNum= Math.floor(Math.random()*limit);
    return ranNum;
}


// definisce l'ordine casuale con cui vedere le modelle
function giveRandomOrder (arr,n,l)
{

var tmpArray = new Array();
for (x=0;x<n;x++)
    {
    var myRand=get_random(l);
    
    while (arr[myRand][6]==0)
       myRand=get_random(l);

    tmpArray[x]=arr[myRand];
    arr[myRand][6]=0;
    }

return tmpArray;
}


function invertOrder (arr)
{
var y=0;
var l=arr.length-1;
var tmpArray = new Array();
for (x=l;x>=0;x--)
    {
    tmpArray[y]=arr[x];
    y++;
    }

return tmpArray;
}
var myModelSize = model.length;
var myModelNextTmp = new Array();
var myModelPastTmp = new Array();
var myModelNext = new Array();
var myModelPast = new Array();
                      var indxNext=0;
                      var indxPast=0;
                      for (x=0;x<myModelSize;x++)
                         {
                         if (model[x][4]==1 && model[x][6]==1)
                             {
                             myModelPastTmp[indxPast]=model[x];
                             indxPast++;
                             }
                         else
                             {
                             if (model[x][4]==2 && model[x][6]==1)
                               {
                               myModelNextTmp[indxNext]=model[x];
                               indxNext++;
                               }
                             }
                          }

myModelNext = giveRandomOrder (myModelNextTmp,6,myModelNextTmp.length);  
myModelPast = giveRandomOrder (myModelPastTmp,8,myModelPastTmp.length);
                   
var j;
document.write('      <table border="1" width="179" bordercolor="#000000" bordercolorlight="#C0C0C0" bordercolordark="#0000FF" cellspacing="1" cellpadding="4"><tr>');
document.write('          <td width="163">');
document.write('            <p align="center"><b><font size="4" color="#FFCC66">Modella del mese</font></b>');
document.write('            <p align="center"><font color="#C0C0C0" size="4"><b><a href="http://www.eurossmodels.com/Models/'+model[modelladelmese][1]+'/index.htm"><img border="0" src="http://www.eurossmodels.com/Models/images/modelladelmese.jpg" width="180" height="135"></a></b></font></p>');
document.write('            <p align="center"><font color="#C0C0C0" size="4"><b><a href="http://www.eurossmodels.com/Models/'+model[modelladelmese][1]+'/index.htm"> <img border="0" src="http://www.eurossmodels.com/images/icon-flashoff.gif" width="33" height="42" onMouseOver="this.src=\'http://www.eurossmodels.com/images/icon-flashon.gif\'" onMouseOut="this.src=\'http://www.eurossmodels.com/images/icon-flashoff.gif\'" ;></a></b></font></p>');
document.write('            <p>&nbsp;</td></tr>');
document.write('<tr><td width="163"><b><font size="4" color="#FFCC66" colspan=2 valign="bottom">Regolamento</font></b><br>');
document.write('<a href="http://www.eurossmodels.com/Models/regolamento.htm">Prendi visione del regolamento per prenotare una sessione</a><br><br></td></tr>');

//----------- NEXT -----------

document.write('<tr><td width="163"><b><font size="4" color="#FFCC66">Prossimi arrivi</font></b><br>');
document.write('<table border="0" width="100%" cellspacing="3" cellpadding="2" height="359">');



for (i=myModelNext.length-1;i>=0;i=i-2)
{
j=i-1;

document.write('<tr><td width="50%" valign="bottom"><font color="#C0C0C0">');
 if (myModelNext[i][3]>0) //-- se ha il link
   {
   document.write('    <a href="http://www.eurossmodels.com/Models/'+myModelNext[i][1]+'/index.htm">');
   document.write('    <img border="0" src="http://www.eurossmodels.com/Models/'+myModelNext[i][1]+'/images/menu.jpg" width="80"></a>');
   }
 else //-- se NON ha il link
   {
   document.write('    <img border="0" src="http://www.eurossmodels.com/Models/'+myModelNext[i][1]+'/images/menu.jpg" width="80">');
   }
 
document.write('  </font></td><td width="50%" valign="bottom"><font color="#C0C0C0">');

if (j>=0) //-- se esiste
  { 
  if (myModelNext[j][3]>0) //-- se ha il link
    {
    document.write('    <a href="http://www.eurossmodels.com/Models/'+myModelNext[j][1]+'/index.htm">');
    document.write('    <img border="0" src="http://www.eurossmodels.com/Models/'+myModelNext[j][1]+'/images/menu.jpg" width="80"></a>');
    }
  else //-- se NON ha il link
    {
    document.write('    <img border="0" src="http://www.eurossmodels.com/Models/'+myModelNext[j][1]+'/images/menu.jpg" width="80">');
    }
  document.write('  </font></td>');
  }
else
  {
  document.write('    &nbsp;</font></td>');
  }

document.write('</tr><tr>');

document.write('  <td width="50%" valign="bottom"><font color="#C0C0C0">');
if (myModelNext[i][3]>0) //-- se ha il link
  {
  document.write('    <a href="http://www.eurossmodels.com/Models/'+myModelNext[i][1]+'/index.htm">'+myModelNext[i][0]+'</a>');
  }
else
  {
  document.write(myModelNext[i][0]);
  }

document.write('  </font></td><td width="50%" valign="bottom"><font color="#C0C0C0">');
if (j>=0) //-- se esiste
  {
  if (myModelNext[j][3]>0) //-- se ha il link
    { 
    document.write('    <a href="http://www.eurossmodels.com/Models/'+myModelNext[j][1]+'/index.htm">'+myModelNext[j][0]+'</a>');
    }
  else
    {
    document.write(myModelNext[j][0]);
    }
  document.write('  </font></td>');
  }
else
  {
  document.write('    &nbsp;</font></td>');
  }
document.write('</tr>');
document.write('<tr><td width="50%" valign="bottom"><br></td><td width="50%" valign="bottom"></td></tr>');
}

document.write('            </table>');
document.write('            <p><font color="#FFFFFF">&nbsp;</font></td>');
document.write('        </tr>');


//----------- PAST -----------

document.write('        <tr>');
document.write('          <td width="163"><b><font size="4" color="#FFCC66">EuRoss Models</font></b><br><br>');
document.write('<table border="0" width="100%" cellspacing="3" cellpadding="2">');

for (i=myModelPast.length-3;i>=0;i=i-2)
{
document.write('<tr><td width="50%" valign="bottom"><font color="#C0C0C0">');
 if (myModelPast[i][3]>0) //-- se ha il link
   {
   document.write('    <a href="http://www.eurossmodels.com/Models/'+myModelPast[i][1]+'/index.htm">');
   document.write('    <img border="0" src="http://www.eurossmodels.com/Models/'+myModelPast[i][1]+'/images/menu.jpg" width="80"></a></font></td>');
   }
 else //-- se NON ha il link
   {
   document.write('    <img border="0" src="http://www.eurossmodels.com/Models/'+myModelPast[i][1]+'/images/menu.jpg" width="80"></font></td>');
   }
 
document.write('  <td width="50%" valign="bottom"><font color="#C0C0C0">');
if (i-1>=0) //-- se esiste
  {
  if (myModelPast[i-1][3]>0) //-- se ha il link
    {
    document.write('    <a href="http://www.eurossmodels.com/Models/'+myModelPast[i-1][1]+'/index.htm">');
    document.write('    <img border="0" src="http://www.eurossmodels.com/Models/'+myModelPast[i-1][1]+'/images/menu.jpg" width="80"></a></font></td>');
    }
  else //-- se NON ha il link
    {
    document.write('    <img border="0" src="http://www.eurossmodels.com/Models/'+myModelPast[i-1][1]+'/images/menu.jpg" width="80"></font></td>');
    }
  }
else
  {
  document.write('    &nbsp;</font></td>');
  }

document.write('</tr><tr>'); // nome e link

document.write('  <td width="50%" valign="bottom"><font color="#C0C0C0">');
if (myModelPast[i][3]>0) //-- se ha il link
  {
  document.write('    <a href="http://www.eurossmodels.com/Models/'+myModelPast[i][1]+'/index.htm">'+myModelPast[i][0]+'</a></font></td>');
  }
else
  {
  document.write('    '+myModelPast[i][0]+'</font></td>');
  }

document.write('  <td width="50%" valign="bottom"><font color="#C0C0C0">');
if (i-1>=0) //-- se esiste
  {
  if (myModelPast[i-1][3]>0) //-- se ha il link
    { 
    document.write('    <a href="http://www.eurossmodels.com/Models/'+myModelPast[i-1][1]+'/index.htm">'+myModelPast[i-1][0]+'</a></font></td>');
    }
  else
    {
    document.write('    '+myModelPast[i-1][0]+'</font></td>');
    }
  }
else
  {
  document.write('    &nbsp;</font></td>');
  }
document.write('</tr>');
document.write('<tr><td width="50%" valign="bottom"><br></td><td width="50%" valign="bottom"></td></tr>');
}

document.write('            </table>');
document.write('            <p>&nbsp;</p>');
document.write('          </td>');
document.write('        </tr>');
document.write('      </table>');


