var inputText = "";

function calendrier(idChamp)
{
	var rpath = document.getElementById("rpath").value;
	inputText = idChamp;
	window.open(rpath + 'lib/widget/calendrier.php','calendrier','width=280,height=202');
}
function majDate(d)
{
	var s = new String(d);
	var dateFormated = s.substring(6,8) + "/" + s.substring(4,6) + "/" + s.substring(0,4);
	document.getElementById(inputText).value = dateFormated;
}

function cleUrl(champFrom, champDest)
{
   var start = document.getElementById(champFrom).value;
   var dest = document.getElementById(champDest).value;
   
   if (dest == '')
   {
       dest = start;
       dest = dest.replace(/[ÀÁÂÃÄÅÆ]/g, 'A');
       dest = dest.replace(/[Ç]/g, 'C');
       dest = dest.replace(/[ÈÉÊË]/g, 'E');
       dest = dest.replace(/[ÌÍÎÏ]/g, 'I');
       dest = dest.replace(/[Ð]/g, 'D');
       dest = dest.replace(/[Ñ]/g, 'N');
       dest = dest.replace(/[ÒÓÔÕÖØ]/g, 'O');
       dest = dest.replace(/[ÙÚÛÜ]/g, 'U');
       dest = dest.replace(/[Ý]/g, 'Y');
       dest = dest.replace(/[Þß]/g, 'B');
       dest = dest.replace(/[àáâãäåæ]/g, 'a');
       dest = dest.replace(/[ç]/g, 'c');
       dest = dest.replace(/[èéêë]/g, 'e');
       dest = dest.replace(/[ìíîï]/g, 'i');
       dest = dest.replace(/[ð]/g, 'd');
       dest = dest.replace(/[ñ]/g, 'n');
       dest = dest.replace(/[òóôõöø]/g, 'o');
       dest = dest.replace(/[ùúûü]/g, 'u');
       dest = dest.replace(/[ýÿ]/g, 'y');
       dest = dest.replace(/[þ]/g, 'b');
       dest = dest.replace(/[^a-zA-Z0-9_]/g, '_');
            
    document.getElementById(champDest).value = dest;
   }

}

function preview()
{
/*fabrication de l'url*/
	var url = new String(document.location);
	var initialAction = document.frm.action;
	if ((debut = url.indexOf('insertForm',0)) == -1)
	{
		if ((debut = url.indexOf('updateForm', 0)) == -1)
		{
			alert("pb lors de la generation de l'url");
		}
	}
	url = url.substring(0,debut);
	url =  url + "preview.html";
	window.open('', 'previewWindow', 'width=800, height=600, scrollbars=yes, menubar=no');
	
	document.frm.action = url;
	document.frm.target="previewWindow";
	document.frm.submit();
	document.frm.action = initialAction;
	document.frm.target="_self";
}

function widgetMedia( champIdx, champLib )
{
	widUrl = document.getElementById("widgetUrl");
	url = new String(widUrl.value);
	reg = new RegExp("(\.html)", "g");
	newUrl = url.replace(reg, "/oField/" + champIdx + "/txtField/" + champLib + ".html");
	window.open(newUrl, 'widgetMediatheque', 'width=800, height=600, scrollbars=yes, status=no, menubar=no');
}

function widgetUrl(champIdx)
{
	var	url = document.getElementById(champIdx).value;
	window.open(url, 'widgetUrl', 'width=640, height=480, scrollbars=yes, status=no, menubar=no');
}

function locate(idChamp)
{
	var largeur = 555;
	var hauteur = 445;
	var url = document.getElementById(idChamp).value;
	var top=(screen.height-hauteur)/2;
    var left=(screen.width-largeur)/2;
	
	//alert(url);
	window.open(url, "locateUrl", "toolbar=no, location=no, directories=no, status=no, scrollbars=yes, resizable=yes, copyhistory=no,top="+top+",left="+left+",width="+largeur+",height="+hauteur);
}

function cleanWidgetField(champIdx, champLib)
{
	var theIdx = document.getElementById(champIdx);
	var theLib = document.getElementById(champLib);
	
	theIdx.value = "";
	theLib.value = "";
}
