[ Index ]
 

Code source de Dolibarr 2.0.1

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/htdocs/lib/ -> lib_head.js (source)

   1  // Copyright (C) 2005 Laurent Destailleur  <eldy@users.sourceforge.net>
   2  //

   3  // Script javascript mis en en-tete de pages (dans section head)

   4  //

   5  // \file       htdocs/lib/lib_head.js
   6  // \brief      Fichier qui inclue les fonctions javascript d'en-tete si option use_javascript active
   7  // \version    $Revision: 1.1 $
   8  
   9  
  10  // Pour la fonction de saisi auto des villes

  11  // *****************************************

  12  
  13  function autofilltownfromzip_PopupPostalCode(postalcode,objectville)
  14  {
  15      var url = 'searchpostalcode.php?cp=' + postalcode + '&targetobject=window.opener.document.formsoc.' + objectville.name;
  16      //  alert(url);
  17      var hWnd = window.open(url, "SearchPostalCodeWindow", "width=" + 300 + ",height=" + 150 + ",resizable=yes,scrollbars=yes");
  18      if((document.window != null) && (!hWnd.opener)) hWnd.opener = document.window;
  19  }
  20  
  21  function autofilltownfromzip_save_refresh_edit()
  22  {
  23      document.formsoc.action.value="edit";
  24      document.formsoc.submit();
  25  }
  26  
  27  function autofilltownfromzip_save_refresh_create()
  28  {
  29      document.formsoc.action.value="create";
  30      document.formsoc.submit();
  31  }
  32  
  33  
  34  // Pour la saisie des dates par calendrier

  35  // ***************************************

  36  
  37  function showDP(base,dateFieldID,format)
  38  {
  39      var dateField= getObjectFromID(dateFieldID);
  40      
  41      //check to see if another box is already showing

  42      var alreadybox=getObjectFromID("DPCancel");
  43      if(alreadybox) closeDPBox();
  44  
  45      //get positioning

  46      var thetop=getTop(dateField)+dateField.offsetHeight;
  47      var theleft=getLeft(dateField);
  48      if (theleft+140 > window.innerWidth)
  49          theleft= theleft-140+dateField.offsetWidth-15;
  50  
  51      showDP.box=document.createElement("div");
  52      showDP.box.className="bodyline";
  53      showDP.box.style.siplay="block";
  54      showDP.box.style.position="absolute";
  55      showDP.box.style.top=thetop + "px";
  56      showDP.box.style.left=theleft + "px";
  57      
  58      showDP.datefieldID=dateFieldID;
  59      
  60      if(dateField.value)
  61      {
  62          selDate=stringToDate(dateField.value,format);
  63          year=selDate.getFullYear();
  64          month=selDate.getMonth()
  65          day=selDate.getDay();
  66      }
  67      else
  68      {
  69          tdate=new Date();
  70          year=tdate.getFullYear();
  71          month=tdate.getUTCMonth()+1;
  72          day=tdate.getDay();
  73      }
  74      loadMonth(base,month,year,year+'-'+month+'-'+day);
  75      hideSelectBoxes();
  76      document.body.appendChild(showDP.box);
  77  }
  78  
  79  // selectedDate must be in format YYYY-MM-DD

  80  function loadMonth(base,month,year,selectedDate)
  81  {
  82      showDP.box.innerHTML="Loading...";
  83      var theURL=base+"datepicker.php?cm=shw";
  84      theURL+="&m="+encodeURIComponent(month);
  85      theURL+="&y="+encodeURIComponent(year);
  86      if (selectedDate){
  87          tempdate=mysqlstringToDate(selectedDate);
  88          theURL+="&sd="+encodeURIComponent(tempdate.getFullYear()+"-"+tempdate.getMonth()+"-"+tempdate.getDate());
  89      }
  90  
  91      loadXMLDoc(theURL,null,false);
  92      showDP.box.innerHTML=req.responseText;    
  93  }
  94  
  95  
  96  function closeDPBox(){
  97      document.body.removeChild(showDP.box);
  98      displaySelectBoxes();
  99      showDP.box=null;    
 100      showDP.datefieldID=null;    
 101  }
 102  
 103  function dpClickDay(year,month,day){
 104      var thefield=getObjectFromID(showDP.datefieldID);
 105      thefield.value=day+"/"+month+"/"+year;
 106      if(thefield.onchange) thefield.onchange.call(thefield);
 107      closeDPBox();
 108  }
 109  
 110  function dpHighlightDay(year,month,day){
 111      var displayinfo=getObjectFromID("dpExp");
 112      var months=Array("January","February","March","April","May","June","July","August","September","October","November","December");
 113      displayinfo.innerHTML=months[month-1]+" "+day+", "+year;
 114  }
 115  
 116  function stringToDate(sDate,format){
 117  // \todo fonction a ecrire pour tenir compte de format

 118      var sep="/";
 119      var month=sDate.substring(0,sDate.indexOf(sep))
 120      var day=sDate.substring(sDate.indexOf(sep)+1,sDate.indexOf(sep,sDate.indexOf(sep)+1))
 121      var year=sDate.substring(sDate.lastIndexOf(sep)+1);
 122      return new Date(year,month,day);
 123  }
 124  
 125  function mysqlstringToDate(sDate){
 126      var sep="-";
 127      var year=sDate.substring(0,sDate.indexOf(sep))
 128      var month=sDate.substring(sDate.indexOf(sep)+1,sDate.indexOf(sep,sDate.indexOf(sep)+1))
 129      var day=sDate.substring(sDate.lastIndexOf(sep)+1);
 130  //    alert(year+','+month+','+day);

 131      return new Date(year,month,day);
 132  }
 133  
 134  
 135  
 136  //Returns an object given an id

 137  function getObjectFromID(id){
 138      var theObject;
 139      if(document.getElementById)
 140          theObject=document.getElementById(id);
 141      else
 142          theObject=document.all[id];
 143      return theObject;
 144  }
 145  
 146  
 147  // This Function returns the Top position of an object

 148  function getTop(theitem){
 149      var offsetTrail = theitem;
 150      var offsetTop = 0;
 151      while (offsetTrail) {
 152          offsetTop += offsetTrail.offsetTop;
 153          offsetTrail = offsetTrail.offsetParent;
 154      }
 155      if (navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined") 
 156          offsetLeft += document.body.TopMargin;
 157      return offsetTop;
 158  }
 159  
 160  // This Function returns the Left position of an object

 161  function getLeft(theitem){
 162      var offsetTrail = theitem;
 163      var offsetLeft = 0;
 164      while (offsetTrail) {
 165          offsetLeft += offsetTrail.offsetLeft;
 166          offsetTrail = offsetTrail.offsetParent;
 167      }
 168      if (navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined") 
 169          offsetLeft += document.body.leftMargin;
 170      return offsetLeft;
 171  }
 172  
 173  function loadXMLDoc(url,readyStateFunction,async) 
 174  {
 175      // branch for native XMLHttpRequest object

 176      if (window.XMLHttpRequest) {
 177          req = new XMLHttpRequest();
 178          req.onreadystatechange = readyStateFunction;
 179          req.open("GET", url, async);
 180          req.send(null);
 181      // branch for IE/Windows ActiveX version

 182      } else if (window.ActiveXObject) {
 183          req = new ActiveXObject("Microsoft.XMLHTTP");
 184          if (req) {
 185              if(readyStateFunction) req.onreadystatechange = readyStateFunction;
 186              req.open("GET", url, async);
 187              req.send();
 188          }
 189      }
 190  }
 191  
 192  function addEvent(obj, evType, fn){
 193   if (obj.addEventListener){
 194      obj.addEventListener(evType, fn, true);
 195      return true;
 196   } else if (obj.attachEvent){
 197      var r = obj.attachEvent("on"+evType, fn);
 198      return r;
 199   } else {
 200      return false;
 201   }
 202  }
 203  
 204  function removeEvent(obj, evType, fn, useCapture){
 205    if (obj.removeEventListener){
 206      obj.removeEventListener(evType, fn, useCapture);
 207      return true;
 208    } else if (obj.detachEvent){
 209      var r = obj.detachEvent("on"+evType, fn);
 210      return r;
 211    } else {
 212      window.status=("Handler could not be removed");
 213    }
 214  }
 215  
 216  function hideSelectBoxes() {
 217      var brsVersion = parseInt(window.navigator.appVersion.charAt(0), 10);
 218      if (brsVersion <= 6 && window.navigator.userAgent.indexOf("MSIE") > -1) {        
 219          for(var i = 0; i < document.all.length; i++) {
 220              if(document.all[i].tagName)
 221                  if(document.all[i].tagName == "SELECT") 
 222                      document.all[i].style.visibility="hidden";
 223          }
 224      }
 225  }
 226  
 227  function displaySelectBoxes() {
 228      var brsVersion = parseInt(window.navigator.appVersion.charAt(0), 10);
 229      if (brsVersion <= 6 && window.navigator.userAgent.indexOf("MSIE") > -1) {        
 230          for(var i = 0; i < document.all.length; i++) {
 231                  if(document.all[i].tagName)
 232                          if(document.all[i].tagName == "SELECT")
 233                                  document.all[i].style.visibility="visible";
 234          }
 235      }
 236  }
 237  
 238  
 239  
 240  /***********************************************

 241  * Cool DHTML tooltip script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)

 242  * This notice MUST stay intact for legal use

 243  * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code

 244  ***********************************************/
 245  
 246  var offsetxpoint=-60 //Customize x offset of tooltip
 247  var offsetypoint=20 //Customize y offset of tooltip
 248  var ie=document.all
 249  var ns6=document.getElementById && !document.all
 250  var enabletip=false
 251  if (ie||ns6)
 252  var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""
 253  
 254  function ietruebody(){
 255  return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
 256  }
 257  
 258  function showtip(thetext){
 259  if (ns6||ie){
 260  tipobj.innerHTML=thetext
 261  enabletip=true
 262  return false
 263  }
 264  }
 265  
 266  function positiontip(e){
 267  if (enabletip){
 268  var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
 269  var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
 270  //Find out how close the mouse is to the corner of the window

 271  var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
 272  var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20
 273  
 274  var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000
 275  
 276  //if the horizontal distance isn't enough to accomodate the width of the context menu

 277  if (rightedge<tipobj.offsetWidth)
 278  //move the horizontal position of the menu to the left by it's width

 279  tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
 280  else if (curX<leftedge)
 281  tipobj.style.left="5px"
 282  else
 283  //position the horizontal position of the menu where the mouse is positioned

 284  tipobj.style.left=curX+offsetxpoint+"px"
 285  
 286  //same concept with the vertical position

 287  if (bottomedge<tipobj.offsetHeight)
 288  tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
 289  else
 290  tipobj.style.top=curY+offsetypoint+"px"
 291  tipobj.style.visibility="visible"
 292  }
 293  }
 294  
 295  function hidetip(){
 296  if (ns6||ie){
 297  enabletip=false
 298  tipobj.style.visibility="hidden"
 299  tipobj.style.left="-1000px"
 300  tipobj.style.backgroundColor=''
 301  tipobj.style.width=''
 302  }
 303  }
 304  
 305  document.onmousemove=positiontip;
 306  


Généré le : Mon Nov 26 12:29:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics