// JavaScript Document

// Permet d'ouvrir une image avec un popup au mileieu de l'ecran à la taille de l'image
function PopupImage(img,titre,altimage,w,h) 
{ 
	entete="SIOPOS - "; 
	// Permet de recupérer la position opur le centrage
	LeftPosition = screen.width-w > 0 ?  (screen.width-w)/2 : 0;
	TopPosition = screen.height-h > 0 ? (screen.height-h)/2 : 0;
	
	w=open(img,'','width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',toolbar=no,scrollbars=no,resizable=no'); 
	w.document.write("<HTML><HEAD><TITLE>"+entete+titre+"</TITLE></HEAD>"); 
	w.document.write("<BODY onblur='window.close()' onclick='window.close()' leftMargin=0 topMargin=0 marginwidth=0 marginheight=0>");
	w.document.write("<TABLE width='100%' border='0' cellspacing='0' cellpadding='0' height='100%'><TR>");
	w.document.write("<TD valign='middle' align='center'><IMG src='"+img+"' border=0 alt='"+altimage+" - Cliquez pour fermer'>"); 
	w.document.write("</TD></TR></TABLE>");
	w.document.write("</BODY></HTML>"); 
	w.document.close();
}

// Prechargement de images
if (navigator.appVersion.substring(0,1) >= 3)
{
	i1=new Image;
	i1.src='Image/SIOPOS.jpg';
	i2=new Image;
	i2.src='Images/LOGO_GD.gif';
	i3=new Image;
	i3.src='Images/Fond.gif';
}

// Interdiction clic droit
function non(clic) 
{
	if (navigator.appName == 'Netscape' && clic.which==3)
		return false;
	else if (navigator.appName == 'Microsoft Internet Explorer' && event.button==2)
	{
		alert(msg);
		return false;
	}
	return true;
}
document.onmousedown = non;

// Maximisation de la fenêtre
function NoError()
{
	return true;
}

window.onerror=NoError;

if (parent.frames.length > 0)
{
	window.top.location.href = location.href;
}
window.moveTo(0,0);

if (document.all) 
{
	window.resizeTo(screen.availWidth,screen.availHeight);
}
else if (document.layers) 
{
	if (window.outerHeight<screen.availHeight||window.outerWidth<screen.availWidth)
	{
		window.outerHeight = screen.availHeight;
		window.outerWidth = screen.availWidth;
	}
}

// Highlight d'un bouton
function highlightButton(s) 
{
	if ("INPUT"==event.srcElement.tagName)
		event.srcElement.className=s
}

// Fonction qui permet de verifier le données du formulaire de saisie du livre d'Or
function verif ()
{
	if ( document.FormOr.EmailOr.value != "" )			
	{
		var emailStr=document.FormOr.EmailOr.value;
		var emailPat=/^(.+)@(.+)$/;
		var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
		var validChars="\[^\\s" + specialChars + "\]";
		var quotedUser="(\"[^\"]*\")";
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
		var atom=validChars + '+';
		var word="(" + atom + "|" + quotedUser + ")";
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
			
		var matchArray=emailStr.match(emailPat);
			
		if (matchArray==null) 
		{
			alert("Adresse E-mail incorecte (verrifiez les @ et les .)");
			return false;
		}
		var user=matchArray[1];
		var domain=matchArray[2];
		if (user.match(userPat)==null)
		{
			alert("Adresse E-mail incorecte");
			return false;
		}
			var IPArray=domain.match(ipDomainPat);
			if (IPArray!=null) {
				  for (var i=1;i<=4;i++) {
					if (IPArray[i]>255) {
						alert("Destination IP address is invalid!");
					return false;
					}
				}
			}
				var domainArray=domain.match(domainPat);
			if (domainArray==null) 
			{
				alert("Veuillez verrifier le nom de domaine");
				return false;
			}

			var atomPat=new RegExp(atom,"g");
			var domArr=domain.match(atomPat);
			var len=domArr.length;
			if (domArr[domArr.length-1].length<2 || 
				domArr[domArr.length-1].length>3) 
			{
			   alert("Veuillez verrifier le nom de domaine");
			   return false;
			}
			if (len<2) 
			{
			   var errStr="Veuillez verrifier le nom de domaine";
			   alert(errStr);
			   return false ;
			}
	}
	
	if ( document.FormOr.NomOr.value == "" )
	{
		alert ( "Vous devez remplir le Nom !" ) ;
		document.FormOr.NomOr.focus() ;
		return false ;
	}
	
	if ( document.FormOr.ComOr.value == "" )
	{
		alert ( "Vous devez saisir un message !" ) ;
		document.FormOr.ComOr.focus() ;
		return false ;
	}
	
	return true ;
}


// Fonction qui permet de faire defiler un texte dans la barre de status
var separateur = " ...       ";
var message = "";
var index = 0;

function defiler(param)
{
	message = param;
	var mess = message + separateur;
	
	window.status = mess.substring(index, mess.length + mess.substring( 0, index ));
	
	//window.status = mess.substring(1, mess.length) + mess.substring(1,1);
	
	index ++;
	if( index > mess.length )
		index = 0;
	
	window.setTimeout( "defiler( message )", 200 );
}
