
var initColor;
var iddd;
var interv;
var count;
var LinkColor = "red";
var screenWidth = 0, screenHeight = 0;


var modalbox;
var shade;
var scrollWidth;
var scrollHeight;

function OverCl1()
{
   if ( count % 2 == 0 )document.getElementById( iddd ).style.color = LinkColor;
   else document.getElementById( iddd ).style.color = initColor;
   count ++ ;
}

function Over( idd )
{
   if ( document.getElementById )
   {
      count = 1;
      iddd = idd;
      initColor = document.getElementById( iddd ).style.color;
      document.getElementById( iddd ).style.color = LinkColor;
      interv = setInterval( "OverCl1()", 500 );
   }
}

function Out( idd )
{
   if ( document.getElementById )
   {
      clearInterval( interv );
      document.getElementById( idd ).style.color = initColor;
   }
}


function findDimensions() {
  if(window.innerWidth) {
    screenWidth = window.innerWidth;
    screenHeight = window.innerHeight;
  }
  else if(document.documentElement && document.documentElement.clientWidth) {
    screenWidth = document.documentElement.clientWidth;
    screenHeight = document.documentElement.clientHeight;
  }
  else if(document.body && document.body.clientWidth) {
    screenWidth = document.body.clientWidth;
    screenHeight = document.body.clientHeight;
  }
}

// функция вывода всплывающих форм
function ShowForm() {
	modalbox = document.getElementById("modalbox");
	shade = document.getElementById("shade");

	scrollWidth = document.body.scrollWidth;
	scrollHeight = document.body.scrollHeight;

	document.getElementById("main").style.width = scrollWidth;
	document.getElementById("main").style.height = scrollHeight;
	
	document.getElementById("main").style.filter = "alpha(opacity=80)";
	document.getElementById("main").style.opacity = 0.8;
	document.getElementById("main").style.display = "block";

	modalbox.style.display = "block";
	shade.style.display = "block";

	posleft = Math.round(scrollWidth / 2) - 250;
	postop = document.body.scrollHeight - 600;

	shade.style.left = posleft + 7;
	shade.style.top = 57;
	//document.body.scrollTop + 307;

	modalbox.style.left = posleft;
	modalbox.style.top = 50;
	//document.body.scrollTop + 300;
}


// функция вывода окна галереи
function ShowGallery(id) {
	modalbox = document.getElementById("modalbox");
	shade = document.getElementById("shade");

	scrollWidth = document.body.scrollWidth;
	scrollHeight = document.body.scrollHeight;

	document.getElementById("main").style.width = scrollWidth;
	document.getElementById("main").style.height = scrollHeight;
	
	document.getElementById("main").style.filter = "alpha(opacity=80)";
	document.getElementById("main").style.opacity = 0.8;
	document.getElementById("main").style.display = "block";
	sendRequest('loadImage.php?id='+id,'picss','<div align="center" style="color:black"><img src="CMS/images/progress.gif"><br/><i>Загрузка...</i></div>');
}


function CenterForm (x, y) {
	modalbox = document.getElementById("modalbox");
	shade = document.getElementById("shade");
	
	posleft = Math.round(scrollWidth / 2) - Math.round((x+20) / 2);
	postop = document.body.scrollTop + 10;
		
	shade.style.left = posleft + 7;
	shade.style.top = postop + 7;
	
	modalbox.style.left = posleft;
	modalbox.style.top = postop;	
	
	shade.style.width=(x+20); 
	shade.style.height=(y+130); 
	
	modalbox.style.width=(x+20); 
	modalbox.style.height=(y+130);	
	
	modalbox.style.display = "block";
	shade.style.display = "block";	
	
	
}


// функция вывода всплывающих форм подробностей файла (используется в модуле cmsUploadedFotos)
function ShowFileInfo(id) {
	modalbox = document.getElementById("modalbox");
	shade = document.getElementById("shade");

	scrollWidth = document.body.scrollWidth;
	scrollHeight = document.body.scrollHeight;

	document.getElementById("main").style.width = scrollWidth;
	document.getElementById("main").style.height = scrollHeight;
	
	document.getElementById("main").style.filter = "alpha(opacity=0)";
	document.getElementById("main").style.opacity = 0;
	document.getElementById("main").style.display = "block";

	modalbox.style.display = "block";
	shade.style.display = "block";

	findDimensions();
	
	if ((posX + 7 + 500) > screenWidth) {
		posleft = posX - 500;
		postop = posY;
	}
	else {
		posleft = posX;
		postop = posY;
	}

	shade.style.left = posleft + 7;
	shade.style.top = postop + 7;
	//document.body.scrollTop + 307;

	modalbox.style.left = posleft;
	modalbox.style.top = postop;
	sendRequest('modules/getFotosInfo.php?id=' + id,'content','<div align="center" style="color:black"><img src="images/progress.gif"><br/><i>Загрузка...</i></div>');
}

// определение координат мыши
function defPosition(event) {	
    var x = y = 0;
    if (document.attachEvent != null) { // Internet Explorer & Opera
        x = window.event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
        y = window.event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
    } else if (!document.attachEvent && document.addEventListener) { // Gecko
        x = event.clientX + window.scrollX;
        y = event.clientY + window.scrollY;
    } else {
        // Do nothing
    }
    return {x:x, y:y};
}

// Функция, убирающая всплывающую форму с экрана (при нажатии кнопки Отмена)
function HideForm() {
	document.getElementById("main").style.display = "none";
	modalbox.style.display = "none";
	shade.style.display = "none";
}


function mouseover(row, font_color, checkedcolor) 
{
	if(row.style.color != checkedcolor) 
	{
		row.style.color = font_color;
	}

}


function mouseout(row, font_color, checkedcolor) 
{
	if(row.style.color != checkedcolor) 
	{
		row.style.color = font_color;
	}

}

function checkBoxchangeState (id,picid) {
	var val; 
	var checkBox = document.getElementById(id);
	
	if (checkBox.value == 1) {
		val = 0;
		checkBox.value = 0;
	} else {
		val = 1; 
		checkBox.value = 1;
	}
	
	sendRequest('modifyStateImg.php?'+id+'='+val+'&id='+picid,'stateimg','<div align=\'right\' style=\'color:white\'><strong>Идет изменение свойств...</strong></div>');	
}


function fileRollOver (id1, id2, color) {
	document.getElementById(id1).style.backgroundColor = color; 
	document.getElementById(id2).style.backgroundColor = color;
}


function showDescrInput(id,insSp) {	
	var tmp = insSp.innerHTML; 
	insSp.onclick='';
	insSp.innerHTML= '<input id="newdesc" style="width:100px" value="'+tmp+'" type="text"><input type="button" onclick="sendRequest(\'modifyStateImg.php?id='+id+'&descr=\'+getElementById(\'newdesc\').value,\'desc\',\'<strong>Отправка...</strong>\');" value="ok">';
	// getElementById(\'desc\').onclick= function() { showDescrInput('+id+',this); } АХТУНГ!!! в опере сохраняет в кракозябры!!!
}