<?php
//****************************************************************************
//
// Copyright (C) 2001 Eric SEIGNE <hide@address.com>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
//****************************************************************************
//
// For more informations, get to the project's main source file.
//
// Description JavaScript functions definitions.
//
//****************************************************************************
if(!defined("__functions_js_php__")):
define("__functions_js_php__", "1");
//----------------------------------------------------------------------------
// ConvertTTCtoHT
//----------------------------------------------------------------------------
$js_ConvertTTCtoHT = "
function ConvertTTCtoHT (ctrl_TTC, ctrl_HT)
{
if(ctrl_TTC.value > 0)
ctrl_HT.value = eval(ctrl_TTC.value / (".$GLOBALS["config_vat"]." / 100 + 1));
}
";
//----------------------------------------------------------------------------
// DHTMLPopup - This code was stolen from WebCalendar and was originally
// written by Benoit Maisonny <hide@address.com>.
//
// I (Benoit Maisonny <hide@address.com>) tested this code
// with Mozilla 0.8.1 (on Linux), with IE5.5 SP1 (on WinNT4) and
// with Netscape Communicator 4.74 (on Linux).
// Netscape 6.0 and 6.01 seem to have a bug related to the
// visibility attribute. I suppose it will be corrected as soon
// as they release a new version, based on a more recent Mozilla
// source code. I'm not able to test this javascript code with
// IE4. It'd be glad to know if it works.
//
// Modified by [JC].
//
// PARAMETERS
// name - ID of element to show/hide
// bshow - Boolean value
// evt - Current event (only if bShow is set to TRUE)
//----------------------------------------------------------------------------
$js_DHTMLPopup = "
function DHTMLPopup (name, bshow, evt)
{
NS4 = (document.layers) ? 1 : 0;
IE4 = (document.all) ? 1 : 0;
W3C = (document.getElementById) ? 1 : 0; // W3C stands for the W3C standard, implemented in Mozilla (and Netscape 6) and IE5
if(bshow == false)
{
if(W3C)
document.getElementById(name).style.visibility = \"hidden\";
else if(NS4)
document.layers[name].visibility = \"hide\";
else
{
// Note - [Benoit]
// I think the following isn't useful, since any sub-element should
// rather inherit its attributes from their parent.
// So i commented it out.
//if(document.all[name].length)
//{
// for(i=0 ; i<document.all[name].length ; i++)
// document.all[name][i].style.visibility = \"hidden\";
//}
//else
document.all[name].style.visibility = \"hidden\";
}
}
else
{
var currentX, // mouse position on X axis
currentY, // mouse position on X axis
x, // layer target position on X axis
y, // layer target position on Y axis
docWidth, // width of current frame
docHeight, // height of current frame
layerWidth, // width of popup layer
layerHeight, // height of popup layer
ele; // points to the popup element
if(IE4)
evt = window.event; // is it necessary ?
// First let's initialize our variables
if(W3C)
{
ele = document.getElementById(name);
currentX = evt.clientX;
currentY = evt.clientY;
docWidth = document.width;
docHeight = document.height;
layerWidth = ele.style.width;
layerHeight = ele.style.height;
}
else if(NS4)
{
ele = document.layers[name];
currentX = evt.pageX;
currentY = evt.pageY;
docWidth = document.width;
docHeight = document.height;
layerWidth = ele.clip.width;
layerHeight = ele.clip.height;
currentX += layerWidth;
}
else // meant for IE4
{
ele = document.all[name];
currentX = evt.clientX;
currentY = evt.clientY;
docHeight = document.body.offsetHeight;
docWidth = document.body.offsetWidth;
layerWidth = ele.offsetWidth; //layerWidth = 200; // for some reason, this doesn't seem to work... so set it to 200
layerHeight = ele.offsetHeight;
}
// Then we calculate the popup element's new position
if((currentX + layerWidth) > docWidth)
x = currentX - layerWidth;
else
x = currentX;
if((currentY + layerHeight) >= docHeight)
y = currentY - layerHeight - 20;
else
y = currentY + 20;
// (for debugging purpose)
//alert(\"docWidth \" + docWidth + \", docHeight \" + docHeight + \"\\nlayerWidth \" + layerWidth + \", layerHeight \" + layerHeight + \"\\ncurrentX \" + currentX + \", currentY \" + currentY + \"\\nx \" + x + \", y \" + y);
// Finally, we set its position and visibility
if(NS4)
{
ele.xpos = parseInt(x);
ele.left = parseInt(x);
ele.ypos = parseInt(y);
ele.top = parseInt(y);
ele.visibility = \"show\";
}
else // IE4 & W3C
{
ele.style.left = parseInt(x);
ele.style.top = parseInt(y);
ele.style.visibility = \"visible\";
}
}
}
";
//----------------------------------------------------------------------------
// FocusFirstCtrl - Apply focus on the first control element of the first form
// in page.
//----------------------------------------------------------------------------
$js_FocusFirstCtrl = "
function FocusFirstCtrl ()
{
if(document.forms[0])
{
for(var i=0 ; i<document.forms[0].elements.length ; i++) {
if(document.forms[0].elements[i].type != \"hidden\") {
document.forms[0].elements[i].focus();
return;
}
}
}
}
";
//----------------------------------------------------------------------------
// OpenPopupWindow
//----------------------------------------------------------------------------
$js_OpenPopupWindow = "
function OpenPopupWindow (url, windowname, width, height)
{
var hardurl = '" . APP_URL . "' + url;
// alert(hardurl);
var hWnd = window.open(hardurl, windowname, \"width=\" + width + \",height=\" + height + \",resizable=yes,scrollbars=yes\");
if((document.window != null) && (!hWnd.opener))
hWnd.opener = document.window;
}
";
//----------------------------------------------------------------------------
// RefreshOpenerAndClose
//----------------------------------------------------------------------------
$js_RefreshOpenerAndClose = "
function RefreshOpenerAndClose ()
{
window.opener.location.reload(true);
window.close();
}
";
//----------------------------------------------------------------------------
// PopupBrowser
//----------------------------------------------------------------------------
$js_PopupBrowser = "
function PopupBrowser (destctrl, path)
{
var url = \"".RedirRobot(FALSE, "browser", NULL)."\";
if(destctrl != '')
url += \"&destctrl=\" + destctrl;
if(path != '')
url += \"&path=\" + path;
OpenPopupWindow(url, \"FileBrowser\", 700, 400);
}
";
//----------------------------------------------------------------------------
// PopupContact
//----------------------------------------------------------------------------
$js_PopupContact = "
function PopupContact (com, contact_id)
{
var url = \"".RedirRobot(FALSE, "contacts_modif", NULL)."&com=\" + com + \"&cid=\" + contact_id;
OpenPopupWindow(url, \"ContactModif\", 460, 660);
}
";
//----------------------------------------------------------------------------
// PopupContactCat
//----------------------------------------------------------------------------
$js_PopupContactCat = "
function PopupContactCat (com, contactcat_id)
{
var url = \"".RedirRobot(FALSE, "contacts_modif_cat", NULL)."&com=\" + com + \"&ccid=\" + contactcat_id;
OpenPopupWindow(url, \"ContactCatModif\", 360, 140);
}
";
//----------------------------------------------------------------------------
// PopupContactsList
//----------------------------------------------------------------------------
$js_PopupContactsList = "
function PopupContactsList (form, ctrl)
{
var url = \"".RedirRobot(FALSE, "contacts_pad", NULL)."&obj=window.opener.document.\" + form.name + \".\" + ctrl.name;
OpenPopupWindow(url, \"ContactsPad\", 420, 500);
}
";
//----------------------------------------------------------------------------
// PopupConverter
//----------------------------------------------------------------------------
$js_PopupConverter = "
function PopupConverter ()
{
var url = \"".RedirRobot(FALSE, "convert", NULL)."\"
var hWnd = window.open(url, \"Converter\", \"width=370,height=310,resizable=yes,scrollbars=yes\");
if((document.window != null) && (!hWnd.opener))
hWnd.opener = document.window;
}
";
//----------------------------------------------------------------------------
// PopupItem
//----------------------------------------------------------------------------
$js_PopupItem = "
function PopupItem (com, item_id)
{
var url = \"".RedirRobot(FALSE, "items_modif", NULL)."&com=\" + com + \"&iid=\" + item_id;
OpenPopupWindow(url, \"ItemModif\", 600, 360);
}
";
//----------------------------------------------------------------------------
// PopupItemCat
//----------------------------------------------------------------------------
$js_PopupItemCat = "
function PopupItemCat (com, itemcat_id)
{
var url = \"".RedirRobot(FALSE, "items_modif_cat", NULL)."&com=\" + com + \"&icid=\" + itemcat_id;
OpenPopupWindow(url, \"ItemCatModif\", 360, 140);
}
";
//----------------------------------------------------------------------------
// PopupItemsList
//----------------------------------------------------------------------------
$js_PopupItemsList = "
function PopupItemsList (form_dest, ctrl_ref, ctrl_desc, ctrl_outprice)
{
var url = \"".RedirRobot(FALSE, "items_pad", NULL)."&o_ref=window.opener.document.\" + form_dest.name + \".\" + ctrl_ref.name + \"&o_desc=window.opener.document.\" + form_dest.name + \".\" + ctrl_desc.name + \"&o_oprice=window.opener.document.\" + form_dest.name + \".\" + ctrl_outprice.name;
OpenPopupWindow(url, \"ItemsPad\", 590, 500);
}
";
//----------------------------------------------------------------------------
// PopupUser
//----------------------------------------------------------------------------
$js_PopupUser = "
function PopupUser (com, user_id)
{
var url = \"".RedirRobot(FALSE, "config_modif_user", NULL)."&com=\" + com + \"&uid=\" + user_id;
OpenPopupWindow(url, \"UserModif\", 450, 380);
}
";
endif;
?>