/* --------------------
Antonin 04/04/2005 21:10
-------------------- */



// Get current date
var now = new Date();
var PMDIM = new Array(754,444);
var PM_Y = 5;
var PM_X = 0;
var PM_IE = ((document.all && document.getElementById && !window.opera && navigator.userAgent.toLowerCase().indexOf("mac") == -1))? true : false;
var PM_AGT = navigator.userAgent.toLowerCase();
var PM_VER = navigator.appVersion.toLowerCase();
var PM_SAFARI = ((PM_AGT.indexOf('safari')!=-1)&&(PM_AGT.indexOf('mac')!=-1))?true:false;


//-----------------------------------------------------------------------------------------------
// Special
//

// --------------------
// Uniquement pour les navigateurs Netscape.
function flashGetHref() { return location.href; }
function flashPutHref(href) { location.href = href; }
function flashGetTitle() { return document.title; }
function flashPutTitle(title) { document.title = title; }


// --------------------
// anti click-droit
function Right(e) { return false; }


// --------------------
//Fed-up with SPAM ?
function AntiSpam(user,domain,mailargs)
{
	locationstring = "mailto:" + user + "@" + domain + mailargs;
	window.location = locationstring;
}


// --------------------
// anti click-droit
function right(e) { return false; }



//-----------------------------------------------------------------------------------------------
// Common
//

// --------------------
//parser une chaîne d'arguments
function ArgsParse(args)
{
	if(args.length==1) return args=args[0].split(','); else return args;
}


// --------------------
//créer une chaîne d'arguments
function ArgsFill(args,val)
{
	var result = "";
	for(i=0; i<(args.length); i++) { if (result != "") result = result + ","; result = result + args[i] + "," + val; }
	return result;
}



//-----------------------------------------------------------------------------------------------
// POP UP
//

// --------------------
// Ouvre une popup à la taille de l'écran
function popUp(URL,name,dawidth,daheight)
{
	if (dawidth == null) dawidth = (screen.availWidth-8);
	//dawidth = screen.availWidth;
	if (daheight == null) daheight = (screen.availHeight-24);
	//daheight = screen.availHeight;
	if ((newWindow=window.open(URL,name,"WIDTH="+dawidth+",HEIGHT="+daheight+",scrollbars=yes,resizable=yes,alwaysraised=yes,toolbar=no,locationbar=no,titlebar=no,menubar=no,statusbar=yes"))!=null)
	{
		//newWindow.moveTo(0,0);
		//newWindow.moveTo(((((screen.availWidth)-dawidth)/2)+(screen.width-screen.availWidth)),((((screen.availHeight)-daheight)/2)+(screen.height-screen.availHeight)));
		newWindow.moveTo((screen.width-screen.availWidth),(screen.height-screen.availHeight));
		newWindow.focus();
	}
}


// --------------------
// Ouvre une popup en fullscreen
function popUpFull(URL,name)
{
	if ((newWindow=window.open(URL,name,"scrollbars=no,alwaysraised=yes,fullscreen=yes"))!=null)
	{
		newWindow.focus();
	}
}


// --------------------
// Redimensionne la fenêtre
function Resize(dawidth, daheight)
{
	if (!dawidth && !daheight)
	{
		dawidth = screen.availWidth;
		daheight = screen.availHeight;
	}
	window.resizeTo(dawidth, daheight);
	window.moveTo(((((screen.availWidth)-dawidth)/2)+(screen.width-screen.availWidth)),((((screen.availHeight)-daheight)/2)+(screen.height-screen.availHeight)));
}



//-----------------------------------------------------------------------------------------------
// UI
//

// --------------------
//checkbox
function ReverseCheck(Obj)
{
	if (Obj.checked) return(false); else return(true);
}


// --------------------
//affichage d'un DIV
function ReverseDisplay(Obj)
{
	if (Obj.style && (Obj.style.display == 'none')) return('block'); else return('none');
}


// --------------------
//affichage d'un DIV
function ReverseVisibility(Obj)
{
	if (Obj.style && (Obj.style.visibility == 'visible')) return('hide'); else return('show');
}


// --------------------
//checkbox
function CheckUncheck()
{
	var args=ArgsParse(CheckUncheck.arguments);
	
	for(i=0; i<(args.length); i+=2)
	{
		if(args[i+1]!=null)
			args[i].checked = args[i+1];
		else
			args[i].checked = ReverseCheck(Obj);
	}
}


// --------------------
//checkbox
function Check()
{
	CheckUncheck(ArgsFill(Check.arguments,1));
}


// --------------------
//checkbox
function Uncheck()
{
	CheckUncheck(ArgsFill(Uncheck.arguments,0));
}


// --------------------
function Hide(obj)
{
	if (obj.style && ((obj.style.display != 'none') || (obj.style.visibility != 'hidden')))
	{
		obj.style.display = 'none';
		obj.style.visibility = 'hidden';
	}
}

// --------------------
function RetourHide()
{
	MM_showHideLayers('retour','','hide');
}

// --------------------
function Show(obj)
{
	if (obj.style && ((obj.style.display != 'block') || (obj.style.visibility != 'visible')))
	{
		obj.style.display = 'block';
		obj.style.visibility = 'visible';
	}
}


// --------------------
function ShowActions(obj)
{	
	if (obj.style && ((obj.style.display != 'block') || (obj.style.visibility != 'visible')))
	{
		if (document.Actions) Hide(document.Actions);
		obj.style.display = 'block';
		obj.style.visibility = 'visible';
		document.Actions = obj;
	}
}



//-----------------------------------------------------------------------------------------------
// MM cross platform API
//

// --------------------
function MM_findObj(n, d)
{
	var p,i,x;
	if (!d) d = document;
	if (!(x = d[n]) && d.all) x = d.all[n];
	for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
	for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n,d.layers[i].document);
	if (!x && d.getElementById) x = d.getElementById(n);
	return x;
}


// --------------------
function MM_swapImage()
{
	var i,j=0,x,a=MM_swapImage.arguments;
	document.MM_sr=new Array;
	for(i=0;i<(a.length-2);i+=3)
	{
		if ((x=MM_findObj(a[i]))!=null)
		{
			document.MM_sr[j++]=x;
			if(!x.oSrc) x.oSrc=x.src;
			x.src=a[i+2];
		}
	}
}


// --------------------
function MM_swapImgRestore()
{
	var i,x,a=document.MM_sr;
	for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}


// --------------------
function MM_showHideLayers()
{
	//alert("MM_showHideLayers");
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  
  for(i=0; i<(args.length-2); i+=3)
  {
  	if ((obj=MM_findObj(args[i],args[i+1]))!=null)
  	{
  		v=(args[i+2]!='')?args[i+2]:ReverseVisibility(obj);
  		b=(v=='show'||v=='visible')?'block':'none';
    	if (obj.style)
    	{
    		obj=obj.style;
    		v=(v=='show'||v=='visible')?'visible':'hidden';
    	}
			if (obj.visibility!=v) obj.visibility=v;
			if (obj.display!=b) obj.display=b;
		}
	}	
}

function MM_showHideLayersBugSafari()
{
	//alert("MM_showHideLayers");
  var i,p,v,obj,args=MM_showHideLayersBugSafari.arguments;
  
  for(i=0; i<(args.length-2); i+=3)
  {
  	if ((obj=MM_findObj(args[i],args[i+1]))!=null)
  	{
  		v=(args[i+2]!='')?args[i+2]:ReverseVisibility(obj);
  		b=(v=='show'||v=='visible')?'block':'none';
    	if (obj.style)
    	{
    		obj=obj.style;
    		v=(v=='show'||v=='visible')?'visible':'hidden';
    	}
			//if (obj.visibility!=v) obj.visibility=v;
			if (obj.display!=b) obj.display=b;
		}
	}	
}


// --------------------
function MM_className()
{
  var i,obj,args=MM_className.arguments;
  
  for(i=0; i<(args.length-4); i+=5)
  {
  	if ((obj=MM_findObj(args[i],args[i+1]))!=null)
  	{
  		old_className = obj.className;
  		obj.className = args[i+2];
  		
  		if (args[i+3] && args[i+4])
  		{
  			launcher = args[i+3];
  			launcher.HclassName = old_className;
  			launcher.H = obj;
  			
  			launcher.onmouseout = function () {
  				this.H.className = this.HclassName;
	  			this.HclassName = null;
	  			this.H = null;
  			}
  		}
		}
	}	
}



//-----------------------------------------------------------------------------------------------
// X DOM API crossbrowser.com
//

// --------------------
function xGetElementsByClassName(clsName, parentEle, tagName, fn)
{
	var found = new Array();
	var re = new RegExp('\\b'+clsName+'\\b', 'i');
	var list = xGetElementsByTagName(tagName, parentEle);
	for (var i = 0; i < list.length; ++i)
	{
		if (list[i].className.search(re) != -1)
		{
			found[found.length] = list[i];
			if (fn) fn(list[i]);
		}
	}
	return found;
}


// --------------------
function xGetElementsByTagName(tagName, parentEle)
{
	var list = null;
	tagName = tagName || '*';
	parentEle = parentEle || document;
	if (parentEle.all)
	{
		if (tagName == '*') list = parentEle.all;
		else list = parentEle.all.tags(tagName);
	}
	else if (parentEle.getElementsByTagName) list = parentEle.getElementsByTagName(tagName);
	return list || new Array();
}


// --------------------
function xGetElementsByAttribute(sTag, sAtt, sRE, fn)
{
	var a, list, found = new Array(), re = new RegExp(sRE, 'i');
	list = xGetElementsByTagName(sTag);
	for (var i = 0; i < list.length; ++i)
	{
		a = list[i].getAttribute(sAtt);
		if (!a) {a = list[i][sAtt];}
		if (typeof(a)=='string' && a.search(re) != -1)
		{
			found[found.length] = list[i];
			if (fn) fn(list[i]);
		}
	}
	return found;
}


// --------------------
// If tag is defined, returns previous sibling with nodeName == tag, else with nodeType == 1.
function xPrevSib(ele, tag)
{
	var s = ele ? ele.previousSibling : null;
	if (tag) while (s && s.nodeName != tag) { s = s.previousSibling; }
	else while (s && s.nodeType != 1) { s = s.previousSibling; }
	return s;
}


// --------------------
// If tag is defined, returns next sibling with nodeName == tag, else with nodeType == 1.
function xNextSib(ele, tag)
{
	var s = ele ? ele.nextSibling : null;
	if (tag) while (s && s.nodeName != tag) { s = s.nextSibling; }
	else while (s && s.nodeType != 1) { s = s.nextSibling; }
	return s;
}


// --------------------
// If tag is defined, returns first child (or first child's sibling) with nodeName == tag, else with nodeType == 1.
function xFirstChild(ele, tag)
{
	var c = ele ? ele.firstChild : null;
	if (tag) while (c && c.nodeName != tag) { c = c.nextSibling; }
	else while (c && c.nodeType != 1) { c = c.nextSibling; }
	return c;
}


// --------------------
function xHideElementsByTagName(tagName, parentEle)
{
	if (list = xGetElementsByTagName(tagName, parentEle))
	{
  	for (var i = 0; i < list.length; ++i)
  	{
  		list[i].style.display = "none";
  		list[i].style.visibility = "hidden";
  	}
	}
}


// --------------------
function xShowElementsByTagName(tagName, parentEle)
{
	if (list = xGetElementsByTagName(tagName, parentEle))
	{
  	for (var i = 0; i < list.length; ++i)
  	{
  		list[i].style.display = "block";
  		list[i].style.visibility = "visible";
  	}
	}
}



//-----------------------------------------------------------------------------------------------
// Built upon MM cross platform API + X DOM API
//

// --------------------
function showpopDesc(idpopdesc,e,h,v)
{
	var relpos = RelPos(e);
	var brelpos = BRelPos(e);
	if ((obj=MM_findObj(idpopdesc))!=null)
	{
		with (obj.style)
		{
			display = 'block';
			if (h == 'g')
				right = brelpos[0].toString() + 'px';
			else
				left = relpos[0].toString() + 'px';
			if (v == 'h')
				bottom = brelpos[1].toString() + 'px';
			else
				top = relpos[1].toString() + 'px';
		}
	}
}


// --------------------
function hidepopDesc(idpopdesc)
{
	if ((obj=MM_findObj(idpopdesc))!=null)
	{
		with (obj.style)
		{
			display='none';
		}
	}
}



//-----------------------------------------------------------------------------------------------
// IE select box + absolute poisitioning workaround
//

// --------------------
function HideByTag(tagName)
{
	if ((document.all&&((Selects=document.all.tags(tagName))!=null)) || ((Selects=document.getElementsByTagName(tagName))!=null))
	{
		for(i=0;i<Selects.length;i++)
		{
			Selects[i].HideState = true;
	   	if (Selects[i].style) Selects[i].style.visibility = 'hidden';
	  }
	}
}


// --------------------
function ShowByTag(tagName)
{
	if ((document.all&&((Selects=document.all.tags(tagName))!=null)) || ((Selects=document.getElementsByTagName(tagName))!=null))
	{
		for(i=0;i<Selects.length;i++)
		{
	   	if (Selects[i].HideState && Selects[i].style)
	   	{
	   		Selects[i].style.visibility = 'visible';
	   		Selects[i].HideState = false;
	   	}
	  }
	}
}


// --------------------
function SelectToggleVisibility(visibility, search)
{
	if (PM_IE && ((Selects=xGetElementsByClassName('Hider',null,'select'))!=null))
	{
		for (i=0;i<Selects.length;i++)
		{
			Selects[i].style.visibility = visibility;
		}
		if (!search) MM_showHideLayers('searchcontainer','',visibility);
	}
}



//-----------------------------------------------------------------------------------------------
// Positioning
//

// --------------------
function RelPos(e)
{
	if (!e) var e = window.event;
	var abspos = AbsPos(e);
	var wsize = WSize();
	var posx = abspos[0] - ((wsize[0] > PMDIM[0])? ((wsize[0] - PMDIM[0]) / 2) : 0);
	//var posy = abspos[1] - ((wsize[1] > PMDIM[1])? ((wsize[1] - PMDIM[1]) / 2) : 0);
	var posy = abspos[1] - PM_Y;
	//alert('rel : '+posx + '-' + posy);
	return new Array(parseInt(posx),parseInt(posy));
}


// --------------------
function BRelPos(e)
{
	if (!e) var e = window.event;
	var abspos = AbsPos(e);
	var wsize = WSize();
	var posx = PMDIM[0] - (abspos[0] - ((wsize[0] > PMDIM[0])? ((wsize[0] - PMDIM[0]) / 2) : 0));
	//var posy = PMDIM[1] - (abspos[1] - ((wsize[1] > PMDIM[1])? ((wsize[1] - PMDIM[1]) / 2) : 0));
	//var posx = ((PMDIM[0] + wsize[0]) / 2) - abspos[0];
	//var posy = ((PMDIM[1] + wsize[1]) / 2) - abspos[1];
	var posy = PMDIM[1] - abspos[1] + PM_Y;
	//alert('brel : '+posx + '-' + posy);
	return new Array(parseInt(posx),parseInt(posy));
}


// --------------------
function AbsPos(e)
{
	if (!e) var e = window.event;
	var posx = 0;
	var posy = 0;
	if (e.pageX || e.pageY)
	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (event.clientX || event.clientY)
	{
		posx = event.clientX + document.body.scrollLeft;
		posy = event.clientY + document.body.scrollTop;
		//alert('scroll : ' + document.body.scrollLeft + '-' + document.body.scrollTop);
	}
	//alert('abs : ' + posx + '-' + posy);
	return new Array(parseInt(posx),parseInt(posy));
}


// --------------------
function WSize()
{
	var Wwidth=0,Wheight=0;
	if(typeof(window.innerWidth)=='number')
	{
		//Non-IE
		Wwidth = window.innerWidth;
		Wheight = window.innerHeight;
	}
	else if( document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
	{
		//IE 6+ in 'standards compliant mode'
		Wwidth = document.documentElement.clientWidth;
		Wheight = document.documentElement.clientHeight;
	}
	else if(document.body && (document.body.clientWidth || document.body.clientHeight))
	{
		//IE 4 compatible
		Wwidth = document.body.clientWidth;
		Wheight = document.body.clientHeight;
	}
	//alert('wsize : '+Wwidth + '-' + Wheight);
	return new Array(Wwidth,Wheight);
}



//-----------------------------------------------------------------------------------------------
// P16N
//


function editModele(modele)
{
	document.location.href='creer.php?Modele='+modele;
}