//AJAX
var httpReponse = '';

function	ajax(nameScript,data,nameFunction)
{
	var xhr_object	= null;

	if(window.XMLHttpRequest)		// Firefox 
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) 	// Internet Explorer 
	      xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	if (xhr_object != null)
	{
		xhr_object.open("POST", nameScript, true);
					
		xhr_object.onreadystatechange = function()
		{ 
			if(xhr_object.readyState == 4)
			{		
				httpReponse = xhr_object.responseText;
				if(nameFunction != '') eval(nameFunction +';')
			}
		}
		xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xhr_object.send(data);
	}
	else
		nameFunction('noAjax');
}

function actionDOM(){
	//alert(unescape(httpReponse));
	eval(unescape(httpReponse));
	//document.getElementById('contenu').innerHTML = unescape(httpReponse);
}

function show(obj,val)
{
	document.getElementById(obj).innerHTML = unescape(val);
}

function in_array(val,tab)
{
	if(tab!='')
	{
		for (t=0 ; t<tab.length ; t++)
		{
			if(tab[t]==val)
				return true;
		}
	}
	return false;
}

function ajaxPagination(nump,nbp,hide)
{
	var classe;
	var tabElement 	= new Array('first','prev','next','end');
	
	var tabHide		= hide.split(',');
	for (i=0 ; i<tabElement.length ; i++)
	{
		couleur = (in_array(tabElement[i],tabHide)) ? 'aaa' : '666';
		document.getElementById(tabElement[i]).style.backgroundColor = '#'+couleur;
	}

	document.getElementById('numP').innerHTML = nump;
	document.getElementById('nbP').innerHTML = nbp;
}

function getCont(type,critere)
{
	//alert(critere);
	ajax('../php/getCont.php','type='+type+'&'+critere,'actionDOM()');
}


function getContForm(type,critere)
{
	var crit		= '';
	var tmpTab 		= critere.split('|');
	for(i=0; i<tmpTab.length ; i++)
	{
		var deb 	= tmpTab[i].substr(0,3);
		if(deb=='CHE')
		{
			var nomCheck= tmpTab[i].substr(3,tmpTab[i].length);
			
			if(eval('document.getElementById("'+nomCheck+'").checked'))
				crit	+= '&'+nomCheck+'='+escape(eval('document.getElementById("'+nomCheck+'").value'));
		}
		else
			crit	+= '&'+tmpTab[i]+'='+escape(eval('document.getElementById("'+tmpTab[i]+'").value'));
	}

	ajax('../php/getCont.php','type='+type+'&'+crit,'actionDOM()');
}


function popup (url, win, width, height)
{
	options = 'width=' + width + ',height=' + height;
	return window.open(url, win, options);
}

/*BULLES*/
function bulle(objet,orientation,texte,largBulle,couleur,positionFleche,bulleLeft,bulleTop)
{
	
	switch(orientation)
	{
		case 'top':  	var ln1		= ' class="fleche" ><div id="fleche" style="top:1px;left:'+positionFleche+'px"></div>';
						var ln2		= '>'+texte;
						var blockP 	= '2';
						var image	= 'bulleFlechHaut.gif';
						break;
						
		case 'bottom': 	var ln1		= '>'+texte;
						var ln2		= ' class="fleche" ><div id="fleche" style="position:relative;bottom:0;left:'+positionFleche+'px"></div>';
						var blockP 	= '1';
						var image	= 'bulleFlechBas.gif';
						break;							
	}
	document.getElementById(objet).innerHTML = '<div id="bulle" style="z-index:200;left:'+bulleLeft+'px;top:'+bulleTop+'px;"><div id="bulleLn1"'+ln1+'</div><div id="bulleLn2"'+ln2+'</div></div>';
	document.getElementById('bulle').style.width = largBulle+'px';
	document.getElementById('bulleLn'+blockP).style.backgroundColor = '#'+couleur;
	document.getElementById('bulleLn'+blockP).style.borderWidth 	= '1px';
	document.getElementById('bulleLn'+blockP).style.borderStyle 	= 'dotted';
	document.getElementById('bulleLn'+blockP).style.borderColor 	= '#999';		
	document.getElementById('bulleLn'+blockP).style.paddingTop 		= '5px';
	document.getElementById('bulleLn'+blockP).style.paddingRight 	= '5px';
	document.getElementById('bulleLn'+blockP).style.paddingBottom 	= '5px';
	document.getElementById('bulleLn'+blockP).style.paddingLeft 	= '5px';
	document.getElementById('bulleLn'+blockP).style.color 			= '#c11616';
	document.getElementById('fleche').style.backgroundImage = 'url(../images/'+image+')';
	showObj(objet, 2000);
}

//apparition temporisée
var T = '';
function showObj(nomObj, duration)
{
	top.document.getElementById(nomObj).style.display='block';
	if(duration!='inf')
	{
		clearTimeout(T);
		var href = top.document.getElementById(nomObj).getElementsByTagName('A');
		for (var i = 0; i < href.length; i++)
		{
			href[i].onmouseover= function (){ showObj(nomObj,duration); }
		}
		T = setTimeout('hideObj("'+nomObj+'");',duration);
	}
}
function hideObj(nomObj)
{
	top.document.getElementById(nomObj).style.display = 'none';
}

//accueil Web rand
function webRandCall(limite,padding,xMax,yMax,timeOut)
{
	getCont('accueilWebRand','limite='+limite+'&padding='+padding+'&xMax='+xMax+'&yMax='+yMax);
	setTimeout('webRandCall("'+limite+'","'+padding+'","'+xMax+'","'+yMax+'","'+timeOut+'");',timeOut);
}

//Franck limitation chaine
function limiteurSaisie(champ, indic, maximum)
{
	if (champ.value.length > maximum)
		champ.value = champ.value.substring(0, maximum);
	else
		indic.value = maximum - champ.value.length;
}

//catalogue
function getCatFormInfos(){
	showAjaxLoader();
	//nomenclature
	inputs 	= 	document.getElementsByTagName('INPUT');
	nom		=	sty	= edi = ven = '';
	if (inputs.length > 0) 
	{
		for (i = 0; i < inputs.length; i++)
		{
			//nomenclature
			if(inputs[i].id.indexOf('nom_') != -1 && inputs[i].checked)
				nom			+=	inputs[i].id+',';
			//style
			if(inputs[i].id.indexOf('sty_') != -1 && inputs[i].checked)
				sty			+=	inputs[i].id+',';		
			//editions
			if(inputs[i].id.indexOf('edi_') != -1 && inputs[i].checked)
				edi			+=	inputs[i].id+',';					
			//vente en ligne
			if(inputs[i].id.indexOf('ven_') != -1 && inputs[i].checked)
				ven			+=	inputs[i].id+',';					
		}
	}
	var page					=	'';
	if(document.getElementById('pageCurrent').value != 1)
				page		=	'&pageCurrent='+document.getElementById('pageCurrent').value;
	
	getCont('catalogue','crit='+nom+sty+edi+ven+page);
}

function hideAjaxLoader()
{
	document.getElementById('ajaxLoader').innerHTML = '';
}
function showAjaxLoader()
{
	document.getElementById('ajaxLoader').innerHTML = '<img src="../images/ajax-loader.gif" />';
}

//extranet show detail
function showDet(num)
{
	display	=	document.getElementById('det'+num).innerHTML.substr(0,1) == 'D' ? 'block' : 'none';
	//document.getElementById('det'+num+'-1').style.display	=	display;
	document.getElementById('det'+num+'-1').style.display	=	display;
	//document.getElementById('det'+num+'-2').style.display	=	display;
	document.getElementById('det'+num).innerHTML			=	document.getElementById('det'+num).innerHTML.substr(0,1) == 'D' ? 'Cacher le d&eacute;tail de l\'oeuvre' : 'D&eacute;tails sur l\'oeuvre (prix, format, style, ...)';
}

