//Time in days to save form fields values after last visit
var memoryduration="30 days"

function setformobjects(){
var theforms=document.forms
memorizearray=new Array()
for (i=0; i< theforms.length; i++){
for (j=0; j< theforms[i].elements.length; j++){
if (theforms[i].elements[j].className.indexOf("memorize")!=-1 && theforms[i].elements[j].type=="text")
memorizearray[memorizearray.length]=theforms[i].elements[j]
}
}
var retrievedvalues=get_cookie("mvalue"+window.location.pathname)
if (retrievedvalues!=""){
retrievedvalues=retrievedvalues.split("|")
if (retrievedvalues[retrievedvalues.length-1]!=parseInt(memoryduration))
resetcookie("mvalue"+window.location.pathname)
else{
for (i=0; i<memorizearray.length; i++){
if (retrievedvalues[i]!="empty_value")
memorizearray[i].value=retrievedvalues[i]
}
}
}
}

function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
  return returnvalue;
}

function resetcookie(id){
var expireDate = new Date()
expireDate.setDate(expireDate.getDate()-10)
document.cookie = id+"=;path=/;expires=" + expireDate.toGMTString()
}

function saveformvalues(){
var formvalues=new Array(), temp
for (i=0; i<memorizearray.length; i++){
temp=memorizearray[i].value!=""? memorizearray[i].value : "empty_value"
formvalues[formvalues.length]=escape(temp)
}
formvalues[formvalues.length]=parseInt(memoryduration)
formvalues=formvalues.join("|")
var expireDate = new Date()
expireDate.setDate(expireDate.getDate()+parseInt(memoryduration))
document.cookie = "mvalue"+window.location.pathname+"="+formvalues+"; path=/;expires=" + expireDate.toGMTString()
}

if (window.addEventListener)
window.addEventListener("load", setformobjects, false)
else if (window.attachEvent)
window.attachEvent("onload", setformobjects)
else if (document.getElementById)
window.onload=setformobjects
if (document.getElementById)
window.onunload=saveformvalues

// Fonction menu d&eacute;roulant
function ChangeUrl(formulaire)
{
if (formulaire.ListeUrl.selectedIndex != 0)
{
location.href = formulaire.ListeUrl.options[formulaire.ListeUrl.selectedIndex].value;
}
else 
{
alert('Veuillez choisir une destination.');
}
}

// Fonction photo en popup
function PopupImage(img) {
	w=open("",'image','width=100,height=100,toolbar=no,scrollbars=no,resizable=no');
	w.document.write("<SCRIPT language=javascript>function checksize()  { if (document.images[0].complete) {  window.resizeTo(document.images[0].width+30,document.images[0].height+80); window.focus();} else { setTimeout('check()',250) } }</"+"SCRIPT>");
	w.document.write("<title>photo grand format</title>");
	w.document.write("<BODY onload='checksize()'>");
	w.document.write("<table width=98% align=center border=0 cellpadding=0 cellspacing=0><tr><td class=paragraphe>");
	w.document.write("<a href=\"javascript:window.close()\"><IMG class=image src='"+img+"' alt=Fermer>");
	w.document.write("</a>");
	w.document.close();
}

// Fonction photo en popup
function ouvreImage(img) {
	w=open("",'image','width=100,height=100,toolbar=no,scrollbars=no,resizable=no');
	w.document.write("<SCRIPT language=javascript>function checksize()  { if (document.images[0].complete) {  window.resizeTo(document.images[0].width+30,document.images[0].height+120); window.focus();} else { setTimeout('check()',250) } }</"+"SCRIPT>");
	w.document.write("<link rel=stylesheet type=text/css href=../_inc/style_int.css><title>photo grand format</title>");
	w.document.write("<BODY onload='checksize()' oncontextmenu='return false' ondragstart='return false' onselectstart='return false'  topmargin='0'>");
	
	w.document.write("<table width=100% height=100% align=center border=0 cellpadding=0 cellspacing=0><tr><td>");
	w.document.write("<table width=98% align=center border=0 cellpadding=0 cellspacing=0><tr><td class=parageneral>");
	w.document.write("<a href=\"javascript:window.close()\"><img class='impres' src='"+img+"' alt=Fermer>");
	w.document.write("</a><br /><br /><div align='center'><font style='color:#fff; font-weight:bold;'>Tous droits de reproduction interdits - &copy;Outremerveilles<br /><br /><font style='color:#fff; font-weight:bold;'><iframe frameborder=0 height=0 marginheight=0 marginwidth=0 src=../_inc/stats.inc></iframe></font></div></td></tr></table></td></tr></table");
	w.document.write("");
	w.document.write("</BODY></HTML>");
	w.document.close();
}

// FOnction limitation de caractères
function clearrecit(){
document.creation.recit.value="";
document.creation.charsleft.value="500";
document.creation.recit.focus();
}
function ShowCharsLeft(sms) {
if(navigator.appName!="Netscape") {
maxLength = 700
if (sms.recit.value.length > maxLength) {
sms.recit.value = creation.recit.value.substring(0,maxLength)
charleft = 0         
}
else {
charleft = maxLength - creation.recit.value.length
}
creation.charsleft.value=charleft
}}

// Fonction ouverture URL
function OuvrirFenetre(url) { window.open(url)}

// Fonction aller à (go page)
function go (page){
var gopage=page;
if ( (gopage != "") && (gopage != null) )
window.location=gopage;
}

// Fonction pr&eacute;load et survol images
//function MM_swapImgRestore() { //v3.0
//var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
//}
//function MM_preloadImages() { //v3.0
//var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
//var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
//if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
//}
//function MM_findObj(n, d) { //v4.01
//var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
//d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
//if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
//for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
//if(!x && d.getElementById) x=d.getElementById(n); return x;
//}
//function MM_swapImage() { //v3.0
//var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
//if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
//}

// Fonction limitaion de texte dans area
var ns6=document.getElementById&&!document.all

function restrictinput(maxlength,e,placeholder){
if (window.event&&event.srcElement.value.length>=maxlength)
return false
else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
var pressedkey=/[a-zA-Z0-9\.\,\/]/ 
if (pressedkey.test(String.fromCharCode(e.which)))
e.stopPropagation()
}
}

function countlimit(maxlength,e,placeholder){
var theform=eval(placeholder)
var lengthleft=maxlength-theform.value.length
var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
if (window.event||e.target&&e.target==eval(placeholder)){
if (lengthleft<0)
theform.value=theform.value.substring(0,maxlength)
placeholderobj.innerHTML=lengthleft
}
}

function displaylimit(thename, theid, thelimit){
var theform=theid!=""? document.getElementById(theid) : thename
var limit_text='<strong><span id="'+theform.toString()+'">'+thelimit+'</span></strong> caractéres maximum.'
if (document.all||ns6)
document.write(limit_text)
if (document.all){
eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
}
else if (ns6){
document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true); 
document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true); 
}
}
