﻿// JScript File
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_beginRequest(beginRequest);
prm.add_endRequest(EndRequest);
var postbackElement;
var position =1;
var timeout ;
var boutonsav;
var parentBouton;
var imgloading ;
function beginRequest(sender, args){
try {
    prm._scrollPosition = null;
    postbackElement = args.get_postBackElement();
    if(typeof(postbackElement) === "undefined")
        return;
    
   if(postbackElement.id.toLowerCase().indexOf('iphone')>-1)
   {
     $get('_inc_config_news_lbl_data').innerHTML ="";
     $get('_inc_config_news_lbl_data').style.display = "none";
     $get('_inc_config_news_lbl_data2').innerHTML = "Upload des fichiers...";
  
      boutonsav = $get(postbackElement.id);
      parentBouton =$get(postbackElement.id).parentNode;
      parentBouton.removeChild(boutonsav);
      var newtext=document.createTextNode("Upload ...");
      var br = document.createElement('br');
      imgloading =document.createElement('img');
      imgloading.src = '../img/ajax-loader.gif';
      imgloading.width ='220';
      imgloading.height ='19';
      parentBouton.appendChild(newtext);
       
      parentBouton.appendChild(imgloading);
     
     
    /* $get(postbackElement.id).disabled =true;
     $get(postbackElement.id).value = "chargement...";*/
     $get('_inc_config_news_dtg_liste').disabled =true;
   }
    if(postbackElement.id.toLowerCase().indexOf('lnk_href_home')>-1 ||postbackElement.id.toLowerCase().indexOf('lnk_section_videosxx') >-1 ){
   
     if($get("loading_img") != null){$get("loading_img").style.display = "block";}
     if($get("fondloading")!=null){
     $get("fondloading").style.backgroundColor = "#000000";
     $get("fondloading").style.display = "block";
     }
     if($get("fondloading2")!=null){
     $get("fondloading2").style.backgroundColor = "#000000";
     $get("fondloading2").style.display = "block";
     }
     
   }
  }
  
  catch(err)
  {
  
  }
}

 function EndRequest(sender, args) {
 try
 {
      if (args.get_error() != null)
       {
           var errorName = args.get_error().name;
           if (errorName.length > 0 )
           {
             if(timeout != null)
              {
                clearInterval (timeout);
              }
              args.set_errorHandled(true);
         
           }
       }

       else
       {
            if(postbackElement.id.toLowerCase().indexOf('iphone')>-1)
           {
              // $get(postbackElement.id).disabled =false;
              //parentBouton.removeChild(imgloading);
            //  parentBouton.appendChild(boutonsav);
              
               $get('_inc_config_news_dtg_liste').disabled =false;
               $get('_inc_config_news_lbl_file').innerHTML ="<b>Les fichiers publiés sont :</b><br />"+$get('_inc_config_news_lbl_file').innerHTML;
               $get('_inc_config_news_lbl_filehome').innerHTML ="<br /><br /><b>Les fichiers publiés en home :</b><br />"+$get('_inc_config_news_lbl_filehome').innerHTML;
              
               $get('_inc_config_news_lbl_data2').innerHTML ="";
               $get('_inc_config_news_lbl_data').innerHTML = "<br />"+   $get('_inc_config_news_lbl_data').innerHTML;
               $get('_inc_config_news_lbl_data').style.display = "block";
           }
       
        if(postbackElement.id.toLowerCase().indexOf('lnk_href_home')>-1 || postbackElement.id.toLowerCase().indexOf('lnk_section_videos') >-1){
         
         if($get("loading_img") != null){$get("loading_img").style.display = "none";}
        if($get("fondloading")!=null){
        $get("fondloading").style.backgroundColor = "#000000";
        $get("fondloading").style.display = "none";
        }
        if($get("fondloading2")!=null){
        $get("fondloading2").style.backgroundColor = "#000000";
        $get("fondloading2").style.display = "none";
        }
        
       }
   
   }
   
 }
 catch(err)
 {
 
 }

}
function stop()
{
  PageMethods.stop(OnSucceeded, OnFailed);
}
function NbrefoisVu(idnews){

        PageMethods.NbrefoisVu(idnews,OnSucceeded, OnFailed);
}
function OnSucceeded(result, userContext, methodName) {
    
       
    
}

function OnFailed(error, userContext, methodName) {
    if (error !== null) {
       
       alert( error.get_message());
    }
}
 function sleep(delay)
{
    var start = new Date().getTime();
    while (new Date().getTime() < start + delay);
}

function carousellite()
{
  

  
  var liste = $get("sections").getElementsByTagName("LI");
  var codeaexecuter;
  var motif1 = /NbrefoisVu\(\'\d+\'\);/;
 
     if(position<liste.length)
        {
            for(j =0;j<liste[position].childNodes.length;j++)
            {
           
             if(liste[position].childNodes[j].tagName !=null)
             {
                   
                if(liste[position].childNodes[j].tagName == "A")
                {
                    if( liste[position].childNodes[j].className == "home_video_a tv")
                    {
                        
                      if(navigator.appVersion.indexOf("MSIE") >-1  )
                      {
                                
                         codeaexecuter =liste[position].childNodes[j].attributes.item("onclick").value;
                      }
                      else if(navigator.appVersion.indexOf("Gecko") >-1)
                      {
                        codeaexecuter =liste[position].childNodes[j].attributes.item(2).nodeValue;
                      }
                       else
                      {
                         codeaexecuter =  liste[position].childNodes[j].attributes[0].nodeValue;
                      }
                         codeaexecuter =  codeaexecuter.replace(motif1,"");
                         codeaexecuter = codeaexecuter.replace("return false;","");
                         if(position - 1 > -1)
                         {
                            liste[position - 1].className = "";
                         
                         }
                         liste[position].className = "suphover";
                         
                         eval(codeaexecuter);
                     
                       position =  position + 1;
                       return;
                    }
                    if( liste[position].childNodes[j].className == "home_actu_a")
                    {
                 
                      codeaexecuter =   liste[position].childNodes[j].href;
                      codeaexecuter = codeaexecuter.replace(motif1,"");
                      codeaexecuter = codeaexecuter.replace("return false;","");
                      if(position - 1 > -1)
                       {
                            liste[position - 1].className = "";
                         
                       }
                      liste[position].className = "suphover";
                      eval(codeaexecuter );
                      position =  position + 1;
                    
                      return;
                    }
                    
                 

                 }
                 
               }
                
             }
            
        
        }
        else
        
        {
        //on recommence en cas de fin
   
         position = 0;
      
        }
       

  
  
  
}
//function carousellite()
//{

//  var liste = $get("sections").getElementsByTagName("LI");
//  var codeaexecuter;
//  var motif1 = /NbrefoisVu\(\'\d+\'\);/;
//  for(i =1;i<liste.length;i++)
//  {
//   
//    for(j =0;j<liste[i].childNodes.length;j++)
//    {

//        if(liste[i].childNodes[j].tagName == "A")
//        {
//            if( liste[i].childNodes[j].className == "home_video_a tv")
//            {
//                 codeaexecuter =  liste[i].childNodes[j].attributes[0].nodeValue;
//             
//                codeaexecuter =  codeaexecuter.replace(motif1,"");
//            
//                 eval(codeaexecuter.replace("return false;",""));
//               
//                
//              
//              
//            
//            }
//            if( liste[i].childNodes[j].className == "home_actu_a")
//            {
//              codeaexecuter =   liste[i].childNodes[j].href;
//              codeaexecuter = codeaexecuter.replace(motif1,"");
//              eval(codeaexecuter.replace("return false;",""));
//             
//             
//            }
//            
//           
//        }
//        
//        
//         break;
//        
//     
//    }
//       

//  
//  }
//  
//}

function loading()
{
  
  $get("sections").getElementsByTagName("LI")[0].className = "suphover";
  timeout = setInterval ("carousellite();",8500/*7950*/);

}

function clearing()
{
 if(timeout != null)
  {
    clearInterval (timeout);
  }
   var liste = $get("sections").getElementsByTagName("LI");
   for(j =0;j<liste.length;j++)
    {
      liste[j].className = "";


    }
   if(prm !=null)
   prm.abortPostBack();

}