//  product selector
//  Visual Solutions - Copyright 2000-2007

var productstring = 'Séries';
var linkstring = 'Accès aux séries';
var resultstring = 'La liste de résultats comprend plus de 30 séries de fabrication. Veuillez sélectionner des critères supplémentaires pour réduire le nombre de résultats.'

var vsstyle = '<STYLE TYPE="text/css">'+
'a {font-size:8pt; font-family:Courier; font-weight:normal; color:#009c82; text-decoration:none;}'+
'a:hover {color:#A90000; text-decoration:none;}'+
'th  {font-size:9pt; font-family:arial; font-weight:bold; color:#000000; background-color:#C7DDF1;}'+
'td  {font-size:8pt; font-family:Arial; text-decoration:none; border-bottom-width:1px; border-bottom-style:solid; color:black; border-color:#DDEEFF}'+
'</STYLE>';

top.name = 'selector1';

var IE = document.all;
var DOM = document.getElementById;

function IdObject(doc, myId )
{
  if (DOM)
    return doc.getElementById(myId);
  else
    return doc.all[myId];
}
function SetIdStyle( myId, Name, Value )
{
  if (DOM)
  {
    if (document.getElementById(myId)) document.getElementById(myId).style[Name] = Value;
  }
  else
  {
    if (document.all[myId]) document.all[myId].style[Name] = Value;
  }
}
function IdStyle( myId )
{
  if (DOM)
    return document.getElementById(myId).style;
  else
    return document.all[myId].style;
}


var KeyList = new Object();
for( var i = 0, L = allselections.length ; i<L ; i++)
{
   for( var ii = 1, LL = allselections[i].length ; ii<LL ; ii++)
   {
      KeyList['a'+i+'b'+ii] = ( allselections[i][ii][0]!=='' ? allselections[i][ii][0] : allselections[i][ii][1] );
      allselections[i][ii][0] = 'a'+i+'b'+ii;
   }
}

var activeselections = new Array( allselections.length );
for( var i=0 ; i<activeselections.length ; i++ )
   activeselections[i] = '';

var selectioncount = 0;
var pcount=allentries.length-2;
var change = false;

// Selector Tabelle ausgeben
function writecolumn( doc , column )
{
   doc.writeln('<td valign=top align=center>');
   doc.writeln('<table border=0 cellspacing=1 cellpadding=0 width=120 bgcolor=#009c82>');
   doc.writeln('<tr><td id="sel'+column+'Value" bgcolor=#009c82 style="color:#FFF"><b>'+allselections[column][0][0]+'</b></td></tr>');
   for( var i = 1, item, L = allselections[column].length ; i<L ; ++i )
   {
   	item = allselections[column][i];
       doc.writeln('<tr><td bgcolor="white" style="cursor:pointer;"><div id="'+item[0]+'" style="cursor:pointer;" onClick="select('+column+',\''+item[0]+'\')">'+item[1]+'</div></td></tr>');
   }
   doc.writeln('</table>');
   doc.writeln('</td>');
}

function deselectall( column )
{
   if (column<allselections.length)
   {
      for( var i = 0, id, L = allselections[column].length ; i<L ; ++i )
      {
      	  id = allselections[column][i][0];
         SetIdStyle( id, 'color', "");
         SetIdStyle( id, 'fontWeight', "normal");
      }
   }
}

function showall( column )
{
   for( var i = 1, id, L = allselections[column].length ; i<L ; ++i )
   {
      	  id = allselections[column][i][0];
         if (IdStyle( id )['textDecoration'] == 'line-through') SetIdStyle( id, 'color', "#000");
         SetIdStyle( id, 'fontStyle', "normal");
         SetIdStyle( id, 'backgroundColor', "");
         SetIdStyle( id, 'textDecoration', "");
         if (IE)
            SetIdStyle( id, 'cursor', "hand");
         else
            SetIdStyle( id, 'cursor', "pointer");
         IdObject(document, allselections[column][i][0] ).onclick = new Function("test","select("+column+",'"+allselections[column][i][0]+"')");
   }
}

function gethidden( column )
{
   var shown = '';
   var shown2 = '';
   var allhidden = new Array();
   var allhidden2 = new Array();
   var evalstr = '';
   j = 2;
   if( allselections[column][0][1] == "f" )
      evalstr = '+"~").indexOf("~"+allentries[i][j]+"~") < 0 )';
   else
      evalstr = '.indexOf(allentries[i][j]) < 0) )';
   for( var i = 1, L = allentries.length-1 ; i<L ; ++i )
   {
      if( (  (allentries[i][1] == "0")  ||  ( (allentries[i][1] & (~( 1 << column ))) <= 0 )  )  )
      {
         if( eval('( (shown'+evalstr) )
            shown += "~" + allentries[i][j];
      }
      else
      {
/*
         for( ik=0 ; ik < allselections.length ; ++ik )
         {
            if(  ( (allentries[i][1] & (~( 1 << column ))) == (1 << ik) )  &&  eval('( (shown2'+evalstr)  )
               shown2 += "~" + allentries[i][j];
         }
*/
      }
   }
   if( allselections[column][0][1] == "f" )
   {
      var nums = shown.split("~");
      var nums2 = shown2.split("~");
      for( var i=1, L = allselections[column].length ; i<L ; ++i )
      {
         var hide = true;
         for( ii=1 ; ii<nums.length ; ++ii )
         {
            n = Number( nums[ii] );
            hide = hide && !eval( allselections[column][i][0] );
         }
         if( hide )
            allhidden = allhidden.concat( allselections[column][i][0] );
         hide = true;
         for( ii=1 ; ii<nums2.length ; ++ii )
         {
            n = Number( nums2[ii] );
            hide = hide && !eval( allselections[column][i][0] );
         }
         if( hide )
            allhidden2 = allhidden2.concat( allselections[column][i][0] );
      }
   }
   else
   {
      for( var i=1, L = allselections[column].length ; i<L ; ++i )
      {
         if( shown.indexOf( KeyList[ allselections[column][i][0] ] ) < 0 )
         {
            allhidden = allhidden.concat( allselections[column][i][0] );
//            if( shown2.indexOf(allselections[column][i][0]) < 0 )
//               allhidden2 = allhidden2.concat( allselections[column][i][0] );
         }
      }
   }
   return [allhidden,allhidden2];
}

var action = 1;
function resetTimeout()
{
  action=0;
}

function select( column, selection )
{
  if (action==0)
  {
    SetIdStyle('bodyid', 'cursor' ,"wait");
    SetIdStyle(selection, 'fontStyle', "italic");
    self.setTimeout( 'select3('+column+',\''+selection+'\')', 1);
  }
}

function select3( column, selection )
{
   action = 1;
   if( activeselections[column]!=='' )  // Gruppe wurde schon gewählt
   {
      deselectall( column );
      if( activeselections[column].indexOf(selection) >=0 )  // Gruppe abwählen
      {
         activeselections[column] = '';
         selection='';
      }
      change = true;
   }
   if( selection!=='' )
   {
      if( allselections[column][0][1] == "m" )
      {
         temp = activeselections[column] + selection;
         activeselections[column] = '';
         for( var i=1, L = allselections[column].length ; i<L ; i++ )
            if( temp.indexOf(allselections[column][i][0]) >=0 )
            {
               activeselections[ column ] += '|'+allselections[column][i][0];
               SetIdStyle( allselections[column][i][0], 'color', "#009C82");
               SetIdStyle( allselections[column][i][0], 'fontWeight', "bold");
            }
         activeselections[ column ] = activeselections[ column ].substr(1);
      }
      else
      {
         activeselections[ column ] = selection;
      }
      SetIdStyle( selection, 'color', "#009C82");
      SetIdStyle( selection, 'fontWeight', "bold");
      if( allselections[column][0][1] == "f" )
         evalstr = '{n=Number( allentries[i]['+(2)+'] ); ('+selection+');}';
      else if( allselections[column][0][1] == "m" )
         evalstr = 'String(allentries[i]['+(2)+']).indexOf(\''+activeselections[column].replace(/\|/g,'\') >=0 && String(allentries[i]['+(2)+']).indexOf(\'')+'\') >=0';
      else
         evalstr = 'String(allentries[i]['+(2)+']).indexOf(KeyList[\''+activeselections[column]+'\']) >=0';
   }
   else
      evalstr = 'true';
//  ---------------  Produkte suchen  --------------------
   pcount=0;
   for( i=1 ; i < allentries.length-1 ; ++i )
   {
      if( eval( evalstr ) )
      {
         allentries[i][1] &= (~( 1 << column ));
         if( allentries[i][1] <= 0 )
            pcount += 1;
      }
      else
         allentries[i][1] |= ( 1 << column );
   }
   for(var k=0 ; k < allselections.length ; ++k )
   {
      showall( k );
      allhidden1 = gethidden( k );
      allhidden = allhidden1[0];
      for(var i=0 ; i < allhidden.length ; ++i)
      {
            SetIdStyle( allhidden[i], 'backgroundColor', "#e0e0de");
            SetIdStyle( allhidden[i], 'textDecoration', "line-through");
            SetIdStyle( allhidden[i], 'cursor', "auto");
            if ( IdObject(document, allhidden[i]) ) IdObject(document, allhidden[i] ).onclick = null;
      }
   }
   if( pcount < 30)
   {
      IdObject(parent.Navigation.document, 'Count').innerHTML = '&nbsp;'+String(pcount)+'&nbsp;'+productstring;
      openWin();
   }
   else
   {
      IdObject(parent.Navigation.document, 'Count').innerHTML = '&nbsp;'+String(pcount)+'&nbsp;'+productstring;
      if (parent.Navigation.document.images['Icon'])
        parent.Navigation.document.images['Icon'].src= 'list_a.gif';
      parent.plist.document.open();
      parent.plist.document.write('<html><head><title>product list</title></head><body bgcolor=#FFFFFF><center style="font-size:9pt; font-family:Arial;">'+resultstring+'</center></body></html>');
      parent.plist.document.close();
   }
   SetIdStyle( 'bodyid', 'cursor', "auto");
   action = self.setTimeout( 'resetTimeout()', 100);
   return false;
}

function reset()
{
   action = 1;
   for( i=1 ; i < allentries.length ; ++i )
      allentries[i][1] = 0;
   for( k=0 ; k<allselections.length ; k++)
   {
      activeselections[k] = '';
      deselectall( k );
      showall( k );
   }
   IdObject(parent.Navigation.document, 'Count').innerHTML = '&nbsp;'+String(pcount)+'&nbsp;'+productstring;
   if (parent.Navigation.document.images['Icon'])
      parent.Navigation.document.images['Icon'].src= 'list.gif';
   parent.plist.document.open();
   parent.plist.document.write('<html><head><title>product list</title></head><body bgcolor=#FFFFFF></body></html>');
   parent.plist.document.close();
   SetIdStyle('bodyid', 'cursor', "auto");
   action = self.setTimeout( 'resetTimeout()', 100);
   return false;
}

function openWin( nav )
{
   if (parent.Navigation.document.images['Icon'])
      parent.Navigation.document.images['Icon'].src= 'list.gif';
  myWin = parent.frames['plist'];
  myWin.document.open();
  myWin.document.writeln('<html><head><title>product list</title>'+vsstyle);
  myWin.document.writeln('</head><body bgcolor=#FFFFFF>');

  myWin.document.writeln('<table id="result" width="100%" cellpadding=0 cellspacing=2 rules=rows border=0>');
   for(i=0; i<allentries.length-1; ++i)
   {
      if ( allentries[i][1] == "0" )
         {
            myWin.document.writeln('<tr>'+
            '<td><a target="new" href="http://www.wilo.fr/cps/rde/xchg/fr-fr'+LinkList[allentries[i][0]]+'" target="_top">'+'Wilo-'+allentries[i][0]+'</a></td>'+
            '<td><a target="new" href="http://www.wilo.fr/cps/rde/xchg/fr-fr'+LinkList[allentries[i][0]]+'" target="_top">'+linkstring+
            '</a></td></tr>');
         }
   }
   myWin.document.writeln('</table>');
   myWin.document.writeln('</body></html>');
   myWin.document.close();
}
