//////////////////////////////////
// LA VOUGERAIE
/////////////////////////////////

var stopMove = 0;
var yValueMain = 0;
var posLayer = 0;
var clipRectValue;
var clipTopValue = 0;
var clipBottomValue;

function setClipBottom(clipBottom)
{
	clipBottomValue = clipBottom;
}

function moveLayer(yValue)
{
	var longueurTexte;
	if (document.layers)
	{
		if (document.ref)
		{
			var clipHeight = document.ref.document.thumb.clip.height;
			longueurTexte = document.ref.document.thumb.document.height - clipHeight + 10;
		}
		else
		{
			var clipHeight = document.thumb.clip.height;
			longueurTexte = document.thumb.document.height - clipHeight + 10;
		}
	}
	else if (document.all)
	{
		var clipHeight = document.all.thumb.style.height;
		clipHeight = clipHeight.substring(clipHeight, clipHeight.length - 2);
		longueurTexte = document.all.thumb.offsetHeight - clipHeight + 10;
	}
	posLayer += yValue;

	if ((document.layers || document.all) && stopMove == 0 && posLayer < 10 && posLayer > - longueurTexte)
	{
		clipTopValue += -yValue;
		clipBottomValue += -yValue;
		if (document.layers)
		{
			if (document.ref)
			{
				document.ref.document.thumb.top += yValue;
				document.ref.document.thumb.clip.top = clipTopValue;
				document.ref.document.thumb.clip.bottom = clipBottomValue;
			}
			else
			{
				document.thumb.top += yValue;
				document.thumb.clip.top = clipTopValue;
				document.thumb.clip.bottom = clipBottomValue;
			}
		}
		else if (document.all)
		{
			var clipWidth = document.all.thumb.style.width;
			clipWidth = clipWidth.substring(clipWidth, clipWidth.length - 2);

			clipRectValue = 'rect(' + clipTopValue + ' '+ clipWidth + ' ' + clipBottomValue + ' 0)';
			document.all.thumb.style.posTop += yValue;
			document.all.thumb.style.clip = clipRectValue;
		}
		yValueMain = yValue;
		setTimeout('moveLayer(yValueMain)', 75);
	}
	else clearTimeout();
}

function stopMoveLayer(stopValue)
{
	stopMove = 1;
	posLayer += stopValue;
}

function callMoveLayer(moveValue)
{
	if (!clipBottomValue)
	{
		alert("Vous devez rajouter la fonction javascript : setClipBottom(int) dans votre page.");
	}
	else
	{
		stopMove = 0;
		moveLayer(moveValue);
	}
}

function date_jour_fr()
{
	var date_jour=new Date();
	date_jour=don_date_format_fr(date_jour);
	return date_jour;
}

function don_date_format_fr(d1)
{
	var m=new Array(13);
	m[1]="Janvier"; m[2]="Février";m[3]="Mars"; m[4]="Avril"; m[5]="Mai"; m[6]="Juin";
	m[7]="Juillet";m[8]="Août"; m[9]="Septembre"; m[10]="Octobre";m[11]="Novembre"; m[12]="Décembre";
	var d=new Array(8);
	var mois=m[d1.getMonth()+1];
	var date=d1.getDate();
	var an=d1.getYear();
	if (an<200) an=1900+an;
	date=date+" "+mois+" "+an;
	return date;
}

function date_jour_en()
{
	var date_jour=new Date();
	date_jour=don_date_format_en(date_jour);
	return date_jour;
}

function don_date_format_en(d1)
{
	var m=new Array(13);
	m[1]="January"; m[2]="February";	m[3]="March"; m[4]="April"; m[5]="May"; m[6]="June";
 	m[7]="July";	m[8]="August"; m[9]="September"; m[10]="October";	m[11]="November"; m[12]="December";
	var d=new Array(8);
	var mois=m[d1.getMonth()+1];
	var date=d1.getDate();
	var an=d1.getYear();
	if (an<200) an=1900+an;
	switch(date)
	{
		case 1 | 21 | 31 :	term="st";
							break;
		case 2 | 22 :	term="nd";
						break;
		case 3 | 23 :	term="rd";
						break;
		default :	term="th";
	} 
	date= mois+", "+date+term+" "+an;
	return date;
}

function AfficheCalques()
{
	if(document.layers)
	{
		if(document.ref)
		{
			document.ref.left = (self.innerWidth - 750)/2;
			document.ref.top = (self.innerHeight - 350)/2;
			document.ref.visibility = "show";
			if(document.ref.document.thumb)
				document.ref.document.thumb.visibility= "show";
			if(document.ref.document.movebottom)
				document.ref.document.movebottom.visibility= "show";
			if(document.ref.document.movetop)
				document.ref.document.movetop.visibility= "show";
		}
	}
	else if(document.all)
	{
		if(document.all.ref)
		{
			document.all.ref.style.left = (document.body.clientWidth - 750)/2;
			document.all.ref.style.top = (document.body.clientHeight - 350)/2;
			document.all.ref.style.visibility = "visible";
		}
		if(document.all.thumb)
			document.all.thumb.style.visibility = "visible";
		if(document.all.movebottom)
			document.all.movebottom.style.visibility = "visible";
		if(document.all.movetop)
			document.all.movetop.style.visibility = "visible";
	}
}

///////////////////////////////////





function MM_swapImgRestore() {
  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_findObj(n, d) {
  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 && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() {
  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];}
}

function popup(url, type, height, width){
  var nsNav = (document.layers) ? 1 : 0;
  var ieNav = (document.all) ? 1 : 0;
  var left = 0;
  var top = 0;

  if(ieNav){
    left = (document.body.clientWidth - width)/2;
	top = (document.body.clientHeight - height)/2;
  }
  else if(nsNav){
    left = (self.innerWidth - width)/2;
	top = (self.innerHeight - height)/2;
  }
  
  wintype="toolbar=\'no\',menubar=\'no\',location=\'no\',scrollbars="+type+",resizable=0,top=0,left=0";
  wintype=wintype + ",height=" + height + ",width=" + width + ",top=" + top + ",left=" + left;
  var newwin = window.open(url,"Assistant"+type,wintype);
}

function search(obj,value)
{
	for (i=0; i < obj.length; i++)
	{
		if(obj[i].value==value)
		return i;
	}
}


function postform()
{
	postwizard();
}


function webeditor(field)
{
	window.open('kernel/services/webeditor/word.php?name='+field,'WebEditor','personalbar=no,toolbar=no,status=no,scrollbars=no,location=no,resizable=yes,menubar=no,titlebar=no,Top='+20+',Left='+20+',Width='+770+',Height='+620);
}

function webColor(value)
{
	return showModalDialog('kernel/services/color/color.htm',value,'status=no,scroll:no;resizable:no;dialogWidth:250px;dialogHeight:370px');
}

function webcalendar(name,hidden)
{
	window.open('kernel/services/calendar/calendar.php?name='+name+'&hidden='+hidden,'calendar_'+name,'status=yes,toolbar=no,scrollbars=yes,resizable=yes,width=200,height=180,left=20,top=20');
}

function validation()
{
	alert(document.form.webeditor.value);
}


function imageGallery(obj,img)
{
  document.wizard.obj.value=img;
}

function display()
{
	var name = document.wizard.template.value;
	if(name) document.image.src = "layers/images/"+name+".gif";
	else document.image.src = "layers/images/empty.gif";
}

//function replace
function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

//Paste the textareavalue in another area value field1 => field2
function paste(field1, field2, size){
	var2 = eval("document.wizard."+field2+".value");
	if(var2 == ""){
		var1 = eval("document.wizard."+field1+".value");
		var1 = replace(var1,'"',"''");
		var1 = replace(var1,'\r',"<br>");
		var1 = replace(var1,'\n',"<br>");
		if(size!=""){
			if(var1.length > size){
				var3 = var1.substring(0,size-4)+"...";
			}
			else{
				var3 = var1;
			}
		}
		else{
			var3 = var1;
		}
		//var3 = replace(var3,"'","/'");
		vareval = "document.wizard."+field2+".value=\""+var3+"\";";
		eval(vareval);

		//alert(var3.length+" &&& "+var1.length);
	}

}


//format the date of the art_date_begin of the day if null
function formatdatebegin(){
	//var datebegin,daY,daM,daD;
	var today = new Date();

	datebegin = document.wizard.art_date_begin.value;
	if (datebegin == ""){
		daY = today.getYear();
		daM = today.getMonth()+1;
		daD = today.getDate();
		if(daM < 10){
      	daM ="0" + daM;
   	}
   	if(daD < 10){
      	daD ="0" + daD;
   	}
		document.wizard.art_date_begin.value = daY+"-"+daM+"-"+daD;
	}
}
//format the date of the art_date_begin of the day if null
function formatdateend(){
	var dateend;
	dateend = document.wizard.art_date_end.value;
	if (dateend == ""){
		document.wizard.art_date_end.value = "2030-12-31";
	}
}


function listBoxValid()
{
  var rub = document.wizard.dir_name.value;
  var tem = document.wizard.art_form.value;
  if (rub != "" && tem != ""){
  	document.wizard.submit();
  }
  else{
  	alert("Le gabarit ou la rubrique ne sont pas sélectionnés");
  }
}

//format the number if the value is a number
function formatNumeric(fieldname){
	var val = StrString = eval("document.wizard."+ fieldname +".value");
	valreturn = "";
	//alert(val);
	if(numericValid(val)){
		if(val == 0 || val == "00" || val == "0 " || val == " 0"){
			valreturn = '';
			eval("document.wizard."+ fieldname +".value=\'\';")
		}
		else{
			if(val < 10 && val.length==1){
				valreturn = "0"+val;
			}
			else{
				valreturn = val;
			}
			//alert();
			eval("document.wizard."+ fieldname +".value=\'"+valreturn+"\';")
		}
	}
}



function getRadioIndex(obj)
{
	for (i=0; i < obj.length; i++)
	{
		if(obj[i].checked==true)
		return i;
	}
	return -1;
}



//add your validation function here
function myValid(value)
{
    if(value=="")
    {
        return false;
    }
    else
    {
        return true;
    }
}
//END OF FORM VALIDATION

//SUBMIT forms
//list_rubrik
function postformrubrik(action)
{
	document.list_rubrik.action = action;
	document.list_rubrik.submit();
}

function checkallsearch(formulaire,chaine)
{
var nom_champ = chaine.substring(0,chaine.length - 1);
var init_field = formulaire.elements[nom_champ];

for (var i=0; i<formulaire.elements.length; i++)
  {
    var e = formulaire.elements[i];
    if (e.name.search(chaine) != -1)
	  {
		if( init_field.checked>0  )
		  {
			e.checked = 1;
		  }
		else e.checked = 0;
		
	  }
   }
}

function checkRights(formulaire,init_field,tab_id)
{
	for (i=0;i<tab_id.length;i++)
	{
		var e = formulaire.elements[tab_id[i]];
		if( formulaire.elements[init_field].checked>0  )
			e.checked = 1;
		else
			e.checked = 0;
	}
}