// Capital Functions
function all_capital(form_n,val) {
	obj=eval("document."+form_n+"."+val)
	if (obj.value!="") obj.value = obj.value.toUpperCase();
}

function first_capital(form_n,val) {
	obj=eval("document."+form_n+"."+val)
	if (obj.value!="") {
			p1=obj.value.substring(0,1)
			p1 = p1.toUpperCase();
			p2=obj.value.substring(1,obj.value.length)
			obj.value = p1+p2
	}
}

function first_capital_2(form_n,val) {
	obj=eval("document."+form_n+"."+val)
	if (obj.value!="") {
			p1=obj.value.substring(0,1)
			p1 = p1.toUpperCase();
			p2=obj.value.substring(1,obj.value.length)
			obj.value = p1+p2
			// s'il y a 2 prénoms ??
			p1=""
			for (var i = 0; i < obj.value.length; i++) {
				car=obj.value.substring(i,i+1)
				if (car==" ") {
					p1=obj.value.substring(0,i)
					p2=obj.value.substring(i+1,obj.value.length)
				}
			}
			if (p1!="") {	// cas 2 prénoms
				c1=p1.substring(0,1)
				c1=c1.toUpperCase();
				c2=p1.substring(1,p1.length)
				
				c3=p2.substring(0,1)
				c3=c3.toUpperCase();
				c4=p2.substring(1,p2.length)
				obj.value = c1+c2+" "+c3+c4
			}
			p1=""
			p2=""
			for (var i = 0; i < obj.value.length; i++) {
				car=obj.value.substring(i,i+1)
				if (car=="-") {
					p1=obj.value.substring(0,i)
					p2=obj.value.substring(i+1,obj.value.length)
				}
			}
			if (p1!="") {	// cas 2 prénoms
				c1=p1.substring(0,1)
				c1=c1.toUpperCase();
				c2=p1.substring(1,p1.length)
				
				c3=p2.substring(0,1)
				c3=c3.toUpperCase();
				c4=p2.substring(1,p2.length)
				obj.value = c1+c2+"-"+c3+c4
			}
	}
}

// Calendar functions
var x,y
	
	function open_cal(img_nb,form_name,field_name) {
		//alert(img_nb)
		d_y=30
		img_nb=img_nb+''
		//obj=eval("document.all.img_cal_"+img_nb)
		obj=eval("document.getElementById('img_cal_"+img_nb+"')")
		curleft=posX(obj)
		curtop=posY(obj)
		//alert(curleft+"   "+curtop)
		x=curleft - document.body.scrollLeft
		y=curtop+d_y - document.body.scrollTop
		
		cur_date = new Date();
		sel_month = cur_date.getMonth() + 1;
		sel_year = cur_date.getYear();
		if (navigator.appName=="Netscape") {sel_year=sel_year+1900}
		
		//alert(x+"   "+y)
		
		param="toolbar=no,menubar=no,resizable=no,scrollbars=no,status=no,height=250,width=200,top="+y+",left="+x
		url="../calendar/calendar_e.htm?"+form_name+"&"+field_name+"&"+sel_month+"&"+sel_year
		cms_cal=window.open(url,'Calendar',param)
		cms_cal.focus()
	}
	
	function open_cal_fr(img_nb,form_name,field_name,align,valign) {
		//alert(img_nb)
		//cal_w=204
		//cal_h=215
		cal_w=204
		cal_h=230
		d_y=30
		img_nb=img_nb+''
		//obj=eval("document.all.img_cal_"+img_nb)
		obj=eval("document.getElementById('img_cal_"+img_nb+"')")
		curleft=posX(obj)
		curtop=posY(obj)
		//alert(curleft+"   "+curtop)
		x=curleft - document.body.scrollLeft
		y=curtop+d_y - document.body.scrollTop
		
		x=curleft-cal_w+31- document.body.scrollLeft
		y=curtop+18 // - document.body.scrollTop
		
		cur_date = new Date();
		sel_month = cur_date.getMonth() + 1;
		sel_year = cur_date.getYear();
		if (navigator.appName=="Netscape") {sel_year=sel_year+1900}
		
		//alert(x+"   "+y)

		//param="toolbar=no,menubar=no,resizable=no,scrollbars=no,status=no,height="+cal_h+",width="+cal_w+",top="+y+",left="+x
		url="../calendar/calendar.htm?"+form_name+"&"+field_name+"&"+sel_month+"&"+sel_year+"&"+img_nb
		//cms_cal=window.open(url,'Calendar',param)
		//cms_cal.focus()
		document.getElementById('div_calendar').style.visibility="visible"
		document.getElementById('div_calendar').style.top=y
		document.getElementById('div_calendar').style.left=x
		document.getElementById('div_calendar').style.top=y
		document.getElementById('div_frame').src=url
		
	}
	
	function posX(obj) {
	    var curleft = 0;
	    if (document.getElementById || document.all)
	    {
	         while (obj.offsetParent)
	         {
	              curleft += obj.offsetLeft
	              obj = obj.offsetParent;
	         }
	    }
	    else if (document.layers)
	         curleft += obj.x;
	    return curleft;
	}
	
	function posY(obj){
	    var curtop = 0;
	    if (document.getElementById || document.all)
	    {
	         while (obj.offsetParent)
	         {
	              curtop += obj.offsetTop
	              obj = obj.offsetParent;
	         }
	    }
	    else if (document.layers)
	         curtop += obj.y;
	    return curtop;
	} 

// Select into Text field function
function put_sel(fi,fo,h) {
	// put value of select box into text field
	// select name must be name of text field followed by "_sel"
		obj1=eval("document."+fo+"."+fi)	
		obj2=eval("document."+fo+"."+fi+"_sel")
		obj1.value=obj2.value
		//if (h!="") {obj2.style.display="none"}
	}
	
// fonction clignotement de couleur d'un objet
var nb_cl=10; bcs=1; ori_col=""; col=""
function blink_color(col,obj) {
	doc_obj=eval("document.getElementById('"+obj+"')")
	ori_col=doc_obj.style.color
	doc_obj.style.color=col
	col2=col
	obj2=obj
	setTimeout('blink_color_s(col2,obj2)',200)
}
function blink_color_s(col,obj) {
	bcs=bcs+1
	doc_obj=eval("document.getElementById('"+obj+"')")
	if(nb_cl > bcs) {
	doc_obj.style.color=ori_col
	col2=col
	obj2=obj
	setTimeout('blink_color(col2,obj2)',200)
	}
	else { doc_obj.style.color=ori_col
		bcs=0
	}
}

// fonction clignotement cacher/montrer
var cl=10; bhv=1; 
function blink_hv(obj) {
	doc_obj=eval("document.getElementById('"+obj+"')")
	doc_obj.style.visibility='hidden'
	obj2=obj
	setTimeout('blink_hv_s(obj2)',200)
}
function blink_hv_s(obj) {
	bhv=bhv+1
	doc_obj=eval("document.getElementById('"+obj+"')")
	if(cl > bhv) {
	doc_obj.style.visibility='visible'
	obj2=obj
	setTimeout('blink_hv(obj2)',200)
	}
	else {
		doc_obj.style.visibility='visible'
		bhv=0
		}
}
	
	
	//alert("cli_r : loaded");
//   Disable Right Clic
var message;
message="Bienvenue sur la boutique !"
function click(e) {
	if (document.all) {
		if (event.button == 2) {
		alert(message);
		return false;
		}
	}
	if (document.layers) {
		if (e.which == 3) {
		alert(message);
		return false;
		}
	}
}
	if (document.layers) {
		document.captureEvents(Event.MOUSEDOWN);
	}
//document.onmousedown=click;	// à remettre avant production


// Disable  F5  , Backspace Key , Enter Key as a submit (if f_focus() and f_blur() used in fields)

var key_back=0
var obj_type=""
function f_focus(val) {
	//obj=eval("document.forms[0]."+val)
	obj=eval(val)
	obj_type=obj.type
	key_back=1
}
function f_blur() {
	obj_type=""
	key_back=0
}


function mykeyhandler() {
	/*
	if (obj_type!="textarea") {
		if (window.event && window.event.keyCode == 13) {	// ENTER key disabled
	    	window.event.keyCode = 9; // replaced by TAB key
	  	}
	}
	*/
	if (window.event && window.event.keyCode == 116) {	// F5 refresh disabled
		//alert("f5")
    	window.event.keyCode = 8; // replaced by BACKSPACE key
  	}
	
	/*
	if (key_back==0) {
	    if (window.event && window.event.keyCode == 8) { // Backspace history -1 disabled
	        window.event.cancelBubble = true;
	        window.event.returnValue = false;
	        return false;
	    }
	}
	*/
	
}

document.onkeydown = mykeyhandler;  // control clavier