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 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		= 715;
	h 		= 600;
	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 modifierFiche(id) {
	if(id) {
		w		= 400;
		h 		= 500;
		t 	= (screen.height - h)/2;
		l 	= (screen.width - w)/2;
		modwin = window.open('exp/exploitant_modifier.php?id='+id,'modif_fiche','width='+w+', height='+h+', top='+t+', left='+l+', menubar=no, scrollbars=yes, status=no, resizable=yes');
		modwin.focus();
	}
}

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 checkMail(em) { 
	if((em !="") && (em.indexOf("@") != -1) &&  (em.indexOf(".") != -1)) { 
		return true; 
	} else {
		return false; 
	} 
} 

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();
}