var currentDiv = null;
var currentIdent = null;
var currentTimeout = 100;
var Images = new Array();
{
	Images[Images.length] = new Image();
	Images[Images.length - 1].src = "";
	Images[Images.length] = new Image();
}
var Nwindow = null;
var photoWnd = null;
var vColor = ["#ffffff", "#DEDEDD", "#FADA7D"];

var vSelected = new Array();

function OpenNW (url, name, features)
{
	Nwindow = window.open(url, name, features);
}

function getElement(id)
{
	if (document.getElementById)
		return document.getElementById(id);
	else if (document.all)
		return document.all[id];
	else return null;
}

//----------------------rollover--------------------------------------
function over(id)
{
	var img = getElement(id);
	if (!img)
		return;

	var iname = img.src;
	iname = iname.substr(iname.lastIndexOf('/') + 1, iname.lastIndexOf('.') - iname.lastIndexOf('/') - 1);
	img.src = '/images/' + iname + '_act.gif';
}

function out(id)
{
	var img = getElement(id);
	if (!img)
		return;

	var iname = img.src;
	iname = iname.substr(iname.lastIndexOf('/') + 1, iname.lastIndexOf('_') - iname.lastIndexOf('/') - 1);

	img.src = '/images/' + iname + '.gif';
}

function chbg(obj, newColor)
{
	var domDetect;//, currentColor;

    if (typeof(window.opera) == 'undefined' && typeof(obj.getAttribute) != 'undefined')
	    //currentColor = obj.getAttribute('bgcolor');
        domDetect    = true;
    else
	    //currentColor = obj.style.backgroundColor;
        domDetect    = false;

	if (!isNaN(newColor))
		newColor = vColor[newColor];
	if (domDetect)
    	obj.setAttribute('bgcolor', newColor, 0);
    else if (obj.style)
        obj.style.backgroundColor = newColor;
}

//----------------------miracle--------------------------------------
function miracle(base_id, group_id, block_id, cell_id, image_name)
{
	var block = 'cell_' + group_id + '_' + block_id;

    if (vSelected[block] == undefined)
    {
        vSelected[block] = 'cell_' + group_id + '_' + block_id + '_0';
    }

    var oldCell = getElement(vSelected[block]);
	if (!oldCell)
		return alert("Can't find old cell!!!");
    chbg(oldCell, 0);
    oldCell.onmouseover = function (){chbg(this, 1)};
    oldCell.onmouseout = function (){chbg(this, 0)};

    vSelected[block] = 'cell_' + group_id + '_' + block_id + '_' + cell_id;
    var newCell = getElement(vSelected[block]);
	if (!newCell)
		return alert("Can't find new cell!!!");
    chbg(newCell, 2);
    newCell.onmouseover = "";
    newCell.onmouseout = "";

	var img = getElement('tvimg_' + group_id + '_' + block_id);
	if (!img)
		return alert("Can't find image for block!!!");
   	img.src = '/images/base/' + image_name + '.jpg';
    img.onclick = function() {openPhoto(base_id, group_id, block_id, cell_id)};
}

function openPhoto(base_id, group_id, block_id, image)
{
  var params = "base=" + base_id + '&group_id=' + group_id + '&block_id=' + block_id + '&image=' + image;
  photoWnd = open("/base-photo/?" + params, "photo", "width=580,height=430,left=50,top=50,resizable=1,scrollbars=yes,menubar=no,status=yes");
  return false;
}

function openPlan(base_id, group_id, block_id, image)
{
  var params = "base=" + base_id + '&group_id=' + group_id + '&block_id=' + block_id + '&image=' + image;
  photoWnd = open("/base-plan/?" + params, "photo", "width=580,height=430,left=50,top=50,resizable=1,scrollbars=yes,menubar=no,status=yes");
  return false;
}

function refreshCaptcha() {
	var t = new Date();
	var timestamp = t.getTime();	
	
	var captcha = new Image();
	captcha.src = '/captcha.jpg?' + timestamp;
	
	
	captcha.onload = function () { 
		document.images['captcha'].width  = captcha.width;
		document.images['captcha'].height = captcha.height;
		document.images['captcha'].src    = captcha.src;
	}
}

