// JavaScript Document

function BOBY_OnLoad ()
{
	setHover ();	

	// guide
	// FillModelForm(window.document.form.marque, window.document.form.modele, window.document.form.game, window.document.form.genre, window.document.form.category);

	// comparator
	FillModelForm(window.document.compform.marque2, window.document.compform.model2);
	FillModelForm(window.document.compform.marque1, window.document.compform.model1);

	
	if (window.document.comp != null) 
	{
		FillModelForm(window.document.comp.marque2, window.document.comp.model2);
		FillModelForm(window.document.comp.marque1, window.document.comp.model1);
	}
/*
	if (window.document.guide != null) 
	{
		FillModelForm(window.document.guide.marque, window.document.guide.modele, window.document.guide.game, window.document.guide.genre, window.document.guide.category);	
	}
*/	

	
}


function inArray (array, value)
{
	for (j=0; j<array.length; j++)
	{
		if (array[j] == value)
			return (true);
	}
	return (false);
}


function indexFromValue (control, value)
{
	for (i=0; i<control.options.length; i++)
	{
	  if (control.options[i].value == value)
			return (i);
	}
	return (-1);
}


function FillModelForm (field1, field2)
{
	if (field1 != undefined  &&  field2 != undefined  &&  field1 != null  &&  field2 != null)
	{
	
		sel1 = field1.options[field1.selectedIndex].value;
		field1.options.length = 1;

		sel2 = field2.options[field2.selectedIndex].value;
		field2.options.length = 1;

		for( i = 0; i < Array1.length; i++ ) 
		{ 
			if (
					(sel2 == -1  ||  inArray (Array1 [i][1], sel2))  
					)
				{
					field1.options[field1.options.length] = new Option (Array1 [i][0]);
					field1.options[field1.options.length-1].value = Array1 [i][0];
				}
		}		
		
		for( i = 0; i < Array2.length; i++ ) 
		{ 
			if (
					(sel1 == -1  ||  inArray (Array2 [i][1], sel1))
					)
				{
					field2.options[field2.options.length] = new Option (Array2 [i][0]);
					field2.options[field2.options.length-1].value = Array2 [i][0];
				}
		}

			
		field1.selectedIndex = indexFromValue (field1, sel1);
		field2.selectedIndex = indexFromValue (field2, sel2);
	}
}



function insertSmiley (text)
{
	var comment = document.getElementById('comment_text');
			comment.value = comment.value + text;	
}



function setHighlight (_div, _action)
{
	if (_action == "over" || _action == "click") 
	{
			_div.style.cursor = 'pointer';
			_div.style.backgroundColor = "#F2F2F2";
	} 
	else 
	{
			_div.style.cursor = 'default';
			_div.style.backgroundColor = "#FFFFFF";
	}		
}	


function setHighlight2 (_div, _action)
{
	if (_action == "over" || _action == "click") 
	{
			_div.style.cursor = 'pointer';
			_div.style.backgroundColor = "#FFFFFF";
	} 
	else 
	{
			_div.style.cursor = 'default';
			_div.style.backgroundColor = "#F2F2F2";
	}		
}	


function setHighlight3 (_div, _action)
{
	if (_action == "over" || _action == "click") 
	{
			_div.style.cursor = 'pointer';
	} 
	else 
	{
			_div.style.cursor = 'default';
	}		
}	




function putIframe(UL, ifr) {
  // Je pense que, logiquement, il ne devrait pas y avoir à faire de distinction entre les 2 cas
  // Mais je n'ai pas trouvé comment faire autrement.
	
	ifr.style.display = 'block';
  // zIndex inférieur à celui du menu
  ifr.style.zIndex = 50;

    // Il ne devrait donc y avoir qu'une partie ressemblant à celle là dans la fonction
    ifr.style.width = UL.offsetWidth;
  	ifr.style.height = UL.offsetHeight;
  	ifr.style.top = UL.offsetTop; // 35 : Hauteur des onglets
  	ifr.style.left = UL.offsetLeft;
}

function hover(obj, ifr, mode) {
  if (document.all) {
    var UL = obj.getElementsByTagName('ul');
    if (UL.length > 0) {
      var sousMenu = UL[0].style;
      if(mode == 1) 
	  {
        sousMenu.display = 'block';
        putIframe(UL[0], ifr);
      }
      else 
	  {
        sousMenu.display = 'none';
        ifr.style.display = 'none';
      }
    }
  }
}

function setHover() {
  var LI = document.getElementById('nav').getElementsByTagName('li');
  var nLI = LI.length;

  var m_ifr = document.getElementById('menuIFrame');

  for (var i = 0; i < nLI; i++) {
      LI[i].onmouseover = function() {
        hover(this, m_ifr, 1);
      }

      LI[i].onmouseout = function() {
        hover(this, m_ifr , 0);
      }
  }
}


function checkCommentForm () 
{
	var ret = true;
	if ($("input[name='name']").val() == '')
	{
		ret = false;
	}

	if ($("textarea[name='comment_text']").val() == '')
	{
		ret = false;
	}

	if ($("input[name='comment_code']").val() == '')
	{
		ret = false;
	}
	
	if ($("input[name='comment_email']").length > 0)
	{
		if ($("input[name='comment_email']").val() == '')
		{
			ret = false;
		}
	}
	
	if (!ret)
	{
		alert ('Tous les champs doivent être remplis !');
		return (false);
	}

	return true;
}
