


function Init()
{
   // Menus.Init();
    Ajax.Init();
    Panel.Init();
    Subscribe.Init();
    Video.Init();
   
}

/**                  SECTION AJAX                      **/
var Ajax = [];
Ajax.Count = 0;
Ajax.Init =  function()
{
    Ajax.Title = document.title;
    Ajax.Content = document.getElementById("Conteneur");
    Ajax.Url =location.href.substring(0,location.href.lastIndexOf("/")+1);
    //alert(Ajax.Url);
    
    if(Ajax.Content!=null)
    {
        if(window.XMLHttpRequest)  
            Ajax.XMLHttpRequest = new XMLHttpRequest();   
        else if(window.ActiveXObject) // Internet Explorer   
            Ajax.XMLHttpRequest = new ActiveXObject("Msxml2.XMLHTTP"); 
        
        if(Ajax.XMLHttpRequest!=null)
        {
            Ajax.XMLHttpRequest.onreadystatechange = Ajax.OnGetPage;
            Ajax.PatchAnchor(document);
            
            if(location.hash!=null && location.hash.length>1)
            {
                //alert(location.hash.substring(1));
                Ajax.LoadPage(location.hash.substring(1));
               
            }
            
        }
        
        
       
        
    }

}

Ajax.PatchAnchor = function(root)
{
    var reg=new RegExp("("+Ajax.Url+")", "g");
    var anchors = root.getElementsByTagName("A");
    //alert("anchor found :"+ anchors.length);
    for(var i=0;i<anchors.length;i++)
    {
        if(anchors[i].target!="_blank")
        {
            anchors[i].source = anchors[i].href.replace(reg,"");
            anchors[i].href = "#";
            anchors[i].onclick =  Ajax.OnAnchorClick;
        }
    }
    
}

Ajax.OnAnchorClick = function()
{
    Ajax.LoadPage(this.source);
}

Ajax.LoadPage = function(href)
{
    
    var url = "" 
    if(href.indexOf("?")>0)
    {
        Ajax.Params = href.substring(href.indexOf("?")+1);
        url = "get.php?page="+href.substring(0,href.indexOf("?"));
    }
    else
    {
        Ajax.Params=null;
        url = "get.php?page="+href;
    }
       
    
     
      
    Ajax.XMLHttpRequest.open("GET", url, true);
    Ajax.XMLHttpRequest.send(null);
    
    if(Ajax.XMLHttpRequest!=null)
        Ajax.XMLHttpRequest.onreadystatechange = Ajax.OnGetPage;
    //Ajax.Content.innerHTML = ""; //"<div id=\"Content\" style=\"padding-top : 100px\"><center><img src=\"images/radar.gif\" /><p>LOADING</p></center></div>";
    
    
}
//Ajax.count = 0;
Ajax.OnGetPage = function()
{
    if(Ajax.XMLHttpRequest.readyState == 4)
    { 
    
       
        if(Ajax.XMLHttpRequest.status==200)
        {
           Ajax.Content.innerHTML = Ajax.XMLHttpRequest.responseText;
           document.title = Ajax.Title ;
           Ajax.PatchAnchor(Ajax.Content);
           Video.Init();
           if(Ajax.Params!=null)
                Brochure.Init(Ajax.Params);
           else
                Contact.Init();
           
        }
        else
        {
             alert(Ajax.XMLHttpRequest.status);
            //Contact.Form.innerHTML = "<br/><p>Your message was not sent properly, please try again.</p> <br/><br/>";
        }  
        
        if(window.ActiveXObject) // Internet Explorer   
        {
            Ajax.XMLHttpRequest = new ActiveXObject("Msxml2.XMLHTTP"); 
            Ajax.XMLHttpRequest.onreadystatechange = Ajax.OnGetPage;
        } 
        
    }
}



/**                 SECTION CONTACT                    **/
var Contact = [];
Contact.Init =  function()
{
   
    Contact.Form = document.getElementById("FormContact");
    if(Contact.Form!=null)
    {
        if(window.XMLHttpRequest)  
            Contact.XMLHttpRequest = new XMLHttpRequest();   
        else if(window.ActiveXObject) // Internet Explorer   
            Contact.XMLHttpRequest = new ActiveXObject("Microsoft.XMLHTTP"); 
        
        if(Contact.XMLHttpRequest!=null)
        {
            //Contact.XMLHttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");  
            Contact.XMLHttpRequest.onreadystatechange = Contact.OnSubmiting;

        
        }
        
        var inputs = Contact.Form.getElementsByTagName("INPUT");
        for(var i=0;i<inputs.length;i++)
        {
            Contact.InitField(inputs[i]);
          
            if(inputs[i].name == "Name")
                Contact.Name = inputs[i];
            else if(inputs[i].name == "Company")
                Contact.Company = inputs[i];
            else if(inputs[i].name == "Phone")
                Contact.Phone = inputs[i];
            else if(inputs[i].name == "Email")
                Contact.Email = inputs[i];
            else if(inputs[i].name == "Submit")
                inputs[i].onclick = Contact.Submit;
            
         }
         
         Contact.Message = Contact.Form.getElementsByTagName("textarea")[0];
         Contact.InitField(Contact.Message);
    }
}

Contact.InitField = function(field)
{
   
   var spans = field.parentNode.getElementsByTagName("SPAN");
   if(spans.length>0)
   {
        field.onkeyup = Contact.TextChange;
        field.span = spans[0];
        //field.span.style.display = "none";
        field.ShowSpan = Contact.ShowSpan;
        field.HideSpan = Contact.HideSpan;
   }
   
}

Contact.TextChange = function()
{
   if(this.value.length>0)
   {
      this.HideSpan();
   }
}

Contact.ShowSpan =  function()
{
   this.span.style.display = "inline";
}

Contact.HideSpan = function()
{
   this.span.style.display = "none";
}


Contact.Submit =  function()
{
    
    var send = true;
  
    if(Contact.Name.value.length==0)
    {
         Contact.Name.ShowSpan();
         send = false;
    }
    if(Contact.Email.value.length==0)
    {
         Contact.Email.ShowSpan();
         send = false;
    }
    if(Contact.Message.value.length==0)
    {
         Contact.Message.ShowSpan();
         send=false;
    }
    
    if(send && Contact.XMLHttpRequest!=null)
    {
        //alert(Contact.XMLHttpRequest.setRequestHeader);
        //http.setRequestHeader("Content-length", params.length);
        //http.setRequestHeader("Connection", "close");
        var params = "name="+ escape(Contact.Name.value) +
                     "&company="+escape(Contact.Company.value) + 
                     "&phone="+escape(Contact.Phone.value) +
                     "&email="+escape(Contact.Email.value) +
                     "&message="+escape(Contact.Message.value);
                 
        Contact.XMLHttpRequest.open("GET", "/Content/About-us/Contact.php?"+params, true);
        //Contact.XMLHttpRequest.setRequestHeader("Content-type : application/x-www-form-urlencoded");
              
           // Contact.XMLHttpRequest.setRequestHeader("Content-length", params.length);
           // Contact.XMLHttpRequest.setRequestHeader("Connection", "close");
       
        Contact.XMLHttpRequest.send(null);
    }   
   
}
 
Contact.OnSubmiting = function()
{
    if(Contact.XMLHttpRequest.readyState == 4)
    { 
      //  alert(Contact.XMLHttpRequest.responseText);
        if(Contact.XMLHttpRequest.responseText=="ok")
        {
            Contact.Form.innerHTML = "<br/><p>Your message has been sent to our sales team, thanks for your business.</p> <br/><br/>";
        }
        else
        {
            Contact.Form.innerHTML = "<br/><p>Your message was not sent properly, please try again.</p> <br/><br/>";
        } 
        
        if(window.ActiveXObject) // Internet Explorer   
        {
            Contact.XMLHttpRequest = new ActiveXObject("Msxml2.XMLHTTP"); 
            Contact.XMLHttpRequest.onreadystatechange = Contact.OnSubmiting;
        }   
        
    }
}


/**                 SECTION BROCHURE REQUEST                    **/
var Brochure = [];
Brochure.Init =  function(doc)
{
   
   Brochure.Doc  = doc;
   document.getElementById("Doc").innerHTML =  doc;
    Brochure.Form = document.getElementById("FormRequest");
    if(Brochure.Form!=null)
    {
        if(window.XMLHttpRequest)  
            Brochure.XMLHttpRequest = new XMLHttpRequest();   
        else if(window.ActiveXObject) // Internet Explorer   
            Brochure.XMLHttpRequest = new ActiveXObject("Microsoft.XMLHTTP"); 
        
        if(Brochure.XMLHttpRequest!=null)
        {
            //Contact.XMLHttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");  
            Brochure.XMLHttpRequest.onreadystatechange = Brochure.OnSubmiting;

        
        }
        
        var inputs = Brochure.Form.getElementsByTagName("INPUT");
        for(var i=0;i<inputs.length;i++)
        {
            Brochure.InitField(inputs[i]);
          
            if(inputs[i].name == "Name")
                Brochure.Name = inputs[i];
            else if(inputs[i].name == "Company")
                Brochure.Company = inputs[i];
            else if(inputs[i].name == "Phone")
                Brochure.Phone = inputs[i];
            else if(inputs[i].name == "Email")
                Brochure.Email = inputs[i];
            else if(inputs[i].name == "Submit")
                inputs[i].onclick = Brochure.Submit;
            
         }
         
         Brochure.Message = Brochure.Form.getElementsByTagName("textarea")[0];
         Brochure.InitField(Brochure.Message);
    }
}

Brochure.InitField = function(field)
{
   
   var spans = field.parentNode.getElementsByTagName("SPAN");
   if(spans.length>0)
   {
        field.onkeyup = Brochure.TextChange;
        field.span = spans[0];
        //field.span.style.display = "none";
        field.ShowSpan = Brochure.ShowSpan;
        field.HideSpan = Brochure.HideSpan;
   }
   
}

Brochure.TextChange = function()
{
   if(this.value.length>0)
   {
      this.HideSpan();
   }
}

Brochure.ShowSpan =  function()
{
   this.span.style.display = "inline";
}

Brochure.HideSpan = function()
{
   this.span.style.display = "none";
}


Brochure.Submit =  function()
{
    
    var send = true;
  
    if(Brochure.Name.value.length==0)
    {
         Brochure.Name.ShowSpan();
         send = false;
    }
    if(Brochure.Email.value.length==0)
    {
         Brochure.Email.ShowSpan();
         send = false;
    }
    if(Brochure.Company.value.length==0)
    {
         Brochure.Company.ShowSpan();
         send=false;
    }
    
    if(send && Brochure.XMLHttpRequest!=null)
    {
        //alert(Contact.XMLHttpRequest.setRequestHeader);
        //http.setRequestHeader("Content-length", params.length);
        //http.setRequestHeader("Connection", "close");
        var params = "name="+ escape(Brochure.Name.value) +
                     "&doc="+escape(Brochure.Doc) + 
                     "&company="+escape(Brochure.Company.value) + 
                     "&phone="+escape(Brochure.Phone.value) +
                     "&email="+escape(Brochure.Email.value) +
                     "&message="+escape(Brochure.Message.value);
                 
        Brochure.XMLHttpRequest.open("GET", "/Content/Product/BrochureRequest.php?"+params, true);
   
       
        Brochure.XMLHttpRequest.send(null);
    }   
   
}
 
Brochure.OnSubmiting = function()
{
    if(Brochure.XMLHttpRequest.readyState == 4)
    { 
      //  alert(Contact.XMLHttpRequest.responseText);
        if(Brochure.XMLHttpRequest.responseText=="ok")
        {
            Brochure.Form.innerHTML = "<br/><p>Your request has been sent to our sales team, thanks for your business.</p> <br/><br/>";
        }
        else
        {
            Brochure.Form.innerHTML = "<br/><p>Your request was not sent properly, please try again.</p> <br/><br/>";
        } 
        
        if(window.ActiveXObject) // Internet Explorer   
        {
            Brochure.XMLHttpRequest = new ActiveXObject("Msxml2.XMLHTTP"); 
            Brochure.XMLHttpRequest.onreadystatechange = Brochure.OnSubmiting;
        }   
        
    }
}
 

/**                  SECTION PANEL                     **/
var Panel = [];
Panel.Init =  function()
{
    
    if(window.ActiveXObject) // Internet Explorer  
    {
        
        var table = document.getElementById("Panel");
        if(table != null )
        {
            table.style.height = '500px';                  
        }
    }
}

/**                  SECTION MENUS                     **/

var Menus = [];

Menus.Init =  function()
{
    var divMenu = document.getElementById("Menu");
    if(divMenu!=null)
    {
        for(var i=0; i<divMenu.childNodes.length; i++)
        {
            var node = divMenu.childNodes[i];
            if(node.nodeType == 1 && node.className =="categorie")
            {
              
               node.divSubMenu = null;
               for(var k=0; k<node.childNodes.length; k++)
               {
                    if(node.childNodes[k].nodeType == 1)
                    {
                       node.childNodes[k].style.width = node.style.width;
                       if(node.childNodes[k].nodeName=="DIV")
                       {
                            node.divSubMenu = node.childNodes[k];
                            node.onmouseover = Menus.PopupOpen;
                            break;
                       }
                    }
                     
               }
               
            }
        }
    }
    

}

Menus.PopupOpen = function()
{
    this.onmouseover = null;
    this.divSubMenu.style.display = "block";
    this.onmouseout = Menus.PopupClose;
}
Menus.PopupClose = function()
{
    this.onmouseout = null;
    this.divSubMenu.style.display = "none";
    this.onmouseover = Menus.PopupOpen;
}

/**                  SECTION ABONNEMENT NEWSLETTER                      **/
var Subscribe = [];

Subscribe.Init =  function()
{
    if(window.XMLHttpRequest)  
        Subscribe.XMLHttpRequest = new XMLHttpRequest();   
    else if(window.ActiveXObject) // Internet Explorer   
        Subscribe.XMLHttpRequest = new ActiveXObject("Microsoft.XMLHTTP"); 
    
    if(Subscribe.XMLHttpRequest!=null)
    {
        Subscribe.XMLHttpRequest.onreadystatechange = Subscribe.OnSubscribing;
    }
    
    Subscribe.Input = document.getElementById("subscriber");
    Subscribe.Button = document.getElementById("subscribe");
    
    if(Subscribe.Input!=null)
    {
        Subscribe.Input.onfocus = Subscribe.Focus;
    }
    if(Subscribe.Button!=null)
    {
       Subscribe.Button.onclick = Subscribe.Action;
    }
}

Subscribe.Focus =  function()
{
    if(Subscribe.Input!=null)
        Subscribe.Input.select();
    if(Subscribe.Button!=null)
        Subscribe.Button.disabled=false;
}

Subscribe.Action = function()
{
    if(Subscribe.Input!=null && Subscribe.XMLHttpRequest!=null)
    {
        Subscribe.XMLHttpRequest.open("GET", "SubscribeNews.php?mail="+escape(Subscribe.Input.value), true);
        Subscribe.XMLHttpRequest.send(null);
        //alert(escape(Subscribe.Input.value));
    }
}

Subscribe.OnSubscribing = function()
{
    if(Subscribe.XMLHttpRequest.readyState == 4)
    { 
        if(Subscribe.XMLHttpRequest.responseText=="ok")
        {
            alert("Your newsletter subscription has been sent !\nThank you");
        }
        else
        {
            alert("Your newsletter subscription failed ... !");
        }  
        
        if(window.ActiveXObject) // Internet Explorer   
        {
            Subscribe.XMLHttpRequest = new ActiveXObject("Msxml2.XMLHTTP"); 
            Subscribe.XMLHttpRequest.onreadystatechange = Subscribe.OnSubscribing
        }    
        
    }
}


/**                  SECTION VIDEO                      **/
var Video = [];

Video.Location = "http://www.pegase-systems.com/Content/Videos/";

Video.Init =  function()
{
    Video.Player = document.getElementById("VideoPlayer");
    if(Video.Player != null)
    {
       var list = document.getElementById("VideoList").getElementsByTagName("DIV");
       //alert(list.length);
       for(var i=0;i<list.length;i++)
       {
           var video = list[i].getAttribute("video");
           if(video!=null)
           {
                list[i].Video = video;
                list[i].onclick =  Video.OnClick;
           }
           
       }
    }
}

Video.OnClick =  function()
{
    //alert("video : " + Video.Location+this.Video);
    Video.Player.SetVariable("player:jsStop", "");
    Video.Player.SetVariable("player:jsUrl", Video.Location+this.Video);
    Video.Player.SetVariable("player:jsPlay", "");
 
}


// Correctif de l'affichage des images PNG dans IE5.5 et IE6 (transparent pour les autres navigateurs).
// V1.1 par Brice de Villeneuve, http://www.boursica.com/
// Licence : freeware, librement utilisable du moment que vous laissez ces commentaires dans votre source.
// Mettre ce script dans le head et dans les balises IMG ajouter simplement : onload='setpng(this)'
// Si l'image n'est pas visible (display:none par exemple), appeler la fonction juste après l'affichage de l'image
// dans un javascript avec, par exemple, un setpng(document.getElementById('idDeMonImage');
function setpng(img) 
{ 
  if(document.all && (IEver=parseFloat(navigator.appVersion.split("MSIE")[1])) && (IEver>=5.5) && (IEver<7) && document.body.filters && img) 
  {
	imgName=img.src.toUpperCase();
	if(imgName.substring(imgName.length-3,imgName.length)=="PNG") 
	    img.outerHTML=
		"<span "+(img.id?"id='"+img.id+"' ":"")+(img.className?"class='"+img.className+"' ":"")+(img.title?"title=\""+img.title+"\" ":"")
		+"style=\"width:"+img.width+"px;height:"+img.height+"px;"+(img.align=="left"?"float:left;":(img.align=="right"?"float:right;":""))
		+(img.parentElement.href?"cursor:hand;":"")+"display:inline-block;"+img.style.cssText+";"
		+"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+img.src+"',sizingMethod='scale');\"></span>";
  }
}
