// JavaScript Document
function CallDisplayImage(URL, w, h, skin){
	obj = document.getElementById("fullscreenimage");
	PlaceOnScreenCenter(obj);
	obj.style.visibility = 'hidden';
	//obj.style.width = w+"px";
	//obj.style.height = h+"px";
	
	fullscreenimageSkin = skin;
	xmlHttp_fsi = getXmlHttp();
	var url = "ajax.php";
	xmlHttp_fsi.open("POST", url, true);
	xmlHttp_fsi.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp_fsi.onreadystatechange = DisplayImage;
	var Request  = "action=DisplayImage&URL="+URL+"&skin="+skin+"&w="+w+"&h="+h;
	xmlHttp_fsi.send(Request);	
	//document.body.onmousewheel = function(){return false;};

}
function DisplayImage(){
	obj = document.getElementById("fullscreenimage");
	if (xmlHttp_fsi.readyState == 4) {
		var response = xmlHttp_fsi.responseText;
		obj.innerHTML = response;
		obj.style.zIndex = 999;
		AddContext("fullscreenimage");
		DisplayDark(obj);
		InsetImageSizeToScreen(document.getElementById("FullScreenImageItself"), 60, false);
		//document.getElementById('fullscreenimageborder').style.width = document.getElementById('FullScreenImageItself').style.width+'2px'; 
		setTimeout(function() { PlaceOnScreenCenter(obj) }, 200);
		setTimeout(function() { document.getElementById('fullscreenimageborder').style.width = document.getElementById('FullScreenImageItself').offsetWidth }, 200);
	}
	if (xmlHttp_fsi.readyState == 1) {
		//PlaceOnScreenCenter(obj);
	}
}
function InsetImageSizeToScreen(obj, border, Zoom){	
	var viewportW = document.documentElement.clientWidth;
	var viewportH = document.documentElement.clientHeight;
	//var computedStyle = obj.currentStyle || window.getComputedStyle(obj, null);
	var oW = obj.width;
	var oH = obj.height;
	
	if(oW>viewportW || oH>viewportH){ 
		var bigsize = 1; 
	} else { 
		var bigsize = 0; 
	}
	//alert(obj.width);
	//if(obj.style.width>=viewportW+border || obj.style.height>=viewportH+border){
		if(Zoom == true || bigsize == 1){
			//alert(bigsize);
			if(oW == oH){
				obj.style.width = obj.style.height = viewportH-border+"px";
				obj.width = obj.height = viewportH-border+"px";
			}
			if(oW>oH){
				obj.style.width = viewportW-border+"px";
				obj.width = viewportW-border+"px";
				var perc = GetStyleInt(obj.style.width)/oW;
				obj.style.height = oH*perc+"px";
				obj.height = oH*perc+"px";
			}
			if(oW<oH){
				obj.style.height = viewportH-border+"px";
				obj.height = viewportH-border+"px";
				var perc = GetStyleInt(obj.style.height)/oH;
				obj.style.width = oW*perc+"px";
				obj.width = oW*perc+"px";
			}
		}
	//}
}
function GetStyleInt(string){
	var s = string.replace("px", "");
	return s;
}
//Catalog menue ///////////////

CatCellHighliteColor = "#FF9900";
//CatCellHighliteColor = "#FF0000";
CatCellDefColor = "#FF0000";
CatCellPrefix = "cat_cell_";
MPointHolderPrefix = "cat_cell_holder_";

OpenMPoints = new Array();
OpenMpointsHolders = new Array();


function AddMPoint(name){OpenMPoints[OpenMPoints.length] = name;}
function AddMPointHolder(name){OpenMpointsHolders[OpenMpointsHolders.length] = name;}

function HighLiteCatCell(Id, Color, DefColor){
	for(var i=0; i<OpenMPoints.length; i++){
		document.getElementById(OpenMPoints[i]).setAttribute("bgcolor", CatCellDefColor);
		document.getElementById(OpenMPoints[i]).className = "RedCell";
	}
	document.getElementById(CatCellPrefix+Id).setAttribute("bgcolor", Color);
	document.getElementById(CatCellPrefix+Id).className = "OrangeCell";
	AddMPoint(CatCellPrefix+Id);
}
function Cat_CallGetDirList(Lang, Sib, Id){
	HighLiteCatCell(Id, CatCellHighliteColor, CatCellDefColor);
	CurrentMPointId=Id;
	xmlHttp_fsi = getXmlHttp();
	var url = "ajax.php";
	xmlHttp_fsi.open("POST", url, true);
	xmlHttp_fsi.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp_fsi.onreadystatechange = DisplayDirList;
	var Request  = "action=BrowseContentTitles&Lang="+Lang+"&Sib="+Sib;
	xmlHttp_fsi.send(Request);
	
}
function DisplayDirList(){
	obj = document.getElementById(MPointHolderPrefix+CurrentMPointId);
	for(var i=0; i<OpenMpointsHolders.length; i++){
		document.getElementById(OpenMpointsHolders[i]).innerHTML = " ";
	}	
	AddMPointHolder(obj.id);
	if (xmlHttp_fsi.readyState == 4) {
		var response = xmlHttp_fsi.responseText;
		obj.innerHTML = response;
	}
	if (xmlHttp_fsi.readyState == 1) {
		obj.innerHTML = "<img src='img/avanta/bar.gif' width='128' height='16' border='0'  />";
	}
}

function CallAddLinks(Table, Id){
	obj = document.getElementById("AdminMainFrame");
	PlaceOnScreenCenter(obj);
	xmlHttp_fsi = getXmlHttp();
	var url = "ajax_admin.php";
	xmlHttp_fsi.open("POST", url, true);
	xmlHttp_fsi.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp_fsi.onreadystatechange = DisplayAddLinks;
	var Request  = "action=AddLinks&Table="+Table+"&Id="+Id;
	xmlHttp_fsi.send(Request);	
}
function DisplayAddLinks(){
	obj = document.getElementById("AdminMainFrame");
	if (xmlHttp_fsi.readyState == 4) {
		var response = xmlHttp_fsi.responseText;
		obj.innerHTML = response;
		PlaceOnScreenCenter(obj);
		AddContext("AdminMainFrame");
		setTimeout(function() { PlaceOnScreenCenter(obj) }, 200);
	}
	if (xmlHttp_fsi.readyState == 1) {
		obj.innerHTML = "<table width='900' border='0' cellpadding='0' cellspacing='0'><tr><td><img src='img/expoan/shade_soft2_c0.png' width='20' height='20' /></td><td height='20' align='right' background='img/expoan/shade_soft2_b0.png'><a href='javascript:void(0)' onclick='closeAllContents();'><img src='img/interface/icon_delete.gif' width='15' height='16' border='0' /></a></td><td><img src='img/expoan/shade_soft2_c1.png' width='20' height='20' /></td></tr><tr><td width='20' background='img/expoan/shade_soft2_b3.png'>&nbsp;</td><td bgcolor='#465f66'><br /><table width='90%' align='center' cellpadding='5' cellspacing='0' class='mainframe1'><tr><td class='mainframe2'><table width='100%' cellpadding='3' cellspacing='0' bgcolor='#edeae4' class='wbbc'><tr><td class='inframe1' ><table width='200' border='0' align='center'><tr><td background='core/img/new/bar.gif'><p>Обработка запроса...</p></td></tr></table></td></tr></table></td></tr></table><br /><br /></td><td width='20' background='img/expoan/shade_soft2_b1.png'>&nbsp;</td></tr><tr><td><img src='img/expoan/shade_soft2_c3.png' width='20' height='20' /></td><td height='20' background='img/expoan/shade_soft2_b2.png'>&nbsp;</td><td><img src='img/expoan/shade_soft2_c2.png' width='20' height='20' /></td></tr></table>";
		PlaceOnScreenCenter(obj);
	}	
}
function CallDisplayFolderX(Table, Path, TargetTable, TargetId){
	obj = document.getElementById("AdminMainFrame");
	PlaceOnScreenCenter(obj);
	xmlHttp_fsi = getXmlHttp();
	var url = "ajax_admin.php";
	xmlHttp_fsi.open("POST", url, true);
	xmlHttp_fsi.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp_fsi.onreadystatechange = DisplayFolderX;
	var Request  = "action=DisplayFolderX&Table="+Table+"&Path="+Path+"&TargetId="+TargetId;
	xmlHttp_fsi.send(Request);	
}
function DisplayFolderX(){
	obj = document.getElementById("AdminMainFrame");
	if (xmlHttp_fsi.readyState == 4) {
		var response = xmlHttp_fsi.responseText;
		obj.innerHTML = response;
		PlaceOnScreenCenter(obj);
		AddContext("AdminMainFrame");
		setTimeout(function() { PlaceOnScreenCenter(obj) }, 200);
	}
	if (xmlHttp_fsi.readyState == 1) {
obj.innerHTML = "<table width='900' border='0' cellpadding='0' cellspacing='0'><tr><td><img src='img/expoan/shade_soft2_c0.png' width='20' height='20' /></td><td height='20' align='right' background='img/expoan/shade_soft2_b0.png'><a href='javascript:void(0)' onclick='closeAllContents();'><img src='img/interface/icon_delete.gif' width='15' height='16' border='0' /></a></td><td><img src='img/expoan/shade_soft2_c1.png' width='20' height='20' /></td></tr><tr><td width='20' background='img/expoan/shade_soft2_b3.png'>&nbsp;</td><td bgcolor='#465f66'><br /><table width='90%' align='center' cellpadding='5' cellspacing='0' class='mainframe1'><tr><td class='mainframe2'><table width='100%' cellpadding='3' cellspacing='0' bgcolor='#edeae4' class='wbbc'><tr><td class='inframe1' ><table width='200' border='0' align='center'><tr><td background='core/img/new/bar.gif'><p>Обработка запроса...</p></td></tr></table></td></tr></table></td></tr></table><br /><br /></td><td width='20' background='img/expoan/shade_soft2_b1.png'>&nbsp;</td></tr><tr><td><img src='img/expoan/shade_soft2_c3.png' width='20' height='20' /></td><td height='20' background='img/expoan/shade_soft2_b2.png'>&nbsp;</td><td><img src='img/expoan/shade_soft2_c2.png' width='20' height='20' /></td></tr></table>";
PlaceOnScreenCenter(obj);
	}	
}

function CallReplace(Table, Id){
	obj = document.getElementById("AdminMainFrame");
	PlaceOnScreenCenter(obj);
	xmlHttp_fsi = getXmlHttp();
	var url = "ajax_admin.php";
	xmlHttp_fsi.open("POST", url, true);
	xmlHttp_fsi.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp_fsi.onreadystatechange = DisplayReplace;
	var Request  = "action=Replace&Table="+Table+"&Id="+Id;
	xmlHttp_fsi.send(Request);	
}
function DisplayReplace(){
	obj = document.getElementById("AdminMainFrame");
	if (xmlHttp_fsi.readyState == 4) {
		var response = xmlHttp_fsi.responseText;
		obj.innerHTML = response;
		PlaceOnScreenCenter(obj);
		AddContext("AdminMainFrame");
		setTimeout(function() { PlaceOnScreenCenter(obj) }, 200);
	}
	if (xmlHttp_fsi.readyState == 1) {
		obj.innerHTML = "<table width='900' border='0' cellpadding='0' cellspacing='0'><tr><td><img src='img/expoan/shade_soft2_c0.png' width='20' height='20' /></td><td height='20' align='right' background='img/expoan/shade_soft2_b0.png'><a href='javascript:void(0)' onclick='closeAllContents();'><img src='img/interface/icon_delete.gif' width='15' height='16' border='0' /></a></td><td><img src='img/expoan/shade_soft2_c1.png' width='20' height='20' /></td></tr><tr><td width='20' background='img/expoan/shade_soft2_b3.png'>&nbsp;</td><td bgcolor='#465f66'><br /><table width='90%' align='center' cellpadding='5' cellspacing='0' class='mainframe1'><tr><td class='mainframe2'><table width='100%' cellpadding='3' cellspacing='0' bgcolor='#edeae4' class='wbbc'><tr><td class='inframe1' ><table width='200' border='0' align='center'><tr><td background='core/img/new/bar.gif'><p>Обработка запроса...</p></td></tr></table></td></tr></table></td></tr></table><br /><br /></td><td width='20' background='img/expoan/shade_soft2_b1.png'>&nbsp;</td></tr><tr><td><img src='img/expoan/shade_soft2_c3.png' width='20' height='20' /></td><td height='20' background='img/expoan/shade_soft2_b2.png'>&nbsp;</td><td><img src='img/expoan/shade_soft2_c2.png' width='20' height='20' /></td></tr></table>";
		PlaceOnScreenCenter(obj);
	}	
}
function CallDisplayFolderXforReplace(Table, Path, TargetTable, TargetId){
	obj = document.getElementById("AdminMainFrame");
	PlaceOnScreenCenter(obj);
	xmlHttp_fsi = getXmlHttp();
	var url = "ajax_admin.php";
	xmlHttp_fsi.open("POST", url, true);
	xmlHttp_fsi.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp_fsi.onreadystatechange = DisplayReplace;
	var Request  = "action=DisplayFolderXforReplace&Table="+Table+"&Path="+Path+"&TargetId="+TargetId+"&TargetTable="+TargetTable;
	xmlHttp_fsi.send(Request);
}

function CallGlobalSearchSupp(lang, value){
	xmlHttp_fsi = getXmlHttp();
	var url = "ajax.php";
	xmlHttp_fsi.open("POST", url, true);
	xmlHttp_fsi.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp_fsi.onreadystatechange = DisplayGlobalSearchSupp;
	var Request  = "action=GlobalSearchSupp&value="+encodeURIComponent(value)+"&lang="+lang;
	xmlHttp_fsi.send(Request);
}
function DisplayGlobalSearchSupp(){
	obj = document.getElementById("GlobalSearch");
	AddMPointHolder(obj.id);
	if (xmlHttp_fsi.readyState == 4) {
		var response = xmlHttp_fsi.responseText;
		obj.innerHTML = response;
		AddContext("GlobalSearch");
		Sup = document.getElementById("GlobalSearchSupp");
		GSF = document.getElementById("GlobalSearchField");
		GSFsize = getsize(GSF);
		GSFPos = GetPosition(GSF);
		if (navigator.userAgent.match('MSIE') ) {
			Sup.style.width = GSFsize.w-1+"px";
			SetPosition(Sup, GSFPos.x-1, GSFPos.y+GSFsize.h-1);
		} else {
			SetPosition(Sup, GSFPos.x, GSFPos.y+GSFsize.h-1);
			Sup.style.width = GSFsize.w-2+"px";
		}
		
		//alert(GSFsize.h+" "+GSFPos.x);
	}
	if (xmlHttp_fsi.readyState == 1) {

	}
}
function SetGlobalSearchValue(value){
	GSF = document.getElementById("GlobalSearchField");
	GSF.value = value;
	closeAllContents();
}

