//-----------------------------------------------------------------------------
// variables
//-----------------------------------------------------------------------------

var isMinNS4 = (navigator.appName.indexOf("Netscape") >= 0 &&
                parseFloat(navigator.appVersion) >= 4) ? 1 : 0;
var isMinIE4 = (document.all) ? 1 : 0;
var isMinIE5 = (isMinIE4 && navigator.appVersion.indexOf("5.") >= 0) ? 1 : 0;
var isMinMoz = (document.getElementById && isMinNS4) ? true : false;

// открытие окна для live operator
// -------------------------------
function openLive(){
userWindow = window.open('directConnect/index.html', 'userWindow', 'width=503, height=400, left=20, top=20, toolbar=no,bar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no');
userWindow.focus();
}

// открытие окна
// -------------
function openNewWindow(fileName,my_width,my_height)
{
myNewWindow=window.open(fileName,'','toolbar=no,bar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes,width='+my_width+',height='+my_height+',top=0,left=0');
} 

// открытие окна для флэша
// -----------------------
function openNewWindow2(fileName,my_width_height)
{
myNewWindow=window.open(fileName,'','toolbar=no,bar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,' + my_width_height + ',top=0,left=0');
} 

// открытие окна для анкеты
// ------------------------
function openNewWindow3(fileName,my_width,my_height)
{
myNewWindow=window.open(fileName + '?from=7211000.ru','','toolbar=no,bar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width='+my_width+',height='+my_height+',top=0,left=0');
} 

// are you sure
// ------------
function areYouSure(stringName){
    return confirm(stringName);
}

// Over for flash
//-----------------------------

function flashSendVar(movieName, variable, varValue)
{
	tmpObj = eval('document.all["' + movieName + '"]');
	tmpObj.SetVariable(variable, varValue);
	return 1;
}

//-----------------------------------------------------------------------------
// Layer utilities.
//-----------------------------------------------------------------------------

function hideLayer(layer) {

	if (isMinIE4 || isMinMoz)
		layer.style.visibility = "hidden";
  	else
	if (isMinNS4 && !isMinMoz)
    	layer.visibility = "hide";
}

//-----------------------------------------------------------------------------
// showLayer
//-----------------------------------------------------------------------------
function showLayer(layer) {

	if (isMinIE4 || isMinMoz)
    	layer.style.visibility = "visible";
	else
	if (isMinNS4 && !isMinMoz)
		layer.visibility = "show";
}

//-----------------------------------------------------------------------------
// getLayer
//-----------------------------------------------------------------------------
function getLayer(name) 
{
	if (isMinMoz)
  			return eval('document.getElementById("' + name + '")');

  	if (isMinNS4)
		return findLayer(name, document);

	if (isMinIE4)
	    	return eval('document.all.' + name);


  	return null;
}

// ----------------------------------------------------------------------------
//  findLayer
// ----------------------------------------------------------------------------
function findLayer(name, doc) {

  var i, layer;

  for (i = 0; i < doc.layers.length; i++) {
    layer = doc.layers[i];
    if (layer.name == name)
      return layer;
    if (layer.document.layers.length > 0)
      if ((layer = findLayer(name, layer.document)) != null)
        return layer;
  }
  return null;
}

// ----------------------------------------------------------------------------
//  findLayer
// ----------------------------------------------------------------------------
function moveLayerTo(layer, x, y) {

	if (isMinMoz || isMinIE4)
	{
    	layer.style.left = x;
	    layer.style.top  = y;
  	}

	if (isMinNS4)
    	layer.moveTo(x, y);
}

// ----------------------------------------------------------------------------
//  centerPosition
// ----------------------------------------------------------------------------
function centerPosition(layer, width, height)
{
	realObj = getLayer(layer);
	objNewLeft = Math.ceil((getWindowWidth() - width) / 2);	
	objNewTop = Math.ceil((getWindowHeight() - height) / 2);	

	moveLayerTo(realObj, objNewLeft, objNewTop);
	
	return false;
}

//-----------------------------------------------------------------------------
// Layer utilities.
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Window and page properties.
//-----------------------------------------------------------------------------

function getWindowWidth() {

  if (isMinNS4)
    return window.innerWidth;
  if (isMinIE4)
    return document.body.clientWidth;
  return -1;
}

function getWindowHeight() {

  if (isMinNS4)
    return window.innerHeight;
  if (isMinIE4)
    return document.body.clientHeight;
  return -1;
}

/**
 * The global array below will be used inside the "setPointer()" function
 */
var markedRow = new Array();


/**
 * Sets/unsets the pointer in browse mode
 *
 * @param   object   the table row
 * @param   object   the color to use for this row
 * @param   object   the background color
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, thePointerColor, theNormalBgColor)
{
    var theCells = null;

    if (thePointerColor == '' || typeof(theRow.style) == 'undefined') {
        return false;
    }
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    var rowCellsCnt  = theCells.length;
    var currentColor = null;
    var newColor     = null;
    // Opera does not return valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined' && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        newColor     = (currentColor.toLowerCase() == thePointerColor.toLowerCase())
                     ? theNormalBgColor
                     : thePointerColor;
        for (var c = 0; c < rowCellsCnt; c++) {
            theCells[c].setAttribute('bgcolor', newColor, 0);
        } // end for
    }
    else {
        currentColor = theCells[0].style.backgroundColor;
        newColor     = (currentColor.toLowerCase() == thePointerColor.toLowerCase())
                     ? theNormalBgColor
                     : thePointerColor;
        for (var c = 0; c < rowCellsCnt; c++) {
            theCells[c].style.backgroundColor = newColor;
        }
    }

    return true;
} // end of the 'setPointer()' function

//-----------------------------------------------------------------------------
// Window and page properties.
//-----------------------------------------------------------------------------
