//..............................................................................................................................
// Made by Laurent Taupin (laurent@wptechnology.com) for GrafImages (contact@grafimages.com)
//    All rights reserved for every countries. You don't have any rights on this program. Please contact the author for
//    any other information.
//..............................................................................................................................

//::::: detect navigators :::::
var netscape = (document.layers)? true:false;
var iexplore = (document.all)? true:false;
var dom = (document.getElementById)? true:false;

//::::: allow getElementById function to exists even on FF !!! :::::
if (!document.getElementById){
  if(document.all){ 
    document.getElementById=function() {
      if (typeof document.all[arguments[0]]!="undefined") { return document.all[arguments[0]] } else { return null }
    }
  } else if(document.layers) {
	document.getElementById=function() {
      if (typeof document[arguments[0]]!="undefined") { return document[arguments[0]] } else { return null }
    }
  }
}

//..............................................................................................................................

function getElement(aID){ 
  return (document.getElementById) ? document.getElementById(aID) : document.all[aID];
} 

//..............................................................................................................................
// used to determine the left/top position of an object

function findPos(obj) {
  var curLeft = curTop = 0;
  if (obj.offsetParent) {
    curLeft = obj.offsetLeft;
    curTop = obj.offsetTop;
    while (obj = obj.offsetParent) {
      curLeft += obj.offsetLeft;
      curTop += obj.offsetTop;
    }
  }
  return [curLeft,curTop];
}

//..............................................................................................................................
// set the position of the div relative to the object 

function setLayer(objName,divName)
{
  var coords = findPos(objName);
  var theDIV = document.getElementById(divName);
  var theObject = document.getElementById(objName);
//  var myTop = coords[1] + theObject.width;
//  var myLeft = coords[0] + theObject.height;
  theDIV.style.top = coords[1] + 'px';
  theDIV.style.left = coords[0] + 'px';
}

function setLayerAt(objName,divName,addX,addY)
{
  var coords = findPos(objName);
  var theDIV = document.getElementById(divName);
  var theObject = document.getElementById(objName);
//  var myTop = coords[1] + theObject.width;
//  var myLeft = coords[0] + theObject.height;
  theDIV.style.top = coords[1]+addY + 'px';
  theDIV.style.left = coords[0]+addX + 'px';
}

function setLayerAfter(objName,divName)
{
  var coords = findPos(objName);
  var theDIV = document.getElementById(divName);
  var theObject = document.getElementById(objName);
  var myTop = coords[1] + theObject.width;
  var myLeft = coords[0] + theObject.height;
  theDIV.style.top = myTop + 'px';
  theDIV.style.left = myLeft + 'px';
}

//..............................................................................................................................
// show a div 

function show(objName,divName)
{
  var aDiv = document.getElementById(divName);
  aDiv.style.display = '';
  setLayer(objName,divName);
}

//..............................................................................................................................

function showAt(objName,divName,addX,addY)
{
  var aDiv = document.getElementById(divName);
  aDiv.style.display = '';
  setLayerAt(objName,divName,addX,addY);
}

//..............................................................................................................................

function showAfter(objName,divName)
{
  var aDiv = document.getElementById(divName);
  aDiv.style.display = '';
  setLayerAfter(objName,divName);
}

//..............................................................................................................................
// hide a div 

function hide(divName)
{
  var aDiv = document.getElementById(divName);
  aDiv.style.display = 'none';
}

//..............................................................................................................................
// change the content of a div

function changeContent(divName,newContent)
{
  var theDIV = document.getElementById(divName);
  theDIV.innerHTML = newContent;
}

//..............................................................................................................................
//:: used to clear a text field. needed params are the fields itself and the normal text inside it ::
function clearBox(field,originalText)
{
  var zoneText = field; // document.getElementById(field);
  if (zoneText.value==originalText) { zoneText.value=""; }
}

//..............................................................................................................................
//:: this will return the keycode of the keypressed on IE AND Firefox ::

function myKeyCode(myEvent)
{
  for (prop in myEvent)
    { if (prop == 'which') return(myEvent.which); }  // netscape/firefox
  return(myEvent.keyCode);                           // internet explorer
}

//..............................................................................................................................
//:: this will accept only A-Z a-z & 0-9 ::
function charsNumbersOnly(myEvent)
{
        var validChars = /\w/;
        var specialChars = /[\x00\x08\x0D]/;
        var decimal  = myKeyCode(myEvent);
        var car = String.fromCharCode(decimal);
        var authorized = validChars.test(car) || specialChars.test(car);
        return authorized;
}

//..............................................................................................................................

function confirmAndGo(question,urlToGo)
{
  if (confirm(question)) location.href=urlToGo;
}

//..............................................................................................................................