/***********************************************
* Pausing up-down scroller- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

function pausescroller(content, divId, divClass, delay){
this.content=content //message array content
this.tickerid=divId //ID of ticker div to display information
this.delay=delay //Delay between msg change, in miliseconds.
this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
this.hiddendivpointer=1 //index of message array for hidden div
document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>')
var scrollerinstance=this
if (window.addEventListener) //run onload in DOM2 browsers
window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
else if (window.attachEvent) //run onload in IE5.5+
window.attachEvent("onload", function(){scrollerinstance.initialize()})
else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
setTimeout(function(){scrollerinstance.initialize()}, 500)
}

// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------

pausescroller.prototype.initialize=function(){
this.tickerdiv=document.getElementById(this.tickerid)
this.visiblediv=document.getElementById(this.tickerid+"1")
this.hiddendiv=document.getElementById(this.tickerid+"2")
this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv))
//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
this.getinline(this.visiblediv, this.hiddendiv)
this.hiddendiv.style.visibility="visible"
var scrollerinstance=this
document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}
if (window.attachEvent) //Clean up loose references in IE
window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}


// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------

pausescroller.prototype.animateup=function(){
var scrollerinstance=this
if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+5)){
this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-5+"px"
this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-5+"px"
setTimeout(function(){scrollerinstance.animateup()}, 50)
}
else{
this.getinline(this.hiddendiv, this.visiblediv)
this.swapdivs()
setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
}
}

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

pausescroller.prototype.swapdivs=function(){
var tempcontainer=this.visiblediv
this.visiblediv=this.hiddendiv
this.hiddendiv=tempcontainer
}

pausescroller.prototype.getinline=function(div1, div2){
div1.style.top=this.visibledivtop+"px"
div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
}

// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

pausescroller.prototype.setmessage=function(){
var scrollerinstance=this
if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
setTimeout(function(){scrollerinstance.setmessage()}, 100)
else{
var i=this.hiddendivpointer
var ceiling=this.content.length
this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
this.animateup()
}
}

pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
if (tickerobj.currentStyle)
return tickerobj.currentStyle["paddingTop"]
else if (window.getComputedStyle) //if DOM2
return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
else
return 0
}



/* AJAX */
function file(fichier)
{
	if(window.XMLHttpRequest) // FIREFOX
	xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) // IE
	xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else
	return(false);
	xhr_object.open("GET", fichier, false);
	xhr_object.send(null);
	if(xhr_object.readyState == 4) return(xhr_object.responseText);
	else return(false);
}


/* Changement de la dispo d'un article en Ajax */
function chg_dispo(id_article, etat)
{
	if(etat)
	{
		dispo='1';
	}
	else
	{
		dispo='0';
	}
	texte = file('../vitishop/ajax/chg_dispo.php?id_article='+id_article+'&dispo='+dispo);
	
	if(texte!="1")
	{
		alert(texte);
	}
}


/* Changement de la dispo d'un article en Ajax */
function chg_ordre(id_article, value)
{
	texte = file('../vitishop/ajax/chg_ordre.php?id_article='+id_article+'&value='+value);
	
	if(texte!="1")
	{
		alert(texte);
	}
}




/* Affichage ou cachage d'un élément */
function show_hiddebis(e,id)
{
 var haut = (navigator.appName.substring(0,3) == "Net") ? e.pageY : event.y+document.body.scrollTop;


haut=haut-170;

	if(document.getElementById(id).style.display=='none')
	{
		document.getElementById(id).style.display='block';
		document.getElementById(id).style.top=haut+'px';
	}
	else
	{
		document.getElementById(id).style.display='none';
	}
}



/* Affichage ou cachage d'un élément */
function show_hidde(id, img)
{
	// Traitement de l'id
	if(document.getElementById(id).style.display=='none')
	{
		document.getElementById(id).style.display='block';
	}
	else
	{
		document.getElementById(id).style.display='none';
	}
	
	// Traitement de l'image
	if(img!="")
	{
		if(document.getElementById(id).style.display=='none')
		{
			document.getElementById(img).src='../imgs/plus.gif';
		}
		else
		{
			document.getElementById(img).src='../imgs/moins.gif';
		}
	}
}


// Fonction pour afficher un texte par défaut dans un input
function indic_input(inputid, lib)
{
	try
	{
		document.getElementById('inputid').value=lib;
	}
	catch(e)
	{
		alert('schwach.js, fonction indic_input: '+e.message);
	}
}

// Fonction pour effacer le texte d'un input lorsque l'on clic dessus
function clear_input(inputid)
{
	try
	{
		document.getElementById('inputid').value='';
		document.getElementById('inputid').style.color='#000000';
	}
	catch(e)
	{
		alert('schwach.js, fonction clear_input: '+e.message);
	}
}


/* Info bulle dynamique */

/***********************************************
* Cool DHTML tooltip script II- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var offsetfromcursorX=12 //Customize x offset of tooltip
var offsetfromcursorY=15 //Customize y offset of tooltip

var offsetdivfrompointerX=10 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

document.write('<div id="dhtmltooltip" style="display:none"></div>') //write out tooltip DIV
document.write('<img id="dhtmlpointer" src="../imgs/structure/arrowpopup.gif" style="display:none">') //write out pointer image

var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : ""

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thewidth, thecolor){
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
tipobj.innerHTML=thetext
enabletip=true
return false
}
}

function positiontip(e){
if (enabletip){
var nondefaultpos=false
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY

var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth){
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=curX-tipobj.offsetWidth+"px"
nondefaultpos=true
}
else if (curX<leftedge)
tipobj.style.left="5px"
else{
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
pointerobj.style.left=curX+offsetfromcursorX+"px"
}

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight){
tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
nondefaultpos=true
}
else{
tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
pointerobj.style.top=curY+offsetfromcursorY+"px"
}
tipobj.style.visibility="visible"
if (!nondefaultpos)
pointerobj.style.visibility="visible"
else
pointerobj.style.visibility="hidden"
}
}

function hideddrivetip(){
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
pointerobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}

document.onmousemove=positiontip



/* Préchargement et fonction des puces du menu */

var isIMG = document.images;
var Bton;
var Btoff;

if (isIMG) {
   Bton = new Image(8,8);
   Bton.src = "../imgs/structure/menu/puce_off.gif";
   Btoff = new Image(10,10);
   Btoff.src = "../imgs/structure/menu/puce_on.gif";
}
function Bt(Arrowname) {
     if (isIMG) {
     document.getElementById(Arrowname).src = (document.getElementById(Arrowname).src.indexOf('imgs/structure/menu/puce_on.gif') != -1) ? '../imgs/structure/menu/puce_off.gif' : '../imgs/structure/menu/puce_on.gif';
     }
}

function Window(mypage, myname, w, h) {
var winl = (screen.width - (w)) / 2;
var wint = (screen.height - (h)) / 2;
var neww = parseInt(w) + parseInt(40);
var newh = parseInt(h) + parseInt(40);
winprops = 'height='+newh+',width='+neww+',top='+wint+',left='+winl+',toolbar=0, location=0, directories=0, status=0, scrollbars=0, resizable=0, copyhistory=0, menuBar=0'
win = window.open(mypage, 'caca', winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

/*
CRYPTAGE DE PAGES WEB
*/


// FONCTIONS DE CODAGE HEXADECIMAL


var codesHexa="0123456789ABCDEF";


function codeHexa (octetDec) // octet décimal ==> hexadécimal
	{
	return (codesHexa.charAt(octetDec>>>4)+codesHexa.charAt(octetDec&15));
	}


function decodeHexa (octetHex) // octet hexadécimal ==> décimal
	{
	return ( (codesHexa.indexOf(octetHex.charAt(0))<<4) + codesHexa.indexOf(octetHex.charAt(1)) );
	}


// FONCTIONS DE CRYPTAGE


var clef="9Ajf0kDhD4GBwnuis1ys1d45br7uyZ"; // Vous pouvez modifier cette clef


function crypte (texte) // texte en clair ==> texte crypté
	{
	resultat="";
	l=texte.length;
	lc=clef.length;

	m=0;
	for (n=0;n<l;n++)
		{
		c=texte.charCodeAt(n);
		if (c<256) // Uniquement les caractères ASCII
			{
     			resultat+=codeHexa( c ^ clef.charCodeAt(m%lc) );
			m++;
			}
		}

	return resultat;
	}


function decrypte (texte) // texte crypté ==> texte en clair
	{
	resultat="";
	l=texte.length;
	lc=clef.length;

	m=0;
	for (n=0;n<l;n+=2)
		{
		c=decodeHexa(texte.substr(n,2));
		resultat+=String.fromCharCode( c ^ clef.charCodeAt(m%lc) );
		m++;
		}
		return resultat;
	}
