var isIE=document.all?true:false;
var isDOM=document.getElementById?true:false;
var isNS4=document.layers?true:false;



// -----------------------------------------------------------------------------------
// incrémentation/décrémentation d'un champ texte par 2 boutons +/-

function QtyDown( field, min_qty )
{
	tab = field.parentNode.getElementsByTagName("input");
	qty_field = tab[0];
	
	var current_qty = parseInt(qty_field.value);
	var min_qty = parseInt(min_qty);
	
	if ( current_qty > min_qty && current_qty > 0 )
	{
		qty_field.value--;
	}
	else
		show(min_qty);	
}

function QtyUp( field )
{
	tab = field.parentNode.getElementsByTagName("input");
	qty_field = tab[0];
	
	var current_qty = qty_field.value;
	
	qty_field.value++;
}

// -----------------------------------------------------------------------------------
// affiche une div par-dessus la page et centrée sur l'écran

//création 
function show( message_value )
{
	var margin_top = 350;
	obj_body = document.getElementsByTagName('body').item(0);
	if (!document.getElementById('messagediv')) 
	{
		//Création du container général
		array_page_size = getPageSize();
		array_page_scroll = getPageScroll();
		obj_content = document.createElement('div');
		obj_content.setAttribute('id', 'messagecontent');
		obj_content.style.width = '320px';
		obj_content.style.height = '130px';
		
		//Positionnement
		obj_body.appendChild(obj_content);
		obj_content.style.left = array_page_size[0]/2 - (parseInt(obj_content.style.width)/2)+'px';
		obj_content.style.top = array_page_scroll[1] + margin_top +'px';
		
		//Création du container message
		obj_message = document.createElement('div');
		obj_message.setAttribute('id', 'messagediv');
		obj_message.style.width = '320px';
		obj_message.style.height = '130px';
		obj_content.appendChild(obj_message);
		
		//Création du texte
		obj_text = document.createElement('div');
		obj_text.setAttribute('id', 'text');
		obj_text.style.width = '320px';
		obj_content.appendChild(obj_text);
		obj_txt = document.createTextNode('La quantité minimale pour ce produit est de ' + message_value );
		obj_text.appendChild(obj_txt);
		
		//fermeture de la div
		obj_image = document.createElement('div');
		obj_image.setAttribute('id', 'fermer');
		obj_image.style.width = '320px';
		obj_image.style.height = '20px';
		obj_content.appendChild(obj_image);
		obj_message.onclick = function() { hide(); return false; }
		obj_image.onclick = function() { hide(); return false; }
	}
	
}

//destruction
function hide() 
{
	obj_body = document.getElementsByTagName('body').item(0);
	obj_body.removeChild(document.getElementById('messagecontent'));
}

// -----------------------------------------------------------------------------------
// getPageScroll()
// Returns array with x,y page scroll values.

function getPageScroll(){
	var yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}
	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

// -----------------------------------------------------------------------------------
// getPageSize()
// Returns array with page width, height and window width, height

function getPageSize(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

// -----------------------------------------------------------------------------------

function Filter( field, url, anchor )
{
	var val = field.value;
	var str = '&' + field.name + '=' + val;
	var anc = (anchor == null) ? '' : '#' + anchor;
	var uri = ( url == null ) ? window.location.href : url;
	
	window.location.href = uri + str + anc;
}

function CheckForm( subaction )
{
    if ( subaction == "login_validate" )
    {
    	if ( getObj("login").value == "" )
    	{
    		getObj("login").focus();
    		return false;
    	}
    	else if ( getObj("pwd").value == "" )
    	{
    		getObj("pwd").focus();
    		return false;
    	}
    	else
    		return true;
    }
	else
		return true;
}

function ClearField ( field )
{
	// clearonce variable
	//var clearvar = 'clear' + field.name;
	if ( isset( aClearField[field.name] ) )
	{
		if ( aClearField[field.name] )
		{	
			aClearField[field.name] = false;
		}
	}
	else
		field.value = "";
		
}

function SubAction( subaction )
{
	//subaction = ( subaction == "" ) ? getObj("pageaction").value : subaction;
	//getObj("pageform").action = phpself;
	getObj("pageaction").value = subaction;
	getObj("pageform").submit();
}

function SubForm( subaction )
{
	if ( CheckForm( subaction ) )
		SubAction( subaction );
	else
		alert('Veuillez entrer votre login et votre mot de passe');
}

function ActionWhenReturn( evt, subaction )
{
    if (document.layers) {
        keyPressed = String.fromCharCode(evt.which);
    } else if (document.all) {
        keyPressed = String.fromCharCode(window.event.keyCode);
    } else if (document.getElementById) {
        keyPressed = String.fromCharCode(evt.keyCode);
    }
 
    if ( ( keyPressed == "\r" || keyPressed == "\n" ) && CheckForm( subaction ))
    {
        SubAction( subaction );
    }
}

function ConfirmMsg( button, msg )
{
	var x = window.confirm( msg + "\r\n Cette action est définitive.")
	if ( x )
		return true; //form.submit();
	else
		return false;
}

function isset(varname)  {
  if(typeof( window[ varname ] ) != "undefined") return true;
  else alert ('toto'); //return false;
}

function ObjShow (obj)
{
	if (document.layers)
		{
			document.layers[obj].display = 'block';
		}
		else if (document.all)
		{
			document.all[obj].style.display = 'block';
		}
		else if (document.getElementById)
		{
			document.getElementById(obj).style.display = 'block';
		}
}

function ObjHide (toto)
{
	if (document.layers)
		{
			document.layers[toto].display = 'none';
		}
		else if (document.all)
		{
			document.all[toto].style.display = 'none';
		}
		else if (document.getElementById)
		{
			document.getElementById(toto).style.display = 'none';
		}
}

function menushow( submenu )
{
	lastMenu = submenu;
	var i,j;
	for (i=0;i<nbMenu;i++)
	{
		j = i + 1;
		ObjHide('menu_'+j);
	}
	ObjShow( submenu );
}

function menuhide()
{
	//if ( submenu == lastMenu )
	//{
		//alert (event.fromElement);
		menushow( currentMenu );
		//menushow(lastMenu);
	//}
}

function menulast( submenu )
{
	lastMenu = submenu;
}

function pageshow( page )
{
	
}

function getObj(n, d)
{
    var p,i,x;
    

    if(!d)
        d=document;
    

    if((p=n.indexOf("?"))>0&&parent.frames.length)
    {
        d=parent.frames[n.substring(p+1)].document;
        n=n.substring(0,p);
    }

    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_swapImgRestore() { //v3.0
  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_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  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() { //v3.0
  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 onLoadActions() {
MM_preloadImages();

}


