// ---------------------------------------------------------------
// initialisation des pages
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

// on deplace le browser en premier plan des fenetres windows
window.focus();

// on deplace le site vers la frame "_top", si elle ne l'est pas
if (this.location.href.indexOf('/admin/selectbanner_list.asp') == 0 || this.location.href.indexOf('/admin/selectbanner_prev.asp') == 0)
	if (window.top.location != this.location.href) { window.top.location = this.location.href;}


// ---------------------------------------------------------------
// permet le rafraichissement des banners
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ns4 = (document.layers)? true:false
ie4 = (document.all)? true:false
function hide(id) {
    if (ns4) { document.layers[id].visibility = "hide";}
    else if (ie4) { document.all[id].style.visibility = "hidden";}
}
function init() {
    if (ns4) { block = document.blockDiv;}
    if (ie4) { block = blockDiv.style;}
    block.xpos = parseInt(block.left)
}
function slide() {
    if (block.xpos < 370) {
        block.xpos += 1;
        block.left = block.xpos;
        setTimeout("slide()",100);}
    else { restart();}
}
function restart() {
    block.xpos = 230;
    block.left = block.xpos;
    slide();
}

// ---------------------------------------------------------------
// functions de RollOver
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function imgOn(imgName)
{
	if (document.images)
	{
		document[imgName].src = eval(imgName + "on.src");
	}
}

function imgOff(imgName)
{
	if (document.images)
	{
		document[imgName].src = eval(imgName + "off.src");
	}
}

// ---------------------------------------------------------------
// autres functions
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function preview()
{
  var txt = document.forms[0].text.value;
  
  if (txt != '') {
    window.open( 'visu.asp' ,'WavreMove','left=200,top=200,height=500,width=300,scrollbars=no,toolbar=no,resizable=no,directories=no,status=no,location=no');
  } else {
    alert('La champ du menu est vide.')
  }
}

function ShowHideTable(tname,action)
{
var coll = document.all.tags("TABLE");
if (coll != null) {
  if (action == "on")
    var newstate = ""
  else
    var newstate = "none";
    for (i=0; i<coll.length; i++)
      if (coll[i].id == tname)
        coll[i].style.display = newstate;
  }
}

function getKey()
{
    if (event.keyCode==13)
    {
	    //document.forms[FormName].submit();
		return true;
    }
	else
	{
		return false;
	}
}

function checkmail(name){
    var stremail = name;
    var strinValid = / (&)|(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)|[*'"]/;
    var strVaild = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
    if (!strinValid.test(stremail) && strVaild.test(stremail)) { 
        return true;
    } else {
        return false;
    }
}

/*
popup function by BiVo
*/
function popup(url,w,h,args)
{
	t = (screen.availHeight-h)/2;
	l = (screen.availWidth-w)/2;
	MyWindow = window.open (url, 'popup', 'top='+t+', left='+l+', width='+w+', height='+h+', '+args);
	setTimeout('MyWindow.focus();',500);
}

/*
popup function by Seb
function popup (url, w, h, args)
{
	var t = (screen.height-h)/2;
	var l = (screen.width-w)/2;
	MyWindow = window.open (url, 'popup', 'top='+t+', left='+l+', width='+w+', height='+h+', '+args);
	setTimeout('MyWindow.focus();',500);
}
*/

// Attention:	Il faut ABSOLUMENT envoyer l'url au format "/mondossier/monimage.jgp" et
//				non pas "\mondossier\monimage.jgp".
function zoom(url) {
		popup ('/include/zoomdisplay.asp?url='+url, 10, 10, 'location=no,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,toolbar=no');
}

// vérification de formulaire.
function VerifForm (FormName)
{
	// nom du formulaire
	var f = document.forms[arguments[0]].elements;
	// pour retourner 'true' ou 'false'
	var block = 0;
	
	// boucle pour trouver les elements obligatoires
	for (var i=0; i < f.length; i++)
	{
		// element
		var elem = f[i];
		
		// si element est requit
		if (elem.required  == "true" || elem.required  == "1")
		{
			// si element != de vide ET si element est une adresse mail
			//if (elem.value.length != 0)
			if (elem.value != '')
			{
				// si element est une adresse mail
				if (elem.param == "mail")
				{
					// si adresse mail pas valise
					if (!checkmail(elem.value))
					{
						// bloquer l'element
						block = 1;
					}
				}
			}
			// si element == vide
			else
			{
				// bloquer l'element
				block = 1;
			}
		}
		//else if ((elem.value.length != 0 && elem.param == "mail"))
		else if ((elem.value != '' && elem.param == "mail"))
		{
			// si adresse mail pas valise
			if (!checkmail(elem.value))
			{
				// bloquer l'element
				block = 1;
			}
		}
		
		// bloquage de l'envoi du formulaire
		if (block == 1)
		{
			//alert ("Le champ sélectionné n'est pas valide, il est requis !");
			alert ("Attention, une erreur a été détectée dans ce formulaire : veuillez complèter tous les champs obligatoires.");
			elem.focus();
			elem.select();
			return false;
		}
	}
}
