var g_caldisp;
var g_activeText;
var g_activeHide;
function swicthCal(e,name)
{
	if(e)
	{
		var pos = eventPos(e);
		moveLayerTo(g_ref.caldiv,pos[0]+10,pos[1]-43)
	}
	showLayer(g_ref.caldiv,!g_caldisp);
	g_caldisp = !g_caldisp;
	if(name)
	{
		g_activeText = document.forms['profile'].elements[name];
		g_activeHide = document.forms['profile'].elements["h_"+name];
	}

	if ( name=="duedate" )
		document.forms['profile'].elements["change_"+name].value="on";
	else if	( name=="enddate" )
		document.forms['profile'].elements["change_"+name].value="on";
}

function dispDate(dat)
{
	var month = (dat.getMonth()+1)+"";
	if(month.length<2) month="0"+month
	var day = dat.getDate()+"";
	if(day.length<2) day="0"+day
	g_activeText.value = day+" "+g_strMonthXml[dat.getMonth()].substring(0,3)+" "+dat.getFullYear();
	g_activeHide.value = dat.getFullYear() + "-"+ month +"-"+ day +" 00:00:00";
	swicthCal();
}

function createDoc(div,idchannel,idtab,idtabcomp)
{
	var filepath = "../components/publication/publish_create.jsp?"
		+"fn=new&idchannel="+idchannel+"&idtab="+idtab+"&idtabcomp="+idtabcomp;

	if(window.getAssociatedContent && window.g_HttpRequest)
		g_ActiveContent = getAssociatedContent(div);

	openCenterWnd(filepath,"Publication",650,700,true,true);
}

function replyDoc(div,iddoc,idchannel,idtab,idtabcomp)
{
	var filepath = "../components/publication/publish_create.jsp?"
		+"fn=new&idchannel="+idchannel+"&idparent="+iddoc+"&idtab="+idtab+"&idtabcomp="+idtabcomp;

	if(window.getAssociatedContent && window.g_HttpRequest)
		g_ActiveContent = getAssociatedContent(div);

	openCenterWnd(filepath,"Publication",650,500,true,true);
}

function translateDoc(div,iddoc,idchannel,idtab,idtabcomp)
{
	var filepath = "../components/publication/publish_create.jsp?"
		+"fn=new&idchannel="+idchannel+"&idbranch="+iddoc+"&idtab="+idtab+"&idtabcomp="+idtabcomp;

	if(window.getAssociatedContent && window.g_HttpRequest)
		g_ActiveContent = getAssociatedContent(div);

	openCenterWnd(filepath,"Publication",650,500,true,true);
}

function correctionDoc(div,iddoc,idchannel,idtab,idtabcomp)
{
	var filepath = "../components/publication/publish_create.jsp?"
		+"fn=edit&id="+iddoc+"&idchannel="+idchannel+"&idtab="+idtab+"&idtabcomp="+idtabcomp;

	if(window.getAssociatedContent && window.g_HttpRequest)
		g_ActiveContent = getAssociatedContent(div);

	openCenterWnd(filepath,"Publication",650,700,true,true);
}

function moderatedDoc(div,iddoc,order,correction,idchannel,idtab,idtabcomp)
{
	var filepath = "../components/publication/publish_create.jsp?"
		+"fn=moderation&id="+iddoc+"&order="+order+"&correction="+correction+"&idchannel="+idchannel+"&idtab="+idtab+"&idtabcomp="+idtabcomp;

		if(window.getAssociatedContent && window.g_HttpRequest)
		g_ActiveContent = getAssociatedContent(div);

	openCenterWnd(filepath,"Publication",650,500,true,true);
}

function editDoc(iddoc,idchannel,idtab,idtabcomp)
{
	var filepath = "../components/publication/publish_edit.jsp?"
		+"fn=edit&id="+iddoc+"&idchannel="+idchannel+"&idtab="+idtab+"&idtabcomp="+idtabcomp;

	openCenterWnd(filepath,"edit",650,700,true,true);
}

function editVersionDoc(iddoc,idchannel,idtab,idtabcomp)
{
	var filepath = "publish_edit.jsp?"
		+"fn=edit&id="+iddoc+"&idchannel="+idchannel+"&idtab="+idtab+"&idtabcomp="+idtabcomp;

	openCenterWnd(filepath,"editversiondoc",650,500,true,true);
}


function crosspostingDoc(div,iddoc,idchannel,idtab,idtabcomp)
{
	var filepath = "../components/publication/publish_crossposting.jsp?"
		+"fn=crossposting&iddoc="+iddoc+"&idchannel="+idchannel+"&idtab="+idtab+"&idtabcomp="+idtabcomp;

	if(window.getAssociatedContent && window.g_HttpRequest)
		g_ActiveContent = getAssociatedContent(div);

	openCenterWnd(filepath,"crossposting",800,220,true,true);
}

function versionDoc(iddoc,order,bcorrection,allrights,idchannel,idtab,idtabcomp)
{
	var filepath = "../components/publication/publish_version.jsp?"
		+"fn=version&id="+iddoc+"&order="+order+"&bcorrection="+bcorrection+"&allrights="+allrights+"&idchannel="+idchannel+"&idtab="+idtab+"&idtabcomp="+idtabcomp;

	openCenterWnd(filepath,"versiondoc",650,500,true,true);
}


function onBtnDeletePublish(theform, msg)
{
	var btmFrm = eval("document." + theform);
	var frm = document.forms['form'+btmFrm.elements['idtabcomp'].value+'_'+btmFrm.elements['idchannel'].value];
	var str="";
	for(var i=0;i<frm.elements.length;i++)
		if(frm.elements[i].checked)
			str += frm.elements[i].value+",";

	if(str.length>0 && confirm(msg))

	{
		if(window.getAssociatedContent && window.g_HttpRequest)
			reloadNewsComp(btmFrm,btmFrm.elements['idtab'].value,btmFrm.elements['idtabcomp'].value,"delete",btmFrm.elements['idchannel'].value);
		else
		{
			btmFrm.fn.value = "delete";
			btmFrm.submit();
		}
	}
}

function onBtnBackupPublish(theform, msg)
{
	var btmFrm = eval("document." + theform);
	var frm = document.forms['form'+btmFrm.elements['idtabcomp'].value+'_'+btmFrm.elements['idchannel'].value];
	var str="";
	for(var i=0;i<frm.elements.length;i++)
		if(frm.elements[i].checked)
			str += frm.elements[i].value+",";

	if(str.length>0 && confirm(msg))
	{
		if(window.getAssociatedContent && window.g_HttpRequest)
			reloadNewsComp(btmFrm,btmFrm.elements['idtab'].value,btmFrm.elements['idtabcomp'].value,"backup",btmFrm.elements['idchannel'].value);
		else
		{
			btmFrm.fn.value = "backup";
			btmFrm.submit();
		}
	}
}

function onBtnHeadlinePublish(theform, msg)
{
	var btmFrm = eval("document." + theform);
	var frm = document.forms['form'+btmFrm.elements['idtabcomp'].value+'_'+btmFrm.elements['idchannel'].value];
	var str="";
	for(var i=0;i<frm.elements.length;i++)
		if(frm.elements[i].checked)
			str += frm.elements[i].value+",";

	if(str.length>0 && confirm(msg))
	{
		if(window.getAssociatedContent && window.g_HttpRequest)
			reloadNewsComp(btmFrm,btmFrm.elements['idtab'].value,btmFrm.elements['idtabcomp'].value,"headline",btmFrm.elements['idchannel'].value);
		else
		{
			btmFrm.fn.value = "headline";
			btmFrm.submit();
		}
	}
}

function onBtnUploadDocFile(fn,iddoc,idchannel,idtab,idtabcomp)
{
	var filepath = "adddocfile.jsp?"
			+"fn="+fn+"&id="+iddoc+"&idchannel="+idchannel+"&idtab="+idtab+"&idtabcomp="+idtabcomp;

 	openCenterWnd(filepath,"adddocfile",650,250,false,true);
}

function onBtnOpenDocFile(name, homepage)
{
/**	AVANT modif pour l'unicode
	var filepath = "donwloaddocfile.jsp?"
			+"name="+escape(name);
**/
	var values = name.split('#');
	var filepath = "donwloaddocfile.jsp?" + "name=" + values [0] + "&id=" + values [1];
		
	if (homepage == 'true')
		filepath = "../components/publication/" + filepath;

	var str ="width="+640+",height="+480;
	var sh = screen.height;
	var sw = screen.width;
	str+=",left=" + parseInt((sw - 640)/2);
	str+=",top=" + parseInt((sh - 480)/2);
	str+=",resizable=yes";
	str+=",scrollbars=yes";
	str +=",menubar=yes,toolbar=no,status=no";
	var wnd = window.open(filepath,"donwloaddocfile",str);
	wnd.opener = window;
}


function onBtnRefusedDoc(msg)
{
	if (confirm(msg))
	{
		document.forms['profile'].elements["refused"].value="on";
		document.forms['profile'].submit();
	}
}

function onBtnDeleteDocFile()
{
	var i;
	var bSubmit = false;
	for(i=0; i<document.forms['profile'].elements.length;i++)
	{
		if(document.forms['profile'].elements[i].name.substring(0, 9) == "checkbox_")
			if(document.forms['profile'].elements[i].checked)
				bSubmit = true
	}
	if(bSubmit)
	{
		document.forms['profile'].elements["deletefile"].value="on";
		document.forms['profile'].submit();
	}
}

function reloadNewsComp(div,idtab,idtabcomp,fn,idchannel)
{
	var frm = document.forms['form'+idtabcomp+'_'+idchannel];
	var iddoc_list="";
	for(var i=0;i<frm.elements.length;i++)
	{
		var elm = frm.elements[i];
		if(elm.type == 'checkbox' && elm.checked)
			iddoc_list+= "&"+elm.name+"=";
	}
	var filepath = g_PublicationCompPath+"publish_actions.jsp?"
			+"idtab="+idtab
			+"&idtabcomp="+idtabcomp
			+"&idchannel="+idchannel
			+"&fn="+fn
			+iddoc_list;

	g_ActiveContent = getAssociatedContent(div);
	g_ActiveContent.innerHTML = "<IMG SRC=\""+g_AbsPath +"shared/img/clock.gif\">";
	g_HttpRequest.queuing(g_ActiveContent,filepath);
}

function onBtnUploadImage()
{
	var URL = "../shared/editor/pastefile.jsp?targeteditor=false";

	openCenterWnd(URL,"UploadImage",50,50,false,true);
}
