/**
 * cs_base.js	version 1.1
 * ==========
 * Description:	Base cross browser functions and global variables 
 *          	(Netscape 4.x, IE4.x-6.x+, Netscape 6.x+)
 * 
 * Created:		07/06/2001
 * Last modified:	02/05/2002
 * 
 * Change Log:	
 *	01/22/2002	- have added a check of forms, embeds, and anchors
 *                  	into the refNSElem(name, obj) function
 *    02/05/2002	- have changed the implementation of the 'refElStyle' function
 *    02/05/2002	- have added the _cs_base_defined_ variable
 * 
 *
 * Copyright (C) 2001-2002, 
 *           Alexander Khroustalev
 *        =-=-= email: KhroustalevA@netscape.net =-=-=
*/

var _cs_base_defined_ = true;


////////////////////////////////////
//
//  Global variables
//

var px = "";

var cmdShow, cmdHide; 

var isDOM   = false;
var isNS4   = false;
var isIE4   = false;
var isMac   = false;
var isDHTML = false;


////////////////////////////////////
//
//  Dimension class
//

function Dim(nLeft, nTop, nWidth, nHeight, nIndex) {
   this.left   = nLeft;
   this.top    = nTop;
   this.width  = nWidth;
   this.height = nHeight;
   this.zIndex = nIndex ? nIndex : 0;
}

////////////////////////////////////
//
//  Element's style class
//

function ElStyle(name, value) { 
   this.name  = name;
   this.value = value;
}

////////////////////////////////////
//
//  Element's event class
//

function ElEvent(name, action) { 
   this.name   = name.toLowerCase();
   this.action = action;
}



////////////////////////////////////
//
//  Setup variables
//

if (navigator.appName == "Microsoft Internet Explorer") {
   if (parseInt(navigator.appVersion) >= 4) { 
	isIE4 = true; 
	px    = "px";
	cmdShow  = "visible";
	cmdHide  = "hidden";
   }
}
else if (navigator.appName == "Netscape") {
   if (parseInt(navigator.appVersion) >= 4) { 
	isNS4 = true; 
	px    = "";
	cmdShow  = "show";
	cmdHide  = "hide";
   }
   // document.captureEvents(Event.MOUSEDOWN);
   // document.onmousedown = new Function ("e", "if(e.which == 2 || e.which == 3) return false")
}
if (typeof(document.getElementById) != "undefined" && typeof(document.createElement) != "undefined") {
   isNS4 = isIE4 = false;
   isDOM = true;
   px    = "px";
   cmdShow  = "visible";
   cmdHide  = "hidden";
   if (navigator.appName == "Netscape") { 
	// window.onmousedown = new Function ("e", "if(e.which == 2 || e.which == 3) { alert("Right click!");return false; }")
   }
   else {
   	// document.oncontextmenu = new Function ("return false")
   }
}
isMac = (navigator.appVersion.indexOf("Mac") != -1);
isDHTML = (isDOM || (isIE4 && !isMac) || isNS4);


////////////////////////////////////
//
//  General functions
//

// refEl(name)
//
//
function refEl(name) {
   var el = null;

   if (isDHTML) {
	if (isDOM)
	   el = document.getElementById(name);
	else if (isNS4)
	   el = getNSElem(name);
	else if (isIE4)
	   el = document.all[name];
   }
   if (typeof(el) == 'undefined') el = null;
   return el;
}

// refElStyle(name)
//
// 
function refElStyle(name) {
   var es = null, el = refEl(name);
   if (el) es = isNS4 ? el : el.style;
   return es;
}


// showEl(elem)
//
//
function showEl(elem) {
   var els = refElStyle(elem);
   if (els) els.visibility = cmdShow;
}


// hideEl(elem)
//
//
function hideEl(elem) {
   var els = refElStyle(elem);
   if (els) els.visibility = cmdHide;
}


// changeColor(elem, color)
//
//
function changeColor(elem, color) {
   var els = refElStyle(elem);
   if (els) 
	if (isNS4)  // for layers only
	   els.document.color = color;
	else
	   els.color = color;
}


// changeBGColor(elem, bgcolor)
//       
//
function changeBGColor(elem, bgcolor) {
   var els = refElStyle(elem);
   if (els) 
	if (isNS4)    // for layers only
	   els.document.bgColor = bgcolor;
	else
	   els.backgroundColor  = bgcolor;
}


// changeImage(elem, ref)
//
//
function changeImage(elem, ref) {
   var el = refEl(elem);
   if (el) el.src = ref;
}


// changeStyle(elem, prop, val)
//       
//
function changeStyle(elem, prop, val) {
   var els = refElStyle(elem);
   if (els && !isNS4)              // for IE4+, IE5+, IE6+ and Netscape 6+ only.
       els[prop] = val; 
}



////////////////////////////////////////
//
//  Netscape Communicator's routine
//

// refNSElem(name, obj)
//
//
function refNSElem(name, obj) {
   var el = obj.document.layers[name];
   if (typeof(el) == 'undefined') el = obj.document.forms[name];
   if (typeof(el) == 'undefined') el = obj.document.images[name];
   if (typeof(el) == 'undefined') el = obj.document.links[name];
   if (typeof(el) == 'undefined') el = obj.document.embeds[name];
   if (typeof(el) == 'undefined') el = obj.document.anchors[name];
   if (typeof(el) == 'undefined') el = null;
   return el;
}

// seekNSElem(name, obj)
//
//
function seekNSElem(name, obj) {
   var el = null;
   if (typeof(obj) != 'undefined') {
	for(var i = 0; i < obj.length; i++) {
	   if(obj[i].name.toUpperCase() == name.toUpperCase()) {
		el = obj[i];
		break;
	   }
	   else {
		el = refNSElem(name, obj[i]);
		if (el != null) break;
	   }
	}
   }
   return el;
}

// getNSElem(name)
//
//
function getNSElem(name) {
   var elm = refNSElem(name, window);
   if (elm == null)
	 elm = seekNSElem(name, window.document.layers);
   return elm;
}
