﻿// JScript File

var Library = new Object();

(function($)
{
    function init()
    {
        // gestion valeur par defaut des champs de formulaires
        $.autoInputDefault();
        
        if (document.getElementById("TAB")) Library.updateTab(null);
    }
    //$(init);
    
    /* GESTION TAB */
    
    var sendOpen = false;
    
    Library.updateTab = function(src)
    {
        if (src != null) 
        {
            $("#TAB").html(src);
            // gestion valeur par defaut des champs de formulaires
            $.autoInputDefault();
        }
        // ouvrir/fermer le champ "Envoyer a un amis"
        $("#TAB div.SendFriend .Toggle").click(toggleSendFriend);
    }
    Library.closeSendFriend = function()
    {
        if (sendOpen) $("#TAB div.SendFriend .Toggle").click();
    }
    
    function toggleSendFriend()
    {
        sendOpen = !sendOpen;
        $(this).parent().animate( { height: sendOpen ? 67 : 21 } );
    }
    
    
    /* GESTION FLASH SONDAGE */
    
    var sondageClosed = 85;
    var sondageNewId = 0;
    var sondageLocked = [];
    var sondageHeight = [];
    
    Library.registerSondage = function(id)
    {
        sondageLocked[id] = false;
        sondageHeight[id] = sondageClosed;
        $("#SondageContainer_" + id).mouseout(autoHideSondage);
    }
    
    function autoHideSondage(e) 
    {
        var id = $(e.target).attr("id");
        id = id.substr(id.indexOf("_")+1);
        if (!sondageLocked[id]) closeSondage(id);
    }
    
    Library.setFooterHeight = function(guid, height, locked)
    {
        var id = guid.split("-").join("");
        height = Math.round(height);
        if (isNaN(height) || sondageHeight[id] == height) return;
        sondageHeight[id] = height;
        sondageLocked[id] = locked;
        resizeSondage(id);
    }
    
    Library.closeFooter = function(guid) 
    { 
        var id = guid.split("-").join("");
        closeSondage(id); 
    }
    
    function closeSondage(id)
    {
        if (sondageHeight[id] == sondageClosed) return;
        sondageHeight[id] = sondageClosed;
        resizeSondage(id);
    }
    
    function resizeSondage(id)
    {
        if (sondageHeight[id] == sondageClosed) 
        {
            var movie = thisMovie("Sondage_" + id);
            if (movie && movie.closeFlashFooter) movie.closeFlashFooter();
        }
        
	    var dims = {
		    height:sondageHeight[id],
		    top:sondageClosed - sondageHeight[id]
	    };
	    $("#SondageContainer_" + id).animate(dims, 300);
    }
    
})(jQuery); 





 function checkMail(Email)
    {
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(Email))
	    {
	    return true;
	    }
	else
	    {
	    return false;
	    }
    }
    
function getObj(name)
	{
	if (document.getElementById)
		{
		return document.getElementById(name);
		}
	else if (document.all)
		{
		return document.all[name];
		}
	else if (document.layers)
		{
		return document.layers[name]; 
		}
	else return false;
	}

function afficher(lelay)
	{
	if(getObj(lelay))
		{
		var oLelay;
		oLelay= getObj(lelay)
		oLelay.style.visibility="visible";
		}
	else
		{
		setTimeout("afficher("+lelay+");",500);
		}
	}
	
function cacher(lelay)
    {
	if(getObj(lelay))
		{
		var oLelay;
		oLelay= getObj(lelay)
		oLelay.style.visibility="hidden";
	    }
	else
		{
		setTimeout("cacher("+lelay+");",500);
		}
    }  
 

function getWindowHeight() {
 var windowHeight = 0;
   if (typeof(window.innerHeight) == 'number') {
        windowHeight = window.innerHeight;
   }
        else {
          if (document.body && document.body.clientHeight) {
            windowHeight = document.body.clientHeight;
        }
        else {
          if (document.documentElement && document.documentElement.clientHeight) {
            windowHeight = document.documentElement.clientHeight;
          }
        }
   }
 return windowHeight;
}

	
	
	  
///////////////////////////////////////////////////////////////////
function CreateXHR()
    {
    try
        {
        XHR = new ActiveXObject("Msxml2.XMLHTTP");
        }
    catch(e)
        {
        try
            {
            XHR = new ActiveXObject("Microsoft.XMLHTTP");            
            }
        catch(E)
            {
            XHR = false;
            }    
        }
    if(!XHR && typeof XMLHttpRequest !='undifined')
        {
        XHR = new XMLHttpRequest();
        }    
    return XHR;
    }
///////////////////////////////////////////////////////////////////     