
function getObj(name)
{
//  alert("getObj('"+name+"')");
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
//  alert("this.obj : " + this.obj + "\nthis.style : " + this.style);
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function focused_value(field, init_value)
{
	if (field.value == init_value)
		field.value = "";
}

function getVar (nomVariable)
{
	var infos = location.href.substring(location.href.indexOf("?")+1, location.href.length)+"&";
	if (infos.indexOf("#")!=-1)
		infos = infos.substring(0,infos.indexOf("#"))+"&";
	var variable=null
	{
		nomVariable = nomVariable + "=";
		var taille = nomVariable.length;
		if (infos.indexOf(nomVariable)!=-1)
			variable = infos.substring(infos.indexOf(nomVariable)+taille,infos.length).substring(0,infos.substring(infos.indexOf(nomVariable)+taille,infos.length).indexOf("&"));
	}
	return variable
}

/*************************************************************************
		Fonctions de gestion des boites et fenetres
*************************************************************************/
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

var windowSize;
function getWindowSize()
{
	var frameWidth = 0;
	var frameHeight = 0;
	if (self.innerWidth)
	{
		frameWidth = self.innerWidth;
		frameHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		frameWidth = document.documentElement.clientWidth;
		frameHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		frameWidth = document.body.clientWidth;
		frameHeight = document.body.clientHeight;
	}
	return [frameWidth,frameHeight];
}
addLoadEvent(function() {
	windowSize = getWindowSize();
});

var remote = null;
function openslide(rmode, phpsession) {
	remote = window.open("/i-Contact/hmenuc.jsp?rmode="+rmode+"&phpsession="+phpsession,"remotewin","toolbar=no,top=0,left=0,width="+(screen.width-10)+",height="+(screen.height-90)+",directories=no,status=no,scrollbars=no,resizable=yes,menubar=no,title=no");
//	remote.focus();
}

function GoFlash()
{
	var objetFlash = new getObj("animation_flash");
	var where = getVar("anim");
	if (where != null)
		objetFlash.obj.GotoFrame(where);
		objetFlash.obj.Play();
}

window.onresize = function(){
	windowSize = getWindowSize();
//	replaceDiaporamasSlide();
}

addLoadEvent(function() {
	windowSize = getWindowSize();
//	replaceDiaporamasSlide();
});

//////////////////////////////////////////////////////////////////////////

/*************************************************************************
		Fonctions de déplacement du slide
*************************************************************************/
var clipLeft = 0; // replace clipTop
var clipHeight = 54; // replace clipWidth
var clipRight = 456; // replace clipBottom
var lefter = 0; // replace topper
var totalAmount = 0; // replace topper
var lyrheight = 0;
var time,amount,theTime,theHeight,DHTML;

function replaceDiaporamasSlide()
{
	var obj_exemples_diaporamas = new getObj('exemples_diaporamas');
	var x = new getObj('slide_complet');
	
	var obj_exemples_diaporamas_position = findPos(obj_exemples_diaporamas.obj);
	lefter = obj_exemples_diaporamas_position[0] + 250 - totalAmount;
	
	if (document.layers)
	{
		x.style.left = lefter;
	}
	else if (document.getElementById || document.all)
	{
		x.style.left = lefter + 'px';
	}
}

function init()
{
	DHTML = (document.getElementById || document.all || document.layers)
	if (!DHTML) return;

	var obj_exemples_diaporamas = new getObj('exemples_diaporamas');
	var obj_exemples_diaporamas_position = findPos(obj_exemples_diaporamas.obj);
	
	lefter = obj_exemples_diaporamas_position[0] + 250;
	
	var x = new getObj('slide_complet');
	if (document.layers)
	{
		lyrheight = x.style.clip.right;
		lyrheight += 20;
		x.style.clip.left = clipLeft;
		x.style.clip.top = 0;
		x.style.clip.bottom = clipWidth;
		x.style.clip.right = clipRight;
		x.style.left = lefter;
	}
	else if (document.getElementById || document.all)
	{
		lyrheight = x.obj.offsetWidth;
		x.style.left = lefter + 'px';
		x.style.clip = 'rect(0px,'+clipRight+'px,'+clipHeight+'px,'+clipLeft+'px)';
	}
}

function scrollayer(layername,amt,tim)
{
	if (!DHTML) return;
	thelayer = new getObj(layername);
	if (!thelayer) return;
	amount = amt;
	theTime = tim;
	realscroll();
}

function realscroll()
{
	if (!DHTML) return;
	clipLeft += amount;
	clipRight += amount;
	lefter -= amount;
	totalAmount += amount;
	if (clipLeft < 0 || clipRight > lyrheight)
	{
		clipLeft -= amount;
		clipRight -= amount;
		lefter += amount;
		totalAmount -= amount;
		return;
	}
	if (document.getElementById || document.all)
	{
		clipstring = 'rect(0px,'+clipRight+'px,'+clipHeight+'px,'+clipLeft+'px)';
		thelayer.style.clip = clipstring;
		thelayer.style.left = lefter + 'px';
	}
	else if (document.layers)
	{
		thelayer.style.clip.left = clipLeft;
		thelayer.style.clip.right = clipRight;
		thelayer.style.left = lefter;
	}
	time = setTimeout('realscroll()',theTime);
}

function stopScroll()
{
	if (time) clearTimeout(time);
}

addLoadEvent(function() {
//	init();
});


//////////////////////////////////////////////////////////////////////////

/*************************************************************************
		Fonctions de gestion des cookies
*************************************************************************/
function EcrireCookie(nom, valeur)
{
   var argv=EcrireCookie.arguments;
   var argc=EcrireCookie.arguments.length;
   var expires=(argc > 2) ? argv[2] : null;
   var path=(argc > 3) ? argv[3] : null;
   var domain=(argc > 4) ? argv[4] : null;
   var secure=(argc > 5) ? argv[5] : false;
   document.cookie=nom+"="+escape(valeur)+
   ((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
   ((path==null) ? "" : ("; path="+path))+
   ((domain==null) ? "" : ("; domain="+domain))+
   ((secure==true) ? "; secure" : "");
}
function getCookieVal(offset)
{
   var endstr=document.cookie.indexOf (";", offset);
   if (endstr==-1) endstr=document.cookie.length;
   return unescape(document.cookie.substring(offset, endstr));
}
function LireCookie(nom)
{
   var arg=nom+"=";
   var alen=arg.length;
   var clen=document.cookie.length;
   var i=0;
   while (i<clen)
   {
       var j=i+alen;
       if (document.cookie.substring(i, j)==arg) return getCookieVal(j);
       i=document.cookie.indexOf(" ",i)+1;
       if (i==0) break;
   }
   return null;
}
function EffaceCookie(nom)
{
   date=new Date;
   date.setFullYear(date.getFullYear()-1);
   EcrireCookie(nom,null,date);
}

function dologforayear() {
   var f1=new getObj("password").obj.value;
   var f2=new getObj("login").obj.value;
   date=new Date;
   date.setFullYear(date.getFullYear()+1);
   EcrireCookie("kizoapwd", f1, date);
   EcrireCookie("kizoalog", f2, date);
}

function ChargeCookieKizoa()
{
	var login = LireCookie("kizoalog");
	var password = LireCookie("kizoapwd");

	if (login != null && password != null)
	{
		new getObj("login").obj.value = login;
		new getObj("password").obj.value = password;
		new getObj("memoriser").obj.checked = true;
	}
}

addLoadEvent(function() {
	ChargeCookieKizoa();
});

//////////////////////////////////////////////////////////////////////////

/*************************************************************************
		Fonctions de gestion du formulaire
*************************************************************************/

function supprimeCookie()
{
	var memoriser = new getObj("memoriser");
	if (memoriser.obj.checked == false)
	{
		EffaceCookie("kizoalog");
		EffaceCookie("kizoapwd");
	}
}

function loginsubmit(evt) {
	if(document.all)evt = event;
  var characterCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
  if (characterCode == 13)
  {
		processForm();
		return false;
	}
  else
    return true;
}

var req = null;

function processForm()
{
	var formulaire = new getObj("login_form");
	if(formulaire.obj.elements[2].checked == true)
	{
		dologforayear();
	}

	remote = window.open("","remotewin","toolbar=no,top=0,left=0,width="+(screen.width-10)+",height="+(screen.height-90)+",directories=no,status=no,scrollbars=no,resizable=yes,menubar=no,title=no");
	formulaire.obj.target = "remotewin";
	formulaire.obj.submit();
	remote.focus();
   
/*
   var url = "/i-Contact/ControllerServlet?operation=22&login="+formulaire.obj.elements[0].value+"&password="+formulaire.obj.elements[1].value;
	
	openslide(1);

	// native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = function() {checkLogin();};
        req.open("GET", url, true);
        req.send(null);
    // IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = function() {checkLogin();};
            req.open("GET", url, true);
            req.send();
        }
    }  */
}

function checkLogin()
{
    // only if req is "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            results = req.responseText;
//			alert(results);
			if (results.indexOf("<status>ok</status>") > 0)
			{
//				openslide(1);
			}
			else
			{
				remote.close();
				alert("Nom d'utilisateur ou mot de passe incorrect.");
			}
		}
	}
}


