var nb = 0;
var dateReg = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/; 
var emailReg = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$/; 

/***************************************************************/

function imprimer()
{
	pageP = window.open('print.html','pageP','width=800, height=600, scrollbars=yes,location=no,status=yes, menubar=yes, resizable=yes');
}

function label()
{
	w		= 300;
	h 		= 400;
	t 	= (screen.height - h)/2;
	l 	= (screen.width - w)/2;
	addwin = window.open('txt/affiche.php?txt=label.txt','label','width='+w+', height='+h+', top='+t+', left='+l+', menubar=no, scrollbars=yes, status=no, resizable=yes');
	addwin.focus();
}

function produits(type,id)
{
	w		= 300;
	h 		= 400;
	t 	= (screen.height - h)/2;
	l 	= (screen.width - w)/2;
	if(type)
	{
		window.open('edit/prod/'+type+'.php?id='+id,'producteur_produit','width='+w+', height='+h+', top='+t+', left='+l+', menubar=no, scrollbars=yes, status=no, resizable=yes');
	}
}

function prods(id)
{
	w		= 300;
	h 		= 400;
	t 	= (screen.height - h)/2;
	l 	= (screen.width - w)/2;
	if(id)
	{
		window.open('pages/visu_produits.php?id='+id,'producteur_produit','width='+w+', height='+h+', top='+t+', left='+l+', menubar=no, scrollbars=yes, status=no, resizable=yes');
	}
}


function position(id)
{
	w		= 820;
	h 		= 670;
	t 	= (screen.height - h)/2;
	l 	= (screen.width - w)/2;
	if(id)
	{
		window.open('edit/carte/positionner.php?id='+id,'pos','width='+w+', height='+h+', top='+t+', left='+l+', menubar=no, scrollbars=no, status=yes, resizable=yes');
	}
	else
	{
		alert('Enregistez le producteur avant de le positionner.');
	}
}

function getMouseXY(e)
{
	if (IE) {
	tempX = event.clientX + document.body.scrollLeft;
	tempY = event.clientY + document.body.scrollTop;
	} else {
	tempX = e.pageX;
	tempY = e.pageY;
	}  
	if (tempX < 0){tempX = 0;}
	if (tempY < 0){tempY = 0;}  
	return true;
}

function setPoint()
{
	decalage = 8;
	img = document.getElementById("carte");
	pos_x = document.getElementById("posx");
	pos_y = document.getElementById("posy");
	if(tempX > decalage && tempY > decalage && tempX <= (img.width+decalage) && tempY <= (img.height+decalage))
	{
		//f.pos_x.value = tempX - decalage;
		pos_x.innerText = tempX - decalage;
		//f.pos_y.value = tempY - decalage
		pos_y.innerText = tempY - decalage;
		setPicto(img,tempX - decalage,tempY - decalage);
	}
}

function suppr_position(id)
{
	if(id)
		if(confirm('Cela supprimera définitivement le point.\nContinuer ?'))
			window.location.href='supprimer.php?id='+id;
}

function setPicto(im,x,y)
{
	if(im && x && y)
		im.src = 'carte.php?x='+x+'&y='+y;
}

function seturl()
{
	document.sendpage.url.value = window.location.href;
}

function mentions()
{
	w		= 300;
	h 		= 400;
	t 	= (screen.height - h)/2;
	l 	= (screen.width - w)/2;
	addwin = window.open('txt/affiche.php?txt=mentions.txt','mentions','width='+w+', height='+h+', top='+t+', left='+l+', menubar=no, scrollbars=yes, status=no, resizable=yes');
	addwin.focus();
}

function changeLine(el,cl,img)
{
	el.className = cl;
	el.firstChild.style.cssText = 'background-image: url(../images/pictos/'+img+');';
}

function modifier(type,id)
{
	if(type && id)
		window.location.href = "index.php?action=edit&type="+type+"&id="+id;
}

function supprimer(type,id)
{
	if(type && id) {
	if(confirm('Etes-vous sūr(e) de vouloir effectuer cette suppression ?')) {
			window.location.href = "delete/"+type+".php?id="+id+"&r="+type;
		}
	}
}

function supprPJ(table,champ,id)
{
	if(table && champ && id) {
		if(confirm('Etes-vous sūr(e) de vouloir supprimer la pičce jointe ?')) {
			window.location.href = "delete/piecejointe.php?r="+table+"&c="+champ+"&id="+id;
		}
	}
}

function decolorize(f)
{
	for(var i=0;i<f.length;i++) {
		if(f.elements[i].type == "text" || f.elements[i].type == "textarea") {
			f.elements[i].className = "edition";
		}
		if(f.elements[i].type == "select-one")
		{
			f.elements[i].style.backgroundColor = "#FFFFFF";
		}
	}
	nb = 0;
}

function colorize(field,regexp)
{
	if(field.value.length == 0 || (regexp && regexp.test(field.value) == false))
	{
		field.className = "editionrouge";
		nb++;
	}
	if(field.type == "select-one" && field.selectedIndex == 0)
	{
		field.style.backgroundColor = "#FFCCFF";
		nb++;
	}
}

function afficheDetails(s,id)
{
	var d = document.getElementById(id);
	if(s.checked == true)
		d.style.cssText = "display: block";
	else
		d.style.cssText = "display: none";
}

function ClipBoard(txt) 
{
	if(bw.mac || bw.ns)
	{
		document.getElementById("liendiv").innerHTML = txt;
	}
	else
	{
		document.getElementById("liendiv").innerHTML = txt;
		hold = document.getElementById("holdtext");
		hold.innerText = txt;
		Copied = hold.createTextRange();
		Copied.execCommand("Copy");
	}
}

function phototheque()
{
	w		= 700;
	h 		= 550;
	t 	= (screen.height - h)/2;
	l 	= (screen.width - w)/2;
	addwin = window.open('phototheque/','phototheque','width='+w+', height='+h+', top='+t+', left='+l+', menubar=no, scrollbars=no, status=yes, resizable=no');
	addwin.focus();
}

function popup_carte(url) {
	var opts = 'scrollbars=yes,resizable=yes,menubar=yes,status=no';
	window.open(url, 'carte', 'width=840, height=570, '+opts);
}

function changeetat(id, table, rub){
	self.location.href = 'changeetat.php?table='+table+'&rub='+rub+'&id='+id;
}

function changearchive(id, table, rub){
	self.location.href = 'changearchive.php?table='+table+'&rub='+rub+'&id='+id;
}

function changeselection_du_jour(id, table, rub){
	self.location.href = 'changeselection_du_jour.php?table='+table+'&rub='+rub+'&id='+id;
}

function deletePJ(id)
{
	if(confirm('Confirmez-vous la suppression de ce fichier ?')) {
		window.location.href = 'delete/quizz_fichier.php?id='+id;
	}
}

function deplie(id){
	var divs=document.getElementsByTagName("div");
	for(var i=0 ; i<divs.length ; i++)
	{
		if(divs[i].id.search(/^bloc/)>=0)
		{
			if(divs[i].id=='bloc'+id)
			{
			divs[i].style.display= divs[i].style.display== "block"?"none":"block";
			}
		else
		{
			divs[i].style.display= "none";   
		}
		
		}
	}

}

function checkQuizz(f) {
	var reg = "";
	var reponses = new Array();
	var radios = f.getElementsByTagName('input');
	
	return true;
}

function popup_document(id)
{
	window.open('popup_document.php?id='+id, '', 'width=400, height=400, scrollbars=yes');
}

function popwin(url,name,w,h,optionlist,align)
{
	if(align == "center")
	{
		t = ((screen.height-h)/2);
		l = ((screen.width-w)/2);
		optionlist += (optionlist != "" ? "," : "")+"top="+t+",left="+l;
	}
	optionlist = optionlist != "" ? ","+optionlist : "";
	eval(name+" = window.open('"+url+"','"+name+"','width="+w+",height="+h+optionlist+"');");
	eval(name+".focus();");
}