// ----------------------------------------------------------------------------------
// Only digits in field!
// ----------------------------------------------------------------------------------
function checkKey(field, evt) {
  var keyCode = 
    document.layers ? evt.which :
    document.all ? event.keyCode :
    document.getElementById ? evt.keyCode : 0;
  //alert(keyCode);
  if ((document.all || document.getElementById) && evt.shiftKey) {
    if (keyCode == 9) return true;
	return false;
  }
  if (document.layers && evt.modifiers & event.SHIFT_MASK) {
    if (keyCode == 9) return true;
	return false;
  }
  // 0 .. 9, 0 .. 9 on right keyboard, Backspace, Tab, End, Home, Left Arrow, Right Arrow, Del button
  if ((keyCode > 47 && keyCode < 58) || (keyCode > 95 && keyCode < 106) || keyCode == 8 || keyCode == 9 || keyCode == 35 || keyCode == 36 || keyCode == 37 || keyCode == 39  || keyCode == 46) return true;
  return false;
}
//-----------------------------------------------------------------------------------
//------------------------------------------------------------------------------------
// Script Anti-flash
//------------------------------------------------------------------------------------
function fixFlash(s) { document.write(s); }


//------------------------------------------------------------------------------------
// Fonction CacheMail
//------------------------------------------------------------------------------------

function CacheMail(mail,domain) {
	this.location = 'mailto:' + mail + '@'+ domain;
	}

// a rajouter au niveau des liens mailto ---> <a href="#" onclick="CacheMail('jerome','actisens.com')">test</a>

//------------------------------------------------------------------------------------
// Fonction TestParam()
//------------------------------------------------------------------------------------

function isCP(obj) {
	if (isNaN(obj.value)==false && obj.value.length==5)  return true;
	else return false;
}

function isTel(obj) {
	if (isNaN(obj.value)==false && obj.value.length==10)  return true;
	else return false;
}

function isEmail(obj) 
{
       if (obj.value.indexOf(" ") + "" == "-1"
       && obj.value.indexOf("@") + "" != "-1"
       && (obj.value.lastIndexOf(".") > obj.value.indexOf("@"))
       && obj.value != "") return true;
       else return false;
}

function RefreshCaptcha() {
	var i = new Image();
	var d = new Date();
	i.src = 'Includes/modCaptcha.asp?Type=4&Dt=' + d.getHours().toString() + d.getMinutes().toString() + d.getSeconds().toString() ;
	document.getElementById("Captcha").src =  i.src;
}

function RefreshCaptchaEch() {
	var i = new Image();
	var d = new Date();
	i.src = 'Includes/modCaptcha-etude-chifree.asp?Type=4&Dt=' + d.getHours().toString() + d.getMinutes().toString() + d.getSeconds().toString() ;
	document.getElementById("Captcha").src =  i.src;
}


//------------------------------------------------------------------------------------
// Script Notice légale
//------------------------------------------------------------------------------------
// s est l'année de création du site.
function showCPR(s) {
       var y = new Date().getYear();
       if (y<1900) y+=1900;
       if (s!=y)
          document.write(s + " - " + y);
	       else
          document.write(y);
}


function verifCode(obj) {
       return (obj.value == "") || (obj.value.length == 5 && !isNaN(obj.value));
	   //si le champ est vide, je retourne vrai (parce que ca n est pas un champ obligatoire)
	   // ou si le champ a une longueur de 5 caractères et que c'est un nombre, je returne vrai
}

//------------------------------------------------------------------------------------
// Rollovers
//------------------------------------------------------------------------------------

function RollOver() {
	document.getElementById('cliquezLogo').src="Images/Accueil/GPub-logo-blue.png";
	document.getElementById('cliquezLogoText').style.color="#008ACE";	
}

function RollOver_restore() {
	document.getElementById('cliquezLogo').src="Images/Accueil/GPub-logo.png";
	document.getElementById('cliquezLogoText').style.color="#8A8A8A";	
}

function RollOver2() {
	document.getElementById('cliquezLogo2').src="Images/Accueil/GPub-logo-orange.png";
	document.getElementById('cliquezLogoText2').style.color="#FF7901";	
}

function RollOver_restore2() {
	document.getElementById('cliquezLogo2').src="Images/Accueil/GPub-logo.png";
	document.getElementById('cliquezLogoText2').style.color="#8A8A8A";	
}

//-------------------------------------------------------------------------------
// Fonction Carousel logos
//-------------------------------------------------------------------------------	
	
	
	function mycarousel_initCallback(carousel) {
		carousel.clip.hover(function() {
			carousel.stopAuto();
		}, function() {
			carousel.startAuto();
		});
	};
	
	jQuery(document).ready(function() {		// IE7 bug!
		jQuery('#mycarousel').jcarousel({
			auto: 5,
			wrap: 'last'
		});
	}); 
	
	
	
//-------------------------------------------------------------------------------
// Fonction Rollover Saturation/Desaturation
//-------------------------------------------------------------------------------

//	$(document).ready(function () {

//	            $("img.a").hover(
//        function () {
//            if (!jQuery.browser.msie)
//                $(this).stop().animate({ "opacity": "0" }, "slow");
//            else
//                $(this).hide();
//        },
//        function () {
//            if (!jQuery.browser.msie)
//                $(this).stop().animate({ "opacity": "1" }, "slow");
////            else
////                $(this).show();
//        });

//	});



	$(document).ready(function () {
	    if (!jQuery.browser.msie) {
            $("img.a").hover(
                function () {
                if (!jQuery.browser.msie)
                    $(this).stop().animate({ "opacity": "0" }, "slow");
                else
                    $(this).hide();
                },
                function () {
                if (!jQuery.browser.msie)
                    $(this).stop().animate({ "opacity": "1" }, "slow");

            });
	    }
	    else
	        $("img.a").hide();

	});


//-------------------------------------------------------------------------------
// Fonction slider
//-------------------------------------------------------------------------------
	jQuery(document).ready(
	function()
	{
		$("div.scrollable").scrollable( { size: 7, clickable : false}); 	
		
		//Rotation du bandeau de la home
		$("#rotator").tabs({
			'fx': {opacity: "toggle"} //,
//			event : 'mouseover'
		}).tabs("rotate", 12000, true);

		// Pour chaque tab
		$(".ui-tabs-nav-item A").each(
			function(index, element) {
				// Sur le click
				$(element).click(
					function() {
						// On récupère l'attribut link
						var _link = $(element).attr('link');
						// On redirige la page vers le lien de link
						if (_link!='') location.href = _link;
					}
				)
			}
		);
		
		jQuery('.pics').cycle({ 
			fx: 'scrollHorz', 
   			delay: 500,
			speed: 400
			//easing:  'easeInOutElastic'
		});
		
		// Création des slides
		slide(1, 293);
		slide(2, 293);
		slide(3, 293);
		
//		// Positionne le menu au chargement de la page
//		positionnerMenu();
//		if(typeof(rub) != "undefined") {
//			positionnerActu(1, 386);
//			positionnerActu(2, 284);
//			positionnerActu(3, 232);
//		}
		
		jQuery(document).ready(function(){
			jQuery(".inline").colorbox({inline:true, href:"#inline_example1"});
			$(".iframe").colorbox({width:"850px", height:"670px", iframe:true});
		
		});
		
		 //Accordéon offres d'emploi
		 $('#list1a').accordion({
			autoheight: false,
			header: 'a.lienNavig',
			active : '.selected'
		});
		
	}
	);

//	// Lie la méthode resize de la fenêtre à la fonction positionnerPub
//	$(window).bind('resize',function(){
//		positionnerMenu();
//		positionnerActu(1, 386);
//		positionnerActu(2, 284);
//		positionnerActu(3, 232);
//	});
	
	// Création des slides
	function slide(item, width) {
		//Actualités emplacement 3
		$("#monslider" + item).wslide({
			width: width,
			height: 169,
			pos: 1,
			autolink: 'conteneur-menu' + item,
			horiz: true,
			duration: 500
        });


        var positionSlide1 = 0;
        function mouve() 
        {

            positionSlide1++;

            var start = '#monslider1-' + positionSlide1;


            $('a[href*="' + start + '"]').click();


            if ($('a[href*="' + start + '"]').length == 0) positionSlide1 = 0;
			
            setTimeout(function () {
                mouve();
            }, 50000);
			
			
        }

        var positionSlide2 = 0;
        function mouve2() {

            positionSlide2++;

            var start = '#monslider2-' + positionSlide2;

            $('a[href*="' + start + '"]').click();


            if ($('a[href*="' + start + '"]').length == 0) positionSlide2 = 0;

            setTimeout(function () {
                mouve2();
            }, 50000);
        }

        var positionSlide3 = 0;
        function mouve3() {

            positionSlide3++;

            var start = '#monslider3-' + positionSlide3;

            $('a[href*="' + start + '"]').click();


            if ($('a[href*="' + start + '"]').length == 0) positionSlide3 = 0;

            setTimeout(function () {
                mouve3();
            }, 50000);
        }


	     setTimeout(function () {
	         mouve(); mouve2(); mouve3();
	     }, 1000);
		 
		 
	}




	
	// Positionne la pub
	/*function positionnerMenu() {
		// Récupère le point de l'entête (top, left)
		var _point = $('#top-menu').position();
		// Positionne en absolue la publicité
		$('#menu').css('left', _point.left + 'px');
	}*/
	
//	// Positionne la pub
//	function positionnerActu(item, width) {
//		var _point = $('#infos' + item).position();
//		if (_point != null) {
//			var _o = $('#conteneur-menu' + item);
//				_o.css('top', _point.top + 93 + 'px');
//				_o.css('left', (_point.left + width - _o.width()) + 'px');
//		}
//	}




//-------------------------------------------------------------------------------
// Fonction menu du Header
//-------------------------------------------------------------------------------

	$(document).ready(function () {

	    function megaHoverOver() {
	        $(this).find(".sub").stop().fadeTo('fast', 1).show();

	        //Calculate width of all ul's
	        (function ($) {
	            jQuery.fn.calcSubWidth = function () {
	                rowWidth = 0;
	                //Calculate row
	                $(this).find("ul").each(function () {
	                    rowWidth += $(this).width();
	                });
	            };
	        })(jQuery);

	        if ($(this).find(".row").length > 0) { //If row exists...
	            var biggestRow = 0;
	            //Calculate each row
	            $(this).find(".row").each(function () {
	                $(this).calcSubWidth();
	                //Find biggest row
	                if (rowWidth > biggestRow) {
	                    biggestRow = rowWidth;
	                }
	            });
	            //Set width
	            $(this).find(".sub").css({ 'width': biggestRow });
	            $(this).find(".row:last").css({ 'margin': '0' });

	        } else { //If row does not exist...

	            $(this).calcSubWidth();
	            //Set Width
	            $(this).find(".sub").css({ 'width': rowWidth });

	        }
	    }

	    function megaHoverOut() {
	        $(this).find(".sub").stop().fadeTo('fast', 0, function () {
	            $(this).hide();
	        });
	    }


	    var config = {
	        sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)    
	        interval: 50, // number = milliseconds for onMouseOver polling interval    
	        over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
	        timeout: 50, // number = milliseconds delay before onMouseOut    
	        out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	    };

	    $("ul#nav-menu li .sub").css({ 'opacity': '0' });
	    $("ul#nav-menu li").hoverIntent(config);


	});


//-------------------------------------------------------------------------------
// Fonction pour enchainement des bannières avec un fadding
//-------------------------------------------------------------------------------
	$(document).ready(function () {
	    $('.slideshow').cycle({
	        fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	        speed: 4000,
	        timeout: 10000,
            cleartypeNoBg : true,
	        delay: 0
	    });
	});


//-------------------------------------------------------------------------------
// Fonction pour désactiver le lien de la page active (sur le menu de droite)
//-------------------------------------------------------------------------------
$(document).ready(function () {
    $('a.right-link-selected').removeAttr("href");
    $('a.right-link-orange-selected').removeAttr("href");
});


//-------------------------------------------------------------------------------
// Gestion ColorBox
//-------------------------------------------------------------------------------

$(document).ready(function () {
    $(".colorbox").colorbox({ transition: "none", width: "728px", height: "728px", opacity: 0.7 });
});

//-------------------------------------------------------------------------------
// Gestion de l'état du menu
//-------------------------------------------------------------------------------

$(document).ready(function () {
    $('#nav-menu ul li ').unbind("mouseout");
    $('#nav-menu ul li ').unbind("mouseover");

    var _licurrent;

    $('#nav-menu LI').each(
        function (li) {
            $(this).mouseover(
                function () {
                    if ($('#nav-menu')[0].id == this.parentNode.id) {
                        _licurrent = $('#nav-menu li a.selected');
                        if (_licurrent[0] != this.children[0])
                            _licurrent.css('background-position', '0 0');
                        else
                            _licurrent.css('background-position', '0 100%');
                    }
                }
            );
            $(this).mouseout(
                function (el) {
                    if ($('#nav-menu')[0].id == this.parentNode.id) {
                        if (_licurrent != undefined) {
                            if (this.children[0] != _licurrent[0])
                                _licurrent.css('background-position', 'left bottom');
                        }
                    }
                }
            );
        }
    );
});

function MenuMouseOut(_licurrent, el) {
    if (_licurrent != undefined) {
        if (el.children[0] != _licurrent[0])
            _licurrent.css('background-position', 'left bottom');
    }
}


//-------------------------------------------------------------------------------
// Gestion du text ghost
//-------------------------------------------------------------------------------

$(document).ready(function () {

    $('#txtLogin-off').show();
    $('#txtLogin').hide();

    $('#txtLogin-off').focus(function () {
        $('#txtLogin-off').hide();
        $('#txtLogin').show();
        $('#txtLogin').focus();
    });
    $('#txtLogin').blur(function () {
        if ($('#txtLogin').val() == '') {
            $('#txtLogin-off').show();
            $('#txtLogin').hide();
        }
    });


    $('#txtPwd-off').show();
    $('#txtPwd').hide();

	$('#txtPwd-off').focus(function () {
	    $('#txtPwd-off').hide();
	    $('#txtPwd').show();
	    $('#txtPwd').focus();
	});
	$('#txtPwd').blur(function () {
	    if ($('#txtPwd').val() == '') {
	        $('#txtPwd-off').show();
	        $('#txtPwd').hide();
	    }
	});

});



$(document).ready(function () {

    $('#txtLogin-off-mp').show();
    $('#txtLoginMp').hide();

    $('#txtLogin-off-mp').focus(function () {
        $('#txtLogin-off-mp').hide();
        $('#txtLoginMp').show();
        $('#txtLoginMp').focus();
    });
    $('#txtLoginMp').blur(function () {
        if ($('#txtLoginMp').val() == '') {
            $('#txtLogin-off-mp').show();
            $('#txtLoginMp').hide();
        }
    });


    $('#txtPwd-off-mp').show();
    $('#txtPwdMp').hide();

    $('#txtPwd-off-mp').focus(function () {
        $('#txtPwd-off-mp').hide();
        $('#txtPwdMp').show();
        $('#txtPwdMp').focus();
    });
    $('#txtPwdMp').blur(function () {
        if ($('#txtPwdMp').val() == '') {
            $('#txtPwd-off-mp').show();
            $('#txtPwdMp').hide();
        }
    });

});


//-------------------------------------------------------------------------------
// Gestion des alert d'erreurs de connexion à l'espace membre
//-------------------------------------------------------------------------------


$(document).ready(function () {
    val = $("#AlertConnexion").val();

    if (val != "")
        jAlert(val, "Connexion &agrave; l'espace membre");

});

////-------------------------------------------------------------------------------
//// Gestion des images de la banniere
////-------------------------------------------------------------------------------


////Permet de récupérer une valeur d'un cookie
//function getCook(nom) {
//    deb = document.cookie.indexOf(nom + "=")
//    if (deb >= 0) {
//        deb += nom.length + 1
//        fin = document.cookie.indexOf(";", deb)
//        if (fin < 0) fin = document.cookie.length
//        return unescape(document.cookie.substring(deb, fin))
//    }
//    return ""
//}

////Fonction de récupération d'un cookie
//function setCook(nom, valeur) {
//    document.cookie = nom + "=" + escape(valeur)
//}


//$(document).ready(function () {
//    //Background-image
//    var bgImage = $('.slideshow .head').eq(0).css('background-image');
//    //Accroche de la banniere
//    var txtAccroche = $('.slideshow .head-text').eq(0).html();
//    //Lien 'En savoir plus'
//    var srcEnSavoirPlus = $('.slideshow .head-link a').eq(0).attr("href");

//    //Ajoute l'url de la banniere au cookie
//    if (bgImage != null && bgImage != '' && getCook("gpImg") == "")
//        setCook("gpImg", bgImage);

//    //Ajoute le texte de l'accorche au cookie
//    if (txtAccroche != null && txtAccroche != '' && getCook("txtAccroche") == "") 
//        setCook("txtAccroche", txtAccroche);

//    //Ajoute l'url du lien 'En savoir plus'
//    if (srcEnSavoirPlus != null && srcEnSavoirPlus != '' && getCook("srcEnSavoirPlus") == "")
//        setCook("srcEnSavoirPlus", srcEnSavoirPlus);
//});


//$(document).ready(function () {
//    var bgImage = getCook("gpImg");
//    var txtAccroche = getCook("txtAccroche");
//    var srcEnSavoirPlus = getCook("srcEnSavoirPlus");

//    var ObjImage = new Image();
//    ObjImage.src = ($('.slideshow .head').eq(0).css('background-image')).replace(/(url)|\)|\(|"/g, '');



//    if ((bgImage != "" || txtAccroche != "") && (bgImage != $('.slideshow .head').eq(0).css('background-image')) && (!ObjImage.complete)) {
//        $('.head-static').css("background-image", bgImage);
//        $('.head-static .head-text').html(txtAccroche);
//        $('.head-static .head-link a').attr("href", srcEnSavoirPlus);
//        $('.head-static').css('display', 'block');
//    }
//    else {
//        $('.head-static').css('display', 'none');
//    }
//});


//$(window).load(function () {
//    $('.head-static').fadeOut(4000);
//});
