var rPos = new Array();
if(lg=='en') {
	rPos[1] = 52;
	rPos[2] = 140;
	rPos[3] = 262;
	rPos[4] = 356;
} else {
	rPos[1] = 0;
	rPos[2] = 160;
	rPos[3] = 254;
	rPos[4] = 365;
}

var rStyle = new Array();
rStyle[1] = 'left';
rStyle[2] = 'left';
rStyle[3] = 'left';
rStyle[4] = 'left';

//var zoom = new Object();
/**
 *
 */
function init() {
	var tg = document.getElementsByTagName('IMG');
	for(var i=0;i<tg.length; i++) {
		if(tg[i].className == 'imageaveczoom') {
			var tmp = tg[i].src;
			var id = tmp.substring(tmp.lastIndexOf('/')+1, tmp.length);
			tg[i].style.cursor = 'pointer';
			tg[i].onclick= getZoom;
//			zoom[id] = new Image();
//			zoom[id].src = tmp;
		}
	}
}
/**
 *
 */
function getZoom(evt) {
	var e, src;
	var param = new Array();
	if(document.all) {
		e = window.event;
		src = e.srcElement.src;
	} else {
		e = evt;
		src = e.target.src;
	}
	param[0]='v='+src.substring(src.lastIndexOf('/')+1, src.length);
	window.open('zoom.php?'+param.join('&'),'zoom', 'width=800,height=600,scrollbars=no');
}

function rubInfo(id)
{
	var tg = document.getElementById('detail');
	if(!tg)
		return false;
	if(id==0) {
		tg.innerHTML = '';
		for(var i=1; i<5; i++) {
			tg = document.getElementById('rublink'+i);
			if(tg) {
				tg.style.color = '#ffffff';
			}
			document.getElementById('menupic_'+i).src = 'media/'+lg+'/menu/r'+i+'_0.gif';
			document.getElementById('pic'+i).src = 'media/img/bt_rub'+i+'_0.jpg';
		}
	} else {
		document.getElementById('menupic_'+id).src = 'media/'+lg+'/menu/r'+id+'_1.gif';
		document.getElementById('pic'+id).src = 'media/img/bt_rub'+id+'_1.jpg';
		tg.innerHTML = '<div style="border: solid 0px blue;height:46px;line-height:13px;text-align: '+rStyle[id]+';padding-left:'+rPos[id]+'px;">'+rubData[id][0]+'</div>';
	}
	return true;
}
/**
 *
 */
function checkSearchField(obj, val, st) {
	o = obj.value;
	switch(st) {
		case 1:
			if(o==val)
				obj.value='';
			break;
		case 0:
			if(o=='')
				obj.value=val;
			break;
	}
}
/**
 *
 */
function swapField(st, obj, field) {
	for(var i=0; i<field.length; i++) {
		obj.elements[field[i]].disabled=st;
	}
}
/**
 *
 */
function setDisplay(d, st) {
	var disp = (st==1) ? 'block' : 'none' ;
	var tg = document.getElementById(d);
	if(tg) {
		tg.style.display = disp;
	}
	return;
}
/**
 *
 */
function setAsso(obj, d) {
	var disp = (obj.selectedIndex==0) ? 'block' : 'none' ;
	var tg = document.getElementById(d);
	if(tg) {
		tg.style.display = disp;
	}
	return;
}
/**
 *
 */
function selectTheme(obj,n) {
	if(obj[n].value!='')
    	self.location = 'img.php?theme='+obj[n].value ;
	return;
}
/**
 *
 */
function check() {
	if (document.forms.f.elements.libelle.value.length!=0) {
		document.forms.f.submit();
	} else {
		alert('vous devez renseigner le champs libelle');
	}
}
/**
 *
 */
function setEditoType(st, on, off) {
	var dispOff = st==true ? 'block' : 'none';
	var dispOn = st==true ?  'none' : 'block';
	for(var i=0; i<on.length; i++) {
		document.getElementById(on[i]).style.display = dispOn;
	}
	for(var i=0; i<off.length; i++) {
		document.getElementById(off[i]).style.display = dispOff;
	}
}
/*
function hover(obj){
  if(document.all){
    UL = obj.getElementsByTagName('ul');
    if(UL.length > 0){
      sousMenu = UL[0].style;
      if(sousMenu.display == 'none' || sousMenu.display == ''){
        sousMenu.display = 'block';
      }else{
        sousMenu.display = 'none';
      }
    }
  }
}
function setHover(id){
  LI = document.getElementById(id).getElementsByTagName('li');
  nLI = LI.length;
  for(i=0; i < nLI; i++){
    LI[i].onmouseover = function(){
      hover(this);
    }
    LI[i].onmouseout = function(){
      hover(this);
    }
  }
}
*/
/**
 *
 */
function setTopColor(obj, tg, max) {
//	var tmp = obj.form.
	for(var i=0; i<max; i++) {
//		document.getElementById(tg+''+(i+1)).style.backgroundColor=obj[obj.selectedIndex].value;
		document.getElementById(tg+''+(i+1)).src= '../media/img/newsletter/p'+(i+1)+'_'+(obj.selectedIndex+1)+'.gif';
	}
}
//////////////////////////////////////////////////////////////////
// V2
//////////////////////////////////////////////////////////////////

function arboOver(obj, im){
	var sousMenu;
	if(im==null) {
		return;
	}
	var tmp = '/'+im.id.replace('p', '');
	var imgStatus=0;
	var UL = $$('#'+obj.id+' .movable');//obj.getElementsByTagName('div');
	if(UL.length > 0){
		sousMenu = UL[0].style;
		if(sousMenu.display == 'none' || sousMenu.display == ''){
			sousMenu.display = 'block';
			imgStatus=1;
		}else{
			sousMenu.display = 'none';
			imgStatus=0;
		}
	}
	if(imgStatus==1) {
		im.src = '../media/img/puce_moins.gif';	
		var oldPath = self.location.hash.replace('#/', '').split('/');
		for(var i=0; i<oldPath.length; i++) {
			if(oldPath[i]==tmp.replace('/', '')) {
				return;
			}
		}
		self.location.hash += tmp;

	} else {
		self.location.hash = self.location.hash.replace(tmp, '');
		im.src = '../media/img/puce_plus.gif';	
	}
	return;
}
/**
 * 
 */
function initArbo(obj, p) {
	var tmp = $(obj);
	var tmpPath = p;
	var tmpRub = tmpPath.split('/'); 
	for(var i=0; i<tmpRub.length; i++) {
		if(tmpRub[i]!='#') {
			arboOver( $(tmpRub[i]), $('p'+tmpRub[i]));
		}
	}
}
/**
 * formulaire d'ajout de sous-rubrique
 */
function addRub(id, tg) {
	var url = "rub_form.php";
	var params = "id_rub="+id;
	var ajax = new Ajax.Request(url,{
		method: "post",
		parameters: params,
		onLoading: function(){},
		onComplete : function(n){ 
			if (n.status == 200) {
				Modalbox.show(n.responseText, {title: 'Cr�ation de rubrique', width: 620, height: 620, afterLoad:function() { new Control.ColorPicker("rub_color")} });
//				$(tg).innerHTML = n.responseText;
			}
		}
	});
}
/**
 * formulaire d'ajout de sous-rubrique
 */
function editRub(id, tg) {
	var url = "rub_edit.php";
	var params = "id_rub="+id;
	var ajax = new Ajax.Request(url,{
		method: "post",
		parameters: params,
		onLoading: function(){},
		onComplete : function(n){ 
			if (n.status == 200) {
				Modalbox.show(n.responseText, {title: 'Edition de rubrique', width: 620, height: 620, afterLoad:function() { new Control.ColorPicker("rub_color")} });
			}
		}
	});
}
/**
 * 
 */
function closeRub() {
	$('colorpicker').hide();
	Modalbox.hide();
}
function closePage() {
	Modalbox.hide();
}
/**
 * formulaire d'ajout de page
 */
function addPage(id, tg) {
	var url = "page_form.php";
	var params = "id_rub="+id;
	var ajax = new Ajax.Request(url,{
		method: "post",
		parameters: params,
		onLoading: function(){},
		onComplete : function(n){ 
			if (n.status == 200) {
				$(tg).innerHTML = n.responseText;
			}
		}
	});
}
/**
 * formulaire d'ajout de page
 */
function editPage(id, tg) {
	var url = "page_edit.php";
	var params = "id_rub="+id;
	var ajax = new Ajax.Request(url,{
		method: "post",
		parameters: params,
		onLoading: function(){},
		onComplete : function(n){ 
			if (n.status == 200) {
				$(tg).innerHTML = n.responseText;
			}
		}
	});
}
/**
 *
 */
function addPageTrad(id_rub, id_rub_type, tg) {
	var url = "page_trad_form.php";
	var params = "id_rub="+id_rub+"&id_rub_type="+id_rub_type;
	var ajax = new Ajax.Request(url,{
		method: "post",
		parameters: params,
		onLoading: function(){},
		onComplete : function(n){ 
			if (n.status == 200) {
				$(tg).innerHTML = n.responseText;
			}
		}
	});
}
/**
 *
 */
function changePageTrad(id_rub, id_rub_type, tg) {
	var url = "page_trad_edit.php";
	var params = "id_rub="+id_rub+"&id_rub_type="+id_rub_type;
	var ajax = new Ajax.Request(url,{
		method: "post",
		parameters: params,
		onLoading: function(){},
		onComplete : function(n){ 
			if (n.status == 200) {
				$(tg).innerHTML = n.responseText;
			}
		}
	});
}
/**
 *
 */
function savePage(obj) {
	var url = "page_save.php";
	var params = Form.serialize(obj.form.id);
	var ajax = new Ajax.Request(url,{
		method: "post",
		parameters: params,
		onLoading: function(){},
		onComplete : function(n){ 
			if (n.status == 200) {
				if(n.responseText==1) {
					reloadTree();
				} else {
					$("error").innerHTML = n.responseText;
				}
			}
		}
	});
}
/**
 *
 */
function saveRub(obj) {
	var url = "rub_save.php";
	var params = Form.serialize(obj.form.id);
	var ajax = new Ajax.Request(url,{
		method: "post",
		parameters: params,
		onLoading: function(){},
		onComplete : function(n){ 
			if (n.status == 200) {
				if(n.responseText==1) {
					reloadTree();
				} else {
					$("error").innerHTML = n.responseText;
				}
			}
		}
	});
}
/**
 *
 */
function updatePage(obj) {
	var url = "page_update.php";
	var params = Form.serialize(obj.form.id);
	var ajax = new Ajax.Request(url,{
		method: "post",
		parameters: params,
		onLoading: function(){},
		onComplete : function(n){ 
			if (n.status == 200) {
				if(n.responseText==1) {
					reloadTree();
				} else {
					$("error").innerHTML = n.responseText;
				}
			}
		}
	});
}
/**
 * BLOG
 */
/**
 *
 */
function addBlogTrad(id_rub, id_rub_type, tg) {
	var url = "blog_trad_form.php";
	var params = "id_rub="+id_rub+"&id_rub_type="+id_rub_type;
	var ajax = new Ajax.Request(url,{
		method: "post",
		parameters: params,
		onLoading: function(){},
		onComplete : function(n){ 
			if (n.status == 200) {
				$(tg).innerHTML = n.responseText;
			}
		}
	});
}
/**
 *
 */
function changeBlogTrad(id_rub, id_rub_type, tg) {
	var url = "blog_trad_edit.php";
	var params = "id_rub="+id_rub+"&id_rub_type="+id_rub_type;
	var ajax = new Ajax.Request(url,{
		method: "post",
		parameters: params,
		onLoading: function(){},
		onComplete : function(n){ 
			if (n.status == 200) {
				$(tg).innerHTML = n.responseText;
			}
		}
	});
}
/**
 *
 */
function saveBlog(obj) {
	var url = "blog_save.php";
	var params = Form.serialize(obj.form.id);
	var ajax = new Ajax.Request(url,{
		method: "post",
		parameters: params,
		onLoading: function(){},
		onComplete : function(n){ 
			if (n.status == 200) {
				if(n.responseText==1) {
					reloadTree();
				} else {
					$("error").innerHTML = n.responseText;
				}
			}
		}
	});
}
/**
 *
 */
function updateBlog(obj) {
	var url = "blog_update.php";
	var params = Form.serialize(obj.form.id);
	var ajax = new Ajax.Request(url,{
		method: "post",
		parameters: params,
		onLoading: function(){},
		onComplete : function(n){ 
			if (n.status == 200) {
				if(n.responseText==1) {
					reloadTree();
				} else {
					$("error").innerHTML = n.responseText;
				}
			}
		}
	});
}


/**
 *
 */
function updateActu(obj) {
	var url = "actu_update.php";
	var params = Form.serialize(obj.form.id);
	var ajax = new Ajax.Request(url,{
		method: "post",
		parameters: params,
		onLoading: function(){},
		onComplete : function(n){ 
			if (n.status == 200) {
				if(n.responseText==1) {
					reloadTree();
				} else {
					$("error").innerHTML = n.responseText;
				}
			}
		}
	});
}

////////////////////////////////////////////
/**
 * 
 */
function reloadTree() {
	var url = "tree.php";
	var ajax = new Ajax.Request(url,{
		method: "post",
		onLoading: function(){},
		onComplete : function(n){ 
			if (n.status == 200) {
				$('tree').innerHTML = n.responseText;
				Sortable.create('arbo', { tree:true, 
						scroll:window,
						ghosting:true,
						handles:$$('#arbo .drag'), 
						hoverclass: "overc",
						onChange: function (p) {
						},
						onUpdate: function(c) {
							var url = "rub_move.php";
							var params = Sortable.serialize(c.id);
							var ajax = new Ajax.Request(url,{
								method: "post",
								parameters: params,
								onLoading: function(){},
								onComplete : function(n){ 
									if (n.status == 200) {
									}
				       			}
							});
						}
				});
				initArbo("arbo", self.location.hash);
				Modalbox.hide();
			}
		}
	});
}
/**
 *
 */
function updateRub(obj) {
	var url = "rub_update.php";
	var params = Form.serialize(obj.form.id);
	var ajax = new Ajax.Request(url,{
		method: "post",
		parameters: params,
		onLoading: function(){},
		onComplete : function(n){ 
			if (n.status == 200) {
				if(n.responseText==1) {
					reloadTree();
				} else {
					$("error").innerHTML = n.responseText;
				}
			}
		}
	});
}