function MM_swapImgRestore(){
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages(){
  var d=document; if(d.images){if(!d.MM_p) d.MM_p=new Array();
  var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
  if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d){
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length){
  d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage(){
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
  if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function PicturePopup( url, width, height )
{
	window.open( url, "PicturePopup", "resizable=1,height=" + ( ( height <= 750) ? height : "750" ) + ",width=" + ( ( width <= 1000 ) ? width : "1000" ) + ",location=no,directories=no,menubar=no,toolbar=no,left=250,top=250,scrollbars=" + ( ( height <= 750 && width <= 1000 ) ? "no" : "yes" ) )
}

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;
}

