// JavaScript Document
var req
function getHttpRequest(fichier)
{
	if(window.XMLHttpRequest) // FIREFOX
		req = new XMLHttpRequest();
	else if(window.ActiveXObject) // IE
			req = new ActiveXObject("Microsoft.XMLHTTP");
		else
			return(false);
	req.open("GET",fichier, false);
	req.send(null);
	if(req.readyState == 4 && req.status == 200) return(req.responseText);
		else return(false);
}


function DivContentLoader(url,id)
{
	document.getElementById(id).style.display='block';
	document.getElementById(id).innerHTML=getHttpRequest(url);
}


function Ctrl_Form_Setting(number)
{
	var j=0,n=0,m=0,compteur=0,k=0;
	var ok, tab_1,tab_2,tab_3,tab;
	tab_1=['le nom','le prénom','la nationalité','fac','le numéro de téléphone','fac','fac','fac','fac'];
	
	tab_2=['le nom','le prénom','la nationalité','fac','le numéro de téléphone','mail','l\'école ou l\'institution de formation','le niveau d\'étude','la filière de formation'];
	
	tab_3=['Le nom commercial','le nom','le prénom','la nationalité','le numéro de téléphone','le pays','l\'adresse postale','le numéro de téléphone','numéro de portable','o','l\'annonce'];
	
	tab_4=['Le nom de l\'entreprise','le nom de la ville','Nom du pays','Le contact de l\'entreprise','Le libellé de l\'offre','les conditions de l\'offre','fac'];
	
	tab_5=['fac','le nom','le prénom','le jour de naissance','le mois de naissance','l\'année de naissance','la nationalité','fac','la situation matrimoniale','fac','le numéro de téléphone','fac','mail','fac','le(s) diplômes'];
	
	switch(number)
	{
		case 1:tab=tab_1;
		break;
		
		case 2:tab=tab_2;
		break;
		
		case 3:tab=tab_3;
		break;
		
		case 4:tab=tab_4;
		break;
		
		case 5:tab=tab_5;
		break;
	}
	var formulaire=document.getElementsByTagName('form');
	(formulaire[k].getAttribute('name')=='etat_civil')?(compteur=2):(compteur=4);
	compteur=2;
	
	mail_adresse= new RegExp;
	mail_adresse=/^[a-z0-9._-]+@[a-z0-9\._-]{2,}\.[a-z]{2,4}$/;
	
	for(var i=0; i<document.forms[k].elements.length-compteur; i++)
	{
		nomchamp=document.forms[k].elements[i].name;
		if((nomchamp=='mail')&&(tab[i]!='fac')&&(!mail_adresse.test(document.forms[k].elements[i].value)))
		{
			m=1;
			j=i;
			ok=false;
			break;
		}else
			if((document.forms[k].elements[i].value=='')&&(tab[i]!='fac'))
			{
					j=i;
					ok=false;
					break;
			}else ok=true;
	}

	if(!ok)
	{
		if(n!=0){
				message='Veuillez saisir un numérique comme valeur';	
		}else 
			if(m!=0){ message='E-mail non valide';}
			else{
			message="veuillez renseigner "+tab[j];
		}
		alert(message);
		document.forms[k].elements[j].focus();
		return false;
	}else return true;
}



function SetImage(source,comment,nbphoto,indice,id_album,nbtt,sublimit)
{
	NewImage=new Image;
	NewImage.src=source;
	var n=nbphoto, nindice=indice, idalbum=id_album, nbttphoto=nbtt,limit=sublimit;
	dimensionImage=450;
	
	document.getElementById('imageContent').style.display='block';	
	setCoordinates('imageContent');
	document.getElementById('grandeImage').innerHTML="<img src='"+source+"' width='"+dimensionImage+"' />";
	document.getElementById('photo_comment').innerHTML=comment;
	
	if(nindice<n && limit<nbttphoto)
		document.getElementById('next').innerHTML="<img src=\"im/next1.gif\" width=\"26\" title=\"suivant\" onclick=\"pagination("+idalbum+","+n+","+(nindice+1)+","+nbttphoto+","+(limit+1)+")\" />";
	else
		document.getElementById('next').innerHTML="";
		
	if(nindice>1)
		document.getElementById('previous').innerHTML="<img src=\"im/prev1.png\" width=\"26\" title=\"pr&eacute;c&eacute;dent\" onclick=\"pagination("+idalbum+","+n+","+(nindice-1)+","+nbttphoto+","+(limit-1)+")\" />";
	else
		document.getElementById('previous').innerHTML="";
		
}


function pagination(idalbum,nbre,indice,nbtt,limit)
{
	var albumid=idalbum,
		nombre=nbre,
		indicephoto=indice,
		nbtotal=nbtt,
		limitphoto=limit,
		sourcephoto=getHttpRequest("ajax.php?id_album="+albumid+"&source=1"+"&indice="+limitphoto),
		commentphoto=getHttpRequest("ajax.php?id_album="+albumid+"&comment=1"+"&indice="+limitphoto);
		
		SetImage("photo/"+sourcephoto,commentphoto,nombre,indicephoto,albumid,nbtotal,limitphoto);
}


function setCoordinates(id)
{
	var object=document.getElementById(id),
		_screenWidth=Math.floor(document.body.clientWidth/2),
		_objectWidth=object.offsetWidth,
		_objectHeight=object.offsetHeight;
		
		object.style.left=_screenWidth - Math.ceil(_objectWidth/2);
	
}
