/* Written By Christian K. Hu */

var  lang ;

function Center ()
{

   var xwidth = screen.availWidth ;
   var xheight = screen.availHeight ;
   var percent = 0 ;

   if ( xwidth > 1150 )
   {
      percent = (xwidth - 950) / xwidth * 50 ;
      $('bdmain').style.marginLeft = parseInt(percent) +'%' ;

      percent = (xheight - 700) / xheight * 50 ;
      $('bdmain').style.marginTop = parseInt(percent) +'%' ;

    }


 }

function MenuOver (e)  {
  var
     elmt = this.id ;

     if (elmt)
     {
     }
     else {
       elmt = e.srcElement.id ;
     }

   document.getElementById (elmt).style.backgroundImage="url(images/"+elmt+".gif)" ;
  }

function MenuOut (e)  {
  var
     elmt = this.id ;

     if (elmt)
     {
     }
     else {
       elmt = e.srcElement.id ;
     }
    document.getElementById (elmt).style.backgroundImage="" ;

  }

function HideBulle ()
{
   $('divBulle').style.visibility = 'hidden' ;
}

function showrevue (item)
{
    
     var X= event.x+document.body.scrollLeft ;
     var Y = event.y+document.body.scrollTop ;

      $('divBulle').innerHTML = item ;
      $('divBulle').style.visibility = 'visible' ;

      if (X < 0 ) X = 0 ;

     $('divBulle').style.top=Y-5+'px' ;
     $('divBulle').style.left=X-20+'px' ;

 }
 
 
function showvideolist ()
{
  $('videolist').style.visibility = "visible" ;

 }


function InitMenu ()
{

 var workdir = '' ;
 var txt = '' ;
 
 Center () ;

 txt =  $('lang').childNodes[0].nodeValue ;
 
 lang =  txt.lastIndexOf ("EN") < 0 ? "en" : "fr"  ;



 Event.observe('wet1' ,'mouseover' ,MenuOver ) ;
 Event.observe('wet2' ,'mouseover' ,MenuOver ) ;
 Event.observe('wet3' ,'mouseover' ,MenuOver ) ;
 Event.observe('wet4' ,'mouseover' ,MenuOver ) ;

 Event.observe('wet1' ,'mouseout' ,MenuOut ) ;
 Event.observe('wet2' ,'mouseout' ,MenuOut ) ;
 Event.observe('wet3' ,'mouseout' ,MenuOut ) ;
 Event.observe('wet4' ,'mouseout' ,MenuOut ) ;

  new Effect.Opacity('planshadow',
    { duration: 1.0,
      transition: Effect.Transitions.linear,
      from: 0.5, to: 0.9 });


 workdir = lang+'/' ;


 if ( lang == 'en' ) {
    $('video').style.backgroundImage = 'url(images/video_en.jpg)' ;
    $('videof').style.backgroundImage = 'url(images/allvideos_en.jpg)' ;
  } else {
    $('video').style.backgroundImage = 'url(images/video.jpg)' ;
    $('videof').style.backgroundImage = 'url(images/allvideos.jpg)' ;
  }

 Event.observe('logo' ,'click' ,function () {
   window.location.href ='index.php';    } ) ;

 Event.observe('wet1' ,'click' ,function () { window.location.href = workdir+'etud1.html'; } ) ;
 Event.observe('wet2' ,'click' ,function () { window.location.href = workdir+'etud2.html'; } ) ;
 Event.observe('wet3' ,'click' ,function () { window.location.href = workdir+'etud3.html'; }  ) ;
 Event.observe('wet4' ,'click' ,function () { window.location.href = workdir+'etud4.html'; } ) ;
 Event.observe('videof' ,'click' ,function () {
                         $('videolist').style.visibility = 'visible' ;
   } ) ;

 Event.observe('videolistcls' ,'click' ,function () {
                         $('videolist').style.visibility = 'hidden' ;
   } ) ;



 Event.observe('accinfo' ,'click' ,function () {
      window.location.href=workdir+'infos.html';
         } ) ;


 Event.observe('connect' ,'click' ,function () {

     if ( $('code').value == '' || $('pwd').value == ''
          || $('code').value == 'code privilège' ||  $('pwd').value == 'Mot de passe' )

          alert ( lang == 'en' ? 'Please enter correct informations ...  ':'Veuillez bien renseigner les champs') ;

     else
       $('connectform').submit() ;
                         
     } ) ;


 Event.observe('seekbtn' ,'click' ,function () {
   var str = $('searchit').value ;

   if ( str.length > 3 )
   {
      window.location.href = 'search.php?searchkey='+str+'&lang='+lang ;
    }
   else
     if  ( lang == 'en' )
         alert ('Please enter a bigger word') ;
     else
         alert ('Veuillez entrer un plus grand mot') ;

   } ) ;

 Event.observe('searchit' ,'focus' ,function() { $('searchit').value ="" ;  } ) ;
 Event.observe('searchit' ,'keydown' ,function(e) {

  var str = $('searchit').value ;
  var isTouche = false ;
  var touche=e.which;


  if ( touche == 13 ) { isTouche = true ; }

   if ( isTouche == true  ||  event.keyCode == 13 )

   {

         if ( str.length > 3 )
         {
            window.location.href = 'search.php?searchkey='+str+'&lang='+lang ;
          }
         else
           if  ( lang == 'en' )
               alert ('Please enter a bigger word') ;
           else
               alert ('Veuillez entrer un plus grand mot') ;


     }


 } ) ;



 Event.observe('accreg' ,'click' ,function () { window.location.href =workdir+'register.html'; } ) ;

 Event.observe('code' ,'focus' ,function () { $('code').value ="" ; } ) ;
 Event.observe('pwd' ,'focus' ,function () { $('pwd').value ="" ; } ) ;

 Event.observe('pwd'  ,'keydown' ,function(e) {

  var isTouche = false ;
  var touche=e.which;

  if ( touche == 13 ) { isTouche = true ; }

   if ( isTouche == true  ||  event.keyCode == 13 )
   {

         if ( $('code').value == '' || $('pwd').value == ''
              || $('code').value == 'code privilège' ||  $('pwd').value == 'Mot de passe' )

              alert ( lang == 'en' ? 'Please enter correct informations ...  ':'Veuillez bien renseigner les champs') ;

         else
           $('connectform').submit() ;

      }

 } ) ;



 Event.observe('video' ,'click' ,function () {
    $('midf').style.visibility = 'hidden';

    $('videof').style.visibility = 'visible';
    $('playercls').style.visibility = 'visible';
    LaunchPlayer ('main') ;
    } ) ;

 Event.observe('playercls' ,'click' ,function () {
    $('midf').style.visibility = 'visible';
    $('videof').style.visibility = 'hidden';
    $('player').style.visibility = 'hidden';
    $('playercls').style.visibility = 'hidden';


    } ) ;


 Event.observe('plantext' ,'click' ,function () {
    new Effect.Appear('plan' , {duration:0 } ) ;
    $('plan').style.visibility = 'visible';
    $('planshadow').style.visibility = 'visible';

   } ) ;

 Event.observe('plancls' ,'click' ,function () {

    new Effect.SlideUp( 'plan' , {duration:1.0 } ) ;

    $('planshadow').style.visibility = 'hidden';

   } ) ;

   
   
   Event.observe('oubli' ,'click' , function ()
        {
          $('forgetbox').style.visibility = 'visible' ;
    } ) ;
  Event.observe('cancel' ,'click' , function ()
        {
          $('forgetbox').style.visibility = 'hidden' ;
    } ) ;

  Event.observe('send' ,'click' , function ()
        {
           if ( $('cp1').value == '' )
                 alert ('Veuillez renseigner votre compte ...') ;
           else
                  $('forgotten').submit () ;

    } ) ;




}

function loadFunctions() {  InitMenu () ; }

Event.observe(window ,'load' ,loadFunctions ) ;
