forked from Wavyzz/dolibarr
L'auteur autorisait bien l'utilisation de ce code SANS meme sa permission ("without any further permission from the author").
Seule sa diffusion en tant que fichier js seul sur un site de téléchargement de script (("the plain javascript on your site for download").
Il autorisait de plus la suppression de l'info ("You may remove this notice from your final code if you wish").
Dans le doute, le code est supprimé en attendant le remplacement des fonctions formatDate et getDateFromFormat.
416 lines
12 KiB
JavaScript
416 lines
12 KiB
JavaScript
// Copyright (C) 2005-2006 Laurent Destailleur <eldy@users.sourceforge.net>
|
|
//
|
|
// Script javascript mis en en-tete de pages (dans section head)
|
|
//
|
|
// \file htdocs/lib/lib_head.js
|
|
// \brief Fichier qui inclue les fonctions javascript d'en-tete (inclue si option use_javascript active)
|
|
// \version $Revision$
|
|
|
|
|
|
|
|
/*=================================================================
|
|
Purpose: Pour la fonction de saisie auto des villes
|
|
Input: postalcode,objectville
|
|
Author: Eric Seigne
|
|
Licence: GPL
|
|
==================================================================*/
|
|
|
|
function autofilltownfromzip_PopupPostalCode(postalcode,objectville)
|
|
{
|
|
var url = 'searchpostalcode.php?cp=' + postalcode + '&targetobject=window.opener.document.formsoc.' + objectville.name;
|
|
// alert(url);
|
|
var hWnd = window.open(url, "SearchPostalCodeWindow", "width=" + 300 + ",height=" + 150 + ",resizable=yes,scrollbars=yes");
|
|
if((document.window != null) && (!hWnd.opener)) hWnd.opener = document.window;
|
|
}
|
|
|
|
function autofilltownfromzip_save_refresh_edit()
|
|
{
|
|
document.formsoc.action.value="edit";
|
|
document.formsoc.submit();
|
|
}
|
|
|
|
function autofilltownfromzip_save_refresh_create()
|
|
{
|
|
document.formsoc.action.value="create";
|
|
document.formsoc.submit();
|
|
}
|
|
|
|
|
|
|
|
/*=================================================================
|
|
Purpose: Pour la saisie des dates par calendrier
|
|
Input: base "/theme/eldy"
|
|
dateFieldID "dateo" Nom du champ
|
|
format "dd/MM/yyyy" Format issu de Dolibarr de SimpleDateFormat à utiliser pour retour
|
|
==================================================================*/
|
|
|
|
function showDP(base,dateFieldID,format)
|
|
{
|
|
showDP.datefieldID=dateFieldID;
|
|
|
|
var dateField=getObjectFromID(dateFieldID);
|
|
|
|
//check to see if another box is already showing
|
|
var alreadybox=getObjectFromID("DPCancel");
|
|
if(alreadybox) closeDPBox();
|
|
|
|
//get positioning
|
|
var thetop=getTop(dateField)+dateField.offsetHeight;
|
|
|
|
// var xxx=getObjectFromID('bottompage');
|
|
//alert(xxx.style.pixelTop);
|
|
//alert(document.body.clientHeight);
|
|
//alert(document.body.style.offsetTop);
|
|
//alert(thetop);
|
|
//alert(window.innerHeight);
|
|
if (thetop+160 > window.innerHeight)
|
|
thetop=thetop-160-20;
|
|
var theleft=getLeft(dateField);
|
|
if (theleft+140 > window.innerWidth)
|
|
theleft= theleft-140+dateField.offsetWidth-15;
|
|
|
|
showDP.box=document.createElement("div");
|
|
showDP.box.className="bodyline";
|
|
showDP.box.style.siplay="block";
|
|
showDP.box.style.position="absolute";
|
|
showDP.box.style.top=thetop + "px";
|
|
showDP.box.style.left=theleft + "px";
|
|
|
|
if(dateField.value) // Si il y avait valeur initiale dans champ
|
|
{
|
|
selDate=getDateFromFormat(dateField.value,format);
|
|
if (selDate)
|
|
{
|
|
year=selDate.getFullYear();
|
|
month=selDate.getMonth()+1;
|
|
day=selDate.getDate();
|
|
datetime=selDate.getTime();
|
|
ymd=formatDate(selDate,'yyyyMMdd');
|
|
}
|
|
}
|
|
else
|
|
{
|
|
selDate=new Date();
|
|
year=selDate.getFullYear();
|
|
month=selDate.getUTCMonth()+1;
|
|
day=selDate.getDate();
|
|
datetime=selDate.getTime();
|
|
ymd=formatDate(selDate,'yyyyMMdd');
|
|
}
|
|
loadMonth(base,month,year,ymd);
|
|
hideSelectBoxes();
|
|
document.body.appendChild(showDP.box);
|
|
}
|
|
|
|
function loadMonth(base,month,year,ymd)
|
|
{
|
|
showDP.box.innerHTML="Loading...";
|
|
var theURL=base+"datepicker.php?cm=shw";
|
|
theURL+="&m="+encodeURIComponent(month);
|
|
theURL+="&y="+encodeURIComponent(year);
|
|
if (selDate)
|
|
{
|
|
theURL+="&sd="+ymd;
|
|
}
|
|
|
|
loadXMLDoc(theURL,null,false);
|
|
showDP.box.innerHTML=req.responseText;
|
|
}
|
|
|
|
function closeDPBox()
|
|
{
|
|
document.body.removeChild(showDP.box);
|
|
displaySelectBoxes();
|
|
showDP.box=null;
|
|
showDP.datefieldID=null;
|
|
}
|
|
|
|
function dpChangeDay(dateFieldID,format)
|
|
{
|
|
showDP.datefieldID=dateFieldID;
|
|
|
|
var thefield=getObjectFromID(showDP.datefieldID);
|
|
var thefieldday=getObjectFromID(showDP.datefieldID+"day");
|
|
var thefieldmonth=getObjectFromID(showDP.datefieldID+"month");
|
|
var thefieldyear=getObjectFromID(showDP.datefieldID+"year");
|
|
|
|
var date=getDateFromFormat(thefield.value,format);
|
|
if (date)
|
|
{
|
|
thefieldday.value=date.getDate();
|
|
if(thefieldday.onchange) thefieldday.onchange.call(thefieldday);
|
|
thefieldmonth.value=date.getMonth()+1;
|
|
if(thefieldmonth.onchange) thefieldmonth.onchange.call(thefieldmonth);
|
|
thefieldyear.value=date.getFullYear();
|
|
if(thefieldyear.onchange) thefieldyear.onchange.call(thefieldyear);
|
|
}
|
|
else
|
|
{
|
|
thefieldday.value='';
|
|
if(thefieldday.onchange) thefieldday.onchange.call(thefieldday);
|
|
thefieldmonth.value='';
|
|
if(thefieldmonth.onchange) thefieldmonth.onchange.call(thefieldmonth);
|
|
thefieldyear.value='';
|
|
if(thefieldyear.onchange) thefieldyear.onchange.call(thefieldyear);
|
|
}
|
|
}
|
|
|
|
function dpClickDay(year,month,day,format)
|
|
{
|
|
var thefield=getObjectFromID(showDP.datefieldID);
|
|
var thefieldday=getObjectFromID(showDP.datefieldID+"day");
|
|
var thefieldmonth=getObjectFromID(showDP.datefieldID+"month");
|
|
var thefieldyear=getObjectFromID(showDP.datefieldID+"year");
|
|
|
|
var dt = new Date();
|
|
dt.setMonth(month-1);
|
|
dt.setYear(year);
|
|
dt.setDate(day);
|
|
|
|
thefield.value=formatDate(dt,format);
|
|
if(thefield.onchange) thefield.onchange.call(thefield);
|
|
|
|
thefieldday.value=day;
|
|
if(thefieldday.onchange) thefieldday.onchange.call(thefieldday);
|
|
thefieldmonth.value=month;
|
|
if(thefieldmonth.onchange) thefieldmonth.onchange.call(thefieldmonth);
|
|
thefieldyear.value=year;
|
|
if(thefieldyear.onchange) thefieldyear.onchange.call(thefieldyear);
|
|
|
|
closeDPBox();
|
|
}
|
|
|
|
function dpHighlightDay(year,month,day){
|
|
var displayinfo=getObjectFromID("dpExp");
|
|
var months=Array("January","February","March","April","May","June","July","August","September","October","November","December");
|
|
displayinfo.innerHTML=months[month-1]+" "+day+", "+year;
|
|
}
|
|
|
|
//Returns an object given an id
|
|
function getObjectFromID(id){
|
|
var theObject;
|
|
if(document.getElementById)
|
|
theObject=document.getElementById(id);
|
|
else
|
|
theObject=document.all[id];
|
|
return theObject;
|
|
}
|
|
|
|
// This Function returns the top position of an object
|
|
function getTop(theitem){
|
|
var offsetTrail = theitem;
|
|
var offsetTop = 0;
|
|
while (offsetTrail) {
|
|
offsetTop += offsetTrail.offsetTop;
|
|
offsetTrail = offsetTrail.offsetParent;
|
|
}
|
|
if (navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined")
|
|
offsetLeft += document.body.TopMargin;
|
|
return offsetTop;
|
|
}
|
|
|
|
// This Function returns the left position of an object
|
|
function getLeft(theitem){
|
|
var offsetTrail = theitem;
|
|
var offsetLeft = 0;
|
|
while (offsetTrail) {
|
|
offsetLeft += offsetTrail.offsetLeft;
|
|
offsetTrail = offsetTrail.offsetParent;
|
|
}
|
|
if (navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined")
|
|
offsetLeft += document.body.leftMargin;
|
|
return offsetLeft;
|
|
}
|
|
|
|
function loadXMLDoc(url,readyStateFunction,async)
|
|
{
|
|
// branch for native XMLHttpRequest object
|
|
if (window.XMLHttpRequest) {
|
|
req = new XMLHttpRequest();
|
|
req.onreadystatechange = readyStateFunction;
|
|
req.open("GET", url, async);
|
|
req.send(null);
|
|
// branch for IE/Windows ActiveX version
|
|
} else if (window.ActiveXObject) {
|
|
req = new ActiveXObject("Microsoft.XMLHTTP");
|
|
if (req) {
|
|
if(readyStateFunction) req.onreadystatechange = readyStateFunction;
|
|
req.open("GET", url, async);
|
|
req.send();
|
|
}
|
|
}
|
|
}
|
|
|
|
function hideSelectBoxes() {
|
|
var brsVersion = parseInt(window.navigator.appVersion.charAt(0), 10);
|
|
if (brsVersion <= 6 && window.navigator.userAgent.indexOf("MSIE") > -1) {
|
|
for(var i = 0; i < document.all.length; i++) {
|
|
if(document.all[i].tagName)
|
|
if(document.all[i].tagName == "SELECT")
|
|
document.all[i].style.visibility="hidden";
|
|
}
|
|
}
|
|
}
|
|
|
|
function displaySelectBoxes() {
|
|
var brsVersion = parseInt(window.navigator.appVersion.charAt(0), 10);
|
|
if (brsVersion <= 6 && window.navigator.userAgent.indexOf("MSIE") > -1) {
|
|
for(var i = 0; i < document.all.length; i++) {
|
|
if(document.all[i].tagName)
|
|
if(document.all[i].tagName == "SELECT")
|
|
document.all[i].style.visibility="visible";
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// Afficher/cacher les champs d'un formulaire
|
|
function formDisplayHideId(baliseId,numField)
|
|
{
|
|
//if (document.getElementById && document.getElementById(baliseId) != null)
|
|
//{
|
|
//var balise = document.getElementById(baliseId);
|
|
|
|
var numDiv = 1
|
|
|
|
if (document.formsoc.typent_id.value == 8)
|
|
{
|
|
|
|
while ( document.getElementById( baliseId + numDiv) ) {
|
|
|
|
var balise = document.getElementById( baliseId + numDiv);
|
|
|
|
if (balise && balise.className == "hidden")
|
|
balise.className = "visible";
|
|
|
|
if (balise && balise.className == "visible")
|
|
balise.className = "hidden";
|
|
numDiv++
|
|
|
|
}
|
|
}
|
|
else
|
|
{
|
|
|
|
while ( document.getElementById( baliseId + numDiv) ) {
|
|
|
|
var balise = document.getElementById( baliseId + numDiv);
|
|
|
|
if (balise && balise.className == "visible")
|
|
balise.className = "hidden";
|
|
|
|
if (balise && balise.className == "hidden")
|
|
balise.className = "visible";
|
|
numDiv++
|
|
|
|
}
|
|
}
|
|
//}
|
|
}
|
|
|
|
|
|
|
|
/***********************************************
|
|
* Cool DHTML tooltip script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
|
|
* This notice MUST stay intact for legal use
|
|
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
|
|
***********************************************/
|
|
|
|
var offsetxpoint=-60 //Customize x offset of tooltip
|
|
var offsetypoint=20 //Customize y offset of tooltip
|
|
var ie=document.all
|
|
var ns6=document.getElementById && !document.all
|
|
var enabletip=false
|
|
if (ie||ns6)
|
|
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""
|
|
|
|
function ietruebody()
|
|
{
|
|
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
|
|
}
|
|
|
|
function showtip(thetext)
|
|
{
|
|
if (ns6||ie)
|
|
{
|
|
tipobj.innerHTML=thetext
|
|
enabletip=true
|
|
return false
|
|
}
|
|
}
|
|
|
|
function positiontip(e)
|
|
{
|
|
if (enabletip)
|
|
{
|
|
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
|
|
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
|
|
//Find out how close the mouse is to the corner of the window
|
|
var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
|
|
var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20
|
|
|
|
var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000
|
|
|
|
//if the horizontal distance isn't enough to accomodate the width of the context menu
|
|
if (rightedge<tipobj.offsetWidth)
|
|
//move the horizontal position of the menu to the left by it's width
|
|
tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
|
|
else if (curX<leftedge)
|
|
tipobj.style.left="5px"
|
|
else
|
|
//position the horizontal position of the menu where the mouse is positioned
|
|
tipobj.style.left=curX+offsetxpoint+"px"
|
|
|
|
//same concept with the vertical position
|
|
if (bottomedge<tipobj.offsetHeight)
|
|
tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
|
|
else
|
|
tipobj.style.top=curY+offsetypoint+"px"
|
|
tipobj.style.visibility="visible"
|
|
}
|
|
}
|
|
|
|
function hidetip()
|
|
{
|
|
if (ns6||ie)
|
|
{
|
|
enabletip=false
|
|
tipobj.style.visibility="hidden"
|
|
tipobj.style.left="-1000px"
|
|
tipobj.style.backgroundColor=''
|
|
tipobj.style.width=''
|
|
}
|
|
}
|
|
|
|
document.onmousemove=positiontip;
|
|
|
|
|
|
|
|
|
|
|
|
/*=================================================================
|
|
Purpose: Fonction pour champ saisie en mode ajax
|
|
Author: Laurent Destailleur
|
|
Licence: GPL
|
|
==================================================================*/
|
|
function publish_selvalue(obj) { $(obj.name).value = obj.options[obj.selectedIndex].value; }
|
|
|
|
|
|
|
|
/*=================================================================
|
|
Purpose: Affiche popup
|
|
Input: url,title
|
|
Author: Laurent Destailleur
|
|
Licence: GPL
|
|
==================================================================*/
|
|
function newpopup(url,title) {
|
|
var argv = newpopup.arguments;
|
|
var argc = newpopup.arguments.length;
|
|
tmp=url;
|
|
var l = (argc > 2) ? argv[2] : 600;
|
|
var h = (argc > 3) ? argv[3] : 400;
|
|
var wfeatures="directories=0,menubar=0,status=0,resizable=0,scrollbars=1,toolbar=0,width="+l+",height="+h+",left=" + eval("(screen.width - l)/2") + ",top=" + eval("(screen.height - h)/2");
|
|
fen=window.open(tmp,title,wfeatures);
|
|
return false;
|
|
}
|