/*______________________________________________________*/
/*							*/
/*	********* DYNAMIC LAYER OBJECT *********	*/
/*	********* � Luc Thibault, 2003 *********	*/
/*	******** aztekstudio@9online.fr ********	*/
/*______________________________________________________*/



function DivObject(name,nest){
	this.name = name
	this.nest = nest
	if (is.DOM || is.opera){
		this.css = document.getElementById(name).style
		this.doc = this.elm = document.getElementById(name)
	} else if (is.ie4){
		this.css = document.all[name].style
		this.doc = this.elm = document.all[name]
	} else if (is.ns4){
		str = (nest) ? 'document.'+this.nest+'.document.layers["'+this.name+'"]' : 'document.layers["'+this.name+'"]'
		this.css = this.elm = eval(str)
		this.doc = this.css.document
	}
	this.obj = this.name + "DivObject"
	eval(this.obj + "=this")

	this.getX = getDivX
	this.getY = getDivY
	this.getW = getDivW
	this.getH = getDivH

	this.showHide = showHideDiv
	this.setBg = setDivBg
	this.setX = setDivX
	this.setY = setDivY
	this.moveTo = moveDivTo
	this.moveBy = moveByDiv
	this.clipTo = clipDiv		// opera not supported
	this.getClip = getDivClipVal

	this.load = DivLoad
	this.loadEnd = DivLoadFinish
	this.write = DivWrite
	this.rollOver = imgRollOver

	this.slideTo = DivSlideTo
	this.slideBy = DivSlideBy
	this.slideStart = DivSlideStart
	this.slide = DivSlide

	this.wipeTo = DivWipeTo		// opera not supported
	this.wipeBy = DivWipeBy
	this.wipeStart = DivWipeStart
	this.wipe = DivWipe

	if (useEvents) {
		this.addEventListener = evtAddListener;
		this.removeEventListener = evtRemoveListener;
	}
}

function getDivX(){
	if (is.opera) return this.css.pixelLeft
	else if (is.DOM) return parseInt(this.css.left.substring(0,this.css.left.length-2))
	else if (is.ns) return this.css.left;
}
function getDivY(){
	if (is.opera) return this.css.pixelTop
	else if (is.DOM || is.ie) return parseInt(this.css.top.substring(0,this.css.top.length-2))
	else if (is.ns) return this.css.top;
}
function getDivW(){
	if (is.opera) return this.css.pixelWidth
	else if (is.DOM || is.ie) return parseInt(this.doc.offsetWidth)
	else if (is.ns) return this.doc.width;
}
function getDivH(){
	if (is.opera) return this.css.pixelHeight
	else if (is.DOM || is.ie) return parseInt(this.doc.offsetHeight)
	else return this.doc.height;
}

function showHideDiv(onoff){
	this.css.visibility = onoff ? "visible" : "hidden"
}

function setDivBg(bg){
	if (bg.substring(0,1)=='#'){
		if (is.ns4) this.css.bgColor = bg
		else  this.css.backgroundColor = bg
	} else this.css.backgroundImage = 'url('+bg+')'
}

function moveDivTo(x,y){
	this.setX(x)
	this.setY(y)
}
function setDivX(x) {this.css.left = x}
function setDivY(y) {this.css.top = y}

function moveByDiv(dx,dy) {
	this.css.left = this.getX()+dx
	this.css.top = this.getY()+dy
}

function clipDiv(l,t,r,b){
	if (is.DOM || is.ie4) {
		this.css.width=r
		this.css.height=b
		this.css.clip = 'rect(' + t + 'px ' + r + 'px ' + b + 'px ' + l + 'px)'
	} else if (is.ns4){
		this.css.clip.left = l
		this.css.clip.right = r
		this.css.clip.top = t
		this.css.clip.bottom = b
	} else if (is.opera) {
		this.css.pixelWidth = r
		this.css.pixelHeight = b
	}
}
function getDivClipVal(which){
	if (is.DOM){
		clipv = this.css.clip.split("rect(")[1].split(")")[0];
		if (is.ie) clipv = clipv.split("px");
		else {
			clipv = clipv.split(", ");
			for (i=0;i<clipv.length;i++) clipv[i] = clipv[i].substring(0, clipv[i].length-2);
		}
	}
	if (which=="t") return (is.DOM)? parseInt(clipv[0]) : this.css.clip.top
	if (which=="r") return (is.DOM)? parseInt(clipv[1]) : this.css.clip.right
	if (which=="b") return (is.DOM)? parseInt(clipv[2]) : this.css.clip.bottom
	if (which=="l") return (is.DOM)? parseInt(clipv[3]) : this.css.clip.left
}

function DivLoad(url,fn) {
	if (is.DOM){
		window.bufferFrame.document.body.innerHTML = '';
		window.bufferFrame.document.location = url;
	} else this.doc.load(url,this.getW());
	this.evalfn = fn
}
function DivLoadFinish() {
	if (is.DOM) this.write(window.bufferFrame.document.body.innerHTML)
}
function DivWrite(html){
	if (is.DOM || is.ie){
		this.doc.innerHTML = html;
	} else {
		this.doc.open();
		this.doc.write(html);
		this.doc.close();
	}
}
function imgRollOver(name,url){
	if (is.opera) document[name].src = url
	else {
		doc = (is.ns4) ? this.doc : document;
		doc.images[name].src =  url
	}
}

/************ SLIDE FUNCTIONS ***********/

function DivSlideTo(endx,endy,inc,speed,fn){
	if (endx==null) endx = this.getX()
	if (endy==null) endy = this.getY()
	var distx = endx-this.getX()
	var disty = endy-this.getY()
	this.slideStart(endx,endy,distx,disty,inc,speed,fn)
}
function DivSlideBy(distx,disty,inc,speed,fn){
	var endx = this.getX() + distx
	var endy = this.getY() + disty
	this.slideStart(endx,endy,distx,disty,inc,speed,fn)
}
function DivSlideStart(endx,endy,distx,disty,inc,speed,fn){
	if (this.slideActive) return
	if (!inc) inc = 10
	if (!speed) speed = 20
	var num = Math.sqrt(Math.pow(distx,2) + Math.pow(disty,2))/inc
	if (num==0) return
	var dx = distx/num
	var dy = disty/num
	if (!fn) fn = null
	this.slideActive = true
	this.slide(dx,dy,endx,endy,num,1,speed,fn)
}
function DivSlide(dx,dy,endx,endy,num,i,speed,fn){
	if (!this.slideActive) return
	if (i++ < num) {
		this.moveBy(dx,dy)
		setTimeout(this.obj+".slide("+dx+","+dy+","+endx+","+endy+","+num+","+i+","+speed+",\""+fn+"\")",speed)
	} else {
		this.slideActive = false
		this.moveTo(endx,endy)
		eval(fn)
	}
}

/************ WIPE FUNCTIONS ************/

function DivWipeTo(endt,endr,endb,endl,num,speed,fn){
	var distt = (endt!=null)? endt-this.getClip('t'):0
	var distr = (endr!=null)? endr-this.getClip('r'):0
	var distb = (endb!=null)? endb-this.getClip('b'):0
	var distl = (endl!=null)? endl-this.getClip('l'):0
	this.wipeStart(distt,distr,distb,distl,endt,endr,endb,endl,num,speed,fn)
}
function DivWipeBy(distt,distr,distb,distl,num,speed,fn){
	this.wipeStart(distt,distr,distb,distl,distt+this.getClip('t'),distr+this.getClip('r'),distb+this.getClip('b'),distl+this.getClip('l'),num,speed,fn)
}
function DivWipeStart(distt,distr,distb,distl,endt,endr,endb,endl,num,speed,fn){
	if (this.wipeActive) return
	if (!fn) fn = null
	this.wipeActive = true
	this.wipe(distt/num,distr/num,distb/num,distl/num,endt,endr,endb,endl,this.getClip('t'),this.getClip('r'),this.getClip('b'),this.getClip('l'),num,1,speed,fn)
}
function DivWipe(dt,dr,db,dl,endt,endr,endb,endl,st,sr,sb,sl,num,i,speed,fn){
	if (!this.wipeActive) return
	if (i++ < num) {
		this.clipTo(sl+i*dl,st+i*dt,sr+i*dr,sb+i*db)
		setTimeout(this.obj+".wipe("+dt+","+dr+","+db+","+dl+","+endt+","+endr+","+endb+","+endl+","+st+","+sr+","+sb+","+sl+","+num+","+i+","+speed+",\""+fn+"\")",speed)
	} else {
		this.wipeActive = false
		this.clipTo(endl,endt,endr,endb)
		eval(fn)
	}
}

/************ PAGE FUNCTIONS **************/

function OffsetX(){
	if (is.ns || is.opera) return parseInt(window.pageXOffset);
	else if (is.ie) return document.body.scrollLeft;
}
function pageW(){
	if (is.ns || is.opera) return parseInt(window.innerWidth);
	else if (is.ie) return document.body.offsetWidth;
}
function getInnerWidth(){
	var w = 0;
	if (is.ns) {
		w = window.innerWidth
		if (document.height > window.innerHeight) w -= 16 // vert scrollbar
	} else if (is.ie4up) {
		w = document.body.clientWidth
	} else if (is.opera) {w = window.innerWidth}
	return w;
}

function OffsetY(){
	if (is.ns || is.opera) return parseInt(window.pageYOffset);
	else if (is.ie) return document.body.scrollTop;
}
function pageH(){
	if (is.ns || is.opera) return parseInt(window.innerHeight);
	else if (is.ie) return document.body.offsetHeight;
}
function getInnerHeight(){
	var h = 0;
	if (is.ns) {
		h = window.innerHeight
		if (document.width > window.innerWidth) h -= 16	// horz scrollbar
	} else if (is.ie4up) {
		h = document.body.clientHeight
	} else if (is.opera) {h = window.innerHeight}
	return h;
}

if (useEvents) {
	testEvent = new dynEventObject();
	if (is.ns4 || is.opera) evtAdd(window, "resize", cbeDefaultOnResizeListener)
	if (!window.addEventListener) {
		window.addEventListener = evtAddWindowListener;
		window.removeEventListener = evtRemoveWindowListener;
	}
	if (!document.addEventListener) {
		document.addEventListener = evtAddDocumentListener;
		document.removeEventListener = evtRemoveDocumentListener;
	}
}

/************ CREATE LAYERS *************/

function createDiv(name,x,y,w,h,visible,z,bg,content,special){
	vis= visible? "visible" : "hidden"
	spe= special? special : '';
	if (is.ie || is.DOM) {
		tstW=(w!=null)?' width:'+w+'px;':(is.ns5 || is.opera)?'':' width:1px;';
		tstH=(h!=null)?' height:'+h+'px;':(is.ns5 || is.opera)?'':' height:1px;';
		bkgd = (is.opera) ? 'background :'+bg+';' : (bg!=null)? (bg.substring(0,1)!='#')? 'background-image: url('+bg+');' : 'background-color:'+bg+';' : '';
		chaine='<div id="'+name+'" style="position:absolute; left:'+x+'px; top:'+y+'px; '+tstW+tstH+' visibility:'+vis+'; z-index:'+z+'; '+bkgd+ '" '+special+'>\n'+content+'\n</div>\n';
	} else {
		tstW=(w!=null)?' width='+w:'width=1';
		tstH=(h!=null)?' height='+h:'height=1';
		bkgd = (bg!=null)? (bg.substring(0,1)!='#')? 'background="'+bg+'" ' : 'bgColor="'+bg+'" ' : '';
		chaine='<layer NAME="'+name+'"  left='+x+' top='+y+' '+tstW+' '+tstH+' z-index='+z+' visibility='+vis+' '+bkgd+' '+special+'>\n'+content+'\n</layer>\n';
	}
	//alert(chaine);
	document.writeln(chaine);
}

/************ PRELOAD IMAGES *************/

var loadImg = new Array()
var count = 0;
var valid = new Array()

function preloadImage(url) {
	i = loadImg.length
	loadImg[i] = new Image
	loadImg[i].src = url
}

function testPreload(){
	for (i=0;i<loadImg.length;i++) {
		if (loadImg.length-count == 1) {
			init()
			break
		} else {
			if ((loadImg[i].complete == true)&&(valid[i] != true)) {
				valid[i] = true;
				count++
			}
			if (i==loadImg.length-1) setTimeout("testPreload()", 100)
		}
	}
}

/************ OPEN WINDOWS *************/

var variation;
var zoom;

if (is.ns) variation = (is.mac)?1:5;
if (is.ie) variation = (is.mac)?-25:0;

function openWindow(url,nom,dimx,dimy,type) {
	dimy = eval(dimy - parseInt(variation));
	featur0 = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width="+ dimx + ",height=" + dimy;
        featur1 = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width="+ dimx + ",height=" + dimy;
	featur2 = "toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width="+ dimx + ",height=" + dimy;
	props = eval('featur'+type);
	win = window.open(url,nom,props);
	win.focus();
	return win;
}


/************ FORM VALIDATION (Jaad - je savais pas trop ou le mettre) *************/
function validation()
{
if (formulaire.nom.value.length < 1) {window.alert("Veuillez entrer votre nom");return false;}
if (formulaire.prenom.value.length < 1) {window.alert("Veuillez entrer votre prenom");return false;}
if (formulaire.societeCode.value.length < 1) {window.alert("Veuillez entrer votre societe ou votre code projet");return false;}
if (formulaire.cp.value.length < 5) {window.alert("Veuillez entrer votre code postal");return false;}
if (formulaire.ville.value.length < 1) {window.alert("Veuillez entrer votre ville");return false;}
if (formulaire.pays.value.length < 1) {window.alert("Veuillez entrer votre pays");return false;}
if (formulaire.email.value.length < 1) {window.alert("Veuillez entrer votre email");return false;} 
if (formulaire.niveauFormation.value.length < 1) {window.alert("Veuillez entrer votre niveau de formation");return false;} 
if (formulaire.emploiOccupe.value.length < 1) {window.alert("Veuillez entrer votre emploi precedemment occupe");return false;} 
if (formulaire.nomEmployeur.value.length < 1) {window.alert("Veuillez entrer le nom de votre precedent employeur");return false;} 
if (formulaire.tempsTravail.value.length < 1) {window.alert("Veuillez entrer le temps de travail de votre situation actuelle");return false;} 

return true;
}

