// JavaScript Document

String.prototype.trim = function()
{ 
return this.replace(/(^\s*)|(\s*$)/g, "");
}

var myLocation="";

function control_frm(form_name)
{
 var nb=document.forms[form_name].elements.length;

//document.getElementById("divIMg").style.visibility="visible";	
 var errorMsg="";
 td_msg.innerHTML="";
 var i=0;
 var j=0;

	 for (i=0;i<nb;i++)
	 {
		var champ=(document.forms[form_name].elements[i].value).trim();
		var name=(document.forms[form_name].elements[i].name);
		var id=document.forms[form_name].elements[i].id;
		var field=document.forms[form_name].elements[i];
		var oblig=id.substring(0,1);
		var oblig2=id.substring(0,2);
		var affich=id;
		var regex=/^[A-za-z0-9 ]*$/;
		var tel = /^[0-9]{10}$/;
		var cp = /^[0-9]{5}$/;
		var prix = /[0-9\,\.]/;
			affich=id.substring(1,id.length);

				//Vérification des champ vides obligation
				if (((champ.length==0 || champ==0) && oblig=="*") || champ=="-1")
				{
				errorMsg=affich+" est vide";
				alert (errorMsg);
				return false;
				}
					

	 }
}

function control(form_name)
 {
 var nb=document.forms[form_name].elements.length;
 var divError=document.getElementById("divJsError");


 divError.style.height="0px";
 divError.style.visibility="hidden";
 divError.innerHTML="<b>Erreur</b> : ";
 var i=0;
 var j=0;

	 for (i=0;i<nb;i++)
	 {
		var champ=(document.forms[form_name].elements[i].value).trim();
		var name=document.forms[form_name].elements[i].name;
		var id=document.forms[form_name].elements[i].id;
		var field=document.forms[form_name].elements[i];
		var oblig=id.substring(0,1);
		var oblig2=id.substring(0,2);
		var affich=id;
		var regex=/^[A-za-z0-9 ]*$/;
		var tel = /^[0-9]{10}$/;
		var cp = /^[0-9]{5}$/;
		var prix = /^[0-9]/;
			affich=id.substring(1,id.length);
	
				//Vérification des champ vides obligation
				if ((champ.length==0 && oblig=="*") || champ=="-1")
				{
				divError.style.height="20px";
 				divError.style.visibility="visible";
				divError.innerHTML+=affich+" est vide";
				return false;
				}
		
				else if (name=="cp"  && champ.search(cp)==-1)
					{
					divError.style.height="20px";
					divError.style.visibility="visible";
					divError.innerHTML+="Le code postal saisi n'est pas valide";
					return false;							
					}
						//Si un champ téléphone ou fax est détecté dans le formulaire
						else if ((name=="tel" && champ.length>0) && champ.search(tel)==-1)
						{
						divError.style.height="20px";
						divError.style.visibility="visible";
						divError.innerHTML+="Le numéro de téléphone saisi n'est pas valide";
						return false;		
						}
						
								else if (name=="mail" && champ.length>0)
								{
								divError.style.height="20px";
								divError.style.visibility="visible";
								var arobas=champ.indexOf("@");
									if (arobas==-1)
									{
									divError.innerHTML+="Mail saisi non valide";
									return false;
									}

								}

											

		 }									
		divError.style.height="0px";
		divError.innerHTML="";
		divError.style.visibility="hidden";
		//document.getElementById("divSendCommande").style.visibility="visible";	

	 }

		function controlPhoto(frm,field)
		{
		var champ=(document.forms[frm].elements[field].value).trim();
		var name=(document.forms[frm].elements[field].name);
			if (champ.length==0)
			{
			alert ("Aucune photo sélectionnée");
			return false
			}
		}

			function controlUrl(form_name)
			 {
		
				var champ=(document.forms[form_name].elements['site'].value).trim();	
				var regex=/^http:\/\//;
				var regex2=/[A-za-z0-9][.\/]*$/;
						//Vérification des champ vides obligation
						if (champ.length>0 && (champ.search(regex)==-1 || champ.search(regex2)==-1))
						{
						return false;
						}
			 }
 
function setFocus(frm,field)
{
document.forms[frm].elements[field].focus();
}

var TBLlocation=new Array();

function saveLocation(path)
{
TBLlocation=new Array(path);
}


function goTo()
{
var id=document.forms["frm_liste"].elements["liste_rub"].value.split("@");
window.location="./?IDdossier="+id[0]+"&lib="+id[1]+"";
}
	
function deconnect(url)
{
	if (confirm("Voulez-vous fermer votre session?"))
	{
	window.location=url;
	}
		else
		{
		
		}
}



	function showImg(img,width,height)
	{
		document.getElementById("divApercu").style.backgroundImage="";
		document.getElementById("divApercu").style.width=width+"px";
		document.getElementById("divApercu").style.height=height+"px";
		document.getElementById("divApercu").innerHTML="<img src='"+ img +"' width='"+ width +"' height='"+ height +"' />";
		//document.getElementById("divApercu").style.backgroundImage="url('"+img+"')";
		document.getElementById("divApercu").style.visibility="visible";
	}


function initialyzeDiv(div)
{
document.getElementById(div).style.visibility="hidden";
}

	function showNextImg()
		{
		//alert(currentIndex+"//"+tblImages.length);
		var _img=document.getElementById("imgThumb");//.images['imgThumb'];
		var _lnkZoom=document.getElementById("lnkZoom");
		var _lnkNextImg=document.getElementById("lnkNextImg");
		currentWidth=0;
		currentHeight=0;
			if (tblImages.length==0)
			{
			_img.style.backgroundImage="url(img/pic/noImage200.png)";
			_lnkZoom.innerHTML="";
			_lnkNextImg.innerHTML="";
			}
				
					else 
					{
					if (tblImages.length>1)
					{
					_lnkNextImg.style.visibility="visible"
					}
	
					_img.style.backgroundImage="url(photos/mini/"+tblImages[currentIndex]+")";//="photos/mini/"+tblImages[currentIndex];
						img.src="photos/"+tblImages[currentIndex];
						currentWidth=img.width;
						currentHeight=img.height;
						if (currentIndex==tblImages.length-1)
						{
						currentIndex=0;
						}
							else
							{
							currentIndex=currentIndex+1;
							}
					}
		}
		
			function showZoom()
			{
			currentWidth=img.width;
			currentHeight=img.height;
			var _calcul=(500/currentWidth);	
			var newHeight=Math.round(currentHeight * _calcul);
			document.getElementById("divApercu").innerHTML="<img src='"+img.src+"' width='500'  />";
			position('event',500,newHeight,'divApercu');
			}

function position(evt,width,height,div)
	{

 	var posx, posy;
  	var div=document.getElementById(div);
	div.style.visibility="visible";
    var posScroll=document.body.scrollTop;
	var decal=0;
	var _marginLeft=0;
	_marginLeft=width/2;
	div.style.marginLeft="-"+_marginLeft+"px";

	
	var navigateur=(navigator.appName.substring(0,3)).toUpperCase();
		if (navigateur=="NET")
		{
		var scrollY=document.body.scrollTop;
		var scrollX=document.body.scrollLeft;
		posx = evt.pageX+scrollX;
			div.style.left=posx+(width/2)+30+"px";
			if (posx+width>screen.width)
			{
			div.style.left=posx-(width/2)-30+"px";
			}
		posy = evt.pageY+scrollY;
		div.style.top=posy-(height/2)+"px";
		
		}
			if (navigateur=="MIC")
			{
			var e = window.event; 
			var scrollY=document.documentElement.scrollTop;
			var scrollX=document.documentElement.scrollLeft;

			posx = event.clientX+scrollX;
			div.style.left=posx+(width/2)+30;
			if (posx+width>screen.width)
			{
			div.style.left=posx-(width/2)-30;
			}

			posy = event.clientY+scrollY;
			div.style.top=posy-(height/2);
				if (posy+height>screen.height)
			{
			div.style.top=posy-(height/2)-30;
			}		
			}
				else
				{
				var scrollY=document.body.scrollTop;
				var scrollX=document.body.scrollLeft;
				posx = evt.pageX;
					div.style.left=posx+(width/2)+30;
					if (posx+width>screen.width)
					{
					div.style.left=posx-(width/2)-30;
					}
				posy = evt.pageY;
				div.style.top=posy-(height/2);
				}
}

function positionConfirmCaddy(evt)
	{
 	var posx, posy;
  	var div=document.getElementById("confirm");
    //
	var navigateur=(navigator.appName.substring(0,3)).toUpperCase();
				if (navigateur=="NET")
		{
		var scrollY=document.body.scrollTop;
		var scrollX=document.body.scrollLeft;
		posx = evt.pageX+scrollX;
			div.style.left=posx+(width/2)+30+"px";
			if (posx+width>screen.width)
			{
			div.style.left=posx-(width/2)-30+"px";
			}
		posy = evt.pageY+scrollY;
		div.style.top=posy-(height/2)+"px";
		
		}
			if (navigateur=="MIC")
			{
			var e = window.event; 
			var scrollY=document.documentElement.scrollTop;
			var scrollX=document.documentElement.scrollLeft;

			posx = event.clientX+scrollX;
			div.style.left=posx+(width/2)+30;
			if (posx+width>screen.width)
			{
			div.style.left=posx-(width/2)-30;
			}
			posy = event.clientY+scrollY;
			div.style.top=posy-(height/2);
			
			}
				else
				{
				var scrollY=document.body.scrollTop;
				var scrollX=document.body.scrollLeft;
				posx = evt.pageX;
					div.style.left=posx+(width/2)+30;
					if (posx+width>screen.width)
					{
					div.style.left=posx-(width/2)-30;
					}
				posy = evt.pageY;
				div.style.top=posy-(height/2);
				}
}

function countSlashes()
{
var listArray=window.location.href.split("/");
var listArrayLength=listArray.length-6;
var i=0;
	if (listArrayLength>0)
	{
		for (i=0;i<listArrayLength;i++)
		{
		myLocation+="../";
		}
	}
		else
		{
		myLocation="";
		}

}

function initField(frm,field)
{
document.forms[frm].elements[field].value="";	
}

function closeDiv(div)
{
document.getElementById(div).style.visibility="hidden";		
}

